Changeset

830:f160166612c2

Properly handle avatar/logo BINVALs Thanks to Petter Ericson for contributing the basis for this patch!
author Rob Hoelz <rob@hoelz.ro>
date Tue, 18 Sep 2012 00:29:28 +0200
parents 829:9c134ff07d0f
children 831:0c3638673464
files mod_storage_ldap/ldap/vcard.lib.lua
diffstat 1 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_storage_ldap/ldap/vcard.lib.lua	Tue Sep 18 00:16:12 2012 +0200
+++ b/mod_storage_ldap/ldap/vcard.lib.lua	Tue Sep 18 00:29:28 2012 +0200
@@ -15,10 +15,41 @@
 
 local builder_methods = {};
 
+local base64_encode = require('util.encodings').base64.encode;
+
 function builder_methods:addvalue(key, value)
     self.vcard:tag(key):text(value):up();
 end
 
+function builder_methods:addphotofield(tagname, format_section)
+    local record = self.record;
+    local format = self.format;
+    local vcard  = self.vcard;
+    local config = format[format_section];
+
+    if not config then
+        return;
+    end
+
+    if config.extval then
+        if record[config.extval] then
+            local tag = vcard:tag(tagname);
+            tag:tag('EXTVAL'):text(record[config.extval]):up();
+        end
+    elseif config.type and config.binval then
+        if record[config.binval] then
+            local tag = vcard:tag(tagname);
+            tag:tag('TYPE'):text(config.type):up();
+            tag:tag('BINVAL'):text(base64_encode(record[config.binval])):up();
+        end
+    else
+        module:log('error', 'You have an invalid %s config section', tagname);
+        return;
+    end
+
+    vcard:up();
+end
+
 function builder_methods:addregularfield(tagname, format_section)
     local record = self.record;
     local format = self.format;
@@ -73,7 +104,7 @@
     self:addvalue(              'FN',          record[format.displayname]);
     self:addregularfield(       'N',           'name');
     self:addvalue(              'NICKNAME',    record[format.nickname]);
-    self:addregularfield(       'PHOTO',       'photo');
+    self:addphotofield(         'PHOTO',       'photo');
     self:addvalue(              'BDAY',        record[format.birthday]);
     self:addmultisectionedfield('ADR',         'address');
     self:addvalue(              'LABEL',       nil); -- we don't support LABEL...yet.
@@ -85,7 +116,7 @@
     self:addregularfield(       'GEO',         'geo');
     self:addvalue(              'TITLE',       record[format.title]);
     self:addvalue(              'ROLE',        record[format.role]);
-    self:addregularfield(       'LOGO',        'logo');
+    self:addphotofield(         'LOGO',        'logo');
     self:addvalue(              'AGENT',       nil); -- we don't support AGENT...yet.
     self:addregularfield(       'ORG',         'org');
     self:addvalue(              'CATEGORIES',  nil); -- we don't support CATEGORIES...yet.