summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.php4
-rw-r--r--lib/default.php2
-rw-r--r--lib/distribqueuehandler.php84
-rw-r--r--lib/iomaster.php12
-rw-r--r--lib/mailhandler.php2
-rw-r--r--lib/oauthstore.php2
-rw-r--r--lib/queuemanager.php9
-rw-r--r--lib/stompqueuemanager.php21
-rw-r--r--lib/util.php2
-rw-r--r--lib/xmppmanager.php4
10 files changed, 127 insertions, 15 deletions
diff --git a/lib/command.php b/lib/command.php
index c0a32e1b1..2a51fd687 100644
--- a/lib/command.php
+++ b/lib/command.php
@@ -422,7 +422,7 @@ class RepeatCommand extends Command
$repeat = $notice->repeat($this->user->id, $channel->source);
if ($repeat) {
- common_broadcast_notice($repeat);
+
$channel->output($this->user, sprintf(_('Notice from %s repeated'), $recipient->nickname));
} else {
$channel->error($this->user, _('Error repeating notice.'));
@@ -492,7 +492,7 @@ class ReplyCommand extends Command
} else {
$channel->error($this->user, _('Error saving notice.'));
}
- common_broadcast_notice($notice);
+
}
}
diff --git a/lib/default.php b/lib/default.php
index d258bbaf4..4f24a6d22 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -30,6 +30,8 @@
$default =
array('site' =>
array('name' => 'Just another StatusNet microblog',
+ 'nickname' => 'statusnet',
+ 'wildcard' => null,
'server' => $_server,
'theme' => 'default',
'path' => $_path,
diff --git a/lib/distribqueuehandler.php b/lib/distribqueuehandler.php
new file mode 100644
index 000000000..f458d238d
--- /dev/null
+++ b/lib/distribqueuehandler.php
@@ -0,0 +1,84 @@
+<?php
+/*
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+/**
+ * Base class for queue handlers.
+ *
+ * As extensions of the Daemon class, each queue handler has the ability
+ * to launch itself in the background, at which point it'll pass control
+ * to the configured QueueManager class to poll for updates.
+ *
+ * Subclasses must override at least the following methods:
+ * - transport
+ * - handle_notice
+ */
+
+class DistribQueueHandler
+{
+ /**
+ * Return transport keyword which identifies items this queue handler
+ * services; must be defined for all subclasses.
+ *
+ * Must be 8 characters or less to fit in the queue_item database.
+ * ex "email", "jabber", "sms", "irc", ...
+ *
+ * @return string
+ */
+
+ function transport()
+ {
+ return 'distrib';
+ }
+
+ /**
+ * Here's the meat of your queue handler -- you're handed a Notice
+ * object, which you may do as you will with.
+ *
+ * If this function indicates failure, a warning will be logged
+ * and the item is placed back in the queue to be re-run.
+ *
+ * @param Notice $notice
+ * @return boolean true on success, false on failure
+ */
+ function handle($notice)
+ {
+ // XXX: do we need to change this for remote users?
+
+ $notice->saveTags();
+
+ $groups = $notice->saveGroups();
+
+ $recipients = $notice->saveReplies();
+
+ $notice->addToInboxes($groups, $recipients);
+
+ $notice->saveUrls();
+
+ Event::handle('EndNoticeSave', array($notice));
+
+ // Enqueue for other handlers
+
+ common_enqueue_notice($notice);
+
+ return true;
+ }
+}
+
diff --git a/lib/iomaster.php b/lib/iomaster.php
index 004e92b3e..94abdeefc 100644
--- a/lib/iomaster.php
+++ b/lib/iomaster.php
@@ -88,7 +88,7 @@ abstract class IoMaster
$sn = new Status_network();
$sn->find();
while ($sn->fetch()) {
- $hosts[] = $sn->hostname;
+ $hosts[] = $sn->getServerName();
}
return $hosts;
}
@@ -102,7 +102,7 @@ abstract class IoMaster
*/
protected function instantiate($class)
{
- if (isset($this->singletons[$class])) {
+ if (is_string($class) && isset($this->singletons[$class])) {
// Already instantiated a multi-site-capable handler.
// Just let it know it should listen to this site too!
$this->singletons[$class]->addSite(common_config('site', 'server'));
@@ -129,7 +129,11 @@ abstract class IoMaster
protected function getManager($class)
{
- return call_user_func(array($class, 'get'));
+ if(is_object($class)){
+ return $class;
+ } else {
+ return call_user_func(array($class, 'get'));
+ }
}
/**
@@ -347,7 +351,7 @@ abstract class IoMaster
* for per-queue and per-site records.
*
* @param string $key counter name
- * @param array $owners list of owner keys like 'queue:jabber' or 'site:stat01'
+ * @param array $owners list of owner keys like 'queue:xmpp' or 'site:stat01'
*/
public function stats($key, $owners=array())
{
diff --git a/lib/mailhandler.php b/lib/mailhandler.php
index 85be89f18..890f6d5b4 100644
--- a/lib/mailhandler.php
+++ b/lib/mailhandler.php
@@ -160,7 +160,7 @@ class MailHandler
foreach($mediafiles as $mf){
$mf->attachToNotice($notice);
}
- common_broadcast_notice($notice);
+
$this->log(LOG_INFO,
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
return true;
diff --git a/lib/oauthstore.php b/lib/oauthstore.php
index df63cc151..b30fb49d5 100644
--- a/lib/oauthstore.php
+++ b/lib/oauthstore.php
@@ -362,7 +362,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
array('is_local' => Notice::REMOTE_OMB,
'uri' => $omb_notice->getIdentifierURI()));
- common_broadcast_notice($notice, true);
+
}
/**
diff --git a/lib/queuemanager.php b/lib/queuemanager.php
index 8921b02cc..61e28085a 100644
--- a/lib/queuemanager.php
+++ b/lib/queuemanager.php
@@ -170,7 +170,9 @@ abstract class QueueManager extends IoManager
{
if (isset($this->handlers[$queue])) {
$class = $this->handlers[$queue];
- if (class_exists($class)) {
+ if(is_object($class)) {
+ return $class;
+ } else if (class_exists($class)) {
return new $class();
} else {
common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
@@ -206,6 +208,7 @@ abstract class QueueManager extends IoManager
$this->connect('plugin', 'PluginQueueHandler');
$this->connect('omb', 'OmbQueueHandler');
$this->connect('ping', 'PingQueueHandler');
+ $this->connect('distrib', 'DistribQueueHandler');
if (common_config('sms', 'enabled')) {
$this->connect('sms', 'SmsQueueHandler');
}
@@ -213,7 +216,7 @@ abstract class QueueManager extends IoManager
// XMPP output handlers...
$this->connect('jabber', 'JabberQueueHandler');
$this->connect('public', 'PublicQueueHandler');
-
+
// @fixme this should get an actual queue
//$this->connect('confirm', 'XmppConfirmHandler');
@@ -231,7 +234,7 @@ abstract class QueueManager extends IoManager
* Only registered transports will be reliably picked up!
*
* @param string $transport
- * @param string $class
+ * @param string $class class name or object instance
* @param string $group
*/
public function connect($transport, $class, $group='queuedaemon')
diff --git a/lib/stompqueuemanager.php b/lib/stompqueuemanager.php
index 4bbdeedc2..8f0091a13 100644
--- a/lib/stompqueuemanager.php
+++ b/lib/stompqueuemanager.php
@@ -294,7 +294,26 @@ class StompQueueManager extends QueueManager
StatusNet::init($site);
}
- $item = $this->decode($frame->body);
+ if (is_numeric($frame->body)) {
+ $id = intval($frame->body);
+ $info = "notice $id posted at {$frame->headers['created']} in queue $queue";
+
+ $notice = Notice::staticGet('id', $id);
+ if (empty($notice)) {
+ $this->_log(LOG_WARNING, "Skipping missing $info");
+ $this->ack($frame);
+ $this->commit();
+ $this->begin();
+ $this->stats('badnotice', $queue);
+ return false;
+ }
+
+ $item = $notice;
+ } else {
+ // @fixme should we serialize, or json, or what here?
+ $info = "string posted at {$frame->headers['created']} in queue $queue";
+ $item = $frame->body;
+ }
$handler = $this->getHandler($queue);
if (!$handler) {
diff --git a/lib/util.php b/lib/util.php
index 01b159ac1..6c9f6316a 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -980,7 +980,7 @@ function common_redirect($url, $code=307)
function common_broadcast_notice($notice, $remote=false)
{
- return common_enqueue_notice($notice);
+ // DO NOTHING!
}
// Stick the notice on the queue
diff --git a/lib/xmppmanager.php b/lib/xmppmanager.php
index 299175dd7..985e7c32e 100644
--- a/lib/xmppmanager.php
+++ b/lib/xmppmanager.php
@@ -101,7 +101,7 @@ class XmppManager extends IoManager
$this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
$this->conn->setReconnectTimeout(600);
- jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', -1);
+ jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', 100);
return !is_null($this->conn);
}
@@ -233,7 +233,7 @@ class XmppManager extends IoManager
common_log(LOG_NOTICE, 'XMPP reconnected');
$this->conn->processUntil('session_start');
- $this->conn->presence(null, 'available', null, 'available', -1);
+ $this->conn->presence(null, 'available', null, 'available', 100);
}