Lines Matching full:wsi

42 lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len)  in lws_read_h1()  argument
48 lwsl_debug("%s: h1 path: wsi state 0x%x\n", __func__, lwsi_state(wsi)); in lws_read_h1()
50 switch (lwsi_state(wsi)) { in lws_read_h1()
57 if (lwsi_role_ws(wsi)) in lws_read_h1()
60 if (lwsi_role_client(wsi)) in lws_read_h1()
63 wsi->hdr_parsing_completed = 0; in lws_read_h1()
68 if (!wsi->http.ah) { in lws_read_h1()
74 if (lws_ws_handshake_client(wsi, &buf, (size_t)len)) in lws_read_h1()
78 if (lws_handshake_server(wsi, &buf, (size_t)len)) in lws_read_h1()
83 if (wsi->role_ops == &role_ops_raw_skt in lws_read_h1()
86 wsi->role_ops == &role_ops_raw_file in lws_read_h1()
101 if (!wsi->hdr_parsing_completed) in lws_read_h1()
105 switch (lwsi_state(wsi)) { in lws_read_h1()
113 wsi->http.rx_content_remain = in lws_read_h1()
114 wsi->http.rx_content_length; in lws_read_h1()
115 if (wsi->http.rx_content_remain) in lws_read_h1()
129 (int)wsi->http.content_length_given, in lws_read_h1()
130 (int)wsi->http.rx_content_remain, (int)len); in lws_read_h1()
132 if (wsi->http.content_length_given && !wsi->http.rx_content_remain) in lws_read_h1()
135 while (len && (!wsi->http.content_length_given || wsi->http.rx_content_remain)) { in lws_read_h1()
140 if (wsi->http.content_length_given) in lws_read_h1()
141 body_chunk_len = min(wsi->http.rx_content_remain, len); in lws_read_h1()
144 wsi->http.rx_content_remain -= body_chunk_len; in lws_read_h1()
147 if (wsi->http.cgi) { in lws_read_h1()
151 args.stdwsi = &wsi->http.cgi->lsp->stdwsi[0]; in lws_read_h1()
157 wsi->a.protocol->callback, in lws_read_h1()
158 wsi, LWS_CALLBACK_CGI_STDIN_DATA, in lws_read_h1()
159 wsi->user_space, in lws_read_h1()
165 if (lwsi_state(wsi) != LRS_DISCARD_BODY) { in lws_read_h1()
167 n = (unsigned int)wsi->a.protocol->callback(wsi, in lws_read_h1()
168 LWS_CALLBACK_HTTP_BODY, wsi->user_space, in lws_read_h1()
181 if (lwsi_role_h2(wsi) && !wsi->http.content_length_given) { in lws_read_h1()
182 struct lws *w = lws_get_network_wsi(wsi); in lws_read_h1()
190 lws_set_timeout(wsi, in lws_read_h1()
192 (int)wsi->a.context->timeout_secs); in lws_read_h1()
199 if (wsi->http.rx_content_remain) { in lws_read_h1()
200 lws_set_timeout(wsi, in lws_read_h1()
202 (int)wsi->a.context->timeout_secs); in lws_read_h1()
212 if (wsi->http.cgi) in lws_read_h1()
213 lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, in lws_read_h1()
214 (int)wsi->a.context->timeout_secs); in lws_read_h1()
217 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); in lws_read_h1()
219 if (!wsi->http.cgi) in lws_read_h1()
223 if (lwsi_state(wsi) == LRS_DISCARD_BODY) { in lws_read_h1()
230 if (lws_http_transaction_completed(wsi)) in lws_read_h1()
236 lws_wsi_tag(wsi), wsi->a.protocol->name); in lws_read_h1()
238 n = (unsigned int)wsi->a.protocol->callback(wsi, in lws_read_h1()
240 wsi->user_space, NULL, 0); in lws_read_h1()
246 if (wsi->mux_substream) in lws_read_h1()
247 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_read_h1()
262 if (lws_ws_handshake_client(wsi, &buf, (size_t)len)) in lws_read_h1()
266 if (lwsi_role_ws(wsi) && lwsi_role_server(wsi) && in lws_read_h1()
270 lws_parse_ws(wsi, &buf, (size_t)len) < 0) { in lws_read_h1()
296 lwsl_err("%s: Unhandled state %d\n", __func__, lwsi_state(wsi)); in lws_read_h1()
304 // wsi, (long)(buf - oldbuf), (int)len, wsi->state); in lws_read_h1()
319 * outer lws_read() does the wsi close. in lws_read_h1()
321 if (!wsi->outer_will_close) in lws_read_h1()
322 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, in lws_read_h1()
329 lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) in lws_h1_server_socket_service() argument
331 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in lws_h1_server_socket_service()
335 if (lwsi_state(wsi) == LRS_DEFERRING_ACTION) in lws_h1_server_socket_service()
350 if (wsi->favoured_pollin && in lws_h1_server_socket_service()
353 wsi->favoured_pollin = 0; in lws_h1_server_socket_service()
362 if (lwsi_state(wsi) == LRS_SSL_ACK_PENDING) in lws_h1_server_socket_service()
367 if ((lwsi_state(wsi) == LRS_ESTABLISHED || in lws_h1_server_socket_service()
368 lwsi_state(wsi) == LRS_ISSUING_FILE || in lws_h1_server_socket_service()
369 lwsi_state(wsi) == LRS_HEADERS || in lws_h1_server_socket_service()
370 lwsi_state(wsi) == LRS_DOING_TRANSACTION || /* at least, SSE */ in lws_h1_server_socket_service()
371 lwsi_state(wsi) == LRS_DISCARD_BODY || in lws_h1_server_socket_service()
372 lwsi_state(wsi) == LRS_BODY)) { in lws_h1_server_socket_service()
374 if (!wsi->http.ah && lws_header_table_attach(wsi, 0)) { in lws_h1_server_socket_service()
376 lws_wsi_tag(wsi)); in lws_h1_server_socket_service()
392 buffered = lws_buflist_aware_read(pt, wsi, &ebuf, 0, __func__); in lws_h1_server_socket_service()
396 wsi->seen_zero_length_recv = 1; in lws_h1_server_socket_service()
397 if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) in lws_h1_server_socket_service()
404 if (wsi->ws && in lws_h1_server_socket_service()
405 (wsi->ws->rx_draining_ext || in lws_h1_server_socket_service()
406 wsi->ws->tx_draining_ext)) in lws_h1_server_socket_service()
422 if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE) { in lws_h1_server_socket_service()
427 if (lwsi_state(wsi) == LRS_ISSUING_FILE) { in lws_h1_server_socket_service()
428 // lwsl_notice("stashing: wsi %p: bd %d\n", wsi, buffered); in lws_h1_server_socket_service()
429 if (lws_buflist_aware_finished_consuming(wsi, &ebuf, 0, in lws_h1_server_socket_service()
441 if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY) in lws_h1_server_socket_service()
442 n = lws_read_h2(wsi, ebuf.token, (unsigned int)ebuf.len); in lws_h1_server_socket_service()
445 n = lws_read_h1(wsi, ebuf.token, (unsigned int)ebuf.len); in lws_h1_server_socket_service()
446 if (n < 0) /* we closed wsi */ in lws_h1_server_socket_service()
451 if (lws_buflist_aware_finished_consuming(wsi, &ebuf, n, in lws_h1_server_socket_service()
460 if (wsi->http.ah && in lws_h1_server_socket_service()
461 !lwsi_role_h1(wsi) && in lws_h1_server_socket_service()
462 !lwsi_role_h2(wsi) && in lws_h1_server_socket_service()
463 !lwsi_role_cgi(wsi)) in lws_h1_server_socket_service()
464 lws_header_table_detach(wsi, 0); in lws_h1_server_socket_service()
472 wsi->favoured_pollin = 1; in lws_h1_server_socket_service()
483 wsi->favoured_pollin = 1; in lws_h1_server_socket_service()
493 if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) { in lws_h1_server_socket_service()
499 wsi->could_have_pending = 0; in lws_h1_server_socket_service()
501 if (lwsi_state(wsi) == LRS_DEFERRING_ACTION) { in lws_h1_server_socket_service()
504 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_h1_server_socket_service()
505 if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) { in lws_h1_server_socket_service()
511 if (!wsi->hdr_parsing_completed) in lws_h1_server_socket_service()
514 if (lwsi_state(wsi) != LRS_ISSUING_FILE) { in lws_h1_server_socket_service()
516 if (lws_has_buffered_out(wsi)) { in lws_h1_server_socket_service()
518 if (lws_issue_raw(wsi, NULL, 0) < 0) { in lws_h1_server_socket_service()
525 n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in lws_h1_server_socket_service()
527 wsi->user_space, NULL, 0); in lws_h1_server_socket_service()
544 n = lws_serve_http_file_fragment(wsi); in lws_h1_server_socket_service()
553 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, in lws_h1_server_socket_service()
561 rops_handle_POLLIN_h1(struct lws_context_per_thread *pt, struct lws *wsi, in rops_handle_POLLIN_h1() argument
564 if (lwsi_state(wsi) == LRS_IDLING) { in rops_handle_POLLIN_h1()
575 // __func__, wsi, wsi->wsistate, wsi->role_ops->name, in rops_handle_POLLIN_h1()
578 rlen = lws_ssl_capable_read(wsi, buf, sizeof(buf)); in rops_handle_POLLIN_h1()
584 if (wsi->http.cgi && (pollfd->revents & LWS_POLLOUT)) { in rops_handle_POLLIN_h1()
585 if (lws_handle_POLLOUT_event(wsi, pollfd)) in rops_handle_POLLIN_h1()
595 if (wsi->http.comp_ctx.buflist_comp || in rops_handle_POLLIN_h1()
596 wsi->http.comp_ctx.may_have_more) { in rops_handle_POLLIN_h1()
600 __func__, wsi->http.comp_ctx.buflist_comp, in rops_handle_POLLIN_h1()
601 wsi->http.comp_ctx.may_have_more in rops_handle_POLLIN_h1()
604 if (lws_rops_fidx(wsi->role_ops, LWS_ROPS_write_role_protocol) && in rops_handle_POLLIN_h1()
605 lws_rops_func_fidx(wsi->role_ops, LWS_ROPS_write_role_protocol). in rops_handle_POLLIN_h1()
606 write_role_protocol(wsi, NULL, 0, &wp) < 0) { in rops_handle_POLLIN_h1()
610 lws_callback_on_writable(wsi); in rops_handle_POLLIN_h1()
612 if (!wsi->http.comp_ctx.buflist_comp && in rops_handle_POLLIN_h1()
613 !wsi->http.comp_ctx.may_have_more && in rops_handle_POLLIN_h1()
614 wsi->http.deferred_transaction_completed) { in rops_handle_POLLIN_h1()
615 wsi->http.deferred_transaction_completed = 0; in rops_handle_POLLIN_h1()
616 if (lws_http_transaction_completed(wsi)) in rops_handle_POLLIN_h1()
624 if (lws_is_flowcontrolled(wsi)) in rops_handle_POLLIN_h1()
631 if (!lwsi_role_client(wsi)) { in rops_handle_POLLIN_h1()
634 lwsl_debug("%s: %s: wsistate 0x%x\n", __func__, lws_wsi_tag(wsi), in rops_handle_POLLIN_h1()
635 (unsigned int)wsi->wsistate); in rops_handle_POLLIN_h1()
638 !lws_buflist_total_len(&wsi->buflist)) in rops_handle_POLLIN_h1()
641 n = lws_h1_server_socket_service(wsi, pollfd); in rops_handle_POLLIN_h1()
644 if (lwsi_state(wsi) != LRS_SSL_INIT) in rops_handle_POLLIN_h1()
645 if (lws_server_socket_service_ssl(wsi, in rops_handle_POLLIN_h1()
656 wsi->hdr_parsing_completed && !wsi->told_user_closed) { in rops_handle_POLLIN_h1()
669 wsi->client_rx_avail = 1; in rops_handle_POLLIN_h1()
670 if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) in rops_handle_POLLIN_h1()
673 //lwsl_notice("calling back %s\n", wsi->a.protocol->name); in rops_handle_POLLIN_h1()
678 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in rops_handle_POLLIN_h1()
680 wsi->user_space, NULL, 0)) { in rops_handle_POLLIN_h1()
689 // if (lwsi_state(wsi) == LRS_ESTABLISHED) in rops_handle_POLLIN_h1()
694 lws_handle_POLLOUT_event(wsi, pollfd)) { in rops_handle_POLLIN_h1()
699 if (lws_http_client_socket_service(wsi, pollfd)) in rops_handle_POLLIN_h1()
703 if (lwsi_state(wsi) == LRS_WAITING_CONNECT && in rops_handle_POLLIN_h1()
711 rops_handle_POLLOUT_h1(struct lws *wsi) in rops_handle_POLLOUT_h1() argument
715 if (lwsi_state(wsi) == LRS_ISSUE_HTTP_BODY || in rops_handle_POLLOUT_h1()
716 lwsi_state(wsi) == LRS_WAITING_SERVER_REPLY) { in rops_handle_POLLOUT_h1()
718 if (wsi->http.proxy_clientside) { in rops_handle_POLLOUT_h1()
721 &wsi->parent->http.buflist_post_body, &buf); in rops_handle_POLLOUT_h1()
731 __func__, lws_wsi_tag(wsi), (int)len, in rops_handle_POLLOUT_h1()
732 (int)wsi->http.tx_content_length, in rops_handle_POLLOUT_h1()
733 (int)wsi->http.tx_content_remain, in rops_handle_POLLOUT_h1()
734 (int)wsi->http.rx_content_length, in rops_handle_POLLOUT_h1()
735 (int)wsi->http.rx_content_remain in rops_handle_POLLOUT_h1()
738 n = lws_write(wsi, prebuf + LWS_PRE, len, LWS_WRITE_HTTP); in rops_handle_POLLOUT_h1()
745 lws_buflist_use_segment(&wsi->parent->http.buflist_post_body, len); in rops_handle_POLLOUT_h1()
749 if (wsi->parent->http.buflist_post_body) { in rops_handle_POLLOUT_h1()
750 lws_callback_on_writable(wsi); in rops_handle_POLLOUT_h1()
754 lwsl_wsi_err(wsi, "nothing to send"); in rops_handle_POLLOUT_h1()
757 wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; in rops_handle_POLLOUT_h1()
758 wsi->http.ah->lextable_pos = 0; in rops_handle_POLLOUT_h1()
760 wsi->http.ah->unk_pos = 0; in rops_handle_POLLOUT_h1()
763 lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); in rops_handle_POLLOUT_h1()
764 lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, in rops_handle_POLLOUT_h1()
765 (int)wsi->a.context->timeout_secs); in rops_handle_POLLOUT_h1()
773 if (lwsi_role_client(wsi)) in rops_handle_POLLOUT_h1()
780 rops_write_role_protocol_h1(struct lws *wsi, unsigned char *buf, size_t len, in rops_write_role_protocol_h1() argument
787 if (wsi->http.lcs && (((*wp) & 0x1f) == LWS_WRITE_HTTP_FINAL || in rops_write_role_protocol_h1()
798 n = lws_http_compression_transform(wsi, buf, len, wp, &out, &o); in rops_write_role_protocol_h1()
804 lws_wsi_tag(wsi), (int)len, in rops_write_role_protocol_h1()
805 (int)o, (int)*wp, wsi->http.comp_ctx.may_have_more); in rops_write_role_protocol_h1()
810 if (wsi->http.comp_ctx.chunking) { in rops_write_role_protocol_h1()
839 n = lws_issue_raw(wsi, (unsigned char *)buf, len); in rops_write_role_protocol_h1()
849 rops_alpn_negotiated_h1(struct lws *wsi, const char *alpn) in rops_alpn_negotiated_h1() argument
851 lwsl_debug("%s: client %d\n", __func__, lwsi_role_client(wsi)); in rops_alpn_negotiated_h1()
853 if (lwsi_role_client(wsi)) { in rops_alpn_negotiated_h1()
861 wsi->keepalive_active = 1; in rops_alpn_negotiated_h1()
869 rops_destroy_role_h1(struct lws *wsi) in rops_destroy_role_h1() argument
871 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in rops_destroy_role_h1()
876 __lws_header_table_detach(wsi, 0); in rops_destroy_role_h1()
881 if (ah->in_use && ah->wsi == wsi) { in rops_destroy_role_h1()
882 lwsl_err("%s: ah leak: wsi %s\n", __func__, in rops_destroy_role_h1()
883 lws_wsi_tag(wsi)); in rops_destroy_role_h1()
885 ah->wsi = NULL; in rops_destroy_role_h1()
893 lws_http_compression_destroy(wsi); in rops_destroy_role_h1()
897 lws_free_set_NULL(wsi->ws); in rops_destroy_role_h1()
905 rops_adoption_bind_h1(struct lws *wsi, int type, const char *vh_prot_name) in rops_adoption_bind_h1() argument
910 if (type & _LWS_ADOPT_FINISH && !lwsi_role_http(wsi)) in rops_adoption_bind_h1()
914 if (!lws_header_table_attach(wsi, 0)) in rops_adoption_bind_h1()
923 if (wsi->a.vhost->ss_handle && in rops_adoption_bind_h1()
924 wsi->a.vhost->ss_handle->policy->protocol == LWSSSP_RAW) { in rops_adoption_bind_h1()
925 lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? in rops_adoption_bind_h1()
934 …if ((!(type & LWS_ADOPT_ALLOW_SSL)) && (wsi->a.vhost->options & LWS_SERVER_OPTION_H2_PRIOR_KNOWLED… in rops_adoption_bind_h1()
936 lws_metrics_tag_wsi_add(wsi, "upg", "h2_prior"); in rops_adoption_bind_h1()
937 lws_role_call_alpn_negotiated(wsi, "h2"); in rops_adoption_bind_h1()
941 lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? in rops_adoption_bind_h1()
950 if (!vh_prot_name && wsi->a.vhost->default_protocol_index < in rops_adoption_bind_h1()
951 wsi->a.vhost->count_protocols) in rops_adoption_bind_h1()
952 wsi->a.protocol = &wsi->a.vhost->protocols[ in rops_adoption_bind_h1()
953 wsi->a.vhost->default_protocol_index]; in rops_adoption_bind_h1()
955 wsi->a.protocol = &wsi->a.vhost->protocols[0]; in rops_adoption_bind_h1()
958 lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, in rops_adoption_bind_h1()
959 (int)wsi->a.context->timeout_secs); in rops_adoption_bind_h1()
973 rops_client_bind_h1(struct lws *wsi, const struct lws_client_connect_info *i) in rops_client_bind_h1() argument
986 if (!wsi->user_space && wsi->stash->cis[CIS_METHOD]) in rops_client_bind_h1()
987 if (lws_ensure_user_space(wsi)) in rops_client_bind_h1()
1000 if (!wsi->stash->cis[CIS_METHOD] && !wsi->stash->cis[CIS_ALPN]) in rops_client_bind_h1()
1001 wsi->stash->cis[CIS_ALPN] = "http/1.1"; in rops_client_bind_h1()
1008 if (lws_header_table_attach(wsi, 0) in rops_client_bind_h1()
1035 if (lws_create_client_ws_object(i, wsi)) in rops_client_bind_h1()
1058 lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, &role_ops_h1); in rops_client_bind_h1()
1068 rops_close_kill_connection_h1(struct lws *wsi, enum lws_close_status reason) in rops_close_kill_connection_h1() argument
1071 if (!wsi->http.proxy_clientside) in rops_close_kill_connection_h1()
1074 wsi->http.proxy_clientside = 0; in rops_close_kill_connection_h1()
1076 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, in rops_close_kill_connection_h1()
1078 wsi->user_space, NULL, 0)) in rops_close_kill_connection_h1()