Skip to content

Commit

Permalink
Whitespace fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Jul 13, 2008
1 parent 10f87b1 commit 66d9d1c
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 122 deletions.
30 changes: 14 additions & 16 deletions base.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* $Id$ */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand Down Expand Up @@ -118,7 +116,7 @@ static int getdestaddr_ipf(int fd, const struct sockaddr_in *client, const struc
}
#endif
if (x < 0) {
if (errno != ESRCH)
if (errno != ESRCH)
log_errno(LOG_WARNING, "ioctl(SIOCGNATL)\n");
return -1;
} else {
Expand Down Expand Up @@ -196,7 +194,7 @@ int getdestaddr(int fd, const struct sockaddr_in *client, const struct sockaddr_
return instance.redirector->getdestaddr(fd, client, bindaddr, destaddr);
}

static redirector_subsys redirector_subsystems[] =
static redirector_subsys redirector_subsystems[] =
{
#ifdef __FreeBSD__
{ .name = "ipf", .init = redir_init_ipf, .fini = redir_close_private, .getdestaddr = getdestaddr_ipf },
Expand All @@ -213,7 +211,7 @@ static redirector_subsys redirector_subsystems[] =
/***********************************************************************
* `base` config parsing
*/
static parser_entry base_entries[] =
static parser_entry base_entries[] =
{
{ .key = "chroot", .type = pt_pchar, .addr = &instance.chroot },
{ .key = "user", .type = pt_pchar, .addr = &instance.user },
Expand All @@ -239,7 +237,7 @@ static int base_onenter(parser_section *section)
static int base_onexit(parser_section *section)
{
const char *err = NULL;

if (instance.redirector_name) {
redirector_subsys *ss;
FOREACH(ss, redirector_subsystems) {
Expand All @@ -255,7 +253,7 @@ static int base_onexit(parser_section *section)
else {
err = "no `redirector` set";
}

if (err)
parser_error(section->context, err);

Expand All @@ -265,11 +263,11 @@ static int base_onexit(parser_section *section)
return err ? -1 : 0;
}

static parser_section base_conf_section =
{
.name = "base",
.entries = base_entries,
.onenter = base_onenter,
static parser_section base_conf_section =
{
.name = "base",
.entries = base_entries,
.onenter = base_onenter,
.onexit = base_onexit
};

Expand All @@ -286,7 +284,7 @@ static int base_init()
log_error(LOG_ERR, "there is no configured instance of `base`, check config file");
return -1;
}

if (instance.redirector->init && instance.redirector->init() < 0)
return -1;

Expand All @@ -309,8 +307,8 @@ static int base_init()
}

if (log_preopen(
instance.log_name ? instance.log_name : instance.daemon ? "syslog:daemon" : "stderr",
instance.log_debug,
instance.log_name ? instance.log_name : instance.daemon ? "syslog:daemon" : "stderr",
instance.log_debug,
instance.log_info
) < 0 ) {
goto fail;
Expand Down Expand Up @@ -392,7 +390,7 @@ static int base_init()
return -1;
}

app_subsys base_subsys =
app_subsys base_subsys =
{
.init = base_init,
.conf_section = &base_conf_section,
Expand Down
3 changes: 2 additions & 1 deletion base.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef BASE_H_SUN_JUN__3_20_15_57_2007
#define BASE_H_SUN_JUN__3_20_15_57_2007
/* $Id$ */

int getdestaddr(int fd, const struct sockaddr_in *client, const struct sockaddr_in *bindaddr, struct sockaddr_in *destaddr);

/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
/* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
#endif /* BASE_H_SUN_JUN__3_20_15_57_2007 */
19 changes: 11 additions & 8 deletions http-connect.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** http-connect upstream module for redsocks
* $Id$
*/

#include <assert.h>
Expand All @@ -26,10 +25,10 @@ static void httpc_client_init(redsocks_client *client)
{
if (client->instance->config.login)
redsocks_log_error(client, LOG_WARNING, "login is ignored for http-connect connections");

if (client->instance->config.password)
redsocks_log_error(client, LOG_WARNING, "password is ignored for http-connect connections");

client->state = httpc_new;
}

Expand All @@ -41,6 +40,8 @@ static void httpc_read_cb(struct bufferevent *buffev, void *_arg)

assert(client->state >= httpc_request_sent);

redsocks_touch_client(client);

if (client->state == httpc_request_sent) {
size_t len = EVBUFFER_LENGTH(buffev->input);
char *line = evbuffer_readline(buffev->input);
Expand All @@ -66,7 +67,7 @@ static void httpc_read_cb(struct bufferevent *buffev, void *_arg)

if (dropped)
return;

while (client->state == httpc_reply_came) {
char *line = evbuffer_readline(buffev->input);
if (line) {
Expand Down Expand Up @@ -96,16 +97,16 @@ static struct evbuffer *httpc_mkconnect(redsocks_client *client)
goto fail;
}

len = evbuffer_add_printf(buff,
"CONNECT %s:%u HTTP/1.0\r\n\r\n",
len = evbuffer_add_printf(buff,
"CONNECT %s:%u HTTP/1.0\r\n\r\n",
inet_ntoa(client->destaddr.sin_addr),
ntohs(client->destaddr.sin_port)
);
if (len < 0) {
redsocks_log_errno(client, LOG_ERR, "evbufer_add_printf");
goto fail;
}

retval = buff;
buff = NULL;

Expand All @@ -120,6 +121,8 @@ static void httpc_write_cb(struct bufferevent *buffev, void *_arg)
{
redsocks_client *client = _arg;

redsocks_touch_client(client);

if (client->state == httpc_new) {
redsocks_write_helper_ex(
buffev, client,
Expand All @@ -132,7 +135,7 @@ static void httpc_write_cb(struct bufferevent *buffev, void *_arg)
}


relay_subsys http_connect_subsys =
relay_subsys http_connect_subsys =
{
.name = "http-connect",
.payload_len = 0,
Expand Down
29 changes: 16 additions & 13 deletions http-relay.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** http-relay upstream module for redsocks
* $Id$
*/

#include <assert.h>
Expand Down Expand Up @@ -27,10 +26,10 @@ static void httpr_client_init(redsocks_client *client)

if (client->instance->config.login)
redsocks_log_error(client, LOG_WARNING, "login is ignored for http-relay connections");

if (client->instance->config.password)
redsocks_log_error(client, LOG_WARNING, "password is ignored for http-relay connections");

client->state = httpr_new;
memset(httpr, 0, sizeof(*httpr));
}
Expand All @@ -53,6 +52,8 @@ static void httpr_relay_write_cb(struct bufferevent *buffev, void *_arg)

assert(httpr->buff);

redsocks_touch_client(client);

len = bufferevent_write_buffer(client->relay, httpr->buff);
// free is done either at _start_relay or at _drop_client

Expand Down Expand Up @@ -87,7 +88,7 @@ static char *fmt_http_host(struct sockaddr_in addr)
if (ntohs(addr.sin_port) == 80)
return inet_ntoa(addr.sin_addr);
else {
snprintf(host, sizeof(host),
snprintf(host, sizeof(host),
"%s:%u",
inet_ntoa(addr.sin_addr),
ntohs(addr.sin_port)
Expand All @@ -102,11 +103,11 @@ static int httpr_toss_http_firstline(redsocks_client *client)
char *uri = NULL;
struct evbuffer *buff = NULL;
char *host = fmt_http_host(client->destaddr);

assert(httpr->firstline);

uri = strchr(httpr->firstline, ' ');
if (uri)
if (uri)
uri += 1; // one char further
else {
redsocks_log_error(client, LOG_NOTICE, "malformed request came");
Expand Down Expand Up @@ -135,7 +136,7 @@ static int httpr_toss_http_firstline(redsocks_client *client)
evbuffer_free(httpr->buff);
httpr->buff = buff;
return 0;

addition_fail:
redsocks_log_error(client, LOG_ERR, "evbuffer_add");
fail:
Expand All @@ -150,7 +151,9 @@ static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg)
httpr_client *httpr = (void*)(client +1);
char *line = NULL;
int connect_relay = 0;


redsocks_touch_client(client);

while ( (line = evbuffer_readline(buffev->input)) && !connect_relay) {
int skip_line = 0;
int do_drop = 0;
Expand Down Expand Up @@ -200,15 +203,15 @@ static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg)
if (line && !skip_line)
if (httpr_append_header(client, line) < 0)
do_drop = 1;

free(line);

if (do_drop) {
redsocks_drop_client(client);
return;
}
}

if (connect_relay)
redsocks_connect_relay(client);
}
Expand All @@ -223,7 +226,7 @@ static void httpr_connect_relay(redsocks_client *client)
redsocks_log_errno(client, LOG_ERR, "evbuffer_new");
redsocks_drop_client(client);
}

client->client->readcb = httpr_client_read_cb;
error = bufferevent_enable(client->client, EV_READ);
if (error) {
Expand All @@ -232,7 +235,7 @@ static void httpr_connect_relay(redsocks_client *client)
}
}

relay_subsys http_relay_subsys =
relay_subsys http_relay_subsys =
{
.name = "http-relay",
.payload_len = sizeof(httpr_client),
Expand Down
2 changes: 1 addition & 1 deletion list.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
/** That's taken from linux-2.6.18.2 source tree with light modifications
* I don't know what copyright to place here but that's GPLv2 code so
* I don't know what copyright to place here but that's GPLv2 code so
* I assume I'm free to reuse it.
*/
#include "utils.h" // container_of
Expand Down
8 changes: 3 additions & 5 deletions log.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* $Id$ */

#include <stdio.h>
#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -60,7 +58,7 @@ int log_preopen(const char *dst, bool log_debug, bool log_info)
{ "local7", LOG_LOCAL7 },
};

FOREACH(ptpl, tpl)
FOREACH(ptpl, tpl)
if (strcmp(facility_name, ptpl->name) == 0) {
facility = ptpl->value;
break;
Expand All @@ -71,7 +69,7 @@ int log_preopen(const char *dst, bool log_debug, bool log_info)
}

openlog("redsocks", LOG_NDELAY | LOG_PID, facility);

logmask = setlogmask(0);
if (!log_debug)
logmask &= ~(LOG_MASK(LOG_DEBUG));
Expand Down Expand Up @@ -104,7 +102,7 @@ void _log_vwrite(const char *file, int line, const char *func, int do_errno, int
evbuffer_add_vprintf(buff, fmt, ap);
message = buff->buffer;
}
else
else
message = lowmem;

log_msg(file, line, func, priority, message, do_errno ? strerror(saved_errno) : NULL);
Expand Down
2 changes: 1 addition & 1 deletion log.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef LOG_H_WED_JAN_24_18_21_27_2007
#define LOG_H_WED_JAN_24_18_21_27_2007
/* $Id$ */

#include <stdarg.h>
#include <stdbool.h>
#include <syslog.h>
Expand Down
8 changes: 3 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* $Id$ */

#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
Expand Down Expand Up @@ -44,14 +42,14 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
}


FILE *f = fopen(confname, "r");
if (!f) {
perror("Unable to open config file");
return EXIT_FAILURE;
}

parser_context* parser = parser_start(f, NULL);
if (!parser) {
perror("Not enough memory for parser");
Expand Down Expand Up @@ -83,7 +81,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
}

log_error(LOG_NOTICE, "redsocks started");

event_dispatch();
Expand Down
1 change: 0 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef MAIN_H_TUE_JAN_23_15_38_25_2007
#define MAIN_H_TUE_JAN_23_15_38_25_2007
/* $Id$ */

#include "parser.h"

Expand Down
Loading

0 comments on commit 66d9d1c

Please sign in to comment.