Comparison

net/xmppclient_listener.lua @ 3136:9630cb97cd3e

xmppclient_listener: Port to onconnect handler
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 Jun 2010 12:32:24 +0100
parent 3034:b9ebd44a35f9
child 3144:9e16012c2155
comparison
equal deleted inserted replaced
3135:f29a297471e3 3136:9630cb97cd3e
109 end 109 end
110 110
111 111
112 -- End of session methods -- 112 -- End of session methods --
113 113
114 function xmppclient.onconnect(conn)
115 local session = sm_new_session(conn);
116 sessions[conn] = session;
117
118 session.log("info", "Client connected");
119
120 -- Client is using legacy SSL (otherwise mod_tls sets this flag)
121 if conn:ssl() then
122 session.secure = true;
123 end
124
125 if opt_keepalives ~= nil then
126 conn:setoption("keepalive", opt_keepalives);
127 end
128
129 session.close = session_close;
130
131 local stream = new_xmpp_stream(session, stream_callbacks);
132 session.stream = stream;
133
134 session.notopen = true;
135
136 function session.reset_stream()
137 session.notopen = true;
138 session.stream:reset();
139 end
140
141 function session.data(data)
142 local ok, err = stream:feed(data);
143 if ok then return; end
144 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
145 session:close("xml-not-well-formed");
146 end
147
148 session.dispatch_stanza = stream_callbacks.handlestanza;
149 end
150
114 function xmppclient.onincoming(conn, data) 151 function xmppclient.onincoming(conn, data)
115 local session = sessions[conn]; 152 local session = sessions[conn];
116 if not session then 153 if session then
117 session = sm_new_session(conn);
118 sessions[conn] = session;
119
120 session.log("info", "Client connected");
121
122 -- Client is using legacy SSL (otherwise mod_tls sets this flag)
123 if conn:ssl() then
124 session.secure = true;
125 end
126
127 if opt_keepalives ~= nil then
128 conn:setoption("keepalive", opt_keepalives);
129 end
130
131 session.close = session_close;
132
133 local stream = new_xmpp_stream(session, stream_callbacks);
134 session.stream = stream;
135
136 session.notopen = true;
137
138 function session.reset_stream()
139 session.notopen = true;
140 session.stream:reset();
141 end
142
143 function session.data(data)
144 local ok, err = stream:feed(data);
145 if ok then return; end
146 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
147 session:close("xml-not-well-formed");
148 end
149
150 session.dispatch_stanza = stream_callbacks.handlestanza;
151 end
152 if data then
153 session.data(data); 154 session.data(data);
154 end 155 end
155 end 156 end
156 157
157 function xmppclient.ondisconnect(conn, err) 158 function xmppclient.ondisconnect(conn, err)