Annotate

util/vcard.lua @ 10171:628e238feb04

util.startup: Removed unnecessary if clause at startup.set_plugindir
author João Duarte <jvsDuarte08@gmail.com>
date Thu, 25 Jul 2019 06:46:04 -0700
parent 9059:e1db06a0cc6b
child 11727:f3aee8a825cc
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
9058
35421a289a75 util.vcard: Include values of 'properties' (eg PHOTO TYPE) in vcard-temp serialization
Kim Alvefur <zash@zash.se>
parents: 8382
diff changeset
64 for _,prop in pairs(prop_def.props) do
35421a289a75 util.vcard: Include values of 'properties' (eg PHOTO TYPE) in vcard-temp serialization
Kim Alvefur <zash@zash.se>
parents: 8382
diff changeset
65 if item[prop] then
35421a289a75 util.vcard: Include values of 'properties' (eg PHOTO TYPE) in vcard-temp serialization
Kim Alvefur <zash@zash.se>
parents: 8382
diff changeset
66 for _, v in ipairs(item[prop]) do
35421a289a75 util.vcard: Include values of 'properties' (eg PHOTO TYPE) in vcard-temp serialization
Kim Alvefur <zash@zash.se>
parents: 8382
diff changeset
67 t:text_tag(prop, v);
35421a289a75 util.vcard: Include values of 'properties' (eg PHOTO TYPE) in vcard-temp serialization
Kim Alvefur <zash@zash.se>
parents: 8382
diff changeset
68 end
6262
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 if prop_def.value then
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
74 t:text_tag(prop_def.value, item[1]);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 elseif prop_def.values then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 local prop_def_values = prop_def.values;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 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
78 for i=1,#item do
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
79 t:text_tag(prop_def.values[i] or repeat_last, item[i]);
6262
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 local function vcard_to_xep54(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 local t = st.stanza("vCard", { xmlns = "vcard-temp" });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 for i=1,#vCard do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 t:add_child(item_to_xep54(vCard[i]));
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 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 function to_xep54(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 if not vCards[1] or vCards[1].name then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 return vcard_to_xep54(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 local t = st.stanza("xCard", { xmlns = "vcard-temp" });
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 t:add_child(vcard_to_xep54(vCards[i]));
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 return t;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 function from_text(data)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 data = data -- unfold and remove empty lines
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 :gsub("\r\n","\n")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 :gsub("\n ", "")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 :gsub("\n\n+","\n");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 local vCards = {};
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
113 local current;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 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
115 line = vCard_unesc(line);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 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
117 value = value:gsub("\29",":");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 if #params > 0 then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 local _params = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 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
121 k = k:upper();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 local _vt = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 for _p in v:gmatch("[^\31]+") do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 _vt[#_vt+1]=_p
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 _vt[_p]=true;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 if isval == "=" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 _params[k]=_vt;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 _params[k]=true;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 end
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 params = _params;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 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
136 current = {};
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
137 vCards[#vCards+1] = current;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 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
139 current = nil;
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
140 elseif current and vCard_dtd[name] then
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 local dtd = vCard_dtd[name];
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
142 local item = { name = name };
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
143 t_insert(current, item);
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
144 local up = current;
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
145 current = item;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 if dtd.types then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 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
148 t = t:lower();
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 if ( params.TYPE and params.TYPE[t] == true)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 or params[t] == true then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
151 current.TYPE=t;
6262
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 if dtd.props then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 for _, p in ipairs(dtd.props) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 if params[p] then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 if params[p] == true then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
159 current[p]=true;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 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
162 current[p]=prop;
6262
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 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
169 t_insert(current, value);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 elseif dtd.values then
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
171 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
172 t_insert(current, p);
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 end
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
175 current = up;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 end
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 return vCards;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 local function item_to_text(item)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 local value = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 for i=1,#item do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 value[i] = vCard_esc(item[i]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 value = t_concat(value, ";");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 local params = "";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 for k,v in pairs(item) do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 if type(k) == "string" and k ~= "name" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 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
192 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 return ("%s%s:%s"):format(item.name, params, value)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 local function vcard_to_text(vcard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 local t={};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 t_insert(t, "BEGIN:VCARD")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 for i=1,#vcard do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 t_insert(t, item_to_text(vcard[i]));
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 t_insert(t, "END:VCARD")
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205 return t_concat(t, line_sep);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 function to_text(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 if vCards[1] and vCards[1].name then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210 return vcard_to_text(vCards)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 t[i]=vcard_to_text(vCards[i]);
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 return t_concat(t, line_sep);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220 local function from_xep54_item(item)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221 local prop_name = item.name;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 local prop_def = vCard_dtd[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 local prop = { name = prop_name };
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226 if prop_def == "text" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 prop[1] = item:get_text();
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 elseif type(prop_def) == "table" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 if prop_def.value then --single item
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230 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
231 elseif prop_def.values then --array
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 local value_names = prop_def.values;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 if value_names.behaviour == "repeat-last" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 for i=1,#item.tags do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 t_insert(prop, item.tags[i]:get_text() or "");
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 for i=1,#value_names do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 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
240 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 elseif prop_def.names then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 local names = prop_def.names;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 for i=1,#names do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 if item:get_child(names[i]) then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 prop[1] = names[i];
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 break;
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 if prop_def.props_verbatim then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 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
254 prop[k] = v;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 if prop_def.types then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 local types = prop_def.types;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 prop.TYPE = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 for i=1,#types do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 if item:get_child(types[i]) then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 t_insert(prop.TYPE, types[i]:lower());
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 if #prop.TYPE == 0 then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 prop.TYPE = nil;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 -- A key-value pair, within a key-value pair?
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 if prop_def.props then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 local params = prop_def.props;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 for i=1,#params do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 local name = params[i]
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 local data = item:get_child_text(name);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 if data then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 prop[name] = prop[name] or {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 t_insert(prop[name], data);
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 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 else
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 return nil
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 return prop;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 local function from_xep54_vCard(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 local tags = vCard.tags;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 for i=1,#tags do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 t_insert(t, from_xep54_item(tags[i]));
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 return t
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 function from_xep54(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 if vCard.attr.xmlns ~= "vcard-temp" then
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 return nil, "wrong-xmlns";
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 if vCard.name == "xCard" then -- A collection of vCards
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 local t = {};
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305 local vCards = vCard.tags;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
306 for i=1,#vCards do
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307 t[i] = from_xep54_vCard(vCards[i]);
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
308 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
309 return t
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
310 elseif vCard.name == "vCard" then -- A single vCard
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 return from_xep54_vCard(vCard)
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 end
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
314
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
315 local vcard4 = { }
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
316
8382
e5d00bf4a4d5 util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6400
diff changeset
317 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
318 self:tag(node:lower())
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
319 -- FIXME params
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
320 if type(value) == "string" then
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
321 self:text_tag("text", value);
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
322 elseif vcard4[node] then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
323 vcard4[node](value);
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 self:up();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
326 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
327
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
328 function vcard4.N(value)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
329 for i, k in ipairs(vCard_dtd.N.values) do
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
330 value:text_tag(k, value[i]);
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
331 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
332 end
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 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
335
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
336 local function item_to_vcard4(item)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
337 local typ = item.name:lower();
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
338 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
339
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
340 local prop_def = vCard4_dtd[typ];
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
341 if prop_def == "text" then
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
342 t:text_tag("text", item[1]);
6308
94c3cf8293a7 util.vcard: Add support for uri types in vcard4
Kim Alvefur <zash@zash.se>
parents: 6265
diff changeset
343 elseif prop_def == "uri" then
6400
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
344 if item.ENCODING and item.ENCODING[1] == 'b' then
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
345 t:text_tag("uri", "data:;base64," .. item[1]);
6400
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
346 else
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
347 t:text_tag("uri", item[1]);
6400
95241c0f9244 util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents: 6308
diff changeset
348 end
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
349 elseif type(prop_def) == "table" then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
350 if prop_def.values then
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
351 for i, v in ipairs(prop_def.values) do
9059
e1db06a0cc6b util.vcard: Use the new :text_tag API in more places
Kim Alvefur <zash@zash.se>
parents: 9058
diff changeset
352 t:text_tag(v:lower(), item[i]);
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
353 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
354 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
355 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
356 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
357 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
358 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
359 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
360 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
361 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
362
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
363 local function vcard_to_vcard4xml(vCard)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
364 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
365 for i=1,#vCard do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
366 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
367 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
368 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
369 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
370
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
371 local function vcards_to_vcard4xml(vCards)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
372 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
373 return vcard_to_vcard4xml(vCards)
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
374 else
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
375 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
376 for i=1,#vCards do
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
377 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
378 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
379 return t;
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
380 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
381 end
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
382
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
383 -- 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
384 vCard_dtd = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
385 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
386 FN = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
387 N = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
388 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
389 "FAMILY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
390 "GIVEN",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
391 "MIDDLE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
392 "PREFIX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
393 "SUFFIX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
394 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
395 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
396 NICKNAME = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
397 PHOTO = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
398 props_verbatim = { ENCODING = { "b" } },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
399 props = { "TYPE" },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
400 value = "BINVAL", --{ "EXTVAL", },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
401 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
402 BDAY = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
403 ADR = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
404 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
405 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
406 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
407 "POSTAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
408 "PARCEL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
409 "DOM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
410 "INTL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
411 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
412 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
413 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
414 "POBOX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
415 "EXTADD",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
416 "STREET",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
417 "LOCALITY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
418 "REGION",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
419 "PCODE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
420 "CTRY",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
421 }
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
422 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
423 LABEL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
424 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
425 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427 "POSTAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
428 "PARCEL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
429 "DOM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
430 "INTL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
431 "PREF",
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 value = "LINE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 TEL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
436 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
437 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
438 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
439 "VOICE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
440 "FAX",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 "PAGER",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
442 "MSG",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
443 "CELL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
444 "VIDEO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
445 "BBS",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
446 "MODEM",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
447 "ISDN",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
448 "PCS",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
449 "PREF",
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 value = "NUMBER",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
452 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
453 EMAIL = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
454 types = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
455 "HOME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
456 "WORK",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
457 "INTERNET",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
458 "PREF",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
459 "X400",
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 value = "USERID",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
462 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
463 JABBERID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
464 MAILER = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
465 TZ = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
466 GEO = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
467 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
468 "LAT",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
469 "LON",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
470 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
471 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
472 TITLE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
473 ROLE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
474 LOGO = "copy of PHOTO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
475 AGENT = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
476 ORG = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
477 values = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
478 behaviour = "repeat-last",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
479 "ORGNAME",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
480 "ORGUNIT",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
481 }
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
482 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
483 CATEGORIES = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
484 values = "KEYWORD",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
485 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
486 NOTE = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
487 PRODID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
488 REV = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
489 SORTSTRING = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
490 SOUND = "copy of PHOTO",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
491 UID = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
492 URL = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
493 CLASS = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
494 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
495 "PUBLIC",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
496 "PRIVATE",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
497 "CONFIDENTIAL",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
498 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
499 },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
500 KEY = {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
501 props = { "TYPE" },
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
502 value = "CRED",
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 DESC = "text",
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
505 };
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
506 vCard_dtd.LOGO = vCard_dtd.PHOTO;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
507 vCard_dtd.SOUND = vCard_dtd.PHOTO;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
508
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
509 vCard4_dtd = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
510 source = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
511 kind = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
512 xml = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
513 fn = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
514 n = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
515 values = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
516 "family",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
517 "given",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
518 "middle",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
519 "prefix",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
520 "suffix",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
521 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
522 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
523 nickname = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
524 photo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
525 bday = "date-and-or-time",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
526 anniversary = "date-and-or-time",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
527 gender = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
528 adr = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
529 values = {
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
530 "pobox",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
531 "ext",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
532 "street",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
533 "locality",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
534 "region",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
535 "code",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
536 "country",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
537 }
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
538 },
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
539 tel = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
540 email = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
541 impp = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
542 lang = "language-tag",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
543 tz = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
544 geo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
545 title = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
546 role = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
547 logo = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
548 org = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
549 member = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
550 related = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
551 categories = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
552 note = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
553 prodid = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
554 rev = "timestamp",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
555 sound = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
556 uid = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
557 clientpidmap = "number, uuid",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
558 url = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
559 version = "text",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
560 key = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
561 fburl = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
562 caladruri = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
563 caluri = "uri",
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
564 };
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
565
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
566 return {
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
567 from_text = from_text;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
568 to_text = to_text;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
569
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
570 from_xep54 = from_xep54;
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
571 to_xep54 = to_xep54;
6263
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
572
e208950446c8 util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents: 6262
diff changeset
573 to_vcard4 = vcards_to_vcard4xml;
6262
e24027bafb0e util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff changeset
574 };