updated spec enabled ssl
[profile/ivi/libwebsockets.git] / lib / client.c
index aa70bfe..3da9326 100644 (file)
@@ -101,7 +101,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
                /* external POLL support via protocol 0 */
                context->protocols[0].callback(context, wsi,
                        LWS_CALLBACK_CLEAR_MODE_POLL_FD,
-                       (void *)(long)wsi->sock, NULL, POLLOUT);
+                       wsi->user_space, (void *)(long)wsi->sock, POLLOUT);
 
                /* we can retry this... just cook the SSL BIO the first time */
 
@@ -179,7 +179,8 @@ int lws_client_socket_service(struct libwebsocket_context *context,
                                 * run into the connection timeout or win
                                 */
 
-                               lwsl_err("SSL connect error %s\n",
+                               lwsl_err("SSL connect error %lu: %s\n", 
+                                       ERR_get_error(),
                                        ERR_error_string(ERR_get_error(),
                                              (char *)context->service_buffer));
                                return 0;
@@ -589,15 +590,14 @@ check_accept:
         */
 
        p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_ACCEPT);
-       if (strcmp(p, wsi->u.hdr.initial_handshake_hash_base64)) {
+       if (strcmp(p, wsi->u.hdr.ah->initial_handshake_hash_base64)) {
                lwsl_warn("lws_client_int_s_hs: accept %s wrong vs %s\n", p,
-                                     wsi->u.hdr.initial_handshake_hash_base64);
+                                 wsi->u.hdr.ah->initial_handshake_hash_base64);
                goto bail2;
        }
 
        /* allocate the per-connection user memory (if any) */
-       if (wsi->protocol->per_session_data_size &&
-                                        !libwebsocket_ensure_user_space(wsi)) {
+       if (libwebsocket_ensure_user_space(wsi)) {
                lwsl_err("Problem allocating wsi user mem\n");
                goto bail2;
        }
@@ -710,8 +710,6 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
        struct libwebsocket_extension *ext1;
        int ext_count = 0;
 #endif
-       static const char magic_websocket_guid[] =
-                                        "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
 
        /*
         * create the random key
@@ -841,13 +839,14 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
 
        /* prepare the expected server accept response */
 
-       n = snprintf(buf, sizeof(buf), "%s%s", key_b64, magic_websocket_guid);
-       buf[sizeof(buf) - 1] = '\0';
+       key_b64[39] = '\0'; /* enforce composed length below buf sizeof */
+       n = sprintf(buf, "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11", key_b64);
+
        SHA1((unsigned char *)buf, n, (unsigned char *)hash);
 
        lws_b64_encode_string(hash, 20,
-                       wsi->u.hdr.initial_handshake_hash_base64,
-                            sizeof(wsi->u.hdr.initial_handshake_hash_base64));
+                       wsi->u.hdr.ah->initial_handshake_hash_base64,
+                         sizeof(wsi->u.hdr.ah->initial_handshake_hash_base64));
 
        return p;
 }