Comparison

net/xmppcomponent_listener.lua @ 3706:b758e4ad30a0

xmppcomponent_listener: Switch to util.xmppstream from xmlhandlers
author Matthew Wild <mwild1@gmail.com>
date Tue, 07 Dec 2010 18:18:11 +0000
parent 3634:0d6b57edb7bd
child 3751:46edbc8339b1
comparison
equal deleted inserted replaced
3705:ddbac8737c2d 3706:b758e4ad30a0
17 local connlisteners = require "net.connlisteners"; 17 local connlisteners = require "net.connlisteners";
18 local uuid_gen = require "util.uuid".generate; 18 local uuid_gen = require "util.uuid".generate;
19 local jid_split = require "util.jid".split; 19 local jid_split = require "util.jid".split;
20 local sha1 = require "util.hashes".sha1; 20 local sha1 = require "util.hashes".sha1;
21 local st = require "util.stanza"; 21 local st = require "util.stanza";
22 local init_xmlhandlers = require "core.xmlhandlers"; 22 local new_xmpp_stream = require "util.xmppstream".new;
23 23
24 local sessions = {}; 24 local sessions = {};
25 25
26 local log = logger.init("componentlistener"); 26 local log = logger.init("componentlistener");
27 27
28 local component_listener = { default_port = 5347; default_mode = "*a"; default_interface = config.get("*", "core", "component_interface") or "127.0.0.1" }; 28 local component_listener = { default_port = 5347; default_mode = "*a"; default_interface = config.get("*", "core", "component_interface") or "127.0.0.1" };
29 29
30 local xmlns_component = 'jabber:component:accept'; 30 local xmlns_component = 'jabber:component:accept';
31 31
32 --- Callbacks/data for xmlhandlers to handle streams for us --- 32 --- Callbacks/data for xmppstream to handle streams for us ---
33 33
34 local stream_callbacks = { default_ns = xmlns_component }; 34 local stream_callbacks = { default_ns = xmlns_component };
35 35
36 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; 36 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
37 37
175 session.log = logger.init(conn_name); 175 session.log = logger.init(conn_name);
176 session.close = session_close; 176 session.close = session_close;
177 177
178 session.log("info", "Incoming Jabber component connection"); 178 session.log("info", "Incoming Jabber component connection");
179 179
180 local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1"); 180 local stream = new_xmpp_stream(session, stream_callbacks);
181 session.parser = parser; 181 session.stream = stream;
182 182
183 session.notopen = true; 183 session.notopen = true;
184 184
185 function session.reset_stream()
186 session.notopen = true;
187 session.stream:reset();
188 end
189
185 function session.data(conn, data) 190 function session.data(conn, data)
186 local ok, err = parser:parse(data); 191 local ok, err = stream:feed(data);
187 if ok then return; end 192 if ok then return; end
188 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); 193 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
189 session:close("not-well-formed"); 194 session:close("not-well-formed");
190 end 195 end
191 196