Annotate

util/vcard.lua @ 8874:d6eb910a204d

util.sasl.anonymous: Shorter!
author Kim Alvefur <zash@zash.se>
date Wed, 06 Jun 2018 00:18:59 +0200
parent 8382:e5d00bf4a4d5
child 9058:35421a289a75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Copyright (C) 2011-2014 Kim Alvefur
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 --
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- This project is MIT/X11 licensed. Please see the
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 --
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- TODO
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 -- Fix folding.
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local st = require "util.stanza";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local t_insert, t_concat = table.insert, table.concat;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local type = type;
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
13 local pairs, ipairs = pairs, ipairs;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local from_text, to_text, from_xep54, to_xep54;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local line_sep = "\n";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local vCard_dtd; -- See end of file
6265
f8945a030bc6 util.vcard: Add missing local declaration
Kim Alvefur <zash@zash.se>
parents: 6263
diff changeset
20 local vCard4_dtd;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local function vCard_esc(s)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 return s:gsub("[,:;\\]", "\\%1"):gsub("\n","\\n");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local function vCard_unesc(s)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 return s:gsub("\\?[\\nt:;,]", {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 ["\\\\"] = "\\",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 ["\\n"] = "\n",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 ["\\r"] = "\r",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 ["\\t"] = "\t",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 ["\\:"] = ":", -- FIXME Shouldn't need to espace : in values, just params
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 ["\\;"] = ";",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 ["\\,"] = ",",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 [":"] = "\29",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 [";"] = "\30",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 [","] = "\31",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local function item_to_xep54(item)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 local t = st.stanza(item.name, { xmlns = "vcard-temp" });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local prop_def = vCard_dtd[item.name];
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 if prop_def == "text" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 t:text(item[1]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 elseif type(prop_def) == "table" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 if prop_def.types and item.TYPE then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 if type(item.TYPE) == "table" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 for _,v in pairs(prop_def.types) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 for _,typ in pairs(item.TYPE) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if typ:upper() == v then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 t:tag(v):up();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 break;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 t:tag(item.TYPE:upper()):up();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 if prop_def.props then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 for _,v in pairs(prop_def.props) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 if item[v] then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 t:tag(v):up();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 if prop_def.value then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 t:tag(prop_def.value):text(item[1]):up();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 elseif prop_def.values then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 local prop_def_values = prop_def.values;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 local repeat_last = prop_def_values.behaviour == "repeat-last" and prop_def_values[#prop_def_values];
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 for i=1,#item do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 t:tag(prop_def.values[i] or repeat_last):text(item[i]):up();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 local function vcard_to_xep54(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 local t = st.stanza("vCard", { xmlns = "vcard-temp" });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 for i=1,#vCard do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 t:add_child(item_to_xep54(vCard[i]));
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 function to_xep54(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 if not vCards[1] or vCards[1].name then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 return vcard_to_xep54(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 local t = st.stanza("xCard", { xmlns = "vcard-temp" });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 t:add_child(vcard_to_xep54(vCards[i]));
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 function from_text(data)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 data = data -- unfold and remove empty lines
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 :gsub("\r\n","\n")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 :gsub("\n ", "")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 :gsub("\n\n+","\n");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 local vCards = {};
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
111 local current;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 for line in data:gmatch("[^\n]+") do
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
113 line = vCard_unesc(line);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 local name, params, value = line:match("^([-%a]+)(\30?[^\29]*)\29(.*)$");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 value = value:gsub("\29",":");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 if #params > 0 then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 local _params = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 for k,isval,v in params:gmatch("\30([^=]+)(=?)([^\30]*)") do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 k = k:upper();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 local _vt = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 for _p in v:gmatch("[^\31]+") do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 _vt[#_vt+1]=_p
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 _vt[_p]=true;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 if isval == "=" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 _params[k]=_vt;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 _params[k]=true;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 params = _params;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 if name == "BEGIN" and value == "VCARD" then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
134 current = {};
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
135 vCards[#vCards+1] = current;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 elseif name == "END" and value == "VCARD" then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
137 current = nil;
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
138 elseif current and vCard_dtd[name] then
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 local dtd = vCard_dtd[name];
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
140 local item = { name = name };
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
141 t_insert(current, item);
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
142 local up = current;
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
143 current = item;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 if dtd.types then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 for _, t in ipairs(dtd.types) do
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
146 t = t:lower();
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 if ( params.TYPE and params.TYPE[t] == true)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 or params[t] == true then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
149 current.TYPE=t;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 if dtd.props then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 for _, p in ipairs(dtd.props) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 if params[p] then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 if params[p] == true then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
157 current[p]=true;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 for _, prop in ipairs(params[p]) do
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
160 current[p]=prop;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 if dtd == "text" or dtd.value then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
167 t_insert(current, value);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 elseif dtd.values then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
169 for p in ("\30"..value):gmatch("\30([^\30]*)") do
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
170 t_insert(current, p);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 end
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
173 current = up;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 return vCards;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 local function item_to_text(item)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 local value = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 for i=1,#item do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 value[i] = vCard_esc(item[i]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 value = t_concat(value, ";");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 local params = "";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187 for k,v in pairs(item) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 if type(k) == "string" and k ~= "name" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 params = params .. (";%s=%s"):format(k, type(v) == "table" and t_concat(v,",") or v);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 return ("%s%s:%s"):format(item.name, params, value)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196 local function vcard_to_text(vcard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197 local t={};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 t_insert(t, "BEGIN:VCARD")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 for i=1,#vcard do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 t_insert(t, item_to_text(vcard[i]));
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 t_insert(t, "END:VCARD")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 return t_concat(t, line_sep);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 function to_text(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207 if vCards[1] and vCards[1].name then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 return vcard_to_text(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 t[i]=vcard_to_text(vCards[i]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 return t_concat(t, line_sep);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218 local function from_xep54_item(item)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 local prop_name = item.name;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220 local prop_def = vCard_dtd[prop_name];
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 local prop = { name = prop_name };
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 if prop_def == "text" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 prop[1] = item:get_text();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226 elseif type(prop_def) == "table" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 if prop_def.value then --single item
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 prop[1] = item:get_child_text(prop_def.value) or "";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 elseif prop_def.values then --array
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230 local value_names = prop_def.values;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 if value_names.behaviour == "repeat-last" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 for i=1,#item.tags do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 t_insert(prop, item.tags[i]:get_text() or "");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 for i=1,#value_names do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 t_insert(prop, item:get_child_text(value_names[i]) or "");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 elseif prop_def.names then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 local names = prop_def.names;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 for i=1,#names do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 if item:get_child(names[i]) then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 prop[1] = names[i];
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 break;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 if prop_def.props_verbatim then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 for k,v in pairs(prop_def.props_verbatim) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 prop[k] = v;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 if prop_def.types then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257 local types = prop_def.types;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 prop.TYPE = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 for i=1,#types do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 if item:get_child(types[i]) then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 t_insert(prop.TYPE, types[i]:lower());
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 if #prop.TYPE == 0 then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 prop.TYPE = nil;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 -- A key-value pair, within a key-value pair?
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 if prop_def.props then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 local params = prop_def.props;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 for i=1,#params do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 local name = params[i]
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 local data = item:get_child_text(name);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 if data then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 prop[name] = prop[name] or {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 t_insert(prop[name], data);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 return nil
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 return prop;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 local function from_xep54_vCard(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 local tags = vCard.tags;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 for i=1,#tags do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 t_insert(t, from_xep54_item(tags[i]));
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 return t
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 function from_xep54(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 if vCard.attr.xmlns ~= "vcard-temp" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 return nil, "wrong-xmlns";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 if vCard.name == "xCard" then -- A collection of vCards
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 local vCards = vCard.tags;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305 t[i] = from_xep54_vCard(vCards[i]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
306 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307 return t
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
308 elseif vCard.name == "vCard" then -- A single vCard
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
309 return from_xep54_vCard(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
310 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
313 local vcard4 = { }
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
314
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
315 function vcard4:text(node, params, value) -- luacheck: ignore 212/params
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
316 self:tag(node:lower())
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
317 -- FIXME params
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
318 if type(value) == "string" then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
319 self:tag("text"):text(value):up()
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
320 elseif vcard4[node] then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
321 vcard4[node](value);
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
322 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
323 self:up();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
324 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
325
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
326 function vcard4.N(value)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
327 for i, k in ipairs(vCard_dtd.N.values) do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
328 value:tag(k):text(value[i]):up();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
329 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
330 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
331
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
332 local xmlns_vcard4 = "urn:ietf:params:xml:ns:vcard-4.0"
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
333
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
334 local function item_to_vcard4(item)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
335 local typ = item.name:lower();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
336 local t = st.stanza(typ, { xmlns = xmlns_vcard4 });
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
337
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
338 local prop_def = vCard4_dtd[typ];
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
339 if prop_def == "text" then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
340 t:tag("text"):text(item[1]):up();
6308
94c3cf8293a7 util.vcard: Add support for uri types in vcard4
Kim Alvefur <zash@zash.se>
parents: 6265
diff changeset
341 elseif prop_def == "uri" then
6400
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
342 if item.ENCODING and item.ENCODING[1] == 'b' then
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
343 t:tag("uri"):text("data:;base64,"):text(item[1]):up();
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
344 else
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
345 t:tag("uri"):text(item[1]):up();
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
346 end
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
347 elseif type(prop_def) == "table" then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
348 if prop_def.values then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
349 for i, v in ipairs(prop_def.values) do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
350 t:tag(v:lower()):text(item[i] or ""):up();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
351 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
352 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
353 t:tag("unsupported",{xmlns="http://zash.se/protocol/vcardlib"})
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
354 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
355 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
356 t:tag("unsupported",{xmlns="http://zash.se/protocol/vcardlib"})
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
357 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
358 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
359 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
360
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
361 local function vcard_to_vcard4xml(vCard)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
362 local t = st.stanza("vcard", { xmlns = xmlns_vcard4 });
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
363 for i=1,#vCard do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
364 t:add_child(item_to_vcard4(vCard[i]));
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
365 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
366 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
367 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
368
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
369 local function vcards_to_vcard4xml(vCards)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
370 if not vCards[1] or vCards[1].name then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
371 return vcard_to_vcard4xml(vCards)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
372 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
373 local t = st.stanza("vcards", { xmlns = xmlns_vcard4 });
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
374 for i=1,#vCards do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
375 t:add_child(vcard_to_vcard4xml(vCards[i]));
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
376 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
377 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
378 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
379 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
380
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
381 -- This was adapted from http://xmpp.org/extensions/xep-0054.html#dtd
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
382 vCard_dtd = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
383 VERSION = "text", --MUST be 3.0, so parsing is redundant
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
384 FN = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
385 N = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
386 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
387 "FAMILY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
388 "GIVEN",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
389 "MIDDLE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
390 "PREFIX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
391 "SUFFIX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
392 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
393 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
394 NICKNAME = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
395 PHOTO = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
396 props_verbatim = { ENCODING = { "b" } },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
397 props = { "TYPE" },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
398 value = "BINVAL", --{ "EXTVAL", },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
399 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
400 BDAY = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
401 ADR = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
402 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
403 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
404 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
405 "POSTAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
406 "PARCEL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
407 "DOM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
408 "INTL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
409 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
410 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
411 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
412 "POBOX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
413 "EXTADD",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
414 "STREET",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
415 "LOCALITY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
416 "REGION",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
417 "PCODE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
418 "CTRY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
419 }
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
420 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
421 LABEL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
422 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
423 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
424 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
425 "POSTAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426 "PARCEL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427 "DOM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
428 "INTL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
429 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
430 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
431 value = "LINE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
432 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
433 TEL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
436 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
437 "VOICE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
438 "FAX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
439 "PAGER",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
440 "MSG",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 "CELL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
442 "VIDEO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
443 "BBS",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
444 "MODEM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
445 "ISDN",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
446 "PCS",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
447 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
448 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
449 value = "NUMBER",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
450 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
451 EMAIL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
452 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
453 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
454 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
455 "INTERNET",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
456 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
457 "X400",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
458 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
459 value = "USERID",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
460 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
461 JABBERID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
462 MAILER = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
463 TZ = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
464 GEO = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
465 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
466 "LAT",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
467 "LON",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
468 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
469 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
470 TITLE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
471 ROLE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
472 LOGO = "copy of PHOTO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
473 AGENT = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
474 ORG = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
475 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
476 behaviour = "repeat-last",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
477 "ORGNAME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
478 "ORGUNIT",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
479 }
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
480 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
481 CATEGORIES = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
482 values = "KEYWORD",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
483 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
484 NOTE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
485 PRODID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
486 REV = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
487 SORTSTRING = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
488 SOUND = "copy of PHOTO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
489 UID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
490 URL = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
491 CLASS = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
492 names = { -- The item.name is the value if it's one of these.
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
493 "PUBLIC",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
494 "PRIVATE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
495 "CONFIDENTIAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
496 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
497 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
498 KEY = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
499 props = { "TYPE" },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
500 value = "CRED",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
501 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
502 DESC = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
503 };
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
504 vCard_dtd.LOGO = vCard_dtd.PHOTO;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
505 vCard_dtd.SOUND = vCard_dtd.PHOTO;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
506
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
507 vCard4_dtd = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
508 source = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
509 kind = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
510 xml = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
511 fn = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
512 n = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
513 values = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
514 "family",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
515 "given",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
516 "middle",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
517 "prefix",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
518 "suffix",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
519 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
520 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
521 nickname = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
522 photo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
523 bday = "date-and-or-time",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
524 anniversary = "date-and-or-time",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
525 gender = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
526 adr = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
527 values = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
528 "pobox",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
529 "ext",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
530 "street",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
531 "locality",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
532 "region",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
533 "code",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
534 "country",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
535 }
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
536 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
537 tel = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
538 email = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
539 impp = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
540 lang = "language-tag",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
541 tz = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
542 geo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
543 title = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
544 role = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
545 logo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
546 org = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
547 member = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
548 related = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
549 categories = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
550 note = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
551 prodid = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
552 rev = "timestamp",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
553 sound = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
554 uid = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
555 clientpidmap = "number, uuid",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
556 url = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
557 version = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
558 key = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
559 fburl = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
560 caladruri = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
561 caluri = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
562 };
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
563
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
564 return {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
565 from_text = from_text;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
566 to_text = to_text;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
567
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
568 from_xep54 = from_xep54;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
569 to_xep54 = to_xep54;
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
570
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
571 to_vcard4 = vcards_to_vcard4xml;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
572 };