Ignore:
Timestamp:
Feb 5, 2010 4:03:29 PM (12 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.