sipsetup.c 4.88 KB
Newer Older
smorlat's avatar
smorlat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
linphone
Copyright (C) 2000  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

20
#ifdef HAVE_CONFIG_H
smorlat's avatar
smorlat committed
21
#include "../config.h"
22
#endif
smorlat's avatar
smorlat committed
23

smorlat's avatar
smorlat committed
24 25
#include "linphonecore.h"

smorlat's avatar
smorlat committed
26 27
#ifndef LINPHONE_PLUGINS_DIR
#ifdef WIN32
28
#define LINPHONE_PLUGINS_DIR "liblinphone\\plugins\\"
smorlat's avatar
smorlat committed
29 30 31 32
#else
#define LINPHONE_PLUGINS_DIR "."
#endif
#endif
smorlat's avatar
smorlat committed
33

smorlat's avatar
smorlat committed
34 35 36 37
static SipSetup *all_sip_setups[]={
	NULL
};

smorlat's avatar
smorlat committed
38 39 40 41
static MSList *registered_sip_setups=NULL;

void sip_setup_register(SipSetup *ss){
	registered_sip_setups=ms_list_append(registered_sip_setups,ss);
smorlat's avatar
smorlat committed
42
}
smorlat's avatar
smorlat committed
43

smorlat's avatar
smorlat committed
44
void sip_setup_register_all(void){
smorlat's avatar
smorlat committed
45
	SipSetup **p=all_sip_setups;
smorlat's avatar
smorlat committed
46
	ms_load_plugins(LINPHONE_PLUGINS_DIR);
smorlat's avatar
smorlat committed
47
	while(*p!=NULL){
smorlat's avatar
smorlat committed
48 49 50 51
		sip_setup_register(*p);
	}
}

smorlat's avatar
smorlat committed
52 53 54 55
const MSList * linphone_core_get_sip_setups(LinphoneCore *lc){
	return registered_sip_setups;
}

smorlat's avatar
smorlat committed
56 57 58 59
SipSetup *sip_setup_lookup(const char *type_name){
	MSList *elem;
	for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
		SipSetup *ss=(SipSetup*)elem->data;
smorlat's avatar
smorlat committed
60
		if ( strcasecmp(ss->name,type_name)==0){
smorlat's avatar
smorlat committed
61 62 63 64 65
			if (!ss->initialized){
				ss->init();
				ss->initialized=TRUE;
				if (ss->capabilities==0){
					ms_error("%s SipSetup isn't capable of anything ?",ss->name);
smorlat's avatar
smorlat committed
66
				}
smorlat's avatar
smorlat committed
67
			}
smorlat's avatar
smorlat committed
68
			return ss;
smorlat's avatar
smorlat committed
69 70 71 72 73 74
		}
	}
	ms_warning("no %s setup manager declared.",type_name);
	return NULL;
}

smorlat's avatar
smorlat committed
75
void sip_setup_unregister_all(void){
smorlat's avatar
smorlat committed
76 77 78 79
	MSList *elem;
	for(elem=registered_sip_setups;elem!=NULL;elem=elem->next){
		SipSetup *ss=(SipSetup*)elem->data;
		if (ss->initialized){
smorlat's avatar
fixes  
smorlat committed
80
			if (ss->exit) ss->exit();
smorlat's avatar
smorlat committed
81
			ss->initialized=FALSE;
smorlat's avatar
smorlat committed
82 83
		}
	}
smorlat's avatar
smorlat committed
84 85
}

smorlat's avatar
smorlat committed
86 87 88
LinphoneProxyConfig *sip_setup_context_get_proxy_config(const SipSetupContext *ctx){
	return ctx->cfg;
}
smorlat's avatar
smorlat committed
89

smorlat's avatar
smorlat committed
90
SipSetupContext *sip_setup_context_new(SipSetup *s, struct _LinphoneProxyConfig *cfg){
smorlat's avatar
smorlat committed
91
	SipSetupContext *obj=(SipSetupContext*)ms_new0(SipSetupContext,1);
smorlat's avatar
smorlat committed
92 93
	obj->funcs=s;
	obj->data=NULL;
smorlat's avatar
smorlat committed
94
	obj->cfg=cfg;
smorlat's avatar
smorlat committed
95 96 97
	if (obj->funcs->init_instance){
		obj->funcs->init_instance(obj);
	}
smorlat's avatar
smorlat committed
98 99 100
	return obj;
}

