summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-02-25 20:46:01 +0100
committerLukas Reschke <lukas@owncloud.com>2016-02-26 09:26:55 +0100
commit59028cced0a4f7377de9c22012c7624440b14a56 (patch)
treedc209a35e1626309032640459bec268323e51bac /lib
parentcb41b1a86397579d55e0ce96e67b80a83037d1d2 (diff)
downloadnextcloud-server-59028cced0a4f7377de9c22012c7624440b14a56.tar.gz
nextcloud-server-59028cced0a4f7377de9c22012c7624440b14a56.zip
Add autodiscovery support to server-to-server sharing
Adds autodiscovery support to server-to-server sharing as specified in the specification. If no discovery data is found it is using the fallback ownCloud endpoints for legacy support.
Diffstat (limited to 'lib')
-rw-r--r--lib/private/share/constants.php2
-rw-r--r--lib/private/share/share.php25
-rw-r--r--lib/private/share20/providerfactory.php8
3 files changed, 23 insertions, 12 deletions
diff --git a/lib/private/share/constants.php b/lib/private/share/constants.php
index e2b87d72476..e60eb98832b 100644
--- a/lib/private/share/constants.php
+++ b/lib/private/share/constants.php
@@ -40,8 +40,6 @@ class Constants {
const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility
- const BASE_PATH_TO_SHARE_API = '/ocs/v1.php/cloud/shares';
-
protected static $shareTypeUserAndGroups = -1;
protected static $shareTypeGroupUserUnique = 2;
protected static $backends = array();
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 149dd082bbc..4453e3758ba 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -38,6 +38,7 @@
namespace OC\Share;
use OC\Files\Filesystem;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IUserSession;
use OCP\IDBConnection;
@@ -2620,19 +2621,25 @@ class Share extends Constants {
/**
* try http post first with https and then with http as a fallback
*
- * @param string $url
+ * @param string $remoteDomain
+ * @param string $urlSuffix
* @param array $fields post parameters
* @return array
*/
- private static function tryHttpPost($url, $fields) {
+ private static function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
$protocol = 'https://';
$result = [
'success' => false,
'result' => '',
];
$try = 0;
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
while ($result['success'] === false && $try < 2) {
- $result = \OC::$server->getHTTPHelper()->post($protocol . $url, $fields);
+ $endpoint = $discoveryManager->getShareEndpoint($protocol . $remoteDomain);
+ $result = \OC::$server->getHTTPHelper()->post($protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, $fields);
$try++;
$protocol = 'http://';
}
@@ -2655,7 +2662,7 @@ class Share extends Constants {
list($user, $remote) = Helper::splitUserRemote($shareWith);
if ($user && $remote) {
- $url = $remote . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT;
+ $url = $remote;
$local = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
@@ -2669,10 +2676,10 @@ class Share extends Constants {
);
$url = self::removeProtocolFromUrl($url);
- $result = self::tryHttpPost($url, $fields);
+ $result = self::tryHttpPostToShareEndpoint($url, '', $fields);
$status = json_decode($result['result'], true);
- if ($result['success'] && $status['ocs']['meta']['statuscode'] === 100) {
+ if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
return true;
}
@@ -2691,13 +2698,13 @@ class Share extends Constants {
* @return bool
*/
private static function sendRemoteUnshare($remote, $id, $token) {
- $url = rtrim($remote, '/') . self::BASE_PATH_TO_SHARE_API . '/' . $id . '/unshare?format=' . self::RESPONSE_FORMAT;
+ $url = rtrim($remote, '/');
$fields = array('token' => $token, 'format' => 'json');
$url = self::removeProtocolFromUrl($url);
- $result = self::tryHttpPost($url, $fields);
+ $result = self::tryHttpPostToShareEndpoint($url, '/'.$id.'/unshare', $fields);
$status = json_decode($result['result'], true);
- return ($result['success'] && $status['ocs']['meta']['statuscode'] === 100);
+ return ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200));
}
/**
diff --git a/lib/private/share20/providerfactory.php b/lib/private/share20/providerfactory.php
index bb440d2e01f..c2980b22515 100644
--- a/lib/private/share20/providerfactory.php
+++ b/lib/private/share20/providerfactory.php
@@ -21,6 +21,7 @@
namespace OC\Share20;
use OCA\FederatedFileSharing\AddressHandler;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
@@ -91,9 +92,14 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getURLGenerator(),
$l
);
+ $discoveryManager = new DiscoveryManager(
+ $this->serverContainer->getMemCacheFactory(),
+ $this->serverContainer->getHTTPClientService()
+ );
$notifications = new Notifications(
$addressHandler,
- $this->serverContainer->getHTTPClientService()
+ $this->serverContainer->getHTTPClientService(),
+ $discoveryManager
);
$tokenHandler = new TokenHandler(
$this->serverContainer->getSecureRandom()