Software /
code /
prosody
Comparison
plugins/mod_component.lua @ 10111:0f335815244f
plugins: Remove tostring call from logging
Taken care of by loggingmanager now
Mass-rewrite using lua pattern like `tostring%b()`
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 30 Jul 2019 02:29:36 +0200 |
parent | 9870:8f4880576835 |
child | 10716:29575fe64860 |
comparison
equal
deleted
inserted
replaced
10110:3fa3872588a8 | 10111:0f335815244f |
---|---|
165 | 165 |
166 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; | 166 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; |
167 | 167 |
168 function stream_callbacks.error(session, error, data) | 168 function stream_callbacks.error(session, error, data) |
169 if session.destroyed then return; end | 169 if session.destroyed then return; end |
170 module:log("warn", "Error processing component stream: %s", tostring(error)); | 170 module:log("warn", "Error processing component stream: %s", error); |
171 if error == "no-stream" then | 171 if error == "no-stream" then |
172 session:close("invalid-namespace"); | 172 session:close("invalid-namespace"); |
173 elseif error == "parse-error" then | 173 elseif error == "parse-error" then |
174 session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(data)); | 174 session.log("warn", "External component %s XML parse error: %s", session.host, data); |
175 session:close("not-well-formed"); | 175 session:close("not-well-formed"); |
176 elseif error == "stream-error" then | 176 elseif error == "stream-error" then |
177 local condition, text = "undefined-condition"; | 177 local condition, text = "undefined-condition"; |
178 for child in data:childtags(nil, xmlns_xmpp_streams) do | 178 for child in data:childtags(nil, xmlns_xmpp_streams) do |
179 if child.name ~= "text" then | 179 if child.name ~= "text" then |
206 function stream_callbacks.streamclosed(session) | 206 function stream_callbacks.streamclosed(session) |
207 session.log("debug", "Received </stream:stream>"); | 207 session.log("debug", "Received </stream:stream>"); |
208 session:close(); | 208 session:close(); |
209 end | 209 end |
210 | 210 |
211 local function handleerr(err) log("error", "Traceback[component]: %s", traceback(tostring(err), 2)); end | 211 local function handleerr(err) log("error", "Traceback[component]: %s", traceback(err, 2)); end |
212 function stream_callbacks.handlestanza(session, stanza) | 212 function stream_callbacks.handlestanza(session, stanza) |
213 -- Namespaces are icky. | 213 -- Namespaces are icky. |
214 if not stanza.attr.xmlns and stanza.name == "handshake" then | 214 if not stanza.attr.xmlns and stanza.name == "handshake" then |
215 stanza.attr.xmlns = xmlns_component; | 215 stanza.attr.xmlns = xmlns_component; |
216 end | 216 end |
266 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); | 266 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); |
267 end | 267 end |
268 if reason.extra then | 268 if reason.extra then |
269 stanza:add_child(reason.extra); | 269 stanza:add_child(reason.extra); |
270 end | 270 end |
271 module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(stanza)); | 271 module:log("info", "Disconnecting component, <stream:error> is: %s", stanza); |
272 session.send(stanza); | 272 session.send(stanza); |
273 elseif reason.name then -- a stanza | 273 elseif reason.name then -- a stanza |
274 module:log("info", "Disconnecting component, <stream:error> is: %s", tostring(reason)); | 274 module:log("info", "Disconnecting component, <stream:error> is: %s", reason); |
275 session.send(reason); | 275 session.send(reason); |
276 end | 276 end |
277 end | 277 end |
278 end | 278 end |
279 session.send("</stream:stream>"); | 279 session.send("</stream:stream>"); |
310 end | 310 end |
311 | 311 |
312 function session.data(_, data) | 312 function session.data(_, data) |
313 local ok, err = stream:feed(data); | 313 local ok, err = stream:feed(data); |
314 if ok then return; end | 314 if ok then return; end |
315 log("debug", "Received invalid XML (%s) %d bytes: %q", tostring(err), #data, data:sub(1, 300)); | 315 log("debug", "Received invalid XML (%s) %d bytes: %q", err, #data, data:sub(1, 300)); |
316 session:close("not-well-formed"); | 316 session:close("not-well-formed"); |
317 end | 317 end |
318 | 318 |
319 session.dispatch_stanza = stream_callbacks.handlestanza; | 319 session.dispatch_stanza = stream_callbacks.handlestanza; |
320 | 320 |
325 session.data(conn, data); | 325 session.data(conn, data); |
326 end | 326 end |
327 function listener.ondisconnect(conn, err) | 327 function listener.ondisconnect(conn, err) |
328 local session = sessions[conn]; | 328 local session = sessions[conn]; |
329 if session then | 329 if session then |
330 (session.log or log)("info", "component disconnected: %s (%s)", tostring(session.host), tostring(err)); | 330 (session.log or log)("info", "component disconnected: %s (%s)", session.host, err); |
331 if session.host then | 331 if session.host then |
332 module:context(session.host):fire_event("component-disconnected", { session = session, reason = err }); | 332 module:context(session.host):fire_event("component-disconnected", { session = session, reason = err }); |
333 end | 333 end |
334 if session.on_destroy then session:on_destroy(err); end | 334 if session.on_destroy then session:on_destroy(err); end |
335 sessions[conn] = nil; | 335 sessions[conn] = nil; |