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