Annotate

util/vcard.lua @ 268:06e6c6de6438

plugins.pep: Load disco, since PEP depends on it
author Kim Alvefur <zash@zash.se>
date Fri, 16 Dec 2011 22:04:03 +0100
parent 227:31019cb93d59
child 298:1897dc6a07bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
227
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Copyright (C) 2011 Kim Alvefur
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
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 -- function lua_to_xep54()
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 -- function lua_to_text()
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 -- replace text_to_xep54() and xep54_to_text() with intermediate lua?
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local st = verse or require "util.stanza";
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 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
14 local type = type;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 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
16
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 module "vcard"
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local vCard_dtd;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 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
22 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
23 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 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
26 return s:gsub("\\?[\\nt:;,]", {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 ["\\\\"] = "\\",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 ["\\n"] = "\n",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 ["\\t"] = "\t",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 ["\\:"] = ":",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 ["\\;"] = ";",
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 [":"] = "\29",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 [";"] = "\30",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 [","] = "\31",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 });
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 function text_to_xep54(data)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 --[[ TODO
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 return lua_to_xep54(text_to_lua(data));
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 --]]
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 data = data
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 :gsub("\r\n","\n")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 :gsub("\n ", "")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 :gsub("\n\n+","\n");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local c = st.stanza("xCard", { xmlns = "vcard-temp" });
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 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
49 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
50 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
51 value = value:gsub("\29",":");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 line = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 if params and #params > 0 then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 local _params = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 for k,isval,v in params:gmatch("\30([^=]+)(=?)([^\30]*)") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 local _vt = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 for _p in v:gmatch("[^\31]*") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 _vt[#_vt]=_p
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 _vt[_p]=true;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 _params[k]=isval == "" or _vt;
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 params = _params;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 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
66 c:tag("vCard", { xmlns = "vcard-temp" });
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 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
68 c:up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 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
70 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
71 c:tag(name);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 if dtd.types then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 for _, t in ipairs(dtd.types) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 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
75 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
76 c:tag(t):up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 if dtd.props then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 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
82 if params[p] then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 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
84 c:tag(p):up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 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
87 c:tag(p):text(prop):up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 if dtd == "text" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 c:text(value);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 elseif dtd.value then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 c:tag(dtd.value):text(value):up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 elseif dtd.values then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local values = dtd.values;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 local i = 1;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 local value = "\30"..value;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 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
102 c:tag(values[i]):text(p):up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 if i < #values then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 i = i + 1;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 c:up();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 return c;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 function text_to_lua(data) --table
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 data = data
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 :gsub("\r\n","\n")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 :gsub("\n ", "")
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 :gsub("\n\n+","\n");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 local vCards = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 local c; -- current item
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 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
122 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
123 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
124 value = value:gsub("\29",":");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 line = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 if #params > 0 then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 local _params = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 for k,isval,v in params:gmatch("\30([^=]+)(=?)([^\30]*)") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 local _vt = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 for _p in v:gmatch("[^\31]*") do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 _vt[#_vt]=_p
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 _vt[_p]=true;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 _params[k]=isval == "" or _vt;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 params = _params;
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 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
139 c = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 vCards[#vCards+1] = c;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 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
142 c = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 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
144 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
145 local p = { name = name };
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 c[#c+1]=p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 --c[name]=p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 local up = c;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 c = p;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 if dtd.types then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 for _, t in ipairs(dtd.types) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 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
153 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
154 c.TYPE=t;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 if dtd.props then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 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
160 if params[p] then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 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
162 c[p]=true;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 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
165 c[p]=prop;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 end
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 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
172 t_insert(c, value);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 elseif dtd.values then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 local value = "\30"..value;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 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
176 t_insert(c, p);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 c = up;
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 return vCards;
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
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 local function vCard_prop(item) -- single item staza object to text line
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 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
187 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
188 if not prop_def then return nil end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 local value, params = "", {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192 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
193 value = item:get_text();
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 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
195 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
196 value = 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
197 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
198 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
199 value = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 if value_names.behaviour == "repeat-last" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 for i=1,#item do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 t_insert(value, item[i]:get_text() or "");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205 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
206 t_insert(value, 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
207 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 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
210 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
211 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
212 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
213 value = names[i];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 break;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 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
220 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
221 params[k] = v;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 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
226 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
227 params.TYPE = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 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
229 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
230 t_insert(params.TYPE, types[i]:lower());
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 if #params.TYPE == 0 then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 params.TYPE = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 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
239 local props = prop_def.props;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 for i=1,#props do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 local prop = props[i]
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 local p = item:get_child_text(prop);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 if p then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 params[prop] = params[prop] or {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 t_insert(params[prop], p);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 end
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 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 return nil
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 if type(value) == "table" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 for i=1,#value do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 value[i]=vCard_esc(value[i]);
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 value = t_concat(value, ";");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 value = vCard_esc(value);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 if next(params) then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 local sparams = "";
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 for k,v in pairs(params) do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 sparams = sparams .. (";%s=%s"):format(k, t_concat(v,","));
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 params = sparams;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 params = "";
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 return ("%s%s:%s"):format(item.name, params, value)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 :gsub(("."):rep(75), "%0\r\n "):gsub("\r\n $","");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 function xep54_to_text(vCard)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 --[[ TODO
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 return lua_to_text(xep54_to_lua(vCard))
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 --]]
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 local r = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 t_insert(r, "BEGIN:VCARD");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 for i = 1,#vCard do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 local item = vCard[i];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 if item.name then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 local s = vCard_prop(item);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286 if s then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 t_insert(r, s);
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 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 t_insert(r, "END:VCARD");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 return t_concat(r, "\r\n");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 local function xep54_item_to_lua(item)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 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
297 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
298 if not prop_def then return nil end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 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
301
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 if value_names.behaviour == "repeat-last" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
310 for i=1,#item do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 t_insert(prop, item[i]:get_text() or "");
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
314 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
315 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
316 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
317 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
318 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
319 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
320 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
321 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
322 prop[1] = names[i];
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
323 break;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
324 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
325 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
326 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
327
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
328 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
329 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
330 prop[k] = v;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
331 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
332 end
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 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
335 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
336 prop.TYPE = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
337 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
338 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
339 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
340 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
341 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
342 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
343 prop.TYPE = nil;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
344 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
345 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
346
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
347 -- 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
348 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
349 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
350 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
351 local name = params[i]
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
352 local data = item:get_child_text(prop_name);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
353 if prop_text then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
354 prop[prop_name] = prop[prop_name] or {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
355 t_insert(prop[prop_name], prop_text);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
356 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
357 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
358 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
359 else
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
360 return nil
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
361 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
362
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
363 return prop;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
364 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
365
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
366 local function xep54_vCard_to_lua(vCard)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
367 local tags = vCard.tags;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
368 local t = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
369 for i=1,#tags do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
370 t[i] = xep54_item_to_lua(tags[i]);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
371 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
372 return t
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
373 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
374
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
375 function xep54_to_lua(vCard)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
376 if vCard.attr.xmlns ~= "vcard-temp" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
377 return false
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
378 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
379 if vCard.name == "xCard" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
380 local t = {};
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
381 local vCards = vCard.tags;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
382 for i=1,#vCards do
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
383 local ti = xep54_vCard_to_lua(vCards[i]);
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
384 t[i] = ti;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
385 --t[ti.name] = ti;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
386 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
387 return t
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
388 elseif vCard.name == "vCard" then
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
389 return xep54_vCard_to_lua(vCard)
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
390 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
391 end
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
392
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
393 -- 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
394 vCard_dtd = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
395 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
396 FN = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
397 N = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
398 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
399 "FAMILY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
400 "GIVEN",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
401 "MIDDLE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
402 "PREFIX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
403 "SUFFIX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
404 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
405 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
406 NICKNAME = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
407 PHOTO = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
408 props_verbatim = { ENCODING = { "b" } },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
409 props = { "TYPE" },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
410 value = "BINVAL", --{ "EXTVAL", },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
411 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
412 BDAY = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
413 ADR = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
414 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
415 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
416 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
417 "POSTAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
418 "PARCEL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
419 "DOM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
420 "INTL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
421 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
422 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
423 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
424 "POBOX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
425 "EXTADD",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426 "STREET",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427 "LOCALITY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
428 "REGION",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
429 "PCODE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
430 "CTRY",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
431 }
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
432 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
433 LABEL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
436 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
437 "POSTAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
438 "PARCEL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
439 "DOM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
440 "INTL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 "PREF",
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 value = "LINE",
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 TEL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
446 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
447 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
448 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
449 "VOICE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
450 "FAX",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
451 "PAGER",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
452 "MSG",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
453 "CELL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
454 "VIDEO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
455 "BBS",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
456 "MODEM",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
457 "ISDN",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
458 "PCS",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
459 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
460 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
461 value = "NUMBER",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
462 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
463 EMAIL = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
464 types = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
465 "HOME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
466 "WORK",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
467 "INTERNET",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
468 "PREF",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
469 "X400",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
470 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
471 value = "USERID",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
472 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
473 JABBERID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
474 MAILER = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
475 TZ = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
476 GEO = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
477 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
478 "LAT",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
479 "LON",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
480 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
481 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
482 TITLE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
483 ROLE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
484 LOGO = "copy of PHOTO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
485 AGENT = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
486 ORG = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
487 values = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
488 behaviour = "repeat-last",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
489 "ORGNAME",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
490 "ORGUNIT",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
491 }
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
492 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
493 CATEGORIES = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
494 values = "KEYWORD",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
495 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
496 NOTE = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
497 PRODID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
498 REV = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
499 SORTSTRING = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
500 SOUND = "copy of PHOTO",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
501 UID = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
502 URL = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
503 CLASS = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
504 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
505 "PUBLIC",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
506 "PRIVATE",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
507 "CONFIDENTIAL",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
508 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
509 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
510 KEY = {
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
511 props = { "TYPE" },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
512 value = "CRED",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
513 },
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
514 DESC = "text",
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
515 };
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
516 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
517 vCard_dtd.SOUND = vCard_dtd.PHOTO;
31019cb93d59 util.vcard: Add util for converting vCard3 to/from XEP 54
Kim Alvefur <zash@zash.se>
parents:
diff changeset
518 return _M