~singpolyma/biboumi

2922c68e8315190bfc1aa81fbf4959dbb052be3b — louiz’ 7 years ago 07e2209
Respond to disco#info requests on IRC server JIDs

This makes it possible to execute an ad-hoc command on a server, with
clients like Gajim, for example.
2 files changed, 39 insertions(+), 1 deletions(-)

M src/xmpp/biboumi_component.cpp
M src/xmpp/biboumi_component.hpp
M src/xmpp/biboumi_component.cpp => src/xmpp/biboumi_component.cpp +35 -1
@@ 399,9 399,10 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
      const XmlNode* query;
      if ((query = stanza.get_child("query", DISCO_INFO_NS)))
        { // Disco info
          Iid iid(to.local, {});
          const std::string node = query->get_tag("node");
          if (to_str == this->served_hostname)
            {
              const std::string node = query->get_tag("node");
              if (node.empty())
                {
                  // On the gateway itself


@@ 409,6 410,14 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
                  stanza_error.disable();
                }
            }
          else if (iid.type == Iid::Type::Server)
            {
                if (node.empty())
                {
                    this->send_irc_server_disco_info(id, from, to_str);
                    stanza_error.disable();
                }
            }
        }
      else if ((query = stanza.get_child("query", VERSION_NS)))
        {


@@ 684,6 693,31 @@ void BiboumiComponent::send_self_disco_info(const std::string& id, const std::st
  this->send_stanza(iq);
}

void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from)
{
  Jid from(jid_from);
  Stanza iq("iq");
  iq["type"] = "result";
  iq["id"] = id;
  iq["to"] = jid_to;
  iq["from"] = jid_from;
  XmlNode query("query");
  query["xmlns"] = DISCO_INFO_NS;
  XmlNode identity("identity");
  identity["category"] = "conference";
  identity["type"] = "irc";
  identity["name"] = "IRC server "s + from.local + " over Biboumi";
  query.add_child(std::move(identity));
  for (const char* ns: {DISCO_INFO_NS, ADHOC_NS, PING_NS, VERSION_NS})
    {
      XmlNode feature("feature");
      feature["var"] = ns;
      query.add_child(std::move(feature));
    }
  iq.add_child(std::move(query));
  this->send_stanza(iq);
}

void BiboumiComponent::send_iq_version_request(const std::string& from,
                                            const std::string& jid_to)
{

M src/xmpp/biboumi_component.hpp => src/xmpp/biboumi_component.hpp +4 -0
@@ 62,6 62,10 @@ public:
   */
  void send_self_disco_info(const std::string& id, const std::string& jid_to);
  /**
   * Send a result IQ with the disco informations regarding IRC server JIDs.
   */
  void send_irc_server_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from);
  /**
   * Send an iq version request
   */
  void send_iq_version_request(const std::string& from,