Software /
code /
prosody
Comparison
util/vcard.lua @ 9059:e1db06a0cc6b
util.vcard: Use the new :text_tag API in more places
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 26 Jul 2018 00:17:23 +0200 |
parent | 9058:35421a289a75 |
child | 11727:f3aee8a825cc |
comparison
equal
deleted
inserted
replaced
9058:35421a289a75 | 9059:e1db06a0cc6b |
---|---|
69 end | 69 end |
70 end | 70 end |
71 end | 71 end |
72 | 72 |
73 if prop_def.value then | 73 if prop_def.value then |
74 t:tag(prop_def.value):text(item[1]):up(); | 74 t:text_tag(prop_def.value, item[1]); |
75 elseif prop_def.values then | 75 elseif prop_def.values then |
76 local prop_def_values = prop_def.values; | 76 local prop_def_values = prop_def.values; |
77 local repeat_last = prop_def_values.behaviour == "repeat-last" and prop_def_values[#prop_def_values]; | 77 local repeat_last = prop_def_values.behaviour == "repeat-last" and prop_def_values[#prop_def_values]; |
78 for i=1,#item do | 78 for i=1,#item do |
79 t:tag(prop_def.values[i] or repeat_last):text(item[i]):up(); | 79 t:text_tag(prop_def.values[i] or repeat_last, item[i]); |
80 end | 80 end |
81 end | 81 end |
82 end | 82 end |
83 | 83 |
84 return t; | 84 return t; |
316 | 316 |
317 function vcard4:text(node, params, value) -- luacheck: ignore 212/params | 317 function vcard4:text(node, params, value) -- luacheck: ignore 212/params |
318 self:tag(node:lower()) | 318 self:tag(node:lower()) |
319 -- FIXME params | 319 -- FIXME params |
320 if type(value) == "string" then | 320 if type(value) == "string" then |
321 self:tag("text"):text(value):up() | 321 self:text_tag("text", value); |
322 elseif vcard4[node] then | 322 elseif vcard4[node] then |
323 vcard4[node](value); | 323 vcard4[node](value); |
324 end | 324 end |
325 self:up(); | 325 self:up(); |
326 end | 326 end |
327 | 327 |
328 function vcard4.N(value) | 328 function vcard4.N(value) |
329 for i, k in ipairs(vCard_dtd.N.values) do | 329 for i, k in ipairs(vCard_dtd.N.values) do |
330 value:tag(k):text(value[i]):up(); | 330 value:text_tag(k, value[i]); |
331 end | 331 end |
332 end | 332 end |
333 | 333 |
334 local xmlns_vcard4 = "urn:ietf:params:xml:ns:vcard-4.0" | 334 local xmlns_vcard4 = "urn:ietf:params:xml:ns:vcard-4.0" |
335 | 335 |
337 local typ = item.name:lower(); | 337 local typ = item.name:lower(); |
338 local t = st.stanza(typ, { xmlns = xmlns_vcard4 }); | 338 local t = st.stanza(typ, { xmlns = xmlns_vcard4 }); |
339 | 339 |
340 local prop_def = vCard4_dtd[typ]; | 340 local prop_def = vCard4_dtd[typ]; |
341 if prop_def == "text" then | 341 if prop_def == "text" then |
342 t:tag("text"):text(item[1]):up(); | 342 t:text_tag("text", item[1]); |
343 elseif prop_def == "uri" then | 343 elseif prop_def == "uri" then |
344 if item.ENCODING and item.ENCODING[1] == 'b' then | 344 if item.ENCODING and item.ENCODING[1] == 'b' then |
345 t:tag("uri"):text("data:;base64,"):text(item[1]):up(); | 345 t:text_tag("uri", "data:;base64," .. item[1]); |
346 else | 346 else |
347 t:tag("uri"):text(item[1]):up(); | 347 t:text_tag("uri", item[1]); |
348 end | 348 end |
349 elseif type(prop_def) == "table" then | 349 elseif type(prop_def) == "table" then |
350 if prop_def.values then | 350 if prop_def.values then |
351 for i, v in ipairs(prop_def.values) do | 351 for i, v in ipairs(prop_def.values) do |
352 t:tag(v:lower()):text(item[i] or ""):up(); | 352 t:text_tag(v:lower(), item[i]); |
353 end | 353 end |
354 else | 354 else |
355 t:tag("unsupported",{xmlns="http://zash.se/protocol/vcardlib"}) | 355 t:tag("unsupported",{xmlns="http://zash.se/protocol/vcardlib"}) |
356 end | 356 end |
357 else | 357 else |