comparison mod_storage_ldap/ldap/vcard.lib.lua @ 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 1d51c5e38faa
children
comparison
equal deleted inserted replaced
829:9c134ff07d0f 830:f160166612c2
13 13
14 local VCARD_NS = 'vcard-temp'; 14 local VCARD_NS = 'vcard-temp';
15 15
16 local builder_methods = {}; 16 local builder_methods = {};
17 17
18 local base64_encode = require('util.encodings').base64.encode;
19
18 function builder_methods:addvalue(key, value) 20 function builder_methods:addvalue(key, value)
19 self.vcard:tag(key):text(value):up(); 21 self.vcard:tag(key):text(value):up();
22 end
23
24 function builder_methods:addphotofield(tagname, format_section)
25 local record = self.record;
26 local format = self.format;
27 local vcard = self.vcard;
28 local config = format[format_section];
29
30 if not config then
31 return;
32 end
33
34 if config.extval then
35 if record[config.extval] then
36 local tag = vcard:tag(tagname);
37 tag:tag('EXTVAL'):text(record[config.extval]):up();
38 end
39 elseif config.type and config.binval then
40 if record[config.binval] then
41 local tag = vcard:tag(tagname);
42 tag:tag('TYPE'):text(config.type):up();
43 tag:tag('BINVAL'):text(base64_encode(record[config.binval])):up();
44 end
45 else
46 module:log('error', 'You have an invalid %s config section', tagname);
47 return;
48 end
49
50 vcard:up();
20 end 51 end
21 52
22 function builder_methods:addregularfield(tagname, format_section) 53 function builder_methods:addregularfield(tagname, format_section)
23 local record = self.record; 54 local record = self.record;
24 local format = self.format; 55 local format = self.format;
71 102
72 self:addvalue( 'VERSION', '2.0'); 103 self:addvalue( 'VERSION', '2.0');
73 self:addvalue( 'FN', record[format.displayname]); 104 self:addvalue( 'FN', record[format.displayname]);
74 self:addregularfield( 'N', 'name'); 105 self:addregularfield( 'N', 'name');
75 self:addvalue( 'NICKNAME', record[format.nickname]); 106 self:addvalue( 'NICKNAME', record[format.nickname]);
76 self:addregularfield( 'PHOTO', 'photo'); 107 self:addphotofield( 'PHOTO', 'photo');
77 self:addvalue( 'BDAY', record[format.birthday]); 108 self:addvalue( 'BDAY', record[format.birthday]);
78 self:addmultisectionedfield('ADR', 'address'); 109 self:addmultisectionedfield('ADR', 'address');
79 self:addvalue( 'LABEL', nil); -- we don't support LABEL...yet. 110 self:addvalue( 'LABEL', nil); -- we don't support LABEL...yet.
80 self:addmultisectionedfield('TEL', 'telephone'); 111 self:addmultisectionedfield('TEL', 'telephone');
81 self:addmultisectionedfield('EMAIL', 'email'); 112 self:addmultisectionedfield('EMAIL', 'email');
83 self:addvalue( 'MAILER', record[format.mailer]); 114 self:addvalue( 'MAILER', record[format.mailer]);
84 self:addvalue( 'TZ', record[format.timezone]); 115 self:addvalue( 'TZ', record[format.timezone]);
85 self:addregularfield( 'GEO', 'geo'); 116 self:addregularfield( 'GEO', 'geo');
86 self:addvalue( 'TITLE', record[format.title]); 117 self:addvalue( 'TITLE', record[format.title]);
87 self:addvalue( 'ROLE', record[format.role]); 118 self:addvalue( 'ROLE', record[format.role]);
88 self:addregularfield( 'LOGO', 'logo'); 119 self:addphotofield( 'LOGO', 'logo');
89 self:addvalue( 'AGENT', nil); -- we don't support AGENT...yet. 120 self:addvalue( 'AGENT', nil); -- we don't support AGENT...yet.
90 self:addregularfield( 'ORG', 'org'); 121 self:addregularfield( 'ORG', 'org');
91 self:addvalue( 'CATEGORIES', nil); -- we don't support CATEGORIES...yet. 122 self:addvalue( 'CATEGORIES', nil); -- we don't support CATEGORIES...yet.
92 self:addvalue( 'NOTE', record[format.note]); 123 self:addvalue( 'NOTE', record[format.note]);
93 self:addvalue( 'PRODID', nil); -- we don't support PRODID...yet. 124 self:addvalue( 'PRODID', nil); -- we don't support PRODID...yet.