From 0177c5f876e8b0d15a33a1c77bf704aede036ad3 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 5 Nov 2013 22:00:19 +0100 Subject: [PATCH] fix compilation errors due to signature change in linphone_auth_info_new() fix failed tests in case of failed authentication. --- console/commands.c | 4 +--- console/linphonec.c | 2 +- coreapi/authentication.c | 17 ++++++++++++----- coreapi/bellesip_sal/sal_impl.c | 13 +++++++------ coreapi/bellesip_sal/sal_op_impl.c | 6 ++---- coreapi/bellesip_sal/sal_op_registration.c | 2 ++ coreapi/help/buddy_status.c | 2 +- coreapi/help/notify.c | 2 +- coreapi/help/registration.c | 2 +- coreapi/proxy.c | 4 ++-- gtk/main.c | 3 +-- gtk/setupwizard.c | 2 +- include/sal/sal.h | 2 +- tester/liblinphone_tester.c | 2 +- tester/register_tester.c | 10 +++++----- 15 files changed, 39 insertions(+), 34 deletions(-) diff --git a/console/commands.c b/console/commands.c index 540b0e636..c4e70ba02 100644 --- a/console/commands.c +++ b/console/commands.c @@ -1930,9 +1930,7 @@ static int lpc_cmd_register(LinphoneCore *lc, char *args){ LinphoneAddress *from; LinphoneAuthInfo *info; if ((from=linphone_address_new(identity))!=NULL){ - char realm[128]; - snprintf(realm,sizeof(realm)-1,"\"%s\"",linphone_address_get_domain(from)); - info=linphone_auth_info_new(linphone_address_get_username(from),NULL,passwd,NULL,NULL); + info=linphone_auth_info_new(NULL,NULL,passwd,NULL,NULL,linphone_address_get_username(from)); linphone_core_add_auth_info(lc,info); linphone_address_destroy(from); linphone_auth_info_destroy(info); diff --git a/console/linphonec.c b/console/linphonec.c index 1677760dd..a453e374b 100644 --- a/console/linphonec.c +++ b/console/linphonec.c @@ -271,7 +271,7 @@ linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm, const char *usern return; } - pending_auth=linphone_auth_info_new(username,NULL,NULL,NULL,realm); + pending_auth=linphone_auth_info_new(username,NULL,NULL,NULL,realm,domain); auth_stack.elem[auth_stack.nitems++]=pending_auth; } } diff --git a/coreapi/authentication.c b/coreapi/authentication.c index 7690cf28c..bd7849832 100644 --- a/coreapi/authentication.c +++ b/coreapi/authentication.c @@ -33,9 +33,17 @@ /** * Create a LinphoneAuthInfo object with supplied information. - * * The object can be created empty, that is with all arguments set to NULL. - * Username, userid, password and realm can be set later using specific methods. + * Username, userid, password, realm and domain can be set later using specific methods. + * At the end, username and passwd (or ha1) are required. + * @param username the username that needs to be authenticated + * @param userid the userid used for authenticating (use NULL if you don't know what it is) + * @param passwd the password in clear text + * @param ha1 the ha1-encrypted password if password is not given in clear text. + * @param realm the authentication domain (which can be larger than the sip domain. Unfortunately many SIP servers don't use this parameter. + * @param domain the SIP domain for which this authentication information is valid, if it has to be restricted for a single SIP domain. + * @return a #LinphoneAuthInfo. linphone_auth_info_destroy() must be used to destroy it when no longer needed. The LinphoneCore makes a copy of LinphoneAuthInfo + * passed through linphone_core_add_auth_info(). **/ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){ LinphoneAuthInfo *obj=ms_new0(LinphoneAuthInfo,1); @@ -344,11 +352,10 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info) lc->auth_info=ms_list_append(lc->auth_info,linphone_auth_info_clone(info)); /* retry pending authentication operations */ for(l=elem=sal_get_pending_auths(lc->sal);elem!=NULL;elem=elem->next){ - const char *username,*realm; SalOp *op=(SalOp*)elem->data; LinphoneAuthInfo *ai; - sal_op_get_auth_requested(op,&realm,&username); - ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username,info->domain); + const SalAuthInfo *req_sai=sal_op_get_auth_requested(op); + ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,req_sai->realm,req_sai->username,req_sai->domain); if (ai){ SalAuthInfo sai; MSList* proxy; diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index d43bc4878..b3a7cfc78 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -284,6 +284,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event); belle_sip_response_t* response = belle_sip_response_event_get_response(event); int response_code = belle_sip_response_get_status_code(response); + if (!client_transaction) { ms_warning("Discarding stateless response [%i]",response_code); return; @@ -305,15 +306,12 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even sal_op_assign_recv_headers(op,(belle_sip_message_t*)response); if (op->callbacks.process_response_event) { - /*handle authorization*/ switch (response_code) { - case 200: { + case 200: break; - } case 401: - case 407:{ - + case 407: /*belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*//*remove op from trans*/ if (op->state == SalOpStateTerminating && strcmp("BYE",belle_sip_request_get_method(request))!=0) { /*only bye are completed*/ @@ -327,7 +325,10 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even sal_process_authentication(op); return; } - } + break; + case 403: + if (op->auth_info) op->base.root->callbacks.auth_failure(op,op->auth_info); + break; } op->callbacks.process_response_event(op,event); } else { diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index f22530892..30bede48a 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -81,10 +81,8 @@ void sal_op_cancel_authentication(SalOp *h){ return ; } -int sal_op_get_auth_requested(SalOp *op, const char **realm, const char **username){ - *realm=op->auth_info?op->auth_info->realm:NULL; - *username=op->auth_info?op->auth_info->username:NULL; - return 0; +SalAuthInfo * sal_op_get_auth_requested(SalOp *op){ + return op->auth_info; } belle_sip_header_contact_t* sal_op_create_contact(SalOp *op){ diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index a611af029..c02546019 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -63,6 +63,8 @@ static void register_refresher_listener (belle_sip_refresher_t* refresher if (op->auth_info) { /*add pending auth*/ sal_add_pending_auth(op->base.root,op); + if (status_code==403) + op->base.root->callbacks.auth_failure(op,op->auth_info); } } } diff --git a/coreapi/help/buddy_status.c b/coreapi/help/buddy_status.c index 64f818683..40db6458e 100644 --- a/coreapi/help/buddy_status.c +++ b/coreapi/help/buddy_status.c @@ -129,7 +129,7 @@ int main(int argc, char *argv[]){ } LinphoneAuthInfo *info; if (password!=NULL){ - info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL); /*create authentication structure from identity*/ + info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } diff --git a/coreapi/help/notify.c b/coreapi/help/notify.c index 0055346ee..58775b044 100644 --- a/coreapi/help/notify.c +++ b/coreapi/help/notify.c @@ -129,7 +129,7 @@ int main(int argc, char *argv[]){ } LinphoneAuthInfo *info; if (password!=NULL){ - info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL); /*create authentication structure from identity*/ + info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } diff --git a/coreapi/help/registration.c b/coreapi/help/registration.c index 6ed93e70d..70ab4f4ca 100644 --- a/coreapi/help/registration.c +++ b/coreapi/help/registration.c @@ -102,7 +102,7 @@ int main(int argc, char *argv[]){ } LinphoneAuthInfo *info; if (password!=NULL){ - info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL); /*create authentication structure from identity*/ + info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } diff --git a/coreapi/proxy.c b/coreapi/proxy.c index dd34e49fe..a353d862e 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -963,9 +963,9 @@ void linphone_core_remove_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cf ms_error("linphone_core_remove_proxy_config: LinphoneProxyConfig %p is not known by LinphoneCore (programming error?)",cfg); return; } - lc->sip_conf.proxies=ms_list_remove(lc->sip_conf.proxies,(void *)cfg); + lc->sip_conf.proxies=ms_list_remove(lc->sip_conf.proxies,cfg); /* add to the list of destroyed proxies, so that the possible unREGISTER request can succeed authentication */ - lc->sip_conf.deleted_proxies=ms_list_append(lc->sip_conf.deleted_proxies,(void *)cfg); + lc->sip_conf.deleted_proxies=ms_list_append(lc->sip_conf.deleted_proxies,cfg); cfg->deletion_date=ms_time(NULL); if (cfg->state==LinphoneRegistrationOk){ /* this will unREGISTER */ diff --git a/gtk/main.c b/gtk/main.c index fbe8dd698..6aabf98c5 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1039,8 +1039,7 @@ static void linphone_gtk_auth_info_requested(LinphoneCore *lc, const char *realm gtk_label_set_markup(GTK_LABEL(label),msg); g_free(msg); gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(w,"userid_entry")),username); - info=linphone_auth_info_new(username, NULL, NULL, NULL,realm); - linphone_auth_info_set_domain(info,domain); + info=linphone_auth_info_new(username, NULL, NULL, NULL,realm,domain); g_object_set_data(G_OBJECT(w),"auth_info",info); g_object_weak_ref(G_OBJECT(w),(GWeakNotify)linphone_auth_info_destroy,info); gtk_widget_show(w); diff --git a/gtk/setupwizard.c b/gtk/setupwizard.c index 6b596dcc3..afb543a85 100644 --- a/gtk/setupwizard.c +++ b/gtk/setupwizard.c @@ -430,7 +430,7 @@ static void linphone_gtk_assistant_prepare(GtkWidget *assistant, GtkWidget *page } gchar domain[128]; g_snprintf(domain, sizeof(domain), "\"%s\"", creator->domain + 4); - LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, domain); + LinphoneAuthInfo *info=linphone_auth_info_new(username, username, creator->password, NULL, NULL, domain); linphone_core_add_auth_info(linphone_gtk_get_core(),info); g_free(username); diff --git a/include/sal/sal.h b/include/sal/sal.h index 51bb2dcac..98c89d8c2 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -481,7 +481,7 @@ void sal_op_release(SalOp *h); void sal_op_authenticate(SalOp *h, const SalAuthInfo *info); void sal_op_cancel_authentication(SalOp *h); void sal_op_set_user_pointer(SalOp *h, void *up); -int sal_op_get_auth_requested(SalOp *h, const char **realm, const char **username); +SalAuthInfo * sal_op_get_auth_requested(SalOp *h); const char *sal_op_get_from(const SalOp *op); const SalAddress *sal_op_get_from_address(const SalOp *op); const char *sal_op_get_to(const SalOp *op); diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 740d02f4a..6be3bd70b 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -78,7 +78,7 @@ void auth_info_requested(LinphoneCore *lc, const char *realm, const char *userna ,realm); counters = get_stats(lc); counters->number_of_auth_info_requested++; - info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ + info=linphone_auth_info_new(test_username,NULL,test_password,NULL,realm,domain); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } diff --git a/tester/register_tester.c b/tester/register_tester.c index 1ee2dc453..adf3197a8 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -104,7 +104,7 @@ static void register_with_refresh_base_3(LinphoneCore* lc if (counters->number_of_auth_info_requested>0 && linphone_proxy_config_get_state(proxy_cfg) == LinphoneRegistrationFailed && late_auth_info) { if (!linphone_core_get_auth_info_list(lc)) { CU_ASSERT_EQUAL(linphone_proxy_config_get_error(proxy_cfg),LinphoneReasonUnauthorized); - info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ + info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } } @@ -148,7 +148,7 @@ static void register_with_refresh_with_send_error() { int retry=0; LinphoneCoreManager* lcm = create_lcm_with_auth(1); stats* counters = &lcm->stat; - LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ + LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain,NULL); /*create authentication structure from identity*/ char route[256]; sprintf(route,"sip:%s",test_route); linphone_core_add_auth_info(lcm->lc,info); /*add authentication info to LinphoneCore*/ @@ -228,7 +228,7 @@ static void simple_tls_register(){ static void simple_authenticated_register(){ stats* counters; LinphoneCoreManager* lcm = create_lcm(); - LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain); /*create authentication structure from identity*/ + LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,test_password,NULL,auth_domain,NULL); /*create authentication structure from identity*/ char route[256]; sprintf(route,"sip:%s",test_route); linphone_core_add_auth_info(lcm->lc,info); /*add authentication info to LinphoneCore*/ @@ -244,7 +244,7 @@ static void ha1_authenticated_register(){ LinphoneAuthInfo *info; char route[256]; sal_auth_compute_ha1(test_username,auth_domain,test_password,ha1); - info=linphone_auth_info_new(test_username,NULL,NULL,ha1,auth_domain); /*create authentication structure from identity*/ + info=linphone_auth_info_new(test_username,NULL,NULL,ha1,auth_domain,NULL); /*create authentication structure from identity*/ sprintf(route,"sip:%s",test_route); linphone_core_add_auth_info(lcm->lc,info); /*add authentication info to LinphoneCore*/ counters = &lcm->stat; @@ -321,7 +321,7 @@ static void authenticated_register_with_wrong_credentials(){ LinphoneCoreManager *mgr; stats* counters; LCSipTransports transport = {5070,5070,0,5071}; - LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,"wrong passwd",NULL,auth_domain); /*create authentication structure from identity*/ + LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,"wrong passwd",NULL,auth_domain,NULL); /*create authentication structure from identity*/ char route[256]; sprintf(route,"sip:%s",test_route);