http-provider: add belle_http_provider_set_recv_error similar to...

http-provider: add belle_http_provider_set_recv_error similar to belle_sip_provider_set_recv_error for test purposes
parent d81b70f1
......@@ -27,6 +27,13 @@ BELLE_SIP_BEGIN_DECLS
BELLESIP_EXPORT int belle_http_provider_set_tls_verify_policy(belle_http_provider_t *obj, belle_tls_verify_policy_t *verify_ctx);
/**
* Can be used to simulate network recv error, for tests.
* @param obj
* @param recv_error if <=0, will cause channel error to be reported
**/
BELLESIP_EXPORT void belle_http_provider_set_recv_error(belle_http_provider_t *obj, int recv_error);
BELLESIP_EXPORT int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener);
BELLESIP_EXPORT void belle_http_provider_cancel_request(belle_http_provider_t *obj, belle_http_request_t *req);
......
......@@ -400,13 +400,13 @@ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_requ
belle_sip_channel_t *chan;
belle_sip_list_t **channels;
belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri);
if (hop->host == NULL){
belle_sip_error("belle_http_provider_send_request(): no host defined in request uri.");
belle_sip_object_unref(hop);
return -1;
}
channels = belle_http_provider_get_channels(obj,hop->transport);
if (listener) belle_http_request_set_listener(req,listener);
......@@ -481,4 +481,20 @@ int belle_http_provider_set_tls_verify_policy(belle_http_provider_t *obj, belle_
return 0;
}
void belle_http_provider_set_recv_error(belle_http_provider_t *obj, int recv_error) {
belle_sip_list_t *lps;
belle_sip_list_t *channels;
for(lps=obj->tcp_channels;lps!=NULL;lps=lps->next){
for(channels=((belle_sip_listening_point_t*)lps->data)->channels;channels!=NULL;channels=channels->next){
((belle_sip_channel_t*)channels->data)->simulated_recv_return=recv_error;
((belle_sip_source_t*)channels->data)->notify_required=(recv_error<=0);
}
}
for(lps=obj->tls_channels;lps!=NULL;lps=lps->next){
for(channels=((belle_sip_listening_point_t*)lps->data)->channels;channels!=NULL;channels=channels->next){
((belle_sip_channel_t*)channels->data)->simulated_recv_return=recv_error;
((belle_sip_source_t*)channels->data)->notify_required=(recv_error<=0);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment