Changeset 3089 for pjproject/trunk/pjsip-apps/src/samples/httpdemo.c
- Timestamp:
- Feb 5, 2010 4:03:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/httpdemo.c
r3087 r3089 44 44 #define THIS_FILE "http_demo" 45 45 46 static 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 53 static void on_send_data(pj_http_req *http_req, void **data, pj_size_t *size) 54 { 55 56 } 57 46 58 static void on_data_read(pj_http_req *hreq, void *data, pj_size_t size) 47 59 { … … 52 64 fflush(f); 53 65 #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)); 55 67 printf("%.*s\n", (int)size, (char *)data); 56 68 #endif … … 63 75 PJ_UNUSED_ARG(hreq); 64 76 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")); 73 79 return; 74 80 } 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)); 76 82 if (resp->size > 0 && resp->data) { 77 83 #ifdef VERBOSE … … 90 96 hcb.on_complete = &on_complete; 91 97 hcb.on_data_read = &on_data_read; 98 hcb.on_send_data = &on_send_data; 99 hcb.on_response = &on_response; 92 100 93 101 /* Create pool, timer, and ioqueue */ … … 128 136 pj_status_t status; 129 137 130 if (argc !=3) {131 puts("Usage: httpdemo URL filename");138 if (argc < 2 || argc > 3) { 139 puts("Usage: httpdemo URL [output-filename]"); 132 140 return 1; 133 141 } 134 142 135 pj_log_set_level( 3);143 pj_log_set_level(5); 136 144 137 145 pj_init(); … … 140 148 pjlib_util_init(); 141 149 142 f = fopen(argv[2], "wb"); 150 if (argc > 2) 151 f = fopen(argv[2], "wb"); 152 else 153 f = stdout; 154 143 155 status = getURL(argv[1]); 144 156 if (status != PJ_SUCCESS) { 145 157 PJ_PERROR(1, (THIS_FILE, status, "Error")); 146 158 } 147 fclose(f);148 159 160 if (f != stdout) 161 fclose(f); 162 163 pj_caching_pool_destroy(&cp); 149 164 pj_shutdown(); 150 165 return 0;
Note: See TracChangeset
for help on using the changeset viewer.