From e48ba315b8fd87957aa18f664d6ca166f46a9b2d Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 10 Feb 2013 15:34:59 +0800 Subject: [PATCH] use context service buffer instead of stack for clent_connect Signed-off-by: Andy Green --- lib/client-handshake.c | 2 +- lib/client.c | 5 +---- lib/server-handshake.c | 21 +++++++++------------ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 1fc78f7..9292c03 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -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= */ diff --git a/lib/client.c b/lib/client.c index 3461754..9c98059 100644 --- a/lib/client.c +++ b/lib/client.c @@ -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; } diff --git a/lib/server-handshake.c b/lib/server-handshake.c index 1fbe836..71007ec 100644 --- a/lib/server-handshake.c +++ b/lib/server-handshake.c @@ -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) { -- 2.7.4