2007-10-24 [colin] 3.0.2cvs100
authorColin Leroy <colin@colino.net>
Wed, 24 Oct 2007 18:03:36 +0000 (18:03 +0000)
committerColin Leroy <colin@colino.net>
Wed, 24 Oct 2007 18:03:36 +0000 (18:03 +0000)
* src/editaddress.c
* src/editaddress_other_attributes_ldap.c
* src/editaddress_other_attributes_ldap.h
* src/ldapctrl.c
* src/ldapquery.c
* src/ldapupdate.c
Fix LDAP writing (got broken in cvs39)
Add read-only support for jpegPhoto LDAP field

ChangeLog
PATCHSETS
configure.ac
src/editaddress.c
src/editaddress_other_attributes_ldap.c
src/editaddress_other_attributes_ldap.h
src/ldapctrl.c
src/ldapquery.c
src/ldapupdate.c

index 26a8e0a..d201418 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-10-24 [colin]     3.0.2cvs100
+
+       * src/editaddress.c
+       * src/editaddress_other_attributes_ldap.c
+       * src/editaddress_other_attributes_ldap.h
+       * src/ldapctrl.c
+       * src/ldapquery.c
+       * src/ldapupdate.c
+               Fix LDAP writing (got broken in cvs39)
+               Add read-only support for jpegPhoto LDAP field
+
 2007-10-23 [colin]     3.0.2cvs99
 
        * src/news.c
index 9c155d3..83c762b 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.101.2.42 -r 1.101.2.43 src/news.c;  ) > 3.0.2cvs97.patchset
 ( cvs diff -u -r 1.13.2.17 -r 1.13.2.18 src/common/socket.h;  cvs diff -u -r 1.9.2.24 -r 1.9.2.25 src/common/ssl.c;  ) > 3.0.2cvs98.patchset
 ( cvs diff -u -r 1.101.2.43 -r 1.101.2.44 src/news.c;  ) > 3.0.2cvs99.patchset
+( cvs diff -u -r 1.14.2.41 -r 1.14.2.42 src/editaddress.c;  cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/editaddress_other_attributes_ldap.c;  cvs diff -u -r 1.1.2.6 -r 1.1.2.7 src/editaddress_other_attributes_ldap.h;  cvs diff -u -r 1.2.2.15 -r 1.2.2.16 src/ldapctrl.c;  cvs diff -u -r 1.3.2.27 -r 1.3.2.28 src/ldapquery.c;  cvs diff -u -r 1.1.2.15 -r 1.1.2.16 src/ldapupdate.c;  ) > 3.0.2cvs100.patchset
index ae77912..b6e2fcc 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=99
+EXTRA_VERSION=100
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 71420e1..344048f 100644 (file)
@@ -704,6 +704,9 @@ static void addressbook_edit_person_set_picture(void)
        gchar *filename;
        int width, height, scalewidth, scaleheight;
 
+       if (personeditdlg.ldap)
+               return;
+
        if ( (filename = filesel_select_file_open(_("Choose a picture"), NULL)) ) {
                GdkPixbuf *pixbuf = NULL;
                gdk_pixbuf_get_file_info(filename, &width, &height);
@@ -1423,6 +1426,7 @@ static gboolean addressbook_edit_person_close( gboolean cancelled )
                /* no callback, as we're discarding the form */
                edit_person_close_post_update_cb = NULL;
                addressbook_edit_person_flush_transient();
+               current_person = NULL;
 
                /* set focus to the address list (this is done by the post_update_cb usually) */
                addressbook_address_list_set_focus();
@@ -1464,21 +1468,34 @@ static gboolean addressbook_edit_person_close( gboolean cancelled )
 
                gchar *name;
                addritem_person_set_common_name( current_person, cn );
-               if (personeditdlg.picture_set) {
+               if (personeditdlg.picture_set) { 
                        GdkPixbuf * pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(personeditdlg.image));
-                       name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
-                                                       ADDRITEM_ID(current_person), ".png", NULL );
+
+                       if (!current_person->picture)
+                               name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                               ADDRITEM_ID(current_person), ".png", NULL );
+                       else 
+                               name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                               current_person->picture, ".png", NULL );
+
                        gdk_pixbuf_save(pixbuf, name, "png", &error, NULL);
                        if (error) {
                                alertpanel_error(_("Failed to save image: \n%s"),
                                                error->message);
                                g_error_free(error);
+                       } else {
+                               debug_print("saved picture to %s\n", name);
                        }
-                       addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
+                       if (!current_person->picture)
+                               addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
                        g_free( name );
                } else {
-                       name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
-                                                       ADDRITEM_ID(current_person), ".png", NULL );
+                       if (!current_person->picture)
+                               name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                               ADDRITEM_ID(current_person), ".png", NULL );
+                       else 
+                               name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
+                                               current_person->picture, ".png", NULL );
                        g_unlink(name);
                        g_free(name);
                }
@@ -1567,6 +1584,10 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
                if( ADDRITEM_NAME(current_person) )
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), ADDRITEM_NAME(person) );
 
+               menu_set_sensitive(personeditdlg.editaddr_popupfactory,
+                               "/Set picture", !personeditdlg.ldap);
+               menu_set_sensitive(personeditdlg.editaddr_popupfactory,
+                               "/Unset picture", !personeditdlg.ldap);
                if( current_person->picture ) { 
                        filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
                                                        current_person->picture, ".png", NULL );
@@ -1580,7 +1601,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
                                }
                                personeditdlg.picture_set = TRUE;
                                menu_set_sensitive(personeditdlg.editaddr_popupfactory,
-                                               "/Unset picture", personeditdlg.picture_set);
+                                               "/Unset picture", !personeditdlg.ldap && personeditdlg.picture_set);
                        } else {
                                goto no_img;
                        }
@@ -1589,6 +1610,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
 no_img:
                        addressbook_edit_person_clear_picture();
                }
+               
                g_free(filename);
                if (pixbuf) {
                        g_object_unref(pixbuf);
@@ -1626,15 +1648,15 @@ no_img:
        edit_person_attrib_clear( NULL );
 
        if (prefs_common.addressbook_use_editaddress_dialog) {
-
-       gtk_main();
+               gtk_main();
                gtk_widget_hide( personeditdlg.container );
 
-               if (!addressbook_edit_person_close( cancelled ))
+               if (!addressbook_edit_person_close( cancelled )) {
                        return NULL;
+               }
        }
-
-       return current_person;
+       
+       return person;
 }
 
 /*
index 9e6764e..f642851 100644 (file)
@@ -355,6 +355,10 @@ void addressbook_edit_person_page_attrib_ldap(PersonEditDlg *dialog, gint pageNu
        combo_box = gtk_combo_box_new_text();
 
        while (*attribute) {
+               if (!strcmp(*attribute, "jpegPhoto")) {
+                       attribute++;
+                       continue;
+               }
                gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), *attribute++);
        }
        gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), 0);
index 2c1c4d6..ed84371 100644 (file)
@@ -102,6 +102,7 @@ static const char *ATTRIBUTE[] = {
        "mobile",
        "pager",
        "roomNumber",
+       "jpegPhoto",
        NULL
 };
 
index aedd7d3..583a0b4 100644 (file)
@@ -634,7 +634,7 @@ char **ldapctl_full_attribute_array( LdapControl *ctl ) {
 
        node = tmp;
        cnt = g_list_length( tmp );
-       ptrArray = g_new0( char *, 1 + cnt );
+       ptrArray = g_new0( char *, 1 + cnt);
        i = 0;
        while( node ) {
                ptrArray[ i++ ] = node->data;
index 1da82a4..336a2bf 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <lber.h>
 
+#include "defs.h"
 #include "ldaputil.h"
 #include "ldapquery.h"
 #include "ldapctrl.h"
@@ -414,9 +415,19 @@ static GSList *ldapqry_add_single_value( LDAP *ld, LDAPMessage *entry, char *att
 
        if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
                if( vals[0] != NULL ) {
-                       debug_print("sv\t%s: %s\n", attr?attr:"null",
-                                       vals[0]->bv_val?vals[0]->bv_val:"null");
-                       list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len ));
+                       if (strcmp(attr, "jpegPhoto")) {
+                               debug_print("sv\t%s: %s\n", attr?attr:"null",
+                                               vals[0]->bv_val?vals[0]->bv_val:"null");
+                               list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len ));
+                       } else {
+                               char *file = get_tmp_file();
+                               FILE *fp = fopen(file, "wb");
+                               if (fp) {
+                                       fwrite(vals[0]->bv_val, 1, vals[0]->bv_len, fp);
+                                       fclose(fp);
+                               }
+                               list = g_slist_append( list, file);
+                       }
                }
        }
        ldap_value_free_len( vals );
@@ -455,6 +466,7 @@ static GList *ldapqry_build_items_fl(
        ItemPerson *person;
        ItemEMail *email;
        ItemFolder *folder;
+       gchar *picfile = NULL;
        GList *listReturn = NULL;
 
        folder = ADDRQUERY_FOLDER(qry);
@@ -511,7 +523,24 @@ static GList *ldapqry_build_items_fl(
        
        for (cur = attributes; cur; cur = cur->next) {
                UserAttribute *attrib = addritem_copy_attribute((UserAttribute *)cur->data);
-               addritem_person_add_attribute( person, attrib );
+               if (attrib->name && strcmp(attrib->name, "jpegPhoto")) {
+                       addritem_person_add_attribute( person, attrib );
+               } else {
+                       if (qry && qry->server && qry->server->control) {
+                               gchar *dir = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, 
+                                                       ADDRBOOK_DIR, G_DIR_SEPARATOR_S, NULL );
+                               gchar *filename = g_strdup_printf("%s-%s-%s",
+                                       qry->server->control->hostName?qry->server->control->hostName:"nohost", 
+                                       qry->server->control->baseDN?qry->server->control->baseDN:"nobase", 
+                                       dn);
+                               picfile = g_strdup_printf("%s%s.png", dir, filename);
+                               addritem_person_set_picture( person, filename );
+                               rename_force(attrib->value, picfile);
+                               g_free(filename);
+                               g_free(picfile);
+                               g_free(dir);
+                       }
+               }
        }
        
        addrcache_folder_add_person( cache, ADDRQUERY_FOLDER(qry), person );
index ad50aa1..5ef1360 100644 (file)
@@ -943,6 +943,10 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                         * If attributes are not part of the search criteria they would seem to hold
                         * no information since their values will not be populated in the GUI
                         */
+                       if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) {
+                               debug_print("not updating jpegPhoto\n");
+                               continue;
+                       }
                        if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) {
                                mod_op = ldapsvr_deside_operation(ld, server, dn, (char *) ATTRIBUTE[i], "");
                                if (mod_op == LDAP_MOD_DELETE) {
@@ -974,6 +978,10 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
        else {
                char **attribs = ldapctl_full_attribute_array(server->control);
                for (i = 0; i < ATTRIBUTE_SIZE; i++) {
+                       if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) {
+                               debug_print("not updating jpegPhoto\n");
+                               continue;
+                       }
                        if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) {
                                if (CHECKED_ATTRIBUTE[i] == FALSE) {
                                        AddrItemObject *aio = addrcache_get_object(server->addressCache, g_hash_table_lookup(contact , "uid"));