stanza.lua

Fri, 17 Sep 2010 14:43:38 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 17 Sep 2010 14:43:38 +0100
changeset 1
ee74a5e9419b
parent 0
319733864f05
permissions
-rw-r--r--

demo.lua: Example usage

0
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local t_insert = table.insert;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local t_concat = table.concat;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local t_remove = table.remove;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local t_concat = table.concat;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local s_format = string.format;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local s_match = string.match;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local tostring = tostring;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local setmetatable = setmetatable;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local getmetatable = getmetatable;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local pairs = pairs;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local ipairs = ipairs;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local type = type;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local next = next;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local print = print;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local unpack = unpack;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local s_gsub = string.gsub;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 local s_char = string.char;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local s_find = string.find;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local os = os;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 local do_pretty_printing = not os.getenv("WINDIR");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local getstyle, getstring;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if do_pretty_printing then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local ok, termcolours = pcall(require, "util.termcolours");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if ok then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 getstyle, getstring = termcolours.getstyle, termcolours.getstring;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 do_pretty_printing = nil;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local xmlns_stanzas = "urn:ietf:params:xml:ns:xmpp-stanzas";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 module "stanza"
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 stanza_mt = { __type = "stanza" };
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 stanza_mt.__index = stanza_mt;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 function stanza(name, attr)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local stanza = { name = name, attr = attr or {}, tags = {}, last_add = {}};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return setmetatable(stanza, stanza_mt);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 function stanza_mt:query(xmlns)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 return self:tag("query", { xmlns = xmlns });
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 function stanza_mt:body(text, attr)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 return self:tag("body", attr):text(text);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 function stanza_mt:tag(name, attrs)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 local s = stanza(name, attrs);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 (self.last_add[#self.last_add] or self):add_direct_child(s);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 t_insert(self.last_add, s);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 return self;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 function stanza_mt:text(text)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 (self.last_add[#self.last_add] or self):add_direct_child(text);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 return self;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 function stanza_mt:up()
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 t_remove(self.last_add);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 return self;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 function stanza_mt:reset()
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local last_add = self.last_add;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 for i = 1,#last_add do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 last_add[i] = nil;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 return self;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 function stanza_mt:add_direct_child(child)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 if type(child) == "table" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 t_insert(self.tags, child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 t_insert(self, child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 function stanza_mt:add_child(child)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 (self.last_add[#self.last_add] or self):add_direct_child(child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 return self;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 function stanza_mt:get_child(name, xmlns)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 for _, child in ipairs(self.tags) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 if (not name or child.name == name)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 and ((not xmlns and self.attr.xmlns == child.attr.xmlns)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 or child.attr.xmlns == xmlns) then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 return child;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 function stanza_mt:child_with_name(name)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 for _, child in ipairs(self.tags) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 if child.name == name then return child; end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 function stanza_mt:child_with_ns(ns)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 for _, child in ipairs(self.tags) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 if child.attr.xmlns == ns then return child; end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 function stanza_mt:children()
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 local i = 0;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 return function (a)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 i = i + 1
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 local v = a[i]
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 if v then return v; end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 end, self, i;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 function stanza_mt:childtags()
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 local i = 0;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 return function (a)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 i = i + 1
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 local v = self.tags[i]
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 if v then return v; end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 end, self.tags[1], i;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 local xml_escape
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 _M.xml_escape = xml_escape;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 local function _dostring(t, buf, self, xml_escape, parentns)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 local nsid = 0;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 local name = t.name
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 t_insert(buf, "<"..name);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 for k, v in pairs(t.attr) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 if s_find(k, "\1", 1, true) then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 local ns, attrk = s_match(k, "^([^\1]*)\1?(.*)$");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 nsid = nsid + 1;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 elseif not(k == "xmlns" and v == parentns) then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 t_insert(buf, " "..k.."='"..xml_escape(v).."'");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 local len = #t;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 if len == 0 then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 t_insert(buf, "/>");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 t_insert(buf, ">");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 for n=1,len do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 local child = t[n];
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 if child.name then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 self(child, buf, self, xml_escape, t.attr.xmlns);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 t_insert(buf, xml_escape(child));
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 t_insert(buf, "</"..name..">");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 function stanza_mt.__tostring(t)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 local buf = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 _dostring(t, buf, _dostring, xml_escape, nil);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 return t_concat(buf);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 function stanza_mt.top_tag(t)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 local attr_string = "";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 if t.attr then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(" %s='%s'", k, xml_escape(tostring(v))); end end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 return s_format("<%s%s>", t.name, attr_string);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 function stanza_mt.get_text(t)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 if #t.tags == 0 then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 return t_concat(t);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 function stanza_mt.get_error(stanza)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 local type, condition, text;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 local error_tag = stanza:get_child("error");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 if not error_tag then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 return nil, nil, nil;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 type = error_tag.attr.type;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 for child in error_tag:children() do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 if child.attr.xmlns == xmlns_stanzas then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 if not text and child.name == "text" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 text = child:get_text();
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 elseif not condition then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 condition = child.name;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 if condition and text then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 break;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 return type, condition or "undefined-condition", text or "";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 function stanza_mt.__add(s1, s2)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 return s1:add_direct_child(s2);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223 do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 local id = 0;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 function new_id()
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 id = id + 1;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227 return "lx"..id;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 function preserialize(stanza)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 local s = { name = stanza.name, attr = stanza.attr };
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 for _, child in ipairs(stanza) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 if type(child) == "table" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 t_insert(s, preserialize(child));
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 t_insert(s, child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 return s;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 function deserialize(stanza)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 -- Set metatable
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 if stanza then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 local attr = stanza.attr;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 for i=1,#attr do attr[i] = nil; end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 local attrx = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 for att in pairs(attr) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 if s_find(att, "|", 1, true) and not s_find(att, "\1", 1, true) then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 local ns,na = s_match(att, "^([^|]+)|(.+)$");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 attrx[ns.."\1"..na] = attr[att];
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 attr[att] = nil;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
256 for a,v in pairs(attrx) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 attr[a] = v;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 setmetatable(stanza, stanza_mt);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260 for _, child in ipairs(stanza) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 if type(child) == "table" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 deserialize(child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 if not stanza.tags then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 -- Rebuild tags
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267 local tags = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268 for _, child in ipairs(stanza) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269 if type(child) == "table" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 t_insert(tags, child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 stanza.tags = tags;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 if not stanza.last_add then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 stanza.last_add = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 return stanza;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 function clone(stanza)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 local lookup_table = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 local function _copy(object)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 if type(object) ~= "table" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 return object;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 elseif lookup_table[object] then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289 return lookup_table[object];
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 local new_table = {};
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 lookup_table[object] = new_table;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 for index, value in pairs(object) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 new_table[_copy(index)] = _copy(value);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 return setmetatable(new_table, getmetatable(object));
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
299 return _copy(stanza)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
300 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 function message(attr, body)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 if not body then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 return stanza("message", attr);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 return stanza("message", attr):tag("body"):text(body);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 function iq(attr)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310 if attr and not attr.id then attr.id = new_id(); end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 return stanza("iq", attr or { id = new_id() });
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 function reply(orig)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) });
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
316 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
318 do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319 local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 function error_reply(orig, type, condition, message)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 local t = reply(orig);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322 t.attr.type = "error";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 t:tag("error", {type = type}) --COMPAT: Some day xmlns:stanzas goes here
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 :tag(condition, xmpp_stanzas_attr):up();
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 if (message) then t:tag("text", xmpp_stanzas_attr):text(message):up(); end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 return t; -- stanza ready for adding app-specific errors
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 function presence(attr)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331 return stanza("presence", attr);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 if do_pretty_printing then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 local style_attrk = getstyle("yellow");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 local style_attrv = getstyle("red");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 local style_tagname = getstyle("red");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 local style_punc = getstyle("magenta");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 local attr_format = " "..getstring(style_attrk, "%s")..getstring(style_punc, "=")..getstring(style_attrv, "'%s'");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 local top_tag_format = getstring(style_punc, "<")..getstring(style_tagname, "%s").."%s"..getstring(style_punc, ">");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 --local tag_format = getstring(style_punc, "<")..getstring(style_tagname, "%s").."%s"..getstring(style_punc, ">").."%s"..getstring(style_punc, "</")..getstring(style_tagname, "%s")..getstring(style_punc, ">");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 local tag_format = top_tag_format.."%s"..getstring(style_punc, "</")..getstring(style_tagname, "%s")..getstring(style_punc, ">");
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 function stanza_mt.pretty_print(t)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 local children_text = "";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 for n, child in ipairs(t) do
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 if type(child) == "string" then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348 children_text = children_text .. xml_escape(child);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 children_text = children_text .. child:pretty_print();
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
351 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
354 local attr_string = "";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 if t.attr then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356 for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(attr_format, k, tostring(v)); end end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 return s_format(tag_format, t.name, attr_string, children_text, t.name);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
361 function stanza_mt.pretty_top_tag(t)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
362 local attr_string = "";
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
363 if t.attr then
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
364 for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(attr_format, k, tostring(v)); end end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
365 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
366 return s_format(top_tag_format, t.name, attr_string);
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 else
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
369 -- Sorry, fresh out of colours for you guys ;)
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 stanza_mt.pretty_print = stanza_mt.__tostring;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
371 stanza_mt.pretty_top_tag = stanza_mt.top_tag;
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
372 end
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373
319733864f05 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
374 return _M;

mercurial