| 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 | typedef struct _FonisContext{ |
|---|
| 25 | int toto; |
|---|
| 26 | }FonisContext; |
|---|
| 27 | |
|---|
| 28 | static ms_thread_t fonis_thread; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | static void *fonis_thread_func(void *arg){ |
|---|
| 32 | if (p2pproxy_application_start(0,NULL)!=0){ |
|---|
| 33 | ms_error("Fail to start fonis thread !"); |
|---|
| 34 | } |
|---|
| 35 | return NULL; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | static bool_t fonis_init(void){ |
|---|
| 39 | static bool_t initd=FALSE; |
|---|
| 40 | if (!initd){ |
|---|
| 41 | ms_thread_create(&fonis_thread,NULL,fonis_thread_func,NULL); |
|---|
| 42 | initd=TRUE; |
|---|
| 43 | } |
|---|
| 44 | sleep(4); |
|---|
| 45 | return TRUE; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | static int fonis_create_account(const char *uri, const char *passwd){ |
|---|
| 50 | int err=p2pproxy_accountmgt_createAccount(uri); |
|---|
| 51 | if (err<0) return -1; |
|---|
| 52 | return 0; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | static int fonis_login_account(SipSetupContext * ctx,const char *uri, const char *passwd){ |
|---|
| 56 | if (p2pproxy_accountmgt_isValidAccount(uri)==P2PPROXY_ACCOUNTMGT_USER_EXIST) { |
|---|
| 57 | return 0; |
|---|
| 58 | } |
|---|
| 59 | else return -1; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | static int fonis_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){ |
|---|
| 63 | int err=p2pproxy_resourcemgt_lookup_sip_proxy(proxy,sz,(char*)domain); |
|---|
| 64 | if (err==0) return 0; |
|---|
| 65 | else return -1; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | static int fonis_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){ |
|---|
| 69 | FonisContext *fc=(FonisContext*)ctx->data; |
|---|
| 70 | int ret=-1; |
|---|
| 71 | p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list(); |
|---|
| 72 | if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){ |
|---|
| 73 | if (l->size>0) strncpy(stun1,l->resource_uri[0],size); |
|---|
| 74 | if (l->size>1) strncpy(stun2,l->resource_uri[1],size); |
|---|
| 75 | ret=0; |
|---|
| 76 | } |
|---|
| 77 | p2pproxy_resourcemgt_delete_resource_list(l); |
|---|
| 78 | return ret; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static int fonis_get_relay(SipSetupContext *ctx, char *relay, size_t size){ |
|---|
| 82 | FonisContext *fc=(FonisContext*)ctx->data; |
|---|
| 83 | int ret=-1; |
|---|
| 84 | p2pproxy_resourcemgt_resource_list_t* l=p2pproxy_resourcemgt_new_resource_list(); |
|---|
| 85 | if (p2pproxy_resourcemgt_lookup_media_resource(l,ctx->domain)==0){ |
|---|
| 86 | if (l->size>0) strncpy(relay,l->resource_uri[0],size); |
|---|
| 87 | ret=0; |
|---|
| 88 | } |
|---|
| 89 | p2pproxy_resourcemgt_delete_resource_list(l); |
|---|
| 90 | return ret; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | static SipSetup fonis_sip_setup={ |
|---|
| 95 | .capabilities=SIP_SETUP_CAP_PROXY_PROVIDER|SIP_SETUP_CAP_STUN_PROVIDER| |
|---|
| 96 | SIP_SETUP_CAP_RELAY_PROVIDER|SIP_SETUP_CAP_ACCOUNT_MANAGER, |
|---|
| 97 | .name="fonis", |
|---|
| 98 | .init=fonis_init, |
|---|
| 99 | .create_account=fonis_create_account, |
|---|
| 100 | .login_account=fonis_login_account, |
|---|
| 101 | .get_proxy=fonis_get_proxy, |
|---|
| 102 | .get_stun_servers=fonis_get_stun_servers, |
|---|
| 103 | .get_relay=fonis_get_relay, |
|---|
| 104 | .exit=p2pproxy_application_stop |
|---|
| 105 | }; |
|---|
| 106 | |
|---|
| 107 | void libfonisprovider_init(void){ |
|---|
| 108 | sip_setup_register(&fonis_sip_setup); |
|---|
| 109 | } |
|---|
| 110 | |
|---|