2007-08-21 [colin] 2.10.0cvs142
[claws.git] / src / editldap.c
index 3a424f3ce5c5e92e7117426b12241129e86ed955..6aa5af20d2576d8885374f6efed2bf152c31f29d 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
+ * 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,
@@ -13,8 +13,8 @@
  * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 /*
@@ -106,6 +106,7 @@ static gboolean editldap_validate_criteria( gchar *criteria ) {
                        *ptr = ' ';
                ptr++;
        }
+       debug_print("cleaned criteria list: %s\n", criteria);
 
        /* Parse string */
        splitStr = g_strsplit( criteria, " ", 0 );
@@ -242,6 +243,7 @@ static void edit_ldap_server_check( void ) {
        g_strchomp( sPass ); g_strchug( sPass );
        if( *sHost != '\0' ) {
                /* Test connection to server */
+               debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind);
                if( ldaputil_test_connect( sHost, iPort, ssl, tls ) ) {
                        /* Attempt to read base DN */
                        baseDN = ldaputil_read_basedn( sHost, iPort, sBind, sPass, iTime, ssl, tls );
@@ -266,6 +268,7 @@ static void edit_ldap_server_check( void ) {
 
        if( sBaseDN ) {
                /* Load search DN */
+               debug_print("baseDN: %s\n", sBaseDN);
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), sBaseDN);
                g_free( sBaseDN );
        }
@@ -299,6 +302,7 @@ static void edit_ldap_basedn_select( void ) {
        g_strchomp( sHost ); g_strchug( sHost );
        g_strchomp( sBind ); g_strchug( sBind );
        g_strchomp( sPass ); g_strchug( sPass );
+       debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind);
        selectDN = edit_ldap_basedn_selection( sHost, iPort, sBase, iTime, sBind, sPass, ssl, tls );
        if( selectDN ) {
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), selectDN);
@@ -311,8 +315,8 @@ static void edit_ldap_basedn_select( void ) {
        g_free( sPass );
 }
 
-static void edit_ldap_search_reset( void ) {
-       gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST );
+static void edit_ldap_search_reset(void) {
+       gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST);
 }
 
 static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
@@ -325,7 +329,8 @@ static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
        GtkWidget *hsbox;
        GtkWidget *statusbar;
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       debug_print("creating edit_ldap_dialog\n");
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editldap");
        gtk_widget_set_size_request(window, 450, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
        gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP Server"));
@@ -383,6 +388,7 @@ static void editldap_update_port (GtkToggleButton *ssl_btn, gpointer data) {
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), 
                        val ? LDAPCTL_DFL_SSL_PORT:LDAPCTL_DFL_PORT );
+       debug_print("Setting port: %d\n", val ? LDAPCTL_DFL_SSL_PORT:LDAPCTL_DFL_PORT);
 }
 
 static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
@@ -395,7 +401,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        GtkObject *spinbtn_port_adj;
        GtkWidget *spinbtn_port;
 #ifdef USE_LDAP_TLS
-       GtkWidget *enable_ssl_chkbtn, *enable_tls_chkbtn;
+       GtkWidget *enable_ssl_checkbtn, *enable_tls_checkbtn;
 #endif
        GtkWidget *entry_baseDN;
        GtkWidget *check_btn;
@@ -450,7 +456,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
                "\"ldap.mydomain.com\" may be appropriate for the " \
                "\"mydomain.com\" organization. An IP address may also be " \
                "used. You may specify \"localhost\" if running an LDAP " \
-               "server on the same computer as Sylpheed-Claws." ),
+               "server on the same computer as Claws Mail." ),
                NULL );
 
        /* Next row */
@@ -467,23 +473,23 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port), TRUE);
        
 #ifdef USE_LDAP_TLS
-       enable_tls_chkbtn = gtk_check_button_new_with_label(_("TLS"));
-       enable_ssl_chkbtn = gtk_check_button_new_with_label(_("SSL"));
-       SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_chkbtn, enable_ssl_chkbtn);
-       SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_chkbtn, enable_tls_chkbtn);
-       gtk_tooltips_set_tip( toolTip, enable_tls_chkbtn, _( 
+       enable_tls_checkbtn = gtk_check_button_new_with_label(_("TLS"));
+       enable_ssl_checkbtn = gtk_check_button_new_with_label(_("SSL"));
+       SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_checkbtn, enable_ssl_checkbtn);
+       SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_checkbtn, enable_tls_checkbtn);
+       gtk_tooltips_set_tip( toolTip, enable_tls_checkbtn, _( 
                "Enable secure connection to the LDAP server via TLS."
                "If connection fails, be sure to check the correct "
-               "configuration in ldap.conf (TLS_CACERT or TLS_CACERTDIR fields)." ),
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ),
                NULL );
