]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/classes/FeedSub.php
HubSub now remembers recent failures and counts them
[quix0rs-gnu-social.git] / plugins / OStatus / classes / FeedSub.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009-2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * @package OStatusPlugin
24  * @maintainer Brion Vibber <brion@status.net>
25  */
26
27 /*
28 WebSub (previously PubSubHubbub/PuSH) subscription flow:
29
30     $profile->subscribe()
31         sends a sub request to the hub...
32
33     main/push/callback
34         hub sends confirmation back to us via GET
35         We verify the request, then echo back the challenge.
36         On our end, we save the time we subscribed and the lease expiration
37
38     main/push/callback
39         hub sends us updates via POST
40
41 */
42
43 /**
44  * FeedSub handles low-level WebSub (PubSubHubbub/PuSH) subscriptions.
45  * Higher-level behavior building OStatus stuff on top is handled
46  * under Ostatus_profile.
47  */
48 class FeedSub extends Managed_DataObject
49 {
50     public $__table = 'feedsub';
51
52     public $id;
53     public $uri;    // varchar(191)   not 255 because utf8mb4 takes more space
54
55     // WebSub subscription data
56     public $huburi;
57     public $secret;
58     public $sub_state; // subscribe, active, unsubscribe, inactive, nohub
59     public $sub_start;
60     public $sub_end;
61     public $last_update;
62
63     public $created;
64     public $modified;
65
66     public static function schemaDef()
67     {
68         return array(
69             'fields' => array(
70                 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'FeedSub local unique id'),
71                 'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'FeedSub uri'),
72                 'huburi' => array('type' => 'text', 'description' => 'FeedSub hub-uri'),
73                 'secret' => array('type' => 'text', 'description' => 'FeedSub stored secret'),
74                 'sub_state' => array('type' => 'enum("subscribe","active","unsubscribe","inactive","nohub")', 'not null' => true, 'description' => 'subscription state'),
75                 'sub_start' => array('type' => 'datetime', 'description' => 'subscription start'),
76                 'sub_end' => array('type' => 'datetime', 'description' => 'subscription end'),
77                 'last_update' => array('type' => 'datetime', 'description' => 'when this record was last updated'),
78                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
79                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
80             ),
81             'primary key' => array('id'),
82             'unique keys' => array(
83                 'feedsub_uri_key' => array('uri'),
84             ),
85         );
86     }
87
88     /**
89      * Get the feed uri (http/https)
90      */
91     public function getUri()
92     {
93         if (empty($this->uri)) {
94             throw new NoUriException($this);
95         }
96         return $this->uri;
97     }
98
99     function getLeaseRemaining()
100     {
101         if (empty($this->sub_end)) {
102             return null;
103         }
104         return strtotime($this->sub_end) - time();
105     }
106
107     /**
108      * Do we have a hub? Then we are a WebSub feed.
109      * WebSub standard: https://www.w3.org/TR/websub/
110      * old: https://en.wikipedia.org/wiki/PubSubHubbub
111      *
112      * If huburi is empty, then doublecheck that we are not using
113      * a fallback hub. If there is a fallback hub, it is only if the
114      * sub_state is "nohub" that we assume it's not a WebSub feed.
115      */
116     public function isWebSub()
117     {
118         if (empty($this->huburi)
119                 && (!common_config('feedsub', 'fallback_hub')
120                     || $this->sub_state === 'nohub')) {
121                 // Here we have no huburi set. Also, either there is no 
122                 // fallback hub configured or sub_state is "nohub".
123             return false;
124         }
125         return true;
126     }
127
128     /**
129      * Fetch the StatusNet-side profile for this feed
130      * @return Profile
131      */
132     public function localProfile()
133     {
134         if ($this->profile_id) {
135             return Profile::getKV('id', $this->profile_id);
136         }
137         return null;
138     }
139
140     /**
141      * Fetch the StatusNet-side profile for this feed
142      * @return Profile
143      */
144     public function localGroup()
145     {
146         if ($this->group_id) {
147             return User_group::getKV('id', $this->group_id);
148         }
149         return null;
150     }
151
152     /**
153      * @param string $feeduri
154      * @return FeedSub
155      * @throws FeedSubException if feed is invalid or lacks WebSub setup
156      */
157     public static function ensureFeed($feeduri)
158     {
159         $feedsub = self::getKV('uri', $feeduri);
160         if ($feedsub instanceof FeedSub) {
161             if (!empty($feedsub->huburi)) {
162                 // If there is already a huburi we don't
163                 // rediscover it on ensureFeed, call
164                 // ensureHub to do that (compare ->modified
165                 // to see if it might be time to do it).
166                 return $feedsub;
167             }
168             if ($feedsub->sub_state !== 'inactive') {
169                 throw new ServerException('Can only ensure WebSub hub for inactive (unsubscribed) feeds.');
170             }
171             // If huburi is empty we continue with ensureHub
172         } else {
173             // If we don't have that local feed URI
174             // stored then we create a new DB object.
175             $feedsub = new FeedSub();
176             $feedsub->uri = $feeduri;
177             $feedsub->sub_state = 'inactive';
178         }
179
180         try {
181             // discover the hub uri
182             $feedsub->ensureHub();
183
184         } catch (FeedSubNoHubException $e) {
185             // Only throw this exception if we can't handle huburi-less feeds
186             // (i.e. we have a fallback hub or we can do feed polling (nohub)
187             if (!common_config('feedsub', 'fallback_hub') && !common_config('feedsub', 'nohub')) {
188                 throw $e;
189             }
190         }
191
192         if (empty($feedsub->id)) {
193             // if $feedsub doesn't have an id we'll insert it into the db here
194             $feedsub->created = common_sql_now();
195             $feedsub->modified = common_sql_now();
196             $result = $feedsub->insert();
197             if ($result === false) {
198                 throw new FeedDBException($feedsub);
199             }
200         }
201
202         return $feedsub;
203     }
204
205     /**
206      * ensureHub will only do $this->update if !empty($this->id)
207      * because otherwise the object has not been created yet.
208      *
209      * @param   bool    $rediscovered   Whether the hub info is rediscovered (to avoid endless loop nesting)
210      *
211      * @return  null    if actively avoiding the database
212      *          int     number of rows updated in the database (0 means untouched)
213      *
214      * @throws  ServerException if something went wrong when updating the database
215      *          FeedSubNoHubException   if no hub URL was discovered
216      */
217     public function ensureHub($rediscovered=false)
218     {
219         common_debug('Now inside ensureHub again, $rediscovered=='._ve($rediscovered));
220         if ($this->sub_state !== 'inactive') {
221             common_log(LOG_INFO, sprintf(__METHOD__ . ': Running hub discovery a possibly active feed in %s state for URI %s', _ve($this->sub_state), _ve($this->uri)));
222         }
223
224         $discover = new FeedDiscovery();
225         $discover->discoverFromFeedURL($this->uri);
226
227         $huburi = $discover->getHubLink();
228         if (empty($huburi)) {
229             // Will be caught and treated with if statements in regards to
230             // fallback hub and feed polling (nohub) configuration.
231             throw new FeedSubNoHubException();
232         }
233
234         // if we've already got a DB object stored, we want to UPDATE, not INSERT
235         $orig = !empty($this->id) ? clone($this) : null;
236
237         $old_huburi = $this->huburi;    // most likely null if we're INSERTing
238         $this->huburi = $huburi;
239
240         if (!empty($this->id)) {
241             common_debug(sprintf(__METHOD__ . ': Feed uri==%s huburi before=%s after=%s (identical==%s)', _ve($this->uri), _ve($old_huburi), _ve($this->huburi), _ve($old_huburi===$this->huburi)));
242             $result = $this->update($orig);
243             if ($result === false) {
244                 // TODO: Get a DB exception class going...
245                 common_debug('Database update failed for FeedSub id=='._ve($this->id).' with new huburi: '._ve($this->huburi));
246                 throw new ServerException('Database update failed for FeedSub.');
247             }
248             if (!$rediscovered) {
249                 $this->renew();
250             }
251             return $result;
252         }
253
254         return null;    // we haven't done anything with the database
255     }
256
257     /**
258      * Send a subscription request to the hub for this feed.
259      * The hub will later send us a confirmation POST to /main/push/callback.
260      *
261      * @return void
262      * @throws ServerException if feed state is not valid
263      */
264     public function subscribe($rediscovered=false)
265     {
266         if ($this->sub_state && $this->sub_state != 'inactive') {
267             common_log(LOG_WARNING, sprintf('Attempting to (re)start WebSub subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
268         }
269
270         if (!Event::handle('FeedSubscribe', array($this))) {
271             // A plugin handled it
272             return;
273         }
274
275         if (empty($this->huburi)) {
276             if (common_config('feedsub', 'fallback_hub')) {
277                 // No native hub on this feed?
278                 // Use our fallback hub, which handles polling on our behalf.
279             } else if (common_config('feedsub', 'nohub')) {
280                 // For this to actually work, we'll need some polling mechanism.
281                 // The FeedPoller plugin should take care of it.
282                 return;
283             } else {
284                 // TRANS: Server exception.
285                 throw new ServerException(_m('Attempting to start WebSub subscription for feed with no hub.'));
286             }
287         }
288
289         $this->doSubscribe('subscribe', $rediscovered);
290     }
291
292     /**
293      * Send a WebSub unsubscription request to the hub for this feed.
294      * The hub will later send us a confirmation POST to /main/push/callback.
295      * Warning: this will cancel the subscription even if someone else in
296      * the system is using it. Most callers will want garbageCollect() instead,
297      * which confirms there's no uses left.
298      *
299      * @throws ServerException if feed state is not valid
300      */
301     public function unsubscribe() {
302         if ($this->sub_state != 'active') {
303             common_log(LOG_WARNING, sprintf('Attempting to (re)end WebSub subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
304         }
305
306         if (!Event::handle('FeedUnsubscribe', array($this))) {
307             // A plugin handled it
308             return;
309         }
310
311         if (empty($this->huburi) && !common_config('feedsub', 'fallback_hub')) {
312             /**
313              * If the huburi is empty and we don't have a fallback hub,
314              * there is nowhere we can send an unsubscribe to.
315              *
316              * A plugin should handle the FeedSub above and set the proper state
317              * if there is no hub. (instead of 'nohub' it should be 'inactive' if
318              * the instance has enabled feed polling for feeds that don't publish
319              * WebSub/PuSH hubs. FeedPoller is a plugin which enables polling.
320              *
321              * Secondly, if we don't have the setting "nohub" enabled (i.e.)
322              * we're ready to poll ourselves, there is something odd with the
323              * database, such as a polling plugin that has been disabled.
324              */
325
326             if (!common_config('feedsub', 'nohub')) {
327                 // TRANS: Server exception.
328                 throw new ServerException(_m('Attempting to end WebSub subscription for feed with no hub.'));
329             }
330
331             return;
332         }
333
334         $this->doSubscribe('unsubscribe');
335     }
336
337     /**
338      * Check if there are any active local uses of this feed, and if not then
339      * make sure it's inactive, unsubscribing if necessary.
340      *
341      * @return boolean true if the subscription is now inactive, false if still active.
342      * @throws NoProfileException in FeedSubSubscriberCount for missing Profile entries
343      * @throws Exception if something goes wrong in unsubscribe() method
344      */
345     public function garbageCollect()
346     {
347         if ($this->sub_state == '' || $this->sub_state == 'inactive') {
348             // No active WebSub subscription, we can just leave it be.
349             return true;
350         }
351
352         // WebSub subscription is either active or in an indeterminate state.
353         // Check if we're out of subscribers, and if so send an unsubscribe.
354         $count = 0;
355         Event::handle('FeedSubSubscriberCount', array($this, &$count));
356
357         if ($count > 0) {
358             common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->getUri());
359             return false;
360         }
361
362         common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->getUri());
363         // Unsubscribe throws various Exceptions on failure
364         $this->unsubscribe();
365
366         return true;
367     }
368
369     static public function renewalCheck()
370     {
371         $fs = new FeedSub();
372         // the "" empty string check is because we historically haven't saved unsubscribed feeds as NULL
373         $fs->whereAdd('sub_end IS NOT NULL AND sub_end!="" AND sub_end < NOW() + INTERVAL 1 day');
374         if (!$fs->find()) { // find can be both false and 0, depending on why nothing was found
375             throw new NoResultException($fs);
376         }
377         return $fs;
378     }
379
380     public function renew($rediscovered=false)
381     {
382         common_debug('FeedSub is being renewed for uri=='._ve($this->uri).' on huburi=='._ve($this->huburi));
383         $this->subscribe($rediscovered);
384     }
385
386     /**
387      * Setting to subscribe means it is _waiting_ to become active. This
388      * cannot be done in a transaction because there is a chance that the
389      * remote script we're calling (as in the case of PuSHpress) performs
390      * the lookup _while_ we're POSTing data, which means the transaction
391      * never completes (PushcallbackAction gets an 'inactive' state).
392      *
393      * @return boolean true when everything is ok (throws Exception on fail)
394      * @throws Exception on failure, can be HTTPClient's or our own.
395      */
396     protected function doSubscribe($mode, $rediscovered=false)
397     {
398         $msg = null;    // carries descriptive error message to enduser (no remote data strings!)
399
400         $orig = clone($this);
401         if ($mode == 'subscribe') {
402             $this->secret = common_random_hexstr(32);
403         }
404         $this->sub_state = $mode;
405         $this->update($orig);
406         unset($orig);
407
408         try {
409             $callback = common_local_url('pushcallback', array('feed' => $this->id));
410             $headers = array('Content-Type: application/x-www-form-urlencoded');
411             $post = array('hub.mode' => $mode,
412                           'hub.callback' => $callback,
413                           'hub.verify' => 'async',  // TODO: deprecated, remove when noone uses PuSH <0.4 (only 'async' method used there)
414                           'hub.verify_token' => 'Deprecated-since-PuSH-0.4', // TODO: rm!
415
416                           'hub.lease_seconds' => 2592000,   // 3600*24*30, request approximately month long lease (may be changed by hub)
417                           'hub.secret' => $this->secret,
418                           'hub.topic' => $this->getUri());
419             $client = new HTTPClient();
420             if ($this->huburi) {
421                 $hub = $this->huburi;
422             } else {
423                 if (common_config('feedsub', 'fallback_hub')) {
424                     $hub = common_config('feedsub', 'fallback_hub');
425                     if (common_config('feedsub', 'hub_user')) {
426                         $u = common_config('feedsub', 'hub_user');
427                         $p = common_config('feedsub', 'hub_pass');
428                         $client->setAuth($u, $p);
429                     }
430                 } else {
431                     throw new FeedSubException('Server could not find a usable WebSub hub.');
432                 }
433             }
434             $response = $client->post($hub, $headers, $post);
435             $status = $response->getStatus();
436             // WebSub specificed response status code
437             if ($status == 202  || $status == 204) {
438                 common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
439                 return;
440             } else if ($status >= 200 && $status < 300) {
441                 common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP $status: " . $response->getBody());
442                 $msg = sprintf(_m("Unexpected HTTP status: %d"), $status);
443             } else if ($status == 422 && !$rediscovered) {
444                 // Error code regarding something wrong in the data (it seems
445                 // that we're talking to a WebSub hub at least, so let's check
446                 // our own data to be sure we're not mistaken somehow, which
447                 // means rediscovering hub data (the boolean parameter means
448                 // we avoid running this part over and over and over and over):
449
450                 common_debug('Running ensureHub again due to 422 status, $rediscovered=='._ve($rediscovered));
451                 $discoveryResult = $this->ensureHub(true);
452                 common_debug('ensureHub is now done and its result was: '._ve($discoveryResult));
453             } else {
454                 common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP $status: " . $response->getBody());
455             }
456         } catch (Exception $e) {
457             common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub {$this->huburi} subscribing to {$this->getUri()}");
458
459             // Reset the subscription state.
460             $orig = clone($this);
461             $this->sub_state = 'inactive';
462             $this->update($orig);
463
464             // Throw the Exception again.
465             throw $e;
466         }
467         throw new ServerException("{$mode} request failed" . (!is_null($msg) ? " ($msg)" : '.'));
468     }
469
470     /**
471      * Save WebSub subscription confirmation.
472      * Sets approximate lease start and end times and finalizes state.
473      *
474      * @param int $lease_seconds provided hub.lease_seconds parameter, if given
475      */
476     public function confirmSubscribe($lease_seconds)
477     {
478         $original = clone($this);
479
480         $this->sub_state = 'active';
481         $this->sub_start = common_sql_date(time());
482         if ($lease_seconds > 0) {
483             $this->sub_end = common_sql_date(time() + $lease_seconds);
484         } else {
485             $this->sub_end = null;  // Backwards compatibility to StatusNet (PuSH <0.4 supported permanent subs)
486         }
487         $this->modified = common_sql_now();
488
489         common_debug(__METHOD__ . ': Updating sub state and metadata for '.$this->getUri());
490         return $this->update($original);
491     }
492
493     /**
494      * Save WebSub unsubscription confirmation.
495      * Wipes active WebSub sub info and resets state.
496      */
497     public function confirmUnsubscribe()
498     {
499         $original = clone($this);
500
501         // @fixme these should all be null, but DB_DataObject doesn't save null values...?????
502         $this->secret = '';
503         $this->sub_state = '';
504         $this->sub_start = '';
505         $this->sub_end = '';
506         $this->modified = common_sql_now();
507
508         return $this->update($original);
509     }
510
511     /**
512      * Accept updates from a WebSub feed. If validated, this object and the
513      * feed (as a DOMDocument) will be passed to the StartFeedSubHandleFeed
514      * and EndFeedSubHandleFeed events for processing.
515      *
516      * Not guaranteed to be running in an immediate POST context; may be run
517      * from a queue handler.
518      *
519      * Side effects: the feedsub record's lastupdate field will be updated
520      * to the current time (not published time) if we got a legit update.
521      *
522      * @param string $post source of Atom or RSS feed
523      * @param string $hmac X-Hub-Signature header, if present
524      */
525     public function receive($post, $hmac)
526     {
527         common_log(LOG_INFO, sprintf(__METHOD__.': packet for %s with HMAC %s', _ve($this->getUri()), _ve($hmac)));
528
529         if (!in_array($this->sub_state, array('active', 'nohub'))) {
530             common_log(LOG_ERR, sprintf(__METHOD__.': ignoring WebSub for inactive feed %s (in state %s)', _ve($this->getUri()), _ve($this->sub_state)));
531             return;
532         }
533
534         if ($post === '') {
535             common_log(LOG_ERR, __METHOD__ . ": ignoring empty post");
536             return;
537         }
538
539         try {
540             if (!$this->validatePushSig($post, $hmac)) {
541                 // Per spec we silently drop input with a bad sig,
542                 // while reporting receipt to the server.
543                 return;
544             }
545
546             $this->receiveFeed($post);
547
548         } catch (FeedSubBadPushSignatureException $e) {
549             // We got a signature, so something could be wrong. Let's check to see if
550             // maybe upstream has switched to another hub. Let's fetch feed and then
551             // compare rel="hub" with $this->huburi, which is done in $this->ensureHub()
552
553             $this->ensureHub(true);
554         }
555     }
556
557     /**
558      * All our feed URIs should be URLs.
559      */
560     public function importFeed()
561     {
562         $feed_url = $this->getUri();
563
564         // Fetch the URL
565         try {
566             common_log(LOG_INFO, sprintf('Importing feed backlog from %s', $feed_url));
567             $feed_xml = HTTPClient::quickGet($feed_url, 'application/atom+xml');
568         } catch (Exception $e) {
569             throw new FeedSubException("Could not fetch feed from URL '%s': %s (%d).\n", $feed_url, $e->getMessage(), $e->getCode());
570         }
571
572         return $this->receiveFeed($feed_xml);
573     }
574
575     protected function receiveFeed($feed_xml)
576     {
577         // We're passed the XML for the Atom feed as $feed_xml,
578         // so read it into a DOMDocument and process.
579         $feed = new DOMDocument();
580         if (!$feed->loadXML($feed_xml)) {
581             // @fixme might help to include the err message
582             common_log(LOG_ERR, __METHOD__ . ": ignoring invalid XML");
583             return;
584         }
585
586         $orig = clone($this);
587         $this->last_update = common_sql_now();
588         $this->update($orig);
589
590         Event::handle('StartFeedSubReceive', array($this, $feed));
591         Event::handle('EndFeedSubReceive', array($this, $feed));
592     }
593
594     /**
595      * Validate the given Atom chunk and HMAC signature against our
596      * shared secret that was set up at subscription time.
597      *
598      * If we don't have a shared secret, there should be no signature.
599      * If we do, our calculated HMAC should match theirs.
600      *
601      * @param string $post raw XML source as POSTed to us
602      * @param string $hmac X-Hub-Signature HTTP header value, or empty
603      * @return boolean true for a match
604      */
605     protected function validatePushSig($post, $hmac)
606     {
607         if ($this->secret) {
608             // {3,16} because shortest hash algorithm name is 3 characters (md2,md4,md5) and longest
609             // is currently 11 characters, but we'll leave some margin in the end...
610             if (preg_match('/^([0-9a-zA-Z\-\,]{3,16})=([0-9a-fA-F]+)$/', $hmac, $matches)) {
611                 $hash_algo  = strtolower($matches[1]);
612                 $their_hmac = strtolower($matches[2]);
613                 common_debug(sprintf(__METHOD__ . ': WebSub push from feed %s uses HMAC algorithm %s with value: %s', _ve($this->getUri()), _ve($hash_algo), _ve($their_hmac)));
614
615                 if (!in_array($hash_algo, hash_algos())) {
616                     // We can't handle this at all, PHP doesn't recognize the algorithm name ('md5', 'sha1', 'sha256' etc: https://secure.php.net/manual/en/function.hash-algos.php)
617                     common_log(LOG_ERR, sprintf(__METHOD__.': HMAC algorithm %s unsupported, not found in PHP hash_algos()', _ve($hash_algo)));
618                     return false;
619                 } elseif (!is_null(common_config('security', 'hash_algos')) && !in_array($hash_algo, common_config('security', 'hash_algos'))) {
620                     // We _won't_ handle this because there is a list of accepted hash algorithms and this one is not in it.
621                     common_log(LOG_ERR, sprintf(__METHOD__.': Whitelist for HMAC algorithms exist, but %s is not included.', _ve($hash_algo)));
622                     return false;
623                 }
624
625                 $our_hmac = hash_hmac($hash_algo, $post, $this->secret);
626                 if ($their_hmac !== $our_hmac) {
627                     common_log(LOG_ERR, sprintf(__METHOD__.': ignoring WebSub push with bad HMAC hash: got %s, expected %s for feed %s from hub %s', _ve($their_hmac), _ve($our_hmac), _ve($this->getUri()), _ve($this->huburi)));
628                     throw new FeedSubBadPushSignatureException('Incoming WebSub push signature did not match expected HMAC hash.');
629                 }
630                 return true;
631
632             } else {
633                 common_log(LOG_ERR, sprintf(__METHOD__.': ignoring WebSub push with bogus HMAC==', _ve($hmac)));
634             }
635         } else {
636             if (empty($hmac)) {
637                 return true;
638             } else {
639                 common_log(LOG_ERR, sprintf(__METHOD__.': ignoring WebSub push with unexpected HMAC==%s', _ve($hmac)));
640             }
641         }
642         return false;
643     }
644
645     public function delete($useWhere=false)
646     {
647         try {
648             $oprofile = Ostatus_profile::getKV('feeduri', $this->getUri());
649             if ($oprofile instanceof Ostatus_profile) {
650                 // Check if there's a profile. If not, handle the NoProfileException below
651                 $profile = $oprofile->localProfile();
652             }
653         } catch (NoProfileException $e) {
654             // If the Ostatus_profile has no local Profile bound to it, let's clean it out at the same time
655             $oprofile->delete();
656         } catch (NoUriException $e) {
657             // FeedSub->getUri() can throw a NoUriException, let's just go ahead and delete it
658         }
659         return parent::delete($useWhere);
660     }
661 }