3 Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "linphonecore.h"
25 #include "mediastreamer2/mediastream.h"
30 void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc){
33 if (!linphone_core_ready(lc)) return;
35 for(elem=lc->sip_conf.proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
36 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
37 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
39 /*to ensure removed configs are erased:*/
40 linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
41 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
44 #define DEFAULT_INT(config,name,default) \
45 config?lp_config_get_int(config,"default_values",#name,default):default
46 #define DEFAULT_STRING(config,name,default) \
47 config?lp_config_get_string(config,"default_values",#name,default):default
49 static void linphone_proxy_config_init(LinphoneCore* lc,LinphoneProxyConfig *obj){
50 memset(obj,0,sizeof(LinphoneProxyConfig));
51 obj->magic=linphone_proxy_config_magic;
52 obj->expires=DEFAULT_INT((lc?lc->config:NULL),reg_expires,3600);
53 obj->dial_prefix=ms_strdup(DEFAULT_STRING((lc?lc->config:NULL),dial_prefix,'\0'));
54 obj->dial_escape_plus=DEFAULT_INT((lc?lc->config:NULL),dial_escape_plus,0);
63 * @deprecated, use #linphone_core_create_proxy_config instead
64 *Creates an empty proxy config.
66 LinphoneProxyConfig *linphone_proxy_config_new() {
67 return linphone_core_create_proxy_config(NULL);
69 LinphoneProxyConfig * linphone_core_create_proxy_config(LinphoneCore *lc) {
70 LinphoneProxyConfig *obj=NULL;
71 obj=ms_new(LinphoneProxyConfig,1);
72 linphone_proxy_config_init(lc,obj);
79 * Destroys a proxy config.
81 * @note: LinphoneProxyConfig that have been removed from LinphoneCore with
82 * linphone_core_remove_proxy_config() must not be freed.
84 void linphone_proxy_config_destroy(LinphoneProxyConfig *obj){
85 if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy);
86 if (obj->reg_identity!=NULL) ms_free(obj->reg_identity);
87 if (obj->reg_route!=NULL) ms_free(obj->reg_route);
88 if (obj->ssctx!=NULL) sip_setup_context_free(obj->ssctx);
89 if (obj->realm!=NULL) ms_free(obj->realm);
90 if (obj->type!=NULL) ms_free(obj->type);
91 if (obj->dial_prefix!=NULL) ms_free(obj->dial_prefix);
92 if (obj->op) sal_op_release(obj->op);
93 if (obj->publish_op) sal_op_release(obj->publish_op);
97 * Returns a boolean indicating that the user is sucessfully registered on the proxy.
99 bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *obj){
100 return obj->state == LinphoneRegistrationOk;
104 * Sets the proxy address
106 * Examples of valid sip proxy address are:
107 * - IP address: sip:87.98.157.38
108 * - IP address with port: sip:87.98.157.38:5062
109 * - hostnames : sip:sip.example.net
111 int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *server_addr){
112 LinphoneAddress *addr=NULL;
115 if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy);
118 if (server_addr!=NULL && strlen(server_addr)>0){
119 if (strstr(server_addr,"sip:")==NULL){
120 modified=ms_strdup_printf("sip:%s",server_addr);
121 addr=linphone_address_new(modified);
125 addr=linphone_address_new(server_addr);
127 obj->reg_proxy=linphone_address_as_string_uri_only(addr);
128 linphone_address_destroy(addr);
130 ms_warning("Could not parse %s",server_addr);
138 * Sets the user identity as a SIP address.
140 * This identity is normally formed with display name, username and domain, such
142 * Alice <sip:alice@example.net>
143 * The REGISTER messages will have from and to set to this identity.
146 int linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *identity){
147 LinphoneAddress *addr;
148 if (identity!=NULL && strlen(identity)>0){
149 addr=linphone_address_new(identity);
150 if (!addr || linphone_address_get_username(addr)==NULL){
151 ms_warning("Invalid sip identity: %s",identity);
153 linphone_address_destroy(addr);
156 if (obj->reg_identity!=NULL) {
157 ms_free(obj->reg_identity);
158 obj->reg_identity=NULL;
160 obj->reg_identity=ms_strdup(identity);
164 obj->realm=ms_strdup(linphone_address_get_domain(addr));
165 linphone_address_destroy(addr);
172 const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg){
178 * When a route is set, all outgoing calls will go to the route's destination if this proxy
179 * is the default one (see linphone_core_set_default_proxy() ).
181 int linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route)
183 if (obj->reg_route!=NULL){
184 ms_free(obj->reg_route);
190 /*try to prepend 'sip:' */
191 if (strstr(route,"sip:")==NULL){
192 tmp=ms_strdup_printf("sip:%s",route);
193 }else tmp=ms_strdup(route);
194 addr=sal_address_new(tmp);
196 sal_address_destroy(addr);
206 bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *obj){
207 if (obj->reg_proxy==NULL){
208 if (lc->vtable.display_warning)
209 lc->vtable.display_warning(lc,_("The sip proxy address you entered is invalid, it must start with \"sip:\""
210 " followed by a hostname."));
213 if (obj->reg_identity==NULL){
214 if (lc->vtable.display_warning)
215 lc->vtable.display_warning(lc,_("The sip identity you entered is invalid.\nIt should look like "
216 "sip:username@proxydomain, such as sip:alice@example.net"));
223 * Indicates whether a REGISTER request must be sent to the proxy.
225 void linphone_proxy_config_enableregister(LinphoneProxyConfig *obj, bool_t val){
226 obj->reg_sendregister=val;
230 * Sets the registration expiration time in seconds.
232 void linphone_proxy_config_expires(LinphoneProxyConfig *obj, int val){
237 void linphone_proxy_config_enable_publish(LinphoneProxyConfig *obj, bool_t val){
241 * Starts editing a proxy configuration.
243 * Because proxy configuration must be consistent, applications MUST
244 * call linphone_proxy_config_edit() before doing any attempts to modify
245 * proxy configuration (such as identity, proxy address and so on).
246 * Once the modifications are done, then the application must call
247 * linphone_proxy_config_done() to commit the changes.
249 void linphone_proxy_config_edit(LinphoneProxyConfig *obj){
250 if (obj->reg_sendregister){
252 if (obj->state != LinphoneRegistrationNone && obj->state != LinphoneRegistrationCleared) {
253 sal_unregister(obj->op);
258 void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc)
261 linphone_proxy_config_done(obj);
264 static char *guess_contact_for_register(LinphoneProxyConfig *obj){
265 LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy);
268 if (proxy==NULL) return NULL;
269 host=linphone_address_get_domain (proxy);
271 char localip[LINPHONE_IPADDR_SIZE];
274 LinphoneAddress *contact;
276 linphone_core_get_local_ip(obj->lc,host,localip);
277 contact=linphone_address_new(obj->reg_identity);
278 linphone_address_set_domain (contact,localip);
279 linphone_address_set_port_int(contact,linphone_core_get_sip_port(obj->lc));
280 linphone_address_set_display_name(contact,NULL);
282 linphone_core_get_sip_transports(obj->lc,&tr);
283 if (tr.udp_port <= 0) {
285 sal_address_set_param(contact,"transport","tcp");
286 } else if (tr.tls_port>0) {
287 sal_address_set_param(contact,"transport","tls");
290 tmp=linphone_address_as_string_uri_only(contact);
291 if (obj->contact_params)
292 ret=ms_strdup_printf("<%s;%s>",tmp,obj->contact_params);
293 else ret=ms_strdup_printf("<%s>",tmp);
294 linphone_address_destroy(contact);
297 linphone_address_destroy (proxy);
301 static void linphone_proxy_config_register(LinphoneProxyConfig *obj){
302 if (obj->reg_sendregister){
305 sal_op_release(obj->op);
306 obj->op=sal_op_new(obj->lc->sal);
307 contact=guess_contact_for_register(obj);
308 sal_op_set_contact(obj->op,contact);
310 sal_op_set_user_pointer(obj->op,obj);
311 if (sal_register(obj->op,obj->reg_proxy,obj->reg_identity,obj->expires)==0) {
312 linphone_proxy_config_set_state(obj,LinphoneRegistrationProgress,"Registration in progress");
314 linphone_proxy_config_set_state(obj,LinphoneRegistrationFailed,"Registration failed");
320 * Refresh a proxy registration.
321 * This is useful if for example you resuming from suspend, thus IP address may have changed.
323 void linphone_proxy_config_refresh_register(LinphoneProxyConfig *obj){
324 if (obj->reg_sendregister && obj->op){
325 if (sal_register_refresh(obj->op,obj->expires) == 0) {
326 linphone_proxy_config_set_state(obj,LinphoneRegistrationProgress, "Refresh registration");
333 * Sets a dialing prefix to be automatically prepended when inviting a number with
334 * linphone_core_invite();
335 * This dialing prefix shall usually be the country code of the country where the user is living.
338 void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char *prefix){
339 if (cfg->dial_prefix!=NULL){
340 ms_free(cfg->dial_prefix);
341 cfg->dial_prefix=NULL;
343 if (prefix && prefix[0]!='\0') cfg->dial_prefix=ms_strdup(prefix);
347 * Returns dialing prefix.
351 const char *linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg){
352 return cfg->dial_prefix;
356 * Sets whether liblinphone should replace "+" by international calling prefix in dialed numbers (passed to
357 * #linphone_core_invite ).
360 void linphone_proxy_config_set_dial_escape_plus(LinphoneProxyConfig *cfg, bool_t val){
361 cfg->dial_escape_plus=val;
365 * Returns whether liblinphone should replace "+" by "00" in dialed numbers (passed to
366 * #linphone_core_invite ).
369 bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg){
370 return cfg->dial_escape_plus;
373 * http://en.wikipedia.org/wiki/Telephone_numbering_plan
374 * http://en.wikipedia.org/wiki/Telephone_numbers_in_Europe
376 typedef struct dial_plan{
378 char ccc[8]; /*country calling code*/
379 int nnl; /*maximum national number length*/
380 const char * icp; /*international call prefix, ex: 00 in europe*/
383 /* TODO: fill with information for all countries over the world*/
384 static dial_plan_t const dial_plans[]={
385 {"France" , "33" , 9 , "00" },
386 {"United States", "1" , 10 , "011" },
387 {"Turkey" , "90" , 10 , "00" },
388 {"Switzerland" , "41" , 9 , "00" },
389 {NULL , "" , 0 , NULL }
392 static dial_plan_t most_common_dialplan={ "generic" , "", 10, "00"};
394 static void lookup_dial_plan(const char *ccc, dial_plan_t *plan){
396 for(i=0;dial_plans[i].country!=NULL;++i){
397 if (strcmp(ccc,dial_plans[i].ccc)==0){
402 /*else return a generic "most common" dial plan*/
403 *plan=most_common_dialplan;
404 strcpy(plan->ccc,ccc);
407 static bool_t is_a_phone_number(const char *username){
409 for(p=username;*p!='\0';++p){
423 static char *flatten_number(const char *number){
424 char *result=ms_malloc0(strlen(number)+1);
427 for(r=number;*r!='\0';++r){
428 if (*r=='+' || isdigit(*r)){
436 static void replace_plus(const char *src, char *dest, size_t destlen, const char *icp){
439 if (icp && src[0]=='+' && (destlen>(i=strlen(icp))) ){
444 for(;(i<destlen-1) && *src!='\0';++i){
452 int linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len){
454 if (is_a_phone_number(username)){
456 flatten=flatten_number(username);
457 ms_message("Flattened number is '%s'",flatten);
459 if (proxy->dial_prefix==NULL || proxy->dial_prefix[0]=='\0'){
460 /*no prefix configured, nothing else to do*/
461 strncpy(result,flatten,result_len);
465 dial_plan_t dialplan;
466 lookup_dial_plan(proxy->dial_prefix,&dialplan);
467 ms_message("Using dialplan '%s'",dialplan.country);
468 if (flatten[0]=='+' || strstr(flatten,dialplan.icp)==flatten){
469 /* the number has international prefix or +, so nothing to do*/
470 ms_message("Prefix already present.");
471 /*eventually replace the plus*/
472 replace_plus(flatten,result,result_len,proxy->dial_escape_plus ? dialplan.icp : NULL);
478 numlen=strlen(flatten);
479 /*keep at most national number significant digits */
480 skip=numlen-dialplan.nnl;
482 /*first prepend internation calling prefix or +*/
483 if (proxy->dial_escape_plus){
484 strncpy(result,dialplan.icp,result_len);
485 i+=strlen(dialplan.icp);
487 strncpy(result,"+",result_len);
491 if (result_len-i>strlen(dialplan.ccc)){
492 strcpy(result+i,dialplan.ccc);
493 i+=strlen(dialplan.ccc);
496 strncpy(result+i,flatten+skip,result_len-i-1);
500 }else strncpy(result,username,result_len);
505 * Commits modification made to the proxy configuration.
507 int linphone_proxy_config_done(LinphoneProxyConfig *obj)
509 if (!linphone_proxy_config_check(obj->lc,obj)) return -1;
511 linphone_proxy_config_write_all_to_config_file(obj->lc);
515 void linphone_proxy_config_set_realm(LinphoneProxyConfig *cfg, const char *realm)
517 if (cfg->realm!=NULL) {
521 if (realm!=NULL) cfg->realm=ms_strdup(realm);
524 int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy,
525 LinphoneOnlineStatus presence_mode){
527 SalOp *op=sal_op_new(proxy->lc->sal);
528 err=sal_publish(op,linphone_proxy_config_get_identity(proxy),
529 linphone_proxy_config_get_identity(proxy),linphone_online_status_to_sal(presence_mode));
530 if (proxy->publish_op!=NULL)
531 sal_op_release(proxy->publish_op);
532 proxy->publish_op=op;
537 * Returns the route set for this proxy configuration.
539 const char *linphone_proxy_config_get_route(const LinphoneProxyConfig *obj){
540 return obj->reg_route;
544 * Returns the SIP identity that belongs to this proxy configuration.
546 * The SIP identity is a SIP address (Display Name <sip:username@@domain> )
548 const char *linphone_proxy_config_get_identity(const LinphoneProxyConfig *obj){
549 return obj->reg_identity;
553 * Returns TRUE if PUBLISH request is enabled for this proxy.
555 bool_t linphone_proxy_config_publish_enabled(const LinphoneProxyConfig *obj){
560 * Returns the proxy's SIP address.
562 const char *linphone_proxy_config_get_addr(const LinphoneProxyConfig *obj){
563 return obj->reg_proxy;
567 * Returns the duration of registration.
569 int linphone_proxy_config_get_expires(const LinphoneProxyConfig *obj){
574 * Returns TRUE if registration to the proxy is enabled.
576 bool_t linphone_proxy_config_register_enabled(const LinphoneProxyConfig *obj){
577 return obj->reg_sendregister;
581 * Set optional contact parameters that will be added to the contact information sent in the registration.
582 * @param obj the proxy config object
583 * @param contact_params a string contaning the additional parameters in text form, like "myparam=something;myparam2=something_else"
585 * The main use case for this function is provide the proxy additional information regarding the user agent, like for example unique identifier or apple push id.
586 * As an example, the contact address in the SIP register sent will look like <sip:joe@15.128.128.93:50421;apple-push-id=43143-DFE23F-2323-FA2232>.
588 void linphone_proxy_config_set_contact_parameters(LinphoneProxyConfig *obj, const char *contact_params){
589 if (obj->contact_params) {
590 ms_free(obj->contact_params);
591 obj->contact_params=NULL;
594 obj->contact_params=ms_strdup(contact_params);
599 * Returns previously set contact parameters.
601 const char *linphone_proxy_config_get_contact_parameters(const LinphoneProxyConfig *obj){
602 return obj->contact_params;
605 struct _LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *obj){
610 * Add a proxy configuration.
611 * This will start registration on the proxy, if registration is enabled.
613 int linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
614 if (!linphone_proxy_config_check(lc,cfg)) {
617 if (ms_list_find(lc->sip_conf.proxies,cfg)!=NULL){
618 ms_warning("ProxyConfig already entered, ignored.");
621 lc->sip_conf.proxies=ms_list_append(lc->sip_conf.proxies,(void *)cfg);
622 linphone_proxy_config_apply(cfg,lc);
627 * Removes a proxy configuration.
629 * LinphoneCore will then automatically unregister and place the proxy configuration
630 * on a deleted list. For that reason, a removed proxy does NOT need to be freed.
632 void linphone_core_remove_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
633 /* check this proxy config is in the list before doing more*/
634 if (ms_list_find(lc->sip_conf.proxies,cfg)==NULL){
635 ms_error("linphone_core_remove_proxy_config: LinphoneProxyConfig %p is not known by LinphoneCore (programming error?)",cfg);
638 lc->sip_conf.proxies=ms_list_remove(lc->sip_conf.proxies,(void *)cfg);
639 /* add to the list of destroyed proxies, so that the possible unREGISTER request can succeed authentication */
640 lc->sip_conf.deleted_proxies=ms_list_append(lc->sip_conf.deleted_proxies,(void *)cfg);
641 cfg->deletion_date=ms_time(NULL);
642 if (cfg->state==LinphoneRegistrationOk){
643 /* this will unREGISTER */
644 linphone_proxy_config_edit(cfg);
646 if (lc->default_proxy==cfg){
647 lc->default_proxy=NULL;
649 linphone_proxy_config_write_all_to_config_file(lc);
652 * Erase all proxies from config.
656 void linphone_core_clear_proxy_config(LinphoneCore *lc){
657 MSList* list=ms_list_copy(linphone_core_get_proxy_config_list((const LinphoneCore*)lc));
659 for(;list!=NULL;list=list->next){
660 linphone_core_remove_proxy_config(lc,(LinphoneProxyConfig *)list->data);
663 linphone_proxy_config_write_all_to_config_file(lc);
666 * Sets the default proxy.
668 * This default proxy must be part of the list of already entered LinphoneProxyConfig.
669 * Toggling it as default will make LinphoneCore use the identity associated with
670 * the proxy configuration in all incoming and outgoing calls.
672 void linphone_core_set_default_proxy(LinphoneCore *lc, LinphoneProxyConfig *config){
673 /* check if this proxy is in our list */
675 if (ms_list_find(lc->sip_conf.proxies,config)==NULL){
676 ms_warning("Bad proxy address: it is not in the list !");
677 lc->default_proxy=NULL;
681 lc->default_proxy=config;
682 if (linphone_core_ready(lc))
683 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
686 void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index){
687 if (index<0) linphone_core_set_default_proxy(lc,NULL);
688 else linphone_core_set_default_proxy(lc,ms_list_nth_data(lc->sip_conf.proxies,index));
692 * Returns the default proxy configuration, that is the one used to determine the current identity.
694 int linphone_core_get_default_proxy(LinphoneCore *lc, LinphoneProxyConfig **config){
696 if (config!=NULL) *config=lc->default_proxy;
697 if (lc->default_proxy!=NULL){
698 pos=ms_list_position(lc->sip_conf.proxies,ms_list_find(lc->sip_conf.proxies,(void *)lc->default_proxy));
704 * Returns an unmodifiable list of entered proxy configurations.
706 const MSList *linphone_core_get_proxy_config_list(const LinphoneCore *lc){
707 return lc->sip_conf.proxies;
710 void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyConfig *obj, int index)
714 sprintf(key,"proxy_%i",index);
715 lp_config_clean_section(config,key);
719 if (obj->type!=NULL){
720 lp_config_set_string(config,key,"type",obj->type);
722 if (obj->reg_proxy!=NULL){
723 lp_config_set_string(config,key,"reg_proxy",obj->reg_proxy);
725 if (obj->reg_route!=NULL){
726 lp_config_set_string(config,key,"reg_route",obj->reg_route);
728 if (obj->reg_identity!=NULL){
729 lp_config_set_string(config,key,"reg_identity",obj->reg_identity);
731 lp_config_set_int(config,key,"reg_expires",obj->expires);
732 lp_config_set_int(config,key,"reg_sendregister",obj->reg_sendregister);
733 lp_config_set_int(config,key,"publish",obj->publish);
734 lp_config_set_int(config,key,"dial_escape_plus",obj->dial_escape_plus);
735 lp_config_set_string(config,key,"dial_prefix",obj->dial_prefix);
740 LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LpConfig *config, int index)
743 const char *identity;
745 LinphoneProxyConfig *cfg;
748 sprintf(key,"proxy_%i",index);
750 if (!lp_config_has_section(config,key)){
754 cfg=linphone_proxy_config_new();
756 identity=lp_config_get_string(config,key,"reg_identity",NULL);
757 proxy=lp_config_get_string(config,key,"reg_proxy",NULL);
759 linphone_proxy_config_set_identity(cfg,identity);
760 linphone_proxy_config_set_server_addr(cfg,proxy);
762 tmp=lp_config_get_string(config,key,"reg_route",NULL);
763 if (tmp!=NULL) linphone_proxy_config_set_route(cfg,tmp);
765 linphone_proxy_config_expires(cfg,lp_config_get_int(config,key,"reg_expires",DEFAULT_INT(config,reg_expires,600)));
766 linphone_proxy_config_enableregister(cfg,lp_config_get_int(config,key,"reg_sendregister",0));
768 linphone_proxy_config_enable_publish(cfg,lp_config_get_int(config,key,"publish",0));
770 linphone_proxy_config_set_dial_escape_plus(cfg,lp_config_get_int(config,key,"dial_escape_plus",DEFAULT_INT(config,dial_escape_plus,0)));
771 linphone_proxy_config_set_dial_prefix(cfg,lp_config_get_string(config,key,"dial_prefix",DEFAULT_STRING(config,dial_prefix,NULL)));
773 tmp=lp_config_get_string(config,key,"type",NULL);
774 if (tmp!=NULL && strlen(tmp)>0)
775 linphone_proxy_config_set_sip_setup(cfg,tmp);
780 static void linphone_proxy_config_activate_sip_setup(LinphoneProxyConfig *cfg){
781 SipSetupContext *ssc;
782 SipSetup *ss=sip_setup_lookup(cfg->type);
783 LinphoneCore *lc=linphone_proxy_config_get_core(cfg);
786 ssc=sip_setup_context_new(ss,cfg);
788 if (cfg->reg_identity==NULL){
789 ms_error("Invalid identity for this proxy configuration.");
792 caps=sip_setup_context_get_capabilities(ssc);
793 if (caps & SIP_SETUP_CAP_ACCOUNT_MANAGER){
794 if (sip_setup_context_login_account(ssc,cfg->reg_identity,NULL)!=0){
795 if (lc->vtable.display_warning){
796 char *tmp=ms_strdup_printf(_("Could not login as %s"),cfg->reg_identity);
797 lc->vtable.display_warning(lc,tmp);
803 if (caps & SIP_SETUP_CAP_PROXY_PROVIDER){
805 if (sip_setup_context_get_proxy(ssc,NULL,proxy,sizeof(proxy))==0){
806 linphone_proxy_config_set_server_addr(cfg,proxy);
808 ms_error("Could not retrieve proxy uri !");
814 SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg){
815 if (cfg->ssctx!=NULL) return cfg->ssctx->funcs;
816 if (cfg->type!=NULL){
817 return sip_setup_lookup(cfg->type);
822 void linphone_proxy_config_update(LinphoneProxyConfig *cfg){
823 LinphoneCore *lc=cfg->lc;
825 if (cfg->type && cfg->ssctx==NULL){
826 linphone_proxy_config_activate_sip_setup(cfg);
828 if (!lc->sip_conf.register_only_when_network_is_up || lc->network_reachable)
829 linphone_proxy_config_register(cfg);
830 if (cfg->publish && cfg->publish_op==NULL){
831 linphone_proxy_config_send_publish(cfg,lc->presence_mode);
837 void linphone_proxy_config_set_sip_setup(LinphoneProxyConfig *cfg, const char *type){
840 cfg->type=ms_strdup(type);
841 if (linphone_proxy_config_get_addr(cfg)==NULL){
842 /*put a placeholder so that the sip setup gets saved into the config */
843 linphone_proxy_config_set_server_addr(cfg,"sip:undefined");
847 SipSetupContext *linphone_proxy_config_get_sip_setup_context(LinphoneProxyConfig *cfg){
855 LinphoneAccountCreator *linphone_account_creator_new(struct _LinphoneCore *core, const char *type){
856 LinphoneAccountCreator *obj;
857 LinphoneProxyConfig *cfg;
858 SipSetup *ss=sip_setup_lookup(type);
859 SipSetupContext *ssctx;
863 if (!(sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER)){
864 ms_error("%s cannot manage accounts.",type);
867 obj=ms_new0(LinphoneAccountCreator,1);
868 cfg=linphone_proxy_config_new();
869 ssctx=sip_setup_context_new(ss,cfg);
872 set_string(&obj->domain,sip_setup_context_get_domains(ssctx)[0]);
877 void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username){
878 set_string(&obj->username,username);
881 void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password){
882 set_string(&obj->password,password);
885 void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain){
886 set_string(&obj->domain,domain);
889 void linphone_account_creator_set_route(LinphoneAccountCreator *obj, const char *route) {
890 set_string(&obj->route,route);
893 void linphone_account_creator_set_email(LinphoneAccountCreator *obj, const char *email) {
894 set_string(&obj->email,email);
897 void linphone_account_creator_set_suscribe(LinphoneAccountCreator *obj, int suscribe) {
898 obj->suscribe = suscribe;
901 const char * linphone_account_creator_get_username(LinphoneAccountCreator *obj){
902 return obj->username;
905 const char * linphone_account_creator_get_domain(LinphoneAccountCreator *obj){
909 int linphone_account_creator_test_existence(LinphoneAccountCreator *obj){
910 SipSetupContext *ssctx=obj->ssctx;
911 char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain);
912 int err=sip_setup_context_account_exists(ssctx,uri);
917 int linphone_account_creator_test_validation(LinphoneAccountCreator *obj) {
918 SipSetupContext *ssctx=obj->ssctx;
919 int err=sip_setup_context_account_validated(ssctx,obj->username);
923 LinphoneProxyConfig * linphone_account_creator_validate(LinphoneAccountCreator *obj){
924 SipSetupContext *ssctx=obj->ssctx;
925 char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain);
926 int err=sip_setup_context_create_account(ssctx, uri, obj->password, obj->email, obj->suscribe);
930 return sip_setup_context_get_proxy_config(ssctx);
935 void linphone_account_creator_destroy(LinphoneAccountCreator *obj){
937 ms_free(obj->username);
939 ms_free(obj->password);
941 ms_free(obj->domain);
942 if (!obj->succeeded){
943 linphone_proxy_config_destroy(sip_setup_context_get_proxy_config(obj->ssctx));
947 void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cr, void * ud) {
951 void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr) {
952 return cr->user_data;
955 void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const char *message){
956 LinphoneCore *lc=cfg->lc;
958 if (lc && lc->vtable.registration_state_changed){
959 lc->vtable.registration_state_changed(lc,cfg,state,message);
963 LinphoneRegistrationState linphone_proxy_config_get_state(const LinphoneProxyConfig *cfg){
967 const char *linphone_registration_state_to_string(LinphoneRegistrationState cs){
969 case LinphoneRegistrationCleared:
970 return "LinphoneRegistrationCleared";
972 case LinphoneRegistrationNone:
973 return "LinphoneRegistrationNone";
975 case LinphoneRegistrationProgress:
976 return "LinphoneRegistrationProgress";
978 case LinphoneRegistrationOk:
979 return "LinphoneRegistrationOk";
981 case LinphoneRegistrationFailed:
982 return "LinphoneRegistrationFailed";
988 LinphoneReason linphone_proxy_config_get_error(const LinphoneProxyConfig *cfg) {
992 void linphone_proxy_config_set_error(LinphoneProxyConfig *cfg,LinphoneReason error) {