Subject: [PATCH] fixes for handling multiple protocols in handshake
authorRene Jager <rene.jager@gmail.com>
Tue, 28 Oct 2014 22:27:20 +0000 (23:27 +0100)
committerAndy Green <andy.green@linaro.org>
Wed, 29 Oct 2014 01:39:34 +0000 (09:39 +0800)
lib/client.c
lib/server-handshake.c
lib/server.c

index 9a00dc6..06d1a50 100755 (executable)
@@ -565,12 +565,12 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
                }
                while (*pc && *pc != ',')
                        pc++;
-               while (*pc && *pc != ' ')
+               while (*pc && *pc == ' ')
                        pc++;
        }
 
        if (!okay) {
-               lwsl_err("lws_client_int_s_hs: got bad protocol %s\n", p);
+               lwsl_err("lws_client_int_s_hs: got bad protocol '%s'\n", p);
                goto bail2;
        }
 
@@ -588,7 +588,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
        }
 
        if (wsi->protocol == NULL) {
-               lwsl_err("lws_client_int_s_hs: fail protocol %s\n", p);
+               lwsl_err("lws_client_int_s_hs: fail protocol '%s'\n", p);
                goto bail2;
        }
 
index 4c0fa73..8a15054 100644 (file)
@@ -217,10 +217,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
 
        if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL)) {
                LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: ");
-               n = lws_hdr_copy(wsi, p, 128, WSI_TOKEN_PROTOCOL);
-               if (n < 0)
-                       goto bail;
-               p += n;
+               LWS_CPYAPP(p, wsi->protocol->name);
        }
 
 #ifndef LWS_NO_EXTENSIONS
index f02e5de..88a1920 100644 (file)
@@ -428,9 +428,9 @@ upgrade_h2c:
                       "HTTP/1.1 101 Switching Protocols\x0d\x0a"
                      "Connection: Upgrade\x0d\x0a"
                      "Upgrade: h2c\x0d\x0a\x0d\x0a");
-               n = lws_issue_raw(wsi, (unsigned char *)protocol_list,
-                                       strlen(protocol_list));
-               if (n != strlen(protocol_list)) {
+               n = lws_issue_raw(wsi, (unsigned char *)wsi->protocol->name,
+                                       strlen(wsi->protocol->name));
+               if (n != strlen(wsi->protocol->name)) {
                        lwsl_debug("http2 switch: ERROR writing to socket\n");
                        return 1;
                }
@@ -471,6 +471,8 @@ upgrade_ws:
                        protocol_name[n] = '\0';
                        if (*p)
                                p++;
+                       while (*p == ' ')
+                               p++;
 
                        lwsl_info("checking %s\n", protocol_name);