function xmppdaemon_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
switch ($errno) {
case E_USER_ERROR:
- echo "ERROR: [$errno] $errstr ($errfile:$errline)\n";
- echo " Fatal error on line $errline in file $errfile";
- echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
- echo "Aborting...\n";
- exit(1);
- break;
+ echo "ERROR: [$errno] $errstr ($errfile:$errline)\n";
+ echo " Fatal error on line $errline in file $errfile";
+ echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
+ echo "Aborting...\n";
+ exit(1);
+ break;
- case E_USER_WARNING:
- echo "WARNING [$errno] $errstr ($errfile:$errline)\n";
- break;
+ case E_USER_WARNING:
+ echo "WARNING [$errno] $errstr ($errfile:$errline)\n";
+ break;
case E_USER_NOTICE:
- echo "My NOTICE [$errno] $errstr ($errfile:$errline)\n";
- break;
-
- default:
- echo "Unknown error type: [$errno] $errstr ($errfile:$errline)\n";
- break;
+ echo "NOTICE [$errno] $errstr ($errfile:$errline)\n";
+ break;
}
/* Don't execute PHP internal error handler */
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');
function handle() {
- static $parts = array('message', 'presence',
- 'end_stream', 'session_start');
-
+ $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()) {
-
- $payloads = $this->conn->processUntil($parts, 10);
-
- if ($payloads) {
- foreach($payloads as $event) {
- $pl = $event[1];
- switch($event[0]) {
- case 'message':
- $this->handle_message($pl);
- break;
- case 'presence':
- $this->handle_presence($pl);
- break;
- case 'session_start':
- $this->handle_session($pl);
- break;
- }
- }
- }
-
+ $this->conn->processTime(5);
$this->broadcast_queue();
$this->confirmation_queue();
}
}
- function handle_session($pl) {
- # XXX what to do here?
- return true;
+ 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;
if ($pl['type'] != 'chat') {
return;
}
- if (strlen($pl['body']) == 0) {
+ if (mb_strlen($pl['body']) == 0) {
return;
}
$this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
return;
} else {
- if(strlen($pl['body'])>140) {
- $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . strlen($pl['body']));
+ $len = mb_strlen($pl['body']);
+ if($len > 140) {
+ $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
return;
}
$this->add_notice($user, $pl);
return false;
}
}
-
+
function from_site($address, $msg) {
$text = '['.common_config('site', 'name') . '] ' . $msg;
jabber_send_message($address, $text);
# (or old)?
$this->log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id);
$orig = clone($qi);
- $qi->claimed = DB_DataObject_Cast::dateTime();
+ $qi->claimed = common_sql_now();
$result = $qi->update($orig);
if ($result) {
$this->log(LOG_INFO, 'claim succeeded.');
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) {
$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() {
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) {
continue;
}
}
+ $cnt++;
}
- } while ($confirm);
+ } while ($confirm && $cnt < MAX_CONFIRM_COUNT);
}
function next_confirm() {
# working around some weird DB_DataObject behaviour
$confirm->whereAdd(''); # clears where stuff
$original = clone($confirm);
- $confirm->claimed = DB_DataObject_Cast::dateTime();
+ $confirm->claimed = common_sql_now();
$result = $confirm->update($original);
if ($result) {
$this->log(LOG_INFO, 'Succeeded in claim! '. $result);