core/xmlhandlers.lua

changeset 557
c9b3ffb08fe3
parent 545
60002993be04
child 615
4ae3e81513f3
equal deleted inserted replaced
556:624367a765cd 557:c9b3ffb08fe3
55 55
56 local send = session.send; 56 local send = session.send;
57 57
58 local cb_streamopened = stream_callbacks.streamopened; 58 local cb_streamopened = stream_callbacks.streamopened;
59 local cb_streamclosed = stream_callbacks.streamclosed; 59 local cb_streamclosed = stream_callbacks.streamclosed;
60 local cb_error = stream_callbacks.error or function (e) error("XML stream error: "..tostring(e)); end; 60 local cb_error = stream_callbacks.error or function (session, e) error("XML stream error: "..tostring(e)); end;
61 local cb_handlestanza = stream_callbacks.handlestanza; 61 local cb_handlestanza = stream_callbacks.handlestanza;
62
63 local stream_ns = stream_callbacks.ns;
62 64
63 local stanza 65 local stanza
64 function xml_handlers:StartElement(name, attr) 66 function xml_handlers:StartElement(name, attr)
65 if stanza and #chardata > 0 then 67 if stanza and #chardata > 0 then
66 -- We have some character data in the buffer 68 -- We have some character data in the buffer
87 end 89 end
88 end 90 end
89 91
90 if not stanza then --if we are not currently inside a stanza 92 if not stanza then --if we are not currently inside a stanza
91 if session.notopen then 93 if session.notopen then
92 if name == "stream" then 94 if name == "stream" and curr_ns == stream_ns then
93 if cb_streamopened then 95 if cb_streamopened then
94 cb_streamopened(session, attr); 96 cb_streamopened(session, attr);
95 end 97 end
96 else 98 else
97 -- Garbage before stream? 99 -- Garbage before stream?
98 cb_error("no-stream"); 100 cb_error(session, "no-stream");
99 end 101 end
100 return; 102 return;
101 end 103 end
102 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then 104 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then
103 cb_error("invalid-top-level-element"); 105 cb_error(session, "invalid-top-level-element");
104 end 106 end
105 107
106 stanza = st.stanza(name, attr); 108 stanza = st.stanza(name, attr);
107 curr_tag = stanza; 109 curr_tag = stanza;
108 else -- we are inside a stanza, so add a tag 110 else -- we are inside a stanza, so add a tag
125 if cb_streamclosed then 127 if cb_streamclosed then
126 cb_streamclosed(session); 128 cb_streamclosed(session);
127 end 129 end
128 return; 130 return;
129 elseif name == "error" then 131 elseif name == "error" then
130 cb_error("stream-error", stanza); 132 cb_error(session, "stream-error", stanza);
131 else 133 else
132 cb_error("parse-error", "unexpected-element-close", name); 134 cb_error(session, "parse-error", "unexpected-element-close", name);
133 end 135 end
134 end 136 end
135 if stanza and #chardata > 0 then 137 if stanza and #chardata > 0 then
136 -- We have some character data in the buffer 138 -- We have some character data in the buffer
137 stanza:text(t_concat(chardata)); 139 stanza:text(t_concat(chardata));

mercurial