Software /
code /
prosody
Annotate
util/vcard.lua @ 6666:42fdc8dddf04
Merge 0.10->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 06 May 2015 19:26:53 +0100 |
parent | 6400:95241c0f9244 |
child | 8382:e5d00bf4a4d5 |
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; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local next, pairs, ipairs = next, pairs, ipairs; |
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 fold_line() |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 error "Not implemented" --TODO |
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 local function unfold_line() |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 error "Not implemented" |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 -- gsub("\r?\n[ \t]([^\r\n])", "%1"); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local function vCard_esc(s) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 return s:gsub("[,:;\\]", "\\%1"):gsub("\n","\\n"); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end |
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 local function vCard_unesc(s) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 return s:gsub("\\?[\\nt:;,]", { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 ["\\\\"] = "\\", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 ["\\n"] = "\n", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 ["\\r"] = "\r", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 ["\\t"] = "\t", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 ["\\:"] = ":", -- 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
|
41 ["\\;"] = ";", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 ["\\,"] = ",", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 [":"] = "\29", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 [";"] = "\30", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 [","] = "\31", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 }); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 local function item_to_xep54(item) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 local t = st.stanza(item.name, { xmlns = "vcard-temp" }); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 local prop_def = vCard_dtd[item.name]; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 if prop_def == "text" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 t:text(item[1]); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 elseif type(prop_def) == "table" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 if prop_def.types and item.TYPE then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 if type(item.TYPE) == "table" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 for _,v in pairs(prop_def.types) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 for _,typ in pairs(item.TYPE) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 if typ:upper() == v then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 t:tag(v):up(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 break; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 t:tag(item.TYPE:upper()):up(); |
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.props then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 for _,v in pairs(prop_def.props) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 if item[v] then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 t:tag(v):up(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 if prop_def.value then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 t:tag(prop_def.value):text(item[1]):up(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 elseif prop_def.values then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 local prop_def_values = prop_def.values; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 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
|
84 for i=1,#item do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 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
|
86 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 |
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 local function vcard_to_xep54(vCard) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 local t = st.stanza("vCard", { xmlns = "vcard-temp" }); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 for i=1,#vCard do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 t:add_child(item_to_xep54(vCard[i])); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 return t; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 function to_xep54(vCards) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 if not vCards[1] or vCards[1].name then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 return vcard_to_xep54(vCards) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 local t = st.stanza("xCard", { xmlns = "vcard-temp" }); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 for i=1,#vCards do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 t:add_child(vcard_to_xep54(vCards[i])); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 return t; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 function from_text(data) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 data = data -- unfold and remove empty lines |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 :gsub("\r\n","\n") |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 :gsub("\n ", "") |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 :gsub("\n\n+","\n"); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 local vCards = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 local c; -- current item |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 for line in data:gmatch("[^\n]+") do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 local line = vCard_unesc(line); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 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
|
123 value = value:gsub("\29",":"); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 if #params > 0 then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 local _params = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 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
|
127 k = k:upper(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 local _vt = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 for _p in v:gmatch("[^\31]+") do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 _vt[#_vt+1]=_p |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 _vt[_p]=true; |
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 isval == "=" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 _params[k]=_vt; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 _params[k]=true; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 params = _params; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 if name == "BEGIN" and value == "VCARD" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 c = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 vCards[#vCards+1] = c; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 elseif name == "END" and value == "VCARD" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 c = nil; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 elseif c and vCard_dtd[name] then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 local dtd = vCard_dtd[name]; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 local p = { name = name }; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 c[#c+1]=p; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 --c[name]=p; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 local up = c; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 c = p; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 if dtd.types then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 for _, t in ipairs(dtd.types) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 local t = t:lower(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 if ( params.TYPE and params.TYPE[t] == true) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 or params[t] == true then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 c.TYPE=t; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 end |
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 if dtd.props then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 for _, p in ipairs(dtd.props) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 if params[p] then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 if params[p] == true then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 c[p]=true; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 for _, prop in ipairs(params[p]) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 c[p]=prop; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 end |
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 |
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 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 if dtd == "text" or dtd.value then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
176 t_insert(c, value); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 elseif dtd.values then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 local value = "\30"..value; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
179 for p in value:gmatch("\30([^\30]*)") do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
180 t_insert(c, p); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
181 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
182 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
183 c = up; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
184 end |
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 return vCards; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
187 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
188 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 local function item_to_text(item) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 local value = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 for i=1,#item do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 value[i] = vCard_esc(item[i]); |
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 value = t_concat(value, ";"); |
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 params = ""; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 for k,v in pairs(item) do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 if type(k) == "string" and k ~= "name" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 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
|
200 end |
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 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
203 return ("%s%s:%s"):format(item.name, params, value) |
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 local function vcard_to_text(vcard) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 local t={}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 t_insert(t, "BEGIN:VCARD") |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
209 for i=1,#vcard do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
210 t_insert(t, item_to_text(vcard[i])); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
211 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
212 t_insert(t, "END:VCARD") |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
213 return t_concat(t, line_sep); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
214 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
215 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
216 function to_text(vCards) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
217 if vCards[1] and vCards[1].name then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
218 return vcard_to_text(vCards) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
219 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
220 local t = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
221 for i=1,#vCards do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
222 t[i]=vcard_to_text(vCards[i]); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
223 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
224 return t_concat(t, line_sep); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
225 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
226 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
227 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
228 local function from_xep54_item(item) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
229 local prop_name = item.name; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
230 local prop_def = vCard_dtd[prop_name]; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
231 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
232 local prop = { name = prop_name }; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
233 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
234 if prop_def == "text" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
235 prop[1] = item:get_text(); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
236 elseif type(prop_def) == "table" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
237 if prop_def.value then --single item |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
238 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
|
239 elseif prop_def.values then --array |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
240 local value_names = prop_def.values; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
241 if value_names.behaviour == "repeat-last" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
242 for i=1,#item.tags do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
243 t_insert(prop, item.tags[i]:get_text() or ""); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
244 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
245 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
246 for i=1,#value_names do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
247 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
|
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 elseif prop_def.names then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
251 local names = prop_def.names; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
252 for i=1,#names do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
253 if item:get_child(names[i]) then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
254 prop[1] = names[i]; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
255 break; |
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 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
258 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
259 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
260 if prop_def.props_verbatim then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
261 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
|
262 prop[k] = v; |
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 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
265 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
266 if prop_def.types then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
267 local types = prop_def.types; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
268 prop.TYPE = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
269 for i=1,#types do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
270 if item:get_child(types[i]) then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
271 t_insert(prop.TYPE, types[i]:lower()); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
272 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
273 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
274 if #prop.TYPE == 0 then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
275 prop.TYPE = nil; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
276 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
277 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
278 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
279 -- A key-value pair, within a key-value pair? |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
280 if prop_def.props then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
281 local params = prop_def.props; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
282 for i=1,#params do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
283 local name = params[i] |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
284 local data = item:get_child_text(name); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
285 if data then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
286 prop[name] = prop[name] or {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
287 t_insert(prop[name], data); |
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 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
290 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
291 else |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
292 return nil |
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 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
295 return prop; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
296 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
297 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
298 local function from_xep54_vCard(vCard) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
299 local tags = vCard.tags; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
300 local t = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
301 for i=1,#tags do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
302 t_insert(t, from_xep54_item(tags[i])); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
303 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
304 return t |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
305 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
306 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
307 function from_xep54(vCard) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
308 if vCard.attr.xmlns ~= "vcard-temp" then |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
309 return nil, "wrong-xmlns"; |
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 if vCard.name == "xCard" then -- A collection of vCards |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
312 local t = {}; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
313 local vCards = vCard.tags; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
314 for i=1,#vCards do |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
315 t[i] = from_xep54_vCard(vCards[i]); |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
316 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
317 return t |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
318 elseif vCard.name == "vCard" then -- A single vCard |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
319 return from_xep54_vCard(vCard) |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
320 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
321 end |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
322 |
6263
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
323 local vcard4 = { } |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
324 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
325 function vcard4:text(node, params, value) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
326 self:tag(node:lower()) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
327 -- FIXME params |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
328 if type(value) == "string" then |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
329 self:tag("text"):text(value):up() |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
330 elseif vcard4[node] then |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
331 vcard4[node](value); |
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 self:up(); |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
334 end |
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 function vcard4.N(value) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
337 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
|
338 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
|
339 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
340 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
341 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
342 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
|
343 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
344 local function item_to_vcard4(item) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
345 local typ = item.name:lower(); |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
346 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
|
347 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
348 local prop_def = vCard4_dtd[typ]; |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
349 if prop_def == "text" then |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
350 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
|
351 elseif prop_def == "uri" then |
6400
95241c0f9244
util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents:
6308
diff
changeset
|
352 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
|
353 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
|
354 else |
95241c0f9244
util.vcard: Turn PHOTO fields into data-uris
Kim Alvefur <zash@zash.se>
parents:
6308
diff
changeset
|
355 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
|
356 end |
6263
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
357 elseif type(prop_def) == "table" then |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
358 if prop_def.values then |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
359 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
|
360 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
|
361 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
362 else |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
363 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
|
364 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
365 else |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
366 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
|
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 vcard_to_vcard4xml(vCard) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
372 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
|
373 for i=1,#vCard do |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
374 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
|
375 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
376 return t; |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
377 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
378 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
379 local function vcards_to_vcard4xml(vCards) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
380 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
|
381 return vcard_to_vcard4xml(vCards) |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
382 else |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
383 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
|
384 for i=1,#vCards do |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
385 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
|
386 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
387 return t; |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
388 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
389 end |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
390 |
6262
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
391 -- 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
|
392 vCard_dtd = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
393 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
|
394 FN = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
395 N = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
396 values = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
397 "FAMILY", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
398 "GIVEN", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
399 "MIDDLE", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
400 "PREFIX", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
401 "SUFFIX", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
402 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
403 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
404 NICKNAME = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
405 PHOTO = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
406 props_verbatim = { ENCODING = { "b" } }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
407 props = { "TYPE" }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
408 value = "BINVAL", --{ "EXTVAL", }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
409 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
410 BDAY = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
411 ADR = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
412 types = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
413 "HOME", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
414 "WORK", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
415 "POSTAL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
416 "PARCEL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
417 "DOM", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
418 "INTL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
419 "PREF", |
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 values = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
422 "POBOX", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
423 "EXTADD", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
424 "STREET", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
425 "LOCALITY", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
426 "REGION", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
427 "PCODE", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
428 "CTRY", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
429 } |
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 LABEL = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
432 types = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
433 "HOME", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
434 "WORK", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
435 "POSTAL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
436 "PARCEL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
437 "DOM", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
438 "INTL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
439 "PREF", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
440 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
441 value = "LINE", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
442 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
443 TEL = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
444 types = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
445 "HOME", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
446 "WORK", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
447 "VOICE", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
448 "FAX", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
449 "PAGER", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
450 "MSG", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
451 "CELL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
452 "VIDEO", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
453 "BBS", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
454 "MODEM", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
455 "ISDN", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
456 "PCS", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
457 "PREF", |
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 = "NUMBER", |
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 EMAIL = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
462 types = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
463 "HOME", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
464 "WORK", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
465 "INTERNET", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
466 "PREF", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
467 "X400", |
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 value = "USERID", |
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 JABBERID = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
472 MAILER = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
473 TZ = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
474 GEO = { |
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 "LAT", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
477 "LON", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
478 }, |
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 TITLE = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
481 ROLE = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
482 LOGO = "copy of PHOTO", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
483 AGENT = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
484 ORG = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
485 values = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
486 behaviour = "repeat-last", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
487 "ORGNAME", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
488 "ORGUNIT", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
489 } |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
490 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
491 CATEGORIES = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
492 values = "KEYWORD", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
493 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
494 NOTE = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
495 PRODID = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
496 REV = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
497 SORTSTRING = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
498 SOUND = "copy of PHOTO", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
499 UID = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
500 URL = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
501 CLASS = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
502 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
|
503 "PUBLIC", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
504 "PRIVATE", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
505 "CONFIDENTIAL", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
506 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
507 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
508 KEY = { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
509 props = { "TYPE" }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
510 value = "CRED", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
511 }, |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
512 DESC = "text", |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
513 }; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
514 vCard_dtd.LOGO = vCard_dtd.PHOTO; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
515 vCard_dtd.SOUND = vCard_dtd.PHOTO; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
516 |
6263
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
517 vCard4_dtd = { |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
518 source = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
519 kind = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
520 xml = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
521 fn = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
522 n = { |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
523 values = { |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
524 "family", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
525 "given", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
526 "middle", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
527 "prefix", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
528 "suffix", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
529 }, |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
530 }, |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
531 nickname = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
532 photo = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
533 bday = "date-and-or-time", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
534 anniversary = "date-and-or-time", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
535 gender = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
536 adr = { |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
537 values = { |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
538 "pobox", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
539 "ext", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
540 "street", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
541 "locality", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
542 "region", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
543 "code", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
544 "country", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
545 } |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
546 }, |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
547 tel = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
548 email = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
549 impp = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
550 lang = "language-tag", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
551 tz = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
552 geo = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
553 title = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
554 role = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
555 logo = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
556 org = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
557 member = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
558 related = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
559 categories = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
560 note = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
561 prodid = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
562 rev = "timestamp", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
563 sound = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
564 uid = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
565 clientpidmap = "number, uuid", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
566 url = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
567 version = "text", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
568 key = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
569 fburl = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
570 caladruri = "uri", |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
571 caluri = "uri", |
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 |
6262
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
574 return { |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
575 from_text = from_text; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
576 to_text = to_text; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
577 |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
578 from_xep54 = from_xep54; |
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
579 to_xep54 = to_xep54; |
6263
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
580 |
e208950446c8
util.vcard: Add support for converting to vcard4
Kim Alvefur <zash@zash.se>
parents:
6262
diff
changeset
|
581 to_vcard4 = vcards_to_vcard4xml; |
6262
e24027bafb0e
util.vcard: Library for parsing vCards
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
582 }; |