Getting a profile from URI would throw exceptions on remote URL lookup failures
This commit is contained in:
parent
5efff58213
commit
f75ddaa8aa
@ -1078,7 +1078,7 @@ class OStatusPlugin extends Plugin
|
|||||||
function onStartGetProfileUri($profile, &$uri)
|
function onStartGetProfileUri($profile, &$uri)
|
||||||
{
|
{
|
||||||
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
|
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
|
||||||
if (!empty($oprofile)) {
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
$uri = $oprofile->uri;
|
$uri = $oprofile->uri;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1302,16 +1302,13 @@ class OStatusPlugin extends Plugin
|
|||||||
|
|
||||||
// Now, check remotely
|
// Now, check remotely
|
||||||
|
|
||||||
|
try {
|
||||||
$oprofile = Ostatus_profile::ensureProfileURI($uri);
|
$oprofile = Ostatus_profile::ensureProfileURI($uri);
|
||||||
|
|
||||||
if (!empty($oprofile)) {
|
|
||||||
$profile = $oprofile->localProfile();
|
$profile = $oprofile->localProfile();
|
||||||
return false;
|
return !($profile instanceof Profile); // localProfile won't throw exception but can return null
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return true; // It's not an OStatus profile as far as we know, continue event handling
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still not a hit, so give up.
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target)
|
function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target)
|
||||||
|
@ -976,7 +976,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
{
|
{
|
||||||
$oprofile = self::getFromProfileURL($profile_url);
|
$oprofile = self::getFromProfileURL($profile_url);
|
||||||
|
|
||||||
if (!empty($oprofile)) {
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1004,7 +1004,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
|
|
||||||
$oprofile = self::getFromProfileURL($finalUrl);
|
$oprofile = self::getFromProfileURL($finalUrl);
|
||||||
|
|
||||||
if (!empty($oprofile)) {
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1063,24 +1063,19 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
static function getFromProfileURL($profile_url)
|
static function getFromProfileURL($profile_url)
|
||||||
{
|
{
|
||||||
$profile = Profile::getKV('profileurl', $profile_url);
|
$profile = Profile::getKV('profileurl', $profile_url);
|
||||||
|
if (!$profile instanceof Profile) {
|
||||||
if (empty($profile)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a known Ostatus profile?
|
// Is it a known Ostatus profile?
|
||||||
|
|
||||||
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
|
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
|
||||||
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
if (!empty($oprofile)) {
|
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a local user?
|
// Is it a local user?
|
||||||
|
|
||||||
$user = User::getKV('id', $profile->id);
|
$user = User::getKV('id', $profile->id);
|
||||||
|
if ($user instanceof User) {
|
||||||
if (!empty($user)) {
|
|
||||||
// @todo i18n FIXME: use sprintf and add i18n (?)
|
// @todo i18n FIXME: use sprintf and add i18n (?)
|
||||||
throw new OStatusShadowException($profile, "'$profile_url' is the profile for local user '{$user->nickname}'.");
|
throw new OStatusShadowException($profile, "'$profile_url' is the profile for local user '{$user->nickname}'.");
|
||||||
}
|
}
|
||||||
@ -1899,7 +1894,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
throw new Exception(_m('Not a valid webfinger address.'));
|
throw new Exception(_m('Not a valid webfinger address.'));
|
||||||
}
|
}
|
||||||
$oprofile = Ostatus_profile::getKV('uri', $uri);
|
$oprofile = Ostatus_profile::getKV('uri', $uri);
|
||||||
if (!empty($oprofile)) {
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1907,7 +1902,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
// Try looking it up
|
// Try looking it up
|
||||||
$oprofile = Ostatus_profile::getKV('uri', 'acct:'.$addr);
|
$oprofile = Ostatus_profile::getKV('uri', 'acct:'.$addr);
|
||||||
|
|
||||||
if (!empty($oprofile)) {
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
|
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
@ -1998,7 +1993,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
|
|
||||||
$profile_id = $profile->insert();
|
$profile_id = $profile->insert();
|
||||||
|
|
||||||
if (!$profile_id) {
|
if ($profile_id === false) {
|
||||||
common_log_db_error($profile, 'INSERT', __FILE__);
|
common_log_db_error($profile, 'INSERT', __FILE__);
|
||||||
// TRANS: Exception. %s is a webfinger address.
|
// TRANS: Exception. %s is a webfinger address.
|
||||||
throw new Exception(sprintf(_m('Could not save profile for "%s".'),$addr));
|
throw new Exception(sprintf(_m('Could not save profile for "%s".'),$addr));
|
||||||
@ -2017,7 +2012,7 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
|
|
||||||
$result = $oprofile->insert();
|
$result = $oprofile->insert();
|
||||||
|
|
||||||
if (!$result) {
|
if ($result === false) {
|
||||||
common_log_db_error($oprofile, 'INSERT', __FILE__);
|
common_log_db_error($oprofile, 'INSERT', __FILE__);
|
||||||
// TRANS: Exception. %s is a webfinger address.
|
// TRANS: Exception. %s is a webfinger address.
|
||||||
throw new Exception(sprintf(_m('Could not save OStatus profile for "%s".'),$addr));
|
throw new Exception(sprintf(_m('Could not save OStatus profile for "%s".'),$addr));
|
||||||
@ -2085,9 +2080,11 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
|
|
||||||
$oprofile = Ostatus_profile::getKV('uri', $uri);
|
$oprofile = Ostatus_profile::getKV('uri', $uri);
|
||||||
|
|
||||||
// If unfound, do discovery stuff
|
if ($oprofile instanceof Ostatus_profile) {
|
||||||
|
return $oprofile;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$oprofile instanceof Ostatus_profile) {
|
// If unfound, do discovery stuff
|
||||||
if (preg_match("/^(\w+)\:(.*)/", $uri, $match)) {
|
if (preg_match("/^(\w+)\:(.*)/", $uri, $match)) {
|
||||||
$protocol = $match[1];
|
$protocol = $match[1];
|
||||||
switch ($protocol) {
|
switch ($protocol) {
|
||||||
@ -2112,7 +2109,6 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
// TRANS: Server exception. %s is a URI.
|
// TRANS: Server exception. %s is a URI.
|
||||||
throw new ServerException(sprintf(_m('No URI protocol for profile: %s.'),$uri));
|
throw new ServerException(sprintf(_m('No URI protocol for profile: %s.'),$uri));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $oprofile;
|
return $oprofile;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user