]> sjero.net Git - linphone/commitdiff
add new api "linphone_core_interpret_url"
authorSimon Morlat <simon.morlat@linphone.org>
Tue, 16 Mar 2010 11:35:40 +0000 (12:35 +0100)
committerSimon Morlat <simon.morlat@linphone.org>
Tue, 16 Mar 2010 11:35:40 +0000 (12:35 +0100)
coreapi/chat.c
coreapi/linphonecore.c
coreapi/linphonecore.h
coreapi/private.h
coreapi/sal_eXosip2_presence.c

index 11c3c978f4106b85598c25a7110665e98d850f1a..c1a8849647f0c640ea054e0d4c6c0e7f98c74fd7 100644 (file)
  
  LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){
        LinphoneAddress *parsed_url=NULL;
-       char *route;
-       if (linphone_core_interpret_url(lc,to,&parsed_url,&route)){
+
+       if ((parsed_url=linphone_core_interpret_url(lc,to))!=NULL){
                LinphoneChatRoom *cr=ms_new0(LinphoneChatRoom,1);
                cr->lc=lc;
                cr->peer=linphone_address_as_string(parsed_url);
                cr->peer_url=parsed_url;
-               cr->route=route;
+               cr->route=ms_strdup(linphone_core_get_route(lc));
                lc->chatrooms=ms_list_append(lc->chatrooms,(void *)cr);
                return cr;
        }
index f699a2a3efdddd80538bff8324421e0f193d7a7b..230776bda3fc644033d65a930724ec50629a6ddf 100644 (file)
@@ -1678,32 +1678,25 @@ void linphone_core_iterate(LinphoneCore *lc){
 }
 
 
-bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAddress **real_parsed_url, char **route){
+LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
        enum_lookup_res_t *enumres=NULL;
-       LinphoneAddress *parsed_url=NULL;       
        char *enum_domain=NULL;
        LinphoneProxyConfig *proxy=lc->default_proxy;;
        char *tmpurl;
-       const char *tmproute;
        LinphoneAddress *uri;
        
-       if (real_parsed_url!=NULL) *real_parsed_url=NULL;
-       *route=NULL;
-       tmproute=linphone_core_get_route(lc);
-
        if (is_enum(url,&enum_domain)){
                lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
                if (enum_lookup(enum_domain,&enumres)<0){
                        lc->vtable.display_status(lc,_("Could not resolve this number."));
                        ms_free(enum_domain);
-                       return FALSE;
+                       return NULL;
                }
                ms_free(enum_domain);
                tmpurl=enumres->sip_address[0];
-               if (real_parsed_url!=NULL) *real_parsed_url=linphone_address_new(tmpurl);
+               uri=linphone_address_new(tmpurl);
                enum_lookup_res_free(enumres);
-               if (tmproute) *route=ms_strdup(tmproute);
-               return TRUE;
+               return uri;
        }
        /* check if we have a "sip:" */
        if (strstr(url,"sip:")==NULL){
@@ -1714,8 +1707,7 @@ bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAd
                        uri=linphone_address_new(tmpurl);
                        ms_free(tmpurl);
                        if (uri){
-                               if (real_parsed_url!=NULL) *real_parsed_url=uri;
-                               return TRUE;
+                               return uri;
                        }
                }
                
@@ -1725,31 +1717,24 @@ bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAd
                        char normalized_username[128];
                        uri=linphone_address_new(identity);
                        if (uri==NULL){
-                               return FALSE;
+                               return NULL;
                        }
                        linphone_address_set_display_name(uri,NULL);
                        linphone_proxy_config_normalize_number(proxy,url,normalized_username,
                                                                sizeof(normalized_username));
                        linphone_address_set_username(uri,normalized_username);
-                                                                               
-                       if (real_parsed_url!=NULL) *real_parsed_url=uri;
-                       if (tmproute) *route=ms_strdup(tmproute);
-                       return TRUE;
-               }else return FALSE;
-       }
-       parsed_url=linphone_address_new(url);
-       if (parsed_url!=NULL){
-               if (real_parsed_url!=NULL) *real_parsed_url=parsed_url;
-               else linphone_address_destroy(parsed_url);
-               if (tmproute) *route=ms_strdup(tmproute);
-               
-               return TRUE;
+                       return uri;
+               }else return NULL;
+       }
+       uri=linphone_address_new(url);
+       if (uri!=NULL){
+               return uri;
        }
        /* else we could not do anything with url given by user, so display an error */
        if (lc->vtable.display_warning!=NULL){
                lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
        }
