Lines Matching refs:wsi

47 			    struct lws *wsi)
51 /* allocate the ws struct for the wsi */
52 wsi->ws = lws_zalloc(sizeof(*wsi->ws), "client ws struct");
53 if (!wsi->ws) {
54 lwsl_wsi_notice(wsi, "OOM");
63 wsi->ws->ietf_spec_revision = (uint8_t)v;
70 lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len)
74 if ((lwsi_state(wsi) != LRS_WAITING_PROXY_REPLY) &&
75 (lwsi_state(wsi) != LRS_H1C_ISSUE_HANDSHAKE) &&
76 (lwsi_state(wsi) != LRS_WAITING_SERVER_REPLY) &&
77 !lwsi_role_client(wsi))
80 lwsl_wsi_debug(wsi, "hs client feels it has %d in", (int)len);
86 if (lws_is_flowcontrolled(wsi)) {
87 lwsl_wsi_debug(wsi, "caching %ld", (long)len);
97 if (lws_rxflow_cache(wsi, *buf, 0, len) ==
106 lwsl_wsi_info(wsi, "trimming inside rxflow cache");
114 if (wsi->ws->rx_draining_ext) {
117 lwsl_wsi_info(wsi, "draining ext");
118 if (lwsi_role_client(wsi))
119 m = lws_ws_client_rx_sm(wsi, 0);
121 m = lws_ws_rx_sm(wsi, 0, 0);
132 if (lws_ws_client_rx_sm(wsi, *(*buf)++)) {
133 lwsl_wsi_info(wsi, "client_rx_sm exited, DROPPING %d",
139 // lwsl_wsi_notice(wsi, "finished with %ld", (long)len);
146 lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1)
158 if (lws_get_random(wsi->a.context, hash, 16) != 16) {
159 lwsl_wsi_err(wsi, "Unable to read from random dev %s",
173 if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS))
175 lws_hdr_simple_ptr(wsi,
181 ext = wsi->a.vhost->ws.extensions;
184 n = wsi->a.vhost->protocols[0].callback(wsi,
186 wsi->user_space, (char *)ext->name, 0);
214 if (wsi->ws->ietf_spec_revision)
216 wsi->ws->ietf_spec_revision);
227 wsi->http.ah->initial_handshake_hash_base64,
228 sizeof(wsi->http.ah->initial_handshake_hash_base64));
234 lws_client_ws_upgrade(struct lws *wsi, const char **cce)
236 struct lws_context *context = wsi->a.context;
243 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
253 if (wsi->client_mux_substream) {/* !!! client ws-over-h2 not there yet */
254 lwsl_wsi_warn(wsi, "client ws-over-h2 upgrade not supported yet");
259 if (wsi->http.ah->http_response == 401) {
260 lwsl_wsi_warn(wsi, "got bad HTTP response '%d'",
261 wsi->http.ah->http_response);
266 if (wsi->http.ah->http_response != 101) {
267 lwsl_wsi_warn(wsi, "got bad HTTP response '%d'",
268 wsi->http.ah->http_response);
273 if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) {
274 lwsl_wsi_info(wsi, "no ACCEPT");
279 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE);
281 lwsl_wsi_info(wsi, "no UPGRADE");
287 lwsl_wsi_warn(wsi, "got bad Upgrade header '%s'", p);
296 n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION);
314 lwsl_wsi_info(wsi, "malformed connection '%s'", buf);
320 pc = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS);
323 lwsl_wsi_parser(wsi, "lws_client_int_s_hs: no protocol list");
325 lwsl_wsi_parser(wsi, "lws_client_int_s_hs: protocol list '%s'", pc);
333 len = lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL);
335 lwsl_wsi_info(wsi, "WSI_TOKEN_PROTOCOL is null");
341 if (wsi->a.protocol) {
342 p = (char *)wsi->a.protocol->name;
349 wsi->a.protocol = &wsi->a.vhost->protocols[0];
353 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL);
369 lwsl_wsi_info(wsi, "got bad protocol %s", p);
377 lws_strncpy(wsi->ws->actual_protocol, p,
378 sizeof(wsi->ws->actual_protocol));
386 if (!lwsi_role_client(wsi))
387 wsi->a.protocol = NULL;
389 while (n < wsi->a.vhost->count_protocols) {
390 if (!wsi->a.protocol &&
391 strcmp(p, wsi->a.vhost->protocols[n].name) == 0) {
392 wsi->a.protocol = &wsi->a.vhost->protocols[n];
398 if (n == wsi->a.vhost->count_protocols) { /* no match */
400 if (!lwsi_role_client(wsi)) {
401 lwsl_wsi_info(wsi, "fail protocol %s", p);
409 while (wsi->a.vhost->protocols[n].callback) {
410 if (wsi->a.protocol && strcmp(wsi->a.protocol->name,
411 wsi->a.vhost->protocols[n].name) == 0) {
412 wsi->a.protocol = &wsi->a.vhost->protocols[n];
418 if (!wsi->a.vhost->protocols[n].callback) {
419 if (wsi->a.protocol)
420 lwsl_wsi_err(wsi, "Failed to match protocol %s",
421 wsi->a.protocol->name);
423 lwsl_wsi_err(wsi, "No protocol on client");
429 lwsl_wsi_debug(wsi, "Selected protocol %s", wsi->a.protocol ?
430 wsi->a.protocol->name : "no pcol");
441 lws_same_vh_protocol_insert(wsi, n);
446 if (!lws_hdr_total_length(wsi, WSI_TOKEN_EXTENSIONS)) {
447 lwsl_wsi_ext(wsi, "no client extensions allowed by server");
456 if (lws_hdr_copy(wsi, sb, (int)context->pt_serv_buf_size,
458 lwsl_wsi_warn(wsi, "ext list from server failed to copy");
497 lwsl_wsi_notice(wsi, "checking client ext %s", ext_name);
500 ext = wsi->a.vhost->ws.extensions;
508 lwsl_wsi_notice(wsi, "instantiating client ext %s", ext_name);
512 wsi->ws->active_extensions[wsi->ws->count_act_ext] = ext;
516 if (ext->callback(lws_get_context(wsi), ext, wsi,
518 (void *)&wsi->ws->act_ext_user[
519 wsi->ws->count_act_ext],
521 lwsl_wsi_info(wsi, " ext %s failed construction",
532 if (user_callback_handle_rxflow(wsi->a.protocol->callback,
533 wsi, LWS_CALLBACK_WS_EXT_DEFAULTS,
541 lws_ext_parse_options(ext, wsi,
542 wsi->ws->act_ext_user[
543 wsi->ws->count_act_ext],
546 lwsl_wsi_err(wsi, "unable to parse user defaults '%s'",
555 if (a && lws_ext_parse_options(ext, wsi,
556 wsi->ws->act_ext_user[
557 wsi->ws->count_act_ext],
559 lwsl_wsi_err(wsi, "unable to parse remote def '%s'", a);
564 if (ext->callback(lws_get_context(wsi), ext, wsi,
566 wsi->ws->act_ext_user[wsi->ws->count_act_ext],
568 lwsl_wsi_err(wsi, "ext %s rejects server options %s",
574 wsi->ws->count_act_ext++;
580 lwsl_wsi_warn(wsi, "Unknown ext '%s'!", ext_name);
596 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_ACCEPT);
597 if (strcmp(p, wsi->http.ah->initial_handshake_hash_base64)) {
598 lwsl_wsi_warn(wsi, "lws_client_int_s_hs: accept '%s' wrong vs '%s'", p,
599 wsi->http.ah->initial_handshake_hash_base64);
605 if (lws_ensure_user_space(wsi)) {
606 lwsl_wsi_err(wsi, "Problem allocating wsi user mem");
615 if (wsi->a.protocol->callback(wsi,
617 wsi->user_space, NULL, 0)) {
623 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
626 lws_header_table_detach(wsi, 0);
628 lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, &role_ops_ws);
629 lws_validity_confirmed(wsi);
631 wsi->rxflow_change_to = LWS_RXFLOW_ALLOW;
638 n = (int)wsi->a.protocol->rx_buffer_size;
642 wsi->ws->rx_ubuf = lws_malloc((unsigned int)n + 4 /* 0x0000ffff zlib */,
644 if (!wsi->ws->rx_ubuf) {
645 lwsl_wsi_err(wsi, "OOM allocating rx buffer %d", n);
649 wsi->ws->rx_ubuf_alloc = (unsigned int)n;
651 lwsl_wsi_debug(wsi, "handshake OK for protocol %s", wsi->a.protocol->name);
655 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_ESTABLISHED,
656 wsi->user_space, NULL, 0)) {