/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2003 Match Grun
+ * Copyright (C) 2001-2007 Match Grun and the Claws Mail team
*
* 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
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
/*
#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
-#include "intl.h"
#include "mgutils.h"
#include "addritem.h"
#include "addrcache.h"
#include "addrbook.h"
+#include "addressbook.h"
#include "addrindex.h"
#include "xml.h"
#include "addrquery.h"
+#include "addr_compl.h"
+#include "utils.h"
+#include "alertpanel.h"
#ifndef DEV_STANDALONE
#include "prefs_gtk.h"
#include "ldapserver.h"
#include "ldapctrl.h"
#include "ldapquery.h"
+#include "ldapupdate.h"
+#include "ldaputil.h"
#endif
#define TAG_ADDRESS_INDEX "addressbook"
#define ATTAG_LDAP_TIMEOUT "timeout"
#define ATTAG_LDAP_MAX_AGE "max-age"
#define ATTAG_LDAP_DYN_SEARCH "dyn-search"
+#define ATTAG_LDAP_MATCH_OPT "match-opt"
+#define ATTAG_LDAP_ENABLE_TLS "enable-tls"
+#define ATTAG_LDAP_ENABLE_SSL "enable-ssl"
#define ELTAG_LDAP_ATTR_SRCH "attribute"
#define ATTAG_LDAP_ATTR_NAME "name"
+/* Attribute values */
+#define ATVAL_BOOLEAN_YES "yes"
+#define ATVAL_BOOLEAN_NO "no"
+#define ATVAL_LDAP_MATCH_BEGIN "begin-with"
+#define ATVAL_LDAP_MATCH_CONTAINS "contains"
+
/* New attributes */
#define ATTAG_LDAP_DEFAULT "default"
-#if 0
-N_("Common address")
-N_("Personal address")
-#endif
-
-#define DISP_NEW_COMMON _("Common address")
-#define DISP_NEW_PERSONAL _("Personal address")
+#define DISP_NEW_COMMON _("Common addresses")
+#define DISP_NEW_PERSONAL _("Personal addresses")
/* Old address book */
#define TAG_IF_OLD_COMMON "common_address"
#define DISP_OLD_COMMON _("Common address")
#define DISP_OLD_PERSONAL _("Personal address")
+/**
+ * Singleton object.
+ */
+static AddressIndex *_addressIndex_ = NULL;
+
/*
* Define attribute name-value pair.
*/
gchar *value;
};
+static AddressDataSource *addrindex_create_datasource ( AddressIfType ifType );
+
+static GList *addrindex_ds_get_all_persons ( AddressDataSource *ds );
+static GList *addrindex_ds_get_all_groups ( AddressDataSource *ds );
+static AddressDataSource *addrindex_get_datasource ( AddressIndex *addrIndex,
+ const gchar *cacheID );
+static AddressInterface *addrindex_get_interface ( AddressIndex *addrIndex,
+ AddressIfType ifType );
+static gint addrindex_write_to ( AddressIndex *addrIndex,
+ const gchar *newFile );
+
/*
* Define DOM fragment.
*/
iface->getListFolder = ( void * ) addrbook_get_list_folder;
iface->getListPerson = ( void * ) addrbook_get_list_person;
iface->getAllPersons = ( void * ) addrbook_get_all_persons;
+ iface->getAllGroups = ( void * ) addrbook_get_all_groups;
iface->getName = ( void * ) addrbook_get_name;
iface->setAccessFlag = ( void * ) addrbook_set_accessed;
- iface->searchOrder = 2;
+ iface->searchOrder = 0;
/* Add to list of interfaces in address book */
addrIndex->interfaceList =
iface->getAllPersons = ( void * ) vcard_get_all_persons;
iface->getName = ( void * ) vcard_get_name;
iface->setAccessFlag = ( void * ) vcard_set_accessed;
- iface->searchOrder = 3;
+ iface->searchOrder = 0;
addrIndex->interfaceList =
g_list_append( addrIndex->interfaceList, iface );
ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex);
iface->getAllPersons = ( void * ) jpilot_get_all_persons;
iface->getName = ( void * ) jpilot_get_name;
iface->setAccessFlag = ( void * ) jpilot_set_accessed;
- iface->searchOrder = 3;
+ iface->searchOrder = 0;
#else
iface->useInterface = FALSE;
iface->haveLibrary = FALSE;
iface = addrindex_create_interface(
ADDR_IF_LDAP, "LDAP", TAG_IF_LDAP, TAG_DS_LDAP );
#ifdef USE_LDAP
+ iface->readOnly = FALSE;
/* iface->haveLibrary = ldapsvr_test_ldap_lib(); */
iface->haveLibrary = ldaputil_test_ldap_lib();
iface->useInterface = iface->haveLibrary;
- /* iface->getModifyFlag = ( void * ) ldapsvr_get_modified; */
+ iface->getModifyFlag = ( void * ) ldapsvr_get_modified;
iface->getAccessFlag = ( void * ) ldapsvr_get_accessed;
- /* iface->getReadFlag = ( void * ) ldapsvr_get_read_flag; */
+ iface->getReadFlag = ( void * ) ldapsvr_get_read_flag;
iface->getStatusCode = ( void * ) ldapsvr_get_status;
- /* iface->getReadData = ( void * ) ldapsvr_read_data; */
+ iface->getReadData = ( void * ) ldapsvr_read_data;
iface->getRootFolder = ( void * ) ldapsvr_get_root_folder;
iface->getListFolder = ( void * ) ldapsvr_get_list_folder;
iface->getListPerson = ( void * ) ldapsvr_get_list_person;
* Free DOM fragment.
* \param fragment Fragment to free.
*/
-static addrindex_free_fragment( AddressIfFragment *fragment ) {
+static void addrindex_free_fragment( AddressIfFragment *fragment ) {
GList *node;
/* Free children */
*/
void addrindex_free_datasource( AddressDataSource *ds ) {
AddressInterface *iface;
- AddressCache *cache;
g_return_if_fail( ds != NULL );
#ifdef USE_LDAP
else if( iface->type == ADDR_IF_LDAP ) {
LdapServer *server = ds->rawDataSource;
- cache = server->addressCache;
- addrcache_use_index( cache, FALSE );
ldapsvr_free( server );
}
#endif
* \param cacheID ID.
* \return Data source, or NULL if not found.
*/
-AddressDataSource *addrindex_get_datasource(
+static AddressDataSource *addrindex_get_datasource(
AddressIndex *addrIndex, const gchar *cacheID )
{
g_return_val_if_fail( addrIndex != NULL, NULL );
* Free hash table of address cache items.
*/
static void addrindex_free_cache_hash( GHashTable *table ) {
- g_hash_table_freeze( table );
g_hash_table_foreach_remove( table, addrindex_free_cache_cb, NULL );
- g_hash_table_thaw( table );
g_hash_table_destroy( table );
}
-/*
+/**
* Remove data source from internal hashtable.
* \param addrIndex Address index.
* \param ds Data source to remove.
}
}
-/*
- * Create a new address index.
+/**
+ * Create a new address index. This is created as a singleton object.
* \return Initialized address index object.
*/
AddressIndex *addrindex_create_index( void ) {
- AddressIndex *addrIndex = g_new0( AddressIndex, 1 );
-
- ADDRITEM_TYPE(addrIndex) = ITEMTYPE_INDEX;
- ADDRITEM_ID(addrIndex) = NULL;
- ADDRITEM_NAME(addrIndex) = g_strdup( "Address Index" );
- ADDRITEM_PARENT(addrIndex) = NULL;
- ADDRITEM_SUBTYPE(addrIndex) = 0;
- addrIndex->filePath = NULL;
- addrIndex->fileName = NULL;
- addrIndex->retVal = MGU_SUCCESS;
- addrIndex->needsConversion = FALSE;
- addrIndex->wasConverted = FALSE;
- addrIndex->conversionError = FALSE;
- addrIndex->interfaceList = NULL;
- addrIndex->lastType = ADDR_IF_NONE;
- addrIndex->dirtyFlag = FALSE;
- addrIndex->hashCache = g_hash_table_new( g_str_hash, g_str_equal );
- addrIndex->loadedFlag = FALSE;
- addrIndex->searchOrder = NULL;
- addrindex_build_if_list( addrIndex );
- return addrIndex;
+ AddressIndex *index;
+
+ if( _addressIndex_ == NULL ) {
+ index = g_new0( AddressIndex, 1 );
+ ADDRITEM_TYPE(index) = ITEMTYPE_INDEX;
+ ADDRITEM_ID(index) = NULL;
+ ADDRITEM_NAME(index) = g_strdup( "Address Index" );
+ ADDRITEM_PARENT(index) = NULL;
+ ADDRITEM_SUBTYPE(index) = 0;
+ index->filePath = NULL;
+ index->fileName = NULL;
+ index->retVal = MGU_SUCCESS;
+ index->needsConversion = FALSE;
+ index->wasConverted = FALSE;
+ index->conversionError = FALSE;
+ index->interfaceList = NULL;
+ index->lastType = ADDR_IF_NONE;
+ index->dirtyFlag = FALSE;
+ index->hashCache = g_hash_table_new( g_str_hash, g_str_equal );
+ index->loadedFlag = FALSE;
+ index->searchOrder = NULL;
+ addrindex_build_if_list( index );
+ _addressIndex_ = index;
+ }
+ return _addressIndex_;
}
/**
addrIndex->fileName = mgu_replace_string( addrIndex->fileName, value );
}
-/**
- * Property - Specify file path to be used.
- * \param addrIndex Address index.
- * \param value Path to JPilot file.
- */
-void addrindex_set_dirty( AddressIndex *addrIndex, const gboolean value ) {
- g_return_if_fail( addrIndex != NULL );
- addrIndex->dirtyFlag = value;
-}
-
-/**
- * Property - get loaded flag. Note that this flag is set after reading data
- * from the address books.
- * \param addrIndex Address index.
- * \return <i>TRUE</i> if address index data was loaded.
- */
-gboolean addrindex_get_loaded( AddressIndex *addrIndex ) {
- g_return_val_if_fail( addrIndex != NULL, FALSE );
- return addrIndex->loadedFlag;
-}
-
/**
* Return list of address interfaces.
* \param addrIndex Address index.
/**
* Perform any other initialization of address index.
- * \param addrIndex Address index.
*/
-void addrindex_initialize( AddressIndex *addrIndex ) {
+void addrindex_initialize( void ) {
+ qrymgr_initialize();
addrcompl_initialize();
}
/**
* Perform any other teardown of address index.
- * \param addrIndex Address index.
*/
-void addrindex_teardown( AddressIndex *addrIndex ) {
+void addrindex_teardown( void ) {
addrcompl_teardown();
+ qrymgr_teardown();
}
/**
addrIndex->loadedFlag = FALSE;
g_free( addrIndex );
+ addrIndex = NULL;
+ _addressIndex_ = NULL;
}
/**
* \param ifType Interface type.
* \return Address interface, or NULL if not found.
*/
-AddressInterface *addrindex_get_interface(
+static AddressInterface *addrindex_get_interface(
AddressIndex *addrIndex, AddressIfType ifType )
{
AddressInterface *retVal = NULL;
* \param lvl Indentation level.
* \param name Element name.
*/
-static void addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) {
+static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) {
gint i;
- for( i = 0; i < lvl; i++ ) fputs( " ", fp );
- fputs( "<", fp );
- fputs( name, fp );
+ for( i = 0; i < lvl; i++ )
+ if (fputs( " ", fp ) == EOF)
+ return -1;
+ if (fputs( "<", fp ) == EOF)
+ return -1;
+ if (fputs( name, fp ) == EOF)
+ return -1;
+ return 0;
}
/**
* \param lvl Indentation level.
* \param name Element name.
*/
-static void addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) {
+static int addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) {
gint i;
- for( i = 0; i < lvl; i++ ) fputs( " ", fp );
- fputs( "</", fp );
- fputs( name, fp );
- fputs( ">\n", fp );
+ for( i = 0; i < lvl; i++ )
+ if (fputs( " ", fp ) == EOF)
+ return -1;
+ if (fputs( "</", fp ) == EOF)
+ return -1;
+ if (fputs( name, fp ) == EOF)
+ return -1;
+ if (fputs( ">\n", fp ) == EOF)
+ return -1;
+ return 0;
}
/**
* \param name Attribute name.
* \param value Attribute value.
*/
-static void addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value ) {
- fputs( " ", fp );
- fputs( name, fp );
- fputs( "=\"", fp );
- xml_file_put_escape_str( fp, value );
- fputs( "\"", fp );
+static int addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value ) {
+ if (fputs( " ", fp ) == EOF)
+ return -1;
+ if (fputs( name, fp ) == EOF)
+ return -1;
+ if (fputs( "=\"", fp ) == EOF)
+ return -1;
+ if (xml_file_put_escape_str( fp, value ) < 0)
+ return -1;
+ if (fputs( "\"", fp ) == EOF)
+ return -1;
+ return 0;
}
/**
guint prevLevel;
gint rc;
+ /* g_print( "addrindex_read_fragment\n" ); */
+
prevLevel = file->level;
/* Get current tag name */
* \param fragment DOM fragment for configuration element.
* \param lvl Indent level.
*/
-static void addrindex_write_fragment(
+static int addrindex_write_fragment(
FILE *fp, const AddressIfFragment *fragment, const gint lvl )
{
GList *node;
if( fragment ) {
- addrindex_write_elem_s( fp, lvl, fragment->name );
+ if (addrindex_write_elem_s( fp, lvl, fragment->name ) < 0)
+ return -1;
node = fragment->attributes;
while( node ) {
AddressIfAttrib *nv = node->data;
- addrindex_write_attr( fp, nv->name, nv->value );
+ if (addrindex_write_attr( fp, nv->name, nv->value ) < 0)
+ return -1;
node = g_list_next( node );
}
if( fragment->children ) {
- fputs(" >\n", fp);
+ if (fputs(" >\n", fp) == EOF)
+ return -1;
/* Output children */
node = fragment->children;
while( node ) {
AddressIfFragment *child = node->data;
- addrindex_write_fragment( fp, child, 1+lvl );
+ if (addrindex_write_fragment( fp, child, 1+lvl ) < 0)
+ return -1;
node = g_list_next( node );
}
/* Output closing tag */
- addrindex_write_elem_e( fp, lvl, fragment->name );
+ if (addrindex_write_elem_e( fp, lvl, fragment->name ) < 0)
+ return -1;
}
else {
- fputs(" />\n", fp);
+ if (fputs(" />\n", fp) == EOF)
+ return -1;
}
}
+
+ return 0;
}
-/*
-static void addrindex_print_fragment_r(
- const AddressIfFragment *fragment, FILE *stream, gint lvl )
-{
- GList *node;
- gint i;
-
- for( i = 0; i < lvl; i++ )
- fprintf( stream, " " );
- fprintf( stream, "Element:%s:\n", fragment->name );
- node = fragment->attributes;
- while( node ) {
- AddressIfAttrib *nv = node->data;
- for( i = 0; i < lvl; i++ )
- fprintf( stream, " " );
- fprintf( stream, " %s : %s\n", nv->name, nv->value );
- node = g_list_next( node );
- }
- node = fragment->children;
- while( node ) {
- AddressIfFragment *child = node->data;
- addrindex_print_fragment_r( child, stream, 1+lvl );
- node = g_list_next( node );
- }
-}
-
-static void addrindex_print_fragment( const AddressIfFragment *fragment, FILE *stream ) {
- addrindex_print_fragment_r( fragment, stream, 0 );
-}
-*/
-
/**
* Read/parse address index file, creating a data source for a regular
* intrinsic XML addressbook.
return ds;
}
-static void addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) {
AddressBookFile *abf = ds->rawDataSource;
if( abf ) {
- addrindex_write_elem_s( fp, lvl, TAG_DS_ADDRESS_BOOK );
- addrindex_write_attr( fp, ATTAG_BOOK_NAME, addrbook_get_name( abf ) );
- addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName );
- fputs( " />\n", fp );
+ if (addrindex_write_elem_s( fp, lvl, TAG_DS_ADDRESS_BOOK ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_BOOK_NAME, addrbook_get_name( abf ) ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName ) < 0)
+ return -1;
+ if (fputs( " />\n", fp ) == EOF)
+ return -1;
}
+ return 0;
}
static AddressDataSource *addrindex_parse_vcard( XMLFile *file ) {
return ds;
}
-static void addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) {
VCardFile *vcf = ds->rawDataSource;
if( vcf ) {
- addrindex_write_elem_s( fp, lvl, TAG_DS_VCARD );
- addrindex_write_attr( fp, ATTAG_VCARD_NAME, vcard_get_name( vcf ) );
- addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path );
- fputs( " />\n", fp );
+ if (addrindex_write_elem_s( fp, lvl, TAG_DS_VCARD ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_VCARD_NAME, vcard_get_name( vcf ) ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path ) < 0)
+ return -1;
+ if (fputs( " />\n", fp ) == EOF)
+ return -1;
}
+ return 0;
}
#ifdef USE_JPILOT
return ds;
}
-static void addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) {
JPilotFile *jpf = ds->rawDataSource;
if( jpf ) {
gint ind;
GList *node;
GList *customLbl = jpilot_get_custom_labels( jpf );
- addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT );
- addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpilot_get_name( jpf ) );
- addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path );
+ if (addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpilot_get_name( jpf ) ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path ) < 0)
+ return -1;
node = customLbl;
ind = 1;
while( node ) {
gchar name[256];
g_snprintf( name, sizeof(name), "%s%d",
ATTAG_JPILOT_CUSTOM, ind );
- addrindex_write_attr( fp, name, node->data );
+ if (addrindex_write_attr( fp, name, node->data ) < 0)
+ return -1;
ind++;
node = g_list_next( node );
}
- fputs( " />\n", fp );
+ if (fputs( " />\n", fp ) == EOF)
+ return -1;
}
+ return 0;
+}
+
+#else
+/*
+ * Just read/write DOM fragments (preserve data found in file).
+ */
+static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) {
+ AddressDataSource *ds;
+
+ ds = addrindex_create_datasource( ADDR_IF_JPILOT );
+ ds->rawDataSource = addrindex_read_fragment( file );
+ return ds;
}
+static int addrindex_write_jpilot( FILE *fp, AddressDataSource *ds, gint lvl ) {
+ AddressIfFragment *fragment = ds->rawDataSource;
+ if( fragment ) {
+ if (addrindex_write_fragment( fp, fragment, lvl ) < 0)
+ return -1;
+ }
+ return 0;
+}
#endif
#ifdef USE_LDAP
}
+void ldapsvr_set_control( LdapServer *server, LdapControl *ctl );
+/**
+ * Parse LDAP control data from XML file.
+ * \param file Index file.
+ * \return Initialized data soruce object.
+ */
static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
AddressDataSource *ds;
LdapServer *server;
GList *attr;
gchar *serverName = NULL;
gchar *criteria = NULL;
- gboolean bSearch = FALSE;
- gboolean cvtFlag = TRUE;
+ gboolean bDynSearch;
+ gboolean bTLS, bSSL;
+ gint iMatch;
+
+ /* g_print( "addrindex_parse_ldap\n" ); */
+ /* Set up some defaults */
+ bDynSearch = FALSE;
+ bTLS = FALSE;
+ bSSL = FALSE;
+ iMatch = LDAPCTL_MATCH_BEGINWITH;
ds = addrindex_create_datasource( ADDR_IF_LDAP );
ctl = ldapctl_create();
gint ivalue = atoi( value );
if( strcmp( name, ATTAG_LDAP_NAME ) == 0 ) {
- if( serverName ) g_free( serverName );
+ g_free( serverName );
serverName = g_strdup( value );
}
else if( strcmp( name, ATTAG_LDAP_HOST ) == 0 ) {
ldapctl_set_bind_password( ctl, value );
}
else if( strcmp( name, ATTAG_LDAP_CRITERIA ) == 0 ) {
- if( criteria ) g_free( criteria );
+ g_free( criteria );
criteria = g_strdup( value );
+ g_print("criteria %s\n", criteria);
}
else if( strcmp( name, ATTAG_LDAP_MAX_ENTRY ) == 0 ) {
ldapctl_set_max_entries( ctl, ivalue );
ldapctl_set_max_query_age( ctl, ivalue );
}
else if( strcmp( name, ATTAG_LDAP_DYN_SEARCH ) == 0 ) {
- bSearch = FALSE;
- cvtFlag = FALSE;
- if( strcmp( value, "yes" ) == 0 ) {
- bSearch = TRUE;
+ bDynSearch = FALSE;
+ if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) {
+ bDynSearch = TRUE;
+ }
+ }
+ else if( strcmp( name, ATTAG_LDAP_MATCH_OPT ) == 0 ) {
+ iMatch = LDAPCTL_MATCH_BEGINWITH;
+ if( strcmp( value, ATVAL_LDAP_MATCH_CONTAINS ) == 0 ) {
+ iMatch = LDAPCTL_MATCH_CONTAINS;
+ }
+ }
+ else if( strcmp( name, ATTAG_LDAP_ENABLE_TLS ) == 0 ) {
+ bTLS = FALSE;
+ if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) {
+ bTLS = TRUE;
+ }
+ }
+ else if( strcmp( name, ATTAG_LDAP_ENABLE_SSL ) == 0 ) {
+ bSSL = FALSE;
+ if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) {
+ bSSL = TRUE;
}
}
attr = g_list_next( attr );
server = ldapsvr_create_noctl();
ldapsvr_set_name( server, serverName );
- ldapsvr_set_search_flag( server, bSearch );
+ ldapsvr_set_search_flag( server, bDynSearch );
+ ldapctl_set_matching_option( ctl, iMatch );
+#ifdef USE_LDAP_TLS
+ ldapctl_set_tls( ctl, bTLS );
+ ldapctl_set_ssl( ctl, bSSL );
+#endif
g_free( serverName );
ldapsvr_set_control( server, ctl );
ds->rawDataSource = server;
}
g_free( criteria );
}
- /*
- * If no search flag was found, then we are converting from old format
- * server data to new format.
- */
- if( cvtFlag ) {
- ldapsvr_set_search_flag( server, TRUE );
- }
/* ldapsvr_print_data( server, stdout ); */
return ds;
}
-static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
LdapServer *server = ds->rawDataSource;
LdapControl *ctl = NULL;
GList *node;
if( server ) {
ctl = server->control;
}
- if( ctl == NULL ) return;
+ if( ctl == NULL ) return 0;
/* Output start element with attributes */
- addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP );
- addrindex_write_attr( fp, ATTAG_LDAP_NAME, ldapsvr_get_name( server ) );
- addrindex_write_attr( fp, ATTAG_LDAP_HOST, ctl->hostName );
+ if (addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_NAME, ldapsvr_get_name( server ) ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_HOST, ctl->hostName ) < 0)
+ return -1;
sprintf( value, "%d", ctl->port );
- addrindex_write_attr( fp, ATTAG_LDAP_PORT, value );
+ if (addrindex_write_attr( fp, ATTAG_LDAP_PORT, value ) < 0)
+ return -1;
- addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, ctl->baseDN );
- addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN );
- addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, ctl->bindPass );
+ if (addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, ctl->baseDN ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, ctl->bindPass ) < 0)
+ return -1;
sprintf( value, "%d", ctl->maxEntries );
- addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value );
+ if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value ) < 0)
+ return -1;
sprintf( value, "%d", ctl->timeOut );
- addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value );
+ if (addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value ) < 0)
+ return -1;
sprintf( value, "%d", ctl->maxQueryAge );
- addrindex_write_attr( fp, ATTAG_LDAP_MAX_AGE, value );
-
- addrindex_write_attr( fp, ATTAG_LDAP_DYN_SEARCH,
- server->searchFlag ? "yes" : "no" );
-
- fputs(" >\n", fp);
+ if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_AGE, value ) < 0)
+ return -1;
+
+ if (addrindex_write_attr( fp, ATTAG_LDAP_DYN_SEARCH,
+ server->searchFlag ?
+ ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+ return -1;
+
+ if (addrindex_write_attr( fp, ATTAG_LDAP_MATCH_OPT,
+ ( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) ?
+ ATVAL_LDAP_MATCH_CONTAINS : ATVAL_LDAP_MATCH_BEGIN ) < 0)
+ return -1;
+
+ if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_TLS,
+ ctl->enableTLS ?
+ ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_SSL,
+ ctl->enableSSL ?
+ ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+ return -1;
+
+ if (fputs(" >\n", fp) == EOF)
+ return -1;
/* Output attributes */
node = ldapctl_get_criteria_list( ctl );
while( node ) {
- addrindex_write_elem_s( fp, 1+lvl, ELTAG_LDAP_ATTR_SRCH );
- addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data );
- fputs(" />\n", fp);
+ if (addrindex_write_elem_s( fp, 1+lvl, ELTAG_LDAP_ATTR_SRCH ) < 0)
+ return -1;
+ if (addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data ) < 0)
+ return -1;
+ if (fputs(" />\n", fp) == EOF)
+ return -1;
node = g_list_next( node );
}
/* End of element */
- addrindex_write_elem_e( fp, lvl, TAG_DS_LDAP );
+ if (addrindex_write_elem_e( fp, lvl, TAG_DS_LDAP ) < 0)
+ return -1;
+
+ return 0;
+}
+#else
+/*
+ * Just read/write DOM fragments (preserve data found in file).
+ */
+static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
+ AddressDataSource *ds;
+
+ ds = addrindex_create_datasource( ADDR_IF_LDAP );
+ ds->rawDataSource = addrindex_read_fragment( file );
+ return ds;
+}
+
+static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
+ AddressIfFragment *fragment = ds->rawDataSource;
+ if( fragment ) {
+ if (addrindex_write_fragment( fp, fragment, lvl ) < 0)
+ return -1;
+ }
+ return 0;
}
#endif
else if( addrIndex->lastType == ADDR_IF_VCARD ) {
ds = addrindex_parse_vcard( file );
}
-#ifdef USE_JPILOT
else if( addrIndex->lastType == ADDR_IF_JPILOT ) {
ds = addrindex_parse_jpilot( file );
}
-#endif
-#ifdef USE_LDAP
else if( addrIndex->lastType == ADDR_IF_LDAP ) {
ds = addrindex_parse_ldap( file );
}
-#endif
if( ds ) {
ds->interface = dsIFace;
addrindex_hash_add_cache( addrIndex, ds );
* \param addrIndex Address index object.
*/
static void addrindex_build_search_order( AddressIndex *addrIndex ) {
- AddressInterface *iface;
GList *nodeIf;
/* Clear existing list */
nodeIf = addrIndex->interfaceList;
while( nodeIf ) {
AddressInterface *iface = nodeIf->data;
- if( iface->searchOrder > 0 ) {
- /* Add to search order list */
- addrIndex->searchOrder = g_list_insert_sorted(
- addrIndex->searchOrder, iface,
- addrindex_search_order_compare );
+ if( iface->useInterface ) {
+ if( iface->searchOrder > 0 ) {
+ /* Add to search order list */
+ addrIndex->searchOrder = g_list_insert_sorted(
+ addrIndex->searchOrder, iface,
+ addrindex_search_order_compare );
+ }
}
nodeIf = g_list_next( nodeIf );
}
-
- nodeIf = addrIndex->searchOrder;
- while( nodeIf ) {
- AddressInterface *iface = nodeIf->data;
- nodeIf = g_list_next( nodeIf );
- }
-
}
static gint addrindex_read_file( AddressIndex *addrIndex ) {
if( file == NULL ) {
/*
- fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName );
+ g_print( " file '%s' does not exist.\n", addrIndex->fileName );
*/
return addrIndex->retVal;
}
return addrIndex->retVal;
}
-static void addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
+static int addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
GList *nodeIF, *nodeDS;
gint lvlList = 1;
gint lvlItem = 1 + lvlList;
AddressInterface *iface = nodeIF->data;
if( ! iface->legacyFlag ) {
nodeDS = iface->listSource;
- addrindex_write_elem_s( fp, lvlList, iface->listTag );
- fputs( ">\n", fp );
+ if (addrindex_write_elem_s( fp, lvlList, iface->listTag ) < 0)
+ return -1;
+ if (fputs( ">\n", fp ) == EOF)
+ return -1;
while( nodeDS ) {
AddressDataSource *ds = nodeDS->data;
if( ds ) {
if( iface->type == ADDR_IF_BOOK ) {
- addrindex_write_book( fp, ds, lvlItem );
+ if (addrindex_write_book( fp, ds, lvlItem ) < 0)
+ return -1;
}
if( iface->type == ADDR_IF_VCARD ) {
- addrindex_write_vcard( fp, ds, lvlItem );
+ if (addrindex_write_vcard( fp, ds, lvlItem ) < 0)
+ return -1;
}
-#ifdef USE_JPILOT
if( iface->type == ADDR_IF_JPILOT ) {
- addrindex_write_jpilot( fp, ds, lvlItem );
+ if (addrindex_write_jpilot( fp, ds, lvlItem ) < 0)
+ return -1;
}
-#endif
-#ifdef USE_LDAP
if( iface->type == ADDR_IF_LDAP ) {
- addrindex_write_ldap( fp, ds, lvlItem );
+ if (addrindex_write_ldap( fp, ds, lvlItem ) < 0)
+ return -1;
}
-#endif
}
nodeDS = g_list_next( nodeDS );
}
- addrindex_write_elem_e( fp, lvlList, iface->listTag );
+ if (addrindex_write_elem_e( fp, lvlList, iface->listTag ) < 0)
+ return -1;
}
nodeIF = g_list_next( nodeIF );
}
+ return 0;
}
/*
* return: Status code, from addrIndex->retVal.
* Note: File will be created in directory specified by addrIndex.
*/
-gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
+static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
FILE *fp;
gchar *fileSpec;
#ifndef DEV_STANDALONE
fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, newFile, NULL );
addrIndex->retVal = MGU_OPEN_FILE;
#ifdef DEV_STANDALONE
- fp = fopen( fileSpec, "wb" );
+ fp = g_fopen( fileSpec, "wb" );
g_free( fileSpec );
if( fp ) {
fputs( "<?xml version=\"1.0\" ?>\n", fp );
g_free( fileSpec );
if( pfile ) {
fp = pfile->fp;
- fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
- conv_get_current_charset_str() );
+ if (fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL ) < 0)
+ goto fail;
#endif
- addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX );
- fputs( ">\n", fp );
+ if (addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX ) < 0)
+ goto fail;
+ if (fputs( ">\n", fp ) == EOF)
+ goto fail;
- addrindex_write_index( addrIndex, fp );
- addrindex_write_elem_e( fp, 0, TAG_ADDRESS_INDEX );
+ if (addrindex_write_index( addrIndex, fp ) < 0)
+ goto fail;
+ if (addrindex_write_elem_e( fp, 0, TAG_ADDRESS_INDEX ) < 0)
+ goto fail;
addrIndex->retVal = MGU_SUCCESS;
#ifdef DEV_STANDALONE
fileSpec = NULL;
return addrIndex->retVal;
+fail:
+ g_warning("error writing AB index\n");
+ addrIndex->retVal = MGU_ERROR_WRITE;
+ if (pfile)
+ prefs_file_close_revert( pfile );
+ return addrIndex->retVal;
}
/*
* return: Status code, from addrIndex->retVal.
*/
gint addrindex_save_data( AddressIndex *addrIndex ) {
+#ifdef USE_LDAP
+ GList *nodeIf;
+ GList *nodeDS;
+#endif
+
g_return_val_if_fail( addrIndex != NULL, -1 );
+#ifdef USE_LDAP
+ nodeIf = addrIndex->interfaceList;
+ /* save LDAP interfaces */
+ while ( nodeIf ) {
+ AddressInterface *iface = nodeIf->data;
+ if( iface->type == ADDR_IF_LDAP ) {
+ nodeDS = iface->listSource;
+ while( nodeDS ) {
+ AddressDataSource *ds = nodeDS->data;
+ LdapServer *abf = ds->rawDataSource;
+ if( ldapsvr_get_read_flag( abf ) ) {
+ if( ldapsvr_get_modified( abf ) ) {
+ ldapsvr_update_book( abf, NULL );
+ if( abf->retVal != LDAPRC_SUCCESS ) {
+ alertpanel( _("Address(es) update"),
+ _("Update failed. Changes not written to Directory."),
+ GTK_STOCK_CLOSE, NULL, NULL );
+ }
+ else {
+ abf->retVal = MGU_SUCCESS;
+ ldapsvr_set_modified( abf, FALSE );
+ }
+ }
+ }
+ nodeDS = g_list_next( nodeDS );
+ }
+ break;
+ }
+ nodeIf = g_list_next( nodeIf );
+ }
+#endif
addrIndex->retVal = MGU_NO_FILE;
if( addrIndex->fileName == NULL || *addrIndex->fileName == '\0' ) return addrIndex->retVal;
if( addrIndex->filePath == NULL || *addrIndex->filePath == '\0' ) return addrIndex->retVal;
if( xml_compare_tag( file, ELTAG_IF_OLD_REMARKS ) ) {
nn->remarks = g_strdup( element );
}
+ g_free(element);
xml_parse_next_tag(file);
}
}
node->list = g_list_append( node->list, newNode );
}
else {
- /* printf( "invalid: !!! \n" ); */
+ /* g_print( "invalid: !!! \n" ); */
attr = xml_get_current_tag_attr( file );
}
}
if (file->level < prev_level) return;
xtag = xml_get_current_tag( file );
- /* printf( "tag : %s\n", xtag->tag ); */
+ /* g_print( "tag : %s\n", xtag->tag ); */
element = xml_get_element( file );
attr = xml_get_current_tag_attr( file );
/* show_attribs( attr ); */
- /* printf( "\ttag value : %s :\n", element ); */
+ /* g_print( "\ttag value : %s :\n", element ); */
addrindex_consume_tree( file );
}
}
if (file->level < prev_level) return;
xtag = xml_get_current_tag( file );
- /* printf( "tag : %d : %s\n", prev_level, xtag->tag ); */
+ /* g_print( "tag : %d : %s\n", prev_level, xtag->tag ); */
if( strcmp( xtag->tag, TAG_IF_OLD_COMMON ) == 0 ) {
if( addrindex_process_book( addrIndex, file, DISP_OLD_COMMON ) ) {
addrIndex->needsConversion = FALSE;
element = xml_get_element( file );
attr = xml_get_current_tag_attr( file );
/* show_attribs( attr ); */
- /* printf( "\ttag value : %s :\n", element ); */
+ /* g_print( "\ttag value : %s :\n", element ); */
addrindex_consume_tree( file );
}
}
g_free( fileSpec );
if( file == NULL ) {
- /* fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName ); */
+ /* g_print( " file '%s' does not exist.\n", addrIndex->fileName ); */
return addrIndex->retVal;
}
iface = ds->interface;
if( iface == NULL ) return retVal;
if( iface->getReadData ) {
+ /*
+ gchar *name = ( iface->getName ) ( ds->rawDataSource );
+ g_print( "addrindex_ds_read_data...reading:::%s:::\n", name );
+ */
retVal = ( iface->getReadData ) ( ds->rawDataSource );
}
return retVal;
return retVal;
}
-/*
- * Return list of folders for specified data source.
- */
-GList *addrindex_ds_get_list_folder( AddressDataSource *ds ) {
- GList *retVal = FALSE;
- AddressInterface *iface;
-
- if( ds == NULL ) return retVal;
- iface = ds->interface;
- if( iface == NULL ) return retVal;
- if( iface->getListFolder ) {
- retVal = ( iface->getListFolder ) ( ds->rawDataSource );
- }
- return retVal;
-}
-
-/*
- * Return list of persons in root folder for specified data source.
- */
-GList *addrindex_ds_get_list_person( AddressDataSource *ds ) {
- GList *retVal = FALSE;
- AddressInterface *iface;
-
- if( ds == NULL ) return retVal;
- iface = ds->interface;
- if( iface == NULL ) return retVal;
- if( iface->getListPerson ) {
- retVal = ( iface->getListPerson ) ( ds->rawDataSource );
- }
- return retVal;
-}
-
/*
* Return name for specified data source.
*/
/*
* Return list of all persons for specified data source.
*/
-GList *addrindex_ds_get_all_persons( AddressDataSource *ds ) {
+static GList *addrindex_ds_get_all_persons( AddressDataSource *ds ) {
GList *retVal = NULL;
AddressInterface *iface;
/*
* Return list of all groups for specified data source.
*/
-GList *addrindex_ds_get_all_groups( AddressDataSource *ds ) {
+static GList *addrindex_ds_get_all_groups( AddressDataSource *ds ) {
GList *retVal = NULL;
AddressInterface *iface;
*/
/**
- * Current query ID. This is incremented for each query created.
- */
-static gint _currentQueryID_ = 0;
-
-/*
- * Variables for the search that is being performed.
- */
-static gchar *_searchTerm_ = NULL;
-static gpointer _searchTarget_ = NULL;
-static AddrSearchCallbackFunc *_searchCallback_ = NULL;
-
-/**
- * Setup or register the search that will be performed.
- * \param addrIndex Address index object.
- * \param searchTerm Search term. A private copy will be made.
- * \param target Target object that will receive data.
- * \param callBack Callback function.
+ * Setup or register the dynamic search that will be performed. The search
+ * is registered with the query manager.
+ *
+ * \param searchTerm Search term. A private copy will be made.
+ * \param callBackEntry Callback function that should be called when
+ * each entry is received.
+ * \param callBackEnd Callback function that should be called when
+ * search has finished running.
* \return ID allocated to query that will be executed.
*/
gint addrindex_setup_search(
- AddressIndex *addrIndex, const gchar *searchTerm,
- const gpointer target, AddrSearchCallbackFunc callBack )
+ const gchar *searchTerm, void *callBackEnd, void *callBackEntry )
{
+ QueryRequest *req;
gint queryID;
- /* printf( "search term ::%s::\n", searchTerm ); */
- g_free( _searchTerm_ );
- _searchTerm_ = g_strdup( searchTerm );
+ /* Set up a dynamic address query */
+ req = qrymgr_add_request( searchTerm, callBackEnd, callBackEntry );
+ queryID = req->queryID;
+ qryreq_set_search_type( req, ADDRSEARCH_DYNAMIC );
- queryID = ++_currentQueryID_;
- _searchTarget_ = target;
- _searchCallback_ = callBack;
- /* printf( "query ID ::%d::\n", queryID ); */
+ /* g_print( "***> query ID ::%d::\n", queryID ); */
return queryID;
}
+#ifdef USE_LDAP
+
+/*
+ * Function prototypes (not in header file or circular reference errors are
+ * encountered!)
+ */
+LdapQuery *ldapsvr_new_dynamic_search(
+ LdapServer *server, QueryRequest *req );
+LdapQuery *ldapsvr_new_explicit_search(
+ LdapServer *server, QueryRequest *req, ItemFolder *folder );
+void ldapsvr_execute_query( LdapServer *server, LdapQuery *qry );
+
+#endif
+
/**
- * Perform the search for specified address cache.
- * \param cache Cache to be searched.
- * \param queryID ID of search query to be executed.
+ * Execute the previously registered dynamic search.
+ *
+ * \param req Address query object to execute.
+ * \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if
+ * failed.
*/
-static void addrindex_search_cache( AddressCache *cache, const gint queryID ) {
- AddrCacheIndex *index;
- GList *listEMail;
+static gboolean addrindex_start_dynamic( QueryRequest *req ) {
+ AddressInterface *iface;
+ AddressDataSource *ds;
+ GList *nodeIf;
+ GList *nodeDS;
+ gint type;
- index = cache->searchIndex;
- if( index == NULL ) return;
- if( index->invalid ) {
- addrcache_build_index( cache );
- }
+ /* g_print( "addrindex_start_dynamic::%d::\n", req->queryID ); */
+ nodeIf = _addressIndex_->searchOrder;
+ while( nodeIf ) {
+ iface = nodeIf->data;
+ nodeIf = g_list_next( nodeIf );
- /*
- printf( "query ::%d:: searching index for ::%s::\n", queryID, _searchTerm_ );
- */
- listEMail = addrcindex_search( index, _searchTerm_ );
- ( _searchCallback_ ) ( queryID, listEMail, _searchTarget_ );
- g_list_free( listEMail );
- listEMail = NULL;
- /* printf( "searching index done\n" ); */
-}
+ if( ! iface->useInterface ) {
+ continue;
+ }
+ if( ! iface->externalQuery ) {
+ continue;
+ }
+ type = iface->type;
+ nodeDS = iface->listSource;
+ while( nodeDS ) {
+ ds = nodeDS->data;
+ nodeDS = g_list_next( nodeDS );
#ifdef USE_LDAP
-/**
- * LDAP callback entry point for each address entry found.
- * \param qry LDAP query.
- * \param listEMail List of Item EMail objects found.
- */
-static void addrindex_ldap_entry_cb( LdapQuery *qry, GList *listEMail ) {
- GList *node;
+ if( type == ADDR_IF_LDAP ) {
+ LdapServer *server;
+ LdapQuery *qry;
- /*
- printf( "\naddrindex::addrindex_ldap_entry_cb ::%s::\n", qry->queryName );
- */
- node = listEMail;
- while( node ) {
- ItemEMail *email = node->data;
- /* printf( "\temail ::%s::\n", email->address ); */
- node = g_list_next( node );
- }
- if( _searchCallback_ ) {
- ( _searchCallback_ ) ( qry->queryID, listEMail, _searchTarget_ );
- }
- g_list_free( listEMail );
-}
+ server = ds->rawDataSource;
+ if( ! server->searchFlag ) {
+ continue;
+ }
+ if( ldapsvr_reuse_previous( server, req ) ) {
+ continue;
+ }
-/**
- * LDAP callback entry point for completion of search.
- * \param qry LDAP query.
- */
-static void addrindex_ldap_end_cb( LdapQuery *qry ) {
- /* printf( "\naddrindex::addrindex_ldap_end_cb ::%s::\n", qry->queryName ); */
+ /* Start a new dynamic search */
+ qry = ldapsvr_new_dynamic_search( server, req );
+ if( qry ) {
+ ldapsvr_execute_query( server, qry );
+ }
+ }
+#endif
+ }
+ }
+ return TRUE;
}
/**
- * Return results of previous query.
- * \param folder.
- * \return List of ItemEMail objects.
+ * Stop the previously registered search.
+ *
+ * \param queryID ID of search query to stop.
*/
-static void addrindex_ldap_use_previous( const ItemFolder *folder, const gint queryID )
-{
- GList *listEMail;
+void addrindex_stop_search( const gint queryID ){
+ QueryRequest *req;
+ AddrQueryObject *aqo;
GList *node;
- GList *nodeEM;
- listEMail = NULL;
- if( _searchCallback_ ) {
- node = folder->listPerson;
- while( node ) {
- AddrItemObject *aio = node->data;
- if( aio && aio->type == ITEMTYPE_PERSON ) {
- ItemPerson *person = node->data;
- nodeEM = person->listEMail;
- while( nodeEM ) {
- ItemEMail *email = nodeEM->data;
- nodeEM = g_list_next( nodeEM );
- listEMail = g_list_append( listEMail, email );
- }
- }
- node = g_list_next( node );
+ /* g_print( "addrindex_stop_search/queryID=%d\n", queryID ); */
+ /* If query ID does not match, search has not been setup */
+ req = qrymgr_find_request( queryID );
+ if( req == NULL ) {
+ return;
+ }
+
+ /* Stop all queries that were associated with request */
+ node = req->queryList;
+ while( node ) {
+ aqo = node->data;
+#ifdef USE_LDAP
+ if( aqo->queryType == ADDRQUERY_LDAP ) {
+ LdapQuery *qry = ( LdapQuery * ) aqo;
+ ldapqry_set_stop_flag( qry, TRUE );
}
- ( _searchCallback_ ) ( queryID, listEMail, _searchTarget_ );
- g_list_free( listEMail );
+#endif
+ node->data = NULL;
+ node = g_list_next( node );
}
-}
-LdapQuery *ldapsvr_locate_query( LdapServer *server, const gchar *searchTerm );
+ /* Delete query request */
+ qrymgr_delete_request( queryID );
+}
/**
- * Construct an LDAP query and initiate an LDAP search.
- * \param server LDAP server object.
- * \param queryID ID of search query to be executed.
+ * Setup or register the explicit search that will be performed. The search is
+ * registered with the query manager.
+ *
+ * \param ds Data source to search.
+ * \param searchTerm Search term to locate.
+ * \param folder Folder to receive search results; may be NULL.
+ * \param callbackEnd Function to call when search has terminated.
+ * \param callbackEntry Function to called for each entry processed.
+ * \return ID allocated to query that will be executed.
*/
-static void addrindex_search_ldap( LdapServer *server, const gint queryID ) {
- LdapQuery *qry;
+gint addrindex_setup_explicit_search(
+ AddressDataSource *ds, const gchar *searchTerm, ItemFolder *folder,
+ void *callBackEnd, void *callBackEntry )
+{
+ QueryRequest *req;
+ gint queryID;
gchar *name;
+ gchar *mySearch;
- if( ! server->searchFlag ) return;
- /* printf( "Searching ::%s::\n", ldapsvr_get_name( server ) ); */
+ /* Name the query */
+ name = g_strdup_printf( "Search '%s'", searchTerm );
- /* Retire any aged queries */
- ldapsvr_retire_query( server );
+ /* Set up query request */
+ if (!strcmp(searchTerm, "*"))
+ mySearch = g_strdup("*@");
+ else
+ mySearch = g_strdup(searchTerm);
+
+ req = qrymgr_add_request( mySearch, callBackEnd, callBackEntry );
- /* Test whether any queries for the same term exist */
- qry = ldapsvr_locate_query( server, _searchTerm_ );
- if( qry ) {
- ItemFolder *folder = qry->folder;
+ g_free(mySearch);
- /* Touch query to ensure it hangs around for a bit longer */
- ldapqry_touch( qry );
- if( folder ) {
- addrindex_ldap_use_previous( folder, queryID );
- return;
- }
- }
+ qryreq_set_search_type( req, ADDRSEARCH_EXPLICIT );
+ queryID = req->queryID;
- /* Construct a query */
- qry = ldapqry_create();
- ldapqry_set_query_id( qry, queryID );
- ldapqry_set_search_value( qry, _searchTerm_ );
- ldapqry_set_query_type( qry, LDAPQUERY_DYNAMIC );
- ldapqry_set_callback_entry( qry, addrindex_ldap_entry_cb );
- ldapqry_set_callback_end( qry, addrindex_ldap_end_cb );
+ if( ds->type == ADDR_IF_LDAP ) {
+#ifdef USE_LDAP
+ LdapServer *server;
- /* Name the query */
- name = g_strdup_printf( "Search for '%s'", _searchTerm_ );
- ldapqry_set_name( qry, name );
+ server = ds->rawDataSource;
+ ldapsvr_new_explicit_search( server, req, folder );
+#endif
+ }
+ else {
+ qrymgr_delete_request( queryID );
+ queryID = 0;
+ }
g_free( name );
- ldapsvr_add_query( server, qry );
- /* printf( "addrindex_search_ldap::executing dynamic search...\n" ); */
- ldapsvr_execute_query( server, qry );
+ return queryID;
}
/**
- * Construct an LDAP query and initiate an LDAP search.
- * \param server LDAP server object to search.
- * \param searchTerm Search term to locate.
- * \param callbackEnd Function to call when search has terminated.
+ * Execute the previously registered explicit search.
*
+ * \param req Address query request object to execute.
+ * \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if
+ * failed.
*/
-void addrindex_search_ldap_noid(
- LdapServer *server, const gchar *searchTerm, void * callbackEnd )
-{
- LdapQuery *qry;
- gchar *name;
+static gboolean addrindex_start_explicit( QueryRequest *req ) {
+ gboolean retVal;
+ AddrQueryObject *aqo;
- /* Construct a query */
- qry = ldapqry_create();
- ldapqry_set_search_value( qry, searchTerm );
- ldapqry_set_query_type( qry, LDAPQUERY_STATIC );
- ldapqry_set_callback_end( qry, callbackEnd );
+ retVal = FALSE;
- /* Name the query */
- name = g_strdup_printf( "Static Search for '%s'", searchTerm );
- ldapqry_set_name( qry, name );
- g_free( name );
+ /* Note: there should only be one query in the list. */
+ aqo = req->queryList->data;
+#ifdef USE_LDAP
+ if( aqo->queryType == ADDRQUERY_LDAP ) {
+ LdapServer *server;
+ LdapQuery *qry;
- ldapsvr_add_query( server, qry );
- /* printf( "addrindex_search_ldap_noid::executing static search...\n" ); */
- ldapsvr_execute_query( server, qry );
-}
+ qry = ( LdapQuery * ) aqo;
+ server = qry->server;
+
+ /* Start the search */
+ retVal = TRUE;
+ ldapsvr_execute_query( server, qry );
+ }
#endif
+ return retVal;
+}
/**
- * Perform the previously registered search.
- * \param addrIndex Address index object.
+ * Start the previously registered search.
+ *
* \param queryID ID of search query to be executed.
* \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if
* failed.
*/
-gboolean addrindex_start_search( AddressIndex *addrIndex, const gint queryID ) {
- AddressInterface *iface;
- AddressDataSource *ds;
+gboolean addrindex_start_search( const gint queryID ) {
+ gboolean retVal;
+ QueryRequest *req;
+ AddrSearchType searchType;
+
+ retVal = FALSE;
+ /* g_print( "addrindex_start_search/queryID=%d\n", queryID ); */
+ req = qrymgr_find_request( queryID );
+ if( req == NULL ) {
+ return retVal;
+ }
+
+ searchType = req->searchType;
+ if( searchType == ADDRSEARCH_DYNAMIC ) {
+ retVal = addrindex_start_dynamic( req );
+ }
+ else if( searchType == ADDRSEARCH_EXPLICIT ) {
+ retVal = addrindex_start_explicit( req );
+ }
+
+ return retVal;
+}
+
+/**
+ * Remove results (folder and data) for specified data source and folder.
+ * \param ds Data source to process.
+ * \param folder Results folder to remove.
+ */
+void addrindex_remove_results( AddressDataSource *ds, ItemFolder *folder ) {
+ AddrBookBase *adbase;
AddressCache *cache;
- GList *nodeIf;
- GList *nodeDS;
- gint type;
+ gint queryID = 0;
- /* printf( "addrindex_start_search::%d::\n", queryID ); */
- nodeIf = addrIndex->searchOrder;
- while( nodeIf ) {
- iface = nodeIf->data;
- nodeIf = g_list_next( nodeIf );
+ /* g_print( "addrindex_remove_results/start\n" ); */
- if( ! iface->useInterface ) {
- continue;
- }
+ /* Test for folder */
+ if( folder->folderType != ADDRFOLDER_QUERY_RESULTS ) return;
+ /* g_print( "folder name ::%s::\n", ADDRITEM_NAME(folder) ); */
+ adbase = ( AddrBookBase * ) ds->rawDataSource;
+ if( adbase == NULL ) return;
+ cache = adbase->addressCache;
- type = iface->type;
- nodeDS = iface->listSource;
- while( nodeDS ) {
- ds = nodeDS->data;
- nodeDS = g_list_next( nodeDS );
- cache = NULL;
+ /* Hide folder to prevent re-display */
+ addritem_folder_set_hidden( folder, TRUE );
- if( type == ADDR_IF_BOOK ) {
- AddressBookFile *abf = ds->rawDataSource;
- cache = abf->addressCache;
- }
- else if( type == ADDR_IF_VCARD ) {
- VCardFile *vcf = ds->rawDataSource;
- cache = vcf->addressCache;
- }
-#ifdef USE_JPILOT
- else if( type == ADDR_IF_JPILOT ) {
- JPilotFile *jpf = ds->rawDataSource;
- cache = jpf->addressCache;
- }
-#endif
+ if( ds->type == ADDR_IF_LDAP ) {
#ifdef USE_LDAP
- else if( type == ADDR_IF_LDAP ) {
- LdapServer *server = ds->rawDataSource;
- addrindex_search_ldap( server, queryID );
- }
-#endif
- if( cache ) {
- addrindex_search_cache( cache, queryID );
- }
+ LdapQuery *qry;
+ gboolean delFlag;
+
+ qry = ( LdapQuery * ) folder->folderData;
+ queryID = ADDRQUERY_ID(qry);
+ /* g_print( "calling ldapquery_remove_results...queryID=%d\n", queryID ); */
+ delFlag = ldapquery_remove_results( qry );
+ if (delFlag) {
+ ldapqry_free( qry );
+ }
+ /* g_print( "calling ldapquery_remove_results...done\n" ); */
+ /*
+ if( delFlag ) {
+ g_print( "delFlag IS-TRUE\n" );
}
+ else {
+ g_print( "delFlag IS-FALSE\n" );
+ }
+ */
+#endif
+ }
+ /* g_print( "addrindex_remove_results/end\n" ); */
+
+ /* Delete query request */
+ if( queryID > 0 ) {
+ qrymgr_delete_request( queryID );
}
- return TRUE;
}
+/* **********************************************************************
+* Address completion stuff.
+* ***********************************************************************
+*/
+
+static void addrindex_load_completion_load_persons(
+ gint (*callBackFunc) ( const gchar *, const gchar *,
+ const gchar *, const gchar *, GList * ),
+ AddressDataSource *ds)
+{
+ GList *listP, *nodeP;
+ GList *nodeM;
+ gchar *sName;
+
+ /* Read address book */
+ if( addrindex_ds_get_modify_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
+ }
+
+ if( ! addrindex_ds_get_read_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
+ }
+
+ /* Get all groups */
+ listP = addrindex_ds_get_all_groups( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemGroup *group = nodeP->data;
+ GList *emails = NULL;
+ for (nodeM = group->listEMail; nodeM; nodeM = g_list_next(nodeM)) {
+ ItemEMail *email = nodeM->data;
+ if (email->address)
+ emails = g_list_append(emails, email);
+ }
+ callBackFunc( ((AddrItemObject *)group)->name, NULL,
+ NULL, NULL, emails );
+ nodeP = g_list_next( nodeP );
+ }
+
+ /* Free up the list */
+ g_list_free( listP );
+ /* Get all persons */
+ listP = addrindex_ds_get_all_persons( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemPerson *person = nodeP->data;
+ nodeM = person->listEMail;
+
+ /* Figure out name to use */
+ sName = ADDRITEM_NAME(person);
+ if( sName == NULL || *sName == '\0' ) {
+ sName = person->nickName;
+ }
+
+ /* Process each E-Mail address */
+ while( nodeM ) {
+ ItemEMail *email = nodeM->data;
+
+ callBackFunc( sName, email->address, person->nickName,
+ ADDRITEM_NAME(email), NULL );
+
+ nodeM = g_list_next( nodeM );
+ }
+ nodeP = g_list_next( nodeP );
+ }
+
+ /* Free up the list */
+ g_list_free( listP );
+}
+
/**
- * Stop the previously registered search.
- * \param addrIndex Address index object.
- * \param queryID ID of search query to stop.
+ * This function is used by the address completion function to load
+ * addresses for all non-external address book interfaces.
+ *
+ * \param callBackFunc Function to be called when an address is
+ * to be loaded.
+ * \param folderpath Addressbook's Book/folder path to restrict to (if NULL or ""
+ * or "Any", assume the whole addressbook
+ * \return <i>TRUE</i> if data loaded, <i>FALSE</i> if address index not loaded.
*/
-void addrindex_stop_search( AddressIndex *addrIndex, const gint queryID ){
-#ifdef USE_LDAP
- AddressInterface *iface;
- AddressDataSource *ds;
- GList *nodeIf;
- GList *nodeDS;
- gint type;
- /* If query ID does not match, search has not been setup */
- /* if( queryID != _queryID_ ) return; */
+gboolean addrindex_load_completion(
+ gint (*callBackFunc) ( const gchar *, const gchar *,
+ const gchar *, const gchar *, GList * ),
+ gchar *folderpath )
+{
+ GList *nodeIf, *nodeDS;
- /* printf( "addrindex_stop_search::%d::\n", queryID ); */
- nodeIf = addrIndex->searchOrder;
- while( nodeIf ) {
- iface = nodeIf->data;
- nodeIf = g_list_next( nodeIf );
+ if( folderpath != NULL ) {
+ AddressDataSource *book;
+ ItemFolder* folder;
- if( ! iface->useInterface ) {
- continue;
+ /* split the folder path we've received, we'll try to match this path, subpath by
+ subpath against the book/folder structure in order and restrict loading of
+ addresses to that subpart (if matches). book/folder path must exist and
+ folderpath must not be empty or NULL */
+
+ if( ! addressbook_peek_folder_exists( folderpath, &book, &folder ) ) {
+ g_warning("addrindex_load_completion: folder path '%s' doesn't exist\n", folderpath);
+ return FALSE;
}
- type = iface->type;
- nodeDS = iface->listSource;
- while( nodeDS ) {
- ds = nodeDS->data;
- nodeDS = g_list_next( nodeDS );
- if( type == ADDR_IF_LDAP ) {
- LdapServer *server = ds->rawDataSource;
- ldapsvr_stop_all_query( server );
+ if( folder != NULL ) {
+
+ GList *items;
+ GList *nodeM;
+ gchar *sName;
+ ItemPerson *person;
+
+ debug_print("addrindex_load_completion: folder %p '%s'\n", folder, folder->obj.name);
+
+ /* Load email addresses */
+ items = addritem_folder_get_person_list( folder );
+ for( ; items != NULL; items = g_list_next( items ) ) {
+ person = items->data;
+ nodeM = person->listEMail;
+
+ /* Figure out name to use */
+ sName = ADDRITEM_NAME(person);
+ if( sName == NULL || *sName == '\0' ) {
+ sName = person->nickName;
+ }
+
+ /* Process each E-Mail address */
+ while( nodeM ) {
+ ItemEMail *email = nodeM->data;
+
+ callBackFunc( sName, email->address, person->nickName,
+ ADDRITEM_NAME(email), NULL );
+
+ nodeM = g_list_next( nodeM );
+ }
}
+ /* Free up the list */
+ mgu_clear_list( items );
+ g_list_free( items );
+
+ return TRUE;
+
+ } else {
+
+ if( book != NULL ) {
+
+ AddressBookFile *abf = book->rawDataSource;
+
+ debug_print("addrindex_load_completion: book %p '%s'\n", book, abf?abf->fileName:"(null)");
+
+ addrindex_load_completion_load_persons( callBackFunc, book );
+
+ return TRUE;
+
+ } else {
+ g_warning("addrindex_load_completion: book/folder path is valid but got no pointer\n");
+ }
+ }
+ return FALSE;
+
+ } else {
+
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
+ while( nodeIf ) {
+ AddressInterface *iface = nodeIf->data;
+
+ nodeIf = g_list_next( nodeIf );
+
+ if( ! iface->useInterface || iface->externalQuery )
+ continue;
+
+ nodeDS = iface->listSource;
+ while( nodeDS ) {
+ addrindex_load_completion_load_persons( callBackFunc, nodeDS->data );
+ nodeDS = g_list_next( nodeDS );
}
}
-#endif
+ }
+
+ return TRUE;
}
/**
- * Read all address books that do not support dynamic queries.
- * \param addrIndex Address index object.
+ * This function can be used to collect information about
+ * addressbook entries that contain a specific attribute.
+ *
+ * \param attr Name of attribute to look for
+ * \param callBackFunc Function to be called when a matching attribute was found
+ * \return <i>TRUE</i>
*/
-void addrindex_read_all( AddressIndex *addrIndex ) {
- AddressInterface *iface;
+gboolean addrindex_load_person_attribute(
+ const gchar *attr,
+ gint (*callBackFunc) ( ItemPerson *, const gchar * ) )
+{
AddressDataSource *ds;
- GList *nodeIf;
- GList *nodeDS;
+ GList *nodeIf, *nodeDS;
+ GList *listP, *nodeP;
+ GList *nodeA;
- nodeIf = addrIndex->searchOrder;
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
while( nodeIf ) {
- iface = nodeIf->data;
+ gchar *cur_bname;
+ AddressInterface *iface = nodeIf->data;
+
nodeIf = g_list_next( nodeIf );
- if( ! iface->useInterface ) {
- continue;
- }
- if( iface->externalQuery ) {
+ if( ! iface->useInterface || iface->externalQuery )
continue;
- }
+
nodeDS = iface->listSource;
while( nodeDS ) {
ds = nodeDS->data;
- nodeDS = g_list_next( nodeDS );
/* Read address book */
if( addrindex_ds_get_modify_flag( ds ) ) {
addrindex_ds_read_data( ds );
- continue;
}
if( ! addrindex_ds_get_read_flag( ds ) ) {
addrindex_ds_read_data( ds );
- continue;
}
+
+ /* Check addressbook name */
+ cur_bname = addrindex_ds_get_name( ds );
+
+ /* Get all persons */
+ listP = addrindex_ds_get_all_persons( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemPerson *person = nodeP->data;
+
+ /* Return all ItemPerson's if attr is NULL */
+ if( attr == NULL ) {
+ callBackFunc(person, cur_bname);
+ }
+
+ /* Return ItemPerson's with specific attribute */
+ else {
+ nodeA = person->listAttrib;
+ /* Process each User Attribute */
+ while( nodeA ) {
+ UserAttribute *attrib = nodeA->data;
+ if( attrib->name &&
+ !strcmp( attrib->name,attr ) ) {
+ callBackFunc(person, cur_bname);
+ }
+ nodeA = g_list_next( nodeA );
+ }
+ }
+ nodeP = g_list_next( nodeP );
+ }
+ /* Free up the list */
+ g_list_free( listP );
+
+ nodeDS = g_list_next( nodeDS );
}
}
- addrIndex->loadedFlag = TRUE;
+ return TRUE;
}
/**
- * Perform a simple search of all non-query type data sources for specified
- * search term. If several entries are found, only the first item is
- * returned. Interfaces that require a time-consuming "external query" are
- * ignored for this search.
+ * This function can be used to collect information about
+ * addressbook entries
*
- * \param addrIndex Address index object.
- * \param searchTerm Search term to find. Typically an email address.
- * \return List of references to zero or mail E-Mail object that was found in
- * the address books, or <i>NULL</i> if nothing found. This list
- * *SHOULD* be freed when done.
- */
-GList *addrindex_quick_search_list(
- AddressIndex *addrIndex, const gchar *searchTerm )
+ * \param callBackFunc Function to be called for each ItemPerson
+ * \return <i>TRUE</i>
+ */
+gboolean addrindex_load_person_ds( gint (*callBackFunc)
+ ( ItemPerson *, AddressDataSource * ) )
{
- GList *listRet = NULL;
- GList *listEMail;
- AddressInterface *iface;
AddressDataSource *ds;
- AddressCache *cache;
- AddrCacheIndex *index;
- ItemEMail *email;
- GList *nodeIf;
- GList *nodeDS;
- GList *nodeEM;
- gint type;
+ GList *nodeIf, *nodeDS;
+ GList *listP, *nodeP;
- nodeIf = addrIndex->searchOrder;
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
while( nodeIf ) {
- iface = nodeIf->data;
+ AddressInterface *iface = nodeIf->data;
+
nodeIf = g_list_next( nodeIf );
- if( ! iface->useInterface ) {
- /* Ignore interfaces that don't have a library */
- continue;
- }
- if( iface->externalQuery ) {
- /* Ignore interfaces that require a "query" */
+ if( ! iface->useInterface || iface->externalQuery )
continue;
- }
- type = iface->type;
nodeDS = iface->listSource;
while( nodeDS ) {
ds = nodeDS->data;
- nodeDS = g_list_next( nodeDS );
- cache = NULL;
- if( type == ADDR_IF_BOOK ) {
- AddressBookFile *abf = ds->rawDataSource;
- cache = abf->addressCache;
- }
- else if( type == ADDR_IF_VCARD ) {
- VCardFile *vcf = ds->rawDataSource;
- cache = vcf->addressCache;
+ /* Read address book */
+ if( addrindex_ds_get_modify_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
}
-#ifdef USE_JPILOT
- else if( type == ADDR_IF_JPILOT ) {
- JPilotFile *jpf = ds->rawDataSource;
- cache = jpf->addressCache;
+
+ if( ! addrindex_ds_get_read_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
}
-#endif
- if( cache ) {
- index = cache->searchIndex;
- if( index == NULL ) {
- continue;
- }
- if( index->invalid ) {
- addrcache_build_index( cache );
- }
- listEMail = addrcindex_search( index, searchTerm );
- nodeEM = listEMail;
- while( nodeEM ) {
- email = listEMail->data;
- listRet = g_list_append( listRet, email );
- nodeEM = g_list_next( nodeEM );
- }
- g_list_free( listEMail );
+
+ /* Get all persons */
+ listP = addrindex_ds_get_all_persons( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemPerson *person = nodeP->data;
+
+ callBackFunc(person, ds);
+ nodeP = g_list_next( nodeP );
}
+ /* Free up the list */
+ g_list_free( listP );
+
+ nodeDS = g_list_next( nodeDS );
}
}
- return listRet;
+ return TRUE;
}
-/**
- * Perform a simple search of all non-query type data sources for specified
- * search term. If several entries are found, only the first item is
- * returned. Interfaces that require a time-consuming "external query" are
- * ignored for this search.
- *
- * \param addrIndex Address index object.
- * \param searchTerm Search term to find. Typically an email address.
- * \return Reference to a single E-Mail object that was found in the address
- * book, or <i>NULL</i> if nothing found. This should *NOT* be freed
- * when done.
- */
-ItemEMail *addrindex_quick_search_single(
- AddressIndex *addrIndex, const gchar *searchTerm )
+gchar *addrindex_get_picture_file(const gchar *emailaddr)
{
- ItemEMail *email = NULL;
- AddressInterface *iface;
AddressDataSource *ds;
- AddressCache *cache;
- AddrCacheIndex *index;
- GList *listEMail;
- GList *nodeIf;
- GList *nodeDS;
- gint type;
-
- /* printf( "addrindex_quick_search::%s::\n", searchTerm ); */
- nodeIf = addrIndex->searchOrder;
+ GList *nodeIf, *nodeDS;
+ GList *listP, *nodeP;
+ gboolean found = FALSE;
+ gchar *filename = NULL;
+ gchar *raw_addr = NULL;
+
+ if (!emailaddr)
+ return NULL;
+
+ Xstrdup_a(raw_addr, emailaddr, return NULL);
+ extract_address(raw_addr);
+
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
while( nodeIf ) {
- iface = nodeIf->data;
+ AddressInterface *iface = nodeIf->data;
+
nodeIf = g_list_next( nodeIf );
- if( ! iface->useInterface ) {
- continue;
- }
- if( iface->externalQuery ) {
+ if( ! iface->useInterface || iface->externalQuery )
continue;
- }
- type = iface->type;
nodeDS = iface->listSource;
- while( nodeDS ) {
+ while( nodeDS && !found) {
ds = nodeDS->data;
- nodeDS = g_list_next( nodeDS );
- cache = NULL;
- if( type == ADDR_IF_BOOK ) {
- AddressBookFile *abf = ds->rawDataSource;
- cache = abf->addressCache;
- }
- else if( type == ADDR_IF_VCARD ) {
- VCardFile *vcf = ds->rawDataSource;
- cache = vcf->addressCache;
+ /* Read address book */
+ if( addrindex_ds_get_modify_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
}
-#ifdef USE_JPILOT
- else if( type == ADDR_IF_JPILOT ) {
- JPilotFile *jpf = ds->rawDataSource;
- cache = jpf->addressCache;
+
+ if( ! addrindex_ds_get_read_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
}
-#endif
- if( cache ) {
- index = cache->searchIndex;
- if( index == NULL ) {
- continue;
- }
- if( index->invalid ) {
- addrcache_build_index( cache );
- }
- listEMail = addrcindex_search( index, searchTerm );
- if( listEMail ) {
- email = listEMail->data;
+ /* Get all persons */
+ listP = addrindex_ds_get_all_persons( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ GList *nodeM;
+ ItemPerson *person = nodeP->data;
+ nodeM = person->listEMail;
+ while(nodeM) {
+ ItemEMail *email = nodeM->data;
+ if (email->address && !strcasecmp(raw_addr, email->address)) {
+ found = TRUE;
+ filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S,
+ ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
+ person->picture, NULL, ".png" );
+ break;
+ }
+ nodeM = nodeM->next;
}
- g_list_free( listEMail );
- if( email ) break;
+ nodeP = g_list_next( nodeP );
}
+ /* Free up the list */
+ g_list_free( listP );
+
+ nodeDS = g_list_next( nodeDS );
}
}
- return email;
+
+ return filename;
}
/*
* End of Source.
*/
-
-