-       return FALSE;
+       return NULL;
 }
 
 /**
@@ -1890,16 +1875,32 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro
  *
  * @ingroup call_control
  * @param lc the LinphoneCore object
+ * @param url the destination of the call (sip address, or phone number).
+**/
+int linphone_core_invite(LinphoneCore *lc, const char *url){
+       LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
+       if (addr){
+               int err=linphone_core_invite_address(lc,addr);
+               linphone_address_destroy(addr);
+               return err;
+       }
+       return -1;
+}
+
+/**
+ * Initiates an outgoing call given a destination LinphoneAddress
+ *
+ * @ingroup call_control
+ * @param lc the LinphoneCore object
  * @param url the destination of the call (sip address).
 **/
-int linphone_core_invite(LinphoneCore *lc, const char *url)
+int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
 {
        int err=0;
-       char *route=NULL;
+       const char *route=NULL;
        const char *from=NULL;
        LinphoneProxyConfig *proxy=NULL;
        LinphoneAddress *parsed_url2=NULL;
-       LinphoneAddress *real_parsed_url=NULL;
        char *real_url=NULL;
        LinphoneProxyConfig *dest_proxy=NULL;
        LinphoneCall *call;
@@ -1910,9 +1911,8 @@ int linphone_core_invite(LinphoneCore *lc, const char *url)
        }
 
        linphone_core_get_default_proxy(lc,&proxy);
-       if (!linphone_core_interpret_url(lc,url,&real_parsed_url,&route)){
-               return -1;
-       }
+       route=linphone_core_get_route(lc);
+       
        real_url=linphone_address_as_string(real_parsed_url);
        dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
 
@@ -1931,7 +1931,7 @@ int linphone_core_invite(LinphoneCore *lc, const char *url)
 
        parsed_url2=linphone_address_new(from);
 
-       call=linphone_call_new_outgoing(lc,parsed_url2,real_parsed_url);
+       call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
        sal_op_set_route(call->op,route);
        
        lc->call=call;
@@ -1946,21 +1946,19 @@ int linphone_core_invite(LinphoneCore *lc, const char *url)
        }
        
        if (real_url!=NULL) ms_free(real_url);
-       if (route!=NULL) ms_free(route);
        return err;
 }
 
 int linphone_core_refer(LinphoneCore *lc, const char *url)
 {
        char *real_url=NULL;
-       LinphoneAddress *real_parsed_url=NULL;
+       LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
        LinphoneCall *call;
-       char *route;
-       if (!linphone_core_interpret_url(lc,url,&real_parsed_url, &route)){
+
+       if (!real_parsed_url){
                /* bad url */
                return -1;
        }
-       if (route!=NULL) ms_free(route);
        call=lc->call;
        if (call==NULL){
                ms_warning("No established call to refer.");
index 56c34c0a240ffc8bfd88023211d455d93931fb77..2006453b319ec3c9a7d663d0453e07781307fd48 100644 (file)
@@ -467,8 +467,12 @@ LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
 /* function to be periodically called in a main loop */
 void linphone_core_iterate(LinphoneCore *lc);
 
+LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url);
+
 int linphone_core_invite(LinphoneCore *lc, const char *url);
 
+int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr);
+
 int linphone_core_refer(LinphoneCore *lc, const char *url);
 
 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc);
index cbb767207ff87021941c2bf162e70c0c1eb4bd29..4125936ffe4e1da5cf0eb34c696182e70cdf74d1 100644 (file)
@@ -177,7 +177,6 @@ void linphone_core_start_media_streams(LinphoneCore *lc, struct _LinphoneCall *c
 void linphone_core_stop_media_streams(LinphoneCore *lc, struct _LinphoneCall *call);
 const char * linphone_core_get_identity(LinphoneCore *lc);
 const char * linphone_core_get_route(LinphoneCore *lc);
-bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAddress **real_parsed_url, char **route);
 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose);
 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progresses);
 void linphone_core_stop_waiting(LinphoneCore *lc);
index 11104b8d1ac9635a69408085f984eadd0304029b..760d8fd8d41609ba4d08d5d2e3a6e6ce48417f2f 100644 (file)
@@ -424,7 +424,7 @@ int sal_notify_close(SalOp *op){
                if (identity==NULL) identity=sal_op_get_to(op);
                osip_message_set_contact(msg,identity);
                eXosip_insubscription_send_request(op->did,msg);
-       }else ms_error("could not create notify for incoming subscription.");
+       }else ms_error("sal_notify_close(): could not create notify for incoming subscription.");
        eXosip_unlock();
        return 0;
 }