1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU Library General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #include "contact_providers_priv.h"
18 #include "linphone/contactprovider.h"
19 #include <linphone/core.h>
20 
21 /* ############################ *
22  * LinphoneContactSearchRequest *
23  * ############################ */
24 
linphone_contact_search_init(LinphoneContactSearch * obj,const char * predicate,ContactSearchCallback cb,void * cb_data)25 void linphone_contact_search_init(LinphoneContactSearch* obj,
26 								const char* predicate,
27 								ContactSearchCallback cb,
28 								void* cb_data)
29 {
30 	static unsigned int request_id_counter = 1;
31 	obj->id = request_id_counter++; // unique id
32 	obj->predicate = ms_strdup(predicate?predicate:"");
33 	obj->cb   = cb;
34 	obj->data = cb_data;
35 }
36 
linphone_contact_search_destroy(LinphoneContactSearch * req)37 static void linphone_contact_search_destroy( LinphoneContactSearch* req) {
38 	if( req->predicate ) ms_free(req->predicate);
39 }
40 
linphone_contact_search_get_id(LinphoneContactSearch * obj)41 LinphoneContactSearchID linphone_contact_search_get_id(LinphoneContactSearch* obj)
42 {
43 	return obj->id;
44 }
45 
linphone_contact_search_get_predicate(LinphoneContactSearch * obj)46 const char*linphone_contact_search_get_predicate(LinphoneContactSearch* obj)
47 {
48 	return obj->predicate;
49 }
50 
linphone_contact_search_invoke_cb(LinphoneContactSearch * req,MSList * friends)51 void linphone_contact_search_invoke_cb(LinphoneContactSearch* req, MSList* friends)
52 {
53 	if( req->cb ) req->cb(req, friends, req->data);
54 }
55 
linphone_contact_search_compare(const void * a,const void * b)56 int linphone_contact_search_compare(const void* a, const void* b) {
57 	LinphoneContactSearch *ra=((LinphoneContactSearch*)a);
58 	LinphoneContactSearch *rb=((LinphoneContactSearch*)b);
59 	return !(ra->id == rb->id); // return 0 if id is equal, 1 otherwise
60 }
61 
linphone_contact_search_ref(void * obj)62 LinphoneContactSearch*linphone_contact_search_ref(void* obj)
63 {
64 	return LINPHONE_CONTACT_SEARCH(belle_sip_object_ref(obj));
65 }
66 
linphone_ldap_contact_search_unref(void * obj)67 void linphone_ldap_contact_search_unref(void* obj)
68 {
69 	belle_sip_object_unref(obj);
70 }
71 
linphone_contact_search_cast(void * obj)72 LinphoneContactSearch* linphone_contact_search_cast(void* obj)
73 {
74 	return LINPHONE_CONTACT_SEARCH(obj);
75 }
76 
77 BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactSearch);
78 
79 BELLE_SIP_INSTANCIATE_VPTR(LinphoneContactSearch,belle_sip_object_t,
80 	(belle_sip_object_destroy_t)linphone_contact_search_destroy,
81 	NULL, // clone
82 	NULL, // marshal
83 	FALSE
84 );
85 
86 
87 
88 /* ####################### *
89  * LinphoneContactProvider *
90  * ####################### */
91 
92 
linphone_contact_provider_init(LinphoneContactProvider * obj,LinphoneCore * lc)93 void linphone_contact_provider_init(LinphoneContactProvider* obj, LinphoneCore* lc){
94 	obj->lc = lc;
95 }
96 
contact_provider_destroy(LinphoneContactProvider * obj)97 static void contact_provider_destroy(LinphoneContactProvider* obj){
98 	(void)obj;
99 }
100 
linphone_contact_provider_begin_search(LinphoneContactProvider * obj,const char * predicate,ContactSearchCallback cb,void * data)101 LinphoneContactSearch* linphone_contact_provider_begin_search(LinphoneContactProvider* obj, const char* predicate, ContactSearchCallback cb, void* data)
102 {
103 	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->begin_search( LINPHONE_CONTACT_PROVIDER(obj), predicate, cb, data);
104 }
105 
linphone_contact_provider_cancel_search(LinphoneContactProvider * obj,LinphoneContactSearch * request)106 unsigned int linphone_contact_provider_cancel_search(LinphoneContactProvider* obj, LinphoneContactSearch* request)
107 {
108 	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->cancel_search( LINPHONE_CONTACT_PROVIDER(obj), request);
109 }
110 
linphone_contact_provider_ref(void * obj)111 LinphoneContactProvider* linphone_contact_provider_ref(void* obj)
112 {
113 	return LINPHONE_CONTACT_PROVIDER(belle_sip_object_ref(obj));
114 }
115 
linphone_contact_provider_unref(void * obj)116 void linphone_contact_provider_unref(void* obj)
117 {
118 	belle_sip_object_unref(obj);
119 }
120 
linphone_contact_provider_cast(void * obj)121 LinphoneContactProvider*linphone_contact_provider_cast(void* obj)
122 {
123 	return LINPHONE_CONTACT_PROVIDER(obj);
124 }
125 
126 BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactProvider);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider)127 BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider)
128 	{
129 		BELLE_SIP_VPTR_INIT(LinphoneContactProvider,belle_sip_object_t,TRUE),
130 		(belle_sip_object_destroy_t) contact_provider_destroy,
131 		NULL,/*no clone*/
132 		NULL,/*no marshal*/
133 		BELLE_SIP_DEFAULT_BUFSIZE_HINT
134 	},
135 	"",
136 	// Pure virtual
137 	NULL, /* begin_search -> pure virtual */
138 	NULL  /* cancel_search -> pure virtual */
139 BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END
140