From e9df76394989085968347992efbeb0fa1cad91a6 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 9 Jan 2013 18:32:13 +0100 Subject: [PATCH] update sal op contact with contact generated by the sip stack for the request --- coreapi/bellesip_sal/sal_impl.c | 44 ++++++++++++++++------ coreapi/bellesip_sal/sal_impl.h | 2 +- coreapi/bellesip_sal/sal_op_impl.c | 7 ++-- coreapi/bellesip_sal/sal_op_registration.c | 7 ++-- coreapi/linphonecore.c | 2 +- coreapi/private.h | 1 + 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 79d7c0fb4..fd063b64f 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -37,6 +37,8 @@ static void sal_add_pending_auth(Sal *sal, SalOp *op){ void sal_process_authentication(SalOp *op, belle_sip_response_t *response) { belle_sip_request_t* request; bool_t is_within_dialog=FALSE; + belle_sip_list_t* auth_list=NULL; + belle_sip_auth_event_t* auth_event; if (op->dialog && belle_sip_dialog_get_state(op->dialog)==BELLE_SIP_DIALOG_CONFIRMED) { request = belle_sip_dialog_create_request_from(op->dialog,(const belle_sip_request_t *)op->request); is_within_dialog=TRUE; @@ -46,7 +48,7 @@ void sal_process_authentication(SalOp *op, belle_sip_response_t *response) { belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_PROXY_AUTHORIZATION); } - if (belle_sip_provider_add_authorization(op->base.root->prov,request,response)) { + if (belle_sip_provider_add_authorization(op->base.root->prov,request,response,&auth_list)) { if (is_within_dialog) { sal_op_resend_request(op,request); } else { @@ -57,6 +59,12 @@ void sal_process_authentication(SalOp *op, belle_sip_response_t *response) { if (is_within_dialog) { belle_sip_object_unref(request); } + if (op->auth_info) sal_auth_info_delete(op->auth_info); + auth_event=(belle_sip_auth_event_t*)(auth_list->data); + op->auth_info=sal_auth_info_new(); + op->auth_info->realm = ms_strdup(belle_sip_auth_event_get_realm(auth_event)) ; + op->auth_info->username = ms_strdup(belle_sip_auth_event_get_username(auth_event)) ; + belle_sip_list_free_with_data(auth_list,(void (*)(void*))belle_sip_auth_event_destroy); sal_add_pending_auth(op->base.root,op); } @@ -172,6 +180,8 @@ 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); SalOp* op = (SalOp*)belle_sip_transaction_get_application_data(BELLE_SIP_TRANSACTION(client_transaction)); belle_sip_response_t* response = belle_sip_response_event_get_response(event); + belle_sip_request_t* request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(client_transaction)); + belle_sip_header_contact_t* original_contact; belle_sip_header_address_t* contact_address=NULL; belle_sip_header_via_t* via_header; belle_sip_uri_t* contact_uri; @@ -198,19 +208,29 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even received = belle_sip_header_via_get_received(via_header); rport = belle_sip_header_via_get_rport(via_header); if (!sal_op_get_contact(op)) { - /*hmm update contact from via*/ - contact_address=belle_sip_header_address_new(); - contact_uri=belle_sip_uri_create(NULL,belle_sip_header_via_get_host(via_header)); - belle_sip_header_address_set_uri(contact_address,contact_uri); + /*check if contqct set in reauest*/ - if (strcasecmp(belle_sip_header_via_get_transport(via_header),"UDP")!=0) { - belle_sip_uri_set_transport_param(contact_uri,belle_sip_header_via_get_transport_lowercase(via_header)); + if ((original_contact=belle_sip_message_get_header_by_type(request,belle_sip_header_contact_t))) { + /*no contact set yet, try to see if sip tack has an updated one*/ + contact_address=belle_sip_header_address_create(NULL,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(original_contact))); + sal_op_set_contact_address(op,(const SalAddress *)contact_address); + belle_sip_object_unref(contact_address); + } else { + + /*hmm update contact from via, maybe useless, some op may not need any contact at all*/ + contact_address=belle_sip_header_address_new(); + contact_uri=belle_sip_uri_create(NULL,belle_sip_header_via_get_host(via_header)); + belle_sip_header_address_set_uri(contact_address,contact_uri); + + if (strcasecmp(belle_sip_header_via_get_transport(via_header),"UDP")!=0) { + belle_sip_uri_set_transport_param(contact_uri,belle_sip_header_via_get_transport_lowercase(via_header)); + } + if (belle_sip_header_via_get_listening_port(via_header) + != belle_sip_listening_point_get_well_known_port(belle_sip_header_via_get_transport(via_header))) { + belle_sip_uri_set_port(contact_uri,belle_sip_header_via_get_listening_port(via_header) ); + } + contact_updated=TRUE; } - if (belle_sip_header_via_get_listening_port(via_header) - != belle_sip_listening_point_get_well_known_port(belle_sip_header_via_get_transport(via_header))) { - belle_sip_uri_set_port(contact_uri,belle_sip_header_via_get_listening_port(via_header) ); - } - contact_updated=TRUE; } if (received!=NULL || rport>0) { diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index d98e85b42..8619bf856 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -54,7 +54,7 @@ struct SalOp{ belle_sip_response_t* response; belle_sip_server_transaction_t* pending_server_trans; belle_sip_client_transaction_t* pending_inv_client_trans; - SalAuthInfo auth_info; + SalAuthInfo* auth_info; unsigned long int registration_refresh_timer; bool_t sdp_offering; belle_sip_dialog_t* dialog; diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index 5d1946cc7..8ed860a05 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -31,6 +31,7 @@ void sal_op_release(SalOp *op){ if (op->registration_refresh_timer>0) { belle_sip_main_loop_cancel_source(belle_sip_stack_get_main_loop(op->base.root->stack),op->registration_refresh_timer); } + if (op->auth_info) sal_auth_info_delete(op->auth_info); __sal_op_free(op); return ; } @@ -46,8 +47,8 @@ void sal_op_cancel_authentication(SalOp *h){ } int sal_op_get_auth_requested(SalOp *op, const char **realm, const char **username){ - *realm=op->auth_info.realm; - *username=op->auth_info.username; + *realm=op->auth_info?op->auth_info->realm:NULL; + *username=op->auth_info?op->auth_info->username:NULL; return 0; } @@ -130,7 +131,7 @@ int sal_op_send_request(SalOp* op, belle_sip_request_t* request) { if (!belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_AUTHORIZATION) && !belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_PROXY_AUTHORIZATION)) { /*hmm just in case we already have authentication param in cache*/ - belle_sip_provider_add_authorization(op->base.root->prov,request,NULL); + belle_sip_provider_add_authorization(op->base.root->prov,request,NULL,NULL); } return belle_sip_client_transaction_send_request(client_transaction); diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index b11b2f839..8f708f6ad 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -50,9 +50,11 @@ static void register_response_event(void *user_ctx, const belle_sip_response_eve contact_header_list = belle_sip_message_get_headers(BELLE_SIP_MESSAGE(response),BELLE_SIP_CONTACT); if (contact_header_list) { - contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list,(belle_sip_compare_func)belle_sip_header_contact_equals, (const void*)original_contact); + contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list,(belle_sip_compare_func)belle_sip_header_contact_not_equals, (const void*)original_contact); if (!contact_header_list) { - contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list,(belle_sip_compare_func)belle_sip_header_contact_equals, (const void*)sal_op_get_contact_address(op)); + /*reset header list*/ + contact_header_list = belle_sip_message_get_headers(BELLE_SIP_MESSAGE(response),BELLE_SIP_CONTACT); + contact_header_list = belle_sip_list_find_custom((belle_sip_list_t*)contact_header_list,(belle_sip_compare_func)belle_sip_header_contact_not_equals, (const void*)sal_op_get_contact_address(op)); } if (!contact_header_list) { tmp_string=belle_sip_object_to_string(BELLE_SIP_OBJECT(original_contact)); @@ -119,7 +121,6 @@ static void send_register_request_with_expires(SalOp* op, belle_sip_request_t* r int sal_register(SalOp *op, const char *proxy, const char *from, int expires){ belle_sip_request_t *req; - sal_op_set_from(op,from); sal_op_set_to(op,from); sal_op_set_route(op,proxy); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 0a76f4b4f..26e0ba572 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -4749,7 +4749,7 @@ void sip_config_uninit(LinphoneCore *lc) ms_list_free(config->proxies); config->proxies=NULL; - linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */ + /*no longuer need to write proxy config if not changedlinphone_proxy_config_write_to_config_file(lc->config,NULL,i);*/ /*mark the end */ ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy); ms_list_free(lc->auth_info); diff --git a/coreapi/private.h b/coreapi/private.h index c171fac88..bc2b65cfb 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -186,6 +186,7 @@ int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *e int linphone_proxy_config_send_publish(LinphoneProxyConfig *cfg, LinphoneOnlineStatus os); void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrationState rstate, const char *message); +void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc); int linphone_online_status_to_eXosip(LinphoneOnlineStatus os); void linphone_friend_close_subscriptions(LinphoneFriend *lf);