Changeset 3841 for pjproject/trunk/pjlib-util/src/pjlib-util/http_client.c
- Timestamp:
- Oct 24, 2011 9:28:13 AM (13 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk
- Property svn:mergeinfo changed
-
pjproject/trunk/pjlib-util/src/pjlib-util/http_client.c
r3553 r3841 27 27 #include <pj/string.h> 28 28 #include <pj/timer.h> 29 #include <pj/rand.h> 29 30 #include <pjlib-util/base64.h> 30 31 #include <pjlib-util/errno.h> … … 33 34 #include <pjlib-util/string.h> 34 35 36 #define THIS_FILE "http_client.c" 37 35 38 #if 0 36 39 /* Enable some tracing */ 37 #define THIS_FILE "http_client.c"38 40 #define TRACE_(arg) PJ_LOG(3,arg) 39 41 #else … … 765 767 param->timeout.msec = PJ_HTTP_DEFAULT_TIMEOUT; 766 768 pj_time_val_normalize(¶m->timeout); 769 param->max_retries = 3; 767 770 } 768 771 … … 1005 1008 } 1006 1009 1007 PJ_DEF(pj_status_t) pj_http_req_start(pj_http_req *http_req) 1010 static pj_status_t start_http_req(pj_http_req *http_req, 1011 pj_bool_t notify_on_fail) 1008 1012 { 1009 1013 pj_sock_t sock = PJ_INVALID_SOCKET; 1010 1014 pj_status_t status; 1011 1015 pj_activesock_cb asock_cb; 1016 int retry = 0; 1012 1017 1013 1018 PJ_ASSERT_RETURN(http_req, PJ_EINVAL); … … 1032 1037 http_req->addr.ipv4.sin_addr.s_addr==PJ_INADDR_NONE)) 1033 1038 { 1034 return status; // cannot resolve host name1039 goto on_return; 1035 1040 } 1036 1041 http_req->resolved = PJ_TRUE; … … 1046 1051 asock_cb.on_data_sent = &http_on_data_sent; 1047 1052 asock_cb.on_connect_complete = &http_on_connect; 1053 1054 do 1055 { 1056 pj_sockaddr_in bound_addr; 1057 pj_uint16_t port = 0; 1058 1059 /* If we are using port restriction. 1060 * Get a random port within the range 1061 */ 1062 if (http_req->param.source_port_range_start != 0) { 1063 port = (pj_uint16_t) 1064 (http_req->param.source_port_range_start + 1065 (pj_rand() % http_req->param.source_port_range_size)); 1066 } 1067 1068 pj_sockaddr_in_init(&bound_addr, NULL, port); 1069 status = pj_sock_bind(sock, &bound_addr, sizeof(bound_addr)); 1070 1071 } while (status != PJ_SUCCESS && (retry++ < http_req->param.max_retries)); 1072 1073 if (status != PJ_SUCCESS) { 1074 PJ_PERROR(1,(THIS_FILE, status, 1075 "Unable to bind to the requested port")); 1076 pj_sock_close(sock); 1077 goto on_return; 1078 } 1048 1079 1049 1080 // TODO: should we set whole data to 0 by default? … … 1053 1084 &asock_cb, http_req, &http_req->asock); 1054 1085 if (status != PJ_SUCCESS) { 1055 if (sock != PJ_INVALID_SOCKET) 1056 pj_sock_close(sock); 1086 pj_sock_close(sock); 1057 1087 goto on_return; // error creating activesock 1058 1088 } … … 1075 1105 if (status == PJ_SUCCESS) { 1076 1106 http_req->state = SENDING_REQUEST; 1077 return http_req_start_sending(http_req); 1107 status = http_req_start_sending(http_req); 1108 if (status != PJ_SUCCESS) 1109 goto on_return; 1078 1110 } else if (status != PJ_EPENDING) { 1079 1111 goto on_return; // error connecting … … 1083 1115 1084 1116 on_return: 1085 http_req_end_request(http_req); 1117 http_req->error = status; 1118 if (notify_on_fail) 1119 pj_http_req_cancel(http_req, PJ_TRUE); 1120 else 1121 http_req_end_request(http_req); 1122 1086 1123 return status; 1124 } 1125 1126 /* Starts an asynchronous HTTP request to the URL specified. */ 1127 PJ_DEF(pj_status_t) pj_http_req_start(pj_http_req *http_req) 1128 { 1129 return start_http_req(http_req, PJ_FALSE); 1087 1130 } 1088 1131 … … 1346 1389 const pj_str_t STR_MD5 = { "MD5", 3 }; 1347 1390 const pj_str_t qop = pj_str("auth"); 1348 const pj_str_t nc = pj_str(" 1");1391 const pj_str_t nc = pj_str("00000001"); 1349 1392 const pj_str_t cnonce = pj_str("b39971"); 1350 1393 … … 1434 1477 http_req_end_request(hreq); 1435 1478 1436 status = pj_http_req_start(hreq);1479 status = start_http_req(hreq, PJ_TRUE); 1437 1480 if (status != PJ_SUCCESS) 1438 1481 goto on_error;
Note: See TracChangeset
for help on using the changeset viewer.