Completed
Pull Request — master (#8855)
by Blizzz
67:52 queued 49:32
created
lib/private/Cache/File.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -33,170 +33,170 @@
 block discarded – undo
33 33
 
34 34
 class File implements ICache {
35 35
 
36
-	/** @var View */
37
-	protected $storage;
36
+    /** @var View */
37
+    protected $storage;
38 38
 
39
-	/**
40
-	 * Returns the cache storage for the logged in user
41
-	 *
42
-	 * @return \OC\Files\View cache storage
43
-	 * @throws \OC\ForbiddenException
44
-	 * @throws \OC\User\NoUserException
45
-	 */
46
-	protected function getStorage() {
47
-		if (isset($this->storage)) {
48
-			return $this->storage;
49
-		}
50
-		if (\OC::$server->getUserSession()->isLoggedIn()) {
51
-			$rootView = new View();
52
-			$user = \OC::$server->getUserSession()->getUser();
53
-			Filesystem::initMountPoints($user->getUID());
54
-			if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
55
-				$rootView->mkdir('/' . $user->getUID() . '/cache');
56
-			}
57
-			$this->storage = new View('/' . $user->getUID() . '/cache');
58
-			return $this->storage;
59
-		} else {
60
-			\OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR);
61
-			throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
62
-		}
63
-	}
39
+    /**
40
+     * Returns the cache storage for the logged in user
41
+     *
42
+     * @return \OC\Files\View cache storage
43
+     * @throws \OC\ForbiddenException
44
+     * @throws \OC\User\NoUserException
45
+     */
46
+    protected function getStorage() {
47
+        if (isset($this->storage)) {
48
+            return $this->storage;
49
+        }
50
+        if (\OC::$server->getUserSession()->isLoggedIn()) {
51
+            $rootView = new View();
52
+            $user = \OC::$server->getUserSession()->getUser();
53
+            Filesystem::initMountPoints($user->getUID());
54
+            if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
55
+                $rootView->mkdir('/' . $user->getUID() . '/cache');
56
+            }
57
+            $this->storage = new View('/' . $user->getUID() . '/cache');
58
+            return $this->storage;
59
+        } else {
60
+            \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR);
61
+            throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
62
+        }
63
+    }
64 64
 
65
-	/**
66
-	 * @param string $key
67
-	 * @return mixed|null
68
-	 * @throws \OC\ForbiddenException
69
-	 */
70
-	public function get($key) {
71
-		$result = null;
72
-		if ($this->hasKey($key)) {
73
-			$storage = $this->getStorage();
74
-			$result = $storage->file_get_contents($key);
75
-		}
76
-		return $result;
77
-	}
65
+    /**
66
+     * @param string $key
67
+     * @return mixed|null
68
+     * @throws \OC\ForbiddenException
69
+     */
70
+    public function get($key) {
71
+        $result = null;
72
+        if ($this->hasKey($key)) {
73
+            $storage = $this->getStorage();
74
+            $result = $storage->file_get_contents($key);
75
+        }
76
+        return $result;
77
+    }
78 78
 
79
-	/**
80
-	 * Returns the size of the stored/cached data
81
-	 *
82
-	 * @param string $key
83
-	 * @return int
84
-	 */
85
-	public function size($key) {
86
-		$result = 0;
87
-		if ($this->hasKey($key)) {
88
-			$storage = $this->getStorage();
89
-			$result = $storage->filesize($key);
90
-		}
91
-		return $result;
92
-	}
79
+    /**
80
+     * Returns the size of the stored/cached data
81
+     *
82
+     * @param string $key
83
+     * @return int
84
+     */
85
+    public function size($key) {
86
+        $result = 0;
87
+        if ($this->hasKey($key)) {
88
+            $storage = $this->getStorage();
89
+            $result = $storage->filesize($key);
90
+        }
91
+        return $result;
92
+    }
93 93
 
94
-	/**
95
-	 * @param string $key
96
-	 * @param mixed $value
97
-	 * @param int $ttl
98
-	 * @return bool|mixed
99
-	 * @throws \OC\ForbiddenException
100
-	 */
101
-	public function set($key, $value, $ttl = 0) {
102
-		$storage = $this->getStorage();
103
-		$result = false;
104
-		// unique id to avoid chunk collision, just in case
105
-		$uniqueId = \OC::$server->getSecureRandom()->generate(
106
-			16,
107
-			ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
108
-		);
94
+    /**
95
+     * @param string $key
96
+     * @param mixed $value
97
+     * @param int $ttl
98
+     * @return bool|mixed
99
+     * @throws \OC\ForbiddenException
100
+     */
101
+    public function set($key, $value, $ttl = 0) {
102
+        $storage = $this->getStorage();
103
+        $result = false;
104
+        // unique id to avoid chunk collision, just in case
105
+        $uniqueId = \OC::$server->getSecureRandom()->generate(
106
+            16,
107
+            ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
108
+        );
109 109
 
110
-		// use part file to prevent hasKey() to find the key
111
-		// while it is being written
112
-		$keyPart = $key . '.' . $uniqueId . '.part';
113
-		if ($storage and $storage->file_put_contents($keyPart, $value)) {
114
-			if ($ttl === 0) {
115
-				$ttl = 86400; // 60*60*24
116
-			}
117
-			$result = $storage->touch($keyPart, time() + $ttl);
118
-			$result &= $storage->rename($keyPart, $key);
119
-		}
120
-		return $result;
121
-	}
110
+        // use part file to prevent hasKey() to find the key
111
+        // while it is being written
112
+        $keyPart = $key . '.' . $uniqueId . '.part';
113
+        if ($storage and $storage->file_put_contents($keyPart, $value)) {
114
+            if ($ttl === 0) {
115
+                $ttl = 86400; // 60*60*24
116
+            }
117
+            $result = $storage->touch($keyPart, time() + $ttl);
118
+            $result &= $storage->rename($keyPart, $key);
119
+        }
120
+        return $result;
121
+    }
122 122
 
