Commit 771877cc authored by Simon Morlat's avatar Simon Morlat

improve lisibility of a code segment and fix possible failure of an http test

parent e8a7273f
......@@ -936,7 +936,7 @@ static void belle_sip_provider_update_or_create_auth_context(belle_sip_provider
int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp,belle_sip_list_t** auth_infos) {
belle_sip_header_call_id_t* call_id;
belle_sip_list_t* auth_context_lst;
belle_sip_list_t* auth_context_iterator;
belle_sip_list_t* authenticate_lst;
belle_sip_list_t* head;
belle_sip_header_www_authenticate_t* authenticate;
......@@ -999,49 +999,49 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
/*put authorization header if passwd found*/
call_id = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(request),belle_sip_header_call_id_t);
from = belle_sip_message_get_header_by_type(request,belle_sip_header_from_t);
if ((head=auth_context_lst = belle_sip_provider_get_auth_context_by_call_id(p,call_id))) {
/*we assume there no existing auth headers*/
for (;auth_context_lst!=NULL;auth_context_lst=auth_context_lst->next) {
/*clear auth info*/
auth_context=(authorization_context_t*)auth_context_lst->data;
auth_event = belle_sip_auth_event_create((belle_sip_object_t*)p,auth_context->realm,from);
/*put data*/
/*call listener*/
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p->listeners,process_auth_requested,auth_event);
if (auth_event->passwd || auth_event->ha1) {
if (!auth_event->userid) {
/*if no userid, username = userid*/
belle_sip_auth_event_set_userid(auth_event,(const char*)auth_event->username);
}
belle_sip_message("Auth info found for [%s] realm [%s]",auth_event->userid,auth_event->realm);
if (auth_context->is_proxy) {
authorization=BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_header_proxy_authorization_new());
} else {
authorization=belle_sip_header_authorization_new();
}
belle_sip_header_authorization_set_scheme(authorization,auth_context->scheme);
belle_sip_header_authorization_set_realm(authorization,auth_context->realm);
belle_sip_header_authorization_set_username(authorization,auth_event->userid);
belle_sip_header_authorization_set_nonce(authorization,auth_context->nonce);
belle_sip_header_authorization_set_qop(authorization,auth_context->qop);
belle_sip_header_authorization_set_opaque(authorization,auth_context->opaque);
belle_sip_header_authorization_set_uri(authorization,(belle_sip_uri_t*)belle_sip_request_get_uri(request));
if (auth_context->qop)
belle_sip_header_authorization_set_nonce_count(authorization,++auth_context->nonce_count);
if (auth_event->ha1) {
ha1=auth_event->ha1;
} else {
belle_sip_auth_helper_compute_ha1(auth_event->userid,auth_context->realm,auth_event->passwd, computed_ha1);
ha1=computed_ha1;
}
if (belle_sip_auth_helper_fill_authorization(authorization
,belle_sip_request_get_method(request)
,ha1)) {
belle_sip_object_unref(authorization);
} else
belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_HEADER(authorization));
result=1;
head=belle_sip_provider_get_auth_context_by_call_id(p,call_id);
/*we assume there no existing auth headers*/
for (auth_context_iterator=head;auth_context_iterator!=NULL;auth_context_iterator=auth_context_iterator->next) {
/*clear auth info*/
auth_context=(authorization_context_t*)auth_context_iterator->data;
auth_event = belle_sip_auth_event_create((belle_sip_object_t*)p,auth_context->realm,from);
/*put data*/
/*call listener*/
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p->listeners,process_auth_requested,auth_event);
if (auth_event->passwd || auth_event->ha1) {
if (!auth_event->userid) {
/*if no userid, username = userid*/
belle_sip_auth_event_set_userid(auth_event,(const char*)auth_event->username);
}
belle_sip_message("Auth info found for [%s] realm [%s]",auth_event->userid,auth_event->realm);
if (auth_context->is_proxy) {
authorization=BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_header_proxy_authorization_new());
} else {
authorization=belle_sip_header_authorization_new();
}
belle_sip_header_authorization_set_scheme(authorization,auth_context->scheme);
belle_sip_header_authorization_set_realm(authorization,auth_context->realm);
belle_sip_header_authorization_set_username(authorization,auth_event->userid);
belle_sip_header_authorization_set_nonce(authorization,auth_context->nonce);
belle_sip_header_authorization_set_qop(authorization,auth_context->qop);
belle_sip_header_authorization_set_opaque(authorization,auth_context->opaque);
belle_sip_header_authorization_set_uri(authorization,(belle_sip_uri_t*)belle_sip_request_get_uri(request));
if (auth_context->qop)
belle_sip_header_authorization_set_nonce_count(authorization,++auth_context->nonce_count);
if (auth_event->ha1) {
ha1=auth_event->ha1;
} else {
belle_sip_auth_helper_compute_ha1(auth_event->userid,auth_context->realm,auth_event->passwd, computed_ha1);
ha1=computed_ha1;
}
if (belle_sip_auth_helper_fill_authorization(authorization
,belle_sip_request_get_method(request)
,ha1)) {
belle_sip_object_unref(authorization);
} else
belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_HEADER(authorization));
result=1;
} else {
belle_sip_message("No auth info found for call id [%s]",belle_sip_header_call_id_get_call_id(call_id));
}
......@@ -1052,12 +1052,8 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
} else {
belle_sip_auth_event_destroy(auth_event);
}
}
belle_sip_list_free(head);
} else {
/*nothing to do*/
}
belle_sip_list_free(head);
return result;
}
......
......@@ -96,9 +96,8 @@ static int http_cleanup(void){
return 0;
}
static void one_get(const char *url,http_counters_t* counters){
static void one_get(const char *url,http_counters_t* counters, int *counter){
belle_http_request_listener_callbacks_t cbs={0};
belle_http_request_listener_t *l;
belle_generic_uri_t *uri;
belle_http_request_t *req;
......@@ -114,14 +113,14 @@ static void one_get(const char *url,http_counters_t* counters){
cbs.process_auth_requested=process_auth_requested;
l=belle_http_request_listener_create_from_callbacks(&cbs,counters);
belle_http_provider_send_request(prov,req,l);
wait_for(stack,&counters->response_count,1,3000);
wait_for(stack,counter,1,3000);
belle_sip_object_unref(l);
}
static void one_http_get(void){
http_counters_t counters={0};
one_get("http://smtp.linphone.org",&counters);
one_get("http://smtp.linphone.org",&counters,&counters.response_count);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
CU_ASSERT_EQUAL(counters.two_hundred,1);
......@@ -129,14 +128,14 @@ static void one_http_get(void){
static void http_get_io_error(void){
http_counters_t counters={0};
one_get("http://blablabla.cul",&counters);
one_get("http://blablabla.cul",&counters,&counters.io_error_count);
CU_ASSERT_TRUE(counters.response_count==0);
CU_ASSERT_EQUAL(counters.io_error_count,1);
}
static void one_https_get(void){
http_counters_t counters={0};
one_get("https://smtp.linphone.org",&counters);
one_get("https://smtp.linphone.org",&counters,&counters.response_count);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
CU_ASSERT_EQUAL(counters.two_hundred,1);
......@@ -144,7 +143,7 @@ static void one_https_get(void){
static void https_get_long_body(void){
http_counters_t counters={0};
one_get("https://www.linphone.org/eng/features/",&counters);
one_get("https://www.linphone.org/eng/features/",&counters, &counters.response_count);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
CU_ASSERT_EQUAL(counters.two_hundred,1);
......@@ -152,7 +151,7 @@ static void https_get_long_body(void){
static void https_digest_get(void){
http_counters_t counters={0};
one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters);
one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters,&counters.response_count);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
CU_ASSERT_EQUAL(counters.three_hundred,1);
......@@ -174,7 +173,7 @@ test_t http_tests[] = {
{ "One https GET", one_https_get },
{ "http request with io error", http_get_io_error },
{ "https GET with long body", https_get_long_body },
{ "https digest GET", https_digest_get }/*, FIXME, nee a server for testing
{ "https digest GET", https_digest_get }/*, FIXME, need a server for testing
{ "https with client certificate", https_client_cert_connection }*/
};
......
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