[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Replaced dbg/printf with log_* functions.



commit 4a339aa90d778b6beec85119058ada5fd8f53bd9
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Thu Jun 9 23:25:18 2011 +0200

    Replaced dbg/printf with log_* functions.
---
 src/network.c         |   22 +++++++++++-----------
 src/protocols/dummy.c |    2 +-
 src/protocols/obfs2.c |   27 ++++++++++++++-------------
 src/socks.c           |   24 ++++++++++++------------
 4 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/src/network.c b/src/network.c
index 76c4ef2..f2410ce 100644
--- a/src/network.c
+++ b/src/network.c
@@ -67,6 +67,7 @@ listener_new(struct event_base *base,
                                           lsn->proto_params->on_address_len);
 
   if (!lsn->listener) {
+    log_warn("Failed to create listener!");
     listener_free(lsn);
     return NULL;
   }
@@ -95,13 +96,13 @@ simple_listener_cb(struct evconnlistener *evcl,
   if (!conn)
     goto err;
 
-  dbg(("Got a connection\n"));
+  log_debug("Got a connection");
 
   conn->mode = lsn->proto_params->mode;
 
   conn->proto = proto_new(lsn->proto_params);
   if (!conn->proto) {
-    printf("Creation of protocol object failed! Closing connection.\n");
+    log_warn("Creation of protocol object failed! Closing connection.");
     goto err;
   }
 
@@ -209,7 +210,6 @@ socks_read_cb(struct bufferevent *bev, void *arg)
   enum socks_ret socks_ret;
   assert(bev == conn->input); /* socks must be on the initial bufferevent */
 
-  //dbg(("Got data on the socks side (%d) \n", conn->socks_state->state));
 
   do {
     enum socks_status_t status = socks_state_get_status(conn->socks_state);
@@ -225,7 +225,7 @@ socks_read_cb(struct bufferevent *bev, void *arg)
                                               get_evdns_base(),
                                               af, addr, port);
       bufferevent_enable(conn->output, EV_READ|EV_WRITE);
-      dbg(("socket_connect_hostname said %d! (%s,%d)\n", r, addr, port));
+      log_debug("socket_connect_hostname said %d! (%s,%d)", r, addr, port);
 
       if (r < 0) {
         /* XXXX send socks reply */
@@ -263,7 +263,7 @@ plaintext_read_cb(struct bufferevent *bev, void *arg)
   struct bufferevent *other;
   other = (bev == conn->input) ? conn->output : conn->input;
 
-  dbg(("Got data on plaintext side\n"));
+  log_debug("Got data on plaintext side");
   if (proto_send(conn->proto,
                  bufferevent_get_input(bev),
                  bufferevent_get_output(other)) < 0)
@@ -278,7 +278,7 @@ obfuscated_read_cb(struct bufferevent *bev, void *arg)
   other = (bev == conn->input) ? conn->output : conn->input;
   enum recv_ret r;
 
-  dbg(("Got data on encrypted side\n"));
+  log_debug("Got data on encrypted side");
   r = proto_recv(conn->proto,
                  bufferevent_get_input(bev),
                  bufferevent_get_output(other));
@@ -295,7 +295,7 @@ static void
 error_or_eof(conn_t *conn,
              struct bufferevent *bev_err, struct bufferevent *bev_flush)
 {
-  dbg(("error_or_eof\n"));
+  log_debug("error_or_eof");
 
   if (conn->flushing || ! conn->is_open ||
       0 == evbuffer_get_length(bufferevent_get_output(bev_flush))) {
@@ -321,7 +321,7 @@ input_event_cb(struct bufferevent *bev, short what, void *arg)
   assert(bev == conn->input);
 
   if (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
-    printf("Got error: %s\n",
+    log_warn("Got error: %s",
            evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
     error_or_eof(conn, bev, conn->output);
   }
@@ -345,7 +345,7 @@ output_event_cb(struct bufferevent *bev, short what, void *arg)
     if ((conn->mode == LSN_SOCKS_CLIENT) && 
         (conn->socks_state) &&
         (socks_state_get_status(conn->socks_state) == ST_HAVE_ADDR)) {
-      dbg(("Connection failed\n"));
+      log_debug("Connection failed") ;
       /* Enable EV_WRITE so that we can send the response.
          Disable EV_READ so that we don't get more stuff from the client. */
       bufferevent_enable(conn->input, EV_WRITE);
@@ -364,7 +364,7 @@ output_event_cb(struct bufferevent *bev, short what, void *arg)
      this connection soon.
   */
   if (conn->flushing || (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR))) {
-    printf("Got error: %s\n",
+    log_warn("Got error: %s",
            evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
     error_or_eof(conn, bev, conn->input);
     return;
@@ -380,7 +380,7 @@ output_event_cb(struct bufferevent *bev, short what, void *arg)
   if (what & BEV_EVENT_CONNECTED) {
     /* woo, we're connected.  Now the input buffer can start reading. */
     conn->is_open = 1;
-    dbg(("Connection done\n"));
+    log_debug("Connection done") ;
     bufferevent_enable(conn->input, EV_READ|EV_WRITE);
     if (conn->mode == LSN_SOCKS_CLIENT) {
       struct sockaddr_storage ss;
diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c
index 71b3313..bbda22f 100644
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@ -81,7 +81,7 @@ parse_and_set_options(int n_options, char **options,
 
   if (resolve_address_port(options[2], 1, 1, 
                            &ss_listen, &sl_listen, defport) < 0) {
-    printf("addr\n");
+    log_warn("addr");
     return -1;
   }
   assert(sl_listen <= sizeof(struct sockaddr_storage));
diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c
index edfc365..b24bf05 100644
--- a/src/protocols/obfs2.c
+++ b/src/protocols/obfs2.c
@@ -25,7 +25,7 @@
 static void obfs2_state_free(void *state);
 static int obfs2_send_initial_message(void *state, struct evbuffer *buf);
 static int obfs2_send(void *state,
-               struct evbuffer *source, struct evbuffer *dest);
+                      struct evbuffer *source, struct evbuffer *dest);
 static enum recv_ret obfs2_recv(void *state, struct evbuffer *source,
                                 struct evbuffer *dest);
 static void *obfs2_state_new(protocol_params_t *params); 
@@ -75,7 +75,7 @@ parse_and_set_options(int n_options, char **options,
   const char* defport;
 
   if ((n_options < 3) || (n_options > 5)) {
-    printf("wrong options number: %d\n", n_options);
+    log_warn("%s(): wrong options number: %d", __func__, n_options);
     return -1;
   }
 
@@ -107,7 +107,7 @@ parse_and_set_options(int n_options, char **options,
         params->shared_secret_len = strlen(*options+16);
         got_ss=1;
       } else {
-        printf("Unknown argument.\n");
+        log_warn("%s(): Unknown argument.", __func__);
         return -1;
       }
       options++;
@@ -123,7 +123,7 @@ parse_and_set_options(int n_options, char **options,
       defport = "11253"; /* 2bf5 */
       params->mode = LSN_SIMPLE_SERVER;
     } else {
-      printf("only client/socks/server modes supported.\n");
+      log_warn("%s(): only client/socks/server modes supported.", __func__);
       return -1;
     }
     options++;
@@ -141,15 +141,16 @@ parse_and_set_options(int n_options, char **options,
 
     /* Validate option selection. */
     if (got_dest && (params->mode == LSN_SOCKS_CLIENT)) {
-      printf("You can't be on socks mode and have --dest.\n");
+      log_warn("%s(): You can't be on socks mode and have --dest.", __func__);
       return -1;
     }
 
     if (!got_dest && (params->mode != LSN_SOCKS_CLIENT)) {
-      printf("client/server mode needs --dest.\n");
+      log_warn("%s(): client/server mode needs --dest.", __func__);
       return -1;
     }
 
+    log_debug("%s(): Parsed obfs2 options nicely!", __func__);
     return 1;
 }
 
@@ -159,7 +160,7 @@ parse_and_set_options(int n_options, char **options,
 static void
 usage(void)
 {
-  printf("You failed at creating an understandable command.\n"
+  printf("You failed at creating a correct obfs2 line.\n"
          "obfs2 syntax:\n"
          "\tobfs2 [obfs2_args] obfs2_opts\n"
          "\t'obfs2_opts':\n"
@@ -430,7 +431,7 @@ crypt_and_transmit(crypt_t *crypto,
       return 0;
     stream_crypt(crypto, data, n);
     evbuffer_add(dest, data, n);
-    dbg(("Processed %d bytes.", n));
+    log_debug("%s(): Processed %d bytes.", __func__, n);
   }
 }
 
@@ -563,7 +564,7 @@ obfs2_recv(void *s, struct evbuffer *source,
 
     /* Fall through here: if there is padding data waiting on the buffer, pull
        it off immediately. */
-    dbg(("Received key, expecting %d bytes of padding\n", plength));
+    log_debug("%s(): Received key, expecting %d bytes of padding", __func__, plength);
   }
 
   /* If we have pending data to send, we set the return code
@@ -583,15 +584,15 @@ obfs2_recv(void *s, struct evbuffer *source,
       n = evbuffer_get_length(source);
     evbuffer_drain(source, n);
     state->padding_left_to_read -= n;
-    dbg(("Received %d bytes of padding; %d left to read\n", n,
-         state->padding_left_to_read));
+    log_debug("%s(): Received %d bytes of padding; %d left to read", 
+              __func__, n, state->padding_left_to_read);
   }
 
   /* Okay; now we're definitely open.  Process whatever data we have. */
   state->state = ST_OPEN;
 
-  dbg(("Processing %d bytes data onto destination buffer\n",
-       (int) evbuffer_get_length(source)));
+  log_debug("%s(): Processing %d bytes data onto destination buffer",
+            __func__, (int) evbuffer_get_length(source));
   crypt_and_transmit(state->recv_crypto, source, dest);
 
   if (r != RECV_SEND_PENDING)
diff --git a/src/socks.c b/src/socks.c
index 6266503..626ba88 100644
--- a/src/socks.c
+++ b/src/socks.c
@@ -129,7 +129,7 @@ socks5_handle_request(struct evbuffer *source, struct parsereq *parsereq)
   unsigned int buflength = evbuffer_get_length(source);
 
   if (buflength < SIZEOF_SOCKS5_STATIC_REQ+1) {
-    printf("socks: request packet is too small (1).\n");
+    log_debug("socks: request packet is too small (1).");
     return SOCKS_INCOMPLETE;
   }
 
@@ -144,7 +144,7 @@ socks5_handle_request(struct evbuffer *source, struct parsereq *parsereq)
      p[1] = Command field
      p[2] = Reserved field */
   if (p[0] != SOCKS5_VERSION || p[2] != 0x00) {
-    printf("socks: Corrupted packet. Discarding.\n");
+    log_debug("socks: Corrupted packet. Discarding.");
     goto err;
   }
 
@@ -171,13 +171,13 @@ socks5_handle_request(struct evbuffer *source, struct parsereq *parsereq)
     /* as above, but we also have the addrlen field byte */
     break;
   default:
-    printf("socks: Address type not supported. Go away.\n");
+    log_debug("socks: Address type not supported. Go away.");
     goto err;
   }
 
   int minsize = SIZEOF_SOCKS5_STATIC_REQ + addrlen + extralen + 2;
   if (buflength < minsize) {
-    printf("socks: request packet too small %d:%d (2)\n", buflength, minsize);
+    log_debug("socks: request packet too small %d:%d (2)", buflength, minsize);
     return SOCKS_INCOMPLETE;
   }
 
@@ -304,7 +304,7 @@ socks5_handle_negotiation(struct evbuffer *source,
   /* XXX user controlled malloc(). range should be: 0x00-0xff */
   p = malloc(nmethods);
   if (!p) {
-    printf("malloc failed!\n");
+    log_warn("malloc failed!");
     return SOCKS_BROKEN;
   }
   if (evbuffer_remove(source, p, nmethods) < 0)
@@ -368,7 +368,7 @@ socks4_read_request(struct evbuffer *source, socks_state_t *state)
     return SOCKS_INCOMPLETE; /* more bytes needed */
   evbuffer_copyout(source, (char*)header, 7);
   if (header[0] != 1) {
-    printf("socks: Only CONNECT supported.\n");
+    log_debug("socks: Only CONNECT supported.");
     return SOCKS_BROKEN;
   }
   memcpy(&portnum, header+1, 2);
@@ -398,7 +398,7 @@ socks4_read_request(struct evbuffer *source, socks_state_t *state)
     }
     hostname_len = end_of_hostname.pos - end_of_user.pos - 1;
     if (hostname_len >= sizeof(state->parsereq.addr)) {
-      printf("socks4a: Hostname too long\n");
+      log_debug("socks4a: Hostname too long");
       return SOCKS_BROKEN;
     }
   }
@@ -461,7 +461,7 @@ handle_socks(struct evbuffer *source, struct evbuffer *dest,
     return SOCKS_BROKEN;
 
   if (evbuffer_get_length(source) < MIN_SOCKS_PACKET) {
-    printf("socks: Packet is too small.\n");
+    log_debug("socks: Packet is too small.");
     return SOCKS_INCOMPLETE;
   }
 
@@ -474,10 +474,10 @@ handle_socks(struct evbuffer *source, struct evbuffer *dest,
     evbuffer_remove(source, &socks_state->version, 1);
     if (socks_state->version != SOCKS5_VERSION &&
         socks_state->version != SOCKS4_VERSION) {
-      printf("socks: unexpected version %d", (int)socks_state->version);
+      log_debug("socks: unexpected version %d", (int)socks_state->version);
       goto broken;
     }
-    dbg(("Got version %d\n",(int)socks_state->version));
+    log_debug("Got version %d",(int)socks_state->version);
   }
 
   switch(socks_state->version) {
@@ -560,7 +560,7 @@ socks_state_set_address(socks_state_t *state, const struct sockaddr *sa)
       return -1;
   } else if (sa->sa_family == AF_INET6) {
     if (state->version == 4) {
-      printf("Oops; socks4 doesn't allow ipv6 addresses\n");
+      log_debug("Oops; socks4 doesn't allow ipv6 addresses");
       return -1;
     }
     const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
@@ -568,7 +568,7 @@ socks_state_set_address(socks_state_t *state, const struct sockaddr *sa)
     if (evutil_inet_ntop(AF_INET6, &sin6->sin6_addr, state->parsereq.addr, sizeof(state->parsereq.addr)) == NULL)
       return -1;
   } else {
-    printf("Unknown address family %d\n", sa->sa_family);
+    log_debug("Unknown address family %d", sa->sa_family);
     return -1;
   }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits