/** * Process a request for a new or modified PuSH feed subscription. * If asynchronous verification is requested, updates won't be saved immediately. * * HTTP return codes: * 202 Accepted - request saved and awaiting verification * 204 No Content - already subscribed * 400 Bad Request - rejecting this (not specifically spec'd) */ function subunsub($mode) { $callback = $this->argUrl('hub.callback'); $topic = $this->argUrl('hub.topic'); if (!$this->recognizedFeed($topic)) { // TRANS: Client exception. %s is a topic. throw new ClientException(sprintf(_m('Unsupported hub.topic %s this hub only serves local user and group Atom feeds.'), $topic)); } $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)); } $secret = $this->arg('hub.secret', null); if ($secret != '' && strlen($secret) >= 200) { // TRANS: Client exception. %s is the invalid hub secret. throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'), $secret)); } $sub = HubSub::getByHashkey($topic, $callback); if (!$sub instanceof HubSub) { // Creating a new one! $sub = new HubSub(); $sub->topic = $topic; $sub->callback = $callback; } if ($mode == 'subscribe') { if ($secret) { $sub->secret = $secret; } if ($lease) { $sub->setLease(intval($lease)); } } $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'); } }
/** * Process a request for a new or modified PuSH feed subscription. * If asynchronous verification is requested, updates won't be saved immediately. * * HTTP return codes: * 202 Accepted - request saved and awaiting verification * 204 No Content - already subscribed * 400 Bad Request - rejecting this (not specifically spec'd) */ function subunsub($mode) { $callback = $this->argUrl('hub.callback'); $topic = $this->argUrl('hub.topic'); if (!$this->recognizedFeed($topic)) { // TRANS: Client exception. %s is a topic. 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. 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. 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. throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'), $secret)); } $sub = HubSub::staticGet($topic, $callback); if (!$sub) { // Creating a new one! $sub = new HubSub(); $sub->topic = $topic; $sub->callback = $callback; } if ($mode == 'subscribe') { if ($secret) { $sub->secret = $secret; } if ($lease) { $sub->setLease(intval($lease)); } } 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 { $sub->verify($mode, $token); header('HTTP/1.1 204 No Content'); } }