]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/xmppdaemon.php
Fix error in xmpp help
[quix0rs-gnu-social.git] / scripts / xmppdaemon.php
index c29b14b7bd22e53f806f4b01d443da30d42e1053..e067fdcdb232ed30c3eb515ab4fd497aa4445068 100755 (executable)
@@ -29,6 +29,7 @@ define('LACONICA', true);
 
 require_once(INSTALLDIR . '/lib/common.php');
 require_once(INSTALLDIR . '/lib/jabber.php');
+require_once(INSTALLDIR . '/lib/daemon.php');
 
 set_error_handler('common_error_handler');
 
@@ -36,7 +37,7 @@ 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 {
+class XMPPDaemon extends Daemon {
 
        function XMPPDaemon($resource=NULL) {
                static $attrs = array('server', 'port', 'user', 'password', 'host');
@@ -74,12 +75,19 @@ class XMPPDaemon {
                return !$this->conn->isDisconnected();
        }
 
-       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 name() {
+               return strtolower('xmppdaemon.'.$this->resource);
+       }
+       
+       function run() {
+               if ($this->connect()) {
+                       
+                       $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) {
@@ -137,6 +145,9 @@ class XMPPDaemon {
                        }
                        $this->add_notice($user, $pl);
                }
+               
+               $user->free();
+               unset($user);
        }
 
        function is_self($from) {
@@ -273,6 +284,8 @@ class XMPPDaemon {
                common_broadcast_notice($notice);
                $this->log(LOG_INFO,
                                   'Added notice ' . $notice->id . ' from user ' . $user->nickname);
+               $notice->free();
+               unset($notice);
        }
 
        function handle_presence(&$pl) {
@@ -302,6 +315,8 @@ class XMPPDaemon {
                                                           ' status from presence.');
                                        $this->add_notice($user, $pl);
                                }
+                               $user->free();
+                               unset($user);
                        }
                        break;
                }
@@ -325,6 +340,4 @@ $resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-liste
 
 $daemon = new XMPPDaemon($resource);
 
-if ($daemon->connect()) {
-       $daemon->handle();
-}
+$daemon->runOnce();