[Commits] ldap-plugin.c 1.12 1.13
miras at claws-mail.org
miras at claws-mail.org
Tue Dec 13 11:37:16 CET 2011
Update of /home/claws-mail/contacts/plugins/ldap
In directory claws-mail:/tmp/cvs-serv20680/plugins/ldap
Modified Files:
ldap-plugin.c
Log Message:
2011-12-13 [mir] 0.6.0cvs40
* plugins/ldap/ldap-plugin.c
* src/utils.c
* src/utils.h
Fix error when saving images as binary data.
RFC 4510 was somewhat vague in defining the
storage format for binary image data which
I wrongly interpreted in that way that binary
image data was to be stored base64 encoded.
Infact LDAP expects the raw image data and
will internally do the base64 encoding when
appropriate.
Index: ldap-plugin.c
===================================================================
RCS file: /home/claws-mail/contacts/plugins/ldap/ldap-plugin.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ldap-plugin.c 30 Nov 2011 02:12:18 -0000 1.12
+++ ldap-plugin.c 13 Dec 2011 10:37:14 -0000 1.13
@@ -971,7 +971,13 @@
}
}
else {
- value = g_strndup(vals[0]->bv_val, vals[0]->bv_len);
+ if (strcasecmp(attribute, "jpegPhoto") == 0) {
+ guchar* image = g_memdup(vals[0]->bv_val, vals[0]->bv_len);
+ value = jpeg_to_png_base64(image, vals[0]->bv_len);
+ g_free(image);
+ }
+ else
+ value = g_strndup(vals[0]->bv_val, vals[0]->bv_len);
debug_print("Found (other): %s->%s\n", attribute, value);
const gchar* key = ldap2native(attribute);
swap_data(contact->data, key, value);
@@ -1194,6 +1200,21 @@
} while(0)
/**
+ * For binary data
+ * \param mods Empty LDAPMod structure
+ * \param modarr Array with values to insert
+ * \param op Operation to perform on LDAP
+ * \param attr Attribute to insert
+ * \param strv Empty array which is NULL terminated
+ * \param val Value for attribute
+ */
+#define SETMODB(mods,modarr,op,attr,bval,val) \
+ do { (mods) = &(modarr); (modarr).mod_type=attr; \
+ (modarr).mod_op=op|LDAP_MOD_BVALUES;\
+ (bval)[0]=(val); (bval)[1]=NULL; (modarr).mod_bvalues=bval; \
+ } while(0)
+
+/**
* Creates a LDAPMod structure
*
* \param mods Empty LDAPMod structure
@@ -1335,15 +1356,19 @@
for (i = 0; NULL != mods[i]; i++) {
LDAPMod *mod = (LDAPMod *) mods[i];
- gchar **vals;
+ gchar** vals;
+ struct berval** bvals;
switch (mod->mod_op) {
case LDAP_MOD_ADD:
+ case LDAP_MOD_ADD|LDAP_MOD_BVALUES:
mod_op = g_strdup("ADD");
break;
case LDAP_MOD_REPLACE:
+ case LDAP_MOD_REPLACE|LDAP_MOD_BVALUES:
mod_op = g_strdup("MODIFY");
break;
case LDAP_MOD_DELETE:
+ case LDAP_MOD_DELETE|LDAP_MOD_BVALUES:
mod_op = g_strdup("DELETE");
break;
default: mod_op = g_strdup("UNKNOWN");
@@ -1351,10 +1376,20 @@
debug_print("Operation: %s\tType:%s\nValues:\n",
mod_op, mod->mod_type);
g_free(mod_op);
- vals = mod->mod_vals.modv_strvals;
- while (*vals) {
- debug_print("\t%s\n", *vals++);
- }
+ if ((mod->mod_op & LDAP_MOD_BVALUES) == LDAP_MOD_BVALUES) {
+ bvals = mod->mod_vals.modv_bvals;
+ while (*bvals) {
+ debug_print("\tSize: %d bytes\n", (*bvals)->bv_len);
+ debug_print("\t%s\n", (*bvals)->bv_val);
+ bvals += 1;
+ }
+ }
+ else {
+ vals = mod->mod_vals.modv_strvals;
+ while (*vals) {
+ debug_print("\t%s\n", *vals++);
+ }
+ }
}
}
@@ -1381,14 +1416,24 @@
static void mods_free(LDAPMod *mods[]) {
int i;
gchar** vals;
+ struct berval** bvals;
for (i = 0; NULL != mods[i]; i++) {
LDAPMod* mod = (LDAPMod *) mods[i];
g_free(mod->mod_type);
- vals = mod->mod_vals.modv_strvals;
- while (*vals) {
- g_free(*vals++);
- }
+ if ((mod->mod_op & LDAP_MOD_BVALUES) == LDAP_MOD_BVALUES) {
+ bvals = mod->mod_vals.modv_bvals;
+ while (*bvals) {
+ g_free((*bvals)->bv_val);
+ bvals += 1;
+ }
+ }
+ else {
+ vals = mod->mod_vals.modv_strvals;
+ while (*vals) {
+ g_free(*vals++);
+ }
+ }
}
}
@@ -1510,6 +1555,7 @@
LDAPMod *mods[size + 2]; /* including NULL and objects */
LDAPMod modarr[size + 2]; /* including NULL and objects */
gchar* attr[size + 1][2];
+ struct berval* battr[size + 1][2];
gchar** obj;
int rc;
gchar** emails = NULL;
@@ -1591,9 +1637,18 @@
AttribDef* def = (AttribDef *) cur->data;
AttribDef* res = (AttribDef *) g_hash_table_lookup(contact->data, def->attrib_name);
if (res) {
- const gchar* value = res->value.string;
- SETMOD(mods[row], modarr[row], LDAP_MOD_ADD, \
- g_strdup(native2ldap(def->attrib_name)), attr[row], g_strdup(value));
+ gchar* value;
+ if (strcasecmp(res->attrib_name, "image") == 0) {
+ struct berval jpeg;
+ jpeg.bv_val = (gchar *) g_base64_decode(res->value.string, &jpeg.bv_len);
+ SETMODB(mods[row], modarr[row], LDAP_MOD_ADD, \
+ g_strdup(native2ldap(def->attrib_name)), battr[row], &jpeg);
+ }
+ else {
+ value = g_strdup(res->value.string);
+ SETMOD(mods[row], modarr[row], LDAP_MOD_ADD, \
+ g_strdup(native2ldap(def->attrib_name)), attr[row], value);
+ }
row++;
}
}
@@ -1706,6 +1761,7 @@
LDAPMod *mods[size + 2]; // including NULL and objects
LDAPMod modarr[size + 2]; // including NULL and objects
gchar* attr[size + 1][2];
+ struct berval* battr[size + 1][2];
int rc;
gchar** emails = NULL;
@@ -1778,9 +1834,17 @@
/* Ignore - emails always modify */
}
else {
- SETMOD(mods[row], modarr[row], LDAP_MOD_ADD, \
- g_strdup(native2ldap(attrib->attrib_name)), \
- attr[row], g_strdup(attrib->value.string));
+ if (strcasecmp(attrib->attrib_name, "image") == 0) {
+ struct berval jpeg;
+ jpeg.bv_val = (gchar *) g_base64_decode(attrib->value.string, &jpeg.bv_len);
+ SETMODB(mods[row], modarr[row], LDAP_MOD_ADD, \
+ g_strdup(native2ldap(attrib->attrib_name)), battr[row], &jpeg);
+ }
+ else {
+ gchar* val = g_strdup(attrib->value.string);
+ SETMOD(mods[row], modarr[row], LDAP_MOD_ADD, \
+ g_strdup(native2ldap(attrib->attrib_name)), attr[row], val);
+ }
row++;
}
break;
@@ -1806,9 +1870,17 @@
num++;
}
else {
- SETMOD(mods[row], modarr[row], LDAP_MOD_REPLACE, \
- g_strdup(native2ldap(attrib->attrib_name)), \
- attr[row], g_strdup(attrib->value.string));
+ if (strcasecmp(attrib->attrib_name, "image") == 0) {
+ struct berval jpeg;
+ jpeg.bv_val = (gchar *) g_base64_decode(attrib->value.string, &jpeg.bv_len);
+ SETMODB(mods[row], modarr[row], LDAP_MOD_REPLACE, \
+ g_strdup(native2ldap(attrib->attrib_name)), battr[row], &jpeg);
+ }
+ else {
+ gchar* val = g_strdup(attrib->value.string);
+ SETMOD(mods[row], modarr[row], LDAP_MOD_REPLACE, \
+ g_strdup(native2ldap(attrib->attrib_name)), attr[row], val);
+ }
row++;
}
break;
More information about the Commits
mailing list