123
-	/**
124
-	 * @param string $key
125
-	 * @return bool
126
-	 * @throws \OC\ForbiddenException
127
-	 */
128
-	public function hasKey($key) {
129
-		$storage = $this->getStorage();
130
-		if ($storage && $storage->is_file($key) && $storage->isReadable($key)) {
131
-			return true;
132
-		}
133
-		return false;
134
-	}
123
+    /**
124
+     * @param string $key
125
+     * @return bool
126
+     * @throws \OC\ForbiddenException
127
+     */
128
+    public function hasKey($key) {
129
+        $storage = $this->getStorage();
130
+        if ($storage && $storage->is_file($key) && $storage->isReadable($key)) {
131
+            return true;
132
+        }
133
+        return false;
134
+    }
135 135
 
136
-	/**
137
-	 * @param string $key
138
-	 * @return bool|mixed
139
-	 * @throws \OC\ForbiddenException
140
-	 */
141
-	public function remove($key) {
142
-		$storage = $this->getStorage();
143
-		if (!$storage) {
144
-			return false;
145
-		}
146
-		return $storage->unlink($key);
147
-	}
136
+    /**
137
+     * @param string $key
138
+     * @return bool|mixed
139
+     * @throws \OC\ForbiddenException
140
+     */
141
+    public function remove($key) {
142
+        $storage = $this->getStorage();
143
+        if (!$storage) {
144
+            return false;
145
+        }
146
+        return $storage->unlink($key);
147
+    }
148 148
 
149
-	/**
150
-	 * @param string $prefix
151
-	 * @return bool
152
-	 * @throws \OC\ForbiddenException
153
-	 */
154
-	public function clear($prefix = '') {
155
-		$storage = $this->getStorage();
156
-		if ($storage and $storage->is_dir('/')) {
157
-			$dh = $storage->opendir('/');
158
-			if (is_resource($dh)) {
159
-				while (($file = readdir($dh)) !== false) {
160
-					if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) {
161
-						$storage->unlink('/' . $file);
162
-					}
163
-				}
164
-			}
165
-		}
166
-		return true;
167
-	}
149
+    /**
150
+     * @param string $prefix
151
+     * @return bool
152
+     * @throws \OC\ForbiddenException
153
+     */
154
+    public function clear($prefix = '') {
155
+        $storage = $this->getStorage();
156
+        if ($storage and $storage->is_dir('/')) {
157
+            $dh = $storage->opendir('/');
158
+            if (is_resource($dh)) {
159
+                while (($file = readdir($dh)) !== false) {
160
+                    if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) {
161
+                        $storage->unlink('/' . $file);
162
+                    }
163
+                }
164
+            }
165
+        }
166
+        return true;
167
+    }
168 168
 
169
-	/**
170
-	 * Runs GC
171
-	 * @throws \OC\ForbiddenException
172
-	 */
173
-	public function gc() {
174
-		$storage = $this->getStorage();
175
-		if ($storage and $storage->is_dir('/')) {
176
-			// extra hour safety, in case of stray part chunks that take longer to write,
177
-			// because touch() is only called after the chunk was finished
178
-			$now = time() - 3600;
179
-			$dh = $storage->opendir('/');
180
-			if (!is_resource($dh)) {
181
-				return null;
182
-			}
183
-			while (($file = readdir($dh)) !== false) {
184
-				if ($file != '.' and $file != '..') {
185
-					try {
186
-						$mtime = $storage->filemtime('/' . $file);
187
-						if ($mtime < $now) {
188
-							$storage->unlink('/' . $file);
189
-						}
190
-					} catch (\OCP\Lock\LockedException $e) {
191
-						// ignore locked chunks
192
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
193
-					} catch (\OCP\Files\ForbiddenException $e) {
194
-						\OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core'));
195
-					} catch (\OCP\Files\LockNotAcquiredException $e) {
196
-						\OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
197
-					}
198
-				}
199
-			}
200
-		}
201
-	}
169
+    /**
170
+     * Runs GC
171
+     * @throws \OC\ForbiddenException
172
+     */
173
+    public function gc() {
174
+        $storage = $this->getStorage();
175
+        if ($storage and $storage->is_dir('/')) {
176
+            // extra hour safety, in case of stray part chunks that take longer to write,
177
+            // because touch() is only called after the chunk was finished
178
+            $now = time() - 3600;
179
+            $dh = $storage->opendir('/');
180
+            if (!is_resource($dh)) {
181
+                return null;
182
+            }
183
+            while (($file = readdir($dh)) !== false) {
184
+                if ($file != '.' and $file != '..') {
185
+                    try {
186
+                        $mtime = $storage->filemtime('/' . $file);
187
+                        if ($mtime < $now) {
188
+                            $storage->unlink('/' . $file);
189
+                        }
190
+                    } catch (\OCP\Lock\LockedException $e) {
191
+                        // ignore locked chunks
192
+                        \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
193
+                    } catch (\OCP\Files\ForbiddenException $e) {
194
+                        \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core'));
195
+                    } catch (\OCP\Files\LockNotAcquiredException $e) {
196
+                        \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core'));
197
+                    }
198
+                }
199
+            }
200
+        }
201
+    }
202 202
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -45,114 +45,114 @@
 block discarded – undo
45 45
  * @package OCA\DAV\Connector\Sabre
46 46
  */
47 47
 class FakeLockerPlugin extends ServerPlugin {
48
-	/** @var \Sabre\DAV\Server */
49
-	private $server;
48
+    /** @var \Sabre\DAV\Server */
49
+    private $server;
50 50
 
51
-	/** {@inheritDoc} */
52
-	public function initialize(\Sabre\DAV\Server $server) {
53
-		$this->server = $server;
54
-		$this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1);
55
-		$this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1);
56
-		$server->on('propFind', [$this, 'propFind']);
57
-		$server->on('validateTokens', [$this, 'validateTokens']);
58
-	}
51
+    /** {@inheritDoc} */
52
+    public function initialize(\Sabre\DAV\Server $server) {
53
+        $this->server = $server;
54
+        $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1);
55
+        $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1);
56
+        $server->on('propFind', [$this, 'propFind']);
57
+        $server->on('validateTokens', [$this, 'validateTokens']);
58
+    }
59 59
 
