Changeset 4d4f656 in mainline for uspace/lib/http/src/response.c


Ignore:
Timestamp:
2013-09-26T20:50:52Z (12 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
408424e
Parents:
b623b68
Message:

libhttp: Add higher-level API for working with headers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/http/src/response.c

    rb623b68 r4d4f656  
    4040
    4141#include <http/http.h>
     42#include <http/errno.h>
    4243
    4344int http_parse_status(const char *line, http_version_t *out_version,
     
    9899                return ENOMEM;
    99100        memset(resp, 0, sizeof(http_response_t));
    100         list_initialize(&resp->headers);
     101        http_headers_init(&resp->headers);
    101102       
    102103        char *line = malloc(http->buffer_size);
     
    115116                goto error;
    116117       
    117         while (true) {
    118                 rc = recv_eol(&http->recv_buffer);
    119                 if (rc < 0)
    120                         goto error;
    121                
    122                 /* Empty line ends header part */
    123                 if (rc > 0)
    124                         break;
    125                
    126                 http_header_t *header = malloc(sizeof(http_header_t));
    127                 if (header == NULL) {
    128                         rc = ENOMEM;
    129                         goto error;
    130                 }
    131                 http_header_init(header);
    132                
    133                 rc = http_header_receive(&http->recv_buffer, header);
    134                 if (rc != EOK) {
    135                         free(header);
    136                         goto error;
    137                 }
    138                
    139                 list_append(&header->link, &resp->headers);
    140         }
     118        rc = http_headers_receive(&http->recv_buffer, &resp->headers);
     119        if (rc != EOK)
     120                goto error;
     121       
     122        rc = recv_eol(&http->recv_buffer);
     123        if (rc == 0)
     124                rc = HTTP_EPARSE;
     125        if (rc < 0)
     126                goto error;
    141127       
    142128        *out_response = resp;
     
    157143{
    158144        free(resp->message);
    159         link_t *link = resp->headers.head.next;
    160         while (link != &resp->headers.head) {
    161                 link_t *next = link->next;
    162                 http_header_t *header = list_get_instance(link, http_header_t, link);
    163                 http_header_destroy(header);
    164                 link = next;
    165         }
     145        http_headers_clear(&resp->headers);
    166146        free(resp);
    167147}
Note: See TracChangeset for help on using the changeset viewer.