X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fxmppdaemon.php;h=ef3f8c63d862472d52d3af9e725e7c1262797ce9;hb=b140bcdee4b1f4c8f2f34a89a9c5c51e7ecfe826;hp=cd27a2c1492b00782c85095cf02b13efbfbadba1;hpb=edbc0c665cc65875b4d14b79939233b1c9c06bb6;p=quix0rs-gnu-social.git diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index cd27a2c149..ef3f8c63d8 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -37,9 +37,11 @@ set_error_handler('common_error_handler'); # in jabber.php, which create a new XMPP class. A more elegant (?) solution # might be to use make this a subclass of XMPP. -class XMPPDaemon extends Daemon { +class XMPPDaemon extends Daemon +{ - function XMPPDaemon($resource=NULL) { + function XMPPDaemon($resource=null) + { static $attrs = array('server', 'port', 'user', 'password', 'host'); foreach ($attrs as $attr) @@ -56,7 +58,8 @@ class XMPPDaemon extends Daemon { $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}"); } - function connect() { + function connect() + { $connect_to = ($this->host) ? $this->host : $this->server; @@ -71,15 +74,17 @@ class XMPPDaemon extends Daemon { $this->conn->setReconnectTimeout(600); jabber_send_presence("Send me a message to post a notice", 'available', - NULL, 'available', 100); + null, 'available', 100); return !$this->conn->isDisconnected(); } - function name() { + function name() + { return strtolower('xmppdaemon.'.$this->resource); } - function run() { + function run() + { if ($this->connect()) { $this->conn->addEventHandler('message', 'handle_message', $this); @@ -90,17 +95,20 @@ class XMPPDaemon extends Daemon { } } - function handle_reconnect(&$pl) { + function handle_reconnect(&$pl) + { $this->conn->processUntil('session_start'); - $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100); + $this->conn->presence('Send me a message to post a notice', 'available', null, 'available', 100); } - function get_user($from) { + function get_user($from) + { $user = User::staticGet('jabber', jabber_normalize_jid($from)); return $user; } - function handle_message(&$pl) { + function handle_message(&$pl) + { if ($pl['type'] != 'chat') { return; } @@ -156,53 +164,59 @@ class XMPPDaemon extends Daemon { unset($user); } - function is_self($from) { + function is_self($from) + { return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from)); } - function get_ofrom($pl) { + function get_ofrom($pl) + { $xml = $pl['xml']; $addresses = $xml->sub('addresses'); if (!$addresses) { $this->log(LOG_WARNING, 'Forwarded message without addresses'); - return NULL; + return null; } $address = $addresses->sub('address'); if (!$address) { $this->log(LOG_WARNING, 'Forwarded message without address'); - return NULL; + return null; } if (!array_key_exists('type', $address->attrs)) { $this->log(LOG_WARNING, 'No type for forwarded message'); - return NULL; + return null; } $type = $address->attrs['type']; if ($type != 'ofrom') { $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom'); - return NULL; + return null; } if (!array_key_exists('jid', $address->attrs)) { $this->log(LOG_WARNING, 'No jid for forwarded message'); - return NULL; + return null; } $jid = $address->attrs['jid']; if (!$jid) { $this->log(LOG_WARNING, 'Could not get jid from address'); - return NULL; + return null; } $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid); return $jid; } - function is_autoreply($txt) { + function is_autoreply($txt) + { if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) { return true; + } else if (preg_match('/^System: Message wasn\'t delivered. Offline storage size was exceeded.$/', $txt)) { + return true; } else { return false; } } - function is_otr($txt) { + function is_otr($txt) + { if (preg_match('/^\?OTR/', $txt)) { return true; } else { @@ -210,7 +224,8 @@ class XMPPDaemon extends Daemon { } } - function is_direct($txt) { + function is_direct($txt) + { if (strtolower(substr($txt, 0, 2))=='d ') { return true; } else { @@ -218,12 +233,14 @@ class XMPPDaemon extends Daemon { } } - function from_site($address, $msg) { + function from_site($address, $msg) + { $text = '['.common_config('site', 'name') . '] ' . $msg; jabber_send_message($address, $text); } - function handle_command($user, $body) { + function handle_command($user, $body) + { $inter = new CommandInterpreter(); $cmd = $inter->handle_command($user, $body); if ($cmd) { @@ -235,7 +252,8 @@ class XMPPDaemon extends Daemon { } } - function add_notice(&$user, &$pl) { + function add_notice(&$user, &$pl) + { $body = trim($pl['body']); $content_shortened = common_shorten_link($body); if (mb_strlen($content_shortened) > 140) { @@ -257,7 +275,8 @@ class XMPPDaemon extends Daemon { unset($notice); } - function handle_presence(&$pl) { + function handle_presence(&$pl) + { $from = jabber_normalize_jid($pl['from']); switch ($pl['type']) { case 'subscribe': @@ -291,11 +310,13 @@ class XMPPDaemon extends Daemon { } } - function log($level, $msg) { + function log($level, $msg) + { common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg); } - function subscribed($to) { + function subscribed($to) + { jabber_special_presence('subscribed', $to); } }