summaryrefslogtreecommitdiff
path: root/plugins/OStatus
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-04 07:00:45 -0800
committerBrion Vibber <brion@pobox.com>2010-03-04 07:00:45 -0800
commit62d5f1addb1b710a387f7732ace1dd33bd1b86c1 (patch)
treedf1d6d402dd057c330b0eb71b803d595c024d476 /plugins/OStatus
parent0f1c6e239acbf2c024c3aae9819d891f02b05bfd (diff)
parent9f861e9d895325adbb2dc7f1d540a442be2c1b2f (diff)
Merge branch 'testing'
Diffstat (limited to 'plugins/OStatus')
-rw-r--r--plugins/OStatus/OStatusPlugin.php6
-rw-r--r--plugins/OStatus/actions/hostmeta.php2
-rw-r--r--plugins/OStatus/actions/ostatusgroup.php4
-rw-r--r--plugins/OStatus/actions/ostatussub.php33
-rw-r--r--plugins/OStatus/actions/ownerxrd.php56
-rw-r--r--plugins/OStatus/actions/userxrd.php48
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php27
-rw-r--r--plugins/OStatus/lib/magicenvelope.php16
-rw-r--r--plugins/OStatus/lib/ostatusqueuehandler.php45
-rw-r--r--plugins/OStatus/lib/xrd.php3
-rw-r--r--plugins/OStatus/lib/xrdaction.php (renamed from plugins/OStatus/actions/xrd.php)32
-rw-r--r--plugins/OStatus/theme/base/css/ostatus.css3
12 files changed, 189 insertions, 86 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index cc7e75976..ad4f61389 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -44,7 +44,9 @@ class OStatusPlugin extends Plugin
$m->connect('.well-known/host-meta',
array('action' => 'hostmeta'));
$m->connect('main/xrd',
- array('action' => 'xrd'));
+ array('action' => 'userxrd'));
+ $m->connect('main/ownerxrd',
+ array('action' => 'ownerxrd'));
$m->connect('main/ostatus',
array('action' => 'ostatusinit'));
$m->connect('main/ostatus?nickname=:nickname',
@@ -111,7 +113,7 @@ class OStatusPlugin extends Plugin
{
if ($action instanceof ShowstreamAction) {
$acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
- $url = common_local_url('xrd');
+ $url = common_local_url('userxrd');
$url.= '?uri='. $acct;
header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
diff --git a/plugins/OStatus/actions/hostmeta.php b/plugins/OStatus/actions/hostmeta.php
index 3d00b98ae..6d35ada6c 100644
--- a/plugins/OStatus/actions/hostmeta.php
+++ b/plugins/OStatus/actions/hostmeta.php
@@ -32,7 +32,7 @@ class HostMetaAction extends Action
parent::handle();
$domain = common_config('site', 'server');
- $url = common_local_url('xrd');
+ $url = common_local_url('userxrd');
$url.= '?uri={uri}';
$xrd = new XRD();
diff --git a/plugins/OStatus/actions/ostatusgroup.php b/plugins/OStatus/actions/ostatusgroup.php
index 4fcd0eb39..f325ba053 100644
--- a/plugins/OStatus/actions/ostatusgroup.php
+++ b/plugins/OStatus/actions/ostatusgroup.php
@@ -72,9 +72,9 @@ class OStatusGroupAction extends OStatusSubAction
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->input('profile',
- _m('Group profile URL'),
+ _m('Join group'),
$this->profile_uri,
- _m('Enter the profile URL of a group on another StatusNet site'));
+ _m("OStatus group's address, like http://example.net/group/nickname"));
$this->elementEnd('li');
$this->elementEnd('ul');
diff --git a/plugins/OStatus/actions/ostatussub.php b/plugins/OStatus/actions/ostatussub.php
index 542f7e20c..65dee2392 100644
--- a/plugins/OStatus/actions/ostatussub.php
+++ b/plugins/OStatus/actions/ostatussub.php
@@ -62,9 +62,9 @@ class OStatusSubAction extends Action
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->input('profile',
- _m('Address or profile URL'),
+ _m('Subscribe to'),
$this->profile_uri,
- _m('Enter the profile URL of a PubSubHubbub-enabled feed'));
+ _m("OStatus user's address, like nickname@example.com or http://example.net/nickname"));
$this->elementEnd('li');
$this->elementEnd('ul');
@@ -244,25 +244,33 @@ class OStatusSubAction extends Action
} else if (Validate::uri($this->profile_uri)) {
$this->oprofile = Ostatus_profile::ensureProfile($this->profile_uri);
} else {
- $this->error = _m("Invalid address format.");
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug('Invalid address format.', __FILE__);
return false;
}
return true;
} catch (FeedSubBadURLException $e) {
- $this->error = _m('Invalid URL or could not reach server.');
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug('Invalid URL or could not reach server.', __FILE__);
} catch (FeedSubBadResponseException $e) {
- $this->error = _m('Cannot read feed; server returned error.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Cannot read feed; server returned error.', __FILE__);
} catch (FeedSubEmptyException $e) {
- $this->error = _m('Cannot read feed; server returned an empty page.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Cannot read feed; server returned an empty page.', __FILE__);
} catch (FeedSubBadHTMLException $e) {
- $this->error = _m('Bad HTML, could not find feed link.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Bad HTML, could not find feed link.', __FILE__);
} catch (FeedSubNoFeedException $e) {
- $this->error = _m('Could not find a feed linked from this URL.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Could not find a feed linked from this URL.', __FILE__);
} catch (FeedSubUnrecognizedTypeException $e) {
- $this->error = _m('Not a recognized feed type.');
- } catch (FeedSubException $e) {
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Not a recognized feed type.', __FILE__);
+ } catch (Exception $e) {
// Any new ones we forgot about
- $this->error = sprintf(_m('Bad feed URL: %s %s'), get_class($e), $e->getMessage());
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug(sprintf('Bad feed URL: %s %s', get_class($e), $e->getMessage()), __FILE__);
}
return false;
@@ -315,7 +323,6 @@ class OStatusSubAction extends Action
if ($this->pullRemoteProfile()) {
$this->validateRemoteProfile();
}
-
return true;
}
@@ -391,7 +398,7 @@ class OStatusSubAction extends Action
function title()
{
// TRANS: Page title for OStatus remote subscription form
- return _m('Authorize subscription');
+ return _m('Confirm');
}
/**
diff --git a/plugins/OStatus/actions/ownerxrd.php b/plugins/OStatus/actions/ownerxrd.php
new file mode 100644
index 000000000..9c141d8c7
--- /dev/null
+++ b/plugins/OStatus/actions/ownerxrd.php
@@ -0,0 +1,56 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer James Walker <james@status.net>
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+class OwnerxrdAction extends XrdAction
+{
+
+ public $uri;
+
+ function prepare($args)
+ {
+ $this->user = User::siteOwner();
+
+ if (!$this->user) {
+ $this->clientError(_('No such user.'), 404);
+ return false;
+ }
+
+ $nick = common_canonical_nickname($this->user->nickname);
+ $acct = 'acct:' . $nick . '@' . common_config('site', 'server');
+
+ $this->xrd = new XRD();
+
+ // Check to see if a $config['webfinger']['owner'] has been set
+ if ($owner = common_config('webfinger', 'owner')) {
+ $this->xrd->subject = Discovery::normalize($owner);
+ $this->xrd->alias[] = $acct;
+ } else {
+ $this->xrd->subject = $acct;
+ }
+
+ return true;
+ }
+}
diff --git a/plugins/OStatus/actions/userxrd.php b/plugins/OStatus/actions/userxrd.php
new file mode 100644
index 000000000..414de9364
--- /dev/null
+++ b/plugins/OStatus/actions/userxrd.php
@@ -0,0 +1,48 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer James Walker <james@status.net>
+ */
+
+if (!defined('STATUSNET')) { exit(1); }
+
+class UserxrdAction extends XrdAction
+{
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->uri = $this->trimmed('uri');
+ $acct = Discovery::normalize($this->uri);
+
+ list($nick, $domain) = explode('@', substr(urldecode($acct), 5));
+ $nick = common_canonical_nickname($nick);
+
+ $this->user = User::staticGet('nickname', $nick);
+ if (!$this->user) {
+ $this->clientError(_('No such user.'), 404);
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 7ab031aa5..fcca1a252 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -1267,6 +1267,11 @@ class Ostatus_profile extends Memcached_DataObject
}
}
+ /**
+ * @param string $addr webfinger address
+ * @return Ostatus_profile
+ * @throws Exception on error conditions
+ */
public static function ensureWebfinger($addr)
{
// First, try the cache
@@ -1275,7 +1280,8 @@ class Ostatus_profile extends Memcached_DataObject
if ($uri !== false) {
if (is_null($uri)) {
- return null;
+ // Negative cache entry
+ throw new Exception('Not a valid webfinger address.');
}
$oprofile = Ostatus_profile::staticGet('uri', $uri);
if (!empty($oprofile)) {
@@ -1299,20 +1305,24 @@ class Ostatus_profile extends Memcached_DataObject
try {
$result = $disco->lookup($addr);
} catch (Exception $e) {
+ // Save negative cache entry so we don't waste time looking it up again.
+ // @fixme distinguish temporary failures?
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
- return null;
+ throw new Exception('Not a valid webfinger address.');
}
+ $hints = array('webfinger' => $addr);
+
foreach ($result->links as $link) {
switch ($link['rel']) {
case Discovery::PROFILEPAGE:
- $profileUrl = $link['href'];
+ $hints['profileurl'] = $profileUrl = $link['href'];
break;
case Salmon::NS_REPLIES:
- $salmonEndpoint = $link['href'];
+ $hints['salmon'] = $salmonEndpoint = $link['href'];
break;
case Discovery::UPDATESFROM:
- $feedUrl = $link['href'];
+ $hints['feedurl'] = $feedUrl = $link['href'];
break;
case Discovery::HCARD:
$hcardUrl = $link['href'];
@@ -1323,11 +1333,6 @@ class Ostatus_profile extends Memcached_DataObject
}
}
- $hints = array('webfinger' => $addr,
- 'profileurl' => $profileUrl,
- 'feedurl' => $feedUrl,
- 'salmon' => $salmonEndpoint);
-
if (isset($hcardUrl)) {
$hcardHints = self::slurpHcard($hcardUrl);
// Note: Webfinger > hcard
@@ -1410,7 +1415,7 @@ class Ostatus_profile extends Memcached_DataObject
return $oprofile;
}
- return null;
+ throw new Exception("Couldn't find a valid profile for '$addr'");
}
function saveHTMLFile($title, $rendered)
diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php
index 230d81ba1..fb8c57c71 100644
--- a/plugins/OStatus/lib/magicenvelope.php
+++ b/plugins/OStatus/lib/magicenvelope.php
@@ -156,18 +156,32 @@ class MagicEnvelope
public function verify($env)
{
if ($env['alg'] != 'RSA-SHA256') {
+ common_log(LOG_DEBUG, "Salmon error: bad algorithm");
return false;
}
if ($env['encoding'] != MagicEnvelope::ENCODING) {
+ common_log(LOG_DEBUG, "Salmon error: bad encoding");
return false;
}
$text = base64_decode($env['data']);
$signer_uri = $this->getAuthor($text);
- $verifier = Magicsig::fromString($this->getKeyPair($signer_uri));
+ try {
+ $keypair = $this->getKeyPair($signer_uri);
+ } catch (Exception $e) {
+ common_log(LOG_DEBUG, "Salmon error: ".$e->getMessage());
+ return false;
+ }
+
+ $verifier = Magicsig::fromString($keypair);
+ if (!$verifier) {
+ common_log(LOG_DEBUG, "Salmon error: unable to parse keypair");
+ return false;
+ }
+
return $verifier->verify($env['data'], $env['sig']);
}
diff --git a/plugins/OStatus/lib/ostatusqueuehandler.php b/plugins/OStatus/lib/ostatusqueuehandler.php
index 6ca31c485..d1e58f1d6 100644
--- a/plugins/OStatus/lib/ostatusqueuehandler.php
+++ b/plugins/OStatus/lib/ostatusqueuehandler.php
@@ -164,46 +164,21 @@ class OStatusQueueHandler extends QueueHandler
*/
function userFeedForNotice()
{
- // @fixme this feels VERY hacky...
- // should probably be a cleaner way to do it
-
- ob_start();
- $api = new ApiTimelineUserAction();
- $api->prepare(array('id' => $this->notice->profile_id,
- 'format' => 'atom',
- 'max_id' => $this->notice->id,
- 'since_id' => $this->notice->id - 1));
- $api->showTimeline();
- $feed = ob_get_clean();
-
- // ...and override the content-type back to something normal... eww!
- // hope there's no other headers that got set while we weren't looking.
- header('Content-Type: text/html; charset=utf-8');
-
- common_log(LOG_DEBUG, $feed);
+ $atom = new AtomUserNoticeFeed($this->user);
+ $atom->addEntryFromNotice($this->notice);
+ $feed = $atom->getString();
+
return $feed;
}
function groupFeedForNotice($group_id)
{
- // @fixme this feels VERY hacky...
- // should probably be a cleaner way to do it
-
- ob_start();
- $api = new ApiTimelineGroupAction();
- $args = array('id' => $group_id,
- 'format' => 'atom',
- 'max_id' => $this->notice->id,
- 'since_id' => $this->notice->id - 1);
- $api->prepare($args);
- $api->handle($args);
- $feed = ob_get_clean();
-
- // ...and override the content-type back to something normal... eww!
- // hope there's no other headers that got set while we weren't looking.
- header('Content-Type: text/html; charset=utf-8');
-
- common_log(LOG_DEBUG, $feed);
+ $group = User_group::staticGet('id', $group_id);
+
+ $atom = new AtomGroupNoticeFeed($group);
+ $atom->addEntryFromNotice($this->notice);
+ $feed = $atom->getString();
+
return $feed;
}
diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php
index f00e1f809..aa13ef024 100644
--- a/plugins/OStatus/lib/xrd.php
+++ b/plugins/OStatus/lib/xrd.php
@@ -57,6 +57,9 @@ class XRD
throw new Exception("Invalid XML");
}
$xrd_element = $dom->getElementsByTagName('XRD')->item(0);
+ if (!$xrd_element) {
+ throw new Exception("Invalid XML, missing XRD root");
+ }
// Check for host-meta host
$host = $xrd_element->getElementsByTagName('Host')->item(0);
diff --git a/plugins/OStatus/actions/xrd.php b/plugins/OStatus/lib/xrdaction.php
index f574b60ee..6881292ad 100644
--- a/plugins/OStatus/actions/xrd.php
+++ b/plugins/OStatus/lib/xrdaction.php
@@ -28,32 +28,24 @@ class XrdAction extends Action
{
public $uri;
+
+ public $user;
- function prepare($args)
- {
- parent::prepare($args);
-
- $this->uri = $this->trimmed('uri');
-
- return true;
- }
-
+ public $xrd;
+
function handle()
{
- $acct = Discovery::normalize($this->uri);
-
- $xrd = new XRD();
+ $nick = $this->user->nickname;
- list($nick, $domain) = explode('@', substr(urldecode($acct), 5));
- $nick = common_canonical_nickname($nick);
-
- $this->user = User::staticGet('nickname', $nick);
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
+ if (empty($this->xrd)) {
+ $xrd = new XRD();
+ } else {
+ $xrd = $this->xrd;
}
- $xrd->subject = $this->uri;
+ if (empty($xrd->subject)) {
+ $xrd->subject = Discovery::normalize($this->uri);
+ }
$xrd->alias[] = common_profile_url($nick);
$xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
'type' => 'text/html',
diff --git a/plugins/OStatus/theme/base/css/ostatus.css b/plugins/OStatus/theme/base/css/ostatus.css
index ac668623d..f7d9853cf 100644
--- a/plugins/OStatus/theme/base/css/ostatus.css
+++ b/plugins/OStatus/theme/base/css/ostatus.css
@@ -52,7 +52,8 @@ margin-bottom:0;
width:405px;
}
-.aside #entity_subscriptions .more {
+.aside #entity_subscriptions .more,
+.aside #entity_groups .more {
float:left;
}