Software /
code /
prosody
Comparison
plugins/mod_c2s.lua @ 5518:0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Apr 2013 17:50:22 +0200 |
parent | 5505:0b6a99e6c1b1 |
child | 5571:ae9672f4079a |
comparison
equal
deleted
inserted
replaced
5517:9d7349bbe4d2 | 5518:0220093e34fa |
---|---|
131 if session.notopen then | 131 if session.notopen then |
132 session.send("<?xml version='1.0'?>"); | 132 session.send("<?xml version='1.0'?>"); |
133 session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); | 133 session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); |
134 end | 134 end |
135 if reason then -- nil == no err, initiated by us, false == initiated by client | 135 if reason then -- nil == no err, initiated by us, false == initiated by client |
136 local stream_error = st.stanza("stream:error"); | |
136 if type(reason) == "string" then -- assume stream error | 137 if type(reason) == "string" then -- assume stream error |
137 log("debug", "Disconnecting client, <stream:error> is: %s", reason); | 138 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
138 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); | |
139 elseif type(reason) == "table" then | 139 elseif type(reason) == "table" then |
140 if reason.condition then | 140 if reason.condition then |
141 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up(); | 141 stream_error:tag(reason.condition, stream_xmlns_attr):up(); |
142 if reason.text then | 142 if reason.text then |
143 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); | 143 stream_error:tag("text", stream_xmlns_attr):text(reason.text):up(); |
144 end | 144 end |
145 if reason.extra then | 145 if reason.extra then |
146 stanza:add_child(reason.extra); | 146 stream_error:add_child(reason.extra); |
147 end | 147 end |
148 log("debug", "Disconnecting client, <stream:error> is: %s", tostring(stanza)); | |
149 session.send(stanza); | |
150 elseif reason.name then -- a stanza | 148 elseif reason.name then -- a stanza |
151 log("debug", "Disconnecting client, <stream:error> is: %s", tostring(reason)); | 149 stream_error = reason; |
152 session.send(reason); | |
153 end | 150 end |
154 end | 151 end |
152 stream_error = tostring(stream_error); | |
153 log("debug", "Disconnecting client, <stream:error> is: %s", stream_error); | |
154 session.send(stream_error); | |
155 end | 155 end |
156 | 156 |
157 session.send("</stream:stream>"); | 157 session.send("</stream:stream>"); |
158 function session.send() return false; end | 158 function session.send() return false; end |
159 | 159 |