From: Miguel Dantas Date: Wed, 7 Aug 2019 21:47:17 +0000 (+0100) Subject: [CORE][QUEUE] Error checking and type declaration on handling notice queue events X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aaabf82eff9388b5ef474f1c6c7fe9195a46e795;p=quix0rs-gnu-social.git [CORE][QUEUE] Error checking and type declaration on handling notice queue events Patch submitted by XRevan86 --- diff --git a/lib/imqueuehandler.php b/lib/imqueuehandler.php index 2df25ac9f4..b1eeb0ac36 100644 --- a/lib/imqueuehandler.php +++ b/lib/imqueuehandler.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +defined('GNUSOCIAL') || die(); /** * Common superclass for all IM sending queue handlers. @@ -35,8 +35,13 @@ class ImQueueHandler extends QueueHandler * @param Notice $notice * @return boolean success */ - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); + return true; + } + $this->plugin->broadcastNotice($notice); if ($notice->isLocal()) { $this->plugin->publicNotice($notice); diff --git a/lib/pingqueuehandler.php b/lib/pingqueuehandler.php index 4e4d74cb1a..7f5b11ea6a 100644 --- a/lib/pingqueuehandler.php +++ b/lib/pingqueuehandler.php @@ -17,20 +17,25 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Queue handler for pushing new notices to ping servers. */ class PingQueueHandler extends QueueHandler { - function transport() { + function transport() + { return 'ping'; } - function handle($notice) { + function handle($notice): bool + { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); + return true; + } + require_once INSTALLDIR . '/lib/ping.php'; return ping_broadcast_notice($notice); } diff --git a/lib/pluginqueuehandler.php b/lib/pluginqueuehandler.php index dcd07d7208..46b61d6a96 100644 --- a/lib/pluginqueuehandler.php +++ b/lib/pluginqueuehandler.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('GNUSOCIAL')) { exit(1); } +defined('GNUSOCIAL') || die(); /** * Queue handler for letting plugins handle stuff. @@ -40,8 +40,13 @@ class PluginQueueHandler extends QueueHandler return 'plugin'; } - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); + return true; + } + try { Event::handle('HandleQueuedNotice', array(&$notice)); } catch (NoProfileException $unp) { diff --git a/lib/queuehandler.php b/lib/queuehandler.php index 2194dd1618..47161a987c 100644 --- a/lib/queuehandler.php +++ b/lib/queuehandler.php @@ -46,7 +46,7 @@ class QueueHandler * @param mixed $object * @return boolean true on success, false on failure */ - function handle($object) + function handle($object): bool { return true; } diff --git a/lib/smsqueuehandler.php b/lib/smsqueuehandler.php index 6085d2b4ac..1df7011e3c 100644 --- a/lib/smsqueuehandler.php +++ b/lib/smsqueuehandler.php @@ -17,9 +17,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Queue handler for pushing new notices to local subscribers using SMS. @@ -31,8 +29,13 @@ class SmsQueueHandler extends QueueHandler return 'sms'; } - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); + return true; + } + require_once(INSTALLDIR.'/lib/mail.php'); return mail_broadcast_notice_sms($notice); } diff --git a/plugins/OStatus/lib/ostatusqueuehandler.php b/plugins/OStatus/lib/ostatusqueuehandler.php index 3ad6b3b2ab..74db1924fa 100644 --- a/plugins/OStatus/lib/ostatusqueuehandler.php +++ b/plugins/OStatus/lib/ostatusqueuehandler.php @@ -17,9 +17,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Prepare WebSub and Salmon distributions for an outgoing message. @@ -46,9 +44,12 @@ class OStatusQueueHandler extends QueueHandler return 'ostatus'; } - function handle($notice) + function handle($notice): bool { - assert($notice instanceof Notice); + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not distributing"); + return true; + } $this->notice = $notice; $this->user = User::getKV('id', $notice->profile_id); diff --git a/plugins/OStatus/lib/pushinqueuehandler.php b/plugins/OStatus/lib/pushinqueuehandler.php index 4946186cf4..0ffb43b14a 100644 --- a/plugins/OStatus/lib/pushinqueuehandler.php +++ b/plugins/OStatus/lib/pushinqueuehandler.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('GNUSOCIAL')) { exit(1); } +defined('GNUSOCIAL') || die(); /** * Process a feed distribution POST from a WebSub (previously PuSH) hub. @@ -31,9 +31,12 @@ class PushInQueueHandler extends QueueHandler return 'pushin'; } - function handle($data) + function handle($data): bool { - assert(is_array($data)); + if (!is_array($data)) { + common_log(LOG_ERR, "Got bogus data, not processing"); + return true; + } $feedsub_id = $data['feedsub_id']; $post = $data['post']; diff --git a/plugins/RSSCloud/lib/rsscloudqueuehandler.php b/plugins/RSSCloud/lib/rsscloudqueuehandler.php index 8a09977489..63f6559412 100644 --- a/plugins/RSSCloud/lib/rsscloudqueuehandler.php +++ b/plugins/RSSCloud/lib/rsscloudqueuehandler.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +defined('GNUSOCIAL') || die(); class RSSCloudQueueHandler extends QueueHandler { @@ -26,8 +26,13 @@ class RSSCloudQueueHandler extends QueueHandler return 'rsscloud'; } - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not using"); + return true; + } + try { $profile = $notice->getProfile(); } catch (Exception $e) { diff --git a/plugins/SubMirror/lib/mirrorqueuehandler.php b/plugins/SubMirror/lib/mirrorqueuehandler.php index 550986b444..abdc259d8f 100644 --- a/plugins/SubMirror/lib/mirrorqueuehandler.php +++ b/plugins/SubMirror/lib/mirrorqueuehandler.php @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +defined('GNUSOCIAL') || die(); + /** * Check for subscription mirroring options on each newly seen post! * @@ -30,8 +32,13 @@ class MirrorQueueHandler extends QueueHandler return 'mirror'; } - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not mirroring"); + return true; + } + $mirror = new SubMirror(); $mirror->subscribed = $notice->profile_id; if ($mirror->find()) { diff --git a/plugins/TwitterBridge/lib/twitterqueuehandler.php b/plugins/TwitterBridge/lib/twitterqueuehandler.php index bba1b8b2bc..2c6c36906f 100644 --- a/plugins/TwitterBridge/lib/twitterqueuehandler.php +++ b/plugins/TwitterBridge/lib/twitterqueuehandler.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +defined('GNUSOCIAL') || die(); require_once dirname(__DIR__) . '/twitter.php'; @@ -28,8 +28,13 @@ class TwitterQueueHandler extends QueueHandler return 'twitter'; } - function handle($notice) + function handle($notice): bool { + if (!($notice instanceof Notice)) { + common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); + return true; + } + $ok = broadcast_twitter($notice); return $ok || common_config('twitter', 'ignore_errors'); }