3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009, StatusNet, Inc.
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.
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.
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/>.
21 * @package FeedSubPlugin
22 * @maintainer Brion Vibber <brion@status.net>
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
28 class PushCallbackAction extends Action
33 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
41 * Handler for POST content updates from the hub
45 $feedid = $this->arg('feed');
46 common_log(LOG_INFO, "POST for feed id $feedid");
48 throw new ServerException('Empty or invalid feed id', 400);
51 $feedsub = FeedSub::staticGet('id', $feedid);
53 throw new ServerException('Unknown PuSH feed id ' . $feedid, 400);
57 if (isset($_SERVER['HTTP_X_HUB_SIGNATURE'])) {
58 $hmac = $_SERVER['HTTP_X_HUB_SIGNATURE'];
61 $post = file_get_contents('php://input');
63 // @fixme Queue this to a background process; we should return
64 // as quickly as possible from a distribution POST.
65 $feedsub->receive($post, $hmac);
69 * Handler for GET verification requests from the hub
73 $mode = $this->arg('hub_mode');
74 $topic = $this->arg('hub_topic');
75 $challenge = $this->arg('hub_challenge');
76 $lease_seconds = $this->arg('hub_lease_seconds');
77 $verify_token = $this->arg('hub_verify_token');
79 if ($mode != 'subscribe' && $mode != 'unsubscribe') {
80 common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with mode \"$mode\"");
81 throw new ServerException("Bogus hub callback: bad mode", 404);
84 $feedsub = FeedSub::staticGet('uri', $topic);
86 common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic");
87 throw new ServerException("Bogus hub callback: unknown feed", 404);
90 if ($feedsub->verify_token !== $verify_token) {
91 common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
92 throw new ServerException("Bogus hub callback: bad token", 404);
95 if ($mode != $feedsub->sub_state) {
96 common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad mode \"$mode\" for feed $topic in state \"{$feedsub->sub_state}\"");
97 throw new ServerException("Bogus hub callback: mode doesn't match subscription state.", 404);
101 if ($mode == 'subscribe') {
102 common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
103 $feedsub->confirmSubscribe($lease_seconds);
105 common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic");
106 $feedsub->confirmUnsubscribe();