3 Copyright (C) 2009 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "../config.h"
24 #include "linphonecore.h"
26 extern SipSetup linphone_sip_login;
27 extern SipSetup linphone_sip_wizard;
29 static SipSetup *all_sip_setups[]={
35 static MSList *registered_sip_setups=NULL;
37 void sip_setup_register(SipSetup *ss){
38 registered_sip_setups=ms_list_append(registered_sip_setups,ss);
41 void sip_setup_register_all(void){
42 SipSetup **p=all_sip_setups;
43 ms_load_plugins(LINPHONE_PLUGINS_DIR);
45 sip_setup_register(*p);
50 const MSList * linphone_core_get_sip_setups(LinphoneCore *lc){
51 return registered_sip_setups;
54 SipSetup *sip_setup_lookup(const char *type_name){
56 for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
57 SipSetup *ss=(SipSetup*)elem->data;
58 if ( strcasecmp(ss->name,type_name)==0){
59 if (!ss->initialized){
60 if (ss->init!=NULL) ss->init();
62 if (ss->capabilities==0){
63 ms_error("%s SipSetup isn't capable of anything ?",ss->name);
69 ms_warning("no %s setup manager declared.",type_name);
73 void sip_setup_unregister_all(void){
75 for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
76 SipSetup *ss=(SipSetup*)elem->data;
78 if (ss->exit) ss->exit();
79 ss->initialized=FALSE;
84 void buddy_lookup_request_set_key(BuddyLookupRequest *req, const char *key){
89 if (key) req->key=ms_strdup(key);
92 void buddy_lookup_request_set_max_results(BuddyLookupRequest *req, int ncount){
93 req->max_results=ncount;
96 void buddy_lookup_request_free(BuddyLookupRequest *req){
97 if (req->key) ms_free(req->key);
99 ms_list_for_each(req->results,(void (*)(void*))buddy_info_free);
100 ms_list_free(req->results);
105 LinphoneProxyConfig *sip_setup_context_get_proxy_config(const SipSetupContext *ctx){
109 SipSetupContext *sip_setup_context_new(SipSetup *s, struct _LinphoneProxyConfig *cfg){
110 SipSetupContext *obj=(SipSetupContext*)ms_new0(SipSetupContext,1);
114 if (obj->funcs->init_instance){
115 obj->funcs->init_instance(obj);
120 unsigned int sip_setup_get_capabilities(SipSetup *s){
121 return s->capabilities;
124 int sip_setup_context_get_capabilities(SipSetupContext *ctx){
125 return ctx->funcs->capabilities;
128 int sip_setup_context_create_account(SipSetupContext * ctx, const char *uri, const char *passwd, const char *email, int suscribe){
129 if (ctx->funcs->create_account)
130 return ctx->funcs->create_account(ctx, uri, passwd, email, suscribe);
134 int sip_setup_context_account_exists(SipSetupContext *ctx, const char *uri){
135 if (ctx->funcs->account_exists)
136 return ctx->funcs->account_exists(ctx,uri);
140 int sip_setup_context_account_validated(SipSetupContext *ctx, const char *uri){
141 if (ctx->funcs->account_validated)
142 return ctx->funcs->account_validated(ctx,uri);
146 int sip_setup_context_login_account(SipSetupContext * ctx, const char *uri, const char *passwd){
147 LinphoneAddress *from=linphone_address_new(uri);
149 ms_warning("Fail to parse %s",uri);
152 strncpy(ctx->domain,linphone_address_get_domain(from),sizeof(ctx->domain));
153 strncpy(ctx->username,linphone_address_get_username(from),sizeof(ctx->username));
154 linphone_address_destroy(from);
155 if (ctx->funcs->login_account)
156 return ctx->funcs->login_account(ctx,uri,passwd);
160 int sip_setup_context_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){
161 if (ctx->funcs->get_proxy)
162 return ctx->funcs->get_proxy(ctx,domain ? domain : ctx->domain,proxy,sz);
166 int sip_setup_context_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){
167 if (ctx->funcs->get_stun_servers)
168 return ctx->funcs->get_stun_servers(ctx,stun1,stun2,size);
172 int sip_setup_context_get_relay(SipSetupContext *ctx,char *relay, size_t size){
173 if (ctx->funcs->get_relay)
174 return ctx->funcs->get_relay(ctx,relay,size);
178 BuddyLookupRequest *sip_setup_context_create_buddy_lookup_request(SipSetupContext *ctx){
179 if (ctx->funcs->buddy_lookup_funcs)
180 return ctx->funcs->buddy_lookup_funcs->request_create(ctx);
184 int sip_setup_context_buddy_lookup_submit(SipSetupContext *ctx , BuddyLookupRequest *req){
185 if (ctx->funcs->buddy_lookup_funcs)
186 return ctx->funcs->buddy_lookup_funcs->request_submit(ctx,req);
190 int sip_setup_context_buddy_lookup_free(SipSetupContext *ctx , BuddyLookupRequest *req){
191 if (ctx->funcs->buddy_lookup_funcs)
192 return ctx->funcs->buddy_lookup_funcs->request_free(ctx,req);
196 const char * sip_setup_context_get_notice(SipSetupContext *ctx){
197 if (ctx->funcs->get_notice)
198 return ctx->funcs->get_notice(ctx);
202 const char ** sip_setup_context_get_domains(SipSetupContext *ctx){
203 if (ctx->funcs->get_domains)
204 return ctx->funcs->get_domains(ctx);
209 int sip_setup_context_logout(SipSetupContext *ctx){
210 if (ctx->funcs->logout_account){
211 return ctx->funcs->logout_account(ctx);
216 void sip_setup_context_free(SipSetupContext *ctx){
217 if (ctx->funcs->uninit_instance){
218 ctx->funcs->uninit_instance(ctx);
224 BuddyInfo *buddy_info_new(){
225 return ms_new0(BuddyInfo,1);
228 void buddy_info_free(BuddyInfo *info){
229 if (info->image_data!=NULL)
230 ms_free(info->image_data);