Commit e37cb37f authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Moved contact provider internals to a private header.

I also added lots of methods to manipulate Contact Providers
parent 08a7bf3b
/*
* 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.
*/
#ifndef CONTACT_PROVIDERS_PRIV_H
#define CONTACT_PROVIDERS_PRIV_H
#include <belle-sip/object.h>
#include "linphonecore.h"
/* Base for contact search and contact provider */
struct _LinphoneContactSearch{
belle_sip_object_t base;
ContactSearchID id;
char* predicate;
ContactSearchCallback cb;
void* data;
};
#define LINPHONE_CONTACT_SEARCH(obj) BELLE_SIP_CAST(obj,LinphoneContactSearch)
BELLE_SIP_DECLARE_VPTR(LinphoneContactSearch)
struct _LinphoneContactProvider {
belle_sip_object_t base;
LinphoneCore* lc;
};
#define LINPHONE_CONTACT_PROVIDER(obj) BELLE_SIP_CAST(obj,LinphoneContactProvider)
typedef LinphoneContactSearch* (*LinphoneContactProviderStartSearchMethod)( LinphoneContactProvider* thiz, const char* predicate, ContactSearchCallback cb, void* data );
typedef unsigned int (*LinphoneContactProviderCancelSearchMethod)( LinphoneContactProvider* thiz, LinphoneContactSearch *request );
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider,belle_sip_object_t)
const char* name; /*!< Name of the contact provider (LDAP, Google, ...) */
/* pure virtual methods: inheriting objects must implement these */
LinphoneContactProviderStartSearchMethod begin_search;
LinphoneContactProviderCancelSearchMethod cancel_search;
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
/* LDAP search and contact providers */
#define LINPHONE_LDAP_CONTACT_SEARCH(obj) BELLE_SIP_CAST(obj,LinphoneLDAPContactSearch)
BELLE_SIP_DECLARE_VPTR(LinphoneLDAPContactSearch)
#define LINPHONE_LDAP_CONTACT_PROVIDER(obj) BELLE_SIP_CAST(obj,LinphoneLDAPContactProvider)
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(LinphoneLDAPContactProvider,LinphoneContactProvider)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#endif // CONTACT_PROVIDERS_PRIV_H
......@@ -14,11 +14,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "contact_providers_priv.h"
#include "contactprovider.h"
#include <linphonecore.h>
/* LinphoneContactSearchRequest
*/
/* ############################ *
* LinphoneContactSearchRequest *
* ############################ */
void linphone_contact_search_init(LinphoneContactSearch* obj,
const char* predicate,
......@@ -57,6 +59,21 @@ int linphone_contact_search_compare(const void* a, const void* b) {
return !(ra->id == rb->id); // return 0 if id is equal, 1 otherwise
}
LinphoneContactSearch*linphone_ldap_contact_search_ref(void* obj)
{
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);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactSearch);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneContactSearch,belle_sip_object_t,
......@@ -66,9 +83,11 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneContactSearch,belle_sip_object_t,
FALSE
);
/*
* LinphoneContactProvider
*/
/* ####################### *
* LinphoneContactProvider *
* ####################### */
void linphone_contact_provider_init(LinphoneContactProvider* obj, LinphoneCore* lc){
......@@ -79,6 +98,30 @@ static void contact_provider_destroy(LinphoneContactProvider* obj){
(void)obj;
}
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);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactProvider);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(LinphoneContactProvider)=
......@@ -95,4 +138,3 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(LinphoneContactProvider)=
NULL /* cancel_search -> pure virtual */
};
......@@ -14,50 +14,30 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <belle-sip/object.h>
#include "linphonecore.h"
/* LinphoneContactSearchRequest */
struct _LinphoneContactSearch{
belle_sip_object_t base;
ContactSearchID id;
char* predicate;
ContactSearchCallback cb;
void* data;
};
#define LINPHONE_CONTACT_SEARCH(obj) BELLE_SIP_CAST(obj,LinphoneContactSearch)
BELLE_SIP_DECLARE_VPTR(LinphoneContactSearch)
void linphone_contact_search_init(LinphoneContactSearch* obj, const char* predicate, ContactSearchCallback cb, void* cb_data);
ContactSearchID linphone_contact_search_get_id(LinphoneContactSearch* obj);
const char* linphone_contact_search_get_predicate(LinphoneContactSearch* obj);
void linphone_contact_search_invoke_cb(LinphoneContactSearch* req, MSList* friends);
LinphoneContactSearch* linphone_contact_search_ref(void* obj);
void linphone_contact_search_unref(void* obj);
LinphoneContactSearch* linphone_contact_search_cast( void*obj );
/* LinphoneContactProvider */
struct _LinphoneContactProvider {
belle_sip_object_t base;
LinphoneCore* lc;
};
typedef struct _LinphoneContactProvider LinphoneContactProvider;
typedef LinphoneContactSearch* (*LinphoneContactProviderStartSearchMethod)( LinphoneContactProvider* thiz, const char* predicate, ContactSearchCallback cb, void* data );
typedef unsigned int (*LinphoneContactProviderCancelSearchMethod)( LinphoneContactProvider* thiz, LinphoneContactSearch *request );
#define LINPHONE_CONTACT_PROVIDER(obj) BELLE_SIP_CAST(obj,LinphoneContactProvider)
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider,belle_sip_object_t)
const char* name; /*!< Name of the contact provider (LDAP, Google, ...) */
/* pure virtual methods: inheriting objects must implement these */
LinphoneContactProviderStartSearchMethod begin_search;
LinphoneContactProviderCancelSearchMethod cancel_search;
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
void linphone_contact_provider_init(LinphoneContactProvider* obj, LinphoneCore* lc);
LinphoneCore* linphone_contact_provider_get_core(LinphoneContactProvider* obj);
const char* linphone_contact_provider_get_name(LinphoneContactProvider* obj);
LinphoneContactProvider* linphone_contact_provider_ref(void* obj);
void linphone_contact_provider_unref(void* obj);
LinphoneContactProvider* linphone_contact_provider_cast( void*obj );
LinphoneContactSearch* linphone_contact_provider_begin_search(LinphoneContactProvider* obj,
const char* predicate,
ContactSearchCallback cb,
void* data);
unsigned int linphone_contact_provider_cancel_search(LinphoneContactProvider* obj,
LinphoneContactSearch* request);
......@@ -18,6 +18,7 @@
#include "linphonecore.h"
#include "linphonecore_utils.h"
#include "lpconfig.h"
#include "contact_providers_priv.h"
#include <belle-sip/dict.h>
#include <ldap.h>
......@@ -571,7 +572,7 @@ static int linphone_ldap_contact_provider_bind( LinphoneLDAPContactProvider* obj
} else {
int err;
ldap_get_option(obj->ld, LDAP_OPT_RESULT_CODE, &err);
ms_error("ldap_sasl_bind error returned %d, err %d (%s), auth_method: %s",
ms_error("ldap_sasl_bind error returned %x, err %x (%s), auth_method: %s",
ret, err, ldap_err2string(err), auth_mechanism );
}
......@@ -616,6 +617,10 @@ LinphoneLDAPContactProvider*linphone_ldap_contact_provider_create(LinphoneCore*
belle_sip_object_unref(obj);
obj = NULL;
} else {
// prevents blocking calls to bind() when the server is invalid, but this is not working for now..
// see bug https://bugzilla.mozilla.org/show_bug.cgi?id=79509
ldap_set_option( obj->ld, LDAP_OPT_CONNECT_ASYNC, LDAP_OPT_ON);
// register our hook into iterate so that LDAP can do its magic asynchronously.
linphone_core_add_iterate_hook(lc, linphone_ldap_contact_provider_iterate, obj);
}
......@@ -740,6 +745,27 @@ static int linphone_ldap_contact_provider_marshal(LinphoneLDAPContactProvider* o
}
LinphoneLDAPContactProvider*linphone_ldap_contact_provider_ref(void* obj)
{
return linphone_ldap_contact_provider_cast(belle_sip_object_ref(obj));
}
void linphone_ldap_contact_provider_unref(void* obj)
{
belle_sip_object_unref(obj);
}
inline LinphoneLDAPContactSearch*linphone_ldap_contact_search_cast(void* obj)
{
return BELLE_SIP_CAST(obj, LinphoneLDAPContactSearch);
}
LinphoneLDAPContactProvider* linphone_ldap_contact_provider_cast(void* obj)
{
return BELLE_SIP_CAST(obj, LinphoneLDAPContactProvider);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneLDAPContactProvider);
......@@ -758,3 +784,4 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(LinphoneLDAPContactProvider)=
}
};
......@@ -16,30 +16,25 @@
#include "contactprovider.h"
#include <ldap.h>
typedef struct _LinphoneLDAPContactProvider LinphoneLDAPContactProvider;
/* LinphoneLDAPContactSearch */
typedef struct _LinphoneLDAPContactSearch LinphoneLDAPContactSearch;
#define LINPHONE_LDAP_CONTACT_SEARCH(obj) BELLE_SIP_CAST(obj,LinphoneLDAPContactSearch)
BELLE_SIP_DECLARE_VPTR(LinphoneLDAPContactSearch)
LinphoneLDAPContactSearch* linphone_ldap_contact_search_create(LinphoneLDAPContactProvider* ld,
const char* predicate,
ContactSearchCallback cb,
void* cb_data);
unsigned int linphone_ldap_contact_search_result_count(LinphoneLDAPContactSearch* obj);
LinphoneLDAPContactSearch* linphone_ldap_contact_search_cast( void* obj );
/* LinphoneLDAPContactProvider */
#define LINPHONE_LDAP_CONTACT_PROVIDER(obj) BELLE_SIP_CAST(obj,LinphoneLDAPContactProvider)
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(LinphoneLDAPContactProvider,LinphoneContactProvider)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
LinphoneLDAPContactProvider* linphone_ldap_contact_provider_create(LinphoneCore* lc, const LinphoneDictionary* config);
unsigned int linphone_ldap_contact_provider_get_max_result(const LinphoneLDAPContactProvider* obj);
unsigned int linphone_ldap_contact_provider_get_max_result(const LinphoneLDAPContactProvider* obj);
LinphoneLDAPContactProvider* linphone_ldap_contact_provider_ref( void* obj );
void linphone_ldap_contact_provider_unref( void* obj );
LinphoneLDAPContactProvider* linphone_ldap_contact_provider_cast( void* obj );
......@@ -5677,13 +5677,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
}
#endif //BUILD_UPNP
#ifdef BUILD_LDAP
if( lc->ldap != NULL ) {
belle_sip_object_unref(lc->ldap);
lc->ldap = NULL;
}
#endif
if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
lp_config_destroy(lc->config);
lc->config = NULL; /* Mark the config as NULL to block further calls */
......
......@@ -2203,8 +2203,9 @@ LINPHONE_PUBLIC const char *linphone_core_get_video_display_filter(LinphoneCore
LINPHONE_PUBLIC void linphone_core_set_video_display_filter(LinphoneCore *lc, const char *filtername);
/** Contact Providers
/** Belle Sip-based objects need unique ids
*/
BELLE_SIP_DECLARE_TYPES_BEGIN(linphone,10000)
BELLE_SIP_TYPE_ID(LinphoneContactSearch),
BELLE_SIP_TYPE_ID(LinphoneContactProvider),
......@@ -2212,10 +2213,14 @@ BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch)
BELLE_SIP_DECLARE_TYPES_END
/** Contact Providers
*/
typedef unsigned int ContactSearchID;
struct _LinphoneContactSearch;
typedef struct _LinphoneContactSearch LinphoneContactSearch;
typedef struct _LinphoneContactProvider LinphoneContactProvider;
typedef void (*ContactSearchCallback)( LinphoneContactSearch* id, MSList* friends, void* data );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment