commit 428802afc8d27a04dd322354b0bbc12d215bbea4
parent 4fd6d8a7a48421f3ca16eda65c7940be64448082
Author: Joris Vink <joris@coders.se>
Date: Mon, 30 Nov 2015 16:23:34 +0100
More cleanup after introducing NOHTTP=1.
* The cli tools must know when building as KORE_NO_HTTP.
* Reshuffle some structs around to avoid forward declarations.
* Move wscbs under !KORE_NO_HTTP as its for websockets.
* Remove unused members from struct connection.
Applications that use the connect callbacks for new connections
must now set the connection state themselves, see nohttp example.
Diffstat:
4 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/examples/nohttp/src/nohttp.c b/examples/nohttp/src/nohttp.c
@@ -40,6 +40,9 @@ connection_setup(struct connection *c)
* 128 bytes were read.
*/
net_recv_queue(c, 128, NETBUF_CALL_CB_ALWAYS, connection_recv_data);
+
+ /* We are responsible for setting the connection state. */
+ c->state = CONN_STATE_ESTABLISHED;
}
/*
diff --git a/includes/kore.h b/includes/kore.h
@@ -96,7 +96,6 @@ extern int daemon(int, int);
#if !defined(KORE_NO_HTTP)
struct http_request;
#endif
-struct connection;
struct netbuf {
u_int8_t *buf;
@@ -121,22 +120,6 @@ TAILQ_HEAD(netbuf_head, netbuf);
#define KORE_TYPE_PGSQL_CONN 3
#define KORE_TYPE_TASK 4
-struct listener {
- u_int8_t type;
- u_int8_t addrtype;
- int fd;
- void (*connect)(struct connection *);
-
- union {
- struct sockaddr_in ipv4;
- struct sockaddr_in6 ipv6;
- } addr;
-
- LIST_ENTRY(listener) list;
-};
-
-LIST_HEAD(listener_head, listener);
-
#define CONN_STATE_UNKNOWN 0
#define CONN_STATE_SSL_SHAKE 1
#define CONN_STATE_ESTABLISHED 2
@@ -181,7 +164,6 @@ struct connection {
u_int8_t flags;
void *hdlr_extra;
X509 *cert;
- void *wscbs;
int tls_reneg;
void (*disconnect)(struct connection *);
@@ -204,17 +186,33 @@ struct connection {
struct netbuf *rnb;
#if !defined(KORE_NO_HTTP)
+ void *wscbs;
TAILQ_HEAD(, http_request) http_requests;
#endif
TAILQ_ENTRY(connection) list;
- TAILQ_ENTRY(connection) flush_list;
};
TAILQ_HEAD(connection_list, connection);
extern struct connection_list connections;
extern struct connection_list disconnected;
+struct listener {
+ u_int8_t type;
+ u_int8_t addrtype;
+ int fd;
+ void (*connect)(struct connection *);
+
+ union {
+ struct sockaddr_in ipv4;
+ struct sockaddr_in6 ipv6;
+ } addr;
+
+ LIST_ENTRY(listener) list;
+};
+
+LIST_HEAD(listener_head, listener);
+
#if !defined(KORE_NO_HTTP)
struct kore_handler_params {
diff --git a/src/cli.c b/src/cli.c
@@ -917,6 +917,10 @@ cli_compile_cfile(void *arg)
args[idx++] = ppath;
#endif
+#if defined(KORE_NO_HTTP)
+ args[idx++] = "-DKORE_NO_HTTP";
+#endif
+
args[idx++] = "-Wall";
args[idx++] = "-Wmissing-declarations";
args[idx++] = "-Wshadow";
diff --git a/src/connection.c b/src/connection.c
@@ -50,7 +50,6 @@ kore_connection_new(void *owner)
c->rnb = NULL;
c->snb = NULL;
c->cert = NULL;
- c->wscbs = NULL;
c->owner = owner;
c->tls_reneg = 0;
c->disconnect = NULL;
@@ -61,6 +60,7 @@ kore_connection_new(void *owner)
c->idle_timer.length = KORE_IDLE_TIMER_MAX;
#if !defined(KORE_NO_HTTP)
+ c->wscbs = NULL;
TAILQ_INIT(&(c->http_requests));
#endif
@@ -265,8 +265,8 @@ kore_connection_handle(struct connection *c)
NETBUF_CALL_CB_ALWAYS, http_header_recv);
#endif
-tls_established:
c->state = CONN_STATE_ESTABLISHED;
+tls_established:
/* FALLTHROUGH */
#endif /* !KORE_NO_TLS */
case CONN_STATE_ESTABLISHED: