Lines Matching refs:h

127 void httpread_destroy(struct httpread *h)  in httpread_destroy()  argument
129 wpa_printf(MSG_DEBUG, "httpread_destroy(%p)", h); in httpread_destroy()
130 if (!h) in httpread_destroy()
133 eloop_cancel_timeout(httpread_timeout_handler, NULL, h); in httpread_destroy()
134 eloop_unregister_sock(h->sd, EVENT_TYPE_READ); in httpread_destroy()
135 os_free(h->body); in httpread_destroy()
136 os_free(h->uri); in httpread_destroy()
137 os_memset(h, 0, sizeof(*h)); /* aid debugging */ in httpread_destroy()
138 h->sd = -1; /* aid debugging */ in httpread_destroy()
139 os_free(h); in httpread_destroy()
147 struct httpread *h = user_ctx; in httpread_timeout_handler() local
148 wpa_printf(MSG_DEBUG, "httpread timeout (%p)", h); in httpread_timeout_handler()
149 (*h->cb)(h, h->cookie, HTTPREAD_EVENT_TIMEOUT); in httpread_timeout_handler()
157 struct httpread *h, in httpread_hdr_option_analyze() argument
168 h->content_length = atol(hbp); in httpread_hdr_option_analyze()
169 if (h->content_length < 0 || h->content_length > h->max_bytes) { in httpread_hdr_option_analyze()
172 h->content_length); in httpread_hdr_option_analyze()
175 h->got_content_length = 1; in httpread_hdr_option_analyze()
188 h->chunked = 1; in httpread_hdr_option_analyze()
189 h->in_chunk_data = 0; in httpread_hdr_option_analyze()
199 static int httpread_hdr_analyze(struct httpread *h) in httpread_hdr_analyze() argument
201 char *hbp = h->hdr; /* pointer into h->hdr */ in httpread_hdr_analyze()
205 h->hdr_type = HTTPREAD_HDR_TYPE_UNKNOWN; in httpread_hdr_analyze()
209 h->hdr_type = HTTPREAD_HDR_TYPE_REPLY; in httpread_hdr_analyze()
214 h->version = 1; in httpread_hdr_analyze()
221 h->reply_code = atol(hbp); in httpread_hdr_analyze()
223 h->hdr_type = HTTPREAD_HDR_TYPE_GET; in httpread_hdr_analyze()
225 h->hdr_type = HTTPREAD_HDR_TYPE_HEAD; in httpread_hdr_analyze()
227 h->hdr_type = HTTPREAD_HDR_TYPE_POST; in httpread_hdr_analyze()
229 h->hdr_type = HTTPREAD_HDR_TYPE_PUT; in httpread_hdr_analyze()
231 h->hdr_type = HTTPREAD_HDR_TYPE_DELETE; in httpread_hdr_analyze()
233 h->hdr_type = HTTPREAD_HDR_TYPE_TRACE; in httpread_hdr_analyze()
235 h->hdr_type = HTTPREAD_HDR_TYPE_CONNECT; in httpread_hdr_analyze()
237 h->hdr_type = HTTPREAD_HDR_TYPE_NOTIFY; in httpread_hdr_analyze()
239 h->hdr_type = HTTPREAD_HDR_TYPE_M_SEARCH; in httpread_hdr_analyze()
241 h->hdr_type = HTTPREAD_HDR_TYPE_M_POST; in httpread_hdr_analyze()
243 h->hdr_type = HTTPREAD_HDR_TYPE_SUBSCRIBE; in httpread_hdr_analyze()
245 h->hdr_type = HTTPREAD_HDR_TYPE_UNSUBSCRIBE; in httpread_hdr_analyze()
265 h->uri = os_malloc((hbp - rawuri) + 1); in httpread_hdr_analyze()
266 if (h->uri == NULL) in httpread_hdr_analyze()
268 uri = h->uri; in httpread_hdr_analyze()
288 h->version = 1; in httpread_hdr_analyze()
306 if (httpread_hdr_option_analyze(h, hbp)) in httpread_hdr_analyze()
315 if (h->chunked) in httpread_hdr_analyze()
316 h->got_content_length = 0; in httpread_hdr_analyze()
322 switch (h->hdr_type) { in httpread_hdr_analyze()
328 if (h->reply_code != 200) in httpread_hdr_analyze()
329 h->max_bytes = 0; in httpread_hdr_analyze()
336 if (h->chunked == 0 && h->got_content_length == 0) in httpread_hdr_analyze()
337 h->max_bytes = 0; in httpread_hdr_analyze()
369 struct httpread *h = sock_ctx; in httpread_read_handler() local
379 wpa_printf(MSG_DEBUG, "httpread: Trying to read more data(%p)", h); in httpread_read_handler()
380 nread = read(h->sd, readbuf, sizeof(readbuf)); in httpread_read_handler()
391 if (!h->got_hdr) { in httpread_read_handler()
393 wpa_printf(MSG_DEBUG, "httpread premature eof(%p)", h); in httpread_read_handler()
396 if (h->chunked || h->got_content_length) { in httpread_read_handler()
400 h, h->body_nbytes, in httpread_read_handler()
401 h->content_length); in httpread_read_handler()
408 wpa_printf(MSG_DEBUG, "httpread ok eof(%p)", h); in httpread_read_handler()
409 h->got_body = 1; in httpread_read_handler()
417 if (!h->got_hdr) { in httpread_read_handler()
418 hbp = h->hdr + h->hdr_nbytes; in httpread_read_handler()
427 if (h->hdr_nbytes == HTTPREAD_HEADER_MAX_SIZE) { in httpread_read_handler()
434 h->hdr_nbytes++; in httpread_read_handler()
435 if (h->hdr_nbytes >= 4 && in httpread_read_handler()
440 h->got_hdr = 1; in httpread_read_handler()
446 if (httpread_hdr_analyze(h)) { in httpread_read_handler()
447 wpa_printf(MSG_DEBUG, "httpread bad hdr(%p)", h); in httpread_read_handler()
450 if (h->max_bytes == 0) { in httpread_read_handler()
452 h); in httpread_read_handler()
455 if (h->got_content_length && h->content_length == 0) { in httpread_read_handler()
457 "httpread zero content length(%p)", h); in httpread_read_handler()
465 if (!os_strncasecmp(h->hdr, "SUBSCRIBE", 9) || in httpread_read_handler()
466 !os_strncasecmp(h->hdr, "UNSUBSCRIBE", 11) || in httpread_read_handler()
467 !os_strncasecmp(h->hdr, "HEAD", 4) || in httpread_read_handler()
468 !os_strncasecmp(h->hdr, "GET", 3)) { in httpread_read_handler()
469 if (!h->got_body) { in httpread_read_handler()
472 h->got_body = 1; in httpread_read_handler()
482 if (!h->got_body) { in httpread_read_handler()
487 if (h->body_alloc_nbytes < (h->body_nbytes + nread + 1)) { in httpread_read_handler()
491 if (h->body_nbytes >= h->max_bytes) { in httpread_read_handler()
494 h->body_nbytes, h->max_bytes); in httpread_read_handler()
497 new_alloc_nbytes = h->body_alloc_nbytes + in httpread_read_handler()
503 if (h->got_content_length && in httpread_read_handler()
504 new_alloc_nbytes < (h->content_length + 1)) in httpread_read_handler()
505 new_alloc_nbytes = h->content_length + 1; in httpread_read_handler()
506 if (new_alloc_nbytes < h->body_alloc_nbytes || in httpread_read_handler()
507 new_alloc_nbytes > h->max_bytes + in httpread_read_handler()
512 h->body_alloc_nbytes, in httpread_read_handler()
513 h->max_bytes); in httpread_read_handler()
516 if ((new_body = os_realloc(h->body, new_alloc_nbytes)) in httpread_read_handler()
524 h->body = new_body; in httpread_read_handler()
525 h->body_alloc_nbytes = new_alloc_nbytes; in httpread_read_handler()
528 bbp = h->body + h->body_nbytes; in httpread_read_handler()
532 if (h->chunked && h->in_chunk_data == 0) { in httpread_read_handler()
534 char *cbp = h->body + h->chunk_start; in httpread_read_handler()
546 h->chunk_size = strtoul(cbp, NULL, 16); in httpread_read_handler()
547 if (h->chunk_size < 0 || in httpread_read_handler()
548 h->chunk_size > h->max_bytes) { in httpread_read_handler()
551 h->chunk_size); in httpread_read_handler()
557 h->body_nbytes = h->chunk_start; in httpread_read_handler()
559 if (h->chunk_size == 0) { in httpread_read_handler()
562 h->in_trailer = 1; in httpread_read_handler()
565 h); in httpread_read_handler()
568 h->in_chunk_data = 1; in httpread_read_handler()
571 } else if (h->chunked) { in httpread_read_handler()
573 if ((h->body_nbytes - h->chunk_start) == in httpread_read_handler()
574 (h->chunk_size + 2)) { in httpread_read_handler()
588 h->body_nbytes -= 2; in httpread_read_handler()
590 h->chunk_start = h->body_nbytes; in httpread_read_handler()
591 h->in_chunk_data = 0; in httpread_read_handler()
592 h->chunk_size = 0; /* just in case */ in httpread_read_handler()
594 } else if (h->got_content_length && in httpread_read_handler()
595 h->body_nbytes >= h->content_length) { in httpread_read_handler()
596 h->got_body = 1; in httpread_read_handler()
598 "httpread got content(%p)", h); in httpread_read_handler()
604 if (h->chunked && h->in_chunk_data) { in httpread_read_handler()
608 ncopy = (h->chunk_start + h->chunk_size + 2) - in httpread_read_handler()
609 h->body_nbytes; in httpread_read_handler()
610 } else if (h->chunked) { in httpread_read_handler()
614 h->body_nbytes++; in httpread_read_handler()
616 } else if (h->got_content_length) { in httpread_read_handler()
617 ncopy = h->content_length - h->body_nbytes; in httpread_read_handler()
631 h->body_nbytes += ncopy; in httpread_read_handler()
636 if (h->chunked && h->in_trailer) { in httpread_read_handler()
649 switch (h->trailer_state) { in httpread_read_handler()
652 h->trailer_state = trailer_empty_cr; in httpread_read_handler()
654 h->trailer_state = trailer_nonempty; in httpread_read_handler()
659 h->trailer_state = trailer_line_begin; in httpread_read_handler()
660 h->in_trailer = 0; in httpread_read_handler()
663 h); in httpread_read_handler()
664 h->got_body = 1; in httpread_read_handler()
667 h->trailer_state = trailer_nonempty; in httpread_read_handler()
671 h->trailer_state = trailer_nonempty_cr; in httpread_read_handler()
675 h->trailer_state = trailer_line_begin; in httpread_read_handler()
677 h->trailer_state = trailer_nonempty; in httpread_read_handler()
686 wpa_printf(MSG_DEBUG, "httpread read/parse failure (%p)", h); in httpread_read_handler()
687 (*h->cb)(h, h->cookie, HTTPREAD_EVENT_ERROR); in httpread_read_handler()
691 wpa_printf(MSG_DEBUG, "httpread: get more (%p)", h); in httpread_read_handler()
696 h->body_nbytes, h->hdr_type); in httpread_read_handler()
698 h->body, h->body_nbytes); in httpread_read_handler()
700 if (h->body) in httpread_read_handler()
701 h->body[h->body_nbytes] = 0; /* null terminate */ in httpread_read_handler()
702 h->got_file = 1; in httpread_read_handler()
707 eloop_unregister_sock(h->sd, EVENT_TYPE_READ); in httpread_read_handler()
711 eloop_cancel_timeout(httpread_timeout_handler, NULL, h); in httpread_read_handler()
712 (*h->cb)(h, h->cookie, HTTPREAD_EVENT_FILE_READY); in httpread_read_handler()
738 struct httpread *h = NULL; in httpread_create() local
740 h = os_zalloc(sizeof(*h)); in httpread_create()
741 if (h == NULL) in httpread_create()
743 h->sd = sd; in httpread_create()
744 h->cb = cb; in httpread_create()
745 h->cookie = cookie; in httpread_create()
746 h->max_bytes = max_bytes; in httpread_create()
747 h->timeout_seconds = timeout_seconds; in httpread_create()
751 httpread_timeout_handler, NULL, h)) { in httpread_create()
756 NULL, h)) { in httpread_create()
760 return h; in httpread_create()
765 httpread_destroy(h); in httpread_create()
771 enum httpread_hdr_type httpread_hdr_type_get(struct httpread *h) in httpread_hdr_type_get() argument
773 return h->hdr_type; in httpread_hdr_type_get()
780 char * httpread_uri_get(struct httpread *h) in httpread_uri_get() argument
782 return h->uri; in httpread_uri_get()
787 int httpread_reply_code_get(struct httpread *h) in httpread_reply_code_get() argument
789 return h->reply_code; in httpread_reply_code_get()
794 int httpread_length_get(struct httpread *h) in httpread_length_get() argument
796 return h->body_nbytes; in httpread_length_get()
804 void * httpread_data_get(struct httpread *h) in httpread_data_get() argument
806 return h->body ? h->body : ""; in httpread_data_get()
814 char * httpread_hdr_get(struct httpread *h) in httpread_hdr_get() argument
816 return h->hdr; in httpread_hdr_get()
828 char * httpread_hdr_line_get(struct httpread *h, const char *tag) in httpread_hdr_line_get() argument
831 char *hdr = h->hdr; in httpread_hdr_line_get()