diff --git a/mod_mix/mod_mix.lua b/mod_mix/mod_mix.lua index 1487848..c83a967 100644 --- a/mod_mix/mod_mix.lua +++ b/mod_mix/mod_mix.lua @@ -134,6 +134,14 @@ function module.load() module:log("debug", "Loading MIX channels done."); end +function channel_not_found(stanza) + -- Wrapper for returning a "Channel-not-found" error stanza + return st.error_reply(stanza, + "cancel", + "item-not-found", + "The MIX channel was not found"); +end + module:hook("host-disco-items", function(event) module:log("debug", "host-disco-items called"); local reply = event.reply; @@ -151,8 +159,12 @@ module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(eve local origin, stanza = event.origin, event.stanza; local _, channel = get_channel(staza.attr.to); if not channel then - -- TODO: Send error message + origin.send(channel_not_found(stanza)); + return; end + + -- TODO: Maybe check permissions + local reply = st.reply(stanza):tag("query", { xmlns = "http://jabber.org/protocol/disco#items", node = "mix" }); for _, node in pairs({"urn:xmpp:mix:nodes:messages", "urn:xmpp:mix:nodes:participants", "urn:xmpp:mix:nodes:info"}) do reply:tag("item", { jid = channel.jid, node = node }):up(); @@ -168,14 +180,16 @@ module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(even local origin, stanza = event.origin, event.stanza; local _, channel = get_channel(stanza.attr.to); if not channel then - -- TODO: Send error message + origin.send(channel_not_found(stanza)); + return; end local reply = st.reply(stanza):tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }); - reply:tag("identity", { category = "conference", name = channel.name, type = "mix" }):up(); - reply:tag("feature", { var = "urn:xmpp:mix:core:1" }):up(); - -- TODO: Do something here - reply:tag("feature", { var = "urn:xmpp:mix:core:1#create-channel" }):up(); reply:tag("feature", { var = "http://jabber.org/protocol/disco#info" }):up(); + reply:tag("identity", { category = "conference", name = channel.name, type = "mix" }):up(); + + reply:tag("feature", { var = "urn:xmpp:mix:core:1" }):up(); + -- TODO: Check permissions + reply:tag("feature", { var = "urn:xmpp:mix:core:1#create-channel" }):up(); origin.send(reply); return true; end); @@ -183,11 +197,11 @@ end); function find_participant(table, jid) for i, v in pairs(table) do if v.jid == jid then - return i + return i; end end - return -1 + return -1; end module:hook("iq-set/bare/urn:xmpp:mix:core:1:leave", function(event) @@ -196,11 +210,16 @@ module:hook("iq-set/bare/urn:xmpp:mix:core:1:leave", function(event) local from = jid.bare(stanza.attr.from); local i, channel = get_channel(stanza.attr.to); if not channel then - -- TODO: Return error + origin.send(channel_not_found(stanza)); + return; end local participant_index = find_participant(channel.participants, from); if participant_index == -1 then + origin.send(st.error_reply(stanza, + "cancel", + "forbidden", + "Not a participant")); channel:debug_print(); module:log("debug", "%s is not a participant in %s", from, channel.jid); return; @@ -230,8 +249,8 @@ module:hook("iq-set/bare/urn:xmpp:mix:core:1:join", function(event) local origin, stanza = event.origin, event.stanza; local i, channel = get_channel(stanza.attr.to); if not channel then - -- TODO: Return error - return + origin.send(channel_not_found(stanza)); + return; end local from = jid.bare(stanza.attr.from); local spid = channel.spid[from] or uuid.generate(); -- Stable Participant ID @@ -273,7 +292,8 @@ module:hook("iq-set/bare/urn:xmpp:mix:core:1:setnick", function(event) local from = jid.bare(stanza.attr.from); local i, channel = get_channel(stanza.attr.to); if not channel then - -- TODO: Return error + origin.send(channel_not_found(stanza)); + return; end local participant_index = find_participant(channel.participants, from); @@ -344,7 +364,11 @@ module:hook("iq-set/host/urn:xmpp:mix:core:1:create", function(event) node = create.attr.channel; local _, channel = get_channel(stanza.attr.to); if channel then - -- TODO: Return error + origin.send(st.error_reply(stanza, + "cancel", + "conflict", + "Channel already exists")); + return; end create_channel(create.attr.channel, from, false); @@ -372,7 +396,8 @@ module:hook("iq-set/host/urn:xmpp:mix:core:1:destroy", function(event) local node_jid = string.format("%s@%s", node, host); local i, channel = get_channel(node_jid); if not channel then - -- TODO: Error + origin.send(channel_not_found(stanza)); + return; end -- TODO: Check permissions @@ -392,21 +417,24 @@ end); module:hook("message/bare", function(event) module:log("debug", "MIX message detected"); - local stanza = event.stanza; + local stanza, origin = event.stanza, event.origin; if stanza.attr.type ~= "groupchat" then - -- TODO: Error handling + -- TODO: Is this correct? + origin.send(st.error_reply(stanza, "cancel", "bad-request", "Non-groupchat message")); + return; end local from = jid.bare(stanza.attr.from); local i, channel = get_channel(stanza.attr.to); if not channel then - -- TODO: Error handlung + origin.send(channel_not_found(stanza)); + return; end local participant_index = find_participant(channel.participants, from); if participant_index == -1 then - -- TODO: Error not in channel + origin.send(st.error_reply(stanza, "cancel", "forbidden", "Not a participant")); return; end local participant = channel.participants[participant_index];