123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace OCA\FederatedFileSharing;
- use OCP\Federation\ICloudIdManager;
- use OCP\HintException;
- use OCP\IL10N;
- use OCP\IURLGenerator;
- use OCP\Util;
- class AddressHandler {
-
- public function __construct(
- private IURLGenerator $urlGenerator,
- private IL10N $l,
- private ICloudIdManager $cloudIdManager,
- ) {
- }
-
- public function splitUserRemote($address) {
- 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, 0, $e);
- }
- }
-
- public function generateRemoteURL() {
- return $this->urlGenerator->getAbsoluteURL('/');
- }
-
- public function compareAddresses($user1, $server1, $user2, $server2) {
- $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1));
- $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2));
- if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) {
-
- Util::emitHook(
- '\OCA\Files_Sharing\API\Server2Server',
- 'preLoginNameUsedAsUserName',
- ['uid' => &$user1]
- );
- Util::emitHook(
- '\OCA\Files_Sharing\API\Server2Server',
- 'preLoginNameUsedAsUserName',
- ['uid' => &$user2]
- );
- if ($user1 === $user2) {
- return true;
- }
- }
- return false;
- }
-
- public function removeProtocolFromUrl($url) {
- if (str_starts_with($url, 'https://')) {
- return substr($url, strlen('https://'));
- } elseif (str_starts_with($url, 'http://')) {
- return substr($url, strlen('http://'));
- }
- return $url;
- }
-
- public function urlContainProtocol($url) {
- if (str_starts_with($url, 'https://') ||
- str_starts_with($url, 'http://')) {
- return true;
- }
- return false;
- }
- }
|