// PHP converts '.'s in incoming var names to '_'s.
// It also merges multiple values, which'll break hub.verify and hub.topic for publishing
// @fixme handle multiple args
- $arg = str_replace('.', '_', $arg);
+ $arg = str_replace('hub.', 'hub_', $arg);
return parent::arg($arg, $def);
}
$sub = new HubSub();
$sub->topic = $feed;
$sub->callback = $callback;
+ $sub->verify_token = $this->arg('hub.verify_token', null);
$sub->secret = $this->arg('hub.secret', null);
+ if (strlen($sub->secret) > 200) {
+ throw new ClientException("hub.secret must be no longer than 200 chars", 400);
+ }
$sub->setLease(intval($this->arg('hub.lease_seconds')));
// @fixme check for feeds we don't manage
$avatar = $munger->getAvatar();
if ($avatar) {
try {
- $this->updateAvatar($avatar);
+ $profile->updateAvatar($avatar);
} catch (Exception $e) {
common_log(LOG_ERR, "Exception setting OStatus avatar: " .
$e->getMessage());
// ripped from oauthstore.php (for old OMB client)
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
copy($url, $temp_filename);
- $imagefile = new ImageFile($profile->id, $temp_filename);
- $filename = Avatar::filename($profile->id,
+
+ // @fixme should we be using different ids?
+ $imagefile = new ImageFile($this->id, $temp_filename);
+ $filename = Avatar::filename($this->id,
image_type_to_extension($imagefile->type),
null,
common_timestamp());
* The hub will later send us a confirmation POST to /main/push/callback.
*
* @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
*/
public function subscribe($mode='subscribe')
{
- if (common_config('feedsub', 'nohub')) {
- // Fake it! We're just testing remote feeds w/o hubs.
- return true;
+ if ($this->sub_state != '') {
+ throw new ServerException("Attempting to start PuSH subscription to feed in state $this->sub_state");
}
- // @fixme use the verification token
- #$token = md5(mt_rand() . ':' . $this->feeduri);
- #$this->verify_token = $token;
- #$this->update(); // @fixme
+ if (empty($this->huburi)) {
+ if (common_config('feedsub', 'nohub')) {
+ // Fake it! We're just testing remote feeds w/o hubs.
+ return true;
+ } else {
+ throw new ServerException("Attempting to start PuSH subscription for feed with no hub");
+ }
+ }
+
+ return $this->doSubscribe('subscribe');
+ }
+
+ /**
+ * Send a PuSH unsubscription request to the hub for this feed.
+ * The hub will later send us a confirmation POST to /main/push/callback.
+ *
+ * @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
+ */
+ public function unsubscribe() {
+ if ($this->sub_state != 'active') {
+ throw new ServerException("Attempting to end PuSH subscription to feed in state $this->sub_state");
+ }
+ if (empty($this->huburi)) {
+ if (common_config('feedsub', 'nohub')) {
+ // Fake it! We're just testing remote feeds w/o hubs.
+ return true;
+ } else {
+ throw new ServerException("Attempting to end PuSH subscription for feed with no hub");
+ }
+ }
+
+ return $this->doSubscribe('unsubscribe');
+ }
+
+ protected function doSubscribe($mode)
+ {
+ $orig = clone($this);
+ $this->verify_token = md5(mt_rand() . ':' . $this->feeduri);
+ $this->sub_state = $mode;
+ $this->update($orig);
+ unset($orig);
+
try {
$callback = common_local_url('pushcallback', array('feed' => $this->id));
$headers = array('Content-Type: application/x-www-form-urlencoded');
} catch (Exception $e) {
// wtf!
common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->feeduri");
+
+ $orig = clone($this);
+ $this->verify_token = null;
+ $this->sub_state = null;
+ $this->update($orig);
+ unset($orig);
+
return false;
}
}
return $this->update($original);
}
- /**
- * Send a PuSH unsubscription request to the hub for this feed.
- * The hub will later send us a confirmation POST to /main/push/callback.
- *
- * @return bool true on success, false on failure
- */
- public function unsubscribe() {
- return $this->subscribe('unsubscribe');
- }
-
/**
* Send an Activity Streams notification to the remote Salmon endpoint,
* if so configured.
{
common_log(LOG_INFO, __METHOD__ . ": packet for \"$this->feeduri\"! $hmac $xml");
+ if ($this->sub_state != 'active') {
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed $this->feeduri (in state '$this->sub_state')");
+ return;
+ }
+
if ($this->secret) {
if (preg_match('/^sha1=([0-9a-fA-F]{40})$/', $hmac, $matches)) {
$their_hmac = strtolower($matches[1]);