Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/download/main.c

    r5a6cc679 ra35b458  
    8181                goto error;
    8282        }
    83        
     83
    8484        i = 1;
    85        
     85
    8686        if (str_cmp(argv[i], "-o") == 0) {
    8787                ++i;
     
    9191                        goto error;
    9292                }
    93                
     93
    9494                ofname = argv[i++];
    9595                ofile = fopen(ofname, "wb");
     
    100100                }
    101101        }
    102        
     102
    103103        if (argc != i + 1) {
    104104                syntax_print();
     
    106106                goto error;
    107107        }
    108        
     108
    109109        uri = uri_parse(argv[i]);
    110110        if (uri == NULL) {
     
    113113                goto error;
    114114        }
    115        
     115
    116116        if (!uri_validate(uri)) {
    117117                fprintf(stderr, "The URI is invalid\n");
     
    119119                goto error;
    120120        }
    121        
     121
    122122        /* TODO uri_normalize(uri) */
    123        
     123
    124124        if (str_cmp(uri->scheme, "http") != 0) {
    125125                fprintf(stderr, "Only http scheme is supported at the moment\n");
     
    127127                goto error;
    128128        }
    129        
     129
    130130        if (uri->host == NULL) {
    131131                fprintf(stderr, "host not set\n");
     
    133133                goto error;
    134134        }
    135        
     135
    136136        uint16_t port = 80;
    137137        if (uri->port != NULL) {
     
    143143                }
    144144        }
    145        
     145
    146146        const char *path = uri->path;
    147147        if (path == NULL || *path == 0)
     
    163163                }
    164164        }
    165        
     165
    166166        http_request_t *req = http_request_create("GET", server_path);
    167167        free(server_path);
     
    171171                goto error;
    172172        }
    173        
     173
    174174        rc = http_headers_append(&req->headers, "Host", uri->host);
    175175        if (rc != EOK) {
     
    177177                goto error;
    178178        }
    179        
     179
    180180        rc = http_headers_append(&req->headers, "User-Agent", USER_AGENT);
    181181        if (rc != EOK) {
     
    183183                goto error;
    184184        }
    185        
     185
    186186        http = http_create(uri->host, port);
    187187        if (http == NULL) {
     
    190190                goto error;
    191191        }
    192        
     192
    193193        rc = http_connect(http);
    194194        if (rc != EOK) {
     
    197197                goto error;
    198198        }
    199        
     199
    200200        rc = http_send_request(http, req);
    201201        if (rc != EOK) {
     
    204204                goto error;
    205205        }
    206        
     206
    207207        http_response_t *response = NULL;
    208208        rc = http_receive_response(&http->recv_buffer, &response, 16 * 1024,
     
    213213                goto error;
    214214        }
    215        
     215
    216216        if (response->status != 200) {
    217217                fprintf(stderr, "Server returned status %d %s\n", response->status,
     
    224224                        goto error;
    225225                }
    226                
     226
    227227                size_t body_size;
    228228                while ((rc = recv_buffer(&http->recv_buffer, buf, buf_size, &body_size)) == EOK && body_size > 0) {
    229229                        fwrite(buf, 1, body_size, ofile != NULL ? ofile : stdout);
    230230                }
    231                
     231
    232232                if (rc != EOK) {
    233233                        fprintf(stderr, "Failed receiving body: %s", str_error(rc));
    234234                }
    235235        }
    236        
     236
    237237        free(buf);
    238238        http_destroy(http);
Note: See TracChangeset for help on using the changeset viewer.