[tor-commits] [obfsproxy/master] Kept argument parsing (set_up_protocol()) to main.c. We now just pass the protocol_params_t to listener_new().

nickm at torproject.org nickm at torproject.org
Thu Jun 9 21:05:16 UTC 2011


commit afa43eb36053c3f0a292d43cd282dba104fc9648
Author: George Kadianakis <desnacked at gmail.com>
Date:   Tue Jun 7 01:47:11 2011 +0200

    Kept argument parsing (set_up_protocol()) to main.c. We now just pass the protocol_params_t to listener_new().
---
 src/main.c    |   10 ++++++++--
 src/network.c |   13 +++++--------
 src/network.h |    3 ++-
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/main.c b/src/main.c
index f7d3d35..065e011 100644
--- a/src/main.c
+++ b/src/main.c
@@ -238,6 +238,7 @@ main(int argc, const char **argv)
   listener_t *listeners[actual_protocols];
   listener_t *temp_listener;
   int n_listeners=0;
+  protocol_params_t *proto_params;
   for (h=0;h<actual_protocols;h++) {
 
     if (n_protocols > 1) {
@@ -246,8 +247,13 @@ main(int argc, const char **argv)
            STUPID_BEAUTIFIER, h+1));
     }
 
-    temp_listener = listener_new(base, n_options_array[h], 
-                                 protocol_options[h]);
+    /** free'd in listener_free() */
+    proto_params = calloc(1, sizeof(protocol_params_t));
+    if (set_up_protocol(n_options_array[h],protocol_options[h],
+                        proto_params)<0)
+      continue;
+
+    temp_listener = listener_new(base, proto_params);
 
     /** Free the space allocated for this protocol's options. */
     free(protocol_options[h]);
diff --git a/src/network.c b/src/network.c
index c7dab85..3d64037 100644
--- a/src/network.c
+++ b/src/network.c
@@ -46,23 +46,20 @@ static void output_event_cb(struct bufferevent *bev, short what, void *arg);
 */
 listener_t *
 listener_new(struct event_base *base,
-             int n_options, char **options)
+             protocol_params_t *proto_params)
 {
   const unsigned flags =
     LEV_OPT_CLOSE_ON_FREE|LEV_OPT_CLOSE_ON_EXEC|LEV_OPT_REUSEABLE;
 
   listener_t *lsn = calloc(1, sizeof(listener_t));
-  if (!lsn)
+  if (!lsn) {
+    if (proto_params)
+      free(proto_params);
     return NULL;
+  }
 
-  protocol_params_t *proto_params = calloc(1, sizeof(protocol_params_t));
   lsn->proto_params = proto_params;
   
-  if (set_up_protocol(n_options,options,lsn->proto_params)<0) {
-    listener_free(lsn);
-    return NULL;
-  }
-
   lsn->listener = evconnlistener_new_bind(base, simple_listener_cb, lsn,
                                           flags,
                                           -1,
diff --git a/src/network.h b/src/network.h
index 5537680..120af80 100644
--- a/src/network.h
+++ b/src/network.h
@@ -21,6 +21,7 @@ typedef struct listener_t *listener;
 struct sockaddr;
 struct event_base;
 struct socks_state_t;
+struct protocol_params_t;
 
 #define LSN_SIMPLE_CLIENT 1
 #define LSN_SIMPLE_SERVER 2
@@ -30,7 +31,7 @@ typedef struct listener_t listener_t;
 struct addrinfo;
 
 listener_t *listener_new(struct event_base *base,
-                         int n_options, char **options);
+                         struct protocol_params_t *params);
 void listener_free(listener_t *listener);
 
 #ifdef NETWORK_PRIVATE





More information about the tor-commits mailing list