Add first parts of websocket support

This commit adapted from:
    2703ca0b42
This commit is contained in:
Sam Dodrill 2013-11-24 13:41:39 -08:00
parent be2a7a772c
commit 1553d3c136
5 changed files with 36 additions and 10 deletions

View File

@ -409,6 +409,7 @@ struct ListClient
#define LFLAGS_SSL 0x00000001 #define LFLAGS_SSL 0x00000001
#define LFLAGS_FLUSH 0x00000002 #define LFLAGS_FLUSH 0x00000002
#define LFLAGS_CORK 0x00000004 #define LFLAGS_CORK 0x00000004
#define LFLAGS_WEBSOCKET 0x00000008
/* umodes, settable flags */ /* umodes, settable flags */
/* lots of this moved to snomask -- jilles */ /* lots of this moved to snomask -- jilles */
@ -495,6 +496,10 @@ struct ListClient
#define SetSSL(x) ((x)->localClient->localflags |= LFLAGS_SSL) #define SetSSL(x) ((x)->localClient->localflags |= LFLAGS_SSL)
#define ClearSSL(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 IsFlush(x) ((x)->localClient->localflags & LFLAGS_FLUSH)
#define SetFlush(x) ((x)->localClient->localflags |= LFLAGS_FLUSH) #define SetFlush(x) ((x)->localClient->localflags |= LFLAGS_FLUSH)
#define ClearFlush(x) ((x)->localClient->localflags &= ~LFLAGS_FLUSH) #define ClearFlush(x) ((x)->localClient->localflags &= ~LFLAGS_FLUSH)

View File

@ -38,13 +38,14 @@ struct Listener
int ref_count; /* number of connection references */ int ref_count; /* number of connection references */
int active; /* current state of listener */ int active; /* current state of listener */
int ssl; /* ssl listener */ int ssl; /* ssl listener */
int websocket; /* websocket listener */
int defer_accept; /* use TCP_DEFER_ACCEPT */ int defer_accept; /* use TCP_DEFER_ACCEPT */
struct rb_sockaddr_storage addr; struct rb_sockaddr_storage addr;
struct DNSQuery *dns_query; struct DNSQuery *dns_query;
char vhost[HOSTLEN + 1]; /* virtual name of listener */ 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_listener(struct Listener *listener);
extern void close_listeners(void); extern void close_listeners(void);
extern const char *get_listener_name(const struct Listener *listener); extern const char *get_listener_name(const struct Listener *listener);

View File

@ -146,7 +146,8 @@ show_ports(struct Client *source_p)
#endif #endif
IsOperAdmin(source_p) ? listener->name : me.name, IsOperAdmin(source_p) ? listener->name : me.name,
listener->ref_count, (listener->active) ? "active" : "disabled", 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" * the format "255.255.255.255"
*/ */
void 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 Listener *listener;
struct rb_sockaddr_storage vaddr; 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->F = NULL;
listener->ssl = ssl; listener->ssl = ssl;
listener->websocket = websocket;
listener->defer_accept = defer_accept; listener->defer_accept = defer_accept;
if(inetport(listener)) 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)) if(ssl_ctl != NULL || rb_fd_ssl(F))
SetSSL(new_client); SetSSL(new_client);
if (listener->websocket)
SetWebSocket(new_client);
++listener->ref_count; ++listener->ref_count;
start_auth(new_client); start_auth(new_client);

View File

@ -240,7 +240,7 @@ static const char * replies[] = {
/* 217 RPL_STATSQLINE, */ "%c %d %s :%s", /* 217 RPL_STATSQLINE, */ "%c %d %s :%s",
/* 218 RPL_STATSYLINE, */ "Y %s %d %d %d %u %d.%d %d.%d %u", /* 218 RPL_STATSYLINE, */ "Y %s %d %d %d %u %d.%d %d.%d %u",
/* 219 RPL_ENDOFSTATS, */ "%c :End of /STATS report", /* 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", /* 221 RPL_UMODEIS, */ "%s",
/* 222 */ NULL, /* 222 */ NULL,
/* 223 */ NULL, /* 223 */ NULL,

View File

@ -883,7 +883,7 @@ conf_set_listen_defer_accept(void *data)
} }
static void 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; conf_parm_t *args = data;
for (; args; args = args->next) for (; args; args = args->next)
@ -896,9 +896,9 @@ conf_set_listen_port_both(void *data, int ssl)
} }
if(listener_address == NULL) 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 #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 #endif
} }
else else
@ -911,7 +911,7 @@ conf_set_listen_port_both(void *data, int ssl)
#endif #endif
family = AF_INET; 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 static void
conf_set_listen_port(void *data) 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 static void
conf_set_listen_sslport(void *data) 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 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", "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", "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", "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", "ip", CF_QSTRING, conf_set_listen_address);
add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address); add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);