Lines Matching defs:ah
45 struct allocated_headers *ah = lws_zalloc(sizeof(*ah), "ah struct");
47 if (!ah)
50 ah->data = lws_malloc(data_size, "ah data");
51 if (!ah->data) {
52 lws_free(ah);
56 ah->next = pt->http.ah_list;
57 pt->http.ah_list = ah;
58 ah->data_length = data_size;
61 lwsl_info("%s: created ah %p (size %d): pool length %u\n", __func__,
62 ah, (int)data_size, (unsigned int)pt->http.ah_pool_length);
64 return ah;
68 _lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah)
71 if ((*a) == ah) {
72 *a = ah->next;
74 lwsl_info("%s: freed ah %p : pool length %u\n",
75 __func__, ah,
77 if (ah->data)
78 lws_free(ah->data);
79 lws_free(ah);
89 _lws_header_table_reset(struct allocated_headers *ah)
91 /* init the ah to reflect no headers or data have appeared yet */
92 memset(ah->frag_index, 0, sizeof(ah->frag_index));
93 memset(ah->frags, 0, sizeof(ah->frags));
94 ah->nfrag = 0;
95 ah->pos = 0;
96 ah->http_response = 0;
97 ah->parser_state = WSI_TOKEN_NAME_PART;
98 ah->lextable_pos = 0;
99 ah->unk_pos = 0;
101 ah->unk_ll_head = 0;
102 ah->unk_ll_tail = 0;
106 // doesn't scrub the ah rxbuffer by default, parent must do if needed
111 struct allocated_headers *ah = wsi->http.ah;
115 /* if we have the idea we're resetting 'our' ah, must be bound to one */
116 assert(ah);
117 /* ah also concurs with ownership */
118 assert(ah->wsi == wsi);
120 _lws_header_table_reset(ah);
122 /* since we will restart the ah, our new headers are not completed */
125 /* while we hold the ah, keep a timeout on the wsi */
129 time(&ah->assigned);
134 lwsl_debug("%s: service on readbuf ah\n", __func__);
219 lwsl_info("%s: %s: ah %p (tsi %d, count = %d) in\n", __func__,
220 lws_wsi_tag(wsi), (void *)wsi->http.ah, wsi->tsi,
232 if (wsi->http.ah) {
245 * particular guy an ah right now...
248 * weren't able to provide the ah
257 wsi->http.ah = _lws_create_ah(pt, context->max_http_header_data);
258 if (!wsi->http.ah) { /* we could not create an ah */
264 wsi->http.ah->in_use = 1;
265 wsi->http.ah->wsi = wsi; /* mark our owner */
270 lws_context_lock(context, "ah attach"); /* <========================= */
278 lwsl_info("%s: did attach wsi %s: ah %p: count %d (on exit)\n", __func__,
279 lws_wsi_tag(wsi), (void *)wsi->http.ah, pt->http.ah_count_in_use);
309 struct allocated_headers *ah = wsi->http.ah;
317 if (!ah)
320 lwsl_info("%s: %s: ah %p (tsi=%d, count = %d)\n", __func__,
321 lws_wsi_tag(wsi), (void *)ah, wsi->tsi,
324 /* we did have an ah attached */
326 if (ah->assigned && now - ah->assigned > 3) {
328 * we're detaching the ah, but it was held an
331 lwsl_debug("%s: %s: ah held %ds, role/state 0x%lx 0x%x,"
333 (int)(now - ah->assigned),
337 ah->assigned = 0;
342 assert(ah->in_use);
343 memset(&wsi->http.ah, 0, sizeof(wsi->http.ah));
346 if (ah->wsi)
349 ah->wsi = NULL; /* no owner */
350 wsi->http.ah = NULL;
354 /* oh there is nobody on the waiting list... leave the ah unattached */
368 /* are we willing to give this guy an ah? */
379 if (!wsi) /* everybody waiting already has too many ah... */
382 lwsl_info("%s: transferring ah to last eligible wsi in wait list "
386 wsi->http.ah = ah;
387 ah->wsi = wsi; /* new owner */
392 lws_context_lock(context, "ah detach"); /* <========================= */
398 /* clients acquire the ah and then insert themselves in fds table... */
402 /* he has been stuck waiting for an ah, but now his wait is
432 lwsl_info("%s: %s: ah %p (tsi=%d, count = %d)\n", __func__,
433 lws_wsi_tag(wsi), (void *)ah, pt->tid, pt->http.ah_count_in_use);
439 _lws_destroy_ah(pt, ah);
463 if (!wsi->http.ah)
466 n = wsi->http.ah->frag_index[h];
471 return wsi->http.ah->frags[n].len;
472 n = wsi->http.ah->frags[n].nfrag;
483 if (!wsi->http.ah)
486 n = wsi->http.ah->frag_index[h];
490 len += wsi->http.ah->frags[n].len;
491 n = wsi->http.ah->frags[n].nfrag;
507 if (!wsi->http.ah)
510 f = wsi->http.ah->frag_index[h];
516 f = wsi->http.ah->frags[f].nfrag;
522 if (wsi->http.ah->frags[f].len >= len)
525 memcpy(dst, wsi->http.ah->data + wsi->http.ah->frags[f].offset,
526 wsi->http.ah->frags[f].len);
527 dst[wsi->http.ah->frags[f].len] = '\0';
529 return wsi->http.ah->frags[f].len;
544 if (!wsi->http.ah)
547 n = wsi->http.ah->frag_index[h];
551 comma = (wsi->http.ah->frags[n].nfrag) ? 1 : 0;
555 __func__, (int)wsi->http.ah->frags[n].len,
556 &wsi->http.ah->data[
557 wsi->http.ah->frags[n].offset]);
559 if (wsi->http.ah->frags[n].len + comma >= len) {
563 strncpy(dst, &wsi->http.ah->data[wsi->http.ah->frags[n].offset],
564 wsi->http.ah->frags[n].len);
565 dst += wsi->http.ah->frags[n].len;
566 len -= wsi->http.ah->frags[n].len;
567 n = wsi->http.ah->frags[n].nfrag;
602 if (!wsi->http.ah || wsi->mux_substream)
605 ll = wsi->http.ah->unk_ll_head;
607 if (ll >= wsi->http.ah->data_length)
610 (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) &&
611 !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], (unsigned int)nlen))
613 (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]);
615 ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]);
628 if (!wsi->http.ah || wsi->mux_substream)
633 ll = wsi->http.ah->unk_ll_head;
635 if (ll >= wsi->http.ah->data_length)
638 (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) &&
639 !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], (unsigned int)nlen)) {
641 (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]);
644 strncpy(dst, &wsi->http.ah->data[ll + UHO_NAME + (unsigned int)nlen], (unsigned int)n);
649 ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]);
661 if (!wsi->http.ah || wsi->mux_substream)
664 ll = wsi->http.ah->unk_ll_head;
667 if (ll >= wsi->http.ah->data_length)
670 cb(&wsi->http.ah->data[ll + UHO_NAME],
671 lws_ser_ru16be((uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]),
674 ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]);
685 if (!wsi->http.ah)
688 n = wsi->http.ah->frag_index[h];
692 return wsi->http.ah->data + wsi->http.ah->frags[n].offset;
698 if (!wsi->http.ah)
701 if (wsi->http.ah->pos <
705 if ((int)wsi->http.ah->pos >= (int)wsi->a.context->max_http_header_data - 1) {
715 (unsigned long)wsi->http.ah->pos,
730 wsi->http.ah->frag_index[h] = 0;
735 wsi->http.ah->nfrag++;
736 if (wsi->http.ah->nfrag == LWS_ARRAY_SIZE(wsi->http.ah->frags)) {
741 wsi->http.ah->frag_index[h] = wsi->http.ah->nfrag;
743 wsi->http.ah->frags[wsi->http.ah->nfrag].offset = wsi->http.ah->pos;
744 wsi->http.ah->frags[wsi->http.ah->nfrag].len = 0;
745 wsi->http.ah->frags[wsi->http.ah->nfrag].nfrag = 0;
751 wsi->http.ah->data[wsi->http.ah->pos++] = *s;
753 wsi->http.ah->frags[wsi->http.ah->nfrag].len++;
767 frag_len = wsi->http.ah->frags[wsi->http.ah->nfrag].len;
772 if (!wsi->http.ah->current_token_limit ||
773 frag_len < wsi->http.ah->current_token_limit) {
774 wsi->http.ah->data[wsi->http.ah->pos++] = (char)c;
775 wsi->http.ah->frags[wsi->http.ah->nfrag].len++;
780 if (frag_len == wsi->http.ah->current_token_limit) {
784 wsi->http.ah->data[wsi->http.ah->pos++] = '\0';
786 (long)wsi->http.ah->parser_state,
787 (long)wsi->http.ah->current_token_limit);
796 struct allocated_headers *ah = wsi->http.ah;
800 // lwsl_notice("ah->ups %d\n", ah->ups);
806 switch (ah->ues) {
809 ah->ues = URIES_SEEN_PERCENT;
818 ah->esc_stash = (char)c;
819 ah->ues = URIES_SEEN_PERCENT_H1;
827 *_c = (uint8_t)(unsigned int)((char_to_hex(ah->esc_stash) << 4) |
831 ah->ues = URIES_IDLE;
844 if (!c && (!ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] ||
845 !ah->post_literal_equal)) {
858 switch (ah->ups) {
866 wsi->http.ah->frags[wsi->http.ah->nfrag].len--;
868 ah->frags[ah->nfrag].nfrag = (uint8_t)(ah->nfrag + 1);
869 ah->nfrag++;
870 if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags))
873 ah->post_literal_equal = 0;
874 ah->frags[ah->nfrag].offset = ++ah->pos;
875 ah->frags[ah->nfrag].len = 0;
876 ah->frags[ah->nfrag].nfrag = 0;
881 ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] &&
882 !ah->post_literal_equal) {
889 ah->post_literal_equal = 1;
897 if (c == '/' && !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS])
898 ah->ups = URIPS_SEEN_SLASH;
906 ah->ups = URIPS_SEEN_SLASH_DOT;
909 ah->ups = URIPS_IDLE;
914 ah->ups = URIPS_SEEN_SLASH_DOT_DOT;
919 ah->ups = URIPS_SEEN_SLASH;
923 ah->ups = URIPS_IDLE;
937 if (ah->frags[ah->nfrag].len > 2) {
938 ah->pos--;
939 ah->frags[ah->nfrag].len--;
941 ah->pos--;
942 ah->frags[ah->nfrag].len--;
943 } while (ah->frags[ah->nfrag].len > 1 &&
944 ah->data[ah->pos] != '/');
946 ah->ups = URIPS_SEEN_SLASH;
947 if (ah->frags[ah->nfrag].len > 1)
958 ah->ups = URIPS_IDLE;
963 !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI args */
964 if (ah->ues != URIES_IDLE)
972 wsi->http.ah->frags[wsi->http.ah->nfrag].len--;
975 ah->nfrag++;
976 if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags))
978 ah->frags[ah->nfrag].offset = ++ah->pos;
979 ah->frags[ah->nfrag].len = 0;
980 ah->frags[ah->nfrag].nfrag = 0;
982 ah->post_literal_equal = 0;
983 ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag;
984 ah->ups = URIPS_IDLE;
1020 struct allocated_headers *ah = wsi->http.ah;
1026 assert(wsi->http.ah);
1032 switch (ah->parser_state) {
1039 lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos + 2],
1040 (uint16_t)(ah->pos - ah->unk_value_pos));
1041 ah->parser_state = WSI_TOKEN_NAME_PART;
1042 ah->unk_pos = 0;
1043 ah->lextable_pos = 0;
1048 if (ah->pos != ah->unk_value_pos ||
1054 ah->data[ah->pos++] = (char)c;
1056 pos = ah->lextable_pos;
1061 lwsl_parser("WSI_TOK_(%d) '%c'\n", ah->parser_state, c);
1065 if (!ah->frags[ah->frag_index[ah->parser_state]].len &&
1070 if (ah->parser_state == methods[m])
1080 if (!ah->frags[ah->nfrag].len)
1084 if (ah->ups == URIPS_SEEN_SLASH_DOT_DOT) {
1091 if (ah->frags[ah->nfrag].len > 2) {
1092 ah->pos--;
1093 ah->frags[ah->nfrag].len--;
1095 ah->pos--;
1096 ah->frags[ah->nfrag].len--;
1097 } while (ah->frags[ah->nfrag].len > 1 &&
1098 ah->data[ah->pos] != '/');
1106 wsi->http.ah->frags[wsi->http.ah->nfrag].len--;
1107 ah->parser_state = WSI_TOKEN_HTTP;
1126 if (ah->parser_state != WSI_TOKEN_CHALLENGE &&
1128 if (ah->ues != URIES_IDLE)
1133 ah->parser_state = WSI_TOKEN_NAME_PART;
1134 ah->unk_pos = 0;
1135 ah->lextable_pos = 0;
1137 ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR;
1147 ah->parser_state = WSI_TOKEN_SKIPPING;
1155 if (!c && ah->parser_state != WSI_TOKEN_HTTP_URI_ARGS)
1157 wsi->http.ah->frags[wsi->http.ah->nfrag].len--;
1163 if (ah->parser_state == WSI_TOKEN_CHALLENGE)
1173 ah->lextable_pos);
1175 if (!ah->unk_pos && c == '\x0a')
1187 if (!wsi->mux_substream && !ah->unk_pos) {
1188 ah->unk_pos = ah->pos;
1200 ah->data[ah->pos++] = 0;
1207 ah->data[ah->pos++] = (char)c;
1208 pos = ah->lextable_pos;
1223 if (!ah->unk_ll_head)
1224 ah->unk_ll_head = ah->unk_pos;
1226 if (ah->unk_ll_tail)
1228 (uint8_t *)&ah->data[ah->unk_ll_tail + UHO_LL],
1229 ah->unk_pos);
1231 ah->unk_ll_tail = ah->unk_pos;
1234 uhlen = (int)(ah->pos - (ah->unk_pos + UHO_NAME));
1236 &ah->data[ah->unk_pos + UHO_NAME],
1240 ah->pos - (ah->unk_pos + UHO_NAME),
1246 lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos],
1247 (uint16_t)((ah->pos - ah->unk_pos) - UHO_NAME));
1249 ah->unk_value_pos = ah->pos;
1255 ah->parser_state = WSI_TOKEN_UNKNOWN_VALUE_PART;
1267 ah->lextable_pos = -1;
1275 ah->lextable_pos = (int16_t)pos;
1291 ah->pos = ah->unk_pos;
1292 ah->unk_pos = 0;
1295 ah->lextable_pos = (int16_t)pos;
1300 ah->lextable_pos = (int16_t)(pos +
1315 if (ah->lextable_pos < 0 && lwsi_role_h1(wsi) &&
1323 if (ah->frag_index[methods[m]]) {
1328 ah->parser_state = WSI_TOKEN_SKIPPING;
1331 ah->parser_state = WSI_TOKEN_SKIPPING;
1367 if (ah->lextable_pos < 0) {
1379 ah->parser_state = WSI_TOKEN_SKIPPING;
1383 if (lextable_h1[ah->lextable_pos] < FAIL_CHAR) {
1386 n = ((unsigned int)lextable_h1[ah->lextable_pos] << 8) |
1387 lextable_h1[ah->lextable_pos + 1];
1392 ah->frag_index[methods[m]]) {
1403 ah->pos = ah->unk_pos;
1404 ah->unk_pos = 0;
1416 ah->parser_state = (uint8_t)
1418 ah->ups = URIPS_IDLE;
1421 ah->current_token_limit = context->
1423 ah->parser_state];
1425 ah->current_token_limit =
1428 if (ah->parser_state == WSI_TOKEN_CHALLENGE)
1437 //ah->parser_state = WSI_TOKEN_SKIPPING;
1444 ah->nfrag++;
1446 if (ah->nfrag == LWS_ARRAY_SIZE(ah->frags)) {
1451 ah->frags[ah->nfrag].offset = ah->pos;
1452 ah->frags[ah->nfrag].len = 0;
1453 ah->frags[ah->nfrag].nfrag = 0;
1454 ah->frags[ah->nfrag].flags = 2;
1456 n = ah->frag_index[ah->parser_state];
1458 ah->frag_index[ah->parser_state] = ah->nfrag;
1459 ah->hdr_token_idx = ah->parser_state;
1463 while (ah->frags[n].nfrag)
1464 n = ah->frags[n].nfrag;
1465 ah->frags[n].nfrag = ah->nfrag;
1477 ah->parser_state = WSI_TOKEN_NAME_PART;
1478 ah->unk_pos = 0;
1479 ah->lextable_pos = 0;
1483 ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR;
1488 if (ah->ues != URIES_IDLE)
1491 ah->parser_state = WSI_TOKEN_NAME_PART;
1492 ah->unk_pos = 0;
1493 ah->lextable_pos = 0;
1495 ah->parser_state = WSI_TOKEN_SKIPPING;
1509 if (ah->ues != URIES_IDLE)
1521 ah->parser_state = WSI_PARSING_COMPLETE;
1548 * This can come to us two ways, in ah fragments (h2) or as a single
1559 int f = wsi->http.ah->frag_index[WSI_TOKEN_HTTP_COOKIE];
1563 p = wsi->http.ah->data + wsi->http.ah->frags[f].offset;
1564 fl = (size_t)wsi->http.ah->frags[f].len;
1578 f = wsi->http.ah->frags[f].nfrag;