#!/usr/bin/env php
<?php
/*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-# Abort if called from a web server
-if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
-}
-
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
-define('LACONICA', true);
-require_once(INSTALLDIR . '/lib/common.php');
-require_once(INSTALLDIR . '/lib/jabber.php');
-require_once(INSTALLDIR . '/lib/queuehandler.php');
+$shortoptions = 'i::';
+$longoptions = array('id::');
-set_error_handler('common_error_handler');
+$helptext = <<<END_OF_PUBLIC_HELP
+Daemon script for pushing new notices to public XMPP subscribers.
-class PublicQueueHandler extends QueueHandler {
-
- function transport() {
- return 'public';
- }
-
- function start() {
- # Low priority; we don't want to receive messages
- $this->conn = jabber_connect($this->_id, NULL, -1);
- return !is_null($this->conn);
- }
+ -i --id Identity (default none)
- function handle_notice($notice) {
- return jabber_public_notice($notice);
- }
-
- function finish() {
- }
-}
+END_OF_PUBLIC_HELP;
-mb_internal_encoding('UTF-8');
+require_once INSTALLDIR.'/scripts/commandline.inc';
-$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-public');
+require_once INSTALLDIR . '/lib/jabber.php';
+require_once INSTALLDIR . '/lib/xmppqueuehandler.php';
-$handler = new XmppQueueHandler($resource);
+class PublicQueueHandler extends XmppQueueHandler
+{
-if ($handler->start()) {
- $handler->handle_queue();
+ function transport()
+ {
+ return 'public';
+ }
+
+ function handle_notice($notice)
+ {
+ try {
+ return jabber_public_notice($notice);
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ die($e->getMessage());
+ }
+ }
}
-$handler->finish();
+// Abort immediately if xmpp is not enabled, otherwise the daemon chews up
+// lots of CPU trying to connect to unconfigured servers
+if (common_config('xmpp','enabled')==false) {
+ print "Aborting daemon - xmpp is disabled\n";
+ exit();
+}
+
+if (have_option('i')) {
+ $id = get_option_value('i');
+} else if (have_option('--id')) {
+ $id = get_option_value('--id');
+} else if (count($args) > 0) {
+ $id = $args[0];
+} else {
+ $id = null;
+}
+
+$handler = new PublicQueueHandler($id);
+
+$handler->runOnce();