summaryrefslogtreecommitdiff
path: root/scripts/xmppdaemon.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-08-30 00:07:17 -0400
committerEvan Prodromou <evan@prodromou.name>2008-08-30 00:07:17 -0400
commit4cdd90283b46db68d278d287074c740348b4ba55 (patch)
tree50cd256e4aa94203641715f26c633f324fcf93ca /scripts/xmppdaemon.php
parent9907a2101d8670a113444c95b2c98c2eec79c184 (diff)
forward messages from queuehandler to listener
The queuehandler sends messages to the user. If the user replies, the messages are typically sent directly to the queuehandler (including resource), not the default bot JID. We add a little code for the xmppqueuehandler to periodically service its queue of received messages. Received messages are forwarded to the listener to deal with. We use XEP 33, 'addresses', to note the original sender. The xmppdaemon checks to see if the 'from' on a message is the daemon address. If so, it looks for a XEP 33 'addresses' stanza, with an 'ofrom' address, which shows who it was originally is from. This should let us send from one resource ID and still process incoming messages in a different connection. darcs-hash:20080830040717-84dde-59c75bfb107a1dd5fd531106751b4544bfd15656.gz
Diffstat (limited to 'scripts/xmppdaemon.php')
-rwxr-xr-xscripts/xmppdaemon.php33
1 files changed, 32 insertions, 1 deletions
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index ed523cd81..b1cdb914c 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -73,7 +73,7 @@ class XMPPDaemon {
function handle() {
$this->conn->addEventHandler('message', 'handle_message', $this);
$this->conn->addEventHandler('presence', 'handle_presence', $this);
-
+
$this->conn->process();
}
@@ -91,6 +91,17 @@ class XMPPDaemon {
}
$from = jabber_normalize_jid($pl['from']);
+
+ # Forwarded from another daemon (probably a broadcaster) for
+ # us to handle
+
+ if (preg_match('/^'.jabber_daemon_address().'/', $from)) {
+ $from = $this->get_ofrom($pl);
+ if (is_null($from)) {
+ return;
+ }
+ }
+
$user = $this->get_user($from);
if (!$user) {
@@ -118,6 +129,26 @@ class XMPPDaemon {
}
}
+ function get_ofrom($pl) {
+ $xml = $pl['raw'];
+ $addresses = $xml->sub('adddresses');
+ if (!$addresses) {
+ $this->log(LOG_WARNING, 'Forwarded message without addresses');
+ return NULL;
+ }
+ $address = $xml->sub('address');
+ if (!$address) {
+ $this->log(LOG_WARNING, 'Forwarded message without address');
+ return NULL;
+ }
+ $type = $address->attr('type');
+ if ($type != 'ofrom') {
+ $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom');
+ return NULL;
+ }
+ return $address->attr('jid');
+ }
+
function is_autoreply($txt) {
if (preg_match('/[\[\(]?[Aa]uto-?[Rr]eply[\]\)]/', $txt)) {
return true;