Changeset 3089


Ignore:
Timestamp:
Feb 5, 2010 4:03:29 PM (10 years ago)
Author:
ming
Message:

Misc (#1018):

  • httpdemo: make the 2nd parameter (output filename) optional (result will be printed to stdout if output file is not provided.
  • remove trailing "\n" from PJ_LOG.
  • change response.status_code from pj_str_t to pj_uint16_t.
  • remove PJ_EPENDING status checking from on_complete.
Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/include/pjlib-util/http_client.h

    r3087 r3089  
    134134{ 
    135135    pj_str_t        version;        /**< HTTP version of the server */ 
    136     pj_str_t        status_code;    /**< Status code of the request */ 
     136    pj_uint16_t     status_code;    /**< Status code of the request */ 
    137137    pj_str_t        reason;         /**< Reason phrase */ 
    138138    pj_http_headers headers;        /**< Response headers */ 
  • pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c

    r3087 r3089  
    134134    PJ_UNUSED_ARG(data); 
    135135 
    136     PJ_LOG(5, (THIS_FILE, "\nData received: %d bytes\n", size)); 
     136    PJ_LOG(5, (THIS_FILE, "\nData received: %d bytes", size)); 
    137137    if (size > 0) { 
    138138#ifdef VERBOSE 
     
    161161    *size = sendsz; 
    162162 
    163     PJ_LOG(5, (THIS_FILE, "\nSending data progress: %d out of %d bytes\n",  
     163    PJ_LOG(5, (THIS_FILE, "\nSending data progress: %d out of %d bytes",  
    164164           send_size, total_size)); 
    165165} 
     
    172172 
    173173    if (status == PJ_ECANCELLED) { 
    174         PJ_LOG(5, (THIS_FILE, "Request cancelled\n")); 
     174        PJ_LOG(5, (THIS_FILE, "Request cancelled")); 
    175175        return; 
    176176    } else if (status == PJ_ETIMEDOUT) { 
    177         PJ_LOG(5, (THIS_FILE, "Request timed out!\n")); 
     177        PJ_LOG(5, (THIS_FILE, "Request timed out!")); 
    178178        return; 
    179     } else if (status != PJ_SUCCESS && status != PJ_EPENDING) { 
    180         PJ_LOG(3, (THIS_FILE, "Error %d\n", status)); 
     179    } else if (status != PJ_SUCCESS) { 
     180        PJ_LOG(3, (THIS_FILE, "Error %d", status)); 
    181181        return; 
    182182    } 
    183     PJ_LOG(5, (THIS_FILE, "\nData completed: %d bytes\n", resp->size)); 
     183    PJ_LOG(5, (THIS_FILE, "\nData completed: %d bytes", resp->size)); 
    184184    if (resp->size > 0 && resp->data) { 
    185185#ifdef VERBOSE 
     
    198198 
    199199#ifdef VERBOSE 
    200     printf("%.*s, %.*s, %.*s\n", STR_PREC(resp->version), 
    201            STR_PREC(resp->status_code), STR_PREC(resp->reason)); 
     200    printf("%.*s, %d, %.*s\n", STR_PREC(resp->version), 
     201           resp->status_code, STR_PREC(resp->reason)); 
    202202    for (i = 0; i < resp->headers.count; i++) { 
    203203        printf("%.*s : %.*s\n",  
  • pjproject/trunk/pjlib-util/src/pjlib-util/http_client.c

    r3087 r3089  
    218218 
    219219    hreq->tcp_state.current_send_size += sent; 
    220     TRACE_((THIS_FILE, "\nData sent: %d out of %d bytes\n",  
     220    TRACE_((THIS_FILE, "\nData sent: %d out of %d bytes",  
    221221           hreq->tcp_state.current_send_size, hreq->tcp_state.send_size)); 
    222222    if (hreq->tcp_state.current_send_size == hreq->tcp_state.send_size) { 
     
    280280    pj_http_req *hreq = (pj_http_req*) pj_activesock_get_user_data(asock); 
    281281 
    282     TRACE_((THIS_FILE, "\nData received: %d bytes\n", size)); 
     282    TRACE_((THIS_FILE, "\nData received: %d bytes", size)); 
    283283 
    284284    if (hreq->state == ABORTING) 
     
    472472    void *newdata; 
    473473    pj_scanner scanner; 
     474    pj_str_t s; 
    474475    pj_status_t status; 
    475476 
     
    509510        pj_scan_get_until_ch(&scanner, ' ', &response->version); 
    510511        pj_scan_advance_n(&scanner, 1, PJ_FALSE); 
    511         pj_scan_get_until_ch(&scanner, ' ', &response->status_code); 
     512        pj_scan_get_until_ch(&scanner, ' ', &s); 
     513        response->status_code = (pj_uint16_t)pj_strtoul(&s); 
    512514        pj_scan_advance_n(&scanner, 1, PJ_FALSE); 
    513515        pj_scan_get_until_ch(&scanner, '\n', &response->reason); 
     
    909911        pj_strcat2(&pkt, "\n"); 
    910912        pkt.ptr[pkt.slen] = 0; 
    911         TRACE_((THIS_FILE, "%s\n", pkt.ptr)); 
     913        TRACE_((THIS_FILE, "%s", pkt.ptr)); 
    912914    } else { 
    913915        pkt.ptr = hreq->param.reqdata.data; 
  • pjproject/trunk/pjsip-apps/src/samples/httpdemo.c

    r3087 r3089  
    4444#define THIS_FILE           "http_demo" 
    4545 
     46static void on_response(pj_http_req *http_req, const pj_http_resp *resp) 
     47{ 
     48    PJ_LOG(3,(THIS_FILE, "%.*s %d %.*s", (int)resp->version.slen, resp->version.ptr, 
     49                                           resp->status_code, 
     50                                           (int)resp->reason.slen, resp->reason.ptr)); 
     51} 
     52 
     53static void on_send_data(pj_http_req *http_req, void **data, pj_size_t *size) 
     54{ 
     55 
     56} 
     57 
    4658static void on_data_read(pj_http_req *hreq, void *data, pj_size_t size) 
    4759{ 
     
    5264        fflush(f); 
    5365#ifdef VERBOSE 
    54         PJ_LOG(3, (THIS_FILE, "\nData received: %d bytes\n", size)); 
     66        PJ_LOG(3, (THIS_FILE, "Data received: %d bytes", size)); 
    5567        printf("%.*s\n", (int)size, (char *)data); 
    5668#endif 
     
    6375    PJ_UNUSED_ARG(hreq); 
    6476 
    65     if (status == PJ_ECANCELLED) { 
    66         PJ_LOG(3, (THIS_FILE, "Request cancelled\n")); 
    67         return; 
    68     } else if (status == PJ_ETIMEDOUT) { 
    69         PJ_LOG(3, (THIS_FILE, "Request timed out!\n")); 
    70         return; 
    71     } else if (status != PJ_SUCCESS && status != PJ_EPENDING) { 
    72         PJ_LOG(3, (THIS_FILE, "Error %d\n", status)); 
     77    if (status != PJ_SUCCESS) { 
     78        PJ_PERROR(1, (THIS_FILE, status, "HTTP request completed with error")); 
    7379        return; 
    7480    } 
    75     PJ_LOG(3, (THIS_FILE, "\nData completed: %d bytes\n", resp->size)); 
     81    PJ_LOG(3, (THIS_FILE, "Data completed: %d bytes", resp->size)); 
    7682    if (resp->size > 0 && resp->data) { 
    7783#ifdef VERBOSE 
     
    9096    hcb.on_complete = &on_complete; 
    9197    hcb.on_data_read = &on_data_read; 
     98    hcb.on_send_data = &on_send_data; 
     99    hcb.on_response = &on_response; 
    92100 
    93101    /* Create pool, timer, and ioqueue */ 
     
    128136    pj_status_t status; 
    129137 
    130     if (argc != 3) { 
    131         puts("Usage: httpdemo URL filename"); 
     138    if (argc < 2 || argc > 3) { 
     139        puts("Usage: httpdemo URL [output-filename]"); 
    132140        return 1; 
    133141    } 
    134142 
    135     pj_log_set_level(3); 
     143    pj_log_set_level(5); 
    136144 
    137145    pj_init(); 
     
    140148    pjlib_util_init(); 
    141149 
    142     f = fopen(argv[2], "wb"); 
     150    if (argc > 2) 
     151        f = fopen(argv[2], "wb"); 
     152    else 
     153        f = stdout; 
     154 
    143155    status = getURL(argv[1]); 
    144156    if (status != PJ_SUCCESS) { 
    145157        PJ_PERROR(1, (THIS_FILE, status, "Error")); 
    146158    } 
    147     fclose(f); 
    148159 
     160    if (f != stdout) 
     161        fclose(f); 
     162 
     163    pj_caching_pool_destroy(&cp); 
    149164    pj_shutdown(); 
    150165    return 0; 
Note: See TracChangeset for help on using the changeset viewer.