Correctly do the error handling when we receive an iq
This commit is contained in:
+20
-11
@@ -367,6 +367,18 @@ void XmppComponent::handle_message(const Stanza& stanza)
|
|||||||
stanza_error.disable();
|
stanza_error.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We MUST return an iq, whatever happens, except if the type is
|
||||||
|
// "result".
|
||||||
|
// To do this, we use a scopeguard. If an exception is raised somewhere, an
|
||||||
|
// iq of type error "internal-server-error" is sent. If we handle the
|
||||||
|
// request properly (by calling a function that registers an iq to be sent
|
||||||
|
// later, or that directly sends an iq), we disable the ScopeGuard. If we
|
||||||
|
// reach the end of the function without having disabled the scopeguard, we
|
||||||
|
// send a "feature-not-implemented" iq as a result. If an other kind of
|
||||||
|
// error is found (for example the feature is implemented in biboumi, but
|
||||||
|
// the request is missing some attribute) we can just change the values of
|
||||||
|
// error_type and error_name and return from the function (without disabling
|
||||||
|
// the scopeguard); an iq error will be sent
|
||||||
void XmppComponent::handle_iq(const Stanza& stanza)
|
void XmppComponent::handle_iq(const Stanza& stanza)
|
||||||
{
|
{
|
||||||
std::string id = stanza.get_tag("id");
|
std::string id = stanza.get_tag("id");
|
||||||
@@ -386,6 +398,8 @@ void XmppComponent::handle_iq(const Stanza& stanza)
|
|||||||
Bridge* bridge = this->get_user_bridge(from);
|
Bridge* bridge = this->get_user_bridge(from);
|
||||||
Jid to(to_str);
|
Jid to(to_str);
|
||||||
|
|
||||||
|
// These two values will be used in the error iq sent if we don't disable
|
||||||
|
// the scopeguard.
|
||||||
std::string error_type("cancel");
|
std::string error_type("cancel");
|
||||||
std::string error_name("internal-server-error");
|
std::string error_name("internal-server-error");
|
||||||
utils::ScopeGuard stanza_error([&](){
|
utils::ScopeGuard stanza_error([&](){
|
||||||
@@ -403,19 +417,14 @@ void XmppComponent::handle_iq(const Stanza& stanza)
|
|||||||
std::string nick = child->get_tag("nick");
|
std::string nick = child->get_tag("nick");
|
||||||
std::string role = child->get_tag("role");
|
std::string role = child->get_tag("role");
|
||||||
if (!nick.empty() && role == "none")
|
if (!nick.empty() && role == "none")
|
||||||
{
|
{ // This is a kick
|
||||||
std::string reason;
|
std::string reason;
|
||||||
XmlNode* reason_el = child->get_child(MUC_ADMIN_NS":reason");
|
XmlNode* reason_el = child->get_child(MUC_ADMIN_NS":reason");
|
||||||
if (reason_el)
|
if (reason_el)
|
||||||
reason = reason_el->get_inner();
|
reason = reason_el->get_inner();
|
||||||
Iid iid(to.local);
|
Iid iid(to.local);
|
||||||
bridge->send_irc_kick(iid, nick, reason);
|
bridge->send_irc_kick(iid, nick, reason);
|
||||||
}
|
stanza_error.disable();
|
||||||
else
|
|
||||||
{
|
|
||||||
error_type = "cancel";
|
|
||||||
error_name = "feature-not-implemented";
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,16 +437,16 @@ void XmppComponent::handle_iq(const Stanza& stanza)
|
|||||||
if (to_str == this->served_hostname)
|
if (to_str == this->served_hostname)
|
||||||
{ // On the gateway itself
|
{ // On the gateway itself
|
||||||
this->send_self_disco_info(id, from);
|
this->send_self_disco_info(id, from);
|
||||||
|
stanza_error.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (type == "result")
|
||||||
{
|
{
|
||||||
|
stanza_error.disable();
|
||||||
|
}
|
||||||
error_type = "cancel";
|
error_type = "cancel";
|
||||||
error_name = "feature-not-implemented";
|
error_name = "feature-not-implemented";
|
||||||
return;
|
|
||||||
}
|
|
||||||
stanza_error.disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmppComponent::handle_error(const Stanza& stanza)
|
void XmppComponent::handle_error(const Stanza& stanza)
|
||||||
|
|||||||
Reference in New Issue
Block a user