diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 84b744f0..f8d0b692 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -358,3 +358,45 @@ bail1: return NULL; } + + +/** + * libwebsocket_client_connect_extended() - Connect to another websocket server + * @context: Websocket context + * @address: Remote server address, eg, "myserver.com" + * @port: Port to connect to on the remote server, eg, 80 + * @ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self + * signed certs + * @path: Websocket path on server + * @host: Hostname on server + * @origin: Socket origin name + * @protocol: Comma-separated list of protocols being asked for from + * the server, or just one. The server will pick the one it + * likes best. + * @ietf_version_or_minus_one: -1 to ask to connect using the default, latest + * protocol supported, or the specific protocol ordinal + * @userdata: Pre-allocated user data + * + * This function creates a connection to a remote server + */ + +struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *context, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, + void *userdata) +{ + struct libwebsocket *ws = + libwebsocket_client_connect(context, address, port, ssl_connection, path, host, origin, protocol, ietf_version_or_minus_one) ; + + if (ws && !ws->user_space && userdata) + ws->user_space = userdata ; + + return ws ; + } diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 15b59f43..f34c5538 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -391,7 +391,7 @@ just_kill_connection: #ifdef LWS_OPENSSL_SUPPORT } #endif - if (wsi->user_space) + if (wsi->protocol && wsi->protocol->per_session_data_size && wsi->user_space) /* user code may own */ free(wsi->user_space); free(wsi); @@ -1198,7 +1198,7 @@ select_protocol: * default to first protocol */ wsi->protocol = &context->protocols[0]; - + wsi->c_callback = wsi->protocol->callback; free(wsi->c_protocol); goto check_accept; @@ -1235,10 +1235,12 @@ select_protocol: */ n = 0; wsi->protocol = NULL; - while (context->protocols[n].callback) { + while (context->protocols[n].callback && !wsi->protocol) { /* Stop after finding first one?? */ if (strcmp(wsi->utf8_token[WSI_TOKEN_PROTOCOL].token, - context->protocols[n].name) == 0) + context->protocols[n].name) == 0) { wsi->protocol = &context->protocols[n]; + wsi->c_callback = wsi->protocol->callback; + } n++; } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index f8bfda4c..c24f09d6 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -675,6 +675,18 @@ libwebsocket_client_connect(struct libwebsocket_context *clients, const char *protocol, int ietf_version_or_minus_one); +LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, + void *userdata); + LWS_EXTERN const char * libwebsocket_canonical_hostname(struct libwebsocket_context *context); diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index afffe0d2..18b1620e 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -468,6 +468,51 @@ protocol supported, or the specific protocol ordinal This function creates a connection to a remote server
+This function creates a connection to a remote server ++
+the request client connection has +been unable to complete a handshake with the remote server +
after your client connection completed @@ -730,7 +780,7 @@ internal polling loop, you can just ignore it. (struct libwebsocket_context * context, struct libwebsocket_extension * ext, struct libwebsocket * wsi, -enum libwebsocket_callback_reasons reason, +enum libwebsocket_extension_callback_reasons reason, void * user, void * in, size_t len) @@ -815,7 +865,7 @@ set the lws_tokens token pointer to it.struct libwebsocket_protocols - List of protocols and handlers server supports.
struct libwebsocket_protocols {
const char * name;
- int (*callback) (struct libwebsocket_context * context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len);
+ callback_function * callback;
size_t per_session_data_size;
struct libwebsocket_context * owning_server;
int broadcast_socket_port;
@@ -861,7 +911,7 @@ allows as many protocols as you like to be handled by one server.struct libwebsocket_extension - An extension we know how to cope with
struct libwebsocket_extension {
const char * name;
- int (*callback) (struct libwebsocket_context *context,struct libwebsocket_extension *ext,struct libwebsocket *wsi,enum libwebsocket_extension_callback_reasons reason,void *user, void *in, size_t len);
+ extension_callback_function * callback;
size_t per_session_data_size;
void * per_context_private_data;
};