use context service buffer instead of stack for clent_connect
authorAndy Green <andy.green@linaro.org>
Sun, 10 Feb 2013 07:34:59 +0000 (15:34 +0800)
committerAndy Green <andy.green@linaro.org>
Sun, 10 Feb 2013 16:34:43 +0000 (00:34 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client-handshake.c
lib/client.c
lib/server-handshake.c

index 1fc78f7..9292c03 100644 (file)
@@ -20,7 +20,7 @@ struct libwebsocket *__libwebsocket_client_connect_2(
         */
 
        if (context->http_proxy_port) {
-               plen = sprintf(context->service_buffer,
+               plen = sprintf((char *)context->service_buffer,
                        "CONNECT %s:%u HTTP/1.0\x0d\x0a"
                        "User-agent: libwebsockets\x0d\x0a"
 /*Proxy-authorization: basic aGVsbG86d29ybGQ= */
index 3461754..9c98059 100644 (file)
@@ -45,9 +45,6 @@ int lws_client_socket_service(struct libwebsocket_context *context, struct libwe
        char *p = (char *)&context->service_buffer[0];
        int len;
        char c;
-#ifdef LWS_OPENSSL_SUPPORT
-       char ssl_err_buf[512];
-#endif
 
        switch (wsi->mode) {
 
@@ -177,7 +174,7 @@ int lws_client_socket_service(struct libwebsocket_context *context, struct libwe
 
                                lwsl_err("SSL connect error %s\n",
                                        ERR_error_string(ERR_get_error(),
-                                                                 ssl_err_buf));
+                                               (char *)context->service_buffer));
                                return 0;
                        }
 
index 1fbe836..71007ec 100644 (file)
@@ -32,9 +32,6 @@
 int
 handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
 {
-       static const char *websocket_magic_guid_04 =
-                                        "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
-       char accept_buf[MAX_WEBSOCKET_04_KEY_LEN + 37];
        unsigned char hash[20];
        int n;
        char *response;
@@ -62,16 +59,16 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
                goto bail;
        }
 
-       strcpy(accept_buf, wsi->u.hdr.hdrs[WSI_TOKEN_KEY].token);
-       strcpy(accept_buf + wsi->u.hdr.hdrs[WSI_TOKEN_KEY].token_len,
-                                                      websocket_magic_guid_04);
+       n = snprintf((char *)context->service_buffer,
+               sizeof context->service_buffer,
+               "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
+               wsi->u.hdr.hdrs[WSI_TOKEN_KEY].token);
 
-       SHA1((unsigned char *)accept_buf,
-                       wsi->u.hdr.hdrs[WSI_TOKEN_KEY].token_len +
-                                        strlen(websocket_magic_guid_04), hash);
+       SHA1(context->service_buffer, n, hash);
 
-       accept_len = lws_b64_encode_string((char *)hash, 20, accept_buf,
-                                                            sizeof accept_buf);
+       accept_len = lws_b64_encode_string((char *)hash, 20,
+                       (char *)context->service_buffer,
+                       sizeof context->service_buffer);
        if (accept_len < 0) {
                lwsl_warn("Base64 encoded hash too long\n");
                goto bail;
@@ -100,7 +97,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
                      "Upgrade: WebSocket\x0d\x0a"
                      "Connection: Upgrade\x0d\x0a"
                      "Sec-WebSocket-Accept: ");
-       strcpy(p, accept_buf);
+       strcpy(p, (char *)context->service_buffer);
        p += accept_len;
 
        if (wsi->u.hdr.hdrs[WSI_TOKEN_PROTOCOL].token) {