• Home
  • Raw
  • Download

Lines Matching refs:hs

127 #define HTTP_IS_DYNAMIC_FILE(hs) ((hs)->buf != NULL)  argument
129 #define HTTP_IS_DYNAMIC_FILE(hs) 0 argument
136 #define HTTP_IS_DATA_VOLATILE(hs) (HTTP_IS_DYNAMIC_FILE(hs) ? TCP_WRITE_FLAG_COPY : 0) argument
140 #define HTTP_IS_HDR_VOLATILE(hs, ptr) 0 argument
308 static err_t http_close_conn(struct altcp_pcb *pcb, struct http_state *hs);
309 static err_t http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abort_conn…
310 static err_t http_find_file(struct http_state *hs, const char *uri, int is_09);
311 static err_t http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri…
313 static u8_t http_check_eof(struct altcp_pcb *pcb, struct http_state *hs);
341 #define http_cgi_params hs->params
342 #define http_cgi_param_vals hs->param_vals
354 http_add_connection(struct http_state *hs) in http_add_connection() argument
357 hs->next = http_connections; in http_add_connection()
358 http_connections = hs; in http_add_connection()
362 http_remove_connection(struct http_state *hs) in http_remove_connection() argument
366 if (http_connections == hs) { in http_remove_connection()
367 http_connections = hs->next; in http_remove_connection()
371 if (last->next == hs) { in http_remove_connection()
372 last->next = hs->next; in http_remove_connection()
383 struct http_state *hs = http_connections; in http_kill_oldest_connection() local
385 while (hs && hs->next) { in http_kill_oldest_connection()
388 if (hs->next->ssi != NULL) { in http_kill_oldest_connection()
389 hs_free_next = hs; in http_kill_oldest_connection()
396 hs_free_next = hs; in http_kill_oldest_connection()
398 LWIP_ASSERT("broken list", hs != hs->next); in http_kill_oldest_connection()
399 hs = hs->next; in http_kill_oldest_connection()
410 #define http_add_connection(hs) argument
411 #define http_remove_connection(hs) argument
446 http_state_init(struct http_state *hs) in http_state_init() argument
449 memset(hs, 0, sizeof(struct http_state)); in http_state_init()
452 hs->hdr_index = NUM_FILE_HDR_STRINGS; in http_state_init()
478 http_state_eof(struct http_state *hs) in http_state_eof() argument
480 if (hs->handle) { in http_state_eof()
482 u32_t ms_needed = sys_now() - hs->time_started; in http_state_eof()
485 … ms_needed, hs->handle->len, ((((u32_t)hs->handle->len) * 10) / needed))); in http_state_eof()
487 fs_close(hs->handle); in http_state_eof()
488 hs->handle = NULL; in http_state_eof()
491 if (hs->buf != NULL) { in http_state_eof()
492 mem_free(hs->buf); in http_state_eof()
493 hs->buf = NULL; in http_state_eof()
497 if (hs->ssi) { in http_state_eof()
498 http_ssi_state_free(hs->ssi); in http_state_eof()
499 hs->ssi = NULL; in http_state_eof()
503 if (hs->req) { in http_state_eof()
504 pbuf_free(hs->req); in http_state_eof()
505 hs->req = NULL; in http_state_eof()
514 http_state_free(struct http_state *hs) in http_state_free() argument
516 if (hs != NULL) { in http_state_free()
517 http_state_eof(hs); in http_state_free()
518 http_remove_connection(hs); in http_state_free()
519 HTTP_FREE_HTTP_STATE(hs); in http_state_free()
596 http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abort_conn) in http_close_or_abort_conn() argument
602 if (hs != NULL) { in http_close_or_abort_conn()
603 if ((hs->post_content_len_left != 0) in http_close_or_abort_conn()
605 || ((hs->no_auto_wnd != 0) && (hs->unrecved_bytes != 0)) in http_close_or_abort_conn()
610 httpd_post_finished(hs, http_uri_buf, LWIP_HTTPD_URI_BUF_LEN); in http_close_or_abort_conn()
621 if (hs != NULL) { in http_close_or_abort_conn()
622 http_state_free(hs); in http_close_or_abort_conn()
646 http_close_conn(struct altcp_pcb *pcb, struct http_state *hs) in http_close_conn() argument
648 return http_close_or_abort_conn(pcb, hs, 0); in http_close_conn()
655 http_eof(struct altcp_pcb *pcb, struct http_state *hs) in http_eof() argument
659 if (hs->keepalive) { in http_eof()
660 http_remove_connection(hs); in http_eof()
662 http_state_eof(hs); in http_eof()
663 http_state_init(hs); in http_eof()
665 hs->pcb = pcb; in http_eof()
666 hs->keepalive = 1; in http_eof()
667 http_add_connection(hs); in http_eof()
673 http_close_conn(pcb, hs); in http_eof()
688 extract_uri_parameters(struct http_state *hs, char *params) in extract_uri_parameters() argument
694 LWIP_UNUSED_ARG(hs); in extract_uri_parameters()
759 get_tag_insert(struct http_state *hs) argument
772 LWIP_ASSERT("hs != NULL", hs != NULL);
773 ssi = hs->ssi;
803 , (hs->handle ? hs->handle->state : NULL)
842 get_http_headers(struct http_state *hs, const char *uri) argument
851 hs->hdrs[HDR_STRINGS_IDX_SERVER_NAME] = g_psHTTPHeaderStrings[HTTP_HDR_SERVER];
852 hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] = NULL;
853 hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_NR] = NULL;
858 hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_NOT_FOUND];
860 if (hs->keepalive) {
861 hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = g_psHTTPHeaderStrings[DEFAULT_404_HTML_PERSISTENT];
865 hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = g_psHTTPHeaderStrings[DEFAULT_404_HTML];
869 hs->hdr_index = 0;
870 hs->hdr_pos = 0;
878 hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_NOT_FOUND];
880 hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_BAD_REQUEST];
882 hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_NOT_IMPL];
884 hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_OK];
926 hs->hdr_index = NUM_FILE_HDR_STRINGS;
933 hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = g_psHTTPHeaders[content_type].content_type;
936 hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = HTTP_HDR_APP;
939 hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = HTTP_HDR_DEFAULT_TYPE;
942 hs->hdr_index = 0;
943 hs->hdr_pos = 0;
948 get_http_content_length(struct http_state *hs) argument
952 LWIP_ASSERT("already been here?", hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] == NULL);
956 if (hs->ssi == NULL) /* @todo: get maximum file length from SSI */
959 if ((hs->handle != NULL) && (hs->handle->flags & FS_FILE_FLAGS_HEADER_PERSISTENT)) {
965 lwip_itoa(hs->hdr_content_len, (size_t)LWIP_HTTPD_MAX_CONTENT_LEN_SIZE,
966 hs->handle->len);
967 len = strlen(hs->hdr_content_len);
969 SMEMCPY(&hs->hdr_content_len[len], CRLF, 3);
970 hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_NR] = hs->hdr_content_len;
977 hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] = g_psHTTPHeaderStrings[HTTP_HDR_KEEPALIVE_LEN];
979 hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] = g_psHTTPHeaderStrings[HTTP_HDR_CONN_CLOSE];
980 hs->keepalive = 0;
984hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] = g_psHTTPHeaderStrings[HTTP_HDR_CONTENT_LENGTH];
998 http_send_headers(struct altcp_pcb *pcb, struct http_state *hs) argument
1005 if (hs->hdrs[HDR_STRINGS_IDX_CONTENT_LEN_KEEPALIVE] == NULL) {
1007 get_http_content_length(hs);
1014 while (len && (hs->hdr_index < NUM_FILE_HDR_STRINGS) && sendlen) {
1019 hdrlen = (u16_t)strlen(hs->hdrs[hs->hdr_index]);
1022 sendlen = (len < (hdrlen - hs->hdr_pos)) ? len : (hdrlen - hs->hdr_pos);
1026 ptr = (const void *)(hs->hdrs[hs->hdr_index] + hs->hdr_pos);
1028 apiflags = HTTP_IS_HDR_VOLATILE(hs, ptr);
1029 if (hs->hdr_index == HDR_STRINGS_IDX_CONTENT_LEN_NR) {
1033 if (hs->hdr_index < NUM_FILE_HDR_STRINGS - 1) {
1046 hs->hdr_pos += sendlen;
1050 if (hs->hdr_pos == hdrlen) {
1052 hs->hdr_index++;
1054 while ((hs->hdr_index < NUM_FILE_HDR_STRINGS) &&
1055 (hs->hdrs[hs->hdr_index] == NULL)) {
1056 hs->hdr_index++;
1058 hs->hdr_pos = 0;
1062 if ((hs->hdr_index >= NUM_FILE_HDR_STRINGS) && (hs->file == NULL)) {
1066 if (http_check_eof(pcb, hs)) {
1078 if ((hs->hdr_index < NUM_FILE_HDR_STRINGS) || !hs->file) {
1093 http_check_eof(struct altcp_pcb *pcb, struct http_state *hs) argument
1104 if (hs->handle == NULL) {
1106 http_eof(pcb, hs);
1109 bytes_left = fs_bytes_left(hs->handle);
1113 http_eof(pcb, hs);
1118 if (hs->buf) {
1120 count = LWIP_MIN(hs->buf_len, bytes_left);
1135 hs->buf = (char *)mem_malloc((mem_size_t)count);
1136 if (hs->buf != NULL) {
1137 hs->buf_len = count;
1144 if (hs->buf == NULL) {
1154 count = fs_read_async(hs->handle, hs->buf, count, http_continue, hs);
1156 count = fs_read(hs->handle, hs->buf, count);
1166 http_eof(pcb, hs);
1172 hs->left = count;
1173 hs->file = hs->buf;
1175 if (hs->ssi) {
1176 hs->ssi->parse_left = count;
1177 hs->ssi->parsed = hs->buf;
1192 http_send_data_nonssi(struct altcp_pcb *pcb, struct http_state *hs) argument
1200 len = (u16_t)LWIP_MIN(hs->left, 0xffff);
1202 err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
1205 hs->file += len;
1206 hs->left -= len;
1219 http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs) argument
1226 struct http_ssi_state *ssi = hs->ssi;
1237 if (ssi->parsed > hs->file) {
1238 len = (u16_t)LWIP_MIN(ssi->parsed - hs->file, 0xffff);
1240 err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
1243 hs->file += len;
1244 hs->left -= len;
1306 (ssi->parsed - hs->file < ssi->tag_index)) {
1311 hs->file += ssi->parsed - hs->file;
1312 hs->left -= ssi->parsed - hs->file;
1313 ssi->tag_end = hs->file;
1409 get_tag_insert(hs);
1423 if (ssi->tag_end > hs->file) {
1426 len = (u16_t)LWIP_MIN(ssi->tag_end - hs->file, 0xffff);
1429 len = (u16_t)LWIP_MIN(ssi->tag_started - hs->file, 0xffff);
1432 err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
1436 if (ssi->tag_started <= hs->file) {
1441 hs->file += len;
1442 hs->left -= len;
1463 if (ssi->tag_end > hs->file) {
1466 len = (u16_t)LWIP_MIN(ssi->tag_end - hs->file, 0xffff);
1468 LWIP_ASSERT("hs->started >= hs->file", ssi->tag_started >= hs->file);
1470 len = (u16_t)LWIP_MIN(ssi->tag_started - hs->file, 0xffff);
1473 err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
1480 if (ssi->tag_started <= hs->file) {
1485 hs->file += len;
1486 hs->left -= len;
1495 get_tag_insert(hs);
1511 HTTP_IS_TAG_VOLATILE(hs));
1542 if ((ssi->tag_state != TAG_SENDING) && (ssi->parsed > hs->file)) {
1547 len = (u16_t)(ssi->tag_started - hs->file);
1548 hs->left -= (ssi->parsed - ssi->tag_started);
1550 ssi->tag_started = hs->buf;
1554 len = (u16_t)LWIP_MIN(ssi->parsed - hs->file, 0xffff);
1557 err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
1560 hs->file += len;
1561 hs->left -= len;
1575 http_send(struct altcp_pcb *pcb, struct http_state *hs) argument
1580 (void *)hs, hs != NULL ? (int)hs->left : 0));
1583 if (hs->unrecved_bytes != 0) {
1589 if (hs == NULL) {
1596 if (!fs_is_file_ready(hs->handle, http_continue, hs)) {
1603 if (hs->hdr_index < NUM_FILE_HDR_STRINGS) {
1604 data_to_send = http_send_headers(pcb, hs);
1607 (hs->hdr_index < NUM_FILE_HDR_STRINGS))) {
1615 if (hs->left == 0) {
1616 if (!http_check_eof(pcb, hs)) {
1622 if (hs->ssi) {
1623 data_to_send = http_send_data_ssi(pcb, hs);
1627 data_to_send = http_send_data_nonssi(pcb, hs);
1630 if ((hs->left == 0) && (fs_bytes_left(hs->handle) <= 0)) {
1634 http_eof(pcb, hs);
1650 http_find_error_file(struct http_state *hs, u16_t error_nr) argument
1664 if (fs_open(&hs->file_handle, uri1) == ERR_OK) {
1666 } else if (fs_open(&hs->file_handle, uri2) == ERR_OK) {
1668 } else if (fs_open(&hs->file_handle, uri3) == ERR_OK) {
1675 return http_init_file(hs, &hs->file_handle, 0, uri, 0, NULL);
1678 #define http_find_error_file(hs, error_nr) ERR_ARG argument
1689 http_get_404_file(struct http_state *hs, const char **uri) argument
1694 err = fs_open(&hs->file_handle, *uri);
1698 err = fs_open(&hs->file_handle, *uri);
1702 err = fs_open(&hs->file_handle, *uri);
1713 return &hs->file_handle;
1718 http_handle_post_finished(struct http_state *hs) argument
1723 if (hs->post_finished) {
1726 hs->post_finished = 1;
1731 httpd_post_finished(hs, http_uri_buf, LWIP_HTTPD_URI_BUF_LEN);
1732 return http_find_file(hs, http_uri_buf, 0);
1745 http_post_rxpbuf(struct http_state *hs, struct pbuf *p) argument
1751 if (hs->post_content_len_left < p->tot_len) {
1752 hs->post_content_len_left = 0;
1754 hs->post_content_len_left -= p->tot_len;
1759 hs->unrecved_bytes++;
1762 err = httpd_post_receive_data(hs, p);
1767 hs->unrecved_bytes--;
1771 hs->post_content_len_left = 0;
1773 if (hs->post_content_len_left == 0) {
1775 if (hs->unrecved_bytes != 0) {
1780 return http_handle_post_finished(hs);
1801 http_post_request(struct pbuf *inp, struct http_state *hs, argument
1835 err = httpd_post_begin(hs, uri, hdr_start_after_uri, hdr_data_len, content_len,
1842 hs->no_auto_wnd = !post_auto_wnd;
1845 hs->post_content_len_left = (u32_t)content_len;
1858 hs->unrecved_bytes = q->tot_len;
1862 return http_post_rxpbuf(hs, q);
1863 } else if (hs->post_content_len_left == 0) {
1865 return http_post_rxpbuf(hs, q);
1871 return http_find_file(hs, http_uri_buf, 0);
1907 struct http_state *hs = (struct http_state *)connection; local
1908 if (hs != NULL) {
1909 if (hs->no_auto_wnd) {
1911 if (hs->unrecved_bytes >= recved_len) {
1912 hs->unrecved_bytes -= recved_len;
1915 len = (u16_t)hs->unrecved_bytes;
1916 hs->unrecved_bytes = 0;
1918 if (hs->pcb != NULL) {
1920 altcp_recved(hs->pcb, len);
1922 if ((hs->post_content_len_left == 0) && (hs->unrecved_bytes == 0)) {
1924 http_handle_post_finished(hs);
1925 http_send(hs->pcb, hs);
1942 struct http_state *hs = (struct http_state *)connection; local
1944 if (hs && (hs->pcb) && (hs->handle)) {
1945 LWIP_ASSERT("hs->pcb != NULL", hs->pcb != NULL);
1947 if (http_send(hs->pcb, hs)) {
1950 altcp_output(hs->pcb);
1968 http_parse_request(struct pbuf *inp, struct http_state *hs, struct altcp_pcb *pcb) argument
1983 LWIP_ASSERT("hs != NULL", hs != NULL);
1985 if ((hs->handle != NULL) || (hs->file != NULL)) {
1999 if (hs->req == NULL) {
2001 hs->req = p;
2004 pbuf_cat(hs->req, p);
2010 if (hs->req->next != NULL) {
2011 data_len = LWIP_MIN(hs->req->tot_len, LWIP_HTTPD_MAX_REQ_LENGTH);
2012 pbuf_copy_partial(hs->req, httpd_req_buf, data_len, 0);
2055 return http_find_error_file(hs, 501);
2083 hs->keepalive = 1;
2085 hs->keepalive = 0;
2096 struct pbuf *q = hs->req;
2100 err = http_post_request(q, hs, data, data_len, uri, sp2);
2114 return http_find_file(hs, uri, is_09);
2124 clen = pbuf_clen(hs->req);
2125 if ((hs->req->tot_len <= LWIP_HTTPD_REQ_BUFSIZE) &&
2137 return http_find_error_file(hs, 400);
2192 http_find_file(struct http_state *hs, const char *uri, int is_09) argument
2240 err = fs_open(&hs->file_handle, file_name);
2243 file = &hs->file_handle;
2272 http_cgi_paramcount = extract_uri_parameters(hs, params);
2273 uri = httpd_cgis[i].pfnCGIHandler(i, http_cgi_paramcount, hs->params,
2274 hs->param_vals);
2283 err = fs_open(&hs->file_handle, uri);
2285 file = &hs->file_handle;
2287 file = http_get_404_file(hs, &uri);
2303 file = http_get_404_file(hs, &uri);
2305 return http_init_file(hs, file, is_09, uri, tag_check, params);
2321 http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri, argument
2343 hs->ssi = ssi;
2349 hs->handle = file;
2360 count = extract_uri_parameters(hs, params);
2371 hs->file = file->data;
2376 hs->left = 0;
2380 hs->left = (u32_t)file->len;
2382 hs->retries = 0;
2384 hs->time_started = sys_now();
2388 (hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0);
2391 if (is_09 && ((hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0)) {
2394 char *file_start = lwip_strnstr(hs->file, CRLF CRLF, hs->left);
2396 int diff = file_start + 4 - hs->file;
2397 hs->file += diff;
2398 hs->left -= (u32_t)diff;
2403 hs->handle = NULL;
2404 hs->file = NULL;
2405 hs->left = 0;
2406 hs->retries = 0;
2411 if ((hs->handle == NULL) || ((hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) == 0)) {
2412 get_http_headers(hs, uri);
2418 if (hs->keepalive) {
2420 if (hs->ssi != NULL) {
2421 hs->keepalive = 0;
2425 if ((hs->handle != NULL) &&
2426 …((hs->handle->flags & (FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT)) == FS_FIL…
2427 hs->keepalive = 0;
2442 struct http_state *hs = (struct http_state *)arg; local
2447 if (hs != NULL) {
2448 http_state_free(hs);
2459 struct http_state *hs = (struct http_state *)arg; local
2465 if (hs == NULL) {
2469 hs->retries = 0;
2471 http_send(pcb, hs);
2486 struct http_state *hs = (struct http_state *)arg; local
2488 (void *)pcb, (void *)hs, tcp_debug_state_str(altcp_dbg_get_tcp_state(pcb))));
2490 if (hs == NULL) {
2504 hs->retries++;
2505 if (hs->retries == HTTPD_MAX_RETRIES) {
2507 http_close_conn(pcb, hs);
2514 if (hs->handle) {
2516 if (http_send(pcb, hs)) {
2534 struct http_state *hs = (struct http_state *)arg; local
2538 if ((err != ERR_OK) || (p == NULL) || (hs == NULL)) {
2545 if (hs == NULL) {
2549 http_close_conn(pcb, hs);
2554 if (hs->no_auto_wnd) {
2555 hs->unrecved_bytes += p->tot_len;
2564 if (hs->post_content_len_left > 0) {
2566 hs->retries = 0;
2568 http_post_rxpbuf(hs, p);
2570 if (hs->post_content_len_left == 0) {
2572 http_send(pcb, hs);
2578 if (hs->handle == NULL) {
2579 err_t parsed = http_parse_request(p, hs, pcb);
2585 if (hs->req != NULL) {
2586 pbuf_free(hs->req);
2587 hs->req = NULL;
2594 if (hs->post_content_len_left == 0)
2597 …D_DEBUG | LWIP_DBG_TRACE, ("http_recv: data %p len %"S32_F"\n", (const void *)hs->file, hs->left));
2598 http_send(pcb, hs);
2602 http_close_conn(pcb, hs);
2619 struct http_state *hs; local
2633 hs = http_state_alloc();
2634 if (hs == NULL) {
2638 hs->pcb = pcb;
2642 altcp_arg(pcb, hs);