diff options
Diffstat (limited to 'apps/federatedfilesharing/lib/AddressHandler.php')
-rw-r--r-- | apps/federatedfilesharing/lib/AddressHandler.php | 73 |
1 files changed, 13 insertions, 60 deletions
diff --git a/apps/federatedfilesharing/lib/AddressHandler.php b/apps/federatedfilesharing/lib/AddressHandler.php index 5fc41c2c804..6c59df06863 100644 --- a/apps/federatedfilesharing/lib/AddressHandler.php +++ b/apps/federatedfilesharing/lib/AddressHandler.php @@ -22,6 +22,7 @@ namespace OCA\FederatedFileSharing; use OC\HintException; +use OCP\Federation\ICloudIdManager; use OCP\IL10N; use OCP\IURLGenerator; @@ -38,18 +39,24 @@ class AddressHandler { /** @var IURLGenerator */ private $urlGenerator; + /** @var ICloudIdManager */ + private $cloudIdManager; + /** * AddressHandler constructor. * * @param IURLGenerator $urlGenerator * @param IL10N $il10n + * @param ICloudIdManager $cloudIdManager */ public function __construct( IURLGenerator $urlGenerator, - IL10N $il10n + IL10N $il10n, + ICloudIdManager $cloudIdManager ) { $this->l = $il10n; $this->urlGenerator = $urlGenerator; + $this->cloudIdManager = $cloudIdManager; } /** @@ -60,44 +67,13 @@ class AddressHandler { * @throws HintException */ public function splitUserRemote($address) { - if (strpos($address, '@') === false) { + try { + $cloudId = $this->cloudIdManager->resolveCloudId($address); + return [$cloudId->getUser(), $cloudId->getRemote()]; + } catch (\InvalidArgumentException $e) { $hint = $this->l->t('Invalid Federated Cloud ID'); - throw new HintException('Invalid Federated Cloud ID', $hint); - } - - // Find the first character that is not allowed in user names - $id = str_replace('\\', '/', $address); - $posSlash = strpos($id, '/'); - $posColon = strpos($id, ':'); - - if ($posSlash === false && $posColon === false) { - $invalidPos = strlen($id); - } else if ($posSlash === false) { - $invalidPos = $posColon; - } else if ($posColon === false) { - $invalidPos = $posSlash; - } else { - $invalidPos = min($posSlash, $posColon); - } - - // Find the last @ before $invalidPos - $pos = $lastAtPos = 0; - while ($lastAtPos !== false && $lastAtPos <= $invalidPos) { - $pos = $lastAtPos; - $lastAtPos = strpos($id, '@', $pos + 1); + throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); } - - if ($pos !== false) { - $user = substr($id, 0, $pos); - $remote = substr($id, $pos + 1); - $remote = $this->fixRemoteURL($remote); - if (!empty($user) && !empty($remote)) { - return array($user, $remote); - } - } - - $hint = $this->l->t('Invalid Federated Cloud ID'); - throw new HintException('Invalid Federated Cloud ID', $hint); } /** @@ -175,27 +151,4 @@ class AddressHandler { return false; } - - /** - * Strips away a potential file names and trailing slashes: - * - http://localhost - * - http://localhost/ - * - http://localhost/index.php - * - http://localhost/index.php/s/{shareToken} - * - * all return: http://localhost - * - * @param string $remote - * @return string - */ - protected function fixRemoteURL($remote) { - $remote = str_replace('\\', '/', $remote); - if ($fileNamePosition = strpos($remote, '/index.php')) { - $remote = substr($remote, 0, $fileNamePosition); - } - $remote = rtrim($remote, '/'); - - return $remote; - } - } |