Software /
code /
verse
Comparison
client.lua @ 170:cb03e8ae2e30
Merge with Zash
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 15 Dec 2010 15:03:56 +0000 |
parent | 166:3499b4ea3277 |
child | 171:741f5311d30c |
comparison
equal
deleted
inserted
replaced
169:4bb1e9c91fbe | 170:cb03e8ae2e30 |
---|---|
8 | 8 |
9 -- Shortcuts to save having to load util.stanza | 9 -- Shortcuts to save having to load util.stanza |
10 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = | 10 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = |
11 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; | 11 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; |
12 | 12 |
13 local init_xmlhandlers = require "core.xmlhandlers"; | 13 local new_xmpp_stream = require "util.xmppstream".new; |
14 | 14 |
15 local xmlns_stream = "http://etherx.jabber.org/streams"; | 15 local xmlns_stream = "http://etherx.jabber.org/streams"; |
16 | 16 |
17 local function compare_srv_priorities(a,b) | 17 local function compare_srv_priorities(a,b) |
18 return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); | 18 return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); |
44 | 44 |
45 return stream:event("stanza", stanza); | 45 return stream:event("stanza", stanza); |
46 end | 46 end |
47 | 47 |
48 function stream:reset() | 48 function stream:reset() |
49 -- Reset stream | 49 if self.stream then |
50 local parser = lxp.new(init_xmlhandlers(self, stream_callbacks), "\1"); | 50 self.stream:reset(); |
51 self.parser = parser; | 51 else |
52 | 52 self.stream = new_xmpp_stream(self, stream_callbacks); |
53 end | |
53 self.notopen = true; | 54 self.notopen = true; |
54 | |
55 return true; | 55 return true; |
56 end | 56 end |
57 | 57 |
58 function stream:connect_client(jid, pass) | 58 function stream:connect_client(jid, pass) |
59 self.jid, self.password = jid, pass; | 59 self.jid, self.password = jid, pass; |
64 self:add_plugin("sasl"); | 64 self:add_plugin("sasl"); |
65 self:add_plugin("bind"); | 65 self:add_plugin("bind"); |
66 self:add_plugin("session"); | 66 self:add_plugin("session"); |
67 | 67 |
68 function self.data(conn, data) | 68 function self.data(conn, data) |
69 local ok, err = self.parser:parse(data); | 69 local ok, err = self.stream:feed(data); |
70 if ok then return; end | 70 if ok then return; end |
71 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); | 71 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
72 stream:close("xml-not-well-formed"); | 72 stream:close("xml-not-well-formed"); |
73 end | 73 end |
74 | 74 |
105 end | 105 end |
106 end | 106 end |
107 return ret; | 107 return ret; |
108 end, -1); | 108 end, -1); |
109 | 109 |
110 self:hook("outgoing", function (data) | |
111 if data.name then | |
112 self:event("stanza-out", data); | |
113 end | |
114 end); | |
115 | |
116 self:hook("stanza-out", function (stanza) | |
117 if not stanza.attr.xmlns then | |
118 self:event(stanza.name.."-out", stanza); | |
119 end | |
120 end); | |
121 | |
110 local function stream_ready() | 122 local function stream_ready() |
111 self:event("ready"); | 123 self:event("ready"); |
112 end | 124 end |
113 self:hook("session-success", stream_ready, -1) | 125 self:hook("session-success", stream_ready, -1) |
114 self:hook("bind-success", stream_ready, -1); | 126 self:hook("bind-success", stream_ready, -1); |