protocol plugins set default

Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2016-05-06 14:24:59 +08:00
parent f4767497d3
commit f6585285cb
5 changed files with 48 additions and 8 deletions

View file

@ -146,7 +146,7 @@ Vhosts can select which plugins they want to offer and give them per-vhost setti
```
"ws-protocols": [{
"warmcat,timezoom": {
"warmcat-timezoom": {
"status": "ok"
}
}]
@ -157,6 +157,19 @@ The "x":"y" parameters like "status":"ok" are made available to the protocol dur
LWS_CALLBACK_PROTOCOL_INIT (@in is a pointer to a linked list of struct lws_protocol_vhost_options
containing the name and value pointers).
To indicate that a protocol should be used when no Protocol: header is sent
by the client, you can use "default": "1"
```
"ws-protocols": [{
"warmcat-timezoom": {
"status": "ok",
"default": "1"
}
}]
```
Other vhost options
-------------------

View file

@ -26,7 +26,8 @@ Fixes
.woff application/font-woff
.xml application/xml
5) Allow per-vhost setting of which protocol should get used
when the protocol: header is not sent by the client
v2.0.0

View file

@ -111,13 +111,15 @@ int
lws_protocol_init(struct lws_context *context)
{
struct lws_vhost *vh = context->vhost_list;
const struct lws_protocol_vhost_options *pvo;
const struct lws_protocol_vhost_options *pvo, *pvo1;
struct lws wsi;
int n;
memset(&wsi, 0, sizeof(wsi));
wsi.context = context;
lwsl_notice("%s\n", __func__);
while (vh) {
wsi.vhost = vh;
@ -128,12 +130,32 @@ lws_protocol_init(struct lws_context *context)
pvo = lws_vhost_protocol_options(vh,
vh->protocols[n].name);
if (pvo)
if (pvo) {
/*
* linked list of options specific to
* vh + protocol
*/
pvo = pvo->options;
pvo1 = pvo;
pvo = pvo1->options;
while (pvo) {
lwsl_notice(" vh %s prot %s opt %s\n",
vh->name,
vh->protocols[n].name,
pvo->name);
if (!strcmp(pvo->name, "default")) {
lwsl_notice("Setting default "
"protocol for vh %s to %s\n",
vh->name,
vh->protocols[n].name);
vh->default_protocol_index = n;
}
pvo = pvo->next;
}
pvo = pvo1->options;
}
/*
* inform all the protocols that they are doing their one-time

View file

@ -678,6 +678,7 @@ struct lws_vhost {
int allow_non_ssl_on_ssl_port;
unsigned int user_supplied_ssl_ctx:1;
#endif
unsigned char default_protocol_index;
};
/*

View file

@ -942,11 +942,14 @@ upgrade_ws:
/*
* some clients only have one protocol and
* do not send the protocol list header...
* allow it and match to protocol 0
* allow it and match to the vhost's default
* protocol (which itself defaults to zero)
*/
lwsl_info("defaulting to prot 0 handler\n");
lwsl_info("defaulting to prot handler %d\n",
wsi->vhost->default_protocol_index);
n = 0;
wsi->protocol = &wsi->vhost->protocols[0];
wsi->protocol = &wsi->vhost->protocols[
(int)wsi->vhost->default_protocol_index];
}
/* allocate wsi->user storage */