Fix LDAP.
authorMatch Grun <match@dimensional.com>
Wed, 5 Nov 2003 03:35:24 +0000 (03:35 +0000)
committerMatch Grun <match@dimensional.com>
Wed, 5 Nov 2003 03:35:24 +0000 (03:35 +0000)
ChangeLog.claws
configure.ac
src/ldapctrl.c
src/ldapctrl.h
src/ldapquery.c

index cdcc491cae90b8a204874ea21200deb058c8946f..32fc1770b73fb3fd56cf1b8449696627d027a385 100644 (file)
@@ -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"
index 3f95857446a6a2777f226467af5ed3598356ea0b..7773d897ecd7730489bb33b60f049b8de5fc020b 100644 (file)
@@ -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
index d11454d90bf10b183c8eb62a594e10e8b57fb2a3..391694b392a17204ccd81cbde7ff3b0ddd6a94df 100644 (file)
@@ -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:
+ * <ul>
+ * <li><code>LDAPCTL_MATCH_BEGINWITH</code> for "begins with" search</li>
+ * <li><code>LDAPCTL_MATCH_CONTAINS</code> for "contains" search</li>
+ * </ul>
+ */
+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:
+ * <ul>
+ * <li><code>LDAPCTL_MATCH_BEGINWITH</code> for "begins with" search</li>
+ * <li><code>LDAPCTL_MATCH_CONTAINS</code> for "contains" search</li>
+ * </ul>
+ *
  * \return Formatted search criteria, or <code>NULL</code> 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 );
                }
        }
 
index b5ffa37dc0499a4a521fd9feffc68ff007631dd5..568e90d7e67b3ecccc580f5f7d0a4a56e63d3449 100644 (file)
 
 #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 );
index 32a5f66f828ae692b8d2884afee4d1b22628b303..59f2d75664d624cd8ceb4b16d1d94a2bb2c142c5 100644 (file)
@@ -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" ); */