From: Jehan Monnier Date: Tue, 18 Jan 2011 11:35:37 +0000 (+0100) Subject: add auth info to outgoing bye message X-Git-Url: http://sjero.net/git/?a=commitdiff_plain;h=aac38a59c7707f25c8c5c9ff340fc01f5cae9c0e;p=linphone add auth info to outgoing bye message --- diff --git a/coreapi/sal.c b/coreapi/sal.c index 979969b2..4e09846f 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -267,3 +267,21 @@ void __sal_op_free(SalOp *op){ sal_media_description_unref(b->remote_media); ms_free(op); } +SalAuthInfo* sal_auth_info_new() { + return ms_new0(SalAuthInfo,1); +} +SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info) { + SalAuthInfo* new_auth_info=sal_auth_info_new(); + new_auth_info->username=auth_info->username?ms_strdup(auth_info->username):NULL; + new_auth_info->userid=auth_info->userid?ms_strdup(auth_info->userid):NULL; + new_auth_info->realm=auth_info->realm?ms_strdup(auth_info->realm):NULL; + new_auth_info->password=auth_info->password?ms_strdup(auth_info->password):NULL; + return new_auth_info; +} +void sal_auth_info_delete(const SalAuthInfo* auth_info) { + if (auth_info->username) ms_free(auth_info->username); + if (auth_info->userid) ms_free(auth_info->userid); + if (auth_info->realm) ms_free(auth_info->realm); + if (auth_info->password) ms_free(auth_info->password); + ms_free((void*)auth_info); +} diff --git a/coreapi/sal.h b/coreapi/sal.h index d98d5eb5..4086dd1e 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -238,6 +238,10 @@ typedef struct SalAuthInfo{ char *realm; }SalAuthInfo; +SalAuthInfo* sal_auth_info_new(); +SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info); +void sal_auth_info_delete(const SalAuthInfo* auth_info); + void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs); int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure); int sal_unlisten_ports(Sal *ctx); diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 69a28153..315c566a 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -165,6 +165,7 @@ SalOp * sal_op_new(Sal *sal){ op->referred_by=NULL; op->masquerade_via=FALSE; op->auto_answer_asked=FALSE; + op->auth_info=NULL; return op; } @@ -209,6 +210,9 @@ void sal_op_release(SalOp *op){ if (op->referred_by){ ms_free(op->referred_by); } + if (op->auth_info) { + sal_auth_info_delete(op->auth_info); + } __sal_op_free(op); } @@ -735,11 +739,28 @@ int sal_call_send_dtmf(SalOp *h, char dtmf){ return 0; } +static void push_auth_to_exosip(const SalAuthInfo *info){ + const char *userid; + if (info->userid==NULL || info->userid[0]=='\0') userid=info->username; + else userid=info->userid; + ms_message("Authentication info for username [%s], id[%s], realm [%s] added to eXosip", info->username,userid, info->realm); + eXosip_add_authentication_info (info->username,userid, + info->password, NULL,info->realm); +} +/** + * Just for symmetry ;-) + */ +static void pop_auth_from_exosip() { + eXosip_clear_authentication_info(); +} + int sal_call_terminate(SalOp *h){ int err; + if (h->auth_info) push_auth_to_exosip(h->auth_info); eXosip_lock(); err=eXosip_call_terminate(h->cid,h->did); eXosip_unlock(); + pop_auth_from_exosip(); if (err!=0){ ms_warning("Exosip could not terminate the call: cid=%i did=%i", h->cid,h->did); } @@ -750,20 +771,17 @@ int sal_call_terminate(SalOp *h){ void sal_op_authenticate(SalOp *h, const SalAuthInfo *info){ if (h->pending_auth){ - const char *userid; - if (info->userid==NULL || info->userid[0]=='\0') userid=info->username; - else userid=info->userid; - ms_message("Authentication info for %s %s added to eXosip", info->username,info->realm); - eXosip_add_authentication_info (info->username,userid, - info->password, NULL,info->realm); + push_auth_to_exosip(info); eXosip_lock(); eXosip_default_action(h->pending_auth); eXosip_unlock(); ms_message("eXosip_default_action() done"); - eXosip_clear_authentication_info(); + pop_auth_from_exosip(); eXosip_event_free(h->pending_auth); sal_remove_pending_auth(sal_op_get_sal(h),h); h->pending_auth=NULL; + if (h->auth_info) sal_auth_info_delete(h->auth_info); /*if already exist*/ + h->auth_info=sal_auth_info_clone(info); /*store auth info for subsequent request*/ } } diff --git a/coreapi/sal_eXosip2.h b/coreapi/sal_eXosip2.h index ad6eeb7f..7d50ae82 100644 --- a/coreapi/sal_eXosip2.h +++ b/coreapi/sal_eXosip2.h @@ -64,6 +64,7 @@ struct SalOp{ bool_t reinvite; bool_t masquerade_via; bool_t auto_answer_asked; + const SalAuthInfo *auth_info; }; void sal_remove_out_subscribe(Sal *sal, SalOp *op);