X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Factions%2Fpushhub.php;h=5d0b9fbf903f64686388e4eeefc494bdddccc511;hb=1e89540c3f52f95e9224d781c01b2c927d3c3f09;hp=1818a079975f5dd2a00043ec005550a626148973;hpb=f8b49e69d02806110cbc780fce4671fbe3357438;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/actions/pushhub.php b/plugins/OStatus/actions/pushhub.php index 1818a07997..5d0b9fbf90 100644 --- a/plugins/OStatus/actions/pushhub.php +++ b/plugins/OStatus/actions/pushhub.php @@ -49,7 +49,7 @@ class PushHubAction extends Action protected function prepare(array $args=array()) { - StatusNet::setApi(true); // reduce exception reports to aid in debugging + GNUsocial::setApi(true); // reduce exception reports to aid in debugging return parent::prepare($args); } @@ -89,20 +89,12 @@ class PushHubAction extends Action throw new ClientException(sprintf(_m('Unsupported hub.topic %s this hub only serves local user and group Atom feeds.'),$topic)); } - $verify = $this->arg('hub.verify'); // @fixme may be multiple - if ($verify != 'sync' && $verify != 'async') { - // TRANS: Client exception. %s is sync or async. - throw new ClientException(sprintf(_m('Invalid hub.verify "%s". It must be sync or async.'),$verify)); - } - $lease = $this->arg('hub.lease_seconds', null); if ($mode == 'subscribe' && $lease != '' && !preg_match('/^\d+$/', $lease)) { // TRANS: Client exception. %s is the invalid lease value. throw new ClientException(sprintf(_m('Invalid hub.lease "%s". It must be empty or positive integer.'),$lease)); } - $token = $this->arg('hub.verify_token', null); - $secret = $this->arg('hub.secret', null); if ($secret != '' && strlen($secret) >= 200) { // TRANS: Client exception. %s is the invalid hub secret. @@ -110,7 +102,7 @@ class PushHubAction extends Action } $sub = HubSub::getByHashkey($topic, $callback); - if (!$sub) { + if (!$sub instanceof HubSub) { // Creating a new one! $sub = new HubSub(); $sub->topic = $topic; @@ -125,16 +117,14 @@ class PushHubAction extends Action } } - if (!common_config('queue', 'enabled')) { - // Won't be able to background it. - $verify = 'sync'; - } - if ($verify == 'async') { - $sub->scheduleVerify($mode, $token); - header('HTTP/1.1 202 Accepted'); - } else { + $verify = $this->arg('hub.verify'); // TODO: deprecated + $token = $this->arg('hub.verify_token', null); // TODO: deprecated + if ($verify == 'sync') { // pre-0.4 PuSH $sub->verify($mode, $token); header('HTTP/1.1 204 No Content'); + } else { // If $verify is not "sync", we might be using PuSH 0.4 + $sub->scheduleVerify($mode, $token); // If we were certain it's PuSH 0.4, token could be removed + header('HTTP/1.1 202 Accepted'); } } @@ -143,54 +133,61 @@ class PushHubAction extends Action * user or group Atom feeds. * * @param string $feed URL - * @return boolean true if it matches + * @return boolean true if it matches, false if not a recognized local feed + * @throws exception if local entity does not exist */ - function recognizedFeed($feed) + protected function recognizedFeed($feed) { $matches = array(); + // Simple mapping to local ID for user or group if (preg_match('!/(\d+)\.atom$!', $feed, $matches)) { $id = $matches[1]; $params = array('id' => $id, 'format' => 'atom'); - $userFeed = common_local_url('ApiTimelineUser', $params); - $groupFeed = common_local_url('ApiTimelineGroup', $params); - if ($feed == $userFeed) { + // Double-check against locally generated URLs + switch ($feed) { + case common_local_url('ApiTimelineUser', $params): $user = User::getKV('id', $id); - if (!$user) { + if (!$user instanceof User) { // TRANS: Client exception. %s is a feed URL. - throw new ClientException(sprintt(_m('Invalid hub.topic "%s". User does not exist.'),$feed)); - } else { - return true; + throw new ClientException(sprintf(_m('Invalid hub.topic "%s". User does not exist.'),$feed)); } - } - if ($feed == $groupFeed) { - $user = User_group::getKV('id', $id); - if (!$user) { + return true; + + case common_local_url('ApiTimelineGroup', $params): + $group = Local_group::getKV('group_id', $id); + if (!$group instanceof Local_group) { // TRANS: Client exception. %s is a feed URL. - throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Group does not exist.'),$feed)); - } else { - return true; + throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Local_group does not exist.'),$feed)); } + return true; } - } else if (preg_match('!/(\d+)/lists/(\d+)/statuses\.atom$!', $feed, $matches)) { + common_debug("Feed was not recognized by any local User or Group Atom feed URLs: {$feed}"); + return false; + } + + // Profile lists are unique per user, so we need both IDs + if (preg_match('!/(\d+)/lists/(\d+)/statuses\.atom$!', $feed, $matches)) { $user = $matches[1]; $id = $matches[2]; $params = array('user' => $user, 'id' => $id, 'format' => 'atom'); - $listFeed = common_local_url('ApiTimelineList', $params); - if ($feed == $listFeed) { + // Double-check against locally generated URLs + switch ($feed) { + case common_local_url('ApiTimelineList', $params): $list = Profile_list::getKV('id', $id); $user = User::getKV('id', $user); - if (!$list || !$user || $list->tagger != $user->id) { + if (!$list instanceof Profile_list || !$user instanceof User || $list->tagger != $user->id) { // TRANS: Client exception. %s is a feed URL. throw new ClientException(sprintf(_m('Invalid hub.topic %s; list does not exist.'),$feed)); - } else { - return true; } + return true; } - common_log(LOG_DEBUG, "Not a user, group or people tag feed? $feed $userFeed $groupFeed $listFeed"); + common_debug("Feed was not recognized by any local Profile_list Atom feed URL: {$feed}"); + return false; } - common_log(LOG_DEBUG, "LOST $feed"); + + common_debug("Unknown feed URL structure, can't match against local user, group or profile_list: {$feed}"); return false; }