Software / code / prosody
Comparison
util/xmppstream.lua @ 4428:0317b01b6bcd
Merge with Florob
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 26 Nov 2011 03:50:51 +0000 |
| parent | 4426:ee65aa40ef60 |
| child | 4482:722cf2680028 |
comparison
equal
deleted
inserted
replaced
| 4423:ded726418b16 | 4428:0317b01b6bcd |
|---|---|
| 9 | 9 |
| 10 local lxp = require "lxp"; | 10 local lxp = require "lxp"; |
| 11 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
| 12 local stanza_mt = st.stanza_mt; | 12 local stanza_mt = st.stanza_mt; |
| 13 | 13 |
| 14 local error = error; | |
| 14 local tostring = tostring; | 15 local tostring = tostring; |
| 15 local t_insert = table.insert; | 16 local t_insert = table.insert; |
| 16 local t_concat = table.concat; | 17 local t_concat = table.concat; |
| 17 local t_remove = table.remove; | 18 local t_remove = table.remove; |
| 18 local setmetatable = setmetatable; | 19 local setmetatable = setmetatable; |
| 19 | 20 |
| 20 local default_log = require "util.logger".init("xmppstream"); | |
| 21 | |
| 22 -- COMPAT: w/LuaExpat 1.1.0 | 21 -- COMPAT: w/LuaExpat 1.1.0 |
| 23 local lxp_supports_doctype = pcall(lxp.new, { StartDoctypeDecl = false }); | 22 local lxp_supports_doctype = pcall(lxp.new, { StartDoctypeDecl = false }); |
| 24 | |
| 25 if not lxp_supports_doctype then | |
| 26 default_log("warn", "The version of LuaExpat on your system leaves Prosody " | |
| 27 .."vulnerable to denial-of-service attacks. You should upgrade to " | |
| 28 .."LuaExpat 1.1.1 or higher as soon as possible. See " | |
| 29 .."http://prosody.im/doc/depends#luaexpat for more information."); | |
| 30 end | |
| 31 | |
| 32 local error = error; | |
| 33 | 23 |
| 34 module "xmppstream" | 24 module "xmppstream" |
| 35 | 25 |
| 36 local new_parser = lxp.new; | 26 local new_parser = lxp.new; |
| 37 | 27 |
| 47 _M.ns_separator = ns_separator; | 37 _M.ns_separator = ns_separator; |
| 48 _M.ns_pattern = ns_pattern; | 38 _M.ns_pattern = ns_pattern; |
| 49 | 39 |
| 50 function new_sax_handlers(session, stream_callbacks) | 40 function new_sax_handlers(session, stream_callbacks) |
| 51 local xml_handlers = {}; | 41 local xml_handlers = {}; |
| 52 | |
| 53 local log = session.log or default_log; | |
| 54 | 42 |
| 55 local cb_streamopened = stream_callbacks.streamopened; | 43 local cb_streamopened = stream_callbacks.streamopened; |
| 56 local cb_streamclosed = stream_callbacks.streamclosed; | 44 local cb_streamclosed = stream_callbacks.streamclosed; |
| 57 local cb_error = stream_callbacks.error or function(session, e) error("XML stream error: "..tostring(e)); end; | 45 local cb_error = stream_callbacks.error or function(session, e) error("XML stream error: "..tostring(e)); end; |
| 58 local cb_handlestanza = stream_callbacks.handlestanza; | 46 local cb_handlestanza = stream_callbacks.handlestanza; |
| 186 stack = {}; | 174 stack = {}; |
| 187 end | 175 end |
| 188 | 176 |
| 189 local function set_session(stream, new_session) | 177 local function set_session(stream, new_session) |
| 190 session = new_session; | 178 session = new_session; |
| 191 log = new_session.log or default_log; | |
| 192 end | 179 end |
| 193 | 180 |
| 194 return xml_handlers, { reset = reset, set_session = set_session }; | 181 return xml_handlers, { reset = reset, set_session = set_session }; |
| 195 end | 182 end |
| 196 | 183 |