commit 656f95d3a0b15a456f51efcee7317752637736c9 Author: George Kadianakis desnacked@gmail.com Date: Sat Jul 9 00:52:23 2011 +0200
Adopt "0 on success, -1 on fail" function return policy. --- src/main.c | 12 +++++------- src/protocols/dummy.c | 4 ++-- src/protocols/obfs2.c | 8 ++++---- src/socks.c | 16 +++++----------- src/socks.h | 12 +++++------- src/test/unittest_obfs2.c | 2 +- src/test/unittest_socks.c | 18 ++++++------------ src/util.c | 18 ++++++++++-------- 8 files changed, 38 insertions(+), 52 deletions(-)
diff --git a/src/main.c b/src/main.c index a8347c2..a5f93de 100644 --- a/src/main.c +++ b/src/main.c @@ -72,8 +72,6 @@ handle_signal_cb(evutil_socket_t fd, short what, void *arg) /** This function visits 'n_options' command line arguments off 'argv' and writes them in 'options_string'. - - Returns 1 on success, -1 on fail. */ static void populate_options(char **options_string, @@ -85,17 +83,17 @@ populate_options(char **options_string, }
/** - Returns 1 if 'name' is the nmae of a supported protocol, otherwise - it returns 0. + Returns 0 if 'name' is the nmae of a supported protocol, otherwise + it returns -1. */ static int is_supported_protocol(const char *name) { int f; for (f=0;f<n_supported_protocols;f++) { if (!strcmp(name,supported_protocols[f])) - return 1; + return 0; } - return 0; + return -1; }
/** @@ -240,7 +238,7 @@ main(int argc, const char **argv) }
/* First option should be protocol_name. See if we support it. */ - if (!is_supported_protocol(argv[start])) { + if (is_supported_protocol(argv[start])<0) { log_warn("We don't support protocol: %s", argv[start]); continue; } diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c index bdf97fc..dea8cfc 100644 --- a/src/protocols/dummy.c +++ b/src/protocols/dummy.c @@ -53,7 +53,7 @@ dummy_init(int n_options, char **options, vtable->send = dummy_send; vtable->recv = dummy_recv;
- return 1; + return 0; }
static int @@ -93,7 +93,7 @@ parse_and_set_options(int n_options, char **options, memcpy(¶ms->on_address, sa_listen, sl_listen); params->on_address_len = sl_listen;
- return 1; + return 0; }
static void diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c index 676ddd7..5447e7b 100644 --- a/src/protocols/obfs2.c +++ b/src/protocols/obfs2.c @@ -58,7 +58,7 @@ obfs2_init(int n_options, char **options, return -1; }
- return 1; + return 0; }
int @@ -148,7 +148,7 @@ parse_and_set_options(int n_options, char **options, }
log_debug("%s(): Parsed obfs2 options nicely!", __func__); - return 1; + return 0; }
/** @@ -174,7 +174,7 @@ usage(void) /** Helper: Allocates space for the protocol vtable and populates it's function pointers. - Returns 1 on success, -1 on fail. + Returns 0 on success, -1 on fail. */ static int set_up_vtable(void) @@ -190,7 +190,7 @@ set_up_vtable(void) vtable->send = obfs2_send; vtable->recv = obfs2_recv;
- return 1; + return 0; }
/** Return true iff the OBFUSCATE_SEED_LENGTH-byte seed in 'seed' is nonzero */ diff --git a/src/socks.c b/src/socks.c index 7e6f6b2..6873683 100644 --- a/src/socks.c +++ b/src/socks.c @@ -236,7 +236,7 @@ socks5_handle_request(struct evbuffer *source, struct parsereq *parsereq) | version | rep | rsv | atyp | destaddr | destport 1b 1b 1b 1b 4b/16b/1+Nb 2b */ -int +void socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state, int status) { @@ -282,8 +282,6 @@ socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state, evbuffer_add(reply_dest, &port, 2);
state->state = ST_SENT_REPLY; /* SOCKS phase is now done. */ - - return 1; }
/** @@ -432,7 +430,7 @@ socks4_read_request(struct evbuffer *source, socks_state_t *state) return SOCKS_GOOD; }
-int +void socks4_send_reply(struct evbuffer *dest, socks_state_t *state, int status) { uint16_t portnum; @@ -450,8 +448,6 @@ socks4_send_reply(struct evbuffer *dest, socks_state_t *state, int status) /* ASN: What should we do here in the case of an FQDN request? */ memcpy(msg+4, &in.s_addr, 4); evbuffer_add(dest, msg, 8); - - return 1; }
/** @@ -596,14 +592,12 @@ socks_state_set_address(socks_state_t *state, const struct sockaddr *sa) If 'error' is not 0, it means that an error was encountered and error carries the errno(3) of the error. */ -int +void socks_send_reply(socks_state_t *state, struct evbuffer *dest, int error) { int status = socks_errno_to_reply(state, error); if (state->version == SOCKS5_VERSION) - return socks5_send_reply(dest, state, status); + socks5_send_reply(dest, state, status); else if (state->version == SOCKS4_VERSION) - return socks4_send_reply(dest, state, status); - else - return -1; + socks4_send_reply(dest, state, status); } diff --git a/src/socks.h b/src/socks.h index 2f1e44b..6ae69e9 100644 --- a/src/socks.h +++ b/src/socks.h @@ -43,9 +43,9 @@ int socks_state_get_address(const socks_state_t *state, const char **addr_out, int *port_out); int socks_state_set_address(socks_state_t *state, const struct sockaddr *sa); -int socks_send_reply(socks_state_t *state, struct evbuffer *dest, int error); -int socks5_send_reply(struct evbuffer *reply_dest, - socks_state_t *state, int status); +void socks_send_reply(socks_state_t *state, struct evbuffer *dest, int error); +void socks5_send_reply(struct evbuffer *reply_dest, + socks_state_t *state, int status);
#define SOCKS5_SUCCESS 0x00 @@ -106,13 +106,11 @@ struct socks_state_t {
enum socks_ret socks5_handle_negotiation(struct evbuffer *source, struct evbuffer *dest, socks_state_t *state); -int socks5_send_reply(struct evbuffer *reply_dest, socks_state_t *state, - int status); enum socks_ret socks5_handle_request(struct evbuffer *source, struct parsereq *parsereq);
enum socks_ret socks4_read_request(struct evbuffer *source, socks_state_t *state); -int socks4_send_reply(struct evbuffer *dest, - socks_state_t *state, int status); +void socks4_send_reply(struct evbuffer *dest, + socks_state_t *state, int status); #endif
#endif diff --git a/src/test/unittest_obfs2.c b/src/test/unittest_obfs2.c index af31adc..27395df 100644 --- a/src/test/unittest_obfs2.c +++ b/src/test/unittest_obfs2.c @@ -31,7 +31,7 @@ test_proto_option_parsing(void *data) log_set_method(LOG_METHOD_NULL, NULL);
tt_assert(set_up_protocol(n_options, options, - proto_params) == 1); + proto_params) == 0);
/** two --dest. */ char *options2[] = {"obfs2", "--dest=127.0.0.1:5555", "--dest=a", diff --git a/src/test/unittest_socks.c b/src/test/unittest_socks.c index c85fcf9..40374d2 100644 --- a/src/test/unittest_socks.c +++ b/src/test/unittest_socks.c @@ -318,8 +318,7 @@ test_socks_socks5_request_reply(void *data) /* First test: We ask the server to send us a reply on an IPv4 request with succesful status. */ - tt_int_op(1, ==, socks5_send_reply(reply_dest, - state, SOCKS5_SUCCESS)); + socks5_send_reply(reply_dest,state, SOCKS5_SUCCESS);
uchar rep1[255]; evbuffer_remove(reply_dest,rep1,255); /* yes, this is dirty */ @@ -340,8 +339,7 @@ test_socks_socks5_request_reply(void *data) state->parsereq.af = AF_INET6; strcpy(state->parsereq.addr, "d:1:5:e:a:5:e:0");
- tt_int_op(1, ==, socks5_send_reply(reply_dest, - state, SOCKS5_SUCCESS)); + socks5_send_reply(reply_dest,state, SOCKS5_SUCCESS);
uchar rep2[255]; evbuffer_remove(reply_dest,rep2,255); @@ -365,8 +363,7 @@ test_socks_socks5_request_reply(void *data) state->parsereq.af = AF_UNSPEC; strcpy(state->parsereq.addr, fqdn);
- tt_int_op(1, ==, socks5_send_reply(reply_dest, - state, SOCKS5_FAILED_GENERAL)); + socks5_send_reply(reply_dest,state, SOCKS5_FAILED_GENERAL);
uchar rep3[255]; evbuffer_remove(reply_dest,rep3,255); @@ -383,8 +380,7 @@ test_socks_socks5_request_reply(void *data) SOCKS5_FAILED_UNSUPPORTED status. */ memset(&state->parsereq,'\x00',sizeof(struct parsereq));
- tt_int_op(1, ==, socks5_send_reply(reply_dest, - state, SOCKS5_FAILED_UNSUPPORTED)); + socks5_send_reply(reply_dest,state, SOCKS5_FAILED_UNSUPPORTED); uchar rep4[255]; evbuffer_remove(reply_dest,rep4,255);
@@ -565,8 +561,7 @@ test_socks_socks4_request_reply(void *data) /* First test: We ask the server to send us a reply on an IPv4 request with succesful status. */ - tt_int_op(1, ==, socks4_send_reply(reply_dest, - state, SOCKS4_SUCCESS)); + socks4_send_reply(reply_dest,state, SOCKS4_SUCCESS);
uchar rep1[255]; evbuffer_remove(reply_dest,rep1,255); /* yes, this is dirty */ @@ -589,8 +584,7 @@ test_socks_socks4_request_reply(void *data) state->parsereq.af = AF_UNSPEC; strcpy(state->parsereq.addr, fqdn);
- tt_int_op(1, ==, socks4_send_reply(reply_dest, - state, SOCKS4_FAILED)); + socks4_send_reply(reply_dest,state, SOCKS4_FAILED);
uchar rep2[255]; evbuffer_remove(reply_dest,rep2,255); diff --git a/src/util.c b/src/util.c index 7e3e747..cd7db2a 100644 --- a/src/util.c +++ b/src/util.c @@ -210,7 +210,7 @@ sev_is_valid(int severity) /** Sets the global logging 'method' and also sets and open the logfile 'filename' in case we want to log into a file. - It returns 1 on success and -1 on fail. + It returns 0 on success and -1 on fail. */ int log_set_method(int method, const char *filename) @@ -223,12 +223,12 @@ log_set_method(int method, const char *filename) if (write_logfile_prologue(logging_logfile) < 0) return -1; } - return 1; + return 0; }
/** Helper: Opens 'filename' and sets it as the obfsproxy logfile. - On success it returns 1, on fail it returns -1. + On success it returns 0, on fail it returns -1. */ static int open_and_set_obfsproxy_logfile(const char *filename) @@ -240,7 +240,7 @@ open_and_set_obfsproxy_logfile(const char *filename) 0644); if (logging_logfile < 0) return -1; - return 1; + return 0; }
/** @@ -260,6 +260,8 @@ close_obfsproxy_logfile(void) /** Writes a small prologue in the logfile 'fd' that mentions the obfsproxy version and helps separate log instances. + + Returns 0 on success, -1 on failure. */ static int write_logfile_prologue(int logfile) { @@ -268,7 +270,7 @@ write_logfile_prologue(int logfile) { return -1; if (write(logfile, buf, strlen(buf)) < 0) return -1; - return 1; + return 0; }
#define TEMP_PROLOGUE "\nBrand new obfsproxy log:\n" @@ -282,13 +284,13 @@ compose_logfile_prologue(char *buf, size_t buflen) log_warn("Logfile prologue couldn't be written."); return -1; } - return 1; + return 0; } #undef TEMP_PROLOGUE
/** Sets the minimum logging severity of obfsproxy to the severity - described by 'sev_string', then it returns 1. If 'sev_string' is + described by 'sev_string', then it returns 0. If 'sev_string' is not a valid severity, it returns -1. */ int @@ -299,7 +301,7 @@ log_set_min_severity(const char* sev_string) { return -1; } logging_min_sev = severity; - return 1; + return 0; }
/**
tor-commits@lists.torproject.org