Changeset a35b458 in mainline for uspace/app/websrv


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/websrv/websrv.c

    r3061bc1 ra35b458  
    137137{
    138138        recv_t *recv;
    139        
     139
    140140        recv = calloc(1, sizeof(recv_t));
    141141        if (recv == NULL)
    142142                return ENOMEM;
    143        
     143
    144144        recv->conn = conn;
    145145        recv->rbuf_out = 0;
    146146        recv->rbuf_in = 0;
    147147        recv->lbuf_used = 0;
    148        
     148
    149149        *rrecv = recv;
    150150        return EOK;
     
    161161        size_t nrecv;
    162162        errno_t rc;
    163        
     163
    164164        if (recv->rbuf_out == recv->rbuf_in) {
    165165                recv->rbuf_out = 0;
    166166                recv->rbuf_in = 0;
    167                
     167
    168168                rc = tcp_conn_recv_wait(recv->conn, recv->rbuf, BUFFER_SIZE, &nrecv);
    169169                if (rc != EOK) {
     
    171171                        return rc;
    172172                }
    173                
     173
    174174                recv->rbuf_in = nrecv;
    175175        }
    176        
     176
    177177        *c = recv->rbuf[recv->rbuf_out++];
    178178        return EOK;
     
    184184        char *bp = recv->lbuf;
    185185        char c = '\0';
    186        
     186
    187187        while (bp < recv->lbuf + BUFFER_SIZE) {
    188188                char prev = c;
    189189                errno_t rc = recv_char(recv, &c);
    190                
     190
    191191                if (rc != EOK)
    192192                        return rc;
    193                
     193
    194194                *bp++ = c;
    195195                if ((prev == '\r') && (c == '\n'))
    196196                        break;
    197197        }
    198        
     198
    199199        recv->lbuf_used = bp - recv->lbuf;
    200200        *bp = '\0';
    201        
     201
    202202        if (bp == recv->lbuf + BUFFER_SIZE)
    203203                return ELIMIT;
    204        
     204
    205205        *rbuf = recv->lbuf;
    206206        return EOK;
     
    211211        if (uri[0] != '/')
    212212                return false;
    213        
     213
    214214        if (uri[1] == '.')
    215215                return false;
    216        
     216
    217217        char *cp = uri + 1;
    218        
     218
    219219        while (*cp != '\0') {
    220220                char c = *cp++;
     
    222222                        return false;
    223223        }
    224        
     224
    225225        return true;
    226226}
     
    229229{
    230230        size_t response_size = str_size(msg);
    231        
     231
    232232        if (verbose)
    233233            fprintf(stderr, "Sending response\n");
    234        
     234
    235235        errno_t rc = tcp_conn_send(conn, (void *) msg, response_size);
    236236        if (rc != EOK) {
     
    238238                return rc;
    239239        }
    240        
     240
    241241        return EOK;
    242242}
     
    249249        size_t nr;
    250250        int fd = -1;
    251        
     251
    252252        fbuf = calloc(BUFFER_SIZE, 1);
    253253        if (fbuf == NULL) {
     
    255255                goto out;
    256256        }
    257        
     257
    258258        if (str_cmp(uri, "/") == 0)
    259259                uri = "/index.html";
    260        
     260
    261261        if (asprintf(&fname, "%s%s", WEB_ROOT, uri) < 0) {
    262262                rc = ENOMEM;
    263263                goto out;
    264264        }
    265        
     265
    266266        rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd);
    267267        if (rc != EOK) {
     
    269269                goto out;
    270270        }
    271        
     271
    272272        free(fname);
    273273        fname = NULL;
    274        
     274
    275275        rc = send_response(conn, msg_ok);
    276276        if (rc != EOK)
    277277                goto out;
    278        
     278
    279279        aoff64_t pos = 0;
    280280        while (true) {
     
    282282                if (rc != EOK)
    283283                        goto out;
    284                
     284
    285285                if (nr == 0)
    286286                        break;
    287                
     287
    288288                rc = tcp_conn_send(conn, fbuf, nr);
    289289                if (rc != EOK) {
     
    292292                }
    293293        }
    294        
     294
    295295        rc = EOK;
    296296out:
     
    311311                return rc;
    312312        }
    313        
     313
    314314        if (verbose)
    315315                fprintf(stderr, "Request: %s", reqline);
    316        
     316
    317317        if (str_lcmp(reqline, "GET ", 4) != 0) {
    318318                rc = send_response(conn, msg_not_implemented);
    319319                return rc;
    320320        }
    321        
     321
    322322        char *uri = reqline + 4;
    323323        char *end_uri = str_chr(uri, ' ');
     
    326326                assert(*end_uri == '\r');
    327327        }
    328        
     328
    329329        *end_uri = '\0';
    330330        if (verbose)
    331331                fprintf(stderr, "Requested URI: %s\n", uri);
    332        
     332
    333333        if (!uri_is_valid(uri)) {
    334334                rc = send_response(conn, msg_bad_request);
    335335                return rc;
    336336        }
    337        
     337
    338338        return uri_get(uri, conn);
    339339}
     
    359359        int value;
    360360        errno_t rc;
    361        
     361
    362362        switch (argv[*index][1]) {
    363363        case 'h':
     
    369369                if (rc != EOK)
    370370                        return rc;
    371                
     371
    372372                port = (uint16_t) value;
    373373                break;
     
    384384                        if (rc != EOK)
    385385                                return rc;
    386                        
     386
    387387                        port = (uint16_t) value;
    388388                } else if (str_cmp(argv[*index] +2, "verbose") == 0) {
     
    397397                return EINVAL;
    398398        }
    399        
     399
    400400        return EOK;
    401401}
     
    405405        errno_t rc;
    406406        recv_t *recv = NULL;
    407        
     407
    408408        if (verbose)
    409409                fprintf(stderr, "New connection, waiting for request\n");
    410        
     410
    411411        rc = recv_create(conn, &recv);
    412412        if (rc != EOK) {
     
    414414                goto error;
    415415        }
    416        
     416
    417417        rc = req_process(conn, recv);
    418418        if (rc != EOK) {
     
    421421                goto error;
    422422        }
    423        
     423
    424424        rc = tcp_conn_send_fin(conn);
    425425        if (rc != EOK) {
     
    434434        if (rc != EOK)
    435435                fprintf(stderr, "Error resetting connection.\n");
    436        
     436
    437437        recv_destroy(recv);
    438438}
     
    444444        tcp_t *tcp;
    445445        errno_t rc;
    446        
     446
    447447        /* Parse command line arguments */
    448448        for (int i = 1; i < argc; i++) {
     
    456456                }
    457457        }
    458        
     458
    459459        printf("%s: HelenOS web server\n", NAME);
    460460
    461461        if (verbose)
    462462                fprintf(stderr, "Creating listener\n");
    463        
     463
    464464        inet_ep_init(&ep);
    465465        ep.port = port;
     
    477477                return 2;
    478478        }
    479        
     479
    480480        fprintf(stderr, "%s: Listening for connections at port %" PRIu16 "\n",
    481481            NAME, port);
     
    483483        task_retval(0);
    484484        async_manager();
    485        
     485
    486486        /* Not reached */
    487487        return 0;
Note: See TracChangeset for help on using the changeset viewer.