From 1553d3c13653eba89ddae727137ab1b0a046dfe7 Mon Sep 17 00:00:00 2001 From: Sam Dodrill Date: Sun, 24 Nov 2013 13:41:39 -0800 Subject: [PATCH] Add first parts of websocket support This commit adapted from: https://github.com/ahf/ircd-ratbox/commit/2703ca0b42769a1b0c707126f19f4ef6fb7d3bd1 --- include/client.h | 5 +++++ include/listener.h | 3 ++- src/listener.c | 10 ++++++++-- src/messages.tab | 2 +- src/newconf.c | 26 ++++++++++++++++++++------ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/client.h b/include/client.h index 0e9ae53..e9c1af1 100644 --- a/include/client.h +++ b/include/client.h @@ -409,6 +409,7 @@ struct ListClient #define LFLAGS_SSL 0x00000001 #define LFLAGS_FLUSH 0x00000002 #define LFLAGS_CORK 0x00000004 +#define LFLAGS_WEBSOCKET 0x00000008 /* umodes, settable flags */ /* lots of this moved to snomask -- jilles */ @@ -495,6 +496,10 @@ struct ListClient #define SetSSL(x) ((x)->localClient->localflags |= LFLAGS_SSL) #define ClearSSL(x) ((x)->localClient->localflags &= ~LFLAGS_SSL) +#define IsWebSocket(x) ((x)->localClient->localflags & LFLAGS_WEBSOCKET) +#define SetWebSocket(x) ((x)->localClient->localflags |= LFLAGS_WEBSOCKET) +#define ClearWebSocket(x) ((x)->localClient->localflags &= ~LFLAGS_WEBSOCKET) + #define IsFlush(x) ((x)->localClient->localflags & LFLAGS_FLUSH) #define SetFlush(x) ((x)->localClient->localflags |= LFLAGS_FLUSH) #define ClearFlush(x) ((x)->localClient->localflags &= ~LFLAGS_FLUSH) diff --git a/include/listener.h b/include/listener.h index 8a37db9..69a2457 100644 --- a/include/listener.h +++ b/include/listener.h @@ -38,13 +38,14 @@ struct Listener int ref_count; /* number of connection references */ int active; /* current state of listener */ int ssl; /* ssl listener */ + int websocket; /* websocket listener */ int defer_accept; /* use TCP_DEFER_ACCEPT */ struct rb_sockaddr_storage addr; struct DNSQuery *dns_query; char vhost[HOSTLEN + 1]; /* virtual name of listener */ }; -extern void add_listener(int port, const char *vaddr_ip, int family, int ssl, int defer_accept); +extern void add_listener(int port, const char *vaddr_ip, int family, int ssl, int websocket, int defer_accept); extern void close_listener(struct Listener *listener); extern void close_listeners(void); extern const char *get_listener_name(const struct Listener *listener); diff --git a/src/listener.c b/src/listener.c index a781f60..469455e 100644 --- a/src/listener.c +++ b/src/listener.c @@ -146,7 +146,8 @@ show_ports(struct Client *source_p) #endif IsOperAdmin(source_p) ? listener->name : me.name, listener->ref_count, (listener->active) ? "active" : "disabled", - listener->ssl ? " ssl" : ""); + listener->ssl ? " ssl" : "", + listener->websocket ? " websocket" : ""); } } @@ -303,7 +304,8 @@ find_listener(struct rb_sockaddr_storage *addr) * the format "255.255.255.255" */ void -add_listener(int port, const char *vhost_ip, int family, int ssl, int defer_accept) +add_listener(int port, const char *vhost_ip, int family, int ssl, int websocket, + int defer_accept) { struct Listener *listener; struct rb_sockaddr_storage vaddr; @@ -376,6 +378,7 @@ add_listener(int port, const char *vhost_ip, int family, int ssl, int defer_acce listener->F = NULL; listener->ssl = ssl; + listener->websocket = websocket; listener->defer_accept = defer_accept; if(inetport(listener)) @@ -465,6 +468,9 @@ add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, str if(ssl_ctl != NULL || rb_fd_ssl(F)) SetSSL(new_client); + if (listener->websocket) + SetWebSocket(new_client); + ++listener->ref_count; start_auth(new_client); diff --git a/src/messages.tab b/src/messages.tab index 8c97439..8bb53eb 100644 --- a/src/messages.tab +++ b/src/messages.tab @@ -240,7 +240,7 @@ static const char * replies[] = { /* 217 RPL_STATSQLINE, */ "%c %d %s :%s", /* 218 RPL_STATSYLINE, */ "Y %s %d %d %d %u %d.%d %d.%d %u", /* 219 RPL_ENDOFSTATS, */ "%c :End of /STATS report", -/* 220 RPL_STATSPLINE, */ "%c %d %s %d :%s%s", +/* 220 RPL_STATSPLINE, */ "%c %d %s %d :%s%s%s", /* 221 RPL_UMODEIS, */ "%s", /* 222 */ NULL, /* 223 */ NULL, diff --git a/src/newconf.c b/src/newconf.c index 1ebc287..322a7ea 100644 --- a/src/newconf.c +++ b/src/newconf.c @@ -883,7 +883,7 @@ conf_set_listen_defer_accept(void *data) } static void -conf_set_listen_port_both(void *data, int ssl) +conf_set_listen_port_both(void *data, int ssl, int websocket) { conf_parm_t *args = data; for (; args; args = args->next) @@ -896,9 +896,9 @@ conf_set_listen_port_both(void *data, int ssl) } if(listener_address == NULL) { - add_listener(args->v.number, listener_address, AF_INET, ssl, yy_defer_accept); + add_listener(args->v.number, listener_address, AF_INET, ssl, websocket, yy_defer_accept); #ifdef RB_IPV6 - add_listener(args->v.number, listener_address, AF_INET6, ssl, yy_defer_accept); + add_listener(args->v.number, listener_address, AF_INET6, ssl, websocket, yy_defer_accept); #endif } else @@ -911,7 +911,7 @@ conf_set_listen_port_both(void *data, int ssl) #endif family = AF_INET; - add_listener(args->v.number, listener_address, family, ssl, yy_defer_accept); + add_listener(args->v.number, listener_address, family, ssl, websocket, yy_defer_accept); } @@ -921,13 +921,25 @@ conf_set_listen_port_both(void *data, int ssl) static void conf_set_listen_port(void *data) { - conf_set_listen_port_both(data, 0); + conf_set_listen_port_both(data, /* ssl */ 0, /* websocket */ 0); } static void conf_set_listen_sslport(void *data) { - conf_set_listen_port_both(data, 1); + conf_set_listen_port_both(data, /* ssl */ 1, /* websocket */ 0); +} + +static void +conf_set_listen_websocketport(void *data) +{ + conf_set_listen_port_both(data, /* ssl */ 0, /* websocket */ 1); +} + +static void +conf_set_listen_websocketsslport(void *data) +{ + conf_set_listen_port_both(data, /* ssl */ 1, /* websocket */ 1); } static void @@ -2411,6 +2423,8 @@ newconf_init() add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept); add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port); add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport); + add_conf_item("listen", "websocketport", CF_INT | CF_FLIST, conf_set_listen_websocketport); + add_conf_item("listen", "websocketsslport", CF_INT | CF_FLIST, conf_set_listen_websocketsslport); add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address); add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);