[tor-commits] [obfsproxy/master] Aggressive removal of nested includes from header files. Potential not to compile on Windows.

nickm at torproject.org nickm at torproject.org
Thu Jul 14 16:28:32 UTC 2011


commit f3ebd94c1caa33f52775a585482431faadcb391d
Author: Zack Weinberg <zackw at panix.com>
Date:   Fri Jul 8 12:03:06 2011 -0700

    Aggressive removal of nested includes from header files.  Potential not to compile on Windows.
---
 src/network.c  |    9 ++++++---
 src/network.h  |   17 ++++-------------
 src/protocol.h |   20 ++++++++++----------
 src/socks.h    |   25 ++++++++++++-------------
 src/util.h     |    4 ++--
 5 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/src/network.c b/src/network.c
index ed78104..0faf136 100644
--- a/src/network.c
+++ b/src/network.c
@@ -10,10 +10,13 @@
 #include "socks.h"
 
 #include <assert.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <errno.h>
+#include <event2/buffer.h>
+#include <event2/bufferevent.h>
+#include <event2/listener.h>
 #include <event2/util.h>
 
 #ifdef _WIN32
@@ -43,7 +46,7 @@ static void output_event_cb(struct bufferevent *bev, short what, void *arg);
    This function sets up the protocol defined by 'options' and
    attempts to bind a new listener for it.
 
-   Returns the listener on success, NULL on fail. 
+   Returns the listener on success, NULL on fail.
 */
 listener_t *
 listener_new(struct event_base *base,
@@ -60,7 +63,7 @@ listener_new(struct event_base *base,
   }
 
   lsn->proto_params = proto_params;
-  
+
   lsn->listener = evconnlistener_new_bind(base, simple_listener_cb, lsn,
                                           flags,
                                           -1,
diff --git a/src/network.h b/src/network.h
index 2a1daeb..7bc4811 100644
--- a/src/network.h
+++ b/src/network.h
@@ -5,19 +5,7 @@
 #ifndef NETWORK_H
 #define NETWORK_H
 
-#include <stdlib.h>
-
-#include <event2/buffer.h>
-#include <event2/bufferevent.h>
-#include <event2/listener.h>
-#include <event2/event.h>
-
-
-typedef struct listener_t *listener;
-
-struct sockaddr;
 struct event_base;
-struct socks_state_t;
 struct protocol_params_t;
 
 #define LSN_SIMPLE_CLIENT 1
@@ -41,13 +29,16 @@ enum recv_ret {
 };
 
 typedef struct listener_t listener_t;
-struct addrinfo;
 
 listener_t *listener_new(struct event_base *base,
                          struct protocol_params_t *params);
 void listener_free(listener_t *listener);
 
 #ifdef NETWORK_PRIVATE
+struct bufferevent;
+struct socks_state_t;
+struct protocol_t;
+
 typedef struct conn_t {
   struct socks_state_t *socks_state;
   struct protocol_t *proto; /* ASN Do we like this here? We probably don't.
diff --git a/src/protocol.h b/src/protocol.h
index ceae438..483bae2 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -2,11 +2,11 @@
    See LICENSE for other credits and copying information
 */
 
-#include <event2/buffer.h>
-
 #ifndef PROTOCOL_H
 #define PROTOCOL_H
 
+#include <sys/socket.h> /* for sockaddr & sockaddr_storage - FIXME */
+
 struct evbuffer;
 struct listener_t;
 
@@ -15,7 +15,7 @@ struct listener_t;
 
 /**
   This struct defines parameters of the protocol per-listener basis.
-  
+
   By 'per-listener basis' I mean that the parameters defined here will
   be inherited by *all* connections opened from the listener_t that
   owns this protocol_params_t.
@@ -35,7 +35,7 @@ typedef struct protocol_params_t {
 struct protocol_t {
   /* protocol vtable */
   struct protocol_vtable *vtable;
-  
+
   /* This protocol specific struct defines the state of the protocol
      per-connection basis.
 
@@ -48,7 +48,7 @@ struct protocol_t {
   */
   void *state;
 };
-int set_up_protocol(int n_options, char **options, 
+int set_up_protocol(int n_options, char **options,
                     struct protocol_params_t *params);
 struct protocol_t *proto_new(struct protocol_params_t *params);
 void proto_destroy(struct protocol_t *proto);
@@ -58,16 +58,16 @@ enum recv_ret proto_recv(struct protocol_t *proto, void *source, void *dest);
 
 void proto_params_free(protocol_params_t *params);
 
-
 typedef struct protocol_vtable {
   /* Initialization function: Fills in the protocol vtable. */
-  int (*init)(int n_options, char **options, 
+  int (*init)(int n_options, char **options,
               struct protocol_params_t *params);
+
   /* Destructor: Destroys the protocol state.  */
   void (*destroy)(void *state);
 
   /* Constructor: Creates a protocol object. */
-  void *(*create)(struct protocol_t *proto_params, 
+  void *(*create)(struct protocol_t *proto_params,
                   struct protocol_params_t *parameters);
 
   /* does handshake. Not all protocols have a handshake. */
@@ -75,12 +75,12 @@ typedef struct protocol_vtable {
                    struct evbuffer *buf);
 
   /* send data function */
-  int (*send)(void *state, 
+  int (*send)(void *state,
               struct evbuffer *source,
               struct evbuffer *dest);
 
   /* receive data function */
-  enum recv_ret (*recv)(void *state, 
+  enum recv_ret (*recv)(void *state,
                         struct evbuffer *source,
                         struct evbuffer *dest);
 
diff --git a/src/socks.h b/src/socks.h
index 2f1e44b..ef7b953 100644
--- a/src/socks.h
+++ b/src/socks.h
@@ -5,14 +5,9 @@
 #ifndef SOCKS_H
 #define SOCKS_H
 
-#ifdef _WIN32
-#include <Winsock2.h>
-#else
-#include <netdb.h>
-#endif
-
 typedef struct socks_state_t socks_state_t;
 struct evbuffer;
+struct sockaddr;
 
 enum socks_status_t {
   /* Waiting for initial socks4 or socks5 message */
@@ -33,7 +28,8 @@ enum socks_ret {
 };
 
 enum socks_ret handle_socks(struct evbuffer *source,
-                             struct evbuffer *dest, socks_state_t *socks_state);
+                            struct evbuffer *dest,
+                            socks_state_t *socks_state);
 socks_state_t *socks_state_new(void);
 void socks_state_free(socks_state_t *s);
 
@@ -44,7 +40,7 @@ int socks_state_get_address(const socks_state_t *state,
                             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, 
+int socks5_send_reply(struct evbuffer *reply_dest,
                       socks_state_t *state, int status);
 
 
@@ -108,11 +104,14 @@ 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 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, 
+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);
-#endif
 
-#endif
+#endif /* SOCKS_PRIVATE */
+
+#endif /* socks.h */
diff --git a/src/util.h b/src/util.h
index ee04c85..90c55c2 100644
--- a/src/util.h
+++ b/src/util.h
@@ -5,8 +5,8 @@
 #ifndef UTIL_H
 #define UTIL_H
 
-/* va_list definition */
-#include <stdarg.h>
+#include <stdarg.h> /* for va_list */
+#include <stddef.h> /* for size_t etc */
 
 struct sockaddr_storage;
 struct event_base;





More information about the tor-commits mailing list