3 Copyright (C) 2000 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 "linphonecore.h"
25 typedef struct _FonisContext{
29 static ms_thread_t fonis_thread;
32 static void *fonis_thread_func(void *arg){
33 char *argv[]={"-edge-only","-sip", "5058",NULL};
34 if (p2pproxy_application_start(3,argv)!=0){
35 ms_error("Fail to start fonis thread !");
40 static bool_t fonis_init(void){
41 static bool_t initd=FALSE;
43 ms_thread_create(&fonis_thread,NULL,fonis_thread_func,NULL);
45 while( p2pproxy_application_get_state()==P2PPROXY_ERROR_APPLICATION_NOT_STARTED){
47 ms_message("Waiting for p2pproxy to start");
53 static bool_t fonis_check_connected(SipSetupContext *ctx){
55 LinphoneCore *lc=linphone_proxy_config_get_core(sip_setup_context_get_proxy_config(ctx));
56 for(retries=0;retries<1200;retries++){
57 if (p2pproxy_application_get_state()==P2PPROXY_CONNECTED){
58 if (retries>0) linphone_core_stop_waiting(lc);
62 ms_message("Waiting for p2pproxy to connect to the network...");
63 linphone_core_start_waiting(lc,"Trying to connect to the fonis network...");
64 }else linphone_core_update_progress(lc,NULL,-1);
66 linphone_core_stop_waiting(lc);
70 static int fonis_test_account(SipSetupContext *ctx, const char *uri){
72 LinphoneCore *lc=linphone_proxy_config_get_core(sip_setup_context_get_proxy_config(ctx));
73 if (!fonis_check_connected(ctx)) return -1;
74 linphone_core_start_waiting(lc,"Checking...");
75 ret=(p2pproxy_accountmgt_isValidAccount(uri)==P2PPROXY_ACCOUNTMGT_USER_EXIST) ? 1 : 0;
76 linphone_core_update_progress(lc,NULL,1);
77 linphone_core_stop_waiting(lc);
81 static int fonis_create_account(SipSetupContext *ctx, const char *uri, const char *passwd){
83 LinphoneCore *lc=linphone_proxy_config_get_core(sip_setup_context_get_proxy_config(ctx));
84 if (!fonis_check_connected(ctx)) return -1;
85 linphone_core_start_waiting(lc,"Creating account...");
86 err=p2pproxy_accountmgt_createAccount(uri);
87 ms_message("Account creation result for %s: %i",uri,err);
88 linphone_core_update_progress(lc,NULL,1);
89 linphone_core_stop_waiting(lc);
94 static int fonis_login_account(SipSetupContext * ctx,const char *uri, const char *passwd){
95 if (!fonis_check_connected(ctx)) return -1;
96 if (p2pproxy_accountmgt_isValidAccount(uri)==P2PPROXY_ACCOUNTMGT_USER_EXIST) {
102 static int fonis_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){
104 if (!fonis_check_connected(ctx)) return -1;
105 err=p2pproxy_resourcemgt_lookup_sip_proxy(proxy,sz,(char*)domain);
106 if (err==0) return 0;
110 static int fonis_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){
111 FonisContext *fc=(FonisContext*)ctx->data;
113 p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list();
114 if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){
115 if (l->size>0) strncpy(stun1,l->resource_uri[0],size);
116 if (l->size>1) strncpy(stun2,l->resource_uri[1],size);
119 p2pproxy_resourcemgt_delete_resource_list(l);
123 static int fonis_get_relay(SipSetupContext *ctx, char *relay, size_t size){
124 FonisContext *fc=(FonisContext*)ctx->data;
126 p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list();
127 if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){
128 if (l->size>0) strncpy(relay,l->resource_uri[0],size);
131 p2pproxy_resourcemgt_delete_resource_list(l);
135 static void fonis_exit(){
136 p2pproxy_application_stop();
139 static const char *fonis_get_notice(SipSetupContext *ssctx){
140 return "<b>WARNING: experimental feature !</b>"
141 "FONIS stands for Free Overlay Network for Instant SIP.\n"
142 "Based on SIP and Peer to Peer technologies, it allows people to find each other through the help of a virtual network."
143 "Once you and your friends are registered, you'll be able to call each other simply by entering your friend's username in "
144 "linphone's sip uri box."
145 "Read more information about FONIS at http://www.fonis.org";
148 static const char *fonis_domains[]={
153 static const char ** fonis_get_domains(SipSetupContext *ssctx){
154 return fonis_domains;
159 static SipSetup fonis_sip_setup={
160 .capabilities=SIP_SETUP_CAP_PROXY_PROVIDER|SIP_SETUP_CAP_STUN_PROVIDER|
161 SIP_SETUP_CAP_RELAY_PROVIDER|SIP_SETUP_CAP_ACCOUNT_MANAGER,
164 .account_exists=fonis_test_account,
165 .create_account=fonis_create_account,
166 .login_account=fonis_login_account,
167 .get_proxy=fonis_get_proxy,
168 .get_stun_servers=fonis_get_stun_servers,
169 .get_relay=fonis_get_relay,
171 .get_notice=fonis_get_notice,
172 .get_domains=fonis_get_domains
175 void libfonisprovider_init(void){
176 sip_setup_register(&fonis_sip_setup);