Software /
code /
verse
Changeset
197:7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 17 Mar 2011 18:33:52 +0100 |
parents | 196:eb9d69d3f0b5 |
children | 198:f6702e7ce5f9 |
files | plugins/bind.lua plugins/compression.lua plugins/disco.lua plugins/groupchat.lua plugins/jingle.lua plugins/presence.lua plugins/sasl.lua plugins/session.lua plugins/smacks.lua plugins/tls.lua |
diffstat | 10 files changed, 31 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/bind.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/bind.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,11 +1,10 @@ -local st = require "util.stanza"; local xmlns_bind = "urn:ietf:params:xml:ns:xmpp-bind"; function verse.plugins.bind(stream) local function handle_features(features) if stream.bound then return; end stream:debug("Binding resource..."); - stream:send_iq(st.iq({ type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource), + stream:send_iq(verse.iq({ type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource), function (reply) if reply.attr.type == "result" then local result_jid = reply
--- a/plugins/compression.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/compression.lua Thu Mar 17 18:33:52 2011 +0100 @@ -5,7 +5,6 @@ -- COPYING file in the source package for more information. -- -local st = require "util.stanza"; local zlib = require "zlib"; local xmlns_compression_feature = "http://jabber.org/features/compress" @@ -18,7 +17,7 @@ local function get_deflate_stream(session) local status, deflate_stream = pcall(zlib.deflate, compression_level); if status == false then - local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); + local error_st = verse.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); session:send(error_st); session:error("Failed to create zlib.deflate filter: %s", tostring(deflate_stream)); return @@ -30,7 +29,7 @@ local function get_inflate_stream(session) local status, inflate_stream = pcall(zlib.inflate); if status == false then - local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); + local error_st = verse.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); session:send(error_st); session:error("Failed to create zlib.inflate filter: %s", tostring(inflate_stream)); return @@ -47,7 +46,7 @@ session:close({ condition = "undefined-condition"; text = compressed; - extra = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("processing-failed"); + extra = verse.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("processing-failed"); }); session:warn("Compressed send failed: %s", tostring(compressed)); return; @@ -66,7 +65,7 @@ session:close({ condition = "undefined-condition"; text = decompressed; - extra = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("processing-failed"); + extra = verse.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("processing-failed"); }); stream:warn("%s", tostring(decompressed)); return; @@ -85,7 +84,7 @@ for a in comp_st:children() do local algorithm = a[1] if algorithm == "zlib" then - stream:send(st.stanza("compress", {xmlns=xmlns_compression_protocol}):tag("method"):text("zlib")) + stream:send(verse.stanza("compress", {xmlns=xmlns_compression_protocol}):tag("method"):text("zlib")) stream:debug("Enabled compression using zlib.") return true; end
--- a/plugins/disco.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/disco.lua Thu Mar 17 18:33:52 2011 +0100 @@ -6,7 +6,6 @@ -- COPYING file in the source package for more information. -- -local st = require "util.stanza" local b64 = require("mime").b64 local sha1 = require("util.sha1").sha1 @@ -79,7 +78,7 @@ -- retrieve the c stanza to insert into the -- presence stanza local hash = calculate_hash() - return st.stanza('c', { + return verse.stanza('c', { xmlns = xmlns_caps, hash = 'sha-1', node = stream.caps.node, @@ -273,7 +272,7 @@ features = stream.disco.info.features else -- unknown node: give an error - local response = st.stanza('iq',{ + local response = verse.stanza('iq',{ to = stanza.attr.from, from = stanza.attr.to, id = stanza.attr.id, @@ -291,7 +290,7 @@ features = stream.disco.info.features end -- construct the response - local result = st.stanza('query',{ + local result = verse.stanza('query',{ xmlns = xmlns_disco_info, node = query.attr.node }) @@ -301,7 +300,7 @@ for key,feature in pairs(features) do result:tag('feature', feature):reset() end - stream:send(st.stanza('iq',{ + stream:send(verse.stanza('iq',{ to = stanza.attr.from, from = stanza.attr.to, id = stanza.attr.id, @@ -323,7 +322,7 @@ items = node.items or {} else -- unknown node: give an error - local response = st.stanza('iq',{ + local response = verse.stanza('iq',{ to = stanza.attr.from, from = stanza.attr.to, id = stanza.attr.id, @@ -340,14 +339,14 @@ items = stream.disco.items end -- construct the response - local result = st.stanza('query',{ + local result = verse.stanza('query',{ xmlns = xmlns_disco_items, node = query.attr.node }) for key,item in pairs(items) do result:tag('item', item):reset() end - stream:send(st.stanza('iq',{ + stream:send(verse.stanza('iq',{ to = stanza.attr.from, from = stanza.attr.to, id = stanza.attr.id,
--- a/plugins/groupchat.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/groupchat.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,5 +1,4 @@ local events = require "events"; -local st = require "util.stanza"; local room_mt = {}; room_mt.__index = room_mt; @@ -100,7 +99,7 @@ room.subject = #subject > 0 and subject or nil; end end); - local join_st = st.presence():tag("x",{xmlns = xmlns_muc}):reset(); + local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset(); self:event("pre-groupchat/joining", join_st); room:send(join_st) self:event("groupchat/joining", room); @@ -134,20 +133,20 @@ end function room_mt:send_message(text) - self:send(st.message():tag("body"):text(text)); + self:send(verse.message():tag("body"):text(text)); end function room_mt:set_subject(text) - self:send(st.message():tag("subject"):text(text)); + self:send(verse.message():tag("subject"):text(text)); end function room_mt:leave(message) self.stream:event("groupchat/leaving", self); - self:send(st.presence({type="unavailable"})); + self:send(verse.presence({type="unavailable"})); end function room_mt:admin_set(nick, what, value, reason) - self:send(st.iq({type="set"}) + self:send(verse.iq({type="set"}) :query(xmlns_muc .. "#admin") :tag("item", {nick = nick, [what] = value}) :tag("reason"):text(reason or ""));
--- a/plugins/jingle.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/jingle.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,5 +1,4 @@ local sha1 = require "util.sha1".sha1; -local st = require "util.stanza"; local timer = require "util.timer"; local uuid_generate = require "util.uuid".generate; @@ -52,7 +51,7 @@ -- No existing Jingle object handled this action, our turn... if action ~= "session-initiate" then -- Trying to send a command to a session we don't know - local reply = st.error_reply(stanza, "cancel", "item-not-found") + local reply = verse.error_reply(stanza, "cancel", "item-not-found") :tag("unknown-session", { xmlns = xmlns_jingle_errors }):up(); stream:send(reply); return; @@ -97,17 +96,17 @@ end if not content then -- FIXME: Fail, no content - stream:send(st.error_reply(stanza, "cancel", "feature-not-implemented", "The specified content is not supported")); + stream:send(verse.error_reply(stanza, "cancel", "feature-not-implemented", "The specified content is not supported")); return; end if not transport then -- FIXME: Refuse session, no transport - stream:send(st.error_reply(stanza, "cancel", "feature-not-implemented", "The specified transport is not supported")); + stream:send(verse.error_reply(stanza, "cancel", "feature-not-implemented", "The specified transport is not supported")); return; end - stream:send(st.reply(stanza)); + stream:send(verse.reply(stanza)); jingle.content_tag = content_tag; jingle.creator, jingle.name = content_tag.attr.creator, content_tag.attr.name; @@ -152,7 +151,7 @@ end function jingle_mt:send_command(command, element, callback) - local stanza = st.iq({ to = self.peer, type = "set" }) + local stanza = verse.iq({ to = self.peer, type = "set" }) :tag("jingle", { xmlns = xmlns_jingle, sid = self.sid, @@ -168,7 +167,7 @@ end function jingle_mt:accept(options) - local accept_stanza = st.iq({ to = self.peer, type = "set" }) + local accept_stanza = verse.iq({ to = self.peer, type = "set" }) :tag("jingle", { xmlns = xmlns_jingle, sid = self.sid, @@ -204,7 +203,7 @@ end function jingle_mt:offer(name, content) - local session_initiate = st.iq({ to = self.peer, type = "set" }) + local session_initiate = verse.iq({ to = self.peer, type = "set" }) :tag("jingle", { xmlns = xmlns_jingle, action = "session-initiate", initiator = self.stream.jid, sid = self.sid });
--- a/plugins/presence.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/presence.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,4 +1,3 @@ -local st = require "util.stanza" function verse.plugins.presence(stream) stream.last_presence = nil; @@ -14,11 +13,8 @@ end end - -- Becase I didn't find util.stanza in the client code. - -- And, then the name fits better :) - -- // Zash function stream:set_status(opts) - local p = st.presence(); + local p = verse.presence(); if type(opts) == "table" then if opts.show then p:tag("show"):text(opts.show):up();
--- a/plugins/sasl.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/sasl.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,4 +1,3 @@ -local st = require "util.stanza"; local base64 = require "mime".b64; local xmlns_sasl = "urn:ietf:params:xml:ns:xmpp-sasl"; @@ -11,7 +10,7 @@ --stream.sasl_state, initial_data = sasl_new({"PLAIN"}, stream.username, stream.password, stream.jid); stream:debug("Selecting PLAIN mechanism..."); - local auth_stanza = st.stanza("auth", { xmlns = xmlns_sasl, mechanism = "PLAIN" }); + local auth_stanza = verse.stanza("auth", { xmlns = xmlns_sasl, mechanism = "PLAIN" }); if initial_data then auth_stanza:text(initial_data); end
--- a/plugins/session.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/session.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,4 +1,3 @@ -local st = require "util.stanza"; local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session"; function verse.plugins.session(stream) @@ -8,7 +7,7 @@ if session_feature and not session_feature:get_child("optional") then local function handle_binding(jid) stream:debug("Establishing Session..."); - stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), + stream:send_iq(verse.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), function (reply) if reply.attr.type == "result" then stream:event("session-success");
--- a/plugins/smacks.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/smacks.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,5 +1,3 @@ -local st = require "util.stanza"; - local xmlns_sm = "urn:xmpp:sm:2"; function verse.plugins.smacks(stream) @@ -75,7 +73,7 @@ local function on_bind_success() if not stream.smacks then --stream:unhook("bind-success", on_bind_success); - stream:send(st.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); + stream:send(verse.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); end end @@ -83,7 +81,7 @@ if features:get_child("sm", xmlns_sm) then stream.stream_management_supported = true; if stream.smacks and stream.bound then -- Already enabled in a previous session - resume - stream:send(st.stanza("resume", { xmlns = xmlns_sm, + stream:send(verse.stanza("resume", { xmlns = xmlns_sm, h = handled_stanza_count, previd = stream.resumption_token })); else stream:hook("bind-success", on_bind_success);
--- a/plugins/tls.lua Thu Mar 17 01:30:44 2011 +0100 +++ b/plugins/tls.lua Thu Mar 17 18:33:52 2011 +0100 @@ -1,4 +1,3 @@ -local st = require "util.stanza"; local xmlns_tls = "urn:ietf:params:xml:ns:xmpp-tls"; function verse.plugins.tls(stream) @@ -6,7 +5,7 @@ if stream.authenticated then return; end if features_stanza:get_child("starttls", xmlns_tls) and stream.conn.starttls then stream:debug("Negotiating TLS..."); - stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); + stream:send(verse.stanza("starttls", { xmlns = xmlns_tls })); return true; elseif not stream.conn.starttls and not stream.secure then stream:warn("SSL libary (LuaSec) not loaded, so TLS not available");