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"
31 void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc){
34 if (!linphone_core_ready(lc)) return;
36 for(elem=lc->sip_conf.proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
37 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
38 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
40 /*to ensure removed configs are erased:*/
41 linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
42 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
45 void linphone_proxy_config_init(LinphoneProxyConfig *obj){
46 memset(obj,0,sizeof(LinphoneProxyConfig));
56 * Creates an empty proxy config.
58 LinphoneProxyConfig *linphone_proxy_config_new(){
59 LinphoneProxyConfig *obj=NULL;
60 obj=ms_new(LinphoneProxyConfig,1);
61 linphone_proxy_config_init(obj);
66 * Destroys a proxy config.
68 * @note: LinphoneProxyConfig that have been removed from LinphoneCore with
69 * linphone_core_remove_proxy_config() must not be freed.
71 void linphone_proxy_config_destroy(LinphoneProxyConfig *obj){
72 if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy);
73 if (obj->reg_identity!=NULL) ms_free(obj->reg_identity);
74 if (obj->reg_route!=NULL) ms_free(obj->reg_route);
75 if (obj->ssctx!=NULL) sip_setup_context_free(obj->ssctx);
76 if (obj->realm!=NULL) ms_free(obj->realm);
77 if (obj->type!=NULL) ms_free(obj->type);
78 if (obj->dial_prefix!=NULL) ms_free(obj->dial_prefix);
79 if (obj->op) sal_op_release(obj->op);
80 if (obj->publish_op) sal_op_release(obj->publish_op);
84 * Returns a boolean indicating that the user is sucessfully registered on the proxy.
86 bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *obj){
87 return obj->state == LinphoneRegistrationOk;
91 * Sets the proxy address
93 * Examples of valid sip proxy address are:
94 * - IP address: sip:87.98.157.38
95 * - IP address with port: sip:87.98.157.38:5062
96 * - hostnames : sip:sip.example.net
98 int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *server_addr){
99 LinphoneAddress *addr=NULL;
102 if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy);
105 if (server_addr!=NULL && strlen(server_addr)>0){
106 if (strstr(server_addr,"sip:")==NULL){
107 modified=ms_strdup_printf("sip:%s",server_addr);
108 addr=linphone_address_new(modified);
112 addr=linphone_address_new(server_addr);
114 obj->reg_proxy=linphone_address_as_string_uri_only(addr);
115 linphone_address_destroy(addr);
117 ms_warning("Could not parse %s",server_addr);
125 * Sets the user identity as a SIP address.
127 * This identity is normally formed with display name, username and domain, such
129 * Alice <sip:alice@example.net>
130 * The REGISTER messages will have from and to set to this identity.
133 int linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *identity){
134 LinphoneAddress *addr;
135 if (identity!=NULL && strlen(identity)>0){
136 addr=linphone_address_new(identity);
137 if (!addr || linphone_address_get_username(addr)==NULL){
138 ms_warning("Invalid sip identity: %s",identity);
140 linphone_address_destroy(addr);
143 if (obj->reg_identity!=NULL) {
144 ms_free(obj->reg_identity);
145 obj->reg_identity=NULL;
147 obj->reg_identity=ms_strdup(identity);
151 obj->realm=ms_strdup(linphone_address_get_domain(addr));
152 linphone_address_destroy(addr);
159 const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg){
165 * When a route is set, all outgoing calls will go to the route's destination if this proxy
166 * is the default one (see linphone_core_set_default_proxy() ).
168 int linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route)
170 if (obj->reg_route!=NULL){
171 ms_free(obj->reg_route);
175 LinphoneAddress *addr;
176 /*try to prepend 'sip:' */
177 if (strstr(route,"sip:")==NULL){
178 obj->reg_route=ms_strdup_printf("sip:%s",route);
179 }else obj->reg_route=ms_strdup(route);
180 addr=linphone_address_new(obj->reg_route);
182 ms_free(obj->reg_route);
184 }else linphone_address_destroy(addr);
189 bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *obj){
190 if (obj->reg_proxy==NULL){
191 if (lc->vtable.display_warning)
192 lc->vtable.display_warning(lc,_("The sip proxy address you entered is invalid, it must start with \"sip:\""
193 " followed by a hostname."));
196 if (obj->reg_identity==NULL){
197 if (lc->vtable.display_warning)
198 lc->vtable.display_warning(lc,_("The sip identity you entered is invalid.\nIt should look like "
199 "sip:username@proxydomain, such as sip:alice@example.net"));
206 * Indicates whether a REGISTER request must be sent to the proxy.
208 void linphone_proxy_config_enableregister(LinphoneProxyConfig *obj, bool_t val){
209 obj->reg_sendregister=val;
213 * Sets the registration expiration time in seconds.
215 void linphone_proxy_config_expires(LinphoneProxyConfig *obj, int val){
220 void linphone_proxy_config_enable_publish(LinphoneProxyConfig *obj, bool_t val){
224 * Starts editing a proxy configuration.
226 * Because proxy configuration must be consistent, applications MUST
227 * call linphone_proxy_config_edit() before doing any attempts to modify
228 * proxy configuration (such as identity, proxy address and so on).
229 * Once the modifications are done, then the application must call
230 * linphone_proxy_config_done() to commit the changes.
232 void linphone_proxy_config_edit(LinphoneProxyConfig *obj){
233 if (obj->reg_sendregister){
235 if (obj->state != LinphoneRegistrationNone && obj->state != LinphoneRegistrationCleared) {
236 sal_unregister(obj->op);
241 void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc)
244 linphone_proxy_config_done(obj);
247 static char *guess_contact_for_register(LinphoneProxyConfig *obj){
248 LinphoneAddress *proxy=linphone_address_new(obj->reg_proxy);
251 if (proxy==NULL) return NULL;
252 host=linphone_address_get_domain (proxy);
254 LinphoneAddress *contact;
255 char localip[LINPHONE_IPADDR_SIZE];
258 linphone_core_get_local_ip(obj->lc,host,localip);
259 contact=linphone_address_new(obj->reg_identity);
260 linphone_address_set_domain (contact,localip);
261 linphone_address_set_port_int(contact,linphone_core_get_sip_port(obj->lc));
262 linphone_address_set_display_name(contact,NULL);
264 linphone_core_get_sip_transports(obj->lc,&tr);
265 if (tr.udp_port <= 0) {
267 sal_address_set_param(contact,"transport","tcp");
268 } else if (tr.tls_port>0) {
269 sal_address_set_param(contact,"transport","tls");
272 ret=linphone_address_as_string(contact);
273 linphone_address_destroy(contact);
275 linphone_address_destroy (proxy);
279 static void linphone_proxy_config_register(LinphoneProxyConfig *obj){
280 if (obj->reg_sendregister){
283 sal_op_release(obj->op);
284 obj->op=sal_op_new(obj->lc->sal);
285 contact=guess_contact_for_register(obj);
286 sal_op_set_contact(obj->op,contact);
288 sal_op_set_user_pointer(obj->op,obj);
289 if (sal_register(obj->op,obj->reg_proxy,obj->reg_identity,obj->expires)==0) {
290 linphone_proxy_config_set_state(obj,LinphoneRegistrationProgress,"Registration in progress");
292 linphone_proxy_config_set_state(obj,LinphoneRegistrationFailed,"Registration failed");
298 * Refresh a proxy registration.
299 * This is useful if for example you resuming from suspend, thus IP address may have changed.
301 void linphone_proxy_config_refresh_register(LinphoneProxyConfig *obj){
302 if (obj->reg_sendregister && obj->op){
303 if (sal_register_refresh(obj->op,obj->expires) == 0) {
304 linphone_proxy_config_set_state(obj,LinphoneRegistrationProgress, "Refresh registration");
311 * Sets a dialing prefix to be automatically prepended when inviting a number with
312 * #linphone_core_invite.
315 void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char *prefix){
316 if (cfg->dial_prefix!=NULL){
317 ms_free(cfg->dial_prefix);
318 cfg->dial_prefix=NULL;
320 if (prefix && prefix[0]!='\0') cfg->dial_prefix=ms_strdup(prefix);
324 * Returns dialing prefix.
328 const char *linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg){
329 return cfg->dial_prefix;
333 * Sets whether liblinphone should replace "+" by "00" in dialed numbers (passed to
334 * #linphone_core_invite ).
337 void linphone_proxy_config_set_dial_escape_plus(LinphoneProxyConfig *cfg, bool_t val){
338 cfg->dial_escape_plus=val;
342 * Returns whether liblinphone should replace "+" by "00" in dialed numbers (passed to
343 * #linphone_core_invite ).
346 bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg){
347 return cfg->dial_escape_plus;
351 static bool_t is_a_phone_number(const char *username){
353 for(p=username;*p!='\0';++p){
366 static char *flatten_number(const char *number){
367 char *result=ms_malloc0(strlen(number)+1);
370 for(r=number;*r!='\0';++r){
371 if (*r=='+' || isdigit(*r)){
379 static void copy_result(const char *src, char *dest, size_t destlen, bool_t escape_plus){
382 if (escape_plus && src[0]=='+' && destlen>2){
389 for(;(i<destlen-1) && *src!='\0';++i){
397 static char *append_prefix(const char *number, const char *prefix){
398 char *res=ms_malloc(strlen(number)+strlen(prefix)+1);
400 return strcat(res,number);
403 int linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len){
406 if (is_a_phone_number(username)){
407 flatten=flatten_number(username);
408 ms_message("Flattened number is '%s'",flatten);
409 numlen=strlen(flatten);
410 if (numlen>10 || flatten[0]=='+' || proxy->dial_prefix==NULL || proxy->dial_prefix[0]=='\0'){
411 ms_message("No need to add a prefix");
412 /* prefix is already there */
413 copy_result(flatten,result,result_len,proxy->dial_escape_plus);
416 }else if (proxy->dial_prefix && proxy->dial_prefix[0]!='\0'){
419 ms_message("Need to prefix with %s",proxy->dial_prefix);
421 /*remove initial number before prepending prefix*/
424 prefixed=append_prefix(flatten+skipped,proxy->dial_prefix);
426 copy_result(prefixed,result,result_len,proxy->dial_escape_plus);
429 }else strncpy(result,username,result_len);
434 * Commits modification made to the proxy configuration.
436 int linphone_proxy_config_done(LinphoneProxyConfig *obj)
438 if (!linphone_proxy_config_check(obj->lc,obj)) return -1;
440 linphone_proxy_config_write_all_to_config_file(obj->lc);
444 void linphone_proxy_config_set_realm(LinphoneProxyConfig *cfg, const char *realm)
446 if (cfg->realm!=NULL) {
450 if (realm!=NULL) cfg->realm=ms_strdup(realm);
453 int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy,
454 LinphoneOnlineStatus presence_mode){
456 SalOp *op=sal_op_new(proxy->lc->sal);
457 err=sal_publish(op,linphone_proxy_config_get_identity(proxy),
458 linphone_proxy_config_get_identity(proxy),linphone_online_status_to_sal(presence_mode));
459 if (proxy->publish_op!=NULL)
460 sal_op_release(proxy->publish_op);
461 proxy->publish_op=op;
466 * Returns the route set for this proxy configuration.
468 const char *linphone_proxy_config_get_route(const LinphoneProxyConfig *obj){
469 return obj->reg_route;
473 * Returns the SIP identity that belongs to this proxy configuration.
475 * The SIP identity is a SIP address (Display Name <sip:username@domain> )
477 const char *linphone_proxy_config_get_identity(const LinphoneProxyConfig *obj){
478 return obj->reg_identity;
482 * Returns TRUE if PUBLISH request is enabled for this proxy.
484 bool_t linphone_proxy_config_publish_enabled(const LinphoneProxyConfig *obj){
489 * Returns the proxy's SIP address.
491 const char *linphone_proxy_config_get_addr(const LinphoneProxyConfig *obj){
492 return obj->reg_proxy;
496 * Returns the duration of registration.
498 int linphone_proxy_config_get_expires(const LinphoneProxyConfig *obj){
503 * Returns TRUE if registration to the proxy is enabled.
505 bool_t linphone_proxy_config_register_enabled(const LinphoneProxyConfig *obj){
506 return obj->reg_sendregister;
509 struct _LinphoneCore * linphone_proxy_config_get_core(const LinphoneProxyConfig *obj){
514 * Add a proxy configuration.
515 * This will start registration on the proxy, if registration is enabled.
517 int linphone_core_add_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
518 if (!linphone_proxy_config_check(lc,cfg)) {
519 linphone_proxy_config_destroy(cfg);
522 if (ms_list_find(lc->sip_conf.proxies,cfg)!=NULL){
523 linphone_proxy_config_destroy(cfg);
524 ms_warning("ProxyConfig already entered, ignored.");
527 lc->sip_conf.proxies=ms_list_append(lc->sip_conf.proxies,(void *)cfg);
528 linphone_proxy_config_apply(cfg,lc);
533 * Removes a proxy configuration.
535 * LinphoneCore will then automatically unregister and place the proxy configuration
536 * on a deleted list. For that reason, a removed proxy does NOT need to be freed.
538 void linphone_core_remove_proxy_config(LinphoneCore *lc, LinphoneProxyConfig *cfg){
539 lc->sip_conf.proxies=ms_list_remove(lc->sip_conf.proxies,(void *)cfg);
540 /* add to the list of destroyed proxies, so that the possible unREGISTER request can succeed authentication */
541 lc->sip_conf.deleted_proxies=ms_list_append(lc->sip_conf.deleted_proxies,(void *)cfg);
542 cfg->deletion_date=ms_time(NULL);
543 /* this will unREGISTER */
544 linphone_proxy_config_edit(cfg);
545 if (lc->default_proxy==cfg){
546 lc->default_proxy=NULL;
548 linphone_proxy_config_write_all_to_config_file(lc);
551 * Erase all proxies from config.
555 void linphone_core_clear_proxy_config(LinphoneCore *lc){
556 MSList* list=ms_list_copy(linphone_core_get_proxy_config_list((const LinphoneCore*)lc));
558 for(;list!=NULL;list=list->next){
559 linphone_core_remove_proxy_config(lc,(LinphoneProxyConfig *)list->data);
562 linphone_proxy_config_write_all_to_config_file(lc);
565 * Sets the default proxy.
567 * This default proxy must be part of the list of already entered LinphoneProxyConfig.
568 * Toggling it as default will make LinphoneCore use the identity associated with
569 * the proxy configuration in all incoming and outgoing calls.
571 void linphone_core_set_default_proxy(LinphoneCore *lc, LinphoneProxyConfig *config){
572 /* check if this proxy is in our list */
574 if (ms_list_find(lc->sip_conf.proxies,config)==NULL){
575 ms_warning("Bad proxy address: it is not in the list !");
576 lc->default_proxy=NULL;
580 lc->default_proxy=config;
581 if (linphone_core_ready(lc))
582 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
585 void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index){
586 if (index<0) linphone_core_set_default_proxy(lc,NULL);
587 else linphone_core_set_default_proxy(lc,ms_list_nth_data(lc->sip_conf.proxies,index));
591 * Returns the default proxy configuration, that is the one used to determine the current identity.
593 int linphone_core_get_default_proxy(LinphoneCore *lc, LinphoneProxyConfig **config){
595 if (config!=NULL) *config=lc->default_proxy;
596 if (lc->default_proxy!=NULL){
597 pos=ms_list_position(lc->sip_conf.proxies,ms_list_find(lc->sip_conf.proxies,(void *)lc->default_proxy));
603 * Returns an unmodifiable list of entered proxy configurations.
605 const MSList *linphone_core_get_proxy_config_list(const LinphoneCore *lc){
606 return lc->sip_conf.proxies;
609 void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyConfig *obj, int index)
613 sprintf(key,"proxy_%i",index);
614 lp_config_clean_section(config,key);
618 if (obj->type!=NULL){
619 lp_config_set_string(config,key,"type",obj->type);
621 if (obj->reg_proxy!=NULL){
622 lp_config_set_string(config,key,"reg_proxy",obj->reg_proxy);
624 if (obj->reg_route!=NULL){
625 lp_config_set_string(config,key,"reg_route",obj->reg_route);
627 if (obj->reg_identity!=NULL){
628 lp_config_set_string(config,key,"reg_identity",obj->reg_identity);
630 lp_config_set_int(config,key,"reg_expires",obj->expires);
631 lp_config_set_int(config,key,"reg_sendregister",obj->reg_sendregister);
632 lp_config_set_int(config,key,"publish",obj->publish);
633 lp_config_set_int(config,key,"dial_escape_plus",obj->dial_escape_plus);
634 lp_config_set_string(config,key,"dial_prefix",obj->dial_prefix);
639 LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LpConfig *config, int index)
642 const char *identity;
644 LinphoneProxyConfig *cfg;
647 sprintf(key,"proxy_%i",index);
649 if (!lp_config_has_section(config,key)){
653 cfg=linphone_proxy_config_new();
655 identity=lp_config_get_string(config,key,"reg_identity",NULL);
656 proxy=lp_config_get_string(config,key,"reg_proxy",NULL);
658 linphone_proxy_config_set_identity(cfg,identity);
659 linphone_proxy_config_set_server_addr(cfg,proxy);
661 tmp=lp_config_get_string(config,key,"reg_route",NULL);
662 if (tmp!=NULL) linphone_proxy_config_set_route(cfg,tmp);
664 linphone_proxy_config_expires(cfg,lp_config_get_int(config,key,"reg_expires",600));
665 linphone_proxy_config_enableregister(cfg,lp_config_get_int(config,key,"reg_sendregister",0));
667 linphone_proxy_config_enable_publish(cfg,lp_config_get_int(config,key,"publish",0));
669 linphone_proxy_config_set_dial_escape_plus(cfg,lp_config_get_int(config,key,"dial_escape_plus",0));
670 linphone_proxy_config_set_dial_prefix(cfg,lp_config_get_string(config,key,"dial_prefix",NULL));
672 tmp=lp_config_get_string(config,key,"type",NULL);
673 if (tmp!=NULL && strlen(tmp)>0)
674 linphone_proxy_config_set_sip_setup(cfg,tmp);
679 static void linphone_proxy_config_activate_sip_setup(LinphoneProxyConfig *cfg){
680 SipSetupContext *ssc;
681 SipSetup *ss=sip_setup_lookup(cfg->type);
682 LinphoneCore *lc=linphone_proxy_config_get_core(cfg);
685 ssc=sip_setup_context_new(ss,cfg);
687 if (cfg->reg_identity==NULL){
688 ms_error("Invalid identity for this proxy configuration.");
691 caps=sip_setup_context_get_capabilities(ssc);
692 if (caps & SIP_SETUP_CAP_ACCOUNT_MANAGER){
693 if (sip_setup_context_login_account(ssc,cfg->reg_identity,NULL)!=0){
694 if (lc->vtable.display_warning){
695 char *tmp=ms_strdup_printf(_("Could not login as %s"),cfg->reg_identity);
696 lc->vtable.display_warning(lc,tmp);
702 if (caps & SIP_SETUP_CAP_PROXY_PROVIDER){
704 if (sip_setup_context_get_proxy(ssc,NULL,proxy,sizeof(proxy))==0){
705 linphone_proxy_config_set_server_addr(cfg,proxy);
707 ms_error("Could not retrieve proxy uri !");
713 SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg){
714 if (cfg->ssctx!=NULL) return cfg->ssctx->funcs;
715 if (cfg->type!=NULL){
716 return sip_setup_lookup(cfg->type);
721 void linphone_proxy_config_update(LinphoneProxyConfig *cfg){
722 LinphoneCore *lc=cfg->lc;
724 if (cfg->type && cfg->ssctx==NULL){
725 linphone_proxy_config_activate_sip_setup(cfg);
727 if (!lc->sip_conf.register_only_when_network_is_up || lc->network_reachable)
728 linphone_proxy_config_register(cfg);
729 if (cfg->publish && cfg->publish_op==NULL){
730 linphone_proxy_config_send_publish(cfg,lc->presence_mode);
736 void linphone_proxy_config_set_sip_setup(LinphoneProxyConfig *cfg, const char *type){
739 cfg->type=ms_strdup(type);
740 if (linphone_proxy_config_get_addr(cfg)==NULL){
741 /*put a placeholder so that the sip setup gets saved into the config */
742 linphone_proxy_config_set_server_addr(cfg,"sip:undefined");
746 SipSetupContext *linphone_proxy_config_get_sip_setup_context(LinphoneProxyConfig *cfg){
754 LinphoneAccountCreator *linphone_account_creator_new(struct _LinphoneCore *core, const char *type){
755 LinphoneAccountCreator *obj;
756 LinphoneProxyConfig *cfg;
757 SipSetup *ss=sip_setup_lookup(type);
758 SipSetupContext *ssctx;
762 if (!(sip_setup_get_capabilities(ss) & SIP_SETUP_CAP_ACCOUNT_MANAGER)){
763 ms_error("%s cannot manage accounts.",type);
766 obj=ms_new0(LinphoneAccountCreator,1);
767 cfg=linphone_proxy_config_new();
768 ssctx=sip_setup_context_new(ss,cfg);
771 set_string(&obj->domain,sip_setup_context_get_domains(ssctx)[0]);
776 void linphone_account_creator_set_username(LinphoneAccountCreator *obj, const char *username){
777 set_string(&obj->username,username);
780 void linphone_account_creator_set_password(LinphoneAccountCreator *obj, const char *password){
781 set_string(&obj->password,password);
784 void linphone_account_creator_set_domain(LinphoneAccountCreator *obj, const char *domain){
785 set_string(&obj->domain,domain);
788 void linphone_account_creator_set_route(LinphoneAccountCreator *obj, const char *route) {
789 set_string(&obj->route,route);
792 void linphone_account_creator_set_email(LinphoneAccountCreator *obj, const char *email) {
793 set_string(&obj->email,email);
796 void linphone_account_creator_set_suscribe(LinphoneAccountCreator *obj, int suscribe) {
797 obj->suscribe = suscribe;
800 const char * linphone_account_creator_get_username(LinphoneAccountCreator *obj){
801 return obj->username;
804 const char * linphone_account_creator_get_domain(LinphoneAccountCreator *obj){
808 int linphone_account_creator_test_existence(LinphoneAccountCreator *obj){
809 SipSetupContext *ssctx=obj->ssctx;
810 char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain);
811 int err=sip_setup_context_account_exists(ssctx,uri);
816 int linphone_account_creator_test_validation(LinphoneAccountCreator *obj) {
817 SipSetupContext *ssctx=obj->ssctx;
818 int err=sip_setup_context_account_validated(ssctx,obj->username);
822 LinphoneProxyConfig * linphone_account_creator_validate(LinphoneAccountCreator *obj){
823 SipSetupContext *ssctx=obj->ssctx;
824 char *uri=ms_strdup_printf("%s@%s",obj->username,obj->domain);
825 int err=sip_setup_context_create_account(ssctx, uri, obj->password, obj->email, obj->suscribe);
829 return sip_setup_context_get_proxy_config(ssctx);
834 void linphone_account_creator_destroy(LinphoneAccountCreator *obj){
836 ms_free(obj->username);
838 ms_free(obj->password);
840 ms_free(obj->domain);
841 if (!obj->succeeded){
842 linphone_proxy_config_destroy(sip_setup_context_get_proxy_config(obj->ssctx));
846 void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cr, void * ud) {
850 void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr) {
851 return cr->user_data;
854 void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const char *message){
855 LinphoneCore *lc=cfg->lc;
857 if (lc && lc->vtable.registration_state_changed){
858 lc->vtable.registration_state_changed(lc,cfg,state,message);
862 LinphoneRegistrationState linphone_proxy_config_get_state(const LinphoneProxyConfig *cfg){
866 const char *linphone_registration_state_to_string(LinphoneRegistrationState cs){
868 case LinphoneRegistrationCleared:
869 return "LinphoneRegistrationCleared";
871 case LinphoneRegistrationNone:
872 return "LinphoneRegistrationNone";
874 case LinphoneRegistrationProgress:
875 return "LinphoneRegistrationProgress";
877 case LinphoneRegistrationOk:
878 return "LinphoneRegistrationOk";
880 case LinphoneRegistrationFailed:
881 return "LinphoneRegistrationFailed";
887 LinphoneReason linphone_proxy_config_get_error(const LinphoneProxyConfig *cfg) {
891 void linphone_proxy_config_set_error(LinphoneProxyConfig *cfg,LinphoneReason error) {