60
-	/**
61
-	 * Indicate that we support LOCK and UNLOCK
62
-	 *
63
-	 * @param string $path
64
-	 * @return string[]
65
-	 */
66
-	public function getHTTPMethods($path) {
67
-		return [
68
-			'LOCK',
69
-			'UNLOCK',
70
-		];
71
-	}
60
+    /**
61
+     * Indicate that we support LOCK and UNLOCK
62
+     *
63
+     * @param string $path
64
+     * @return string[]
65
+     */
66
+    public function getHTTPMethods($path) {
67
+        return [
68
+            'LOCK',
69
+            'UNLOCK',
70
+        ];
71
+    }
72 72
 
73
-	/**
74
-	 * Indicate that we support locking
75
-	 *
76
-	 * @return integer[]
77
-	 */
78
-	function getFeatures() {
79
-		return [2];
80
-	}
73
+    /**
74
+     * Indicate that we support locking
75
+     *
76
+     * @return integer[]
77
+     */
78
+    function getFeatures() {
79
+        return [2];
80
+    }
81 81
 
82
-	/**
83
-	 * Return some dummy response for PROPFIND requests with regard to locking
84
-	 *
85
-	 * @param PropFind $propFind
86
-	 * @param INode $node
87
-	 * @return void
88
-	 */
89
-	function propFind(PropFind $propFind, INode $node) {
90
-		$propFind->handle('{DAV:}supportedlock', function() {
91
-			return new SupportedLock(true);
92
-		});
93
-		$propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) {
94
-			return new LockDiscovery([]);
95
-		});
96
-	}
82
+    /**
83
+     * Return some dummy response for PROPFIND requests with regard to locking
84
+     *
85
+     * @param PropFind $propFind
86
+     * @param INode $node
87
+     * @return void
88
+     */
89
+    function propFind(PropFind $propFind, INode $node) {
90
+        $propFind->handle('{DAV:}supportedlock', function() {
91
+            return new SupportedLock(true);
92
+        });
93
+        $propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) {
94
+            return new LockDiscovery([]);
95
+        });
96
+    }
97 97
 
98
-	/**
99
-	 * Mark a locking token always as valid
100
-	 *
101
-	 * @param RequestInterface $request
102
-	 * @param array $conditions
103
-	 */
104
-	public function validateTokens(RequestInterface $request, &$conditions) {
105
-		foreach($conditions as &$fileCondition) {
106
-			if(isset($fileCondition['tokens'])) {
107
-				foreach($fileCondition['tokens'] as &$token) {
108
-					if(isset($token['token'])) {
109
-						if(substr($token['token'], 0, 16) === 'opaquelocktoken:') {
110
-							$token['validToken'] = true;
111
-						}
112
-					}
113
-				}
114
-			}
115
-		}
116
-	}
98
+    /**
99
+     * Mark a locking token always as valid
100
+     *
101
+     * @param RequestInterface $request
102
+     * @param array $conditions
103
+     */
104
+    public function validateTokens(RequestInterface $request, &$conditions) {
105
+        foreach($conditions as &$fileCondition) {
106
+            if(isset($fileCondition['tokens'])) {
107
+                foreach($fileCondition['tokens'] as &$token) {
108
+                    if(isset($token['token'])) {
109
+                        if(substr($token['token'], 0, 16) === 'opaquelocktoken:') {
110
+                            $token['validToken'] = true;
111
+                        }
112
+                    }
113
+                }
114
+            }
115
+        }
116
+    }
117 117
 
118
-	/**
119
-	 * Fakes a successful LOCK
120
-	 *
121
-	 * @param RequestInterface $request
122
-	 * @param ResponseInterface $response
123
-	 * @return bool
124
-	 */
125
-	public function fakeLockProvider(RequestInterface $request,
126
-									 ResponseInterface $response) {
118
+    /**
119
+     * Fakes a successful LOCK
120
+     *
121
+     * @param RequestInterface $request
122
+     * @param ResponseInterface $response
123
+     * @return bool
124
+     */
125
+    public function fakeLockProvider(RequestInterface $request,
126
+                                        ResponseInterface $response) {
127 127
 
128
-		$lockInfo = new LockInfo();
129
-		$lockInfo->token = md5($request->getPath());
130
-		$lockInfo->uri = $request->getPath();
131
-		$lockInfo->depth = \Sabre\DAV\Server::DEPTH_INFINITY;
132
-		$lockInfo->timeout = 1800;
128
+        $lockInfo = new LockInfo();
129
+        $lockInfo->token = md5($request->getPath());
130
+        $lockInfo->uri = $request->getPath();
131
+        $lockInfo->depth = \Sabre\DAV\Server::DEPTH_INFINITY;
132
+        $lockInfo->timeout = 1800;
133 133
 
134
-		$body = $this->server->xml->write('{DAV:}prop', [
135
-				'{DAV:}lockdiscovery' =>
136
-						new LockDiscovery([$lockInfo])
137
-		]);
134
+        $body = $this->server->xml->write('{DAV:}prop', [
135
+                '{DAV:}lockdiscovery' =>
136
+                        new LockDiscovery([$lockInfo])
137
+        ]);
138 138
 
139
-		$response->setStatus(200);
140
-		$response->setBody($body);
139
+        $response->setStatus(200);
140
+        $response->setBody($body);
141 141
 
142
-		return false;
143
-	}
142
+        return false;
143
+    }
144 144
 
145
-	/**
146
-	 * Fakes a successful LOCK
147
-	 *
148
-	 * @param RequestInterface $request
149
-	 * @param ResponseInterface $response
150
-	 * @return bool
151
-	 */
152
-	public function fakeUnlockProvider(RequestInterface $request,
153
-									 ResponseInterface $response) {
154
-		$response->setStatus(204);
155
-		$response->setHeader('Content-Length', '0');
156
-		return false;
157
-	}
145
+    /**
146
+     * Fakes a successful LOCK
147
+     *
148
+     * @param RequestInterface $request
149
+     * @param ResponseInterface $response
150
+     * @return bool
151
+     */
152
+    public function fakeUnlockProvider(RequestInterface $request,
153
+                                        ResponseInterface $response) {
154
+        $response->setStatus(204);
155
+        $response->setHeader('Content-Length', '0');
156
+        return false;
157
+    }
158 158
 }
Please login to merge, or discard this patch.
lib/public/Files/Search/ISearchQuery.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -27,41 +27,41 @@
 block discarded – undo
27 27
  * @since 12.0.0
28 28
  */
