protocol plugins set default
authorAndy Green <andy@warmcat.com>
Fri, 6 May 2016 06:42:37 +0000 (14:42 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 6 May 2016 06:42:37 +0000 (14:42 +0800)
Signed-off-by: Andy Green <andy@warmcat.com>
README.lwsws.md
changelog
lib/context.c
lib/private-libwebsockets.h
lib/server.c

index 63b026686ecb7ba24fd91cefc23081a2627bc49b..9d6c82a3bb993a2ff203f594e41a3792e7804648 100644 (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
 -------------------
index 0d06acc72d2678aca20180969877b1a2a57ed4ea..e9132c5db77027274e10ebea7306c20fd464186d 100644 (file)
--- a/changelog
+++ b/changelog
@@ -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
index 23d218d02fbdbf6d70b99dc55b80ad85c9005596..8c0a69be97e0abe79229ac65329dd3e7f051d5c6 100644 (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
index cb1976be9905c7c304b63d50bd9f29ecad2cee8a..4ed08953a021c91bef43ff988017d21f7660c063 100644 (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;
 };
 
 /*
index 0e06cfa413c293430732e436b03b119d437561a5..1343a243735d718c6048c39cbc3ed1f8a35571f7 100644 (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 */