Lines Matching refs:wsi
31 lws_extension_server_handshake(struct lws *wsi, char **p, int budget) in lws_extension_server_handshake() argument
33 struct lws_context *context = wsi->a.context; in lws_extension_server_handshake()
34 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in lws_extension_server_handshake()
48 if (!lws_hdr_total_length(wsi, WSI_TOKEN_EXTENSIONS)) in lws_extension_server_handshake()
56 if (lws_hdr_copy(wsi, (char *)pt->serv_buf, (int)context->pt_serv_buf_size, in lws_extension_server_handshake()
62 wsi->ws->count_act_ext = 0; in lws_extension_server_handshake()
115 ext = wsi->a.vhost->ws.extensions; in lws_extension_server_handshake()
128 for (m = 0; m < wsi->ws->count_act_ext; m++) in lws_extension_server_handshake()
129 if (wsi->ws->active_extensions[m] == ext) { in lws_extension_server_handshake()
138 m = (wsi->a.protocol->callback)(wsi, in lws_extension_server_handshake()
140 wsi->user_space, ext_name, 0); in lws_extension_server_handshake()
158 wsi->ws->active_extensions[wsi->ws->count_act_ext] = ext; in lws_extension_server_handshake()
162 if (ext->callback(lws_get_context(wsi), ext, wsi, in lws_extension_server_handshake()
164 (void *)&wsi->ws->act_ext_user[ in lws_extension_server_handshake()
165 wsi->ws->count_act_ext], in lws_extension_server_handshake()
214 if (!ext->callback(lws_get_context(wsi), in lws_extension_server_handshake()
215 ext, wsi, in lws_extension_server_handshake()
217 wsi->ws->act_ext_user[ in lws_extension_server_handshake()
218 wsi->ws->count_act_ext], in lws_extension_server_handshake()
236 wsi->ws->count_act_ext++; in lws_extension_server_handshake()
238 wsi->ws->count_act_ext); in lws_extension_server_handshake()
255 lws_process_ws_upgrade2(struct lws *wsi) in lws_process_ws_upgrade2() argument
257 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in lws_process_ws_upgrade2()
271 pvos = lws_vhost_protocol_options(wsi->a.vhost, wsi->a.protocol->name); in lws_process_ws_upgrade2()
276 switch (lws_check_basic_auth(wsi, ws_prot_basic_auth, LWSAUTHM_DEFAULT in lws_process_ws_upgrade2()
281 return lws_unauthorised_basic_auth(wsi); in lws_process_ws_upgrade2()
283 lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); in lws_process_ws_upgrade2()
284 return lws_http_transaction_completed(wsi); in lws_process_ws_upgrade2()
304 if (!wsi->h2_stream_carries_ws) { in lws_process_ws_upgrade2()
305 lws_role_transition(wsi, LWSIFR_SERVER, LRS_ESTABLISHED, in lws_process_ws_upgrade2()
314 if (wsi->a.vhost->ss_handle) { in lws_process_ws_upgrade2()
316 __func__, lws_ss_tag(wsi->a.vhost->ss_handle)); in lws_process_ws_upgrade2()
317 wsi->a.protocol = &protocol_secstream_ws; in lws_process_ws_upgrade2()
325 (void)lws_ss_event_helper(wsi->a.vhost->ss_handle, in lws_process_ws_upgrade2()
335 wsi->ws = lws_zalloc(sizeof(*wsi->ws), "ws struct"); in lws_process_ws_upgrade2()
336 if (!wsi->ws) { in lws_process_ws_upgrade2()
341 if (lws_hdr_total_length(wsi, WSI_TOKEN_VERSION)) in lws_process_ws_upgrade2()
342 wsi->ws->ietf_spec_revision = (uint8_t) in lws_process_ws_upgrade2()
343 atoi(lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION)); in lws_process_ws_upgrade2()
346 if (lws_ensure_user_space(wsi)) { in lws_process_ws_upgrade2()
355 if ((wsi->a.protocol->callback)(wsi, in lws_process_ws_upgrade2()
357 wsi->user_space, in lws_process_ws_upgrade2()
358 lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) { in lws_process_ws_upgrade2()
368 switch (wsi->ws->ietf_spec_revision) { in lws_process_ws_upgrade2()
371 wsi->ws->ietf_spec_revision); in lws_process_ws_upgrade2()
372 wsi->ws->ietf_spec_revision = 13; in lws_process_ws_upgrade2()
377 if (wsi->h2_stream_carries_ws) { in lws_process_ws_upgrade2()
378 if (lws_h2_ws_handshake(wsi)) { in lws_process_ws_upgrade2()
382 lws_role_transition(wsi, in lws_process_ws_upgrade2()
392 lws_sul_cancel(&wsi->sul_validity); in lws_process_ws_upgrade2()
397 if (handshake_0405(wsi->a.context, wsi)) { in lws_process_ws_upgrade2()
405 if (lws_server_init_wsi_for_ws(wsi)) { in lws_process_ws_upgrade2()
409 lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision); in lws_process_ws_upgrade2()
414 int l = 14, meth = lws_http_get_uri_and_method(wsi, &uptr, &l); in lws_process_ws_upgrade2()
416 if (wsi->h2_stream_carries_ws) in lws_process_ws_upgrade2()
417 wsi->http.request_version = HTTP_VERSION_2; in lws_process_ws_upgrade2()
419 wsi->http.access_log.response = 101; in lws_process_ws_upgrade2()
423 wsi->a.protocol->name); in lws_process_ws_upgrade2()
427 lws_prepare_access_log_info(wsi, combo, l, meth); in lws_process_ws_upgrade2()
428 lws_access_log(wsi); in lws_process_ws_upgrade2()
432 lwsl_info("%s: %s: dropping ah on ws upgrade\n", __func__, lws_wsi_tag(wsi)); in lws_process_ws_upgrade2()
433 lws_header_table_detach(wsi, 1); in lws_process_ws_upgrade2()
439 lws_process_ws_upgrade(struct lws *wsi) in lws_process_ws_upgrade() argument
447 if (!wsi->a.protocol) in lws_process_ws_upgrade()
458 if (!wsi->mux_substream) { in lws_process_ws_upgrade()
465 n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); in lws_process_ws_upgrade()
500 meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); in lws_process_ws_upgrade()
501 hit = lws_find_mount(wsi, uri_ptr, uri_len); in lws_process_ws_upgrade()
519 return lws_http_proxy_start(wsi, hit, uri_ptr, 1); in lws_process_ws_upgrade()
532 n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_PROTOCOL); in lws_process_ws_upgrade()
539 int n = wsi->a.vhost->default_protocol_index; in lws_process_ws_upgrade()
550 if (n >= wsi->a.vhost->count_protocols) { in lws_process_ws_upgrade()
559 lws_bind_protocol(wsi, &wsi->a.vhost->protocols[n], in lws_process_ws_upgrade()
566 if (wsi->a.vhost->ss_handle) { in lws_process_ws_upgrade()
567 lws_ss_handle_t *sssh = wsi->a.vhost->ss_handle; in lws_process_ws_upgrade()
581 pcol = lws_vhost_name_to_protocol(wsi->a.vhost, in lws_process_ws_upgrade()
584 lws_bind_protocol(wsi, pcol, "ss ws upg pcol"); in lws_process_ws_upgrade()
605 pcol = lws_vhost_name_to_protocol(wsi->a.vhost, name); in lws_process_ws_upgrade()
608 lws_bind_protocol(wsi, pcol, "ws upg pcol"); in lws_process_ws_upgrade()
634 return lws_process_ws_upgrade2(wsi); in lws_process_ws_upgrade()
638 handshake_0405(struct lws_context *context, struct lws *wsi) in handshake_0405() argument
640 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in handshake_0405()
647 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST) || in handshake_0405()
648 !lws_hdr_total_length(wsi, WSI_TOKEN_KEY)) { in handshake_0405()
654 if (lws_hdr_total_length(wsi, WSI_TOKEN_KEY) >= in handshake_0405()
666 lws_hdr_simple_ptr(wsi, WSI_TOKEN_KEY)); in handshake_0405()
678 if (lws_ensure_user_space(wsi)) in handshake_0405()
697 if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) && in handshake_0405()
699 wsi->a.protocol->name && in handshake_0405()
700 wsi->a.protocol->name[0]) { in handshake_0405()
701 const char *prot = wsi->a.protocol->name; in handshake_0405()
704 if (wsi->proxied_ws_parent && wsi->child_list) in handshake_0405()
705 prot = wsi->child_list->ws->actual_protocol; in handshake_0405()
710 lws_ss_handle_t *sssh = wsi->a.vhost->ss_handle; in handshake_0405()
740 if (lws_extension_server_handshake(wsi, &p, 192)) in handshake_0405()
748 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in handshake_0405()
750 wsi->user_space, &args, 0)) in handshake_0405()
766 n = lws_write(wsi, (unsigned char *)response, lws_ptr_diff_size_t(p, response), in handshake_0405()
775 lwsi_set_state(wsi, LRS_ESTABLISHED); in handshake_0405()
776 wsi->lws_rx_parse_state = LWS_RXPS_NEW; in handshake_0405()
780 lws_hdr_simple_ptr(wsi, WSI_TOKEN_GET_URI); in handshake_0405()
781 int uri_len = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI); in handshake_0405()
783 lws_find_mount(wsi, uri_ptr, uri_len); in handshake_0405()
785 wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, in handshake_0405()
786 wsi->user_space, (void *)hit->cgienv, 0)) in handshake_0405()
805 lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) in lws_ws_frame_rest_is_payload() argument
811 unsigned int old_packet_length = (unsigned int)wsi->ws->rx_packet_length; in lws_ws_frame_rest_is_payload()
824 if (!wsi->ws->count_act_ext) in lws_ws_frame_rest_is_payload()
827 if (wsi->a.protocol->rx_buffer_size) in lws_ws_frame_rest_is_payload()
828 avail = (unsigned int)wsi->a.protocol->rx_buffer_size; in lws_ws_frame_rest_is_payload()
830 avail = wsi->a.context->pt_serv_buf_size; in lws_ws_frame_rest_is_payload()
834 if (avail > wsi->ws->rx_packet_length) in lws_ws_frame_rest_is_payload()
835 avail = (unsigned int)wsi->ws->rx_packet_length; in lws_ws_frame_rest_is_payload()
849 if (!wsi->ws->all_zero_nonce) { in lws_ws_frame_rest_is_payload()
852 mask[n] = wsi->ws->mask[(wsi->ws->mask_idx + n) & 3]; in lws_ws_frame_rest_is_payload()
872 wsi->ws->mask_idx = (wsi->ws->mask_idx + avail) & 3; in lws_ws_frame_rest_is_payload()
880 wsi->ws->rx_packet_length -= avail; in lws_ws_frame_rest_is_payload()
883 n = lws_ext_cb_active(wsi, LWS_EXT_CB_PAYLOAD_RX, &pmdrx, 0); in lws_ws_frame_rest_is_payload()
897 wsi->socket_is_permanently_unusable = 1; in lws_ws_frame_rest_is_payload()
915 !wsi->ws->rx_packet_length && /* raw ws packet payload all gone */ in lws_ws_frame_rest_is_payload()
916 wsi->ws->final && /* the raw ws packet is a FIN guy */ in lws_ws_frame_rest_is_payload()
917 wsi->a.protocol->callback && in lws_ws_frame_rest_is_payload()
918 !wsi->wsistate_pre_close) { in lws_ws_frame_rest_is_payload()
922 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in lws_ws_frame_rest_is_payload()
924 wsi->user_space, NULL, 0)) in lws_ws_frame_rest_is_payload()
934 if (wsi->ws->count_act_ext && !pmdrx.eb_out.len) in lws_ws_frame_rest_is_payload()
939 lws_add_wsi_to_draining_ext_list(wsi); in lws_ws_frame_rest_is_payload()
941 lws_remove_wsi_from_draining_ext_list(wsi); in lws_ws_frame_rest_is_payload()
945 wsi->ws->check_utf8 && !wsi->ws->defeat_check_utf8) { in lws_ws_frame_rest_is_payload()
946 if (lws_check_utf8(&wsi->ws->utf8, in lws_ws_frame_rest_is_payload()
949 lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, in lws_ws_frame_rest_is_payload()
955 if (!wsi->ws->rx_packet_length && wsi->ws->final && in lws_ws_frame_rest_is_payload()
956 wsi->ws->utf8 && !n) { in lws_ws_frame_rest_is_payload()
958 lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, in lws_ws_frame_rest_is_payload()
969 if (wsi->a.protocol->callback && !wsi->wsistate_pre_close) in lws_ws_frame_rest_is_payload()
970 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in lws_ws_frame_rest_is_payload()
972 wsi->user_space, in lws_ws_frame_rest_is_payload()
977 wsi->ws->first_fragment = 0; in lws_ws_frame_rest_is_payload()
982 wsi->ws->rx_draining_ext); in lws_ws_frame_rest_is_payload()
990 lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len) in lws_parse_ws() argument
1005 if (wsi->rxflow_bitmap) { in lws_parse_ws()
1017 if (lws_rxflow_cache(wsi, *buf, 0, len) == in lws_parse_ws()
1034 if (wsi->ws->rx_draining_ext) { in lws_parse_ws()
1036 m = lws_ws_rx_sm(wsi, ALREADY_PROCESSED_IGNORE_CHAR, 0); in lws_parse_ws()
1044 while (wsi->lws_rx_parse_state == LWS_RXPS_WS_FRAME_PAYLOAD && in lws_parse_ws()
1045 (wsi->ws->opcode == LWSWSOPC_TEXT_FRAME || in lws_parse_ws()
1046 wsi->ws->opcode == LWSWSOPC_BINARY_FRAME || in lws_parse_ws()
1047 wsi->ws->opcode == LWSWSOPC_CONTINUATION) && in lws_parse_ws()
1052 m = lws_ws_frame_rest_is_payload(wsi, buf, len); in lws_parse_ws()
1069 m = lws_ws_rx_sm(wsi, 0, *(*buf)++); in lws_parse_ws()
1080 wsi->ws->rx_draining_ext); in lws_parse_ws()
1082 m = lws_ws_rx_sm(wsi, ALREADY_PROCESSED_IGNORE_CHAR | in lws_parse_ws()