Lines Matching refs:wsi
66 struct lws *wsi = lws_container_of(d, struct lws, listen_list); in check_extant() local
69 if (!lws_vhost_compare_listen(wsi->a.vhost, a->vhost)) in check_extant()
72 if (wsi->af != a ->af) in check_extant()
75 lwsl_notice(" using listen skt from vhost %s\n", wsi->a.vhost->name); in check_extant()
91 struct lws *wsi; in _lws_vhost_init_server_af() local
303 wsi = __lws_wsi_create_with_role(cx, m, &role_ops_listen, NULL); in _lws_vhost_init_server_af()
305 if (wsi == NULL) { in _lws_vhost_init_server_af()
310 wsi->af = (uint8_t)a->af; in _lws_vhost_init_server_af()
316 wsi->unix_skt = 1; in _lws_vhost_init_server_af()
322 wsi->desc.sockfd = sockfd; in _lws_vhost_init_server_af()
323 wsi->a.protocol = a->vhost->protocols; in _lws_vhost_init_server_af()
324 lws_vhost_bind_wsi(a->vhost, wsi); in _lws_vhost_init_server_af()
325 wsi->listener = 1; in _lws_vhost_init_server_af()
327 if (wsi->a.context->event_loop_ops->init_vhost_listen_wsi) in _lws_vhost_init_server_af()
328 wsi->a.context->event_loop_ops->init_vhost_listen_wsi(wsi); in _lws_vhost_init_server_af()
333 if (__insert_wsi_socket_into_fds(cx, wsi)) { in _lws_vhost_init_server_af()
339 lws_dll2_add_tail(&wsi->listen_list, &a->vhost->listen_wsi); in _lws_vhost_init_server_af()
345 if (setsockopt(wsi->desc.sockfd, IPPROTO_TCP, in _lws_vhost_init_server_af()
358 if (setsockopt(wsi->desc.sockfd, SOL_TCP, TCP_FASTOPEN, in _lws_vhost_init_server_af()
365 n = listen(wsi->desc.sockfd, LWS_SOMAXCONN); in _lws_vhost_init_server_af()
368 lws_dll2_remove(&wsi->listen_list); in _lws_vhost_init_server_af()
369 __remove_wsi_socket_from_fds(wsi); in _lws_vhost_init_server_af()
373 if (wsi) in _lws_vhost_init_server_af()
376 &wsi->lc, "listen|%s|%s|%d", in _lws_vhost_init_server_af()
636 lws_vfs_prepare_flags(struct lws *wsi) in lws_vfs_prepare_flags() argument
640 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)) in lws_vfs_prepare_flags()
643 if (strstr(lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING), in lws_vfs_prepare_flags()
653 lws_http_serve(struct lws *wsi, char *uri, const char *origin, in lws_http_serve() argument
678 wsi->handling_404 = 0; in lws_http_serve()
679 if (!wsi->a.vhost) in lws_http_serve()
683 if (wsi->a.vhost->http.error_document_404 && in lws_http_serve()
684 !strcmp(uri, wsi->a.vhost->http.error_document_404)) in lws_http_serve()
685 wsi->handling_404 = 1; in lws_http_serve()
692 fflags |= lws_vfs_prepare_flags(wsi); in lws_http_serve()
696 fops = lws_vfs_select_fops(wsi->a.context->fops, path, &vpath); in lws_http_serve()
698 if (wsi->http.fop_fd) in lws_http_serve()
699 lws_vfs_file_close(&wsi->http.fop_fd); in lws_http_serve()
701 wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->a.context->fops, in lws_http_serve()
703 if (!wsi->http.fop_fd) { in lws_http_serve()
717 if (fstat(wsi->http.fop_fd->fd, &st)) { in lws_http_serve()
739 wsi->http.fop_fd->mod_time = (uint32_t)st.st_mtime; in lws_http_serve()
766 (unsigned long long)lws_vfs_get_length(wsi->http.fop_fd), in lws_http_serve()
767 (unsigned long)lws_vfs_get_mod_time(wsi->http.fop_fd)); in lws_http_serve()
771 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_IF_RANGE)) in lws_http_serve()
772 if (strcmp(sym, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_IF_RANGE))) in lws_http_serve()
774 wsi->http.ah->frag_index[WSI_TOKEN_HTTP_RANGE] = 0; in lws_http_serve()
776 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_IF_NONE_MATCH)) { in lws_http_serve()
781 if (!strcmp(sym, lws_hdr_simple_ptr(wsi, in lws_http_serve()
791 if (lws_add_http_header_status(wsi, in lws_http_serve()
798 if (lws_add_http_header_by_token(wsi, in lws_http_serve()
810 intermediates[wsi->cache_intermediaries], in lws_http_serve()
816 intermediates[wsi->cache_intermediaries], in lws_http_serve()
821 if (lws_add_http_header_by_token(wsi, in lws_http_serve()
826 if (lws_finalize_http_header(wsi, &p, end)) in lws_http_serve()
829 n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), in lws_http_serve()
838 lws_vfs_file_close(&wsi->http.fop_fd); in lws_http_serve()
840 if (lws_http_transaction_completed(wsi)) in lws_http_serve()
847 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_ETAG, in lws_http_serve()
855 if (lws_return_http_status(wsi, in lws_http_serve()
857 lws_http_transaction_completed(wsi)) in lws_http_serve()
865 wsi->sending_chunked = 0; in lws_http_serve()
866 wsi->interpreting = 0; in lws_http_serve()
876 wsi->interpreting = 1; in lws_http_serve()
877 if (!wsi->mux_substream) in lws_http_serve()
878 wsi->sending_chunked = 1; in lws_http_serve()
880 wsi->protocol_interpret_idx = (char)( in lws_http_serve()
881 lws_vhost_name_to_protocol(wsi->a.vhost, in lws_http_serve()
883 &lws_get_vhost(wsi)->protocols[0]); in lws_http_serve()
886 wsi->a.vhost->protocols[ in lws_http_serve()
887 (int)wsi->protocol_interpret_idx].name, in lws_http_serve()
888 wsi->a.protocol->name); in lws_http_serve()
889 if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[ in lws_http_serve()
890 (int)wsi->protocol_interpret_idx], __func__)) in lws_http_serve()
893 if (lws_ensure_user_space(wsi)) in lws_http_serve()
900 if (wsi->sending_chunked) { in lws_http_serve()
901 if (lws_add_http_header_by_token(wsi, in lws_http_serve()
910 wsi->a.vhost, m->protocol); in lws_http_serve()
912 if (lws_bind_protocol(wsi, pp, __func__)) in lws_http_serve()
916 if (pp->callback(wsi, LWS_CALLBACK_ADD_HEADERS, in lws_http_serve()
917 wsi->user_space, &args, 0)) in lws_http_serve()
923 n = lws_serve_http_file(wsi, path, mimetype, (char *)start, in lws_http_serve()
926 if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi))) in lws_http_serve()
939 lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len) in lws_find_mount() argument
944 hm = wsi->a.vhost->http.mount_list; in lws_find_mount()
953 lws_metrics_tag_wsi_add(wsi, "mnt", hm->mountpoint); in lws_find_mount()
958 lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) || in lws_find_mount()
959 lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) || in lws_find_mount()
961 lws_hdr_total_length(wsi, WSI_TOKEN_PUT_URI) || in lws_find_mount()
962 lws_hdr_total_length(wsi, WSI_TOKEN_PATCH_URI) || in lws_find_mount()
963 lws_hdr_total_length(wsi, WSI_TOKEN_DELETE_URI) || in lws_find_mount()
965 lws_hdr_total_length(wsi, WSI_TOKEN_HEAD_URI) || in lws_find_mount()
967 (wsi->mux_substream && in lws_find_mount()
968 lws_hdr_total_length(wsi, in lws_find_mount()
1033 lws_unauthorised_basic_auth(struct lws *wsi) in lws_unauthorised_basic_auth() argument
1035 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in lws_unauthorised_basic_auth()
1043 if (lws_add_http_header_status(wsi, HTTP_STATUS_UNAUTHORIZED, &p, end)) in lws_unauthorised_basic_auth()
1047 if (lws_add_http_header_by_token(wsi, in lws_unauthorised_basic_auth()
1052 if (lws_add_http_header_content_length(wsi, 0, &p, end)) in lws_unauthorised_basic_auth()
1055 if (lws_finalize_http_header(wsi, &p, end)) in lws_unauthorised_basic_auth()
1058 n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS | in lws_unauthorised_basic_auth()
1063 return lws_http_transaction_completed(wsi); in lws_unauthorised_basic_auth()
1114 lws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len) in lws_http_get_uri_and_method() argument
1119 if (lws_hdr_total_length(wsi, methods[n])) in lws_http_get_uri_and_method()
1127 !((wsi->mux_substream || wsi->h2_stream_carries_ws) in lws_http_get_uri_and_method()
1130 lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH) in lws_http_get_uri_and_method()
1138 if (lws_hdr_total_length(wsi, methods[n])) { in lws_http_get_uri_and_method()
1139 *puri_ptr = lws_hdr_simple_ptr(wsi, methods[n]); in lws_http_get_uri_and_method()
1140 *puri_len = lws_hdr_total_length(wsi, methods[n]); in lws_http_get_uri_and_method()
1150 lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, in lws_check_basic_auth() argument
1161 ml = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_AUTHORIZATION); in lws_check_basic_auth()
1167 fi = wsi->http.ah->frag_index[WSI_TOKEN_HTTP_AUTHORIZATION]; in lws_check_basic_auth()
1168 if (wsi->http.ah->frags[fi].nfrag) { in lws_check_basic_auth()
1173 m = lws_hdr_copy(wsi, b64, sizeof(b64), in lws_check_basic_auth()
1209 bar = wsi->a.protocol->callback(wsi, in lws_check_basic_auth()
1211 wsi->user_space, plain, (unsigned int)m); in lws_check_basic_auth()
1226 wsi->http.ah->frags[fi].len = (uint16_t)lws_ptr_diff_size_t(pcolon, &plain[0]); in lws_check_basic_auth()
1227 pcolon = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_AUTHORIZATION); in lws_check_basic_auth()
1231 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_AUTHORIZATION)); in lws_check_basic_auth()
1248 lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit, in lws_http_proxy_start() argument
1255 …unsigned int max_http_header_data = wsi->a.context->max_http_header_data > 256 ? wsi->a.context->m… in lws_http_proxy_start()
1274 lws_bind_protocol(wsi, &lws_ws_proxy, __func__); in lws_http_proxy_start()
1277 i.context = lws_get_context(wsi); in lws_http_proxy_start()
1330 na = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_URI_ARGS); in lws_http_proxy_start()
1349 budg = lws_hdr_copy(wsi, p, in lws_http_proxy_start()
1367 n = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_AUTHORITY); in lws_http_proxy_start()
1369 i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_AUTHORITY); in lws_http_proxy_start()
1373 n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST); in lws_http_proxy_start()
1375 i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST); in lws_http_proxy_start()
1381 !lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)) in lws_http_proxy_start()
1384 i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST); in lws_http_proxy_start()
1388 if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_POST_URI) in lws_http_proxy_start()
1391 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD) && in lws_http_proxy_start()
1392 !strcmp(lws_hdr_simple_ptr(wsi, in lws_http_proxy_start()
1398 else if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_PUT_URI) in lws_http_proxy_start()
1401 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD) && in lws_http_proxy_start()
1402 !strcmp(lws_hdr_simple_ptr(wsi, in lws_http_proxy_start()
1408 else if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_PATCH_URI) in lws_http_proxy_start()
1411 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD) && in lws_http_proxy_start()
1412 !strcmp(lws_hdr_simple_ptr(wsi, in lws_http_proxy_start()
1418 else if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_DELETE_URI) in lws_http_proxy_start()
1421 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD) && in lws_http_proxy_start()
1422 !strcmp(lws_hdr_simple_ptr(wsi, in lws_http_proxy_start()
1434 wsi->a.vhost->listen_port); in lws_http_proxy_start()
1441 i.parent_wsi = wsi; in lws_http_proxy_start()
1444 i.protocol = lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL); in lws_http_proxy_start()
1464 lws_return_http_status(wsi, in lws_http_proxy_start()
1479 wsi->proxied_ws_parent = 1; in lws_http_proxy_start()
1498 lws_http_redirect_hit(struct lws_context_per_thread *pt, struct lws *wsi, in lws_http_redirect_hit() argument
1532 *end = p + wsi->a.context->pt_serv_buf_size - in lws_http_redirect_hit()
1546 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { in lws_http_redirect_hit()
1548 if (!lws_hdr_total_length(wsi, in lws_http_redirect_hit()
1554 "%s%s%s/", oprot[!!lws_is_ssl(wsi)], in lws_http_redirect_hit()
1555 lws_hdr_simple_ptr(wsi, in lws_http_redirect_hit()
1563 "%s%s%s/", oprot[!!lws_is_ssl(wsi)], in lws_http_redirect_hit()
1564 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), in lws_http_redirect_hit()
1569 n = lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, in lws_http_redirect_hit()
1574 return lws_http_transaction_completed(wsi); in lws_http_redirect_hit()
1580 lws_header_table_detach(wsi, 1); in lws_http_redirect_hit()
1586 lws_http_action(struct lws *wsi) in lws_http_action() argument
1588 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in lws_http_action()
1603 meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); in lws_http_action()
1607 lws_metrics_tag_wsi_add(wsi, "vh", wsi->a.vhost->name); in lws_http_action()
1608 lws_metrics_tag_wsi_add(wsi, "meth", method_names[meth]); in lws_http_action()
1613 lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); in lws_http_action()
1621 if (wsi->role_ops && in lws_http_action()
1622 lws_rops_fidx(wsi->role_ops, LWS_ROPS_check_upgrades)) in lws_http_action()
1623 switch (lws_rops_func_fidx(wsi->role_ops, in lws_http_action()
1625 check_upgrades(wsi)) { in lws_http_action()
1634 if (lws_ensure_user_space(wsi)) in lws_http_action()
1639 wsi->http.rx_content_length = 0; in lws_http_action()
1640 wsi->http.content_length_explicitly_zero = 0; in lws_http_action()
1641 if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) in lws_http_action()
1644 lws_hdr_total_length(wsi, WSI_TOKEN_PATCH_URI) || in lws_http_action()
1645 lws_hdr_total_length(wsi, WSI_TOKEN_PUT_URI) in lws_http_action()
1648 wsi->http.rx_content_length = 100 * 1024 * 1024; in lws_http_action()
1650 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && in lws_http_action()
1651 lws_hdr_copy(wsi, content_length_str, in lws_http_action()
1654 wsi->http.rx_content_remain = wsi->http.rx_content_length = in lws_http_action()
1656 if (!wsi->http.rx_content_length) { in lws_http_action()
1657 wsi->http.content_length_explicitly_zero = 1; in lws_http_action()
1662 if (wsi->mux_substream) { in lws_http_action()
1663 wsi->http.request_version = HTTP_VERSION_2; in lws_http_action()
1669 http_version_len = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP); in lws_http_action()
1671 lws_hdr_copy(wsi, http_version_str, in lws_http_action()
1677 wsi->http.request_version = request_version; in lws_http_action()
1686 if (lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION) && in lws_http_action()
1687 lws_hdr_copy(wsi, http_conn_str, sizeof(http_conn_str) - 1, in lws_http_action()
1696 wsi->http.conn_type = conn_type; in lws_http_action()
1699 n = (unsigned int)wsi->a.protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION, in lws_http_action()
1700 wsi->user_space, uri_ptr, (unsigned int)uri_len); in lws_http_action()
1710 if (!wsi->mux_stream_immortal) in lws_http_action()
1711 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, in lws_http_action()
1712 (int)wsi->a.context->timeout_secs); in lws_http_action()
1714 if (wsi->tls.redirect_to_https) { in lws_http_action()
1722 *end = p + wsi->a.context->pt_serv_buf_size - in lws_http_action()
1725 n = (unsigned int)lws_hdr_total_length(wsi, WSI_TOKEN_HOST); in lws_http_action()
1729 if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)) in lws_http_action()
1733 memcpy(p, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), n); in lws_http_action()
1745 while (lws_hdr_copy_fragment(wsi, (char *)p + 1, in lws_http_action()
1758 n = (unsigned int)lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, in lws_http_action()
1763 return lws_http_transaction_completed(wsi); in lws_http_action()
1768 lws_prepare_access_log_info(wsi, uri_ptr, uri_len, meth); in lws_http_action()
1773 hit = lws_find_mount(wsi, uri_ptr, uri_len); in lws_http_action()
1779 if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[0], in lws_http_action()
1783 lwsi_set_state(wsi, LRS_DOING_TRANSACTION); in lws_http_action()
1785 m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, in lws_http_action()
1786 wsi->user_space, uri_ptr, (unsigned int)uri_len); in lws_http_action()
1794 n = (unsigned int)lws_http_redirect_hit(pt, wsi, hit, uri_ptr, uri_len, &ha); in lws_http_action()
1802 switch (lws_check_basic_auth(wsi, hit->basic_auth_login_file, in lws_http_action()
1807 return lws_unauthorised_basic_auth(wsi); in lws_http_action()
1809 lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); in lws_http_action()
1810 return lws_http_transaction_completed(wsi); in lws_http_action()
1826 n = (unsigned int)lws_http_proxy_start(wsi, hit, uri_ptr, 0); in lws_http_action()
1847 pp = lws_vhost_name_to_protocol(wsi->a.vhost, name); in lws_http_action()
1854 if (lws_bind_protocol(wsi, pp, "http action CALLBACK bind")) in lws_http_action()
1866 n = (unsigned int)wsi->a.protocol->callback(wsi, in lws_http_action()
1868 wsi->user_space, &args, 0); in lws_http_action()
1870 lws_return_http_status(wsi, HTTP_STATUS_UNAUTHORIZED, in lws_http_action()
1877 if (hit->cgienv && wsi->a.protocol->callback(wsi, in lws_http_action()
1879 wsi->user_space, (void *)hit->cgienv, 0)) in lws_http_action()
1882 if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)) { in lws_http_action()
1883 m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, in lws_http_action()
1884 wsi->user_space, in lws_http_action()
1906 n = (unsigned int)lws_cgi(wsi, cmd, hit->mountpoint_len, (int)n, in lws_http_action()
1925 wsi->cache_secs = (unsigned int)hit->cache_max_age; in lws_http_action()
1926 wsi->cache_reuse = hit->cache_reusable; in lws_http_action()
1927 wsi->cache_revalidate = hit->cache_revalidate; in lws_http_action()
1928 wsi->cache_intermediaries = hit->cache_intermediaries; in lws_http_action()
1933 m = lws_http_serve(wsi, s, hit->origin, hit); in lws_http_action()
1944 wsi->a.vhost, hit->protocol); in lws_http_action()
1950 lwsi_set_state(wsi, LRS_DOING_TRANSACTION); in lws_http_action()
1952 if (lws_bind_protocol(wsi, pp, "http_action HTTP")) in lws_http_action()
1955 m = pp->callback(wsi, LWS_CALLBACK_HTTP, in lws_http_action()
1956 wsi->user_space, in lws_http_action()
1960 m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, in lws_http_action()
1961 wsi->user_space, uri_ptr, (size_t)uri_len); in lws_http_action()
1982 if (lwsi_state(wsi) == LRS_ISSUING_FILE) in lws_http_action()
1987 (long long)wsi->http.rx_content_length, in lws_http_action()
1988 wsi->upgraded_to_http2, wsi->mux_substream); in lws_http_action()
1990 if (wsi->http.content_length_explicitly_zero && in lws_http_action()
1991 lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)) { in lws_http_action()
2004 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY, in lws_http_action()
2005 wsi->user_space, NULL, 0)) in lws_http_action()
2007 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY_COMPLETION, in lws_http_action()
2008 wsi->user_space, NULL, 0)) in lws_http_action()
2014 if (wsi->http.rx_content_length <= 0) in lws_http_action()
2017 if (lwsi_state(wsi) != LRS_DISCARD_BODY) { in lws_http_action()
2018 lwsi_set_state(wsi, LRS_BODY); in lws_http_action()
2020 lws_wsi_tag(wsi), (int)wsi->wsistate); in lws_http_action()
2022 wsi->http.rx_content_remain = wsi->http.rx_content_length; in lws_http_action()
2035 ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist, in lws_http_action()
2041 m = lws_read_h1(wsi, ebuf.token, (lws_filepos_t)ebuf.len); in lws_http_action()
2045 if (lws_buflist_aware_finished_consuming(wsi, &ebuf, m, 1, in lws_http_action()
2053 lws_header_table_detach(wsi, 1); in lws_http_action()
2059 lws_confirm_host_header(struct lws *wsi) in lws_confirm_host_header() argument
2071 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { in lws_confirm_host_header()
2078 if (wsi->tls.ssl) in lws_confirm_host_header()
2082 n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_HOST); in lws_confirm_host_header()
2095 if (strncmp(ts.token, wsi->a.vhost->name, ts.token_len)) { in lws_confirm_host_header()
2098 __func__, ts.token, wsi->a.vhost->name); in lws_confirm_host_header()
2112 if (wsi->a.vhost->listen_port != port) { in lws_confirm_host_header()
2114 __func__, port, wsi->a.vhost->listen_port); in lws_confirm_host_header()
2130 lws_http_to_fallback(struct lws *wsi, unsigned char *obuf, size_t olen) in lws_http_to_fallback() argument
2134 &wsi->a.vhost->protocols[wsi->a.vhost->raw_protocol_index]; in lws_http_to_fallback()
2138 if (wsi->a.vhost->listen_accept_role && in lws_http_to_fallback()
2139 lws_role_by_name(wsi->a.vhost->listen_accept_role)) in lws_http_to_fallback()
2140 role = lws_role_by_name(wsi->a.vhost->listen_accept_role); in lws_http_to_fallback()
2142 if (wsi->a.vhost->listen_accept_protocol) { in lws_http_to_fallback()
2143 p1 = lws_vhost_name_to_protocol(wsi->a.vhost, in lws_http_to_fallback()
2144 wsi->a.vhost->listen_accept_protocol); in lws_http_to_fallback()
2149 lws_bind_protocol(wsi, protocol, __func__); in lws_http_to_fallback()
2151 lws_role_transition(wsi, LWSIFR_SERVER, LRS_ESTABLISHED, role); in lws_http_to_fallback()
2153 lws_header_table_detach(wsi, 0); in lws_http_to_fallback()
2154 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); in lws_http_to_fallback()
2157 if (wsi->role_ops->adoption_cb[1]) in lws_http_to_fallback()
2158 n = wsi->role_ops->adoption_cb[1]; in lws_http_to_fallback()
2162 lws_get_peer_simple(wsi, ipbuf, sizeof(ipbuf)); in lws_http_to_fallback()
2166 "protocol %s, cb %d, ah %p\n", __func__, wsi->a.vhost->name, in lws_http_to_fallback()
2168 wsi->http.ah); in lws_http_to_fallback()
2170 if ((wsi->a.protocol->callback)(wsi, (enum lws_callback_reasons)n, wsi->user_space, NULL, 0)) in lws_http_to_fallback()
2174 if (wsi->role_ops->rx_cb[lwsi_role_server(wsi)]) in lws_http_to_fallback()
2175 n = wsi->role_ops->rx_cb[lwsi_role_server(wsi)]; in lws_http_to_fallback()
2176 if (wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)n, wsi->user_space, obuf, olen)) in lws_http_to_fallback()
2183 lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len) in lws_handshake_server() argument
2185 struct lws_context *context = lws_get_context(wsi); in lws_handshake_server()
2186 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in lws_handshake_server()
2202 if (!wsi->http.ah) { in lws_handshake_server()
2208 if (!lwsi_role_server(wsi) || !lwsi_role_http(wsi)) { in lws_handshake_server()
2210 (int)lwsi_role(wsi)); in lws_handshake_server()
2215 m = lws_parse(wsi, *buf, &i); in lws_handshake_server()
2234 if (lws_http_to_fallback(wsi, obuf, olen)) { in lws_handshake_server()
2249 if (!wsi->http.ah) in lws_handshake_server()
2252 if (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) in lws_handshake_server()
2259 if (wsi->a.vhost->listen_port && in lws_handshake_server()
2260 lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { in lws_handshake_server()
2262 context, wsi->a.vhost->listen_port, in lws_handshake_server()
2263 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)); in lws_handshake_server()
2266 lws_vhost_bind_wsi(vhost, wsi); in lws_handshake_server()
2270 if ((!lwsi_role_h2(wsi) || !lwsi_role_server(wsi)) && in lws_handshake_server()
2271 (!wsi->conn_stat_done)) in lws_handshake_server()
2272 wsi->conn_stat_done = 1; in lws_handshake_server()
2276 if (wsi->a.context->reject_service_keywords) { in lws_handshake_server()
2278 wsi->a.context->reject_service_keywords; in lws_handshake_server()
2281 if (lws_hdr_copy(wsi, ua, sizeof(ua) - 1, in lws_handshake_server()
2297 lws_return_http_status(wsi, in lws_handshake_server()
2300 meth = lws_http_get_uri_and_method(wsi, in lws_handshake_server()
2303 lws_prepare_access_log_info(wsi, in lws_handshake_server()
2332 n = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); in lws_handshake_server()
2334 hit = lws_find_mount(wsi, uri_ptr, uri_len); in lws_handshake_server()
2336 n = lws_http_redirect_hit(pt, wsi, hit, uri_ptr, in lws_handshake_server()
2346 if (lws_hdr_total_length(wsi, WSI_TOKEN_CONNECT)) { in lws_handshake_server()
2351 lwsi_set_state(wsi, LRS_PRE_WS_SERVING_ACCEPT); in lws_handshake_server()
2352 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); in lws_handshake_server()
2354 if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) { in lws_handshake_server()
2356 const char *up = lws_hdr_simple_ptr(wsi, in lws_handshake_server()
2363 if (lws_return_http_status(wsi, in lws_handshake_server()
2365 lws_http_transaction_completed(wsi)) in lws_handshake_server()
2369 n = user_callback_handle_rxflow(wsi->a.protocol->callback, in lws_handshake_server()
2370 wsi, LWS_CALLBACK_HTTP_CONFIRM_UPGRADE, in lws_handshake_server()
2371 wsi->user_space, (char *)up, 0); in lws_handshake_server()
2381 if (lws_http_transaction_completed(wsi)) in lws_handshake_server()
2391 if (wsi->a.vhost->options & in lws_handshake_server()
2393 lws_confirm_host_header(wsi)) in lws_handshake_server()
2398 lws_metrics_tag_wsi_add(wsi, "upg", "ws"); in lws_handshake_server()
2405 lws_metrics_tag_wsi_add(wsi, "upg", "h2c"); in lws_handshake_server()
2414 lwsl_info("%s: %s: No upgrade\n", __func__, lws_wsi_tag(wsi)); in lws_handshake_server()
2416 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_handshake_server()
2418 wsi->http.fop_fd = NULL; in lws_handshake_server()
2422 lws_http_compression_validate(wsi); in lws_handshake_server()
2425 lwsl_debug("%s: %s: ah %p\n", __func__, lws_wsi_tag(wsi), in lws_handshake_server()
2426 (void *)wsi->http.ah); in lws_handshake_server()
2428 n = lws_http_action(wsi); in lws_handshake_server()
2434 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP2_SETTINGS)) { in lws_handshake_server()
2441 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP2_SETTINGS); in lws_handshake_server()
2449 wsi->upgraded_to_http2 = 1; in lws_handshake_server()
2453 ah = wsi->http.ah; in lws_handshake_server()
2454 lws_role_transition(wsi, LWSIFR_SERVER, LRS_H2_AWAIT_PREFACE, in lws_handshake_server()
2458 wsi->http.ah = ah; in lws_handshake_server()
2460 if (!wsi->h2.h2n) { in lws_handshake_server()
2461 wsi->h2.h2n = lws_zalloc(sizeof(*wsi->h2.h2n), "h2n"); in lws_handshake_server()
2462 if (!wsi->h2.h2n) in lws_handshake_server()
2466 lws_h2_init(wsi); in lws_handshake_server()
2470 lws_h2_settings(wsi, &wsi->h2.h2n->peer_set, (uint8_t *)tbuf, n); in lws_handshake_server()
2472 if (lws_hpack_dynamic_size(wsi, (int)wsi->h2.h2n->peer_set.s[ in lws_handshake_server()
2480 n = lws_issue_raw(wsi, (unsigned char *)tbuf, (unsigned int)m); in lws_handshake_server()
2490 if (lws_process_ws_upgrade(wsi)) in lws_handshake_server()
2501 lws_header_table_detach(wsi, 1); in lws_handshake_server()
2508 lws_http_transaction_completed(struct lws *wsi) in lws_http_transaction_completed() argument
2512 if (wsi->http.cgi_transaction_complete) in lws_http_transaction_completed()
2515 if (lws_has_buffered_out(wsi) in lws_http_transaction_completed()
2517 || wsi->http.comp_ctx.buflist_comp || in lws_http_transaction_completed()
2518 wsi->http.comp_ctx.may_have_more in lws_http_transaction_completed()
2530 lws_wsi_tag(wsi)); in lws_http_transaction_completed()
2531 wsi->http.deferred_transaction_completed = 1; in lws_http_transaction_completed()
2532 lws_callback_on_writable(wsi); in lws_http_transaction_completed()
2543 if (wsi->http.rx_content_length && wsi->http.rx_content_remain) { in lws_http_transaction_completed()
2548 if (lwsi_state(wsi) == LRS_DISCARD_BODY) in lws_http_transaction_completed()
2554 lwsi_set_state(wsi, LRS_DISCARD_BODY); in lws_http_transaction_completed()
2563 lws_snprintf(tmp, sizeof(tmp), "%u", wsi->http.response_code); in lws_http_transaction_completed()
2564 lws_metrics_tag_wsi_add(wsi, "status", tmp); in lws_http_transaction_completed()
2568 lwsl_info("%s: %s\n", __func__, lws_wsi_tag(wsi)); in lws_http_transaction_completed()
2571 lws_http_compression_destroy(wsi); in lws_http_transaction_completed()
2573 lws_access_log(wsi); in lws_http_transaction_completed()
2575 if (!wsi->hdr_parsing_completed in lws_http_transaction_completed()
2577 && !wsi->http.cgi in lws_http_transaction_completed()
2583 lws_get_peer_simple(wsi, peer, sizeof(peer) - 1); in lws_http_transaction_completed()
2594 if (wsi->http.cgi) { in lws_http_transaction_completed()
2596 wsi->http.cgi_transaction_complete = 1; in lws_http_transaction_completed()
2597 lws_cgi_remove_and_kill(wsi); in lws_http_transaction_completed()
2598 lws_spawn_piped_destroy(&wsi->http.cgi->lsp); in lws_http_transaction_completed()
2599 lws_sul_cancel(&wsi->http.cgi->sul_grace); in lws_http_transaction_completed()
2601 lws_free_set_NULL(wsi->http.cgi); in lws_http_transaction_completed()
2602 wsi->http.cgi_transaction_complete = 0; in lws_http_transaction_completed()
2607 if (wsi->mux_substream) in lws_http_transaction_completed()
2610 if (wsi->seen_zero_length_recv) in lws_http_transaction_completed()
2613 if (wsi->http.conn_type != HTTP_CONNECTION_KEEP_ALIVE) { in lws_http_transaction_completed()
2614 lwsl_info("%s: %s: close connection\n", __func__, lws_wsi_tag(wsi)); in lws_http_transaction_completed()
2618 if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[0], __func__)) in lws_http_transaction_completed()
2628 lws_wsi_tag(wsi), (int)wsi->wsistate, wsi->buflist); in lws_http_transaction_completed()
2629 lwsi_set_state(wsi, LRS_DEFERRING_ACTION); in lws_http_transaction_completed()
2630 wsi->http.tx_content_length = 0; in lws_http_transaction_completed()
2631 wsi->http.tx_content_remain = 0; in lws_http_transaction_completed()
2632 wsi->hdr_parsing_completed = 0; in lws_http_transaction_completed()
2633 wsi->sending_chunked = 0; in lws_http_transaction_completed()
2635 wsi->http.access_log.sent = 0; in lws_http_transaction_completed()
2638 if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && in lws_http_transaction_completed()
2639 wsi->http.fop_fd != NULL) in lws_http_transaction_completed()
2640 lws_vfs_file_close(&wsi->http.fop_fd); in lws_http_transaction_completed()
2644 if (wsi->a.vhost->keepalive_timeout) in lws_http_transaction_completed()
2646 lws_set_timeout(wsi, (enum pending_timeout)n, wsi->a.vhost->keepalive_timeout); in lws_http_transaction_completed()
2660 if (wsi->http.ah) { in lws_http_transaction_completed()
2662 if (!lws_buflist_next_segment_len(&wsi->buflist, NULL)) { in lws_http_transaction_completed()
2664 __func__, lws_wsi_tag(wsi)); in lws_http_transaction_completed()
2665 lws_header_table_detach(wsi, 1); in lws_http_transaction_completed()
2673 if (wsi->a.vhost->tls.use_ssl && in lws_http_transaction_completed()
2674 wsi->a.context->simultaneous_ssl_restriction && in lws_http_transaction_completed()
2675 wsi->a.context->simultaneous_ssl == in lws_http_transaction_completed()
2676 wsi->a.context->simultaneous_ssl_restriction) { in lws_http_transaction_completed()
2684 __func__, lws_wsi_tag(wsi)); in lws_http_transaction_completed()
2685 lws_header_table_reset(wsi, 0); in lws_http_transaction_completed()
2692 lws_set_timeout(wsi, PENDING_TIMEOUT_HOLDING_AH, in lws_http_transaction_completed()
2693 wsi->a.vhost->keepalive_timeout); in lws_http_transaction_completed()
2696 if (wsi->http.ah) in lws_http_transaction_completed()
2697 wsi->http.ah->ues = URIES_IDLE; in lws_http_transaction_completed()
2701 if (lws_buflist_next_segment_len(&wsi->buflist, NULL)) in lws_http_transaction_completed()
2702 if (lws_header_table_attach(wsi, 0)) in lws_http_transaction_completed()
2706 __func__, lws_wsi_tag(wsi), (int)wsi->wsistate); in lws_http_transaction_completed()
2707 lws_callback_on_writable(wsi); in lws_http_transaction_completed()
2714 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, in lws_serve_http_file() argument
2717 struct lws_context *context = lws_get_context(wsi); in lws_serve_http_file()
2718 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in lws_serve_http_file()
2721 struct lws_range_parsing *rp = &wsi->http.range; in lws_serve_http_file()
2735 if (wsi->handling_404) in lws_serve_http_file()
2745 if (!wsi->http.fop_fd) { in lws_serve_http_file()
2746 fops = lws_vfs_select_fops(wsi->a.context->fops, file, &vpath); in lws_serve_http_file()
2747 fflags |= lws_vfs_prepare_flags(wsi); in lws_serve_http_file()
2748 wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->a.context->fops, in lws_serve_http_file()
2750 if (!wsi->http.fop_fd) { in lws_serve_http_file()
2753 if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, in lws_serve_http_file()
2756 return !wsi->mux_substream; in lws_serve_http_file()
2764 wsi->http.filelen = lws_vfs_get_length(wsi->http.fop_fd); in lws_serve_http_file()
2765 total_content_length = wsi->http.filelen; in lws_serve_http_file()
2768 ranges = lws_ranges_init(wsi, rp, wsi->http.filelen); in lws_serve_http_file()
2780 lws_return_http_status(wsi, in lws_serve_http_file()
2782 if (lws_http_transaction_completed(wsi)) in lws_serve_http_file()
2785 lws_vfs_file_close(&wsi->http.fop_fd); in lws_serve_http_file()
2793 if (lws_add_http_header_status(wsi, (unsigned int)n, &p, end)) in lws_serve_http_file()
2796 if ((wsi->http.fop_fd->flags & (LWS_FOP_FLAG_COMPR_ACCEPTABLE_GZIP | in lws_serve_http_file()
2799 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2813 if (!wsi->interpreting && ( in lws_serve_http_file()
2817 lws_http_compression_apply(wsi, NULL, &p, end, 0); in lws_serve_http_file()
2826 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2835 lws_strncpy(wsi->http.multipart_content_type, content_type, in lws_serve_http_file()
2836 sizeof(wsi->http.multipart_content_type)); in lws_serve_http_file()
2838 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2887 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2894 wsi->http.range.inside = 0; in lws_serve_http_file()
2896 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_ACCEPT_RANGES, in lws_serve_http_file()
2901 if (!wsi->mux_substream) { in lws_serve_http_file()
2903 if (!wsi->sending_chunked in lws_serve_http_file()
2905 && !wsi->http.lcs in lws_serve_http_file()
2912 if (lws_add_http_header_content_length(wsi, in lws_serve_http_file()
2918 if (wsi->http.lcs) { in lws_serve_http_file()
2928 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2943 wsi->http.comp_ctx.chunking = 1; in lws_serve_http_file()
2949 if (wsi->cache_secs && wsi->cache_reuse) { in lws_serve_http_file()
2950 if (!wsi->cache_revalidate) { in lws_serve_http_file()
2953 intermediates[wsi->cache_intermediaries], in lws_serve_http_file()
2954 wsi->cache_secs); in lws_serve_http_file()
2959 intermediates[wsi->cache_intermediaries], in lws_serve_http_file()
2960 wsi->cache_secs); in lws_serve_http_file()
2969 if (lws_add_http_header_by_token(wsi, in lws_serve_http_file()
2982 if (lws_finalize_http_header(wsi, &p, end)) in lws_serve_http_file()
2985 ret = lws_write(wsi, response, lws_ptr_diff_size_t(p, response), LWS_WRITE_HTTP_HEADERS); in lws_serve_http_file()
2992 wsi->http.filepos = 0; in lws_serve_http_file()
2993 lwsi_set_state(wsi, LRS_ISSUING_FILE); in lws_serve_http_file()
2995 if (lws_hdr_total_length(wsi, WSI_TOKEN_HEAD_URI)) { in lws_serve_http_file()
2997 lws_vfs_file_close(&wsi->http.fop_fd); in lws_serve_http_file()
2998 if (lws_http_transaction_completed(wsi)) in lws_serve_http_file()
3004 lws_callback_on_writable(wsi); in lws_serve_http_file()
3009 lws_vfs_file_close(&wsi->http.fop_fd); in lws_serve_http_file()
3017 int lws_serve_http_file_fragment(struct lws *wsi) in lws_serve_http_file_fragment() argument
3019 struct lws_context *context = wsi->a.context; in lws_serve_http_file_fragment()
3020 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in lws_serve_http_file_fragment()
3032 lwsl_debug("wsi->mux_substream %d\n", wsi->mux_substream); in lws_serve_http_file_fragment()
3038 if (lws_has_buffered_out(wsi)) { in lws_serve_http_file_fragment()
3039 if (lws_issue_raw(wsi, NULL, 0) < 0) { in lws_serve_http_file_fragment()
3049 if (wsi->http.comp_ctx.buflist_comp || in lws_serve_http_file_fragment()
3050 wsi->http.comp_ctx.may_have_more) { in lws_serve_http_file_fragment()
3054 __func__, wsi->http.comp_ctx.buflist_comp, in lws_serve_http_file_fragment()
3055 wsi->http.comp_ctx.may_have_more); in lws_serve_http_file_fragment()
3057 if (lws_rops_fidx(wsi->role_ops, LWS_ROPS_write_role_protocol) && in lws_serve_http_file_fragment()
3058 lws_rops_func_fidx(wsi->role_ops, LWS_ROPS_write_role_protocol). in lws_serve_http_file_fragment()
3059 write_role_protocol(wsi, NULL, 0, &wp) < 0) { in lws_serve_http_file_fragment()
3063 lws_callback_on_writable(wsi); in lws_serve_http_file_fragment()
3069 if (wsi->http.filepos == wsi->http.filelen) in lws_serve_http_file_fragment()
3076 if (wsi->http.range.count_ranges && !wsi->http.range.inside) { in lws_serve_http_file_fragment()
3079 wsi->http.range.start); in lws_serve_http_file_fragment()
3081 if ((long long)lws_vfs_file_seek_cur(wsi->http.fop_fd, in lws_serve_http_file_fragment()
3082 (lws_fileofs_t)wsi->http.range.start - in lws_serve_http_file_fragment()
3083 (lws_fileofs_t)wsi->http.filepos) < 0) in lws_serve_http_file_fragment()
3086 wsi->http.filepos = wsi->http.range.start; in lws_serve_http_file_fragment()
3088 if (wsi->http.range.count_ranges > 1) { in lws_serve_http_file_fragment()
3097 wsi->http.multipart_content_type, in lws_serve_http_file_fragment()
3098 wsi->http.range.start, in lws_serve_http_file_fragment()
3099 wsi->http.range.end, in lws_serve_http_file_fragment()
3100 wsi->http.range.extent); in lws_serve_http_file_fragment()
3104 wsi->http.range.budget = wsi->http.range.end - in lws_serve_http_file_fragment()
3105 wsi->http.range.start + 1; in lws_serve_http_file_fragment()
3106 wsi->http.range.inside = 1; in lws_serve_http_file_fragment()
3118 nwsi = lws_get_network_wsi(wsi); in lws_serve_http_file_fragment()
3125 if (wsi->http.tx_content_length) in lws_serve_http_file_fragment()
3126 if (poss > wsi->http.tx_content_remain) in lws_serve_http_file_fragment()
3127 poss = wsi->http.tx_content_remain; in lws_serve_http_file_fragment()
3133 if (wsi->a.protocol->tx_packet_size && in lws_serve_http_file_fragment()
3134 poss > wsi->a.protocol->tx_packet_size) in lws_serve_http_file_fragment()
3135 poss = wsi->a.protocol->tx_packet_size; in lws_serve_http_file_fragment()
3137 if (lws_rops_fidx(wsi->role_ops, LWS_ROPS_tx_credit)) { in lws_serve_http_file_fragment()
3138 lws_filepos_t txc = (unsigned int)lws_rops_func_fidx(wsi->role_ops, in lws_serve_http_file_fragment()
3140 tx_credit(wsi, LWSTXCR_US_TO_PEER, 0); in lws_serve_http_file_fragment()
3148 lws_wsi_tag(wsi)); in lws_serve_http_file_fragment()
3162 if (wsi->http.range.count_ranges) { in lws_serve_http_file_fragment()
3163 if (wsi->http.range.count_ranges > 1) in lws_serve_http_file_fragment()
3165 if (poss > wsi->http.range.budget) in lws_serve_http_file_fragment()
3166 poss = wsi->http.range.budget; in lws_serve_http_file_fragment()
3169 if (wsi->sending_chunked) { in lws_serve_http_file_fragment()
3177 if (lws_vfs_file_read(wsi->http.fop_fd, &amount, p, poss) < 0) in lws_serve_http_file_fragment()
3180 if (wsi->sending_chunked) in lws_serve_http_file_fragment()
3188 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, in lws_serve_http_file_fragment()
3191 if (wsi->interpreting) { in lws_serve_http_file_fragment()
3195 args.final = wsi->http.filepos + (unsigned int)n == in lws_serve_http_file_fragment()
3196 wsi->http.filelen; in lws_serve_http_file_fragment()
3197 args.chunked = wsi->sending_chunked; in lws_serve_http_file_fragment()
3199 wsi->a.vhost->protocols[ in lws_serve_http_file_fragment()
3200 (int)wsi->protocol_interpret_idx].callback, in lws_serve_http_file_fragment()
3201 wsi, LWS_CALLBACK_PROCESS_HTML, in lws_serve_http_file_fragment()
3202 wsi->user_space, &args, 0) < 0) in lws_serve_http_file_fragment()
3210 if (wsi->http.range.send_ctr + 1 == in lws_serve_http_file_fragment()
3211 wsi->http.range.count_ranges && // last range in lws_serve_http_file_fragment()
3212 wsi->http.range.count_ranges > 1 && // was 2+ ranges (ie, multipart) in lws_serve_http_file_fragment()
3213 wsi->http.range.budget - amount == 0) {// final part in lws_serve_http_file_fragment()
3219 m = lws_write(wsi, p, (unsigned int)n, wsi->http.filepos + amount == in lws_serve_http_file_fragment()
3220 wsi->http.filelen ? in lws_serve_http_file_fragment()
3225 wsi->http.filepos += amount; in lws_serve_http_file_fragment()
3228 if (wsi->http.range.count_ranges >= 1) { in lws_serve_http_file_fragment()
3229 wsi->http.range.budget -= amount; in lws_serve_http_file_fragment()
3230 if (wsi->http.range.budget == 0) { in lws_serve_http_file_fragment()
3232 wsi->http.range.inside = 0; in lws_serve_http_file_fragment()
3233 wsi->http.range.send_ctr++; in lws_serve_http_file_fragment()
3235 if (lws_ranges_next(&wsi->http.range) < 1) { in lws_serve_http_file_fragment()
3245 if (lws_vfs_file_seek_cur(wsi->http.fop_fd, in lws_serve_http_file_fragment()
3253 if ((!lws_has_buffered_out(wsi) in lws_serve_http_file_fragment()
3255 && !wsi->http.comp_ctx.buflist_comp && in lws_serve_http_file_fragment()
3256 !wsi->http.comp_ctx.may_have_more in lws_serve_http_file_fragment()
3258 ) && (wsi->http.filepos >= wsi->http.filelen in lws_serve_http_file_fragment()
3265 lwsi_set_state(wsi, LRS_ESTABLISHED); in lws_serve_http_file_fragment()
3267 lws_vfs_file_close(&wsi->http.fop_fd); in lws_serve_http_file_fragment()
3271 if (wsi->a.protocol->callback && in lws_serve_http_file_fragment()
3272 user_callback_handle_rxflow(wsi->a.protocol->callback, in lws_serve_http_file_fragment()
3273 wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, in lws_serve_http_file_fragment()
3274 wsi->user_space, NULL, 0) < 0) { in lws_serve_http_file_fragment()
3289 if (wsi->mux_substream) in lws_serve_http_file_fragment()
3302 } while (!lws_send_pipe_choked(wsi)); in lws_serve_http_file_fragment()
3304 lws_callback_on_writable(wsi); in lws_serve_http_file_fragment()
3309 lws_vfs_file_close(&wsi->http.fop_fd); in lws_serve_http_file_fragment()