Annotate

util/vcard.lua @ 316:03ad51d96858

plugins.vcard: Convert textual vCards to XEP-54 format
author Kim Alvefur <zash@zash.se>
date Thu, 11 Oct 2012 17:00:20 +0200
parent 311:de6e59e751eb
child 317:38562b0b50f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
298
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
1 -- Copyright (C) 2011-2012 Kim Alvefur
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 --
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- This project is MIT/X11 licensed. Please see the
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 --
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- TODO
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
8 -- Fix folding.
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
10 local st = require "util.stanza";
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local t_insert, t_concat = table.insert, table.concat;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local type = type;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local next, pairs, ipairs = next, pairs, ipairs;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
15 local from_text, to_text, from_xep54, to_xep54;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
16
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
17 local line_sep = "\n";
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
18
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
19 local vCard_dtd; -- See end of file
298
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
20
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
21 local function fold_line()
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
22 error "Not implemented" --TODO
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
23 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
24 local function unfold_line()
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
25 error "Not implemented"
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
26 -- gsub("\r?\n[ \t]([^\r\n])", "%1");
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
27 end
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 local function vCard_esc(s)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 return s:gsub("[,:;\\]", "\\%1"):gsub("\n","\\n");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local function vCard_unesc(s)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 return s:gsub("\\?[\\nt:;,]", {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 ["\\\\"] = "\\",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 ["\\n"] = "\n",
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
37 ["\\r"] = "\r",
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 ["\\t"] = "\t",
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
39 ["\\:"] = ":", -- FIXME Shouldn't need to espace : in values, just params
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 ["\\;"] = ";",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 ["\\,"] = ",",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 [":"] = "\29",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 [";"] = "\30",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 [","] = "\31",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 });
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
48 local function item_to_xep54(item)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
49 local t = st.stanza(item.name, { xmlns = "vcard-temp" });
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
50
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
51 local prop_def = vCard_dtd[item.name];
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
52 if prop_def == "text" then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
53 t:text(item[1]);
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
54 elseif type(prop_def) == "table" then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
55 if prop_def.types and item.TYPE then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
56 if type(item.TYPE) == "table" then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
57 for _,v in pairs(prop_def.types) do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
58 for _,typ in pairs(item.TYPE) do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
59 if typ:upper() == v then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
60 t:tag(v):up();
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
61 break;
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
65 else
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
66 t:tag(item.TYPE:upper()):up();
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
68 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
69
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
70 if prop_def.props then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
71 for _,v in pairs(prop_def.props) do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
72 if item[v] then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
73 t:tag(v):up();
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
76 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
77
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
78 if prop_def.value then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
79 t:tag(prop_def.value):text(item[1]):up();
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
80 elseif prop_def.values then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
81 local prop_def_values = prop_def.values;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
82 local repeat_last = prop_def_values.behaviour == "repeat-last" and prop_def_values[#prop_def_values];
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
83 for i=1,#item do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
84 t:tag(prop_def.values[i] or repeat_last):text(item[i]):up();
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
85 end
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
88
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
89 return t;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
90 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
91
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
92 local function vcard_to_xep54(vCard)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
93 local t = st.stanza("vCard", { xmlns = "vcard-temp" });
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
94 for i=1,#vCard do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
95 t:add_child(item_to_xep54(vCard[i]));
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
96 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
97 return t;
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
100 function to_xep54(vCards)
311
de6e59e751eb util.vcard: Handle empty vcards
Kim Alvefur <zash@zash.se>
parents: 310
diff changeset
101 if not vCards[1] or vCards[1].name then
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
102 return vcard_to_xep54(vCards)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
103 else
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
104 local t = st.stanza("xCard", { xmlns = "vcard-temp" });
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
105 for i=1,#vCards do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
106 t:add_child(vcard_to_xep54(vCards[i]));
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
107 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
108 return t;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
109 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
110 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
111
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
112 function from_text(data)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
113 data = data -- unfold and remove empty lines
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 :gsub("\r\n","\n")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 :gsub("\n ", "")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 :gsub("\n\n+","\n");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 local vCards = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 local c; -- current item
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 for line in data:gmatch("[^\n]+") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 local line = vCard_unesc(line);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 local name, params, value = line:match("^([-%a]+)(\30?[^\29]*)\29(.*)$");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 value = value:gsub("\29",":");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 if #params > 0 then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 local _params = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 for k,isval,v in params:gmatch("\30([^=]+)(=?)([^\30]*)") do
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
126 k = k:upper();
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 local _vt = {};
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
128 for _p in v:gmatch("[^\31]+") do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
129 _vt[#_vt+1]=_p
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 _vt[_p]=true;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
132 if isval == "=" then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
133 _params[k]=_vt;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
134 else
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
135 _params[k]=true;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
136 end
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 params = _params;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 if name == "BEGIN" and value == "VCARD" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 c = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 vCards[#vCards+1] = c;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 elseif name == "END" and value == "VCARD" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 c = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 elseif vCard_dtd[name] then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 local dtd = vCard_dtd[name];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 local p = { name = name };
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 c[#c+1]=p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 --c[name]=p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 local up = c;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 c = p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 if dtd.types then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 for _, t in ipairs(dtd.types) do
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
154 local t = t:lower();
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 if ( params.TYPE and params.TYPE[t] == true)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 or params[t] == true then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 c.TYPE=t;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 if dtd.props then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 for _, p in ipairs(dtd.props) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 if params[p] then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 if params[p] == true then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 c[p]=true;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 for _, prop in ipairs(params[p]) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 c[p]=prop;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 if dtd == "text" or dtd.value then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 t_insert(c, value);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 elseif dtd.values then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 local value = "\30"..value;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 for p in value:gmatch("\30([^\30]*)") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 t_insert(c, p);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 c = up;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 return vCards;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
188 local function item_to_text(item)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
189 local value = {};
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
190 for i=1,#item do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
191 value[i] = vCard_esc(item[i]);
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
192 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
193 value = t_concat(value, ";");
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
195 local params = "";
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
196 for k,v in pairs(item) do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
197 if type(k) == "string" and k ~= "name" then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
198 params = params .. (";%s=%s"):format(k, type(v) == "table" and t_concat(v,",") or v);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 return ("%s%s:%s"):format(item.name, params, value)
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
203 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
204
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
205 local function vcard_to_text(vcard)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
206 local t={};
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
207 t_insert(t, "BEGIN:VCARD")
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
208 for i=1,#vcard do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
209 t_insert(t, item_to_text(vcard[i]));
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
210 end
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
211 t_insert(t, "END:VCARD")
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
212 return t_concat(t, line_sep);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
215 function to_text(vCards)
311
de6e59e751eb util.vcard: Handle empty vcards
Kim Alvefur <zash@zash.se>
parents: 310
diff changeset
216 if vCards[1] and vCards[1].name then
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
217 return vcard_to_text(vCards)
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
218 else
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
219 local t = {};
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
220 for i=1,#vCards do
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
221 t[i]=vcard_to_text(vCards[i]);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
223 return t_concat(t, line_sep);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
227 local function from_xep54_item(item)
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 local prop_name = item.name;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 local prop_def = vCard_dtd[prop_name];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 local prop = { name = prop_name };
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 if prop_def == "text" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 prop[1] = item:get_text();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 elseif type(prop_def) == "table" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 if prop_def.value then --single item
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 prop[1] = item:get_child_text(prop_def.value) or "";
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 elseif prop_def.values then --array
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 local value_names = prop_def.values;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 if value_names.behaviour == "repeat-last" then
310
c3e2b95b5b0b util.vcard: Iterate on tags instead of items (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 307
diff changeset
241 for i=1,#item.tags do
c3e2b95b5b0b util.vcard: Iterate on tags instead of items (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 307
diff changeset
242 t_insert(prop, item.tags[i]:get_text() or "");
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 for i=1,#value_names do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 t_insert(prop, item:get_child_text(value_names[i]) or "");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249 elseif prop_def.names then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 local names = prop_def.names;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 for i=1,#names do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 if item:get_child(names[i]) then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 prop[1] = names[i];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 break;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 if prop_def.props_verbatim then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 for k,v in pairs(prop_def.props_verbatim) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 prop[k] = v;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 if prop_def.types then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 local types = prop_def.types;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 prop.TYPE = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 for i=1,#types do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 if item:get_child(types[i]) then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 t_insert(prop.TYPE, types[i]:lower());
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 if #prop.TYPE == 0 then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 prop.TYPE = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 -- A key-value pair, within a key-value pair?
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 if prop_def.props then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 local params = prop_def.props;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 for i=1,#params do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 local name = params[i]
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
283 local data = item:get_child_text(name);
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
284 if data then
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
285 prop[name] = prop[name] or {};
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
286 t_insert(prop[name], data);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 return nil
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 return prop;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
297 local function from_xep54_vCard(vCard)
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 local tags = vCard.tags;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 local t = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 for i=1,#tags do
307
9d295d44a16e util.vcard: Ignore undefined properties
Kim Alvefur <zash@zash.se>
parents: 306
diff changeset
301 t_insert(t, from_xep54_item(tags[i]));
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 return t
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
306 function from_xep54(vCard)
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307 if vCard.attr.xmlns ~= "vcard-temp" then
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
308 return nil, "wrong-xmlns";
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
309 end
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
310 if vCard.name == "xCard" then -- A collection of vCards
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 local t = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312 local vCards = vCard.tags;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 for i=1,#vCards do
307
9d295d44a16e util.vcard: Ignore undefined properties
Kim Alvefur <zash@zash.se>
parents: 306
diff changeset
314 t[i] = from_xep54_vCard(vCards[i]);
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
315 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
316 return t
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
317 elseif vCard.name == "vCard" then -- A single vCard
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
318 return from_xep54_vCard(vCard)
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
319 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
320 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
321
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
322 -- This was adapted from http://xmpp.org/extensions/xep-0054.html#dtd
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
323 vCard_dtd = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
324 VERSION = "text", --MUST be 3.0, so parsing is redundant
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
325 FN = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
326 N = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
327 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
328 "FAMILY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
329 "GIVEN",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
330 "MIDDLE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
331 "PREFIX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
332 "SUFFIX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
333 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
334 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
335 NICKNAME = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
336 PHOTO = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
337 props_verbatim = { ENCODING = { "b" } },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
338 props = { "TYPE" },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
339 value = "BINVAL", --{ "EXTVAL", },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
340 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
341 BDAY = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
342 ADR = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
343 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
344 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
345 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
346 "POSTAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
347 "PARCEL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
348 "DOM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
349 "INTL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
350 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
351 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
352 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
353 "POBOX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
354 "EXTADD",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
355 "STREET",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
356 "LOCALITY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
357 "REGION",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
358 "PCODE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
359 "CTRY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
360 }
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
361 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
362 LABEL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
363 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
364 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
365 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
366 "POSTAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
367 "PARCEL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
368 "DOM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
369 "INTL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
370 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
371 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
372 value = "LINE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
373 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
374 TEL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
375 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
376 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
377 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
378 "VOICE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
379 "FAX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
380 "PAGER",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
381 "MSG",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
382 "CELL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
383 "VIDEO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
384 "BBS",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
385 "MODEM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
386 "ISDN",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
387 "PCS",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
388 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
389 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
390 value = "NUMBER",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
391 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
392 EMAIL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
393 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
394 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
395 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
396 "INTERNET",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
397 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
398 "X400",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
399 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
400 value = "USERID",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
401 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
402 JABBERID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
403 MAILER = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
404 TZ = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
405 GEO = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
406 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
407 "LAT",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
408 "LON",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
409 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
410 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
411 TITLE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
412 ROLE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
413 LOGO = "copy of PHOTO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
414 AGENT = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
415 ORG = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
416 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
417 behaviour = "repeat-last",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
418 "ORGNAME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
419 "ORGUNIT",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
420 }
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
421 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
422 CATEGORIES = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
423 values = "KEYWORD",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
424 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
425 NOTE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426 PRODID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427 REV = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
428 SORTSTRING = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
429 SOUND = "copy of PHOTO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
430 UID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
431 URL = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
432 CLASS = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
433 names = { -- The item.name is the value if it's one of these.
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 "PUBLIC",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 "PRIVATE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
436 "CONFIDENTIAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
437 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
438 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
439 KEY = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
440 props = { "TYPE" },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 value = "CRED",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
442 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
443 DESC = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
444 };
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
445 vCard_dtd.LOGO = vCard_dtd.PHOTO;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
446 vCard_dtd.SOUND = vCard_dtd.PHOTO;
298
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
447
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
448 return {
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
449 from_text = from_text;
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
450 to_text = to_text;
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
451
298
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
452 from_xep54 = from_xep54;
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
453 to_xep54 = to_xep54;
306
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
454
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
455 -- COMPAT:
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
456 lua_to_text = to_text;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
457 lua_to_xep54 = to_xep54;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
458
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
459 text_to_lua = from_text;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
460 text_to_xep54 = function (...) return to_xep54(from_text(...)); end;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
461
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
462 xep54_to_lua = from_xep54;
c6183b218f77 util.vcard: Completed separation of parsers and generators
Kim Alvefur <zash@zash.se>
parents: 298
diff changeset
463 xep54_to_text = function (...) return to_text(from_xep54(...)) end;
298
1897dc6a07bb util.vcard: Don't use module()
Kim Alvefur <zash@zash.se>
parents: 227
diff changeset
464 };