diff --git a/.cproject b/.cproject index 02473afca..ed10f0f5e 100644 --- a/.cproject +++ b/.cproject @@ -22,7 +22,7 @@ - + diff --git a/console/Makefile.am b/console/Makefile.am index 82ce998e5..e33d608d1 100644 --- a/console/Makefile.am +++ b/console/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS=\ -I$(top_srcdir) \ -I$(top_srcdir)/coreapi \ + -I$(top_srcdir)/include \ -I$(top_srcdir)/exosip COMMON_CFLAGS=\ diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index a88860e23..83073578b 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -16,10 +16,9 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + #include "sal_impl.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif void _belle_sip_log(belle_sip_log_level lev, const char *fmt, va_list args) { int ortp_level; @@ -232,30 +231,11 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even via_header= (belle_sip_header_via_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(response),BELLE_SIP_VIA); received = belle_sip_header_via_get_received(via_header); rport = belle_sip_header_via_get_rport(via_header); - if (!sal_op_get_contact(op)) { - /*check if contqct set in reauest*/ - - 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 ((original_contact=belle_sip_message_get_header_by_type(request,belle_sip_header_contact_t))) { + /*update contact with sent values in any cases*/ + 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); } if (received!=NULL || rport>0) { @@ -289,10 +269,12 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even } } if (contact_updated) { + char* old_contact=belle_sip_object_to_string(BELLE_SIP_OBJECT(sal_op_get_contact_address(op))); new_contact=belle_sip_object_to_string(BELLE_SIP_OBJECT(contact_address)); - ms_message("Updating contact from [%s] to [%s] for [%p]",sal_op_get_contact(op),new_contact,op); - sal_op_set_contact(op,new_contact); + ms_message("Updating contact from [%s] to [%s] for [%p]",old_contact,new_contact,op); + sal_op_set_contact_address(op,(const SalAddress *)contact_address); belle_sip_free(new_contact); + belle_sip_free(old_contact); } if (contact_address)belle_sip_object_unref(contact_address); } diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index 085ce8f8b..e7e22b9b2 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -19,10 +19,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SAL_IMPL_H_ #define SAL_IMPL_H_ + #include "sal/sal.h" #include "belle-sip/belle-sip.h" #include "belle-sip/belle-sdp.h" + + struct Sal{ SalCallbacks callbacks; MSList *pending_auths;/*MSList of SalOp */ diff --git a/coreapi/friend.c b/coreapi/friend.c index b1dd9c4c9..e55deb75d 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -108,7 +108,6 @@ void __linphone_friend_do_subscribe(LinphoneFriend *fr){ char *friend=NULL; const char *route=NULL; const char *from=NULL; - const char *fixed_contact=NULL; LinphoneProxyConfig *cfg; friend=linphone_address_as_string(fr->uri); @@ -116,12 +115,6 @@ void __linphone_friend_do_subscribe(LinphoneFriend *fr){ if (cfg!=NULL){ route=linphone_proxy_config_get_route(cfg); from=linphone_proxy_config_get_identity(cfg); - if (cfg->op){ - fixed_contact=sal_op_get_contact(cfg->op); - if (fixed_contact) { - ms_message("Contact for subscribe has been fixed using proxy to %s",fixed_contact); - } - } }else from=linphone_core_get_primary_contact(fr->lc); if (fr->outsub==NULL){ /* people for which we don't have yet an answer should appear as offline */ @@ -136,7 +129,10 @@ void __linphone_friend_do_subscribe(LinphoneFriend *fr){ } fr->outsub=sal_op_new(fr->lc->sal); sal_op_set_route(fr->outsub,route); - sal_op_set_contact(fr->outsub,fixed_contact); + if (cfg && cfg->op && sal_op_get_contact(cfg->op)) + sal_op_set_contact(fr->outsub,sal_op_get_contact(cfg->op)); + else + sal_op_set_contact(fr->outsub,NULL); sal_subscribe_presence(fr->outsub,from,friend); fr->subscribe_active=TRUE; ms_free(friend); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 199a1cc3b..16375869b 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2318,54 +2318,68 @@ const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAdd } return linphone_core_get_primary_contact (lc); } - +#ifndef USE_BELLESIP static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){ - LinphoneAddress *ctt; +#else +static LinphoneAddress *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){ +#endif + LinphoneAddress *ctt=NULL; +#ifdef USE_BELLESIP + LinphoneAddress *ret; +#else + char* ret; +#endif const char *localip=call->localip; /* first use user's supplied ip address if asked*/ if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){ ctt=linphone_core_get_primary_contact_parsed(lc); - return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt), - linphone_core_get_nat_address_resolved(lc)); - } - - /* if already choosed, don't change it */ - if (call->op && sal_op_get_contact(call->op)!=NULL){ + linphone_address_set_domain(ctt,linphone_core_get_nat_address_resolved(lc)); + #ifdef USE_BELLESIP + ret=ctt; + #else + ret=linphone_adress_as_string(ctt); + #endif + } else if (call->op && sal_op_get_contact(call->op)!=NULL){ + /* if already choosed, don't change it */ return NULL; - } - /* if the ping OPTIONS request succeeded use the contact guessed from the - received, rport*/ - if (call->ping_op){ - const char *guessed=sal_op_get_contact(call->ping_op); - if (guessed){ - ms_message("Contact has been fixed using OPTIONS to %s",guessed); - return ms_strdup(guessed); - } - } - + } else if (call->ping_op && sal_op_get_contact(call->ping_op)) { + /* if the ping OPTIONS request succeeded use the contact guessed from the + received, rport*/ + ms_message("Contact has been fixed using OPTIONS"/* to %s",guessed*/); +#ifdef USE_BELLESIP + ret=linphone_address_clone(sal_op_get_contact(call->ping_op));; +#else + ret=ms_strdup(sal_op_get_contact(call->ping_op)); +#endif + } else if (dest_proxy && dest_proxy->op && sal_op_get_contact(dest_proxy->op)){ /*if using a proxy, use the contact address as guessed with the REGISTERs*/ - if (dest_proxy && dest_proxy->op){ - const char *fixed_contact=sal_op_get_contact(dest_proxy->op); - if (fixed_contact) { - ms_message("Contact has been fixed using proxy to %s",fixed_contact); - return ms_strdup(fixed_contact); + ms_message("Contact has been fixed using proxy" /*to %s",fixed_contact*/); +#ifdef USE_BELLESIP + ret=linphone_address_clone(sal_op_get_contact(dest_proxy->op)); +#else + ret=ms_strdup(sal_op_get_contact(dest_proxy->op)); +#endif + } else { + ctt=linphone_core_get_primary_contact_parsed(lc); + if (ctt!=NULL){ + /*otherwise use supllied localip*/ + linphone_address_set_domain(ctt,localip); + linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc)); + ms_message("Contact has been fixed using local ip"/* to %s",ret*/); +#ifdef USE_BELLESIP + ret=ctt; +#else + ret=linphone_address_as_string_uri_only(ctt); +#endif } } +#ifndef USE_BELLESIP + if (ctt) linphone_address_destroy(ctt); +#endif + return ret; - ctt=linphone_core_get_primary_contact_parsed(lc); - if (ctt!=NULL){ - char *ret; - /*otherwise use supllied localip*/ - linphone_address_set_domain(ctt,localip); - linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc)); - ret=linphone_address_as_string_uri_only(ctt); - linphone_address_destroy(ctt); - ms_message("Contact has been fixed using local ip to %s",ret); - return ret; - } - return NULL; } int linphone_core_proceed_with_invite_if_ready(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){ @@ -2401,7 +2415,12 @@ int linphone_core_proceed_with_invite_if_ready(LinphoneCore *lc, LinphoneCall *c int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call){ int err; +#ifndef USE_BELLESIP char *contact; +#else + LinphoneAddress *contact; +#endif + char *real_url,*barmsg; char *from; LinphoneProxyConfig *dest_proxy=call->dest_proxy; @@ -2410,7 +2429,12 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call){ contact=get_fixed_contact(lc,call,dest_proxy); if (contact){ sal_op_set_contact(call->op, contact); +#ifndef USE_BELLESIP ms_free(contact); +#else + linphone_address_destroy(contact); +#endif + } linphone_core_stop_dtmf_stream(lc); linphone_call_init_media_streams(call); @@ -3103,7 +3127,11 @@ int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call){ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params) { LinphoneProxyConfig *cfg=NULL; - const char *contact=NULL; +#ifndef USE_BELLESIP + char *contact=NULL; +#else + LinphoneAddress *contact=NULL; +#endif SalOp *replaced; SalMediaDescription *new_md; bool_t was_ringing=FALSE; @@ -3159,9 +3187,14 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call, } /*try to be best-effort in giving real local or routable contact address*/ contact=get_fixed_contact(lc,call,call->dest_proxy); - if (contact) + if (contact) { sal_op_set_contact(call->op,contact); - +#ifdef USE_BELLESIP + linphone_address_destroy(contact); +#else + ms_free(contact); +#endif + } if (params){ const SalMediaDescription *md = sal_call_get_remote_media_description(call->op); _linphone_call_params_copy(&call->params,params); diff --git a/coreapi/presence.c b/coreapi/presence.c index ca6357258..4643d7d9f 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -58,7 +58,6 @@ void linphone_subscription_new(LinphoneCore *lc, SalOp *op, const char *from){ char *tmp; LinphoneAddress *uri; LinphoneProxyConfig *cfg; - const char *fixed_contact; uri=linphone_address_new(from); linphone_address_clean(uri); @@ -68,10 +67,9 @@ void linphone_subscription_new(LinphoneCore *lc, SalOp *op, const char *from){ cfg=linphone_core_lookup_known_proxy(lc,uri); if (cfg!=NULL){ if (cfg->op){ - fixed_contact=sal_op_get_contact(cfg->op); - if (fixed_contact) { - sal_op_set_contact (op,fixed_contact); - ms_message("Contact for next subscribe answer has been fixed using proxy to %s",fixed_contact); + if (sal_op_get_contact(cfg->op)) { + sal_op_set_contact (op,sal_op_get_contact(cfg->op)); + ms_message("Contact for next subscribe answer has been fixed using proxy "/*to %s",fixed_contact*/); } } } diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 6998b8731..8ab64606b 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -255,49 +255,62 @@ void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc) obj->lc=lc; linphone_proxy_config_done(obj); } - +#ifndef USE_BELLESIP static char *guess_contact_for_register(LinphoneProxyConfig *obj){ - LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy); char *ret=NULL; + #else +LinphoneAddress *guess_contact_for_register(LinphoneProxyConfig *obj){ + LinphoneAddress *ret=NULL; +#endif + LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy); + const char *host; if (proxy==NULL) return NULL; host=linphone_address_get_domain (proxy); if (host!=NULL){ int localport = -1; - char localip_tmp[LINPHONE_IPADDR_SIZE] = {'\0'}; + const char *localip = NULL; char *tmp; LCSipTransports tr; - LinphoneAddress *contact; + LinphoneAddress *contact=linphone_address_new(obj->reg_identity); + + if (obj->contact_params) + tmp=ms_strdup_printf("",linphone_address_get_username(contact) + ,linphone_address_get_domain(contact) + ,obj->contact_params); + else + tmp=ms_strdup_printf("",linphone_address_get_username(contact) + ,linphone_address_get_domain(contact)); - contact=linphone_address_new(obj->reg_identity); + linphone_address_destroy(contact); + contact=linphone_address_new(tmp); #ifdef BUILD_UPNP if (obj->lc->upnp != NULL && linphone_core_get_firewall_policy(obj->lc)==LinphonePolicyUseUpnp && linphone_upnp_context_get_state(obj->lc->upnp) == LinphoneUpnpStateOk) { localip = linphone_upnp_context_get_external_ipaddress(obj->lc->upnp); localport = linphone_upnp_context_get_external_port(obj->lc->upnp); + linphone_core_get_sip_transports(obj->lc,&tr); + if (tr.udp_port <= 0) { + if (tr.tcp_port>0) { + sal_address_set_param(contact,"transport","tcp"); + } else if (tr.tls_port>0) { + sal_address_set_param(contact,"transport","tls"); + } + } + } #endif //BUILD_UPNP -#ifdef USE_BELLESIP -#ifdef BUILD_UPNP - else -#endif /*BUILD_UPNP*/ - { - linphone_address_destroy(contact); - return NULL; - } -#endif /*USE_BELLESIP*/ + +#ifndef USE_BELLESIP if(localip == NULL) { + char localip_tmp[LINPHONE_IPADDR_SIZE] = {'\0'}; localip = localip_tmp; linphone_core_get_local_ip(obj->lc,host,localip_tmp); } if(localport == -1) { localport = linphone_core_get_sip_port(obj->lc); } - linphone_address_set_port_int(contact,localport); - linphone_address_set_domain(contact,localip); - linphone_address_set_display_name(contact,NULL); - linphone_core_get_sip_transports(obj->lc,&tr); if (tr.udp_port <= 0) { if (tr.tcp_port>0) { @@ -306,27 +319,41 @@ static char *guess_contact_for_register(LinphoneProxyConfig *obj){ sal_address_set_param(contact,"transport","tls"); } } +#endif - tmp=linphone_address_as_string_uri_only(contact); - if (obj->contact_params) - ret=ms_strdup_printf("<%s;%s>",tmp,obj->contact_params); - else ret=ms_strdup_printf("<%s>",tmp); + linphone_address_set_port_int(contact,localport); + linphone_address_set_domain(contact,localip); + linphone_address_set_display_name(contact,NULL); + +#ifndef USE_BELLESIP + ret = linphone_address_as_string(contact); linphone_address_destroy(contact); +#else + ret=contact; +#endif /*USE_BELLESIP*/ + linphone_address_destroy (proxy); ms_free(tmp); } - linphone_address_destroy (proxy); return ret; } static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ if (obj->reg_sendregister){ +#ifndef USE_BELLESIP char *contact; +#else + LinphoneAddress *contact; +#endif if (obj->op) sal_op_release(obj->op); obj->op=sal_op_new(obj->lc->sal); if ((contact=guess_contact_for_register(obj))) { sal_op_set_contact(obj->op,contact); +#ifndef USE_BELLESIP ms_free(contact); +#else + linphone_address_destroy(contact); +#endif } sal_op_set_user_pointer(obj->op,obj); if (sal_register(obj->op,obj->reg_proxy,obj->reg_identity,obj->expires)==0) { diff --git a/coreapi/sal.c b/coreapi/sal.c index 07d189ed8..4685b0bc5 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -22,7 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The purpose of this layer is too allow experiment different call signaling protocols and implementations under linphone, for example SIP, JINGLE... **/ - +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "sal/sal.h" const char* sal_transport_to_string(SalTransport transport) { switch (transport) { @@ -246,16 +248,15 @@ static void assign_string(char **str, const char *arg){ *str=ms_strdup(arg); } - +#ifdef USE_BELLESIP void sal_op_set_contact_address(SalOp *op, const SalAddress *address){ - char* address_string=sal_address_as_string(address); /*can probably be optimized*/ - sal_op_set_contact(op,address_string); - ms_free(address_string); + if (((SalOpBase*)op)->contact_address) sal_address_destroy(((SalOpBase*)op)->contact_address); + ((SalOpBase*)op)->contact_address=address?sal_address_clone(address):NULL; } const SalAddress* sal_op_get_contact_address(const SalOp *op) { return ((SalOpBase*)op)->contact_address; } - +#endif #define SET_PARAM(op,name) \ char* name##_string=NULL; \ assign_address(&((SalOpBase*)op)->name##_address,name); \ @@ -265,10 +266,14 @@ const SalAddress* sal_op_get_contact_address(const SalOp *op) { assign_string(&((SalOpBase*)op)->name,name##_string); \ if(name##_string) ms_free(name##_string); +#ifndef USE_BELLESIP void sal_op_set_contact(SalOp *op, const char *contact){ - SET_PARAM(op,contact); + assign_string(&((SalOpBase*)op)->contact,contact); } - +const char *sal_op_get_contact(const SalOp *op){ + return ((SalOpBase*)op)->contact; +} +#endif void sal_op_set_route(SalOp *op, const char *route){ char* route_string=(void *)0; SalOpBase* op_base = (SalOpBase*)op; @@ -339,9 +344,7 @@ const char *sal_op_get_to(const SalOp *op){ const SalAddress *sal_op_get_to_address(const SalOp *op){ return ((SalOpBase*)op)->to_address; } -const char *sal_op_get_contact(const SalOp *op){ - return ((SalOpBase*)op)->contact; -} + const char *sal_op_get_remote_contact(const SalOp *op){ return ((SalOpBase*)op)->remote_contact; @@ -404,10 +407,16 @@ void __sal_op_free(SalOp *op){ ms_free(b->route); b->route=NULL; } +#ifndef USE_BELLESIP if (b->contact) { ms_free(b->contact); b->contact=NULL; } +#else + if (b->contact_address) { + sal_address_destroy(b->contact_address); + } +#endif if (b->origin){ ms_free(b->origin); b->origin=NULL; diff --git a/include/sal/sal.h b/include/sal/sal.h index 70a788769..f48edbde3 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -26,6 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef sal_h #define sal_h +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "mediastreamer2/mscommon.h" #include "ortp/ortp_srtp.h" @@ -226,8 +230,11 @@ typedef struct SalOpBase{ Sal *root; char *route; /*or request-uri for REGISTER*/ MSList* route_addresses; /*list of SalAddress* */ +#ifndef USE_BELLESIP char *contact; +#else SalAddress* contact_address; +#endif char *from; SalAddress* from_address; char *to; @@ -401,8 +408,12 @@ SalOp * sal_op_new(Sal *sal); /*generic SalOp API, working for all operations */ Sal *sal_op_get_sal(const SalOp *op); +#ifndef USE_BELLESIP void sal_op_set_contact(SalOp *op, const char *contact); +#else +#define sal_op_set_contact sal_op_set_contact_address /*for liblinphone compatibility*/ void sal_op_set_contact_address(SalOp *op, const SalAddress* address); +#endif void sal_op_set_route(SalOp *op, const char *route); void sal_op_set_route_address(SalOp *op, const SalAddress* address); void sal_op_add_route_address(SalOp *op, const SalAddress* address); @@ -419,8 +430,12 @@ 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); const SalAddress *sal_op_get_to_address(const SalOp *op); +#ifndef USE_BELLESIP const char *sal_op_get_contact(const SalOp *op); +#else const SalAddress *sal_op_get_contact_address(const SalOp *op); +#define sal_op_get_contact sal_op_get_contact_address /*for liblinphone compatibility*/ +#endif const char *sal_op_get_route(const SalOp *op); const MSList* sal_op_get_route_addresses(const SalOp *op); const char *sal_op_get_proxy(const SalOp *op);