From 7abcee54ea9d4ca71bf8422fd88b87a45e465843 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 2 Sep 2008 12:53:19 -0400 Subject: [PATCH] add reconnect handlers to main XMPP-handling scripts darcs-hash:20080902165319-84dde-b6cc255f014e6c5c059905c37c258a6c7a53b39a.gz --- scripts/publicqueuehandler.php | 12 +++++++----- scripts/xmppconfirmhandler.php | 12 +++++++----- scripts/xmppdaemon.php | 6 ++++++ scripts/xmppqueuehandler.php | 12 +++++++----- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index 555298f6a9..b482d029a7 100755 --- a/scripts/publicqueuehandler.php +++ b/scripts/publicqueuehandler.php @@ -42,14 +42,16 @@ class PublicQueueHandler extends QueueHandler { function start() { $this->log(LOG_INFO, "INITIALIZE"); # Low priority; we don't want to receive messages - $this->conn = jabber_connect($this->_id); - if ($this->conn) { - $this->conn->addEventHandler('message', 'forward_message', $this); - jabber_send_presence("Send me a message to post an notice", 'available', NULL, 'available', -1); - } + $this->conn = jabber_connect($this->_id, NULL, -1); + $this->conn->addEventHandler('message', 'forward_message', $this); return !is_null($this->conn); } + function handle_reconnect(&$pl) { + $this->conn->processUntil('session_start'); + $this->conn->presence(NULL, 'available', NULL, 'available', -1); + } + function handle_notice($notice) { return jabber_public_notice($notice); } diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php index 7971198b1e..c63498f551 100755 --- a/scripts/xmppconfirmhandler.php +++ b/scripts/xmppconfirmhandler.php @@ -48,14 +48,16 @@ class XmppConfirmHandler { function start() { # Low priority; we don't want to receive messages $this->log(LOG_INFO, "INITIALIZE"); - $this->conn = jabber_connect($this->_id); - if ($this->conn) { - $this->conn->addEventHandler('message', 'forward_message', $this); - jabber_send_presence("Send me a message to post an notice", 'available', NULL, 'available', -1); - } + $this->conn = jabber_connect($this->_id, NULL, -1); + $this->conn->addEventHandler('message', 'forward_message', $this); return !is_null($this->conn); } + function handle_reconnect(&$pl) { + $this->conn->processUntil('session_start'); + $this->conn->presence(NULL, 'available', NULL, 'available', -1); + } + function handle_queue() { $this->log(LOG_INFO, 'checking for queued confirmations'); do { diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 03cadee7cb..2372a17e6d 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -75,10 +75,16 @@ class XMPPDaemon { function handle() { $this->conn->addEventHandler('message', 'handle_message', $this); $this->conn->addEventHandler('presence', 'handle_presence', $this); + $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); $this->conn->process(); } + function handle_reconnect(&$pl) { + $this->conn->processUntil('session_start'); + $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100); + } + function get_user($from) { $user = User::staticGet('jabber', jabber_normalize_jid($from)); return $user; diff --git a/scripts/xmppqueuehandler.php b/scripts/xmppqueuehandler.php index 7f1e6c28f4..49d3df0f50 100755 --- a/scripts/xmppqueuehandler.php +++ b/scripts/xmppqueuehandler.php @@ -44,14 +44,16 @@ class XmppQueueHandler extends QueueHandler { function start() { $this->log(LOG_INFO, "INITIALIZE"); # Low priority; we don't want to receive messages - $this->conn = jabber_connect($this->_id); - if ($this->conn) { - $this->conn->addEventHandler('message', 'forward_message', $this); - jabber_send_presence("Send me a message to post an notice", 'available', NULL, 'available', -1); - } + $this->conn = jabber_connect($this->_id, NULL, -1); + $this->conn->addEventHandler('message', 'forward_message', $this); return !is_null($this->conn); } + function handle_reconnect(&$pl) { + $this->conn->processUntil('session_start'); + $this->conn->presence(NULL, 'available', NULL, 'available', -1); + } + function handle_notice($notice) { return jabber_broadcast_notice($notice); } -- 2.39.5