summaryrefslogtreecommitdiff
path: root/src/xmpp/xmpp_component.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-07 01:53:09 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-07 01:53:09 +0100
commita418b6ed5d70f0e61e71bb1adce2a693ade89e30 (patch)
treef4d979e1dae286df4faa6de3660288495d4ced77 /src/xmpp/xmpp_component.cpp
parent4b76a30d0479f366374c7dcf99ac211038722503 (diff)
downloadbiboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.gz
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.bz2
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.tar.xz
biboumi-a418b6ed5d70f0e61e71bb1adce2a693ade89e30.zip
Send and receive messages
Also correctly respond to PING with the id, escape some XML content, but not always
Diffstat (limited to 'src/xmpp/xmpp_component.cpp')
-rw-r--r--src/xmpp/xmpp_component.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp
index 3a288c7..cd9cd6f 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -25,6 +25,8 @@ XmppComponent::XmppComponent(const std::string& hostname, const std::string& sec
std::bind(&XmppComponent::handle_handshake, this,std::placeholders::_1));
this->stanza_handlers.emplace("presence",
std::bind(&XmppComponent::handle_presence, this,std::placeholders::_1));
+ this->stanza_handlers.emplace("message",
+ std::bind(&XmppComponent::handle_message, this,std::placeholders::_1));
}
XmppComponent::~XmppComponent()
@@ -151,6 +153,20 @@ void XmppComponent::handle_presence(const Stanza& stanza)
bridge->join_irc_channel(iid, to.resource);
}
+void XmppComponent::handle_message(const Stanza& stanza)
+{
+ Bridge* bridge = this->get_user_bridge(stanza["from"]);
+ Jid to(stanza["to"]);
+ Iid iid(to.local);
+ XmlNode* body = stanza.get_child("body");
+ if (stanza["type"] == "groupchat")
+ {
+ if (to.resource.empty())
+ if (body && !body->get_inner().empty())
+ bridge->send_channel_message(iid, body->get_inner());
+ }
+}
+
Bridge* XmppComponent::get_user_bridge(const std::string& user_jid)
{
try
@@ -239,3 +255,17 @@ void XmppComponent::send_topic(const std::string& from, const std::string& topic
message.close();
this->send_stanza(message);
}
+
+void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, const std::string body_str, const std::string& jid_to)
+{
+ Stanza message("message");
+ message["to"] = jid_to;
+ message["from"] = muc_name + "@" + this->served_hostname + "/" + nick;
+ message["type"] = "groupchat";
+ XmlNode body("body");
+ body.set_inner(body_str);
+ body.close();
+ message.add_child(std::move(body));
+ message.close();
+ this->send_stanza(message);
+}