29 29
 interface ISearchQuery {
30
-	/**
31
-	 * @return ISearchOperator
32
-	 * @since 12.0.0
33
-	 */
34
-	public function getSearchOperation();
30
+    /**
31
+     * @return ISearchOperator
32
+     * @since 12.0.0
33
+     */
34
+    public function getSearchOperation();
35 35
 
36
-	/**
37
-	 * Get the maximum number of results to return
38
-	 *
39
-	 * @return integer
40
-	 * @since 12.0.0
41
-	 */
42
-	public function getLimit();
36
+    /**
37
+     * Get the maximum number of results to return
38
+     *
39
+     * @return integer
40
+     * @since 12.0.0
41
+     */
42
+    public function getLimit();
43 43
 
44
-	/**
45
-	 * Get the offset for returned results
46
-	 *
47
-	 * @return integer
48
-	 * @since 12.0.0
49
-	 */
50
-	public function getOffset();
44
+    /**
45
+     * Get the offset for returned results
46
+     *
47
+     * @return integer
48
+     * @since 12.0.0
49
+     */
50
+    public function getOffset();
51 51
 
52
-	/**
53
-	 * The fields and directions to order by
54
-	 *
55
-	 * @return ISearchOrder[]
56
-	 * @since 12.0.0
57
-	 */
58
-	public function getOrder();
52
+    /**
53
+     * The fields and directions to order by
54
+     *
55
+     * @return ISearchOrder[]
56
+     * @since 12.0.0
57
+     */
58
+    public function getOrder();
59 59
 
60
-	/**
61
-	 * The user that issued the search
62
-	 *
63
-	 * @return IUser
64
-	 * @since 12.0.0
65
-	 */
66
-	public function getUser();
60
+    /**
61
+     * The user that issued the search
62
+     *
63
+     * @return IUser
64
+     * @since 12.0.0
65
+     */
66
+    public function getUser();
67 67
 }
Please login to merge, or discard this patch.
lib/private/Files/Search/SearchQuery.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -27,66 +27,66 @@
 block discarded – undo
27 27
 use OCP\IUser;
28 28
 
29 29
 class SearchQuery implements ISearchQuery {
30
-	/** @var  ISearchOperator */
31
-	private $searchOperation;
32
-	/** @var  integer */
33
-	private $limit;
34
-	/** @var  integer */
35
-	private $offset;
36
-	/** @var  ISearchOrder[] */
37
-	private $order;
38
-	/** @var IUser */
39
-	private $user;
30
+    /** @var  ISearchOperator */
31
+    private $searchOperation;
32
+    /** @var  integer */
33
+    private $limit;
34
+    /** @var  integer */
35
+    private $offset;
36
+    /** @var  ISearchOrder[] */
37
+    private $order;
38
+    /** @var IUser */
39
+    private $user;
40 40
 
41
-	/**
42
-	 * SearchQuery constructor.
43
-	 *
44
-	 * @param ISearchOperator $searchOperation
45
-	 * @param int $limit
46
-	 * @param int $offset
47
-	 * @param array $order
48
-	 * @param IUser $user
49
-	 */
50
-	public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order, IUser $user) {
51
-		$this->searchOperation = $searchOperation;
52
-		$this->limit = $limit;
53
-		$this->offset = $offset;
54
-		$this->order = $order;
55
-		$this->user = $user;
56
-	}
41
+    /**
42
+     * SearchQuery constructor.
43
+     *
44
+     * @param ISearchOperator $searchOperation
45
+     * @param int $limit
46
+     * @param int $offset
47
+     * @param array $order
48
+     * @param IUser $user
49
+     */
50
+    public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order, IUser $user) {
51
+        $this->searchOperation = $searchOperation;
52
+        $this->limit = $limit;
53
+        $this->offset = $offset;
54
+        $this->order = $order;
55
+        $this->user = $user;
56
+    }
57 57
 
58
-	/**
59
-	 * @return ISearchOperator
60
-	 */
61
-	public function getSearchOperation() {
62
-		return $this->searchOperation;
63
-	}
58
+    /**
59
+     * @return ISearchOperator
60
+     */
61
+    public function getSearchOperation() {
62
+        return $this->searchOperation;
63
+    }
64 64
 
65
-	/**
66
-	 * @return int
67
-	 */
68
-	public function getLimit() {
69
-		return $this->limit;
70
-	}
65
+    /**
66
+     * @return int
67
+     */
68
+    public function getLimit() {
69
+        return $this->limit;
70
+    }
71 71
 
72
-	/**
73
-	 * @return int
74
-	 */
75
-	public function getOffset() {
76
-		return $this->offset;
77
-	}
72
+    /**
73
+     * @return int
74
+     */
75
+    public function getOffset() {
76
+        return $this->offset;
77
+    }
78 78
 
79
-	/**
80
-	 * @return ISearchOrder[]
81
-	 */
82
-	public function getOrder() {
83
-		return $this->order;
84
-	}
79
+    /**
80
+     * @return ISearchOrder[]
81
+     */
82
+    public function getOrder() {
83
+        return $this->order;
84
+    }
85 85
 
86
-	/**
87
-	 * @return IUser
88
-	 */
89
-	public function getUser() {
90
-		return $this->user;
91
-	}
86
+    /**
87
+     * @return IUser
88
+     */
89
+    public function getUser() {
90
+        return $this->user;
91
+    }
92 92
 }
Please login to merge, or discard this patch.
lib/private/OCS/Provider.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -24,92 +24,92 @@
 block discarded – undo
24 24
 namespace OC\OCS;
25 25
 
