From: Match Grun Date: Wed, 5 Nov 2003 03:35:24 +0000 (+0000) Subject: Fix LDAP. X-Git-Tag: rel_0_9_7~35 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=ac65b5222470f65e972eb5fc847650c5c87fb3a6 Fix LDAP. --- diff --git a/ChangeLog.claws b/ChangeLog.claws index cdcc491ca..32fc1770b 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,10 @@ +2003-11-04 [match] 0.9.6claws68 + * src/ldapctrl.[ch] + fix broken LDAP support. + + * src/ldapquery.c + remove printf's. + 2003-11-04 [luke] 0.9.6claws67 * src/mimeview.c o fixed bug 4 "focus lost on messages with attachments" diff --git a/configure.ac b/configure.ac index 3f9585744..7773d897e 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=9 MICRO_VERSION=6 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=67 +EXTRA_VERSION=68 if test $EXTRA_VERSION -eq 0; then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws else diff --git a/src/ldapctrl.c b/src/ldapctrl.c index d11454d90..391694b39 100644 --- a/src/ldapctrl.c +++ b/src/ldapctrl.c @@ -55,6 +55,7 @@ LdapControl *ldapctl_create( void ) { ctl->maxEntries = LDAPCTL_MAX_ENTRIES; ctl->timeOut = LDAPCTL_DFL_TIMEOUT; ctl->maxQueryAge = LDAPCTL_DFL_QUERY_AGE; + ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; /* Mutex to protect control block */ ctl->mutexCtl = g_malloc0( sizeof( pthread_mutex_t ) ); @@ -162,6 +163,27 @@ void ldapctl_set_max_query_age( LdapControl* ctl, const gint value ) { } } +/** + * Specify matching option to be used for searches. + * \param ctl Control object to process. + * \param value Matching option, as follows: + * + */ +void ldapctl_set_matching_option( LdapControl* ctl, const gint value ) { + if( value < LDAPCTL_MATCH_BEGINWITH ) { + ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; + } + else if( value > LDAPCTL_MATCH_CONTAINS ) { + ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; + } + else { + ctl->matchingOption = value; + } +} + /** * Specify search criteria list to be used. * \param ctl Control data object. @@ -259,6 +281,7 @@ void ldapctl_clear( LdapControl *ctl ) { ctl->maxEntries = 0; ctl->timeOut = 0; ctl->maxQueryAge = 0; + ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; } /** @@ -299,6 +322,7 @@ void ldapctl_default_values( LdapControl *ctl ) { ctl->maxEntries = LDAPCTL_MAX_ENTRIES; ctl->timeOut = LDAPCTL_DFL_TIMEOUT; ctl->maxQueryAge = LDAPCTL_DFL_QUERY_AGE; + ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; ldapctl_default_attributes( ctl ); } @@ -325,6 +349,7 @@ void ldapctl_print( const LdapControl *ctl, FILE *stream ) { fprintf( stream, "max entry: %d\n", ctl->maxEntries ); fprintf( stream, " timeout: %d\n", ctl->timeOut ); fprintf( stream, " max age: %d\n", ctl->maxQueryAge ); + fprintf( stream, "match opt: %d\n", ctl->matchingOption ); fprintf( stream, "crit list:\n" ); if( ctl->listCriteria ) { mgu_print_dlist( ctl->listCriteria, stream ); @@ -377,29 +402,56 @@ void ldapctl_copy( const LdapControl *ctlFrom, LdapControl *ctlTo ) { ctlTo->maxEntries = ctlFrom->maxEntries; ctlTo->timeOut = ctlFrom->timeOut; ctlTo->maxQueryAge = ctlFrom->maxQueryAge; + ctlTo->matchingOption = ctlFrom->matchingOption; /* Unlock */ pthread_mutex_unlock( ctlTo->mutexCtl ); pthread_mutex_unlock( ctlFrom->mutexCtl ); } +/** + * Search criteria fragment - two terms - begin with (default). + */ +static gchar *_criteria2BeginWith = "(&(givenName=%s*)(sn=%s*))"; + +/** + * Search criteria fragment - two terms - contains. + */ +static gchar *_criteria2Contains = "(&(givenName=*%s*)(sn=*%s*))"; + /** * Create an LDAP search criteria by parsing specified search term. The search * term may contain two names separated by the first embedded space found in * the search term. It is assumed that the two tokens are first name and last * name, or vice versa. An appropriate search criteria will be constructed. * - * \param searchTerm Reference to search term to process. + * \param searchTerm Reference to search term to process. + * \param matchOption Set to the following: + * + * * \return Formatted search criteria, or NULL if there is no * embedded spaces. The search term should be g_free() when no * longer required. */ -static gchar *ldapctl_build_ldap_criteria( gchar *searchTerm ) { +static gchar *ldapctl_build_ldap_criteria( + const gchar *searchTerm, const gint matchOption ) +{ gchar *p; gchar *t1; gchar *t2 = NULL; gchar *term; gchar *crit = NULL; + gchar *criteriaFmt; + + if( matchOption == LDAPCTL_MATCH_CONTAINS ) { + criteriaFmt = _criteria2Contains; + } + else { + criteriaFmt = _criteria2BeginWith; + } term = g_strdup( searchTerm ); g_strstrip( term ); @@ -420,8 +472,8 @@ static gchar *ldapctl_build_ldap_criteria( gchar *searchTerm ) { gchar *p1, *p2; g_strstrip( t2 ); - p1 = g_strdup_printf( "(&(givenName=%s*)(sn=%s*))", t1, t2 ); - p2 = g_strdup_printf( "(&(givenName=%s*)(sn=%s*))", t2, t1 ); + p1 = g_strdup_printf( criteriaFmt, t1, t2 ); + p2 = g_strdup_printf( criteriaFmt, t2, t1 ); crit = g_strdup_printf( "(&(|%s%s)(mail=*))", p1, p2 ); g_free( t2 ); @@ -432,6 +484,17 @@ static gchar *ldapctl_build_ldap_criteria( gchar *searchTerm ) { return crit; } + +/** + * Search criteria fragment - single term - begin with (default). + */ +static gchar *_criteriaBeginWith = "(%s=%s*)"; + +/** + * Search criteria fragment - single term - contains. + */ +static gchar *_criteriaContains = "(%s=*%s*)"; + /** * Build a formatted LDAP search criteria string from criteria list. * \param ctl Control object to process. @@ -441,14 +504,22 @@ static gchar *ldapctl_build_ldap_criteria( gchar *searchTerm ) { gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) { GList *node; gchar *p1, *p2, *retVal; + gchar *criteriaFmt; g_return_val_if_fail( ctl != NULL, NULL ); g_return_val_if_fail( searchVal != NULL, NULL ); /* Test whether there are more that one search terms */ - retVal = ldapctl_build_ldap_criteria( searchVal ); + retVal = ldapctl_build_ldap_criteria( searchVal, ctl->matchingOption ); if( retVal ) return retVal; + if( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) { + criteriaFmt = _criteriaContains; + } + else { + criteriaFmt = _criteriaBeginWith; + } + /* No - just a simple search */ /* p1 contains previous formatted criteria */ /* p2 contains next formatted criteria */ @@ -468,7 +539,7 @@ gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) { gchar *crit; /* Format query criteria */ - crit = g_strdup_printf( "(%s=%s*)", attr, searchVal ); + crit = g_strdup_printf( criteriaFmt, attr, searchVal ); /* Append to existing criteria */ g_free( p2 ); @@ -478,7 +549,7 @@ gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) { } else { /* First time through - Format query criteria */ - p2 = g_strdup_printf( "(%s=%s*)", attr, searchVal ); + p2 = g_strdup_printf( criteriaFmt, attr, searchVal ); } } diff --git a/src/ldapctrl.h b/src/ldapctrl.h index b5ffa37dc..568e90d7e 100644 --- a/src/ldapctrl.h +++ b/src/ldapctrl.h @@ -46,6 +46,12 @@ #define LDAPCTL_DFL_ATTR_LIST "mail, cn, givenName, sn" +/* + * Search matching options. + */ +#define LDAPCTL_MATCH_BEGINWITH 0 +#define LDAPCTL_MATCH_CONTAINS 1 + /* * Data structures. */ @@ -59,6 +65,7 @@ struct _LdapControl { gint maxEntries; gint timeOut; gint maxQueryAge; + gint matchingOption; gchar *attribEMail; gchar *attribCName; gchar *attribFName; @@ -77,6 +84,7 @@ void ldapctl_set_bind_password ( LdapControl* ctl, const gchar *value ); void ldapctl_set_max_entries ( LdapControl* ctl, const gint value ); void ldapctl_set_timeout ( LdapControl* ctl, const gint value ); void ldapctl_set_max_query_age ( LdapControl* ctl, const gint value ); +void ldapctl_set_matching_option( LdapControl* ctl, const gint value ); void ldapctl_set_criteria_list ( LdapControl* ctl, GList *value ); GList *ldapctl_get_criteria_list( const LdapControl* ctl ); void ldapctl_criteria_list_clear( LdapControl *ctl ); diff --git a/src/ldapquery.c b/src/ldapquery.c index 32a5f66f8..59f2d7566 100644 --- a/src/ldapquery.c +++ b/src/ldapquery.c @@ -710,11 +710,11 @@ static gint ldapqry_connect( LdapQuery *qry ) { gint rc; /* Initialize connection */ - printf( "===ldapqry_connect===\n" ); - ldapqry_print( qry, stdout ); + /* printf( "===ldapqry_connect===\n" ); */ + /* ldapqry_print( qry, stdout ); */ ctl = qry->control; - ldapctl_print( ctl, stdout ); - printf( "======\n" ); + /* ldapctl_print( ctl, stdout ); */ + /* printf( "======\n" ); */ ldapqry_touch( qry ); qry->startTime = qry->touchTime; qry->elapsedTime = -1; @@ -1356,6 +1356,10 @@ gint ldapqry_perform_locate( LdapQuery *qry ) { void ldapquery_remove_results( LdapQuery *qry ) { /* Set query as aged - will be retired on a later call */ ldapqry_set_aged_flag( qry, TRUE ); + /* + printf( "ldapquery_remove_results...\n" ); + printf( "testing busy flag...\n" ); + */ if( ldapqry_get_busy_flag( qry ) ) { /* Query is still busy - cancel query */ /* printf( "\tquery is still busy running...\n" ); */