blob: f80b9b487823aaa2938b29a2d7472bb828f917dc [file] [log] [blame]
Andy Green4739e5c2011-01-22 12:51:57 +00001#include "private-libwebsockets.h"
Andy Green4739e5c2011-01-22 12:51:57 +00002
Markus Elfring75212332013-10-26 20:23:00 +08003struct libwebsocket *libwebsocket_client_connect_2(
Andy Greena41314f2011-05-23 10:00:03 +01004 struct libwebsocket_context *context,
5 struct libwebsocket *wsi
6) {
7 struct pollfd pfd;
Andy Green055f2972014-03-24 16:09:25 +08008#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +08009 struct sockaddr_in6 server_addr6;
10 struct sockaddr_in6 client_addr6;
11 struct addrinfo hints, *result;
12#endif
13 struct sockaddr_in server_addr4;
14 struct sockaddr_in client_addr4;
Andy Greena41314f2011-05-23 10:00:03 +010015 struct hostent *server_hostent;
James Devine3f13ea22014-03-24 16:09:25 +080016
17 struct sockaddr *v;
Andy Greena41314f2011-05-23 10:00:03 +010018 int n;
19 int plen = 0;
Andy Greene77fb802013-02-11 13:04:45 +080020 const char *ads;
Andy Greena41314f2011-05-23 10:00:03 +010021
Markus Elfring75212332013-10-26 20:23:00 +080022 lwsl_client("libwebsocket_client_connect_2\n");
Andy Greena41314f2011-05-23 10:00:03 +010023
24 /*
25 * proxy?
26 */
27
28 if (context->http_proxy_port) {
Andy Greene48ba312013-02-10 15:34:59 +080029 plen = sprintf((char *)context->service_buffer,
Andy Greenf54a94b2013-02-10 15:19:39 +080030 "CONNECT %s:%u HTTP/1.0\x0d\x0a"
Andy Greena41314f2011-05-23 10:00:03 +010031 "User-agent: libwebsockets\x0d\x0a"
32/*Proxy-authorization: basic aGVsbG86d29ybGQ= */
Andy Greene77fb802013-02-11 13:04:45 +080033 "\x0d\x0a",
34 lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS),
Andy Greena7521de2013-02-18 10:38:45 +080035 wsi->u.hdr.ah->c_port);
Andy Green36efd822013-10-25 22:07:57 +080036 ads = context->http_proxy_address;
James Devine3f13ea22014-03-24 16:09:25 +080037
Andy Green055f2972014-03-24 16:09:25 +080038#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +080039 if (LWS_IPV6_ENABLED(context))
40 server_addr6.sin6_port = htons(context->http_proxy_port);
41 else
42#endif
43 server_addr4.sin_port = htons(context->http_proxy_port);
44
Andy Green36efd822013-10-25 22:07:57 +080045 } else {
46 ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
Andy Green7844d042014-03-25 14:08:21 +080047#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +080048 if (LWS_IPV6_ENABLED(context))
49 server_addr6.sin6_port = htons(wsi->u.hdr.ah->c_port);
50 else
51#endif
52 server_addr4.sin_port = htons(wsi->u.hdr.ah->c_port);
Andy Greena41314f2011-05-23 10:00:03 +010053 }
54
55 /*
56 * prepare the actual connection (to the proxy, if any)
57 */
Markus Elfring75212332013-10-26 20:23:00 +080058 lwsl_client("libwebsocket_client_connect_2: address %s\n", ads);
Andy Greene77fb802013-02-11 13:04:45 +080059
Andy Green055f2972014-03-24 16:09:25 +080060#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +080061 if (LWS_IPV6_ENABLED(context)) {
62 memset(&hints, 0, sizeof(struct addrinfo));
63 n = getaddrinfo(ads, NULL, &hints, &result);
64 if (n) {
65 lwsl_err("getaddrinfo: %s\n", gai_strerror(n));
66 goto oom4;
67 }
68
69 server_addr6.sin6_family = AF_INET6;
70 switch (result->ai_family) {
71 case AF_INET:
72 /* map IPv4 to IPv6 */
73 bzero((char *)&server_addr6.sin6_addr,
74 sizeof(struct in6_addr));
75 server_addr6.sin6_addr.s6_addr16[5] = 0xffff;
76 bcopy(&((struct sockaddr_in *)result->ai_addr)->sin_addr,
77 &server_addr6.sin6_addr.s6_addr16[6],
78 sizeof(struct in_addr));
79 break;
80 case AF_INET6:
81 memcpy(&server_addr6.sin6_addr,
82 &((struct sockaddr_in6 *)result->ai_addr)->sin6_addr,
83 sizeof(struct in6_addr));
84 break;
85 default:
86 lwsl_err("Unknown address family\n");
87 freeaddrinfo(result);
88 goto oom4;
89 }
90
91 freeaddrinfo(result);
92 } else
93#endif
94 {
95 server_hostent = gethostbyname(ads);
96 if (!server_hostent) {
97 lwsl_err("Unable to get host name from %s\n", ads);
98 goto oom4;
99 }
100
101 server_addr4.sin_family = AF_INET;
102 server_addr4.sin_addr =
103 *((struct in_addr *)server_hostent->h_addr);
104 bzero(&server_addr4.sin_zero, 8);
Andy Greena41314f2011-05-23 10:00:03 +0100105 }
106
Andy Greena41314f2011-05-23 10:00:03 +0100107 if (wsi->sock < 0) {
Andy Green5dc62ea2013-09-20 20:26:12 +0800108
Andy Green055f2972014-03-24 16:09:25 +0800109#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +0800110 if (LWS_IPV6_ENABLED(context))
111 wsi->sock = socket(AF_INET6, SOCK_STREAM, 0);
112 else
113#endif
114 wsi->sock = socket(AF_INET, SOCK_STREAM, 0);
Andy Green5dc62ea2013-09-20 20:26:12 +0800115
116 if (wsi->sock < 0) {
117 lwsl_warn("Unable to open socket\n");
118 goto oom4;
119 }
120
121 if (lws_set_socket_options(context, wsi->sock)) {
122 lwsl_err("Failed to set wsi socket options\n");
123 compatible_close(wsi->sock);
124 goto oom4;
125 }
126
127 wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT;
128
129 insert_wsi_socket_into_fds(context, wsi);
130
131 libwebsocket_set_timeout(wsi,
132 PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE,
133 AWAITING_TIMEOUT);
Andy Green055f2972014-03-24 16:09:25 +0800134#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +0800135 if (LWS_IPV6_ENABLED(context)) {
136 v = (struct sockaddr *)&client_addr6;
137 n = sizeof(client_addr6);
138 bzero((char *)v, n);
139 client_addr6.sin6_family = AF_INET6;
140 } else
141#endif
142 {
143 v = (struct sockaddr *)&client_addr4;
144 n = sizeof(client_addr4);
145 bzero((char *)v, n);
146 client_addr4.sin_family = AF_INET;
147 }
Mattias Lundberg03bb8f92014-02-18 10:06:57 +0100148
James Devine3f13ea22014-03-24 16:09:25 +0800149 if (context->iface) {
150 if (interface_to_sa(context, context->iface,
151 (struct sockaddr_in *)v, n) < 0) {
152 lwsl_err("Unable to find interface %s\n",
153 context->iface);
Mattias Lundberg03bb8f92014-02-18 10:06:57 +0100154 compatible_close(wsi->sock);
155 goto failed;
156 }
157
James Devine3f13ea22014-03-24 16:09:25 +0800158 if (bind(wsi->sock, v, n) < 0) {
159 lwsl_err("Error binding to interface %s",
160 context->iface);
Mattias Lundberg03bb8f92014-02-18 10:06:57 +0100161 compatible_close(wsi->sock);
162 goto failed;
163 }
164 }
Andy Greena41314f2011-05-23 10:00:03 +0100165 }
166
Andy Green055f2972014-03-24 16:09:25 +0800167#ifdef LWS_USE_IPV6
James Devine3f13ea22014-03-24 16:09:25 +0800168 if (LWS_IPV6_ENABLED(context)) {
169 v = (struct sockaddr *)&server_addr6;
170 n = sizeof(struct sockaddr_in6);
171 } else
172#endif
173 {
174 v = (struct sockaddr *)&server_addr4;
175 n = sizeof(struct sockaddr);
176 }
Andy Green36efd822013-10-25 22:07:57 +0800177
James Devine3f13ea22014-03-24 16:09:25 +0800178 if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) {
Andy Green5dc62ea2013-09-20 20:26:12 +0800179
Patrick Gansterer2dbd8372014-02-28 12:37:52 +0100180 if (LWS_ERRNO == LWS_EALREADY || LWS_ERRNO == LWS_EINPROGRESS) {
Andy Green5dc62ea2013-09-20 20:26:12 +0800181 lwsl_client("nonblocking connect retry\n");
182
183 /*
184 * must do specifically a POLLOUT poll to hear
185 * about the connect completion
186 */
Andy Green91f19d82013-12-21 11:18:34 +0800187 lws_change_pollfd(wsi, 0, POLLOUT);
Andy Green5dc62ea2013-09-20 20:26:12 +0800188
189 return wsi;
190 }
191
Patrick Gansterer2dbd8372014-02-28 12:37:52 +0100192 if (LWS_ERRNO != LWS_EISCONN) {
Patrick Gansterer2dbd8372014-02-28 12:37:52 +0100193 lwsl_debug("Connect failed errno=%d\n", LWS_ERRNO);
shys5efcb3f2013-10-25 15:49:11 +0200194 goto failed;
195 }
Andy Greena41314f2011-05-23 10:00:03 +0100196 }
197
Andy Green43db0452013-01-10 19:50:35 +0800198 lwsl_client("connected\n");
Andy Greena41314f2011-05-23 10:00:03 +0100199
Andy Greena41314f2011-05-23 10:00:03 +0100200 /* we are connected to server, or proxy */
201
202 if (context->http_proxy_port) {
203
Andy Green36efd822013-10-25 22:07:57 +0800204 /* OK from now on we talk via the proxy, so connect to that */
205
206 /*
207 * (will overwrite existing pointer,
208 * leaving old string/frag there but unreferenced)
209 */
210 if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
211 context->http_proxy_address))
212 goto failed;
213 wsi->u.hdr.ah->c_port = context->http_proxy_port;
214
Joachim Bauch8294c1f2013-06-29 10:22:09 +0800215 n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL);
Andy Greena41314f2011-05-23 10:00:03 +0100216 if (n < 0) {
Andy Green43db0452013-01-10 19:50:35 +0800217 lwsl_debug("ERROR writing to proxy socket\n");
Andy Green5dc62ea2013-09-20 20:26:12 +0800218 goto failed;
Andy Greena41314f2011-05-23 10:00:03 +0100219 }
220
221 libwebsocket_set_timeout(wsi,
Andy Greenb5b23192013-02-11 17:13:32 +0800222 PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
223 AWAITING_TIMEOUT);
Andy Greena41314f2011-05-23 10:00:03 +0100224
225 wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY;
226
227 return wsi;
228 }
229
230 /*
231 * provoke service to issue the handshake directly
232 * we need to do it this way because in the proxy case, this is the
233 * next state and executed only if and when we get a good proxy
Andy Green73abc252013-01-13 11:05:30 +0800234 * response inside the state machine... but notice in SSL case this
235 * may not have sent anything yet with 0 return, and won't until some
236 * many retries from main loop. To stop that becoming endless,
237 * cover with a timeout.
Andy Greena41314f2011-05-23 10:00:03 +0100238 */
239
Andy Green73abc252013-01-13 11:05:30 +0800240 libwebsocket_set_timeout(wsi,
241 PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, AWAITING_TIMEOUT);
242
Andy Greena41314f2011-05-23 10:00:03 +0100243 wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
244 pfd.fd = wsi->sock;
245 pfd.revents = POLLIN;
David Galeano36750b82013-01-09 16:17:04 +0800246
247 n = libwebsocket_service_fd(context, &pfd);
248
249 if (n < 0)
Andy Green5dc62ea2013-09-20 20:26:12 +0800250 goto failed;
Andy Greena41314f2011-05-23 10:00:03 +0100251
David Galeano36750b82013-01-09 16:17:04 +0800252 if (n) /* returns 1 on failure after closing wsi */
253 return NULL;
254
Andy Greena41314f2011-05-23 10:00:03 +0100255 return wsi;
256
257oom4:
Andy Greene77fb802013-02-11 13:04:45 +0800258 free(wsi->u.hdr.ah);
Andy Greena41314f2011-05-23 10:00:03 +0100259 free(wsi);
Andy Green5dc62ea2013-09-20 20:26:12 +0800260 return NULL;
Andy Greena41314f2011-05-23 10:00:03 +0100261
Andy Green5dc62ea2013-09-20 20:26:12 +0800262failed:
263 libwebsocket_close_and_free_session(context, wsi,
264 LWS_CLOSE_STATUS_NOSTATUS);
Andy Greena41314f2011-05-23 10:00:03 +0100265 return NULL;
266}
267
Andy Green90c7cbc2011-01-27 06:26:52 +0000268/**
269 * libwebsocket_client_connect() - Connect to another websocket server
Peter Hinz56885f32011-03-02 22:03:47 +0000270 * @context: Websocket context
Andy Green90c7cbc2011-01-27 06:26:52 +0000271 * @address: Remote server address, eg, "myserver.com"
272 * @port: Port to connect to on the remote server, eg, 80
273 * @ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
274 * signed certs
275 * @path: Websocket path on server
276 * @host: Hostname on server
277 * @origin: Socket origin name
278 * @protocol: Comma-separated list of protocols being asked for from
279 * the server, or just one. The server will pick the one it
280 * likes best.
Andy Greenbfb051f2011-02-09 08:49:14 +0000281 * @ietf_version_or_minus_one: -1 to ask to connect using the default, latest
Andy Green6ee372f2012-04-09 15:09:01 +0800282 * protocol supported, or the specific protocol ordinal
Andy Green90c7cbc2011-01-27 06:26:52 +0000283 *
284 * This function creates a connection to a remote server
285 */
286
Peter Pentchev9a4fef72013-03-30 09:52:21 +0800287LWS_VISIBLE struct libwebsocket *
Peter Hinz56885f32011-03-02 22:03:47 +0000288libwebsocket_client_connect(struct libwebsocket_context *context,
Andy Green4739e5c2011-01-22 12:51:57 +0000289 const char *address,
290 int port,
Andy Green90c7cbc2011-01-27 06:26:52 +0000291 int ssl_connection,
Andy Green4739e5c2011-01-22 12:51:57 +0000292 const char *path,
293 const char *host,
294 const char *origin,
Andy Greenbfb051f2011-02-09 08:49:14 +0000295 const char *protocol,
296 int ietf_version_or_minus_one)
Andy Green4739e5c2011-01-22 12:51:57 +0000297{
Andy Green4739e5c2011-01-22 12:51:57 +0000298 struct libwebsocket *wsi;
Andy Green3182ece2013-01-20 17:08:31 +0800299#ifndef LWS_NO_EXTENSIONS
Andy Green760c3d42013-02-18 10:43:18 +0800300 int n;
Andy Greena41314f2011-05-23 10:00:03 +0100301 int m;
302 struct libwebsocket_extension *ext;
303 int handled;
Andy Green3182ece2013-01-20 17:08:31 +0800304#endif
305
Andy Greenbe93fef2011-02-14 20:25:43 +0000306#ifndef LWS_OPENSSL_SUPPORT
Andy Green90c7cbc2011-01-27 06:26:52 +0000307 if (ssl_connection) {
Andy Green43db0452013-01-10 19:50:35 +0800308 lwsl_err("libwebsockets not configured for ssl\n");
Andy Green90c7cbc2011-01-27 06:26:52 +0000309 return NULL;
310 }
311#endif
Andy Green4739e5c2011-01-22 12:51:57 +0000312
Aaron Zinman4550f1d2013-01-10 12:35:18 +0800313 wsi = (struct libwebsocket *) malloc(sizeof(struct libwebsocket));
Andy Greenbe93fef2011-02-14 20:25:43 +0000314 if (wsi == NULL)
Andy Green224149a2013-02-11 21:43:41 +0800315 goto bail;
Andy Green4739e5c2011-01-22 12:51:57 +0000316
Andy Greenb5b23192013-02-11 17:13:32 +0800317 memset(wsi, 0, sizeof(*wsi));
Andy Green5dc62ea2013-09-20 20:26:12 +0800318 wsi->sock = -1;
Darin Willitsc19456f2011-02-14 17:52:39 +0000319
Andy Greenbfb051f2011-02-09 08:49:14 +0000320 /* -1 means just use latest supported */
321
322 if (ietf_version_or_minus_one == -1)
Andy Green193306c2011-02-26 11:08:46 +0000323 ietf_version_or_minus_one = SPEC_LATEST_SUPPORTED;
Andy Greenbfb051f2011-02-09 08:49:14 +0000324
325 wsi->ietf_spec_revision = ietf_version_or_minus_one;
Andy Green4739e5c2011-01-22 12:51:57 +0000326 wsi->user_space = NULL;
327 wsi->state = WSI_STATE_CLIENT_UNCONNECTED;
Andy Green927eb7b2011-02-01 08:52:55 +0000328 wsi->protocol = NULL;
Andy Greena71eafc2011-02-14 17:59:43 +0000329 wsi->pending_timeout = NO_PENDING_TIMEOUT;
Andy Green3182ece2013-01-20 17:08:31 +0800330#ifndef LWS_NO_EXTENSIONS
Andy Greend6e09112011-03-05 16:12:15 +0000331 wsi->count_active_extensions = 0;
Andy Green3182ece2013-01-20 17:08:31 +0800332#endif
Andy Greenbe93fef2011-02-14 20:25:43 +0000333#ifdef LWS_OPENSSL_SUPPORT
334 wsi->use_ssl = ssl_connection;
335#endif
336
Andy Green16ab3182013-02-10 18:02:31 +0800337 if (lws_allocate_header_table(wsi))
Andy Greene77fb802013-02-11 13:04:45 +0800338 goto bail;
339
340 /*
341 * we're not necessarily in a position to action these right away,
342 * stash them... we only need during connect phase so u.hdr is fine
343 */
Andy Greena7521de2013-02-18 10:38:45 +0800344 wsi->u.hdr.ah->c_port = port;
Andy Greene77fb802013-02-11 13:04:45 +0800345 if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, address))
346 goto bail1;
347
348 /* these only need u.hdr lifetime as well */
349
350 if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, path))
351 goto bail1;
352
353 if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_HOST, host))
354 goto bail1;
355
356 if (origin)
Andy Greenb5b23192013-02-11 17:13:32 +0800357 if (lws_hdr_simple_create(wsi,
358 _WSI_TOKEN_CLIENT_ORIGIN, origin))
Andy Greene77fb802013-02-11 13:04:45 +0800359 goto bail1;
360 /*
361 * this is a list of protocols we tell the server we're okay with
362 * stash it for later when we compare server response with it
363 */
364 if (protocol)
Andy Greenb5b23192013-02-11 17:13:32 +0800365 if (lws_hdr_simple_create(wsi,
366 _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, protocol))
Andy Greene77fb802013-02-11 13:04:45 +0800367 goto bail1;
368
369 wsi->protocol = &context->protocols[0];
Andy Green4739e5c2011-01-22 12:51:57 +0000370
Andy Green3182ece2013-01-20 17:08:31 +0800371#ifndef LWS_NO_EXTENSIONS
Andy Green4739e5c2011-01-22 12:51:57 +0000372 /*
Andy Greena41314f2011-05-23 10:00:03 +0100373 * Check with each extension if it is able to route and proxy this
374 * connection for us. For example, an extension like x-google-mux
375 * can handle this and then we don't need an actual socket for this
376 * connection.
Andy Green9659f372011-01-27 22:01:43 +0000377 */
378
Andy Greena41314f2011-05-23 10:00:03 +0100379 handled = 0;
380 ext = context->extensions;
381 n = 0;
Andy Green9659f372011-01-27 22:01:43 +0000382
Andy Greena41314f2011-05-23 10:00:03 +0100383 while (ext && ext->callback && !handled) {
384 m = ext->callback(context, ext, wsi,
385 LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
386 (void *)(long)n, (void *)address, port);
387 if (m)
388 handled = 1;
Andy Green9659f372011-01-27 22:01:43 +0000389
Andy Greena41314f2011-05-23 10:00:03 +0100390 ext++;
391 n++;
Andy Green9659f372011-01-27 22:01:43 +0000392 }
393
Andy Greena41314f2011-05-23 10:00:03 +0100394 if (handled) {
Andy Green43db0452013-01-10 19:50:35 +0800395 lwsl_client("libwebsocket_client_connect: ext handling conn\n");
Andy Green5b9a4c02011-01-28 09:39:29 +0000396
Andy Greenbe93fef2011-02-14 20:25:43 +0000397 libwebsocket_set_timeout(wsi,
Andy Greenb5b23192013-02-11 17:13:32 +0800398 PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
399 AWAITING_TIMEOUT);
Andy Green5b9a4c02011-01-28 09:39:29 +0000400
Andy Greena41314f2011-05-23 10:00:03 +0100401 wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
Andy Greenbe93fef2011-02-14 20:25:43 +0000402 return wsi;
Andy Green9659f372011-01-27 22:01:43 +0000403 }
Andy Green3182ece2013-01-20 17:08:31 +0800404#endif
Andy Green43db0452013-01-10 19:50:35 +0800405 lwsl_client("libwebsocket_client_connect: direct conn\n");
Andy Green4739e5c2011-01-22 12:51:57 +0000406
Markus Elfring75212332013-10-26 20:23:00 +0800407 return libwebsocket_client_connect_2(context, wsi);
Andy Green4739e5c2011-01-22 12:51:57 +0000408
Andy Green4739e5c2011-01-22 12:51:57 +0000409bail1:
Andy Greene77fb802013-02-11 13:04:45 +0800410 free(wsi->u.hdr.ah);
411bail:
Andy Green4739e5c2011-01-22 12:51:57 +0000412 free(wsi);
413
414 return NULL;
415}
David Brooks2c60d952012-04-20 12:19:01 +0800416
417
418/**
419 * libwebsocket_client_connect_extended() - Connect to another websocket server
420 * @context: Websocket context
421 * @address: Remote server address, eg, "myserver.com"
422 * @port: Port to connect to on the remote server, eg, 80
423 * @ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
424 * signed certs
425 * @path: Websocket path on server
426 * @host: Hostname on server
427 * @origin: Socket origin name
428 * @protocol: Comma-separated list of protocols being asked for from
429 * the server, or just one. The server will pick the one it
430 * likes best.
431 * @ietf_version_or_minus_one: -1 to ask to connect using the default, latest
Andy Greenb5b23192013-02-11 17:13:32 +0800432 * protocol supported, or the specific protocol ordinal
David Brooks2c60d952012-04-20 12:19:01 +0800433 * @userdata: Pre-allocated user data
434 *
435 * This function creates a connection to a remote server
436 */
437
Peter Pentchev9a4fef72013-03-30 09:52:21 +0800438LWS_VISIBLE struct libwebsocket *
David Brooks2c60d952012-04-20 12:19:01 +0800439libwebsocket_client_connect_extended(struct libwebsocket_context *context,
440 const char *address,
441 int port,
442 int ssl_connection,
443 const char *path,
444 const char *host,
445 const char *origin,
446 const char *protocol,
447 int ietf_version_or_minus_one,
Andy Greenb5b23192013-02-11 17:13:32 +0800448 void *userdata)
David Brooks2c60d952012-04-20 12:19:01 +0800449{
450 struct libwebsocket *ws =
Andy Greenb5b23192013-02-11 17:13:32 +0800451 libwebsocket_client_connect(context, address, port,
452 ssl_connection, path, host, origin, protocol,
453 ietf_version_or_minus_one);
David Brooks2c60d952012-04-20 12:19:01 +0800454
455 if (ws && !ws->user_space && userdata)
456 ws->user_space = userdata ;
457
458 return ws ;
Andy Greenb5b23192013-02-11 17:13:32 +0800459}