26 26
 class Provider extends \OCP\AppFramework\Controller {
27
-	/** @var \OCP\App\IAppManager */
28
-	private $appManager;
27
+    /** @var \OCP\App\IAppManager */
28
+    private $appManager;
29 29
 
30
-	/**
31
-	 * @param string $appName
32
-	 * @param \OCP\IRequest $request
33
-	 * @param \OCP\App\IAppManager $appManager
34
-	 */
35
-	public function __construct($appName,
36
-								\OCP\IRequest $request,
37
-								\OCP\App\IAppManager $appManager) {
38
-		parent::__construct($appName, $request);
39
-		$this->appManager = $appManager;
40
-	}
30
+    /**
31
+     * @param string $appName
32
+     * @param \OCP\IRequest $request
33
+     * @param \OCP\App\IAppManager $appManager
34
+     */
35
+    public function __construct($appName,
36
+                                \OCP\IRequest $request,
37
+                                \OCP\App\IAppManager $appManager) {
38
+        parent::__construct($appName, $request);
39
+        $this->appManager = $appManager;
40
+    }
41 41
 
42
-	/**
43
-	 * @return \OCP\AppFramework\Http\JSONResponse
44
-	 */
45
-	public function buildProviderList() {
46
-		$services = [
47
-			'PRIVATE_DATA' => [
48
-				'version' => 1,
49
-				'endpoints' => [
50
-					'store' => '/ocs/v2.php/privatedata/setattribute',
51
-					'read' => '/ocs/v2.php/privatedata/getattribute',
52
-					'delete' => '/ocs/v2.php/privatedata/deleteattribute',
53
-				],
54
-			],
55
-		];
42
+    /**
43
+     * @return \OCP\AppFramework\Http\JSONResponse
44
+     */
45
+    public function buildProviderList() {
46
+        $services = [
47
+            'PRIVATE_DATA' => [
48
+                'version' => 1,
49
+                'endpoints' => [
50
+                    'store' => '/ocs/v2.php/privatedata/setattribute',
51
+                    'read' => '/ocs/v2.php/privatedata/getattribute',
52
+                    'delete' => '/ocs/v2.php/privatedata/deleteattribute',
53
+                ],
54
+            ],
55
+        ];
56 56
 
57
-		if($this->appManager->isEnabledForUser('files_sharing')) {
58
-			$services['SHARING'] = [
59
-				'version' => 1,
60
-				'endpoints' => [
61
-					'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
62
-				],
63
-			];
64
-			$services['FEDERATED_SHARING'] = [
65
-				'version' => 1,
66
-				'endpoints' => [
67
-					'share' => '/ocs/v2.php/cloud/shares',
68
-					'webdav' => '/public.php/webdav/',
69
-				],
70
-			];
71
-		}
57
+        if($this->appManager->isEnabledForUser('files_sharing')) {
58
+            $services['SHARING'] = [
59
+                'version' => 1,
60
+                'endpoints' => [
61
+                    'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares',
62
+                ],
63
+            ];
64
+            $services['FEDERATED_SHARING'] = [
65
+                'version' => 1,
66
+                'endpoints' => [
67
+                    'share' => '/ocs/v2.php/cloud/shares',
68
+                    'webdav' => '/public.php/webdav/',
69
+                ],
70
+            ];
71
+        }
72 72
 
73
-		if ($this->appManager->isEnabledForUser('federation')) {
74
-			if (isset($services['FEDERATED_SHARING'])) {
75
-				$services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
76
-				$services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
77
-				$services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
78
-			} else {
79
-				$services['FEDERATED_SHARING'] = [
80
-					'version' => 1,
81
-					'endpoints' => [
82
-						'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
83
-						'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
84
-						'carddav-user' => 'system'
85
-					],
86
-				];
87
-			}
88
-		}
73
+        if ($this->appManager->isEnabledForUser('federation')) {
74
+            if (isset($services['FEDERATED_SHARING'])) {
75
+                $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret';
76
+                $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system';
77
+                $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system';
78
+            } else {
79
+                $services['FEDERATED_SHARING'] = [
80
+                    'version' => 1,
81
+                    'endpoints' => [
82
+                        'shared-secret' => '/ocs/v2.php/cloud/shared-secret',
83
+                        'system-address-book' => '/remote.php/dav/addressbooks/system/system/system',
84
+                        'carddav-user' => 'system'
85
+                    ],
86
+                ];
87
+            }
88
+        }
89 89
 
90
-		if($this->appManager->isEnabledForUser('activity')) {
91
-			$services['ACTIVITY'] = [
92
-				'version' => 1,
93
-				'endpoints' => [
94
-					'list' => '/ocs/v2.php/cloud/activity',
95
-				],
96
-			];
97
-		}
90
+        if($this->appManager->isEnabledForUser('activity')) {
91
+            $services['ACTIVITY'] = [
92
+                'version' => 1,
93
+                'endpoints' => [
94
+                    'list' => '/ocs/v2.php/cloud/activity',
95
+                ],
96
+            ];
97
+        }
98 98
 
99
-		if($this->appManager->isEnabledForUser('provisioning_api')) {
100
-			$services['PROVISIONING'] = [
101
-				'version' => 1,
102
-				'endpoints' => [
103
-					'user' => '/ocs/v2.php/cloud/users',
104
-					'groups' => '/ocs/v2.php/cloud/groups',
105
-					'apps' => '/ocs/v2.php/cloud/apps',
106
-				],
107
-			];
108
-		}
99
+        if($this->appManager->isEnabledForUser('provisioning_api')) {
100
+            $services['PROVISIONING'] = [
101
+                'version' => 1,
102
+                'endpoints' => [
103
+                    'user' => '/ocs/v2.php/cloud/users',
104
+                    'groups' => '/ocs/v2.php/cloud/groups',
105
+                    'apps' => '/ocs/v2.php/cloud/apps',
106
+                ],
107
+            ];
108
+        }
109 109
 
110
-		return new \OCP\AppFramework\Http\JSONResponse([
111
-			'version' => 2,
112
-			'services' => $services,
113
-		]);
114
-	}
110
+        return new \OCP\AppFramework\Http\JSONResponse([
111
+            'version' => 2,
112
+            'services' => $services,
113
+        ]);
114
+    }
115 115
 }
Please login to merge, or discard this patch.
lib/private/Preview/MP3.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -29,38 +29,38 @@
 block discarded – undo
29 29
 use ID3Parser\ID3Parser;
30 30
 
