2007-08-21 [colin] 2.10.0cvs142
[claws.git] / src / ldapctrl.c
index 11b38b81efd2f34005f2dc9996963d01f1cfdf18..9207d3d583798f46ab778c39e4a9a335f6a1f5b7 100644 (file)
@@ -526,7 +526,6 @@ gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) {
        node = ctl->listCriteria;
        while( node ) {
                gchar *attr, *tmp;
        node = ctl->listCriteria;
        while( node ) {
                gchar *attr, *tmp;
-
                attr = node->data;
                node = g_list_next( node );
 
                attr = node->data;
                node = g_list_next( node );
 
@@ -571,25 +570,54 @@ gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) {
  * \return NULL terminated list.
  */
 char **ldapctl_attribute_array( LdapControl *ctl ) {
  * \return NULL terminated list.
  */
 char **ldapctl_attribute_array( LdapControl *ctl ) {
+       char **ptrArray;
+       GList *node;
+       gint cnt, i;
+       g_return_val_if_fail( ctl != NULL, NULL );
+
+       node = ctl->listCriteria;
+       cnt = g_list_length( ctl->listCriteria );
+       ptrArray = g_new0( char *, 1 + cnt );
+       i = 0;
+       while( node ) {
+               ptrArray[ i++ ] = node->data;
+               /*debug_print("adding search attribute: %s\n", (gchar *) node->data);*/
+               node = g_list_next( node );
+       }
+       ptrArray[ i ] = NULL;
+       return ptrArray;
+}
+
+/**
+ * Return array of pointers to attributes for LDAP query.
+ * \param  ctl  Control object to process.
+ * \return NULL terminated list.
+ */
+char **ldapctl_full_attribute_array( LdapControl *ctl ) {
        char **ptrArray;
        GList *node, *def;
        char **ptrArray;
        GList *node, *def;
+       GList *tmp = NULL;
        gint cnt, i;
        g_return_val_if_fail( ctl != NULL, NULL );
 
        gint cnt, i;
        g_return_val_if_fail( ctl != NULL, NULL );
 
+       def = ctl->listCriteria;
+       while (def) {
+               tmp = g_list_append(tmp, g_strdup(def->data));
+               def = def->next;
+       }
+
        def = ldapctl_get_default_criteria_list();
        def = ldapctl_get_default_criteria_list();
-       /* check if this servers config is updated to the new
-        * default list of search criteria. If not update the list */
-       if (! ldapctl_compare_list(ctl->listCriteria, def)) {
-               /* Deep copy search criteria */
-               ldapctl_criteria_list_clear(ctl);
-               while(def) {
-                       ctl->listCriteria = g_list_append(
-                               ctl->listCriteria, g_strdup(def->data));
-                       def = g_list_next(def);
+       
+       while (def) {
+               if( g_list_find_custom(tmp, (gpointer)def->data, 
+                               (GCompareFunc)strcmp2) == NULL) {
+                       tmp = g_list_append(tmp, g_strdup(def->data));
                }
                }
+               def = def->next;
        }
        }
-       node = ctl->listCriteria;
-       cnt = g_list_length( ctl->listCriteria );
+
+       node = tmp;
+       cnt = g_list_length( tmp );
        ptrArray = g_new0( char *, 1 + cnt );
        i = 0;
        while( node ) {
        ptrArray = g_new0( char *, 1 + cnt );
        i = 0;
        while( node ) {
@@ -664,11 +692,13 @@ void ldapctl_parse_ldap_search( LdapControl *ctl, gchar *criteria ) {
  * \return Formatted string or <i>""</i>. Should be g_free() when done.
  */
 gchar *ldapctl_get_default_criteria() {
  * \return Formatted string or <i>""</i>. Should be g_free() when done.
  */
 gchar *ldapctl_get_default_criteria() {
-       gchar *retVal = LDAPCTL_DFL_ATTR_LIST;
+       gchar *retVal = g_strdup(LDAPCTL_DFL_ATTR_LIST);
        const gchar **attrs = ATTRIBUTE; 
 
        while (*attrs) {
        const gchar **attrs = ATTRIBUTE; 
 
        while (*attrs) {
-               retVal = g_strdup_printf("%s, %s", retVal, *attrs++);
+               gchar *tmp = g_strdup_printf("%s, %s", retVal, *attrs++);
+               g_free(retVal);
+               retVal = tmp;
        }
        debug_print("default search criteria: %s\n", retVal);
        return retVal;
        }
        debug_print("default search criteria: %s\n", retVal);
        return retVal;