contactprovider.c 4.1 KB
Newer Older
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *  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 Library 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.
 */

Ghislain MARY's avatar
Ghislain MARY committed
17
#include "linphone/contactprovider.h"
18 19 20
#include "linphone/core.h"

#include "contact_providers_priv.h"
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
21

22 23 24
/* ############################ *
 * LinphoneContactSearchRequest *
 * ############################ */
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
25

26 27 28 29
void linphone_contact_search_init(LinphoneContactSearch* obj,
								const char* predicate,
								ContactSearchCallback cb,
								void* cb_data)
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
30
{
31 32 33 34 35 36 37 38 39
	static unsigned int request_id_counter = 1;
	obj->id = request_id_counter++; // unique id
	obj->predicate = ms_strdup(predicate?predicate:"");
	obj->cb   = cb;
	obj->data = cb_data;
}

static void linphone_contact_search_destroy( LinphoneContactSearch* req) {
	if( req->predicate ) ms_free(req->predicate);
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
40 41
}

42
LinphoneContactSearchID linphone_contact_search_get_id(LinphoneContactSearch* obj)
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
43
{
44 45
	return obj->id;
}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
46

47 48 49
const char*linphone_contact_search_get_predicate(LinphoneContactSearch* obj)
{
	return obj->predicate;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
50 51
}

52 53
void linphone_contact_search_invoke_cb(LinphoneContactSearch* req, MSList* friends)
{
54
	if( req->cb ) req->cb(req, friends, req->data);
55 56 57 58 59 60 61 62
}

int linphone_contact_search_compare(const void* a, const void* b) {
	LinphoneContactSearch *ra=((LinphoneContactSearch*)a);
	LinphoneContactSearch *rb=((LinphoneContactSearch*)b);
	return !(ra->id == rb->id); // return 0 if id is equal, 1 otherwise
}

63
LinphoneContactSearch*linphone_contact_search_ref(void* obj)
64 65 66 67 68 69 70 71 72 73 74 75 76 77
{
	return LINPHONE_CONTACT_SEARCH(belle_sip_object_ref(obj));
}

void linphone_ldap_contact_search_unref(void* obj)
{
	belle_sip_object_unref(obj);
}

LinphoneContactSearch* linphone_contact_search_cast(void* obj)
{
	return LINPHONE_CONTACT_SEARCH(obj);
}

78 79 80 81 82 83 84 85 86
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactSearch);

BELLE_SIP_INSTANCIATE_VPTR(LinphoneContactSearch,belle_sip_object_t,
	(belle_sip_object_destroy_t)linphone_contact_search_destroy,
	NULL, // clone
	NULL, // marshal
	FALSE
);

87 88 89 90 91


/* ####################### *
 * LinphoneContactProvider *
 * ####################### */
92 93 94 95 96 97 98 99 100 101


void linphone_contact_provider_init(LinphoneContactProvider* obj, LinphoneCore* lc){
	obj->lc = lc;
}

static void contact_provider_destroy(LinphoneContactProvider* obj){
	(void)obj;
}

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
LinphoneContactSearch* linphone_contact_provider_begin_search(LinphoneContactProvider* obj, const char* predicate, ContactSearchCallback cb, void* data)
{
	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->begin_search( LINPHONE_CONTACT_PROVIDER(obj), predicate, cb, data);
}

unsigned int linphone_contact_provider_cancel_search(LinphoneContactProvider* obj, LinphoneContactSearch* request)
{
	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->cancel_search( LINPHONE_CONTACT_PROVIDER(obj), request);
}

LinphoneContactProvider* linphone_contact_provider_ref(void* obj)
{
	return LINPHONE_CONTACT_PROVIDER(belle_sip_object_ref(obj));
}

void linphone_contact_provider_unref(void* obj)
{
	belle_sip_object_unref(obj);
}

LinphoneContactProvider*linphone_contact_provider_cast(void* obj)
{
	return LINPHONE_CONTACT_PROVIDER(obj);
}
126 127

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactProvider);
128
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider)
129 130 131 132 133
	{
		BELLE_SIP_VPTR_INIT(LinphoneContactProvider,belle_sip_object_t,TRUE),
		(belle_sip_object_destroy_t) contact_provider_destroy,
		NULL,/*no clone*/
		NULL,/*no marshal*/
134
		BELLE_SIP_DEFAULT_BUFSIZE_HINT
135 136 137 138 139
	},
	"",
	// Pure virtual
	NULL, /* begin_search -> pure virtual */
	NULL  /* cancel_search -> pure virtual */
140
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END