31 31
 class MP3 extends Provider {
32
-	/**
33
-	 * {@inheritDoc}
34
-	 */
35
-	public function getMimeType() {
36
-		return '/audio\/mpeg/';
37
-	}
32
+    /**
33
+     * {@inheritDoc}
34
+     */
35
+    public function getMimeType() {
36
+        return '/audio\/mpeg/';
37
+    }
38 38
 
39
-	/**
40
-	 * {@inheritDoc}
41
-	 */
42
-	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
43
-		$getID3 = new ID3Parser();
39
+    /**
40
+     * {@inheritDoc}
41
+     */
42
+    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
43
+        $getID3 = new ID3Parser();
44 44
 
45
-		$tmpPath = $fileview->toTmpFile($path);
46
-		$tags = $getID3->analyze($tmpPath);
47
-		unlink($tmpPath);
48
-		$picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
49
-		if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
50
-			$picture = $tags['id3v2']['PIC'][0]['data'];
51
-		}
45
+        $tmpPath = $fileview->toTmpFile($path);
46
+        $tags = $getID3->analyze($tmpPath);
47
+        unlink($tmpPath);
48
+        $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
49
+        if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
50
+            $picture = $tags['id3v2']['PIC'][0]['data'];
51
+        }
52 52
 
53
-		if(!is_null($picture)) {
54
-			$image = new \OC_Image();
55
-			$image->loadFromData($picture);
53
+        if(!is_null($picture)) {
54
+            $image = new \OC_Image();
55
+            $image->loadFromData($picture);
56 56
 
57
-			if ($image->valid()) {
58
-				$image->scaleDownToFit($maxX, $maxY);
57
+            if ($image->valid()) {
58
+                $image->scaleDownToFit($maxX, $maxY);
59 59
 
60
-				return $image;
61
-			}
62
-		}
60
+                return $image;
61
+            }
62
+        }
63 63
 
64
-		return false;
65
-	}
64
+        return false;
65
+    }
66 66
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/appinfo/routes.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@
 block discarded – undo
23 23
  */
24 24
 
