Lines Matching refs:http

47 #include <gpxe/http.h>
95 struct http_request *http =
98 uri_put ( http->uri );
99 empty_line_buffer ( &http->linebuf );
100 free ( http );
106 * @v http HTTP request
109 static void http_done ( struct http_request *http, int rc ) {
112 http->rx_state = HTTP_RX_DEAD;
117 if ( http->content_length &&
118 ( http->content_length != http->rx_len ) ) {
119 DBGC ( http, "HTTP %p incorrect length %zd, should be %zd\n",
120 http, http->rx_len, http->content_length );
125 process_del ( &http->process );
128 xfer_nullify ( &http->socket );
129 xfer_close ( &http->socket, rc );
130 xfer_nullify ( &http->xfer );
131 xfer_close ( &http->xfer, rc );
160 * @v http HTTP request
164 static int http_rx_response ( struct http_request *http, char *response ) {
168 DBGC ( http, "HTTP %p response \"%s\"\n", http, response );
178 http->response = strtoul ( spc, NULL, 10 );
179 if ( ( rc = http_response_to_rc ( http->response ) ) != 0 )
183 http->rx_state = HTTP_RX_HEADER;
190 * @v http HTTP request
194 static int http_rx_location ( struct http_request *http, const char *value ) {
198 DBGC ( http, "HTTP %p redirecting to %s\n", http, value );
199 if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI_STRING,
201 DBGC ( http, "HTTP %p could not redirect: %s\n",
202 http, strerror ( rc ) );
212 * @v http HTTP request
216 static int http_rx_content_length ( struct http_request *http,
220 http->content_length = strtoul ( value, &endp, 10 );
222 DBGC ( http, "HTTP %p invalid Content-Length \"%s\"\n",
223 http, value );
228 xfer_seek ( &http->xfer, http->content_length, SEEK_SET );
229 xfer_seek ( &http->xfer, 0, SEEK_SET );
240 * @v http HTTP request
246 int ( * rx ) ( struct http_request *http, const char *value );
265 * @v http HTTP request
269 static int http_rx_header ( struct http_request *http, char *header ) {
277 DBGC ( http, "HTTP %p start of data\n", http );
278 empty_line_buffer ( &http->linebuf );
279 http->rx_state = HTTP_RX_DATA;
283 DBGC ( http, "HTTP %p header \"%s\"\n", http, header );
288 DBGC ( http, "HTTP %p malformed header\n", http );
297 if ( ( rc = handler->rx ( http, value ) ) != 0 )
309 * @v http HTTP request
313 int ( * rx ) ( struct http_request *http, char *line );
325 * @v http HTTP request
329 static int http_rx_data ( struct http_request *http,
334 http->rx_len += iob_len ( iobuf );
337 if ( ( rc = xfer_deliver_iob ( &http->xfer, iobuf ) ) != 0 )
341 if ( http->content_length &&
342 ( http->rx_len >= http->content_length ) ) {
343 http_done ( http, 0 );
360 struct http_request *http =
368 switch ( http->rx_state ) {
376 rc = http_rx_data ( http, iob_disown ( iobuf ) );
383 len = line_buffer ( &http->linebuf, iobuf->data,
387 DBGC ( http, "HTTP %p could not buffer line: "
388 "%s\n", http, strerror ( rc ) );
392 line = buffered_line ( &http->linebuf );
394 lh = &http_line_handlers[http->rx_state];
395 if ( ( rc = lh->rx ( http, line ) ) != 0 )
407 http_done ( http, rc );
418 struct http_request *http =
420 const char *host = http->uri->host;
421 const char *user = http->uri->user;
423 ( http->uri->password ? http->uri->password : "" );
430 int request_len = unparse_uri ( NULL, 0, http->uri,
433 if ( xfer_window ( &http->socket ) ) {
437 unparse_uri ( request, sizeof ( request ), http->uri,
441 process_del ( &http->process );
454 if ( ( rc = xfer_printf ( &http->socket,
460 http->uri->path ? "" : "/",
467 http_done ( http, rc );
479 struct http_request *http =
482 DBGC ( http, "HTTP %p socket closed: %s\n",
483 http, strerror ( rc ) );
485 http_done ( http, rc );
505 struct http_request *http =
508 DBGC ( http, "HTTP %p interface closed: %s\n",
509 http, strerror ( rc ) );
511 http_done ( http, rc );
537 struct http_request *http;
547 http = zalloc ( sizeof ( *http ) );
548 if ( ! http )
550 http->refcnt.free = http_free;
551 xfer_init ( &http->xfer, &http_xfer_operations, &http->refcnt );
552 http->uri = uri_get ( uri );
553 xfer_init ( &http->socket, &http_socket_operations, &http->refcnt );
554 process_init ( &http->process, http_step, &http->refcnt );
558 server.st_port = htons ( uri_port ( http->uri, default_port ) );
559 socket = &http->socket;
570 xfer_plug_plug ( &http->xfer, xfer );
571 ref_put ( &http->refcnt );
575 DBGC ( http, "HTTP %p could not create request: %s\n",
576 http, strerror ( rc ) );
577 http_done ( http, rc );
578 ref_put ( &http->refcnt );
595 .scheme = "http",