Lines Matching refs:req
157 httpc_free_state(httpc_state_t* req) in httpc_free_state() argument
161 if (req->request != NULL) { in httpc_free_state()
162 pbuf_free(req->request); in httpc_free_state()
163 req->request = NULL; in httpc_free_state()
165 if (req->rx_hdrs != NULL) { in httpc_free_state()
166 pbuf_free(req->rx_hdrs); in httpc_free_state()
167 req->rx_hdrs = NULL; in httpc_free_state()
170 tpcb = req->pcb; in httpc_free_state()
171 mem_free(req); in httpc_free_state()
172 req = NULL; in httpc_free_state()
192 httpc_close(httpc_state_t* req, httpc_result_t result, u32_t server_response, err_t err) in httpc_close() argument
194 if (req != NULL) { in httpc_close()
195 if (req->conn_settings != NULL) { in httpc_close()
196 if (req->conn_settings->result_fn != NULL) { in httpc_close()
197 …req->conn_settings->result_fn(req->callback_arg, result, req->rx_content_len, server_response, err… in httpc_close()
200 return httpc_free_state(req); in httpc_close()
282 httpc_state_t* req = (httpc_state_t*)arg; in httpc_tcp_recv() local
287 if (req->parse_state != HTTPC_PARSE_RX_DATA) { in httpc_tcp_recv()
290 } else if ((req->hdr_content_len != HTTPC_CONTENT_LEN_INVALID) && in httpc_tcp_recv()
291 (req->hdr_content_len != req->rx_content_len)) { in httpc_tcp_recv()
298 return httpc_close(req, result, req->rx_status, ERR_OK); in httpc_tcp_recv()
300 if (req->parse_state != HTTPC_PARSE_RX_DATA) { in httpc_tcp_recv()
301 if (req->rx_hdrs == NULL) { in httpc_tcp_recv()
302 req->rx_hdrs = p; in httpc_tcp_recv()
304 pbuf_cat(req->rx_hdrs, p); in httpc_tcp_recv()
306 if (req->parse_state == HTTPC_PARSE_WAIT_FIRST_LINE) { in httpc_tcp_recv()
308 …err_t err = http_parse_response_status(req->rx_hdrs, &req->rx_http_version, &req->rx_status, &stat… in httpc_tcp_recv()
311 req->parse_state = HTTPC_PARSE_WAIT_HEADERS; in httpc_tcp_recv()
314 if (req->parse_state == HTTPC_PARSE_WAIT_HEADERS) { in httpc_tcp_recv()
316 err_t err = http_wait_headers(req->rx_hdrs, &req->hdr_content_len, &total_header_len); in httpc_tcp_recv()
321 if (req->conn_settings) { in httpc_tcp_recv()
322 if (req->conn_settings->headers_done_fn) { in httpc_tcp_recv()
323 …err = req->conn_settings->headers_done_fn(req, req->callback_arg, req->rx_hdrs, total_header_len, … in httpc_tcp_recv()
325 return httpc_close(req, HTTPC_RESULT_LOCAL_ABORT, req->rx_status, err); in httpc_tcp_recv()
330 q = pbuf_free_header(req->rx_hdrs, total_header_len); in httpc_tcp_recv()
332 req->rx_hdrs = NULL; in httpc_tcp_recv()
334 req->parse_state = HTTPC_PARSE_RX_DATA; in httpc_tcp_recv()
338 if ((p != NULL) && (req->parse_state == HTTPC_PARSE_RX_DATA)) { in httpc_tcp_recv()
339 req->rx_content_len += p->tot_len; in httpc_tcp_recv()
340 if (req->recv_fn != NULL) { in httpc_tcp_recv()
342 return req->recv_fn(req->callback_arg, pcb, p, r); in httpc_tcp_recv()
355 httpc_state_t* req = (httpc_state_t*)arg; in httpc_tcp_err() local
356 if (req != NULL) { in httpc_tcp_err()
358 req->pcb = NULL; in httpc_tcp_err()
359 httpc_close(req, HTTPC_RESULT_ERR_CLOSED, 0, err); in httpc_tcp_err()
368 httpc_state_t* req = (httpc_state_t*)arg; in httpc_tcp_poll() local
370 if (req != NULL) { in httpc_tcp_poll()
371 if (req->timeout_ticks) { in httpc_tcp_poll()
372 req->timeout_ticks--; in httpc_tcp_poll()
374 if (!req->timeout_ticks) { in httpc_tcp_poll()
375 return httpc_close(req, HTTPC_RESULT_ERR_TIMEOUT, 0, ERR_OK); in httpc_tcp_poll()
397 httpc_state_t* req = (httpc_state_t*)arg; in httpc_tcp_connected() local
402 r = altcp_write(req->pcb, req->request->payload, req->request->len - 1, TCP_WRITE_FLAG_COPY); in httpc_tcp_connected()
405 return httpc_close(req, HTTPC_RESULT_ERR_MEM, 0, r); in httpc_tcp_connected()
408 pbuf_free(req->request); in httpc_tcp_connected()
409 req->request = NULL; in httpc_tcp_connected()
411 altcp_output(req->pcb); in httpc_tcp_connected()
417 httpc_get_internal_addr(httpc_state_t* req, const ip_addr_t *ipaddr) in httpc_get_internal_addr() argument
420 LWIP_ASSERT("req != NULL", req != NULL); in httpc_get_internal_addr()
422 if (&req->remote_addr != ipaddr) { in httpc_get_internal_addr()
424 req->remote_addr = *ipaddr; in httpc_get_internal_addr()
427 err = altcp_connect(req->pcb, &req->remote_addr, req->remote_port, httpc_tcp_connected); in httpc_get_internal_addr()
442 httpc_state_t* req = (httpc_state_t*)arg; in httpc_dns_found() local
449 err = httpc_get_internal_addr(req, ipaddr); in httpc_dns_found()
460 httpc_close(req, result, 0, err); in httpc_dns_found()
466 httpc_get_internal_dns(httpc_state_t* req, const char* server_name) in httpc_get_internal_dns() argument
469 LWIP_ASSERT("req != NULL", req != NULL); in httpc_get_internal_dns()
472 err = dns_gethostbyname(server_name, &req->remote_addr, httpc_dns_found, req); in httpc_get_internal_dns()
474 err = ipaddr_aton(server_name, &req->remote_addr) ? ERR_OK : ERR_ARG; in httpc_get_internal_dns()
479 err = httpc_get_internal_addr(req, &req->remote_addr); in httpc_get_internal_dns()
513 httpc_state_t *req; in httpc_init_connection_common() local
537 req = (httpc_state_t*)mem_malloc((mem_size_t)alloc_len); in httpc_init_connection_common()
538 if(req == NULL) { in httpc_init_connection_common()
541 memset(req, 0, sizeof(httpc_state_t)); in httpc_init_connection_common()
542 req->timeout_ticks = HTTPC_POLL_TIMEOUT; in httpc_init_connection_common()
543 req->request = pbuf_alloc(PBUF_RAW, (u16_t)(req_len + 1), PBUF_RAM); in httpc_init_connection_common()
544 if (req->request == NULL) { in httpc_init_connection_common()
545 httpc_free_state(req); in httpc_init_connection_common()
548 if (req->request->next != NULL) { in httpc_init_connection_common()
550 httpc_free_state(req); in httpc_init_connection_common()
553 req->hdr_content_len = HTTPC_CONTENT_LEN_INVALID; in httpc_init_connection_common()
555 req->server_name = (char*)(req + 1); in httpc_init_connection_common()
557 memcpy(req->server_name, server_name, server_name_len + 1); in httpc_init_connection_common()
559 req->uri = req->server_name + server_name_len + 1; in httpc_init_connection_common()
560 memcpy(req->uri, uri, uri_len + 1); in httpc_init_connection_common()
562 req->pcb = altcp_new(settings->altcp_allocator); in httpc_init_connection_common()
563 if(req->pcb == NULL) { in httpc_init_connection_common()
564 httpc_free_state(req); in httpc_init_connection_common()
567 req->remote_port = settings->use_proxy ? settings->proxy_port : server_port; in httpc_init_connection_common()
568 altcp_arg(req->pcb, req); in httpc_init_connection_common()
569 altcp_recv(req->pcb, httpc_tcp_recv); in httpc_init_connection_common()
570 altcp_err(req->pcb, httpc_tcp_err); in httpc_init_connection_common()
571 altcp_poll(req->pcb, httpc_tcp_poll, HTTPC_POLL_INTERVAL); in httpc_init_connection_common()
572 altcp_sent(req->pcb, httpc_tcp_sent); in httpc_init_connection_common()
576 (char *)req->request->payload, req_len + 1); in httpc_init_connection_common()
578 httpc_free_state(req); in httpc_init_connection_common()
582 req->recv_fn = recv_fn; in httpc_init_connection_common()
583 req->conn_settings = settings; in httpc_init_connection_common()
584 req->callback_arg = callback_arg; in httpc_init_connection_common()
586 *connection = req; in httpc_init_connection_common()
636 httpc_state_t* req; in httpc_get_file() local
640 err = httpc_init_connection_addr(&req, settings, server_addr, port, in httpc_get_file()
647 err = httpc_get_internal_addr(req, &settings->proxy_addr); in httpc_get_file()
649 err = httpc_get_internal_addr(req, server_addr); in httpc_get_file()
652 httpc_free_state(req); in httpc_get_file()
657 *connection = req; in httpc_get_file()
681 httpc_state_t* req; in httpc_get_file_dns() local
685 err = httpc_init_connection(&req, settings, server_name, port, uri, recv_fn, callback_arg); in httpc_get_file_dns()
691 err = httpc_get_internal_addr(req, &settings->proxy_addr); in httpc_get_file_dns()
693 err = httpc_get_internal_dns(req, server_name); in httpc_get_file_dns()
696 httpc_free_state(req); in httpc_get_file_dns()
701 *connection = req; in httpc_get_file_dns()
822 httpc_state_t* req; in httpc_get_file_to_disk() local
832 err = httpc_init_connection_addr(&req, &filestate->settings, server_addr, port, in httpc_get_file_to_disk()
840 err = httpc_get_internal_addr(req, &settings->proxy_addr); in httpc_get_file_to_disk()
842 err = httpc_get_internal_addr(req, server_addr); in httpc_get_file_to_disk()
846 httpc_free_state(req); in httpc_get_file_to_disk()
851 *connection = req; in httpc_get_file_to_disk()
874 httpc_state_t* req; in httpc_get_file_dns_to_disk() local
884 err = httpc_init_connection(&req, &filestate->settings, server_name, port, in httpc_get_file_dns_to_disk()
892 err = httpc_get_internal_addr(req, &settings->proxy_addr); in httpc_get_file_dns_to_disk()
894 err = httpc_get_internal_dns(req, server_name); in httpc_get_file_dns_to_disk()
898 httpc_free_state(req); in httpc_get_file_dns_to_disk()
903 *connection = req; in httpc_get_file_dns_to_disk()