From d5dec527c964fd08b91f9ab6ffeea228ca214ad6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 24 Feb 2017 16:09:52 +0100 Subject: get addressbook url and carddav user from remote server Signed-off-by: Bjoern Schiessle --- apps/federation/lib/SyncFederationAddressBooks.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'apps/federation/lib/SyncFederationAddressBooks.php') diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php index 759b59183aa..87419a5ba54 100644 --- a/apps/federation/lib/SyncFederationAddressBooks.php +++ b/apps/federation/lib/SyncFederationAddressBooks.php @@ -23,12 +23,10 @@ */ namespace OCA\Federation; +use OC\OCS\DiscoveryService; use OCA\DAV\CardDAV\SyncService; use OCP\AppFramework\Http; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; +use OCP\OCS\IDiscoveryService; class SyncFederationAddressBooks { @@ -38,13 +36,21 @@ class SyncFederationAddressBooks { /** @var SyncService */ private $syncService; + /** @var DiscoveryService */ + private $ocsDiscoveryService; + /** * @param DbHandler $dbHandler * @param SyncService $syncService + * @param IDiscoveryService $ocsDiscoveryService */ - function __construct(DbHandler $dbHandler, SyncService $syncService) { + public function __construct(DbHandler $dbHandler, + SyncService $syncService, + IDiscoveryService $ocsDiscoveryService + ) { $this->syncService = $syncService; $this->dbHandler = $dbHandler; + $this->ocsDiscoveryService = $ocsDiscoveryService; } /** @@ -59,6 +65,10 @@ class SyncFederationAddressBooks { $sharedSecret = $trustedServer['shared_secret']; $syncToken = $trustedServer['sync_token']; + $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING'); + $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system'; + $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system'; + if (is_null($sharedSecret)) { continue; } @@ -68,7 +78,7 @@ class SyncFederationAddressBooks { '{DAV:}displayname' => $url ]; try { - $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); + $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); if ($newToken !== $syncToken) { $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); } -- cgit v1.2.3