25 25
 return [
26
-	'routes' => [
27
-		['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
-		['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
-	],
30
-	'ocs' => [
31
-		['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
-		['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
-		['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
-		['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
-		['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
-		['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
-		['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
-		['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'],
39
-	],
26
+    'routes' => [
27
+        ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
+        ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
+    ],
30
+    'ocs' => [
31
+        ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
+        ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
+        ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
+        ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
+        ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
+        ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
+        ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
+        ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'],
39
+    ],
40 40
 ];
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Notifications.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -33,280 +33,280 @@
 block discarded – undo
33 33
 use OCP\OCS\IDiscoveryService;
34 34
 
35 35
 class Notifications {
36
-	const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
37
-
38
-	/** @var AddressHandler */
39
-	private $addressHandler;
40
-
41
-	/** @var IClientService */
42
-	private $httpClientService;
43
-
44
-	/** @var IDiscoveryService */
45
-	private $discoveryService;
46
-
47
-	/** @var IJobList  */
48
-	private $jobList;
49
-
50
-	/**
51
-	 * @param AddressHandler $addressHandler
52
-	 * @param IClientService $httpClientService
53
-	 * @param IDiscoveryService $discoveryService
54
-	 * @param IJobList $jobList
55
-	 */
56
-	public function __construct(
57
-		AddressHandler $addressHandler,
58
-		IClientService $httpClientService,
59
-		IDiscoveryService $discoveryService,
60
-		IJobList $jobList
61
-	) {
62
-		$this->addressHandler = $addressHandler;
63
-		$this->httpClientService = $httpClientService;
64
-		$this->discoveryService = $discoveryService;
65
-		$this->jobList = $jobList;
66
-	}
67
-
68
-	/**
69
-	 * send server-to-server share to remote server
70
-	 *
71
-	 * @param string $token
72
-	 * @param string $shareWith
73
-	 * @param string $name
74
-	 * @param int $remote_id
75
-	 * @param string $owner
76
-	 * @param string $ownerFederatedId
77
-	 * @param string $sharedBy
78
-	 * @param string $sharedByFederatedId
79
-	 * @return bool
80
-	 * @throws \OC\HintException
81
-	 * @throws \OC\ServerNotAvailableException
82
-	 */
83
-	public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) {
84
-
85
-		list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
86
-
87
-		if ($user && $remote) {
88
-			$local = $this->addressHandler->generateRemoteURL();
89
-
90
-			$fields = array(
91
-				'shareWith' => $user,
92
-				'token' => $token,
93
-				'name' => $name,
94
-				'remoteId' => $remote_id,
95
-				'owner' => $owner,
96
-				'ownerFederatedId' => $ownerFederatedId,
97
-				'sharedBy' => $sharedBy,
98
-				'sharedByFederatedId' => $sharedByFederatedId,
99
-				'remote' => $local,
100
-			);
101
-
102
-			$result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
103
-			$status = json_decode($result['result'], true);
104
-
105
-			if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
106
-				\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
107
-				return true;
108
-			}
109
-
110
-		}
111
-
112
-		return false;
113
-	}
114
-
115
-	/**
116
-	 * ask owner to re-share the file with the given user
117
-	 *
118
-	 * @param string $token
119
-	 * @param int $id remote Id
120
-	 * @param int $shareId internal share Id
121
-	 * @param string $remote remote address of the owner
122
-	 * @param string $shareWith
123
-	 * @param int $permission
124
-	 * @return bool
125
-	 * @throws \OC\HintException
126
-	 * @throws \OC\ServerNotAvailableException
127
-	 */
128
-	public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) {
129
-
130
-		$fields = array(
131
-			'shareWith' => $shareWith,
132
-			'token' => $token,
133
-			'permission' => $permission,
134
-			'remoteId' => $shareId
135
-		);
136
-
137
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
138
-		$status = json_decode($result['result'], true);
139
-
140
-		$httpRequestSuccessful = $result['success'];
141
-		$ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
142
-		$validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
143
-		$validRemoteId = isset($status['ocs']['data']['remoteId']);
144
-
145
-		if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
146
-			return [
147
-				$status['ocs']['data']['token'],
148
-				(int)$status['ocs']['data']['remoteId']
149
-			];
150
-		}
151
-
152
-		return false;
153
-	}
154
-
155
-	/**
156
-	 * send server-to-server unshare to remote server
157
-	 *
158
-	 * @param string $remote url
159
-	 * @param int $id share id
160
-	 * @param string $token
161
-	 * @return bool
162
-	 */
163
-	public function sendRemoteUnShare($remote, $id, $token) {
164
-		$this->sendUpdateToRemote($remote, $id, $token, 'unshare');
165
-	}
166
-
167
-	/**
168
-	 * send server-to-server unshare to remote server
169
-	 *
170
-	 * @param string $remote url
171
-	 * @param int $id share id
172
-	 * @param string $token
173
-	 * @return bool
174
-	 */
175
-	public function sendRevokeShare($remote, $id, $token) {
176
-		$this->sendUpdateToRemote($remote, $id, $token, 'revoke');
177
-	}
178
-
179
-	/**
180
-	 * send notification to remote server if the permissions was changed
181
-	 *
182
-	 * @param string $remote
183
-	 * @param int $remoteId
184
-	 * @param string $token
185
-	 * @param int $permissions
186
-	 * @return bool
187
-	 */
188
-	public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
189
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
190
-	}
191
-
192
-	/**
193
-	 * forward accept reShare to remote server
194
-	 *
195
-	 * @param string $remote
196
-	 * @param int $remoteId
197
-	 * @param string $token
198
-	 */
199
-	public function sendAcceptShare($remote, $remoteId, $token) {
200
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
201
-	}
202
-
203
-	/**
204
-	 * forward decline reShare to remote server
205
-	 *
206
-	 * @param string $remote
207
-	 * @param int $remoteId
208
-	 * @param string $token
209
-	 */
210
-	public function sendDeclineShare($remote, $remoteId, $token) {
211
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
212
-	}
213
-
214
-	/**
215
-	 * inform remote server whether server-to-server share was accepted/declined
216
-	 *
217
-	 * @param string $remote
218
-	 * @param string $token
219
-	 * @param int $remoteId Share id on the remote host
220
-	 * @param string $action possible actions: accept, decline, unshare, revoke, permissions
221
-	 * @param array $data
222
-	 * @param int $try
223
-	 * @return boolean
224
-	 */
225
-	public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
226
-
227
-		$fields = array('token' => $token);
228
-		foreach ($data as $key => $value) {
229
-			$fields[$key] = $value;
230
-		}
231
-
232
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields);
233
-		$status = json_decode($result['result'], true);
234
-
235
-		if ($result['success'] &&
236
-			($status['ocs']['meta']['statuscode'] === 100 ||
237
-				$status['ocs']['meta']['statuscode'] === 200
238
-			)
239
-		) {
240
-			return true;
241
-		} elseif ($try === 0) {
242
-			// only add new job on first try
243
-			$this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
244
-				[
245
-					'remote' => $remote,
246
-					'remoteId' => $remoteId,
247
-					'token' => $token,
248
-					'action' => $action,
249
-					'data' => json_encode($data),
250
-					'try' => $try,
251
-					'lastRun' => $this->getTimestamp()
252
-				]
253
-			);
254
-		}
255
-
256
-		return false;
257
-	}
258
-
259
-
260
-	/**
261
-	 * return current timestamp
262
-	 *
263
-	 * @return int
264
-	 */
265
-	protected function getTimestamp() {
266
-		return time();
267
-	}
268
-
269
-	/**
270
-	 * try http post with the given protocol, if no protocol is given we pick
271
-	 * the secure one (https)
272
-	 *
273
-	 * @param string $remoteDomain
274
-	 * @param string $urlSuffix
275
-	 * @param array $fields post parameters
276
-	 * @return array
277
-	 * @throws \Exception
278
-	 */
279
-	protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
280
-		$client = $this->httpClientService->newClient();
281
-
282
-		if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
283
-			$remoteDomain = 'https://' . $remoteDomain;
284
-		}
285
-
286
-		$result = [
287
-			'success' => false,
288
-			'result' => '',
289
-		];
290
-
291
-		$federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
292
-		$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
293
-		try {
294
-			$response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
295
-				'body' => $fields,
296
-				'timeout' => 10,
297
-				'connect_timeout' => 10,
298
-			]);
299
-			$result['result'] = $response->getBody();
300
-			$result['success'] = true;
301
-		} catch (\Exception $e) {
302
-			// if flat re-sharing is not supported by the remote server
303
-			// we re-throw the exception and fall back to the old behaviour.
304
-			// (flat re-shares has been introduced in Nextcloud 9.1)
305
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
306
-				throw $e;
307
-			}
308
-		}
309
-
310
-		return $result;
311
-	}
36
+    const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
37
+
38
+    /** @var AddressHandler */
39
+    private $addressHandler;
40
+
41
+    /** @var IClientService */
42
+    private $httpClientService;
43
+
44
+    /** @var IDiscoveryService */
45
+    private $discoveryService;
46
+
47
+    /** @var IJobList  */
48
+    private $jobList;
49
+
50
+    /**
51
+     * @param AddressHandler $addressHandler
52
+     * @param IClientService $httpClientService
53
+     * @param IDiscoveryService $discoveryService
54
+     * @param IJobList $jobList
55
+     */
56
+    public function __construct(
57
+        AddressHandler $addressHandler,
58
+        IClientService $httpClientService,
59
+        IDiscoveryService $discoveryService,
60
+        IJobList $jobList
61
+    ) {
62
+        $this->addressHandler = $addressHandler;
63
+        $this->httpClientService = $httpClientService;
64
+        $this->discoveryService = $discoveryService;
65
+        $this->jobList = $jobList;
66
+    }
67
+
68
+    /**
69
+     * send server-to-server share to remote server
70
+     *
71
+     * @param string $token
72
+     * @param string $shareWith
73
+     * @param string $name
74
+     * @param int $remote_id
75
+     * @param string $owner
76
+     * @param string $ownerFederatedId
77
+     * @param string $sharedBy
78
+     * @param string $sharedByFederatedId
79
+     * @return bool
80
+     * @throws \OC\HintException
81
+     * @throws \OC\ServerNotAvailableException
82
+     */
83
+    public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) {
84
+
85
+        list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
86
+
87
+        if ($user && $remote) {
88
+            $local = $this->addressHandler->generateRemoteURL();
89
+
90
+            $fields = array(
91
+                'shareWith' => $user,
92
+                'token' => $token,
93
+                'name' => $name,
94
+                'remoteId' => $remote_id,
95
+                'owner' => $owner,
96
+                'ownerFederatedId' => $ownerFederatedId,
97
+                'sharedBy' => $sharedBy,
98
+                'sharedByFederatedId' => $sharedByFederatedId,
99
+                'remote' => $local,
100
+            );
101
+
102
+            $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
103
+            $status = json_decode($result['result'], true);
104
+
105
+            if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
106
+                \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
107
+                return true;
108
+            }
109
+
110
+        }
111
+
112
+        return false;
113
+    }
114
+
115
+    /**
116
+     * ask owner to re-share the file with the given user
117
+     *
118
+     * @param string $token
119
+     * @param int $id remote Id
120
+     * @param int $shareId internal share Id
121
+     * @param string $remote remote address of the owner
122
+     * @param string $shareWith
123
+     * @param int $permission
124
+     * @return bool
125
+     * @throws \OC\HintException
126
+     * @throws \OC\ServerNotAvailableException
127
+     */
128
+    public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) {
129
+
130
+        $fields = array(
131
+            'shareWith' => $shareWith,
132
+            'token' => $token,
133
+            'permission' => $permission,
134
+            'remoteId' => $shareId
135
+        );
136
+
137
+        $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
138
+        $status = json_decode($result['result'], true);
139
+
140
+        $httpRequestSuccessful = $result['success'];
141
+        $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
142
+        $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
143
+        $validRemoteId = isset($status['ocs']['data']['remoteId']);
144
+
145
+        if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
146
+            return [
147
+                $status['ocs']['data']['token'],
148
+                (int)$status['ocs']['data']['remoteId']
149
+            ];
150
+        }
151
+
152
+        return false;
153
+    }
154
+
155
+    /**
156
+     * send server-to-server unshare to remote server
157
+     *
158
+     * @param string $remote url
159
+     * @param int $id share id
160
+     * @param string $token
161
+     * @return bool
162
+     */
163
+    public function sendRemoteUnShare($remote, $id, $token) {
164
+        $this->sendUpdateToRemote($remote, $id, $token, 'unshare');
165
+    }
166
+
167
+    /**
168
+     * send server-to-server unshare to remote server
169
+     *
170
+     * @param string $remote url
171
+     * @param int $id share id
172
+     * @param string $token
173
+     * @return bool
174
+     */
175
+    public function sendRevokeShare($remote, $id, $token) {
176
+        $this->sendUpdateToRemote($remote, $id, $token, 'revoke');
177
+    }
178
+
179
+    /**
180
+     * send notification to remote server if the permissions was changed
181
+     *
182
+     * @param string $remote
183
+     * @param int $remoteId
184
+     * @param string $token
185
+     * @param int $permissions
186
+     * @return bool
187
+     */
188
+    public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
189
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
190
+    }
191
+
192
+    /**
193
+     * forward accept reShare to remote server
194
+     *
195
+     * @param string $remote
196
+     * @param int $remoteId
197
+     * @param string $token
198
+     */
199
+    public function sendAcceptShare($remote, $remoteId, $token) {
200
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
201
+    }
202
+
203
+    /**
204
+     * forward decline reShare to remote server
205
+     *
206
+     * @param string $remote
207
+     * @param int $remoteId
208
+     * @param string $token
209
+     */
210
+    public function sendDeclineShare($remote, $remoteId, $token) {
211
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
212
+    }
213
+
214
+    /**
215
+     * inform remote server whether server-to-server share was accepted/declined
216
+     *
217
+     * @param string $remote
218
+     * @param string $token
219
+     * @param int $remoteId Share id on the remote host
220
+     * @param string $action possible actions: accept, decline, unshare, revoke, permissions
221
+     * @param array $data
222
+     * @param int $try
223
+     * @return boolean
224
+     */
225
+    public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
226
+
227
+        $fields = array('token' => $token);
228
+        foreach ($data as $key => $value) {
229
+            $fields[$key] = $value;
230
+        }
231
+
232
+        $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields);
233
+        $status = json_decode($result['result'], true);
234
+
235
+        if ($result['success'] &&
236
+            ($status['ocs']['meta']['statuscode'] === 100 ||
237
+                $status['ocs']['meta']['statuscode'] === 200
238
+            )
239
+        ) {
240
+            return true;
241
+        } elseif ($try === 0) {
242
+            // only add new job on first try
243
+            $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
244
+                [
245
+                    'remote' => $remote,
246
+                    'remoteId' => $remoteId,
247
+                    'token' => $token,
248
+                    'action' => $action,
249
+                    'data' => json_encode($data),
250
+                    'try' => $try,
251
+                    'lastRun' => $this->getTimestamp()
252
+                ]
253
+            );
254
+        }
255
+
256
+        return false;
257
+    }
258
+
259
+
260
+    /**
261
+     * return current timestamp
262
+     *
263
+     * @return int
264
+     */
265
+    protected function getTimestamp() {
266
+        return time();
267
+    }
268
+
269
+    /**
270
+     * try http post with the given protocol, if no protocol is given we pick
271
+     * the secure one (https)
272
+     *
273
+     * @param string $remoteDomain
274
+     * @param string $urlSuffix
275
+     * @param array $fields post parameters
276
+     * @return array
277
+     * @throws \Exception
278
+     */
279
+    protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
280
+        $client = $this->httpClientService->newClient();
281
+
282
+        if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
283
+            $remoteDomain = 'https://' . $remoteDomain;
284
+        }
285
+
286
+        $result = [
287
+            'success' => false,
288
+            'result' => '',
289
+        ];
290
+
291
+        $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
292
+        $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
293
+        try {
294
+            $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
295
+                'body' => $fields,
296
+                'timeout' => 10,
297
+                'connect_timeout' => 10,
298
+            ]);
299
+            $result['result'] = $response->getBody();
300
+            $result['success'] = true;
301
+        } catch (\Exception $e) {
302
+            // if flat re-sharing is not supported by the remote server
303
+            // we re-throw the exception and fall back to the old behaviour.
304
+            // (flat re-shares has been introduced in Nextcloud 9.1)
305
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
306
+                throw $e;
307
+            }
308
+        }
309
+
310
+        return $result;
311
+    }
312 312
 }
Please login to merge, or discard this patch.
apps/dav/appinfo/v2/remote.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
  */
22 22
 // no php execution timeout for webdav
23 23
 if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
24
-	@set_time_limit(0);
24
+    @set_time_limit(0);
25 25
 }
26 26
 ignore_user_abort(true);
27 27
 
Please login to merge, or discard this patch.