]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/xmppdaemon.php
csrf protection in userauthorization
[quix0rs-gnu-social.git] / scripts / xmppdaemon.php
index c15f28113121cb73d4cfd515fb35edc564eebb5c..da1638011603f57250187d78e9679afd91a76d6e 100755 (executable)
@@ -53,6 +53,9 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 define('LACONICA', true);
 define('CLAIM_TIMEOUT', 100000);
 
+define('MAX_BROADCAST_COUNT', 20);
+define('MAX_CONFIRM_COUNT', 20);
+
 require_once(INSTALLDIR . '/lib/common.php');
 require_once(INSTALLDIR . '/lib/jabber.php');
 
@@ -96,17 +99,22 @@ class XMPPDaemon {
 
        function handle() {
 
-               $this->conn->addEventHandler('message','handle_message',$this);
-               $this->conn->addEventHandler('presence','handle_presence',$this);
+               $this->conn->addEventHandler('message', 'handle_message', $this);
+               $this->conn->addEventHandler('presence', 'handle_presence', $this);
+               $this->conn->addEventHandler('session_start', 'handle_session_start', $this);
+               
                while(!$this->conn->isDisconnected()) {
-
-                       $this->conn->processTime(10);
+                       $this->conn->processTime(5);
                        $this->broadcast_queue();
                        $this->confirmation_queue();
                }
        }
 
-
+       function handle_session_start(&$pl) {
+               $this->conn->getRoster();
+               $this->set_status("Send me a message to post a notice");
+       }
+       
        function get_user($from) {
                $user = User::staticGet('jabber', jabber_normalize_jid($from));
                return $user;
@@ -334,6 +342,7 @@ class XMPPDaemon {
        function broadcast_queue() {
                $this->clear_old_claims();
                $this->log(LOG_INFO, 'checking for queued notices');
+               $cnt = 0;
                do {
                        $qi = $this->top_queue_item();
                        if ($qi) {
@@ -357,8 +366,9 @@ class XMPPDaemon {
                                        $this->log(LOG_WARNING, 'queue item for notice that does not exist');
                                }
                                $qi->delete();
+                               $cnt++;
                        }
-               } while ($qi);
+               } while ($qi && $cnt < MAX_BROADCAST_COUNT);
        }
 
        function clear_old_claims() {
@@ -376,6 +386,7 @@ class XMPPDaemon {
        function confirmation_queue() {
            # $this->clear_old_confirm_claims();
                $this->log(LOG_INFO, 'checking for queued confirmations');
+               $cnt = 0;
                do {
                        $confirm = $this->next_confirm();
                        if ($confirm) {
@@ -404,8 +415,9 @@ class XMPPDaemon {
                                                continue;
                                        }
                                }
+                               $cnt++;
                        }
-               } while ($confirm);
+               } while ($confirm && $cnt < MAX_CONFIRM_COUNT);
        }
 
        function next_confirm() {