Changeset a35b458 in mainline for uspace/lib/http


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/lib/http
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/http/include/http/receive-buffer.h

    r3061bc1 ra35b458  
    5656        size_t in;
    5757        size_t out;
    58        
     58
    5959        void *client_data;
    6060        receive_func_t receive;
    61        
     61
    6262        list_t marks;
    6363} receive_buffer_t;
  • uspace/lib/http/src/headers.c

    r3061bc1 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:
  • uspace/lib/http/src/http.c

    r3061bc1 ra35b458  
    6060        if (http == NULL)
    6161                return NULL;
    62        
     62
    6363        http->host = str_dup(host);
    6464        if (http->host == NULL) {
     
    6767        }
    6868        http->port = port;
    69        
     69
    7070        http->buffer_size = 4096;
    7171        errno_t rc = recv_buffer_init(&http->recv_buffer, http->buffer_size,
     
    7575                return NULL;
    7676        }
    77        
     77
    7878        return http;
    7979}
     
    8383        if (http->conn != NULL)
    8484                return EBUSY;
    85        
     85
    8686        errno_t rc = inet_host_plookup_one(http->host, ip_any, &http->addr, NULL,
    8787            NULL);
    8888        if (rc != EOK)
    8989                return rc;
    90        
     90
    9191        inet_ep2_t epp;
    92        
     92
    9393        inet_ep2_init(&epp);
    9494        epp.remote.addr = http->addr;
    9595        epp.remote.port = http->port;
    96        
     96
    9797        rc = tcp_create(&http->tcp);
    9898        if (rc != EOK)
    9999                return rc;
    100        
     100
    101101        rc = tcp_conn_create(http->tcp, &epp, NULL, NULL, &http->conn);
    102102        if (rc != EOK)
    103103                return rc;
    104        
     104
    105105        rc = tcp_conn_wait_connected(http->conn);
    106106        if (rc != EOK)
    107107                return rc;
    108        
     108
    109109        return rc;
    110110}
     
    114114        if (http->conn == NULL)
    115115                return EINVAL;
    116        
     116
    117117        tcp_conn_destroy(http->conn);
    118118        http->conn = NULL;
    119119        tcp_destroy(http->tcp);
    120120        http->tcp = NULL;
    121        
     121
    122122        return EOK;
    123123}
  • uspace/lib/http/src/receive-buffer.c

    r3061bc1 ra35b458  
    4848        rb->receive = receive;
    4949        rb->client_data = client_data;
    50        
     50
    5151        rb->in = 0;
    5252        rb->out = 0;
    5353        rb->size = buffer_size;
    54        
     54
    5555        list_initialize(&rb->marks);
    56        
     56
    5757        rb->buffer = malloc(buffer_size);
    5858        if (rb->buffer == NULL)
     
    7373        if (rc != EOK)
    7474                return rc;
    75        
     75
    7676        memcpy(rb->buffer, buf, size);
    7777        rb->in = size;
     
    111111        if (a->offset > b->offset)
    112112                return EINVAL;
    113        
     113
    114114        size_t size = b->offset - a->offset;
    115115        void *buf = malloc(size);
    116116        if (buf == NULL)
    117117                return ENOMEM;
    118        
     118
    119119        memcpy(buf, rb->buffer + a->offset, size);
    120120        *out_buf = buf;
     
    127127        if (a->offset > b->offset)
    128128                return EINVAL;
    129        
     129
    130130        size_t size = b->offset - a->offset;
    131131        char *buf = malloc(size + 1);
    132132        if (buf == NULL)
    133133                return ENOMEM;
    134        
     134
    135135        memcpy(buf, rb->buffer + a->offset, size);
    136136        buf[size] = 0;
     
    156156                                min_mark = min(min_mark, mark->offset);
    157157                        }
    158                        
     158
    159159                        if (min_mark == 0)
    160160                                return ELIMIT;
    161                        
     161
    162162                        size_t new_in = rb->in - min_mark;
    163163                        memmove(rb->buffer, rb->buffer + min_mark, new_in);
     
    168168                        }
    169169                }
    170                
     170
    171171                size_t nrecv;
    172172                errno_t rc = rb->receive(rb->client_data, rb->buffer + rb->in, free, &nrecv);
    173173                if (rc != EOK)
    174174                        return rc;
    175                
     175
    176176                rb->in = nrecv;
    177177        }
    178        
     178
    179179        *c = rb->buffer[rb->out];
    180180        if (consume)
     
    194194                return EOK;
    195195        }
    196        
     196
    197197        return rb->receive(rb->client_data, buf, buf_size, nrecv);
    198198}
     
    248248                if (rc != EOK)
    249249                        return rc;
    250                
     250
    251251                if (!class(c))
    252252                        break;
    253                
     253
    254254                rc = recv_char(rb, &c, true);
    255255                if (rc != EOK)
    256256                        return rc;
    257257        }
    258        
     258
    259259        return EOK;
    260260}
     
    272272        if (rc != EOK)
    273273                return rc;
    274        
     274
    275275        if (c != '\r' && c != '\n') {
    276276                *nrecv = 0;
    277277                return EOK;
    278278        }
    279        
     279
    280280        rc = recv_char(rb, &c, true);
    281281        if (rc != EOK)
    282282                return rc;
    283        
     283
    284284        size_t nr;
    285285        rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nr);
    286286        if (rc != EOK)
    287287                return rc;
    288        
     288
    289289        *nrecv = 1 + nr;
    290290        return EOK;
     
    296296        size_t written = 0;
    297297        size_t nr;
    298        
     298
    299299        while (written < size) {
    300300                char c = 0;
     
    321321                line[written++] = c;
    322322        }
    323        
     323
    324324        return ELIMIT;
    325325}
  • uspace/lib/http/src/request.c

    r3061bc1 ra35b458  
    5252        if (req == NULL)
    5353                return NULL;
    54        
     54
    5555        req->method = str_dup(method);
    5656        if (req->method == NULL) {
     
    5858                return NULL;
    5959        }
    60        
     60
    6161        req->path = str_dup(path);
    6262        if (req->path == NULL) {
     
    6565                return NULL;
    6666        }
    67        
     67
    6868        http_headers_init(&req->headers);
    69        
     69
    7070        return req;
    7171}
     
    9898                return EINVAL;
    9999        size_t size = meth_size;
    100        
     100
    101101        http_headers_foreach(req->headers, header) {
    102102                ssize_t header_size = http_header_encode(header, NULL, 0);
     
    106106        }
    107107        size += str_length(HTTP_REQUEST_LINE);
    108        
     108
    109109        char *buf = malloc(size);
    110110        if (buf == NULL)
    111111                return ENOMEM;
    112        
     112
    113113        char *pos = buf;
    114114        size_t pos_size = size;
     
    120120        pos += written;
    121121        pos_size -= written;
    122        
     122
    123123        http_headers_foreach(req->headers, header) {
    124124                written = http_header_encode(header, pos, pos_size);
     
    130130                pos_size -= written;
    131131        }
    132        
     132
    133133        size_t rlsize = str_size(HTTP_REQUEST_LINE);
    134134        memcpy(pos, HTTP_REQUEST_LINE, rlsize);
    135135        pos_size -= rlsize;
    136136        assert(pos_size == 0);
    137        
     137
    138138        *out_buf = buf;
    139139        *out_buf_size = size;
     
    145145        char *buf = NULL;
    146146        size_t buf_size = 0;
    147        
     147
    148148        errno_t rc = http_request_format(req, &buf, &buf_size);
    149149        if (rc != EOK)
    150150                return rc;
    151        
     151
    152152        rc = tcp_conn_send(http->conn, buf, buf_size);
    153153        free(buf);
    154        
     154
    155155        return rc;
    156156}
  • uspace/lib/http/src/response.c

    r3061bc1 ra35b458  
    5151        receive_buffer_mark_t start;
    5252        receive_buffer_mark_t end;
    53        
     53
    5454        recv_mark(rb, &start);
    5555        errno_t rc = recv_while(rb, is_digit);
     
    5959        }
    6060        recv_mark(rb, &end);
    61        
     61
    6262        rc = recv_cut_str(rb, &start, &end, str);
    6363        recv_unmark(rb, &start);
     
    7070        char *str = NULL;
    7171        errno_t rc = receive_number(rb, &str);
    72        
    73         if (rc != EOK)
    74                 return rc;
    75        
     72
     73        if (rc != EOK)
     74                return rc;
     75
    7676        rc = str_uint8_t(str, NULL, 10, true, out_value);
    7777        free(str);
    78        
     78
    7979        return rc;
    8080}
     
    8484        char *str = NULL;
    8585        errno_t rc = receive_number(rb, &str);
    86        
    87         if (rc != EOK)
    88                 return rc;
    89        
     86
     87        if (rc != EOK)
     88                return rc;
     89
    9090        rc = str_uint16_t(str, NULL, 10, true, out_value);
    9191        free(str);
    92        
     92
    9393        return rc;
    9494}
     
    116116        uint16_t status;
    117117        char *message = NULL;
    118        
     118
    119119        errno_t rc = expect(rb, "HTTP/");
    120120        if (rc != EOK)
    121121                return rc;
    122        
     122
    123123        rc = receive_uint8_t(rb, &version.major);
    124124        if (rc != EOK)
    125125                return rc;
    126        
     126
    127127        rc = expect(rb, ".");
    128128        if (rc != EOK)
    129129                return rc;
    130        
     130
    131131        rc = receive_uint8_t(rb, &version.minor);
    132132        if (rc != EOK)
    133133                return rc;
    134        
     134
    135135        rc = expect(rb, " ");
    136136        if (rc != EOK)
    137137                return rc;
    138        
     138
    139139        rc = receive_uint16_t(rb, &status);
    140140        if (rc != EOK)
    141141                return rc;
    142        
     142
    143143        rc = expect(rb, " ");
    144144        if (rc != EOK)
    145145                return rc;
    146        
     146
    147147        receive_buffer_mark_t msg_start;
    148148        recv_mark(rb, &msg_start);
    149        
     149
    150150        rc = recv_while(rb, is_not_newline);
    151151        if (rc != EOK) {
     
    153153                return rc;
    154154        }
    155        
     155
    156156        receive_buffer_mark_t msg_end;
    157157        recv_mark(rb, &msg_end);
    158        
     158
    159159        if (out_message) {
    160160                rc = recv_cut_str(rb, &msg_start, &msg_end, &message);
     
    165165                }
    166166        }
    167        
     167
    168168        recv_unmark(rb, &msg_start);
    169169        recv_unmark(rb, &msg_end);
    170        
     170
    171171        size_t nrecv;
    172172        rc = recv_eol(rb, &nrecv);
     
    177177                return rc;
    178178        }
    179        
     179
    180180        if (out_version)
    181181                *out_version = version;
     
    195195        memset(resp, 0, sizeof(http_response_t));
    196196        http_headers_init(&resp->headers);
    197        
     197
    198198        errno_t rc = http_receive_status(rb, &resp->version, &resp->status,
    199199            &resp->message);
    200200        if (rc != EOK)
    201201                goto error;
    202        
     202
    203203        rc = http_headers_receive(rb, &resp->headers, max_headers_size,
    204204            max_headers_count);
    205205        if (rc != EOK)
    206206                goto error;
    207        
     207
    208208        size_t nrecv;
    209209        rc = recv_eol(rb, &nrecv);
     
    212212        if (rc != EOK)
    213213                goto error;
    214        
     214
    215215        *out_response = resp;
    216        
     216
    217217        return EOK;
    218218error:
Note: See TracChangeset for help on using the changeset viewer.