Software /
code /
prosody
Annotate
util/xmppstream.lua @ 3130:80e630e60f06
mod_pep: Use is_contact_subscribed (which uses the new rostermanager fix to avoid unnecessary roster loads)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 01 Jun 2010 20:10:17 +0100 |
parent | 3032:38459cffaf67 |
child | 3424:9e0df614e5d0 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1414
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2261
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2261
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
355
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
355
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
355
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
355
diff
changeset
|
9 |
2921
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
10 local lxp = require "lxp"; |
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
11 local st = require "util.stanza"; |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
12 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
13 local tostring = tostring; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
14 local t_insert = table.insert; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
15 local t_concat = table.concat; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
16 |
145 | 17 local default_log = require "util.logger".init("xmlhandlers"); |
18 | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
19 local error = error; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
20 |
2920
f3335285b20d
util.xmppstream: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
2506
diff
changeset
|
21 module "xmppstream" |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
22 |
2921
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
23 local new_parser = lxp.new; |
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
24 |
148 | 25 local ns_prefixes = { |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
26 ["http://www.w3.org/XML/1998/namespace"] = "xml"; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
27 }; |
2464
0b5f0ae7a6b1
xmlhandlers: More refactoring, split up stream_ns and stream_tag, add stream_error_tag so that callers don't need to be so worried about the separator we use
Matthew Wild <mwild1@gmail.com>
parents:
2463
diff
changeset
|
28 |
0b5f0ae7a6b1
xmlhandlers: More refactoring, split up stream_ns and stream_tag, add stream_error_tag so that callers don't need to be so worried about the separator we use
Matthew Wild <mwild1@gmail.com>
parents:
2463
diff
changeset
|
29 local xmlns_streams = "http://etherx.jabber.org/streams"; |
0b5f0ae7a6b1
xmlhandlers: More refactoring, split up stream_ns and stream_tag, add stream_error_tag so that callers don't need to be so worried about the separator we use
Matthew Wild <mwild1@gmail.com>
parents:
2463
diff
changeset
|
30 |
2463
d9ff0190eb4a
xmlhandlers: Define ns_separator and ns_pattern to save repeating it in literal form throughout the file
Matthew Wild <mwild1@gmail.com>
parents:
2261
diff
changeset
|
31 local ns_separator = "\1"; |
d9ff0190eb4a
xmlhandlers: Define ns_separator and ns_pattern to save repeating it in literal form throughout the file
Matthew Wild <mwild1@gmail.com>
parents:
2261
diff
changeset
|
32 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; |
148 | 33 |
2921
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
34 function new_sax_handlers(session, stream_callbacks) |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
35 local xml_handlers = {}; |
3032
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
36 |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
37 local log = session.log or default_log; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
38 |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
39 local cb_streamopened = stream_callbacks.streamopened; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
40 local cb_streamclosed = stream_callbacks.streamclosed; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
41 local cb_error = stream_callbacks.error or function(session, e) error("XML stream error: "..tostring(e)); end; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
42 local cb_handlestanza = stream_callbacks.handlestanza; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
43 |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
44 local stream_ns = stream_callbacks.stream_ns or xmlns_streams; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
45 local stream_tag = stream_ns..ns_separator..(stream_callbacks.stream_tag or "stream"); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
46 local stream_error_tag = stream_ns..ns_separator..(stream_callbacks.error_tag or "error"); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
47 |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
48 local stream_default_ns = stream_callbacks.default_ns; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
49 |
3032
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
50 local chardata, stanza = {}; |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
51 function xml_handlers:StartElement(tagname, attr) |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
52 if stanza and #chardata > 0 then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
53 -- We have some character data in the buffer |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
54 stanza:text(t_concat(chardata)); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
55 chardata = {}; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
56 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
57 local curr_ns,name = tagname:match(ns_pattern); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
58 if name == "" then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
59 curr_ns, name = "", curr_ns; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
60 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
61 |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
62 if curr_ns ~= stream_default_ns then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
63 attr.xmlns = curr_ns; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
64 end |
2464
0b5f0ae7a6b1
xmlhandlers: More refactoring, split up stream_ns and stream_tag, add stream_error_tag so that callers don't need to be so worried about the separator we use
Matthew Wild <mwild1@gmail.com>
parents:
2463
diff
changeset
|
65 |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
66 -- FIXME !!!!! |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
67 for i=1,#attr do |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
68 local k = attr[i]; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
69 attr[i] = nil; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
70 local ns, nm = k:match(ns_pattern); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
71 if nm ~= "" then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
72 ns = ns_prefixes[ns]; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
73 if ns then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
74 attr[ns..":"..nm] = attr[k]; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
75 attr[k] = nil; |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
76 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
77 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
78 end |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
79 |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
80 if not stanza then --if we are not currently inside a stanza |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
81 if session.notopen then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
82 if tagname == stream_tag then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
83 if cb_streamopened then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
84 cb_streamopened(session, attr); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
85 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
86 else |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
87 -- Garbage before stream? |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
88 cb_error(session, "no-stream"); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
89 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
90 return; |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
91 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
92 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
93 cb_error(session, "invalid-top-level-element"); |
1051
0327c569eb1a
xmlhandlers: Fix tag pattern again for the default namespace
Matthew Wild <mwild1@gmail.com>
parents:
1003
diff
changeset
|
94 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
95 |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
96 stanza = st.stanza(name, attr); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
97 else -- we are inside a stanza, so add a tag |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
98 attr.xmlns = nil; |
899
b95368f199a1
core.xmlhandlers: Filter out default stream namespace from stanzas
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
99 if curr_ns ~= stream_default_ns then |
148 | 100 attr.xmlns = curr_ns; |
101 end | |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
102 stanza:tag(name, attr); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
103 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
104 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
105 function xml_handlers:CharacterData(data) |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
106 if stanza then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
107 t_insert(chardata, data); |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
108 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
109 end |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
110 function xml_handlers:EndElement(tagname) |
2493
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
111 if stanza then |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
112 if #chardata > 0 then |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
113 -- We have some character data in the buffer |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
114 stanza:text(t_concat(chardata)); |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
115 chardata = {}; |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
116 end |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
117 -- Complete stanza |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
118 if #stanza.last_add == 0 then |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
119 if tagname ~= stream_error_tag then |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
120 cb_handlestanza(session, stanza); |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
121 else |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
122 cb_error(session, "stream-error", stanza); |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
123 end |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
124 stanza = nil; |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
125 else |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
126 stanza:up(); |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
127 end |
ec09d16a51e1
xmlhandlers: Rearranged a little code.
Waqas Hussain <waqas20@gmail.com>
parents:
2492
diff
changeset
|
128 else |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
129 if tagname == stream_tag then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
130 if cb_streamclosed then |
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
131 cb_streamclosed(session); |
148 | 132 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
133 else |
2505
0849e349992d
xmlhandlers: A little optimization.
Waqas Hussain <waqas20@gmail.com>
parents:
2493
diff
changeset
|
134 local curr_ns,name = tagname:match(ns_pattern); |
0849e349992d
xmlhandlers: A little optimization.
Waqas Hussain <waqas20@gmail.com>
parents:
2493
diff
changeset
|
135 if name == "" then |
0849e349992d
xmlhandlers: A little optimization.
Waqas Hussain <waqas20@gmail.com>
parents:
2493
diff
changeset
|
136 curr_ns, name = "", curr_ns; |
0849e349992d
xmlhandlers: A little optimization.
Waqas Hussain <waqas20@gmail.com>
parents:
2493
diff
changeset
|
137 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
138 cb_error(session, "parse-error", "unexpected-element-close", name); |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
139 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
140 stanza, chardata = nil, {}; |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
141 end |
2492
b5e2d1919ec3
xmlhandlers: Fixed indentation and added some semicolons.
Waqas Hussain <waqas20@gmail.com>
parents:
2468
diff
changeset
|
142 end |
3032
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
143 |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
144 local function reset() |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
145 stanza, chardata = nil, {}; |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
146 end |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
147 |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
148 return xml_handlers, { reset = reset }; |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
149 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
150 |
2921
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
151 function new(session, stream_callbacks) |
3032
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
152 local handlers, meta = new_sax_handlers(session, stream_callbacks); |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
153 local parser = new_parser(handlers, ns_separator); |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
154 local parse = parser.parse; |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
155 |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
156 return { |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
157 reset = function () |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
158 parser = new_parser(handlers, ns_separator); |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
159 parse = parser.parse; |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
160 meta.reset(); |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
161 end, |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
162 feed = function (self, data) |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
163 return parse(parser, data); |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
164 end |
38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
Matthew Wild <mwild1@gmail.com>
parents:
2926
diff
changeset
|
165 }; |
2921
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
166 end |
f0ddfd7739ea
util.xmppstream: new() now returns a parser object
Matthew Wild <mwild1@gmail.com>
parents:
2920
diff
changeset
|
167 |
2920
f3335285b20d
util.xmppstream: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
2506
diff
changeset
|
168 return _M; |