/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2004 Match Grun
+ * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws 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
*
* 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
-#include "intl.h"
#include "mgutils.h"
#include "addritem.h"
#include "addrcache.h"
#include "xml.h"
#include "addrquery.h"
#include "addr_compl.h"
+#include "utils.h"
#ifndef DEV_STANDALONE
#include "prefs_gtk.h"
#include "ldapserver.h"
#include "ldapctrl.h"
#include "ldapquery.h"
+#include "ldaputil.h"
#endif
#define TAG_ADDRESS_INDEX "addressbook"
/* 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"
* 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 );
}
}
}
-#if 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 );
-}
-#endif
-
/**
* Read/parse address index file, creating a data source for a regular
* intrinsic XML addressbook.
}
+void ldapsvr_set_control( LdapServer *server, LdapControl *ctl );
/**
* Parse LDAP control data from XML file.
* \param file Index file.
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 );
}
else if( strcmp( name, ATTAG_LDAP_MAX_ENTRY ) == 0 ) {
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() );
+ fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL );
#endif
addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX );
fputs( ">\n", fp );
if( xml_compare_tag( file, ELTAG_IF_OLD_REMARKS ) ) {
nn->remarks = g_strdup( element );
}
+ g_free(element);
xml_parse_next_tag(file);
}
}
LdapServer *server, QueryRequest *req );
LdapQuery *ldapsvr_new_explicit_search(
LdapServer *server, QueryRequest *req, ItemFolder *folder );
+void ldapsvr_execute_query( LdapServer *server, LdapQuery *qry );
#endif
QueryRequest *req;
gint queryID;
gchar *name;
+ gchar *mySearch;
/* Name the query */
name = g_strdup_printf( "Search '%s'", searchTerm );
/* Set up query request */
- req = qrymgr_add_request( searchTerm, callBackEnd, callBackEntry );
+ if (!strcmp(searchTerm, "*"))
+ mySearch = g_strdup("*@");
+ else
+ mySearch = g_strdup(searchTerm);
+
+ req = qrymgr_add_request( mySearch, callBackEnd, callBackEntry );
+
+ g_free(mySearch);
+
qryreq_set_search_type( req, ADDRSEARCH_EXPLICIT );
queryID = req->queryID;
queryID = ADDRQUERY_ID(qry);
/* printf( "calling ldapquery_remove_results...queryID=%d\n", queryID ); */
delFlag = ldapquery_remove_results( qry );
+ if (delFlag) {
+ ldapqry_free( qry );
+ }
/* printf( "calling ldapquery_remove_results...done\n" ); */
/*
if( delFlag ) {
return TRUE;
}
-/*
- * End of Source.
+/**
+ * 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>
*/
+gboolean addrindex_load_person_attribute(
+ const gchar *attr,
+ gint (*callBackFunc) ( ItemPerson *, const gchar * ) )
+{
+ AddressDataSource *ds;
+ GList *nodeIf, *nodeDS;
+ GList *listP, *nodeP;
+ GList *nodeA;
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
+ while( nodeIf ) {
+ gchar *cur_bname;
+ AddressInterface *iface = nodeIf->data;
+ nodeIf = g_list_next( nodeIf );
+ if( ! iface->useInterface ) {
+ continue;
+ }
+ if( iface->externalQuery ) {
+ continue;
+ }
+ nodeDS = iface->listSource;
+ while( nodeDS ) {
+ ds = nodeDS->data;
+
+ /* 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 );
+ }
+
+ /* 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 );
+ }
+ }
+ return TRUE;
+}
+
+/*
+ * End of Source.
+ */