smorlat's avatar
smorlat committed
101 102 103 104
unsigned int sip_setup_get_capabilities(SipSetup *s){
	return s->capabilities;
}

smorlat's avatar
smorlat committed
105 106 107 108
int sip_setup_context_get_capabilities(SipSetupContext *ctx){
	return ctx->funcs->capabilities;
}

smorlat's avatar
smorlat committed
109 110 111
int sip_setup_context_create_account(SipSetupContext * ctx, const char *uri, const char *passwd){
	if (ctx->funcs->create_account)
		return ctx->funcs->create_account(ctx,uri, passwd);
smorlat's avatar
smorlat committed
112 113 114
	else return -1;
}

smorlat's avatar
smorlat committed
115 116 117 118 119 120
int sip_setup_context_account_exists(SipSetupContext *ctx, const char *uri){
	if (ctx->funcs->account_exists)
		return ctx->funcs->account_exists(ctx,uri);
	return -1;
}

smorlat's avatar
smorlat committed
121
int sip_setup_context_login_account(SipSetupContext * ctx, const char *uri, const char *passwd){
smorlat's avatar
smorlat committed
122 123 124 125 126 127
	osip_from_t *from;
	osip_from_init(&from);
	osip_from_parse(from,uri);
	strncpy(ctx->domain,from->url->host,sizeof(ctx->domain));
	strncpy(ctx->username,from->url->username,sizeof(ctx->username));
	osip_from_free(from);
smorlat's avatar
smorlat committed
128 129 130 131 132 133 134
	if (ctx->funcs->login_account)
		return ctx->funcs->login_account(ctx,uri,passwd);
	return -1;
}

int sip_setup_context_get_proxy(SipSetupContext *ctx, const char *domain, char *proxy, size_t sz){
	if (ctx->funcs->get_proxy)
smorlat's avatar
smorlat committed
135
		return ctx->funcs->get_proxy(ctx,domain ? domain : ctx->domain,proxy,sz);
smorlat's avatar
smorlat committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
	return -1;
}

int sip_setup_context_get_stun_servers(SipSetupContext *ctx, char *stun1, char *stun2, size_t size){
	if (ctx->funcs->get_stun_servers)
		return ctx->funcs->get_stun_servers(ctx,stun1,stun2,size);
	return -1;
}

int sip_setup_context_get_relay(SipSetupContext *ctx,char *relay, size_t size){
	if (ctx->funcs->get_relay)
		return ctx->funcs->get_relay(ctx,relay,size);
	return -1;
}

smorlat's avatar
smorlat committed
151
int sip_setup_context_lookup_buddy(SipSetupContext *ctx, const char *key){
smorlat's avatar
smorlat committed
152
	if (ctx->funcs->lookup_buddy)
smorlat's avatar
smorlat committed
153 154 155 156 157 158 159 160 161 162 163 164 165
		return ctx->funcs->lookup_buddy(ctx,key);
	return -1;
}

BuddyLookupStatus sip_setup_context_get_buddy_lookup_status(SipSetupContext *ctx){
	if (ctx->funcs->get_buddy_lookup_status)
		return ctx->funcs->get_buddy_lookup_status(ctx);
	return BuddyLookupFailure;
}

int sip_setup_context_get_buddy_lookup_results(SipSetupContext *ctx, MSList **results /*of BuddyInfo */){
	if (ctx->funcs->get_buddy_lookup_results)
		return ctx->funcs->get_buddy_lookup_results(ctx,results);
smorlat's avatar
smorlat committed
166 167 168
	return -1;
}

169 170 171 172 173
void sip_setup_context_free_results(MSList *results){
	ms_list_for_each(results,(void (*)(void*))&ms_free);
	ms_list_free(results);
}

smorlat's avatar
smorlat committed
174
void sip_setup_context_free(SipSetupContext *ctx){
smorlat's avatar
smorlat committed
175 176 177
	if (ctx->funcs->uninit_instance){
		ctx->funcs->uninit_instance(ctx);
	}
smorlat's avatar
smorlat committed
178 179
	ms_free(ctx);
}