aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Share
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-02-09 14:54:32 +0100
committerGitHub <noreply@github.com>2017-02-09 14:54:32 +0100
commitbf88060a98ce397768d4afa7935b80751e4533f8 (patch)
tree6baaf10832fa68999eea01ab3df5241fdd3ece0a /lib/private/Share
parent4a5a3681d921adad8c4cb5bb29180514446ea2b9 (diff)
parent0d8d658b7e3885d92103a6e6248b37863f9acf1b (diff)
downloadnextcloud-server-bf88060a98ce397768d4afa7935b80751e4533f8.tar.gz
nextcloud-server-bf88060a98ce397768d4afa7935b80751e4533f8.zip
Merge pull request #3297 from nextcloud/cloud-id-resolve
Add a single public api for resolving a cloud id to a user and remote and back
Diffstat (limited to 'lib/private/Share')
-rw-r--r--lib/private/Share/Helper.php42
1 files changed, 5 insertions, 37 deletions
diff --git a/lib/private/Share/Helper.php b/lib/private/Share/Helper.php
index 20aaa793728..a1a56077d40 100644
--- a/lib/private/Share/Helper.php
+++ b/lib/private/Share/Helper.php
@@ -249,46 +249,14 @@ class Helper extends \OC\Share\Constants {
* @throws HintException
*/
public static function splitUserRemote($id) {
- if (strpos($id, '@') === false) {
+ try {
+ $cloudId = \OC::$server->getCloudIdManager()->resolveCloudId($id);
+ return [$cloudId->getUser(), $cloudId->getRemote()];
+ } catch (\InvalidArgumentException $e) {
$l = \OC::$server->getL10N('core');
$hint = $l->t('Invalid Federated Cloud ID');
- throw new HintException('Invalid Federated Cloud ID', $hint);
+ throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e);
}
-
- // Find the first character that is not allowed in user names
- $id = str_replace('\\', '/', $id);
- $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);
- }
-
- if ($pos !== false) {
- $user = substr($id, 0, $pos);
- $remote = substr($id, $pos + 1);
- $remote = self::fixRemoteURL($remote);
- if (!empty($user) && !empty($remote)) {
- return array($user, $remote);
- }
- }
-
- $l = \OC::$server->getL10N('core');
- $hint = $l->t('Invalid Federated Cloud ID');
- throw new HintException('Invalid Fededrated Cloud ID', $hint);
}
/**