Comparison

net/xmppserver_listener.lua @ 3147:bc8c31399520

xmppserver_listener: Add filters for incoming bytes and stanzas
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 Jun 2010 18:23:39 +0100
parent 3141:50318ac90394
child 3332:c941d1191709
comparison
equal deleted inserted replaced
3146:aaaea4cdbf10 3147:bc8c31399520
123 function session.reset_stream() 123 function session.reset_stream()
124 session.notopen = true; 124 session.notopen = true;
125 session.stream:reset(); 125 session.stream:reset();
126 end 126 end
127 127
128 local filter = session.filter;
128 function session.data(data) 129 function session.data(data)
129 local ok, err = stream:feed(data); 130 data = filter("bytes/in", data);
130 if ok then return; end 131 if data then
131 (session.log or log)("warn", "Received invalid XML: %s", data); 132 local ok, err = stream:feed(data);
132 (session.log or log)("warn", "Problem was: %s", err); 133 if ok then return; end
133 session:close("xml-not-well-formed"); 134 (session.log or log)("warn", "Received invalid XML: %s", data);
135 (session.log or log)("warn", "Problem was: %s", err);
136 session:close("xml-not-well-formed");
137 end
134 end 138 end
135 139
136 session.close = session_close; 140 session.close = session_close;
137 session.dispatch_stanza = stream_callbacks.handlestanza; 141 local handlestanza = stream_callbacks.handlestanza;
142 function session.dispatch_stanza(session, stanza)
143 stanza = filters("stanzas/in", stanza);
144 if stanza then
145 return handlestanza(session, stanza);
146 end
147 end
138 end 148 end
139 149
140 function xmppserver.onconnect(conn) 150 function xmppserver.onconnect(conn)
141 if not sessions[conn] then -- May be an existing outgoing session 151 if not sessions[conn] then -- May be an existing outgoing session
142 local session = s2s_new_incoming(conn); 152 local session = s2s_new_incoming(conn);