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