pushinqueuehandler.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 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. if (!defined('GNUSOCIAL')) { exit(1); }
  20. /**
  21. * Process a feed distribution POST from a WebSub (previously PuSH) hub.
  22. * @package FeedSub
  23. * @author Brion Vibber <brion@status.net>
  24. */
  25. class PushInQueueHandler extends QueueHandler
  26. {
  27. function transport()
  28. {
  29. return 'pushin';
  30. }
  31. function handle($data)
  32. {
  33. assert(is_array($data));
  34. $feedsub_id = $data['feedsub_id'];
  35. $post = $data['post'];
  36. $hmac = $data['hmac'];
  37. try {
  38. $feedsub = FeedSub::getByID($feedsub_id);
  39. $feedsub->receive($post, $hmac);
  40. } catch(NoResultException $e) {
  41. common_log(LOG_INFO, "Discarding POST to unknown feed subscription id {$feedsub_id}");
  42. } catch(Exception $e) {
  43. if (is_null($feedsub)) {
  44. common_log(LOG_ERR, "Exception "._ve(get_class($e))." during WebSub push input processing where FeedSub->receive returned null!" . _ve($e->getMessage()));
  45. } else {
  46. common_log(LOG_ERR, "Exception "._ve(get_class($e))." during WebSub push input processing for {$feedsub->getUri()}: " . _ve($e->getMessage()));
  47. }
  48. }
  49. return true;
  50. }
  51. }