mix: Return error conditions
This commit is contained in:
parent
881085e767
commit
08f0ad4e20
@ -134,6 +134,14 @@ function module.load()
|
|||||||
module:log("debug", "Loading MIX channels done.");
|
module:log("debug", "Loading MIX channels done.");
|
||||||
end
|
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:hook("host-disco-items", function(event)
|
||||||
module:log("debug", "host-disco-items called");
|
module:log("debug", "host-disco-items called");
|
||||||
local reply = event.reply;
|
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 origin, stanza = event.origin, event.stanza;
|
||||||
local _, channel = get_channel(staza.attr.to);
|
local _, channel = get_channel(staza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Send error message
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: Maybe check permissions
|
||||||
|
|
||||||
local reply = st.reply(stanza):tag("query", { xmlns = "http://jabber.org/protocol/disco#items", node = "mix" });
|
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
|
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();
|
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 origin, stanza = event.origin, event.stanza;
|
||||||
local _, channel = get_channel(stanza.attr.to);
|
local _, channel = get_channel(stanza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Send error message
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
local reply = st.reply(stanza):tag("query", { xmlns = "http://jabber.org/protocol/disco#info" });
|
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("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);
|
origin.send(reply);
|
||||||
return true;
|
return true;
|
||||||
end);
|
end);
|
||||||
@ -183,11 +197,11 @@ end);
|
|||||||
function find_participant(table, jid)
|
function find_participant(table, jid)
|
||||||
for i, v in pairs(table) do
|
for i, v in pairs(table) do
|
||||||
if v.jid == jid then
|
if v.jid == jid then
|
||||||
return i
|
return i;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return -1
|
return -1;
|
||||||
end
|
end
|
||||||
|
|
||||||
module:hook("iq-set/bare/urn:xmpp:mix:core:1:leave", function(event)
|
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 from = jid.bare(stanza.attr.from);
|
||||||
local i, channel = get_channel(stanza.attr.to);
|
local i, channel = get_channel(stanza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Return error
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
local participant_index = find_participant(channel.participants, from);
|
local participant_index = find_participant(channel.participants, from);
|
||||||
if participant_index == -1 then
|
if participant_index == -1 then
|
||||||
|
origin.send(st.error_reply(stanza,
|
||||||
|
"cancel",
|
||||||
|
"forbidden",
|
||||||
|
"Not a participant"));
|
||||||
channel:debug_print();
|
channel:debug_print();
|
||||||
module:log("debug", "%s is not a participant in %s", from, channel.jid);
|
module:log("debug", "%s is not a participant in %s", from, channel.jid);
|
||||||
return;
|
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 origin, stanza = event.origin, event.stanza;
|
||||||
local i, channel = get_channel(stanza.attr.to);
|
local i, channel = get_channel(stanza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Return error
|
origin.send(channel_not_found(stanza));
|
||||||
return
|
return;
|
||||||
end
|
end
|
||||||
local from = jid.bare(stanza.attr.from);
|
local from = jid.bare(stanza.attr.from);
|
||||||
local spid = channel.spid[from] or uuid.generate(); -- Stable Participant ID
|
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 from = jid.bare(stanza.attr.from);
|
||||||
local i, channel = get_channel(stanza.attr.to);
|
local i, channel = get_channel(stanza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Return error
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
local participant_index = find_participant(channel.participants, from);
|
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;
|
node = create.attr.channel;
|
||||||
local _, channel = get_channel(stanza.attr.to);
|
local _, channel = get_channel(stanza.attr.to);
|
||||||
if channel then
|
if channel then
|
||||||
-- TODO: Return error
|
origin.send(st.error_reply(stanza,
|
||||||
|
"cancel",
|
||||||
|
"conflict",
|
||||||
|
"Channel already exists"));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
create_channel(create.attr.channel, from, false);
|
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 node_jid = string.format("%s@%s", node, host);
|
||||||
local i, channel = get_channel(node_jid);
|
local i, channel = get_channel(node_jid);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Error
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
-- TODO: Check permissions
|
-- TODO: Check permissions
|
||||||
|
|
||||||
@ -392,21 +417,24 @@ end);
|
|||||||
|
|
||||||
module:hook("message/bare", function(event)
|
module:hook("message/bare", function(event)
|
||||||
module:log("debug", "MIX message detected");
|
module:log("debug", "MIX message detected");
|
||||||
local stanza = event.stanza;
|
local stanza, origin = event.stanza, event.origin;
|
||||||
|
|
||||||
if stanza.attr.type ~= "groupchat" then
|
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
|
end
|
||||||
|
|
||||||
local from = jid.bare(stanza.attr.from);
|
local from = jid.bare(stanza.attr.from);
|
||||||
local i, channel = get_channel(stanza.attr.to);
|
local i, channel = get_channel(stanza.attr.to);
|
||||||
if not channel then
|
if not channel then
|
||||||
-- TODO: Error handlung
|
origin.send(channel_not_found(stanza));
|
||||||
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
local participant_index = find_participant(channel.participants, from);
|
local participant_index = find_participant(channel.participants, from);
|
||||||
if participant_index == -1 then
|
if participant_index == -1 then
|
||||||
-- TODO: Error not in channel
|
origin.send(st.error_reply(stanza, "cancel", "forbidden", "Not a participant"));
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
local participant = channel.participants[participant_index];
|
local participant = channel.participants[participant_index];
|
||||||
|
Loading…
Reference in New Issue
Block a user