Lines Matching full:wsi

134 void lws_h2_init(struct lws *wsi)  in lws_h2_init()  argument
136 wsi->h2.h2n->our_set = wsi->a.vhost->h2.set; in lws_h2_init()
137 wsi->h2.h2n->peer_set = lws_h2_defaults; in lws_h2_init()
141 lws_h2_state(struct lws *wsi, enum lws_h2_states s) in lws_h2_state() argument
143 if (!wsi) in lws_h2_state()
145 lwsl_info("%s: %s: state %s -> %s\n", __func__, lws_wsi_tag(wsi), in lws_h2_state()
146 h2_state_names[wsi->h2.h2_state], in lws_h2_state()
150 wsi->h2.h2_state = (uint8_t)s; in lws_h2_state()
154 lws_h2_update_peer_txcredit(struct lws *wsi, unsigned int sid, int bump) in lws_h2_update_peer_txcredit() argument
156 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_update_peer_txcredit()
159 assert(wsi); in lws_h2_update_peer_txcredit()
165 sid = wsi->mux.my_sid; in lws_h2_update_peer_txcredit()
168 (int)wsi->txc.peer_tx_cr_est + bump); in lws_h2_update_peer_txcredit()
176 wsi->txc.peer_tx_cr_est += bump; in lws_h2_update_peer_txcredit()
178 lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); in lws_h2_update_peer_txcredit()
180 lws_pps_schedule(wsi, pps); in lws_h2_update_peer_txcredit()
198 lws_h2_get_peer_txcredit_estimate(struct lws *wsi) in lws_h2_get_peer_txcredit_estimate() argument
200 lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); in lws_h2_get_peer_txcredit_estimate()
201 return (int)wsi->txc.peer_tx_cr_est; in lws_h2_get_peer_txcredit_estimate()
205 lws_h2_update_peer_txcredit_thresh(struct lws *wsi, unsigned int sid, int threshold, int bump) in lws_h2_update_peer_txcredit_thresh() argument
207 if (wsi->txc.peer_tx_cr_est > threshold) in lws_h2_update_peer_txcredit_thresh()
210 return lws_h2_update_peer_txcredit(wsi, sid, bump); in lws_h2_update_peer_txcredit_thresh()
223 struct lws *wsi; in __lws_wsi_server_new() local
263 wsi = lws_create_new_server_wsi(vh, parent_wsi->tsi, tmp); in __lws_wsi_server_new()
264 if (!wsi) { in __lws_wsi_server_new()
265 lwsl_notice("new server wsi failed (%s)\n", lws_vh_tag(vh)); in __lws_wsi_server_new()
271 lws_metrics_caliper_bind(wsi->cal_conn, wsi->a.context->mth_srv); in __lws_wsi_server_new()
277 lws_wsi_mux_insert(wsi, parent_wsi, sid); in __lws_wsi_server_new()
281 wsi->mux_substream = 1; in __lws_wsi_server_new()
282 wsi->seen_nonpseudoheader = 0; in __lws_wsi_server_new()
284 wsi->txc.tx_cr = (int32_t)nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; in __lws_wsi_server_new()
285 wsi->txc.peer_tx_cr_est = in __lws_wsi_server_new()
288 lwsi_set_state(wsi, LRS_ESTABLISHED); in __lws_wsi_server_new()
289 lwsi_set_role(wsi, lwsi_role(parent_wsi)); in __lws_wsi_server_new()
291 wsi->a.protocol = &vh->protocols[0]; in __lws_wsi_server_new()
292 if (lws_ensure_user_space(wsi)) in __lws_wsi_server_new()
296 if (lws_adopt_ss_server_accept(wsi)) in __lws_wsi_server_new()
301 lws_validity_confirmed(wsi); in __lws_wsi_server_new()
304 lws_wsi_tag(parent_wsi), lws_wsi_tag(wsi), sid, wsi->user_space); in __lws_wsi_server_new()
306 lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); in __lws_wsi_server_new()
309 return wsi; in __lws_wsi_server_new()
313 parent_wsi->mux.child_list = wsi->mux.sibling_list; in __lws_wsi_server_new()
316 if (wsi->user_space) in __lws_wsi_server_new()
317 lws_free_set_NULL(wsi->user_space); in __lws_wsi_server_new()
318 vh->protocols[0].callback(wsi, LWS_CALLBACK_WSI_DESTROY, NULL, NULL, 0); in __lws_wsi_server_new()
319 __lws_vhost_unbind_wsi(wsi); in __lws_wsi_server_new()
320 lws_free(wsi); in __lws_wsi_server_new()
326 lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi) in lws_wsi_h2_adopt() argument
339 wsi->seen_nonpseudoheader = 0; in lws_wsi_h2_adopt()
341 wsi->client_mux_substream = 1; in lws_wsi_h2_adopt()
343 wsi->h2.initialized = 1; in lws_wsi_h2_adopt()
347 if (!wsi->mux.my_sid) { in lws_wsi_h2_adopt()
348 wsi->mux.my_sid = nwsi->h2.h2n->highest_sid; in lws_wsi_h2_adopt()
353 lwsl_info("%s: binding wsi %s to sid %d (next %d)\n", __func__, in lws_wsi_h2_adopt()
354 lws_wsi_tag(wsi), (int)wsi->mux.my_sid, (int)nwsi->h2.h2n->highest_sid); in lws_wsi_h2_adopt()
356 lws_wsi_mux_insert(wsi, parent_wsi, wsi->mux.my_sid); in lws_wsi_h2_adopt()
358 wsi->txc.tx_cr = (int32_t)nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; in lws_wsi_h2_adopt()
359 wsi->txc.peer_tx_cr_est = (int32_t) in lws_wsi_h2_adopt()
362 lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); in lws_wsi_h2_adopt()
364 if (lws_ensure_user_space(wsi)) in lws_wsi_h2_adopt()
367 lws_role_transition(wsi, LWSIFR_CLIENT, LRS_H2_WAITING_TO_SEND_HEADERS, in lws_wsi_h2_adopt()
370 lws_callback_on_writable(wsi); in lws_wsi_h2_adopt()
372 return wsi; in lws_wsi_h2_adopt()
376 parent_wsi->mux.child_list = wsi->mux.sibling_list; in lws_wsi_h2_adopt()
379 if (wsi->user_space) in lws_wsi_h2_adopt()
380 lws_free_set_NULL(wsi->user_space); in lws_wsi_h2_adopt()
381 wsi->a.protocol->callback(wsi, LWS_CALLBACK_WSI_DESTROY, NULL, NULL, 0); in lws_wsi_h2_adopt()
382 lws_free(wsi); in lws_wsi_h2_adopt()
389 lws_h2_issue_preface(struct lws *wsi) in lws_h2_issue_preface() argument
391 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_issue_preface()
402 lwsl_debug("%s: %s: fd %d\n", __func__, lws_wsi_tag(wsi), (int)wsi->desc.sockfd); in lws_h2_issue_preface()
404 if (lws_issue_raw(wsi, (uint8_t *)preface, strlen(preface)) != in lws_h2_issue_preface()
410 lws_role_transition(wsi, LWSIFR_CLIENT, LRS_H2_WAITING_TO_SEND_HEADERS, in lws_h2_issue_preface()
414 wsi->txc.tx_cr = 65535; in lws_h2_issue_preface()
422 lws_pps_schedule(wsi, pps); in lws_h2_issue_preface()
429 lws_pps_schedule(struct lws *wsi, struct lws_h2_protocol_send *pps) in lws_pps_schedule() argument
431 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_pps_schedule()
436 lws_rx_flow_control(wsi, LWS_RXFLOW_REASON_APPLIES_DISABLE | in lws_pps_schedule()
438 lws_callback_on_writable(wsi); in lws_pps_schedule()
442 lws_h2_goaway(struct lws *wsi, uint32_t err, const char *reason) in lws_h2_goaway() argument
444 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_goaway()
454 lwsl_info("%s: %s: ERR 0x%x, '%s'\n", __func__, lws_wsi_tag(wsi), (int)err, reason); in lws_h2_goaway()
459 lws_pps_schedule(wsi, pps); in lws_h2_goaway()
467 lws_h2_rst_stream(struct lws *wsi, uint32_t err, const char *reason) in lws_h2_rst_stream() argument
469 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_rst_stream()
476 if (!wsi->h2_stream_carries_ws && h2n->type == LWS_H2_FRAME_TYPE_COUNT) in lws_h2_rst_stream()
484 (int)err, wsi->mux.my_sid, reason); in lws_h2_rst_stream()
486 pps->u.rs.sid = wsi->mux.my_sid; in lws_h2_rst_stream()
489 lws_pps_schedule(wsi, pps); in lws_h2_rst_stream()
492 lws_h2_state(wsi, LWS_H2_STATE_CLOSED); in lws_h2_rst_stream()
498 lws_h2_settings(struct lws *wsi, struct http2_settings *settings, in lws_h2_settings() argument
501 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_settings()
539 if (wsi->flags & LCCSCF_H2_QUIRK_OVERFLOWS_TXCR && in lws_h2_settings()
578 if (b < wsi->a.vhost->h2.set.s[H2SET_MAX_FRAME_SIZE]) { in lws_h2_settings()
626 lws_h2_tx_cr_get(struct lws *wsi) in lws_h2_tx_cr_get() argument
628 int c = wsi->txc.tx_cr; in lws_h2_tx_cr_get()
629 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_tx_cr_get()
631 if (!wsi->mux_substream && !nwsi->upgraded_to_http2) in lws_h2_tx_cr_get()
635 __func__, lws_wsi_tag(wsi), c, (int)nwsi->txc.tx_cr); in lws_h2_tx_cr_get()
647 lws_h2_tx_cr_consume(struct lws *wsi, int consumed) in lws_h2_tx_cr_consume() argument
649 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_tx_cr_consume()
651 wsi->txc.tx_cr -= consumed; in lws_h2_tx_cr_consume()
653 if (nwsi != wsi) in lws_h2_tx_cr_consume()
657 int lws_h2_frame_write(struct lws *wsi, int type, int flags, in lws_h2_frame_write() argument
660 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_frame_write()
664 //if (wsi->h2_stream_carries_ws) in lws_h2_frame_write()
678 "txcr=%d, nwsi->txcr=%d\n", __func__, lws_wsi_tag(wsi), in lws_h2_frame_write()
680 sid, len, (int)wsi->txc.tx_cr, (int)nwsi->txc.tx_cr); in lws_h2_frame_write()
683 if (wsi->txc.tx_cr < (int)len) in lws_h2_frame_write()
687 lws_wsi_tag(wsi), len, (int)wsi->txc.tx_cr); in lws_h2_frame_write()
688 lws_h2_tx_cr_consume(wsi, (int)len); in lws_h2_frame_write()
702 static void lws_h2_set_bin(struct lws *wsi, int n, unsigned char *buf) in lws_h2_set_bin() argument
706 *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 24); in lws_h2_set_bin()
707 *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 16); in lws_h2_set_bin()
708 *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 8); in lws_h2_set_bin()
709 *buf = (uint8_t)wsi->h2.h2n->our_set.s[n]; in lws_h2_set_bin()
714 int lws_h2_do_pps_send(struct lws *wsi) in lws_h2_do_pps_send() argument
716 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_do_pps_send()
738 lwsl_info("%s: %s: %d\n", __func__, lws_wsi_tag(wsi), pps->type); in lws_h2_do_pps_send()
752 wsi->h2.h2n->our_set.s[n]); in lws_h2_do_pps_send()
754 lws_h2_set_bin(wsi, n, &set[LWS_PRE + m]); in lws_h2_do_pps_send()
757 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, in lws_h2_do_pps_send()
778 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, in lws_h2_do_pps_send()
789 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, 1, in lws_h2_do_pps_send()
796 wsi->h2_acked_settings = 0; in lws_h2_do_pps_send()
798 if (lwsi_state(wsi) == LRS_H2_AWAIT_SETTINGS) { in lws_h2_do_pps_send()
799 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_h2_do_pps_send()
801 wsi->http.fop_fd = NULL; in lws_h2_do_pps_send()
803 if (lws_is_ssl(lws_get_network_wsi(wsi))) in lws_h2_do_pps_send()
806 if (wsi->a.vhost->options & in lws_h2_do_pps_send()
815 lws_context_lock(wsi->a.context, "h2 mig"); in lws_h2_do_pps_send()
816 lws_vhost_lock(wsi->a.vhost); in lws_h2_do_pps_send()
818 h2n->swsi = __lws_wsi_server_new(wsi->a.vhost, wsi, 1); in lws_h2_do_pps_send()
820 lws_vhost_unlock(wsi->a.vhost); in lws_h2_do_pps_send()
821 lws_context_unlock(wsi->a.context); in lws_h2_do_pps_send()
827 h2n->swsi->http.ah = wsi->http.ah; in lws_h2_do_pps_send()
828 wsi->http.ah = NULL; in lws_h2_do_pps_send()
864 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_PING, flags, in lws_h2_do_pps_send()
887 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_GOAWAY, 0, in lws_h2_do_pps_send()
903 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_RST_STREAM, in lws_h2_do_pps_send()
909 cwsi = lws_wsi_mux_from_id(wsi, pps->u.rs.sid); in lws_h2_do_pps_send()
911 lwsl_debug("%s: closing cwsi %s %s %s (wsi %s)\n", in lws_h2_do_pps_send()
914 cwsi->a.protocol->name, lws_wsi_tag(wsi)); in lws_h2_do_pps_send()
927 n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_WINDOW_UPDATE, in lws_h2_do_pps_send()
951 lws_h2_parse_end_of_frame(struct lws *wsi);
958 lws_h2_parse_frame_header(struct lws *wsi) in lws_h2_parse_frame_header() argument
960 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_parse_frame_header()
968 h2n->swsi = wsi; in lws_h2_parse_frame_header()
975 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, pes); in lws_h2_parse_frame_header()
980 /* let the network wsi live a bit longer if subs are active */ in lws_h2_parse_frame_header()
982 if (!wsi->immortal_substream_count) in lws_h2_parse_frame_header()
983 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, in lws_h2_parse_frame_header()
984 wsi->a.vhost->keepalive_timeout ? in lws_h2_parse_frame_header()
985 wsi->a.vhost->keepalive_timeout : 31); in lws_h2_parse_frame_header()
988 h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); in lws_h2_parse_frame_header()
991 lws_wsi_tag(wsi), lws_wsi_tag(h2n->swsi), h2n->type, in lws_h2_parse_frame_header()
1015 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1029 && wsi->client_h2_alpn in lws_h2_parse_frame_header()
1041 lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, in lws_h2_parse_frame_header()
1047 /* if the sid is credible, treat as wsi for it closed */ in lws_h2_parse_frame_header()
1054 lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, in lws_h2_parse_frame_header()
1072 lws_h2_goaway(wsi, (unsigned int)n, "invalid rx for state"); in lws_h2_parse_frame_header()
1088 lws_h2_goaway(wsi, (unsigned int)n, "Continuation hdrs State"); in lws_h2_parse_frame_header()
1098 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "DATA 0 sid"); in lws_h2_parse_frame_header()
1115 lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, "conn closed"); in lws_h2_parse_frame_header()
1120 lws_h2_parse_end_of_frame(wsi); in lws_h2_parse_frame_header()
1127 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1132 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1139 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "Server only"); in lws_h2_parse_frame_header()
1152 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1157 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1168 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1175 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1183 if (wsi->upgraded_to_http2 && in lws_h2_parse_frame_header()
1185 (!(wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) || in lws_h2_parse_frame_header()
1189 !wsi->h2_acked_settings)) { in lws_h2_parse_frame_header()
1194 lws_pps_schedule(wsi, pps); in lws_h2_parse_frame_header()
1195 wsi->h2_acked_settings = 1; in lws_h2_parse_frame_header()
1202 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1209 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1214 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1228 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1234 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1245 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "sid 0"); in lws_h2_parse_frame_header()
1252 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1258 if (wsi->client_h2_alpn) { in lws_h2_parse_frame_header()
1260 h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); in lws_h2_parse_frame_header()
1262 "to wsi %s\n", lws_wsi_tag(wsi), in lws_h2_parse_frame_header()
1274 if (wsi->mux.child_count + 1 > in lws_h2_parse_frame_header()
1275 wsi->h2.h2n->our_set.s[H2SET_MAX_CONCURRENT_STREAMS]) { in lws_h2_parse_frame_header()
1276 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1287 lws_context_lock(wsi->a.context, "h2 new str"); in lws_h2_parse_frame_header()
1288 lws_vhost_lock(wsi->a.vhost); in lws_h2_parse_frame_header()
1290 h2n->swsi = __lws_wsi_server_new(wsi->a.vhost, wsi, in lws_h2_parse_frame_header()
1293 lws_vhost_unlock(wsi->a.vhost); in lws_h2_parse_frame_header()
1294 lws_context_unlock(wsi->a.context); in lws_h2_parse_frame_header()
1297 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_frame_header()
1314 * ah needs attaching to child wsi, even though in lws_h2_parse_frame_header()
1315 * we only fill it from network wsi in lws_h2_parse_frame_header()
1333 lws_start_foreach_ll(struct lws *, w, wsi->mux.child_list) { in lws_h2_parse_frame_header()
1381 lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, in lws_h2_parse_frame_header()
1389 lws_h2_parse_end_of_frame(wsi); in lws_h2_parse_frame_header()
1429 * wsi with a pending partial send... we may call lws_http_action() to send
1432 * So in that case we change the wsi state and do the lws_http_action() in the
1436 lws_h2_parse_end_of_frame(struct lws *wsi) in lws_h2_parse_end_of_frame() argument
1438 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_parse_end_of_frame()
1439 struct lws *eff_wsi = wsi; in lws_h2_parse_end_of_frame()
1447 h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); in lws_h2_parse_end_of_frame()
1453 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "depends on own sid"); in lws_h2_parse_end_of_frame()
1462 if (wsi->client_h2_alpn && !wsi->client_mux_migrated && in lws_h2_parse_end_of_frame()
1468 wsi->http.fop_fd = NULL; in lws_h2_parse_end_of_frame()
1471 wsi->client_mux_migrated = 1; in lws_h2_parse_end_of_frame()
1476 lws_context_lock(wsi->a.context, "h2 mig"); in lws_h2_parse_end_of_frame()
1477 lws_vhost_lock(wsi->a.vhost); in lws_h2_parse_end_of_frame()
1479 h2n->swsi = __lws_wsi_server_new(wsi->a.vhost, wsi, 1); in lws_h2_parse_end_of_frame()
1481 lws_vhost_unlock(wsi->a.vhost); in lws_h2_parse_end_of_frame()
1482 lws_context_unlock(wsi->a.context); in lws_h2_parse_end_of_frame()
1488 assert(lws_wsi_mux_from_id(wsi, 1) == h2n->swsi); in lws_h2_parse_end_of_frame()
1490 // lws_role_transition(wsi, LWSIFR_CLIENT, in lws_h2_parse_end_of_frame()
1499 h2n->swsi->http.ah = wsi->http.ah; in lws_h2_parse_end_of_frame()
1501 lws_fi_import(&h2n->swsi->fic, &wsi->fic); in lws_h2_parse_end_of_frame()
1506 h2n->swsi->flags = wsi->flags; in lws_h2_parse_end_of_frame()
1512 h2n->swsi->conmon = wsi->conmon; in lws_h2_parse_end_of_frame()
1513 h2n->swsi->conmon_datum = wsi->conmon_datum; in lws_h2_parse_end_of_frame()
1514 h2n->swsi->sa46_peer = wsi->sa46_peer; in lws_h2_parse_end_of_frame()
1515 wsi->conmon.dns_results_copy = NULL; in lws_h2_parse_end_of_frame()
1520 if (wsi->for_ss) { in lws_h2_parse_end_of_frame()
1521 lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); in lws_h2_parse_end_of_frame()
1524 wsi->for_ss = 0; in lws_h2_parse_end_of_frame()
1526 if (h->wsi == wsi) in lws_h2_parse_end_of_frame()
1527 h->wsi = h2n->swsi; in lws_h2_parse_end_of_frame()
1531 h2n->swsi->a.protocol = wsi->a.protocol; in lws_h2_parse_end_of_frame()
1535 h2n->swsi->user_space = wsi->user_space; in lws_h2_parse_end_of_frame()
1537 wsi->user_space_externally_allocated; in lws_h2_parse_end_of_frame()
1538 h2n->swsi->a.opaque_user_data = wsi->a.opaque_user_data; in lws_h2_parse_end_of_frame()
1539 wsi->a.opaque_user_data = NULL; in lws_h2_parse_end_of_frame()
1541 wsi->txc.manual_initial_tx_credit; in lws_h2_parse_end_of_frame()
1544 lws_strncpy(h2n->swsi->alpn, wsi->alpn, in lws_h2_parse_end_of_frame()
1545 sizeof(wsi->alpn)); in lws_h2_parse_end_of_frame()
1548 wsi->user_space = NULL; in lws_h2_parse_end_of_frame()
1551 h2n->swsi->http.ah->wsi = h2n->swsi; in lws_h2_parse_end_of_frame()
1552 wsi->http.ah = NULL; in lws_h2_parse_end_of_frame()
1555 lws_wsi_tag(wsi), lws_wsi_tag(h2n->swsi)); in lws_h2_parse_end_of_frame()
1564 if (!wsi->h2.initialized) { in lws_h2_parse_end_of_frame()
1565 wsi->txc.tx_cr = (int32_t) in lws_h2_parse_end_of_frame()
1570 lws_wsi_tag(wsi), (int)wsi->txc.tx_cr); in lws_h2_parse_end_of_frame()
1571 wsi->h2.initialized = 1; in lws_h2_parse_end_of_frame()
1576 if (!wsi->h2_acked_settings || in lws_h2_parse_end_of_frame()
1577 !(wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) in lws_h2_parse_end_of_frame()
1582 lws_pps_schedule(wsi, pps); in lws_h2_parse_end_of_frame()
1584 wsi->h2_acked_settings = 1; in lws_h2_parse_end_of_frame()
1589 lws_wsi_mux_apply_queue(wsi); in lws_h2_parse_end_of_frame()
1603 lws_h2_goaway(wsi, H2_ERR_COMPRESSION_ERROR, in lws_h2_parse_end_of_frame()
1623 lws_h2_goaway(wsi, H2_ERR_COMPRESSION_ERROR, in lws_h2_parse_end_of_frame()
1638 lwsl_info("http req, %s, h2n->swsi=%s\n", lws_wsi_tag(wsi), in lws_h2_parse_end_of_frame()
1650 * In that case, the wsi survives having being reset in lws_h2_parse_end_of_frame()
1707 lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, in lws_h2_parse_end_of_frame()
1754 __func__, lws_wsi_tag(wsi), in lws_h2_parse_end_of_frame()
1765 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_end_of_frame()
1777 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_end_of_frame()
1869 lws_validity_confirmed(wsi); in lws_h2_parse_end_of_frame()
1880 lws_pps_schedule(wsi, pps); in lws_h2_parse_end_of_frame()
1900 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_end_of_frame()
1922 lws_h2_goaway(wsi, H2_ERR_FLOW_CONTROL_ERROR, in lws_h2_parse_end_of_frame()
1928 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parse_end_of_frame()
1950 lws_start_foreach_ll(struct lws *, w, wsi->mux.child_list) { in lws_h2_parse_end_of_frame()
1986 * This may want to send something on the network wsi, which may be in the
1990 * The read parser for the network wsi has no choice but to parse its stream
1995 * wsi, we must change its state and handle it as a priority in the
1998 * About closing... for the main network wsi, it should return nonzero to
2002 lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, in lws_h2_parser() argument
2005 struct lws_h2_netconn *h2n = wsi->h2.h2n; in lws_h2_parser()
2017 switch (lwsi_state(wsi)) { in lws_h2_parser()
2025 lwsl_info("http2: %s: established\n", lws_wsi_tag(wsi)); in lws_h2_parser()
2026 lwsi_set_state(wsi, LRS_H2_AWAIT_SETTINGS); in lws_h2_parser()
2027 lws_validity_confirmed(wsi); in lws_h2_parser()
2029 wsi->txc.tx_cr = 65535; in lws_h2_parser()
2039 lws_pps_schedule(wsi, pps); in lws_h2_parser()
2071 lws_h2_goaway(wsi, in lws_h2_parser()
2097 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parser()
2104 /* applies to wsi->h2.swsi which may be wsi */ in lws_h2_parser()
2113 lws_h2_settings(wsi, &h2n->peer_set, in lws_h2_parser()
2165 * let the network wsi live a bit longer if in lws_h2_parser()
2169 if (!wsi->immortal_substream_count) in lws_h2_parser()
2170 lws_set_timeout(wsi, in lws_h2_parser()
2172 wsi->a.vhost->keepalive_timeout ? in lws_h2_parser()
2173 wsi->a.vhost->keepalive_timeout : 31); in lws_h2_parser()
2209 lws_h2_goaway(wsi, in lws_h2_parser()
2236 wsi->txc.peer_tx_cr_est -= n; in lws_h2_parser()
2270 * to the pt list of wsi holding buflist in lws_h2_parser()
2300 &wsi->buflist, NULL))) { in lws_h2_parser()
2324 wsi->txc.peer_tx_cr_est -= n; in lws_h2_parser()
2354 lws_h2_update_peer_txcredit(wsi, 0, n); in lws_h2_parser()
2371 lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, in lws_h2_parser()
2424 n = lws_h2_parse_end_of_frame(wsi); in lws_h2_parser()
2470 lws_h2_parse_frame_header(wsi)) in lws_h2_parser()
2507 lws_h2_client_handshake(struct lws *wsi) in lws_h2_client_handshake() argument
2509 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in lws_h2_client_handshake()
2511 char *meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD), in lws_h2_client_handshake()
2512 *uri = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI), *simp; in lws_h2_client_handshake()
2513 struct lws *nwsi = lws_get_network_wsi(wsi); in lws_h2_client_handshake()
2536 wsi->mux.my_sid = nwsi->h2.h2n->highest_sid_opened = sid; in lws_h2_client_handshake()
2538 lws_wsi_tag(wsi), sid); in lws_h2_client_handshake()
2542 __func__, wsi->mux.my_sid); in lws_h2_client_handshake()
2545 end = start + (wsi->a.context->pt_serv_buf_size / 2) - LWS_PRE - 1; in lws_h2_client_handshake()
2554 if (lws_add_http_header_by_token(wsi, in lws_h2_client_handshake()
2560 if (lws_add_http_header_by_token(wsi, in lws_h2_client_handshake()
2567 n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI); in lws_h2_client_handshake()
2571 if (wsi->stash && wsi->stash->cis[CIS_PATH]) { in lws_h2_client_handshake()
2572 path = wsi->stash->cis[CIS_PATH]; in lws_h2_client_handshake()
2582 if (n && lws_add_http_header_by_token(wsi, in lws_h2_client_handshake()
2587 n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_HOST); in lws_h2_client_handshake()
2588 simp = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST); in lws_h2_client_handshake()
2589 if (!n && wsi->stash && wsi->stash->cis[CIS_ADDRESS]) { in lws_h2_client_handshake()
2590 n = (int)strlen(wsi->stash->cis[CIS_ADDRESS]); in lws_h2_client_handshake()
2591 simp = wsi->stash->cis[CIS_ADDRESS]; in lws_h2_client_handshake()
2594 // n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_ORIGIN); in lws_h2_client_handshake()
2595 // simp = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN); in lws_h2_client_handshake()
2597 if (n && simp && lws_add_http_header_by_token(wsi, in lws_h2_client_handshake()
2604 if (/*!wsi->client_h2_alpn && */n && simp && in lws_h2_client_handshake()
2605 lws_add_http_header_by_token(wsi, WSI_TOKEN_HOST, in lws_h2_client_handshake()
2610 if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) { in lws_h2_client_handshake()
2611 p1 = lws_http_multipart_headers(wsi, p); in lws_h2_client_handshake()
2617 if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) { in lws_h2_client_handshake()
2618 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, in lws_h2_client_handshake()
2622 lws_client_http_body_pending(wsi, 1); in lws_h2_client_handshake()
2628 if (wsi->flags & LCCSCF_CACHE_COOKIES) in lws_h2_client_handshake()
2629 lws_cookie_send_cookies(wsi, (char **)&p, (char *)end); in lws_h2_client_handshake()
2632 if (wsi->a.protocol->callback(wsi, in lws_h2_client_handshake()
2634 wsi->user_space, &p, lws_ptr_diff_size_t(end, p) - 12)) in lws_h2_client_handshake()
2637 if (lws_finalize_http_header(wsi, &p, end)) in lws_h2_client_handshake()
2644 if ((wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) && in lws_h2_client_handshake()
2645 !(wsi->client_http_body_pending || lws_has_buffered_out(wsi))) in lws_h2_client_handshake()
2651 n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)m); in lws_h2_client_handshake()
2666 if (wsi->flags & LCCSCF_H2_MANUAL_RXFLOW) { in lws_h2_client_handshake()
2667 n = wsi->txc.manual_initial_tx_credit; in lws_h2_client_handshake()
2668 wsi->txc.manual = 1; in lws_h2_client_handshake()
2671 if (lws_h2_update_peer_txcredit(wsi, wsi->mux.my_sid, n)) in lws_h2_client_handshake()
2674 lws_h2_state(wsi, LWS_H2_STATE_OPEN); in lws_h2_client_handshake()
2675 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_h2_client_handshake()
2677 if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) in lws_h2_client_handshake()
2678 lws_callback_on_writable(wsi); in lws_h2_client_handshake()
2691 lws_h2_ws_handshake(struct lws *wsi) in lws_h2_ws_handshake() argument
2700 if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) in lws_h2_ws_handshake()
2703 if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) > 64) in lws_h2_ws_handshake()
2706 if (wsi->proxied_ws_parent && wsi->child_list) { in lws_h2_ws_handshake()
2707 if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL)) { in lws_h2_ws_handshake()
2708 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_PROTOCOL, in lws_h2_ws_handshake()
2709 (uint8_t *)lws_hdr_simple_ptr(wsi, in lws_h2_ws_handshake()
2711 (int)strlen(lws_hdr_simple_ptr(wsi, in lws_h2_ws_handshake()
2720 if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) && in lws_h2_ws_handshake()
2722 wsi->a.protocol->name && wsi->a.protocol->name[0]) { in lws_h2_ws_handshake()
2733 if (wsi->a.vhost && wsi->a.vhost->ss_handle && in lws_h2_ws_handshake()
2734 wsi->a.vhost->ss_handle->policy->u.http.u.ws.subprotocol) { in lws_h2_ws_handshake()
2736 (lws_ss_handle_t *)wsi->a.opaque_user_data; in lws_h2_ws_handshake()
2738 lwsl_notice("%s: Server SS %s .wsi %s switching to ws protocol\n", in lws_h2_ws_handshake()
2739 __func__, lws_ss_tag(h), lws_wsi_tag(h->wsi)); in lws_h2_ws_handshake()
2741 wsi->a.protocol = &protocol_secstream_ws; in lws_h2_ws_handshake()
2751 lws_mux_mark_immortal(wsi); in lws_h2_ws_handshake()
2753 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_PROTOCOL, in lws_h2_ws_handshake()
2754 (unsigned char *)wsi->a.vhost->ss_handle->policy-> in lws_h2_ws_handshake()
2756 (int)strlen(wsi->a.vhost->ss_handle->policy-> in lws_h2_ws_handshake()
2762 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_PROTOCOL, in lws_h2_ws_handshake()
2763 (unsigned char *)wsi->a.protocol->name, in lws_h2_ws_handshake()
2764 (int)strlen(wsi->a.protocol->name), &p, end)) in lws_h2_ws_handshake()
2769 if (lws_finalize_http_header(wsi, &p, end)) in lws_h2_ws_handshake()
2774 n = lws_write(wsi, start, m, LWS_WRITE_HTTP_HEADERS); in lws_h2_ws_handshake()
2786 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_h2_ws_handshake()
2787 wsi->lws_rx_parse_state = 0; // ==LWS_RXPS_NEW; in lws_h2_ws_handshake()
2789 uri_ptr = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH); in lws_h2_ws_handshake()
2790 n = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH); in lws_h2_ws_handshake()
2791 hit = lws_find_mount(wsi, uri_ptr, n); in lws_h2_ws_handshake()
2794 wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, wsi->user_space, in lws_h2_ws_handshake()
2798 lws_validity_confirmed(wsi); in lws_h2_ws_handshake()
2805 lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len) in lws_read_h2() argument
2811 // wsi->wsistate, (int)len); in lws_read_h2()
2814 * wsi here is always the network connection wsi, not a stream in lws_read_h2()
2815 * wsi. Once we unpicked the framing we will find the right in lws_read_h2()
2829 if (lws_is_flowcontrolled(wsi)) { in lws_read_h2()
2830 lws_rxflow_cache(wsi, buf, 0, (size_t)len); in lws_read_h2()
2839 * situation on the network wsi... in lws_read_h2()
2843 * wsi in order to gain tx credit to send, which is in lws_read_h2()
2846 * ALL network wsi-specific frames are sent by PPS in lws_read_h2()
2849 * problem is when a stream wsi wants to send an, eg, in lws_read_h2()
2851 * we will do now... the *stream wsi* must stall in a in lws_read_h2()
2857 m = lws_h2_parser(wsi, buf, len, &body_chunk_len); in lws_read_h2()
2860 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, in lws_read_h2()
2879 lws_h2_client_stream_long_poll_rxonly(struct lws *wsi) in lws_h2_client_stream_long_poll_rxonly() argument
2882 if (!wsi->mux_substream) in lws_h2_client_stream_long_poll_rxonly()
2889 wsi->h2.long_poll = 1; in lws_h2_client_stream_long_poll_rxonly()
2890 wsi->h2.send_END_STREAM = 1; in lws_h2_client_stream_long_poll_rxonly()
2892 // lws_header_table_detach(wsi, 0); in lws_h2_client_stream_long_poll_rxonly()
2894 lws_callback_on_writable(wsi); in lws_h2_client_stream_long_poll_rxonly()