]> sjero.net Git - linphone/blob - coreapi/sipsetup.c
wizard must be optionnal, add G729 payload type
[linphone] / coreapi / sipsetup.c
1 /*
2 linphone
3 Copyright (C) 2009  Simon MORLAT (simon.morlat@linphone.org)
4
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.
9
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.
14
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.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "../config.h"
22 #endif
23
24 #include "linphonecore.h"
25
26 extern SipSetup linphone_sip_login;
27 #if defined(ANDROID) || defined(IOS)
28 static SipSetup *all_sip_setups[]={
29         &linphone_sip_login,
30         NULL
31 };
32 #else
33 #ifdef BUILD_WIZARD
34 extern SipSetup linphone_sip_wizard;
35 #endif
36 static SipSetup *all_sip_setups[]={
37         &linphone_sip_login,
38 #ifdef BUILD_WIZARD
39         &linphone_sip_wizard,
40 #endif
41         NULL
42 };
43 #endif
44
45 static MSList *registered_sip_setups=NULL;
46
47 void sip_setup_register(SipSetup *ss){
48         registered_sip_setups=ms_list_append(registered_sip_setups,ss);
49 }
50
51 void sip_setup_register_all(void){
52         SipSetup **p=all_sip_setups;
53         ms_load_plugins(LINPHONE_PLUGINS_DIR);
54         while(*p!=NULL){
55                 sip_setup_register(*p);
56                 p++;
57         }
58 }
59
60 const MSList * linphone_core_get_sip_setups(LinphoneCore *lc){
61         return registered_sip_setups;
62 }
63
64 SipSetup *sip_setup_lookup(const char *type_name){
65         MSList *elem;
66         for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
67                 SipSetup *ss=(SipSetup*)elem->data;
68                 if ( strcasecmp(ss->name,type_name)==0){
69                         if (!ss->initialized){
70                                 if (ss->init!=NULL) ss->init();
71                                 ss->initialized=TRUE;
72                                 if (ss->capabilities==0){
73                                         ms_error("%s SipSetup isn't capable of anything ?",ss->name);
74                                 }
75                         }
76                         return ss;
77                 }
78         }
79         ms_warning("no %s setup manager declared.",type_name);
80         return NULL;
81 }
82
83 void sip_setup_unregister_all(void){
84         MSList *elem;
85         for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
86                 SipSetup *ss=(SipSetup*)elem->data;
87                 if (ss->initialized){
88                         if (ss->exit) ss->exit();
89                         ss->initialized=FALSE;
90                 }
91         }
92 }
93
94 void buddy_lookup_request_set_key(BuddyLookupRequest *req, const char *key){
95         if (req->key!=NULL) {
96                 ms_free(req->key);
97                 req->key=NULL;
98         }
99         if (key) req->key=ms_strdup(key);
100 }
101
102 void buddy_lookup_request_set_max_results(BuddyLookupRequest *req, int ncount){
103         req->max_results=ncount;
104 }
105
106 void buddy_lookup_request_free(BuddyLookupRequest *req){
107         if (req->key) ms_free(req->key);
108         if (req->results){
109                 ms_list_for_each(req->results,(void (*)(void*))buddy_info_free);
110                 ms_list_free(req->results);
111         }
112         ms_free(req);
113 }
114
115 LinphoneProxyConfig *sip_setup_context_get_proxy_config(const SipSetupContext *ctx){
116         return ctx->cfg;
117 }
118
119 SipSetupContext *sip_setup_context_new(SipSetup *s, struct _LinphoneProxyConfig *cfg){
120         SipSetupContext *obj=(SipSetupContext*)ms_new0(SipSetupContext,1);
121         obj->funcs=s;
122         obj->data=NULL;
123         obj->cfg=cfg;
124         if (obj->funcs->init_instance){
125                 obj->funcs->init_instance(obj);
126         }
127         return obj;
128 }
129
130 unsigned int sip_setup_get_capabilities(SipSetup *s){
131         return s->capabilities;
132 }
133
134 int sip_setup_context_get_capabilities(SipSetupContext *ctx){
135         return ctx->funcs->capabilities;
136 }
137
138 int sip_setup_context_create_account(SipSetupContext * ctx, const char *uri, const char *passwd, const char *email, int suscribe){
139         if (ctx->funcs->create_account)
140                 return ctx->funcs->create_account(ctx, uri, passwd, email, suscribe);
141         else return -1;
142 }
143
144 int sip_setup_context_account_exists(SipSetupContext *ctx, const char *uri){
145         if (ctx->funcs->account_exists)
146                 return ctx->funcs->account_exists(ctx,uri);
147         return -1;
148 }
149
150 int sip_setup_context_account_validated(SipSetupContext *ctx, const char *uri){
151         if (ctx->funcs->account_validated)
152                 return ctx->funcs->account_validated(ctx,uri);
153         return -1;
154 }
155
156 int sip_setup_context_login_account(SipSetupContext * ctx, const char *uri, const char *passwd){
157         LinphoneAddress *from=linphone_address_new(uri);
158         if (from==NULL) {
159                 ms_warning("Fail to parse %s",uri);
160                 return -1;
161         }
162         strncpy(ctx->domain,linphone_address_get_domain(from),sizeof(ctx->domain));
163         strncpy(ctx->username,linphone_address_get_username(from),sizeof(ctx->username));
164         linphone_address_destroy(from);
165         if (ctx->funcs->login_account)
166                 return ctx->funcs->login_account(ctx,uri,passwd);
167         return -1;
168 }
169
170 int sip_setup_context_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){
171         if (ctx->funcs->get_proxy)
172                 return ctx->funcs->get_proxy(ctx,domain ? domain : ctx->domain,proxy,sz);
173         return -1;
174 }
175
176 int sip_setup_context_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){
177         if (ctx->funcs->get_stun_servers)
178                 return ctx->funcs->get_stun_servers(ctx,stun1,stun2,size);
179         return -1;
180 }
181
182 int sip_setup_context_get_relay(SipSetupContext *ctx,char *relay, size_t size){
183         if (ctx->funcs->get_relay)
184                 return ctx->funcs->get_relay(ctx,relay,size);
185         return -1;
186 }
187
188 BuddyLookupRequest *sip_setup_context_create_buddy_lookup_request(SipSetupContext *ctx){
189         if (ctx->funcs->buddy_lookup_funcs)
190                 return ctx->funcs->buddy_lookup_funcs->request_create(ctx);
191         return NULL;
192 }
193
194 int sip_setup_context_buddy_lookup_submit(SipSetupContext *ctx , BuddyLookupRequest *req){
195         if (ctx->funcs->buddy_lookup_funcs)
196                 return ctx->funcs->buddy_lookup_funcs->request_submit(ctx,req);
197         return -1;
198 }
199
200 int sip_setup_context_buddy_lookup_free(SipSetupContext *ctx , BuddyLookupRequest *req){
201         if (ctx->funcs->buddy_lookup_funcs)
202                 return ctx->funcs->buddy_lookup_funcs->request_free(ctx,req);
203         return -1;
204 }
205
206 const char * sip_setup_context_get_notice(SipSetupContext *ctx){
207         if (ctx->funcs->get_notice)
208                 return ctx->funcs->get_notice(ctx);
209         return NULL;
210 }
211
212 const char ** sip_setup_context_get_domains(SipSetupContext *ctx){
213         if (ctx->funcs->get_domains)
214                 return ctx->funcs->get_domains(ctx);
215         return NULL;
216 }
217
218
219 int sip_setup_context_logout(SipSetupContext *ctx){
220         if (ctx->funcs->logout_account){
221                 return ctx->funcs->logout_account(ctx);
222         }
223         return -1;
224 }
225
226 void sip_setup_context_free(SipSetupContext *ctx){
227         if (ctx->funcs->uninit_instance){
228                 ctx->funcs->uninit_instance(ctx);
229         }
230         ms_free(ctx);
231 }
232
233
234 BuddyInfo *buddy_info_new(){
235         return ms_new0(BuddyInfo,1);
236 }
237
238 void buddy_info_free(BuddyInfo *info){
239         if (info->image_data!=NULL)
240                 ms_free(info->image_data);
241         ms_free(info);
242 }