Ignore:
File:
1 edited

Legend:

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

    r5a6cc679 ra35b458  
    6464                return NULL;
    6565        }
    66        
     66
    6767        header->value = str_dup(value);
    6868        if (header->value == NULL) {
     
    101101                if (name_end)
    102102                        recv_mark_update(rb, name_end);
    103                
     103
    104104                errno_t rc = recv_char(rb, &c, true);
    105105                if (rc != EOK)
    106106                        return rc;
    107107        } while (is_token(c));
    108        
     108
    109109        if (c != ':')
    110110                return EINVAL;
    111        
     111
    112112        return EOK;
    113113}
     
    118118        errno_t rc = EOK;
    119119        char c = 0;
    120        
     120
    121121        /* Ignore any inline LWS */
    122122        while (true) {
    123123                if (value_start)
    124124                        recv_mark_update(rb, value_start);
    125                
     125
    126126                rc = recv_char(rb, &c, false);
    127127                if (rc != EOK)
    128128                        return rc;
    129                
     129
    130130                if (c != ' ' && c != '\t')
    131131                        break;
    132                
     132
    133133                rc = recv_char(rb, &c, true);
    134134                if (rc != EOK)
    135135                        return rc;
    136136        }
    137        
     137
    138138        while (true) {
    139139                recv_mark_update(rb, value_end);
    140                
     140
    141141                rc = recv_char(rb, &c, true);
    142142                if (rc != EOK)
    143143                        return rc;
    144                
     144
    145145                if (c != '\r' && c != '\n')
    146146                        continue;
    147                
     147
    148148                size_t nrecv;
    149149                rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nrecv);
    150150                if (rc != EOK)
    151151                        return rc;
    152                
     152
    153153                rc = recv_char(rb, &c, false);
    154154                if (rc != EOK)
    155155                        return rc;
    156                
     156
    157157                if (c != ' ' && c != '\t')
    158158                        break;
    159                
     159
    160160                /* Ignore the char */
    161161                rc = recv_char(rb, &c, true);
     
    163163                        return rc;
    164164        }
    165        
     165
    166166        return EOK;
    167167}
     
    172172        receive_buffer_mark_t mark_start;
    173173        receive_buffer_mark_t mark_end;
    174        
     174
    175175        recv_mark(rb, &mark_start);
    176176        recv_mark(rb, &mark_end);
    177        
     177
    178178        errno_t rc = http_header_receive_name(rb, &mark_end);
    179179        if (rc != EOK)
    180180                goto end;
    181        
     181
    182182        size_t name_size = mark_end.offset - mark_start.offset;
    183183        if (size_limit > 0 && name_size > size_limit) {
     
    185185                goto end;
    186186        }
    187        
     187
    188188        char *name = NULL;
    189189        rc = recv_cut_str(rb, &mark_start, &mark_end, &name);
    190190        if (rc != EOK)
    191191                goto end;
    192        
     192
    193193        rc = http_header_receive_value(rb, &mark_start, &mark_end);
    194194        if (rc != EOK)
    195195                goto end_with_name;
    196        
     196
    197197        size_t value_size = mark_end.offset - mark_start.offset;
    198198        if (size_limit > 0 && (name_size + value_size) > size_limit) {
     
    200200                goto end_with_name;
    201201        }
    202        
     202
    203203        char *value = NULL;
    204204        rc = recv_cut_str(rb, &mark_start, &mark_end, &value);
    205205        if (rc != EOK)
    206206                goto end_with_name;
    207        
     207
    208208        if (out_bytes_used)
    209209                *out_bytes_used = name_size + value_size;
    210        
     210
    211211        header->name = name;
    212212        header->value = value;
     
    228228        size_t read_index = 0;
    229229        size_t write_index = 0;
    230        
     230
    231231        while (is_lws(value[read_index])) read_index++;
    232        
     232
    233233        while (value[read_index] != 0) {
    234234                if (is_lws(value[read_index])) {
    235235                        while (is_lws(value[read_index])) read_index++;
    236                        
     236
    237237                        if (value[read_index] != 0)
    238238                                value[write_index++] = ' ';
    239                        
     239
    240240                        continue;
    241241                }
    242                
     242
    243243                value[write_index++] = value[read_index++];
    244244        }
    245        
     245
    246246        value[write_index] = 0;
    247247}
     
    266266                if (!http_header_name_match(header->name, name))
    267267                        continue;
    268                
     268
    269269                if (found == NULL) {
    270270                        found = header;
     
    274274                }
    275275        }
    276        
     276
    277277        if (found == NULL)
    278278                return HTTP_EMISSING_HEADER;
    279        
     279
    280280        *out_header = found;
    281281        return EOK;
     
    288288        if (header == NULL)
    289289                return ENOMEM;
    290        
     290
    291291        http_headers_append_header(headers, header);
    292292        return EOK;
     
    300300        if (rc != EOK && rc != HTTP_EMISSING_HEADER)
    301301                return rc;
    302        
     302
    303303        if (rc == HTTP_EMISSING_HEADER)
    304304                return http_headers_append(headers, name, value);
    305        
     305
    306306        char *new_value = str_dup(value);
    307307        if (new_value == NULL)
    308308                return ENOMEM;
    309        
     309
    310310        free(header->value);
    311311        header->value = new_value;
     
    319319        if (rc != EOK)
    320320                return rc;
    321        
     321
    322322        *value = header->value;
    323323        return EOK;
     
    329329        errno_t rc = EOK;
    330330        unsigned added = 0;
    331        
     331
    332332        while (true) {
    333333                char c = 0;
     
    335335                if (rc != EOK)
    336336                        goto error;
    337                
     337
    338338                if (c == '\n' || c == '\r')
    339339                        break;
    340                
     340
    341341                if (limit_count > 0 && added >= limit_count) {
    342342                        rc = ELIMIT;
    343343                        goto error;
    344344                }
    345                
     345
    346346                http_header_t *header = malloc(sizeof(http_header_t));
    347347                if (header == NULL) {
     
    350350                }
    351351                http_header_init(header);
    352                
     352
    353353                size_t header_size;
    354354                rc = http_header_receive(rb, header, limit_alloc, &header_size);
     
    358358                }
    359359                limit_alloc -= header_size;
    360                
     360
    361361                http_headers_append_header(headers, header);
    362362                added++;
    363363        }
    364        
     364
    365365        return EOK;
    366366error:
Note: See TracChangeset for help on using the changeset viewer.