-       gtk_tooltips_set_tip( toolTip, enable_ssl_chkbtn, _( 
+       gtk_tooltips_set_tip( toolTip, enable_ssl_checkbtn, _( 
                "Enable secure connection to the LDAP server via SSL."
                "If connection fails, be sure to check the correct "
-               "configuration in ldap.conf (TLS_CACERT or TLS_CACERTDIR fields)." ),
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ),
                NULL );
 
-       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_tls_chkbtn, TRUE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_ssl_chkbtn, TRUE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_tls_checkbtn, TRUE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_ssl_checkbtn, TRUE, FALSE, 0);
 #endif
 
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
@@ -517,7 +523,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_tooltips_set_tip( toolTip, entry_baseDN, _( 
                "This specifies the name of the directory to be searched " \
                "on the server. Examples include:\n" \
-               "  dc=sylpheed,dc=org\n" \
+               "  dc=claws-mail,dc=org\n" \
                "  ou=people,dc=domainname,dc=com\n" \
                "  o=Organization Name,c=Country\n"
                ),
@@ -546,10 +552,10 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        ldapedit.spinbtn_port = spinbtn_port;
        ldapedit.entry_baseDN = entry_baseDN;
 #ifdef USE_LDAP_TLS
-       ldapedit.enable_ssl = enable_ssl_chkbtn;
-       ldapedit.enable_tls = enable_tls_chkbtn;
+       ldapedit.enable_ssl = enable_ssl_checkbtn;
+       ldapedit.enable_tls = enable_tls_checkbtn;
 
-       g_signal_connect(G_OBJECT(enable_ssl_chkbtn), "toggled", \
+       g_signal_connect(G_OBJECT(enable_ssl_checkbtn), "toggled", \
                         G_CALLBACK(editldap_update_port), NULL); 
 #endif                  
 }
@@ -732,7 +738,7 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_tooltips_set_tip( toolTip, entry_bindDN, _( 
                "The LDAP user account name to be used to connect to the server. " \
                "This is usually only used for protected servers. This name " \
-               "is typically formatted as: \"cn=user,dc=sylpheed,dc=com\". " \
+               "is typically formatted as: \"cn=user,dc=claws-mail,dc=org\". " \
                "This is usually left empty when performing a search." ),
                NULL );
 
@@ -811,39 +817,6 @@ static void addressbook_edit_ldap_create( gboolean *cancelled ) {
        gtk_widget_show_all( ldapedit.window );
 }
 
-void edit_ldap_set_optmenu( GtkOptionMenu *optmenu, const gint value ) {
-       GList *cur;
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-       gint menuVal;
-       gint n = 0;
-
-       g_return_if_fail(optmenu != NULL);
-
-       menu = gtk_option_menu_get_menu(optmenu);
-       for( cur = GTK_MENU_SHELL(menu)->children; cur != NULL; cur = cur->next ) {
-               menuitem = GTK_WIDGET(cur->data);
-               menuVal = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
-               if( menuVal == value ) {
-                       gtk_option_menu_set_history(optmenu, n);
-                       return;
-               }
-               n++;
-       }
-       gtk_option_menu_set_history(optmenu, 0);
-}
-
-gint edit_ldap_get_optmenu( GtkOptionMenu *optmenu ) {
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-
-       g_return_val_if_fail(optmenu != NULL, -1);
-
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
-}
-
 /**
  * Format criteria list for display.
  * \param ctl Control object.
@@ -911,7 +884,7 @@ static void editldap_parse_criteria( gchar *criteria, LdapControl *ctl ) {
 /**
  * Clear entry fields to reasonable defaults (for a new server entry).
  */
-static void edit_ldap_clear_fields( void ) {
+static void edit_ldap_clear_fields(void) {
        gtk_entry_set_text(
                GTK_ENTRY(ldapedit.entry_name), ADDRESSBOOK_GUESS_LDAP_NAME );
        gtk_entry_set_text(
@@ -926,7 +899,7 @@ static void edit_ldap_clear_fields( void ) {
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ), LDAPCTL_DFL_TIMEOUT );
        gtk_entry_set_text(
-               GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST );
+               GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST);
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), LDAPCTL_DFL_QUERY_AGE );
        gtk_toggle_button_set_active(
@@ -966,8 +939,6 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        if( ctl->bindPass )
                gtk_entry_set_text(
                        GTK_ENTRY(ldapedit.entry_bindPW), ctl->bindPass );
-       gtk_spin_button_set_value(
-               GTK_SPIN_BUTTON(ldapedit.spinbtn_port), ctl->port );
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON(ldapedit.spinbtn_timeout), ctl->timeOut );
        gtk_spin_button_set_value(
@@ -978,6 +949,8 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        gtk_toggle_button_set_active(
                GTK_TOGGLE_BUTTON(ldapedit.enable_ssl), ctl->enableSSL );
 #endif
+       gtk_spin_button_set_value(
+               GTK_SPIN_BUTTON(ldapedit.spinbtn_port), ctl->port );
        /* Format criteria */
        crit = editldap_build_criteria_list( ctl );
        if( crit ) {
@@ -1071,6 +1044,7 @@ AdapterDSource *addressbook_edit_ldap(
        tls = gtk_toggle_button_get_active(
                        GTK_TOGGLE_BUTTON( ldapedit.enable_tls ) );
 #endif
+       debug_print("saving server config:\nname: %s\nhost: %s\nbase: %s\ncriteria: %s\nbind: %s\nport: %d\ntime: %d\nmax_entries: %d\ntimeout: %d\ndynamic: %d\ncheck_match: %d\n",sName, sHost, sBase, sCrit, sBind, iPort, iTime, iMaxE, iAge, bSrch, bMatch);
        fin = FALSE;
        if( *sName == '\0' ) fin = TRUE;
        if( *sHost == '\0' ) fin = TRUE;