]> sjero.net Git - linphone/blob - coreapi/fonis.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / coreapi / fonis.c
1 /*
2 linphone
3 Copyright (C) 2000  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
21 #include "sipsetup.h"
22 #include "p2pproxy.h"
23
24 static ms_thread_t fonis_thread;
25
26
27 static void *fonis_thread_func(void *arg){
28         if (p2pproxy_application_start(0,NULL)!=0){
29                 ms_error("Fail to start fonis thread !");
30         }
31         return NULL;
32 }
33
34 static bool_t fonis_init(void){
35         static bool_t initd=FALSE;
36         if (!initd){
37                 ms_thread_create(&fonis_thread,NULL,fonis_thread_func,NULL);
38                 initd=TRUE;
39         }
40         return TRUE;
41 }
42
43
44 static int fonis_create_account(const char *uri, const char *passwd){
45         int err=p2pproxy_accountmgt_createAccount(uri);
46         if (err<0) return -1;
47         return 0;
48 }
49
50 static int fonis_login_account(SipSetupContext * ctx,const char *uri, const char *passwd){
51         if (p2pproxy_accountmgt_isValidAccount==P2PPROXY_ACCOUNTMGT_USER_EXIST) {
52                 return 0;
53         }
54         else return -1;
55 }
56
57 static int fonis_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){
58         int err=p2pproxy_resourcemgt_lookup_sip_proxy(proxy,sz,(char*)domain);
59         if (err==0) return 0;
60         else return -1;
61 }
62
63 static int fonis_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){
64         FonisContext *fc=(FonisContext*)ctx->data;
65         int ret=-1;
66         p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list();
67         if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){
68                 if (l->size>0) strncpy(stun1,l->resource_uri[0],size);
69                 if (l->size>1) strncpy(stun2,l->resource_uri[1],size);
70                 ret=0;
71         }
72         p2pproxy_resourcemgt_delete_resource_list(l);
73         return ret;
74 }
75
76 static int fonis_get_stun_relay(SipSetupContext *ctx, char *relay, size_t size){
77         FonisContext *fc=(FonisContext*)ctx->data;
78         int ret=-1;
79         p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list();
80         if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){
81                 if (l->size>0) strncpy(relay,l->resource_uri[0],size);
82                 ret=0;
83         }
84         p2pproxy_resourcemgt_delete_resource_list(l);
85         return ret;
86 }
87
88
89 SipSetup fonis_sip_setup={
90         .name="fonis",
91         .init=fonis_init,
92         .create_account=fonis_create_account,
93         .login_account=fonis_login_account,
94         .get_proxy=fonis_get_proxy,
95         .get_stun_servers=fonis_get_stun_servers,
96         .get_relay=fonis_get_relay,
97         .exit=p2pproxy_application_stop
98 };
99