commit c6c6b1823ff1dd974431b3d4395d08f18b24b68b
parent 68d0523817537f46783aaf1bc61a10da2fc9af74
Author: Joris Vink <joris@coders.se>
Date: Sun, 21 Apr 2013 20:35:47 +0200
read next protocol properly and remember it for later.
Diffstat:
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -46,9 +46,14 @@ struct listener {
#define CONN_STATE_SSL_SHAKE 1
#define CONN_STATE_ESTABLISHED 2
+#define CONN_PROTO_UNKNOWN 0
+#define CONN_PROTO_SPDY 1
+#define CONN_PROTO_HTTP 2
+
struct connection {
int fd;
int state;
+ int proto;
struct sockaddr_in sin;
void *owner;
SSL *ssl;
diff --git a/src/kore.c b/src/kore.c
@@ -40,14 +40,13 @@
static int efd = -1;
static SSL_CTX *ssl_ctx = NULL;
+static int kore_socket_nonblock(int);
static int kore_server_sslstart(void);
-static int kore_server_bind(struct listener *, const char *, int);
+static void kore_event(int, int, void *);
static int kore_server_accept(struct listener *);
static int kore_connection_handle(struct connection *, int);
-static int kore_socket_nonblock(int);
-static void kore_event(int, int, void *);
-static int kore_ssl_npn_cb(SSL *, const unsigned char **,
- unsigned int *, void *);
+static int kore_server_bind(struct listener *, const char *, int);
+static int kore_ssl_npn_cb(SSL *, const u_char **, unsigned int *, void *);
int
main(int argc, char *argv[])
@@ -188,7 +187,9 @@ kore_server_accept(struct listener *l)
c->owner = l;
c->ssl = NULL;
+ c->proto = CONN_PROTO_UNKNOWN;
c->state = CONN_STATE_SSL_SHAKE;
+
TAILQ_INIT(&(c->send_queue));
TAILQ_INIT(&(c->recv_queue));
kore_event(c->fd, EPOLLIN | EPOLLET, c);
@@ -200,7 +201,9 @@ kore_server_accept(struct listener *l)
static int
kore_connection_handle(struct connection *c, int flags)
{
- int r;
+ int r;
+ u_int32_t len;
+ const u_char *data;
switch (c->state) {
case CONN_STATE_SSL_SHAKE:
@@ -233,6 +236,16 @@ kore_connection_handle(struct connection *c, int flags)
return (KORE_RESULT_ERROR);
}
+ SSL_get0_next_proto_negotiated(c->ssl, &data, &len);
+ if (data) {
+ if (!memcmp(data, "spdy/3", 6))
+ kore_log("using SPDY/3");
+ c->proto = CONN_PROTO_SPDY;
+ } else {
+ kore_log("using HTTP/1.1");
+ c->proto = CONN_PROTO_HTTP;
+ }
+
c->state = CONN_STATE_ESTABLISHED;
break;
case CONN_STATE_ESTABLISHED:
@@ -277,8 +290,7 @@ kore_event(int fd, int flags, void *udata)
}
static int
-kore_ssl_npn_cb(SSL *ssl, const unsigned char **data,
- unsigned int *len, void *arg)
+kore_ssl_npn_cb(SSL *ssl, const u_char **data, unsigned int *len, void *arg)
{
kore_log("npn callback: sending protocols");