OCCommunication.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. //
  2. // OCCommunication.h
  3. // Owncloud iOs Client
  4. //
  5. // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. //
  24. // Add : getNotificationServer & setNotificationServer
  25. // Add : getUserProfileServer
  26. // Add : Support for Favorite
  27. // Add : getActivityServer
  28. //
  29. // Author Marino Faggiana <m.faggiana@twsweb.it>
  30. // Copyright (c) 2017 TWS. All rights reserved.
  31. //
  32. #import <Foundation/Foundation.h>
  33. @class OCHTTPRequestOperation;
  34. @class AFURLSessionManager;
  35. @class AFSecurityPolicy;
  36. @class OCCapabilities;
  37. @class OCUserProfile;
  38. @interface OCCommunication : NSObject
  39. //Type of credential
  40. typedef enum {
  41. credentialNotSet = -1,
  42. credentialNormal = 0, //user, password
  43. credentialCookie = 1,
  44. credentialOauth = 2
  45. } kindOfCredentialEnum;
  46. typedef enum {
  47. OCErrorUnknow = 90, //On all errors
  48. OCErrorForbidenCharacters = 100, //On create folder and rename
  49. OCErrorMovingDestinyNameHaveForbiddenCharacters = 110,//On move file or folder
  50. OCErrorMovingTheDestinyAndOriginAreTheSame = 111, //On move file or folder
  51. OCErrorMovingFolderInsideHimself = 112, //On move file or folder
  52. OCErrorFileToUploadDoesNotExist = 120 //The file that we want upload does not exist
  53. } OCErrorEnum;
  54. //Private properties
  55. @property NSInteger kindOfCredential;
  56. @property (nonatomic, strong) NSString *user;
  57. @property (nonatomic, strong) NSString *password;
  58. @property (nonatomic, strong) NSString *userAgent;
  59. //Public properties
  60. @property (nonatomic, strong) NSMutableArray *downloadTaskNetworkQueueArray;
  61. @property (nonatomic, strong) AFURLSessionManager *uploadSessionManager;
  62. @property (nonatomic, strong) AFURLSessionManager *downloadSessionManager;
  63. @property (nonatomic, strong) AFURLSessionManager *networkSessionManager;
  64. @property (nonatomic, strong) AFSecurityPolicy * securityPolicy;
  65. /*This flag control the use of cookies on the requests.
  66. -On OC6 the use of cookies limit to one request at the same time. So if we want to do several requests at the same time you should set this as NO (by default).
  67. -On OC7 we can do several requests at the same time with the same session so you can set this flag to YES.
  68. */
  69. @property BOOL isCookiesAvailable;
  70. /* This flag indicate if the server handling forbidden characters */
  71. @property BOOL isForbiddenCharactersAvailable;
  72. ///-----------------------------------
  73. /// @name Init with Upload Session Manager
  74. ///-----------------------------------
  75. /**
  76. * Method to init the OCCommunication with a AFURLSessionManager (upload session) to receive the SSL callbacks to support Self Signed servers
  77. *
  78. * @param uploadSessionManager -> AFURLSessionManager
  79. */
  80. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager;
  81. /**
  82. * Method to init the OCCommunication with a AFURLSessionManager (uploads and downloads sessions) to receive the SSL callbacks to support Self Signed servers
  83. *
  84. * @param uploadSessionManager -> AFURLSessionManager
  85. * @param downloadSessionManager -> AFURLSessionManager
  86. *
  87. */
  88. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager andDownloadSessionManager:(AFURLSessionManager *) downloadSessionManager andNetworkSessionManager:(AFURLSessionManager *) networkSessionManager;
  89. - (AFSecurityPolicy *) createSecurityPolicy;
  90. - (void)setSecurityPolicyManagers:(AFSecurityPolicy *)securityPolicy;
  91. #pragma mark - Credentials
  92. ///-----------------------------------
  93. /// @name Set Credential With User
  94. ///-----------------------------------
  95. /**
  96. * Method to set credentials with user and password
  97. *
  98. * @param user -> NSString username
  99. * @param password -> NSString password
  100. */
  101. - (void) setCredentialsWithUser:(NSString*) user andPassword:(NSString*) password;
  102. ///-----------------------------------
  103. /// @name Set Credential with cookie
  104. ///-----------------------------------
  105. /**
  106. * Method that set credentials with cookie.
  107. * Used for SAML servers.
  108. *
  109. * @param cookie -> NSString cookie string
  110. */
  111. - (void) setCredentialsWithCookie:(NSString*) cookie;
  112. ///-----------------------------------
  113. /// @name Set Credential with OAuth
  114. ///-----------------------------------
  115. /**
  116. * Method to set credentials for OAuth with token
  117. *
  118. * @param token -> NSString token
  119. */
  120. - (void) setCredentialsOauthWithToken:(NSString*) token;
  121. /**
  122. * @optional
  123. *
  124. * Method to set the user agent, in order to identify the client app to the server.
  125. *
  126. * @param userAgent -> String with the user agent. Ex. "iOS-ownCloud"
  127. */
  128. - (void) setUserAgent:(NSString *)userAgent;
  129. /*
  130. * Method to update the a request with the current credentials
  131. */
  132. - (id) getRequestWithCredentials:(id) request;
  133. #pragma mark - Network operations
  134. ///-----------------------------------
  135. /// @name Check Server
  136. ///-----------------------------------
  137. /**
  138. * Method to check if on the path exist a ownCloud server
  139. *
  140. * @param path -> NSString with the url of the server with
  141. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/
  142. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  143. *
  144. * @warning this method do not need set the Credentials before because with this method we can know the kind of authentication needed.
  145. *
  146. * @warning the "path" must not be on URL Encoding.
  147. * Ex:
  148. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/
  149. *
  150. */
  151. - (void) checkServer: (NSString *) path
  152. onCommunication:(OCCommunication *)sharedOCCommunication
  153. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  154. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  155. ///-----------------------------------
  156. /// @name createFolder
  157. ///-----------------------------------
  158. /**
  159. * Method to create a folder giving the full address where we want put the folder
  160. *
  161. * @param path -> NSString with the url where we want put the folder.
  162. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  163. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  164. *
  165. * @param isFCSupported -> From Owncloud 8.1 the forbidden characters are controller by the server except the '/'. With this flag
  166. * we controller if the server support forbbiden characters. To know that you can use "hasServerForbiddenCharactersSupport ..." request in this class.
  167. *
  168. * @warning remember that you must to set the Credentials before call this method or any other.
  169. *
  170. * @warning the "path" must not be on URL Encoding.
  171. * Ex:
  172. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Pop Music/
  173. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Pop%20Music/
  174. *
  175. * @warning the folder name must not contain the next forbidden characers: "\", "/","<",">",":",""","|","?","*"
  176. */
  177. - (void) createFolder: (NSString *) path
  178. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  179. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  180. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  181. errorBeforeRequest:(void(^)(NSError *error)) errorBeforeRequest;
  182. ///-----------------------------------
  183. /// @name moveFileOrFolder
  184. ///-----------------------------------
  185. /**
  186. * Method to move or rename a file/folder
  187. *
  188. * MOVE
  189. * @param sourcePath -> NSString with the url of the file or folder that you want move
  190. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  191. * @param destinyPath -> NSString with the new url where we cant move the file or folder
  192. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
  193. *
  194. * RENAME
  195. * @param sourcePath -> NSString with the url of the file or folder that you want move
  196. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  197. * @param destinyPath -> NSString with the new url where we cant move the file or folder
  198. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Movies
  199. *
  200. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  201. *
  202. * @param isFCSupported -> From Owncloud 8.1 the forbidden characters are controller by the server except the '/'. With this flag
  203. * we controller if the server support forbbiden characters. To know that you can use "hasServerForbiddenCharactersSupport ..." request in this class.
  204. *
  205. * @warning the move will overwritte an existing file on the destiny.
  206. *
  207. * @warning remember that you must to set the Credentials before call this method or any other.
  208. *
  209. * @warning the "sourcePath" and "destinyPath" must not be on URL Encoding.
  210. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
  211. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other%20Folder/Music
  212. *
  213. * @warning: to move a folder the "sourcePath" and "destinyPath" must end on "/" character
  214. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music/
  215. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  216. *
  217. * @warning: to move a file the "sourcePath" and "destinyPath" must not end on "/" character
  218. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music.mp3
  219. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music.mp3/
  220. */
  221. - (void) moveFileOrFolder:(NSString *)sourcePath
  222. toDestiny:(NSString *)destinyPath
  223. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  224. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectServer))successRequest
  225. failureRequest:(void (^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest
  226. errorBeforeRequest:(void (^)(NSError *error))errorBeforeRequest;
  227. ///-----------------------------------
  228. /// @name Read Folder
  229. ///-----------------------------------
  230. /**
  231. * Block to get the list of files/folders for a path
  232. *
  233. * @param path -> NSString with the url of the path
  234. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  235. *
  236. * @param token -> User Session token. To get this token you should be use "getUserSessionToken" method of UtilsFramework class
  237. * We use this token to be sure that the callbacks of the request are for the correct user. We need that when we use multiaccount.
  238. * if not you can leave as nil.
  239. *
  240. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  241. *
  242. * @warning the "path" must not be on URL Encoding.
  243. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
  244. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other%20Folder/Music
  245. *
  246. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  247. *
  248. */
  249. - (void) readFolder: (NSString *) path depth:(NSString *)depth withUserSessionToken:(NSString *)token
  250. onCommunication:(OCCommunication *)sharedOCCommunication
  251. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
  252. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
  253. ///-----------------------------------
  254. /// @name Read File
  255. ///-----------------------------------
  256. /**
  257. * Block to get the unique file/folder of a path. Used to get the properties of the file.
  258. *
  259. * @param path -> NSString with the url of the path
  260. * Ex: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Music
  261. *
  262. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  263. *
  264. * @warning the "path" must not be on URL Encoding.
  265. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
  266. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other%20Folder/Music
  267. *
  268. */
  269. - (void) readFile: (NSString *) path
  270. onCommunication:(OCCommunication *)sharedOCCommunication
  271. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest
  272. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  273. ///-----------------------------------
  274. /// @name Delete a file or a folder
  275. ///-----------------------------------
  276. /**
  277. * This method delete a file or a folder
  278. *
  279. * @param path -> NSString with the url of the file or the folder that the user want to delete
  280. * Ex:http://www.myowncloudserver.com/owncloud/remote.php/webdav/Folder
  281. *
  282. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  283. *
  284. * @warning the "path" must not be on URL Encoding.
  285. * Correct path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other Folder/Music
  286. * Wrong path: http://www.myowncloudserver.com/owncloud/remote.php/webdav/Other%20Folder/Music
  287. *
  288. * @warning remember that you must to set the Credentials before call this method or any other.
  289. *
  290. */
  291. - (void) deleteFileOrFolder:(NSString *)path
  292. onCommunication:(OCCommunication *)sharedOCCommunication
  293. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  294. failureRquest:(void (^)(NSHTTPURLResponse *resposne, NSError *error, NSString *redirectedServer))failureRequest;
  295. ///-----------------------------------
  296. /// @name Download File Session
  297. ///-----------------------------------
  298. /**
  299. * Method to download a file. All the files will be download one by one in a queue. The files download also in background when the system close the app.
  300. *
  301. * This method download a file of a path and returns blocks
  302. *
  303. * progress: get the download inputs about the progress of the download
  304. * successRequest: the download it's complete
  305. * failureRequest: the download fail
  306. *
  307. * @param NSString -> remotePath the path of the file
  308. * @param NSString -> localPath the local path where we want store the file
  309. * @param BOOL -> defaultPriority define if the priority is defined by the library (default) or not. It used to manage multiple downloads from the app.
  310. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  311. *
  312. * @return NSURLSessionDownloadTask -> You can cancel the download using this object
  313. * Ex: [downloadTask cancel]
  314. *
  315. * @warning remember that you must to set the Credentials before call this method or any other.
  316. *
  317. * @warning this method use NSURLSession only supported in iOS 7, with iOS 6 use the previous method
  318. *
  319. */
  320. - (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest;
  321. ///-----------------------------------
  322. /// @name Set Download Task Complete Block
  323. ///-----------------------------------
  324. /**
  325. *
  326. * Method to set the callbak block of the pending download background tasks.
  327. *
  328. * @param block A block object to be executed when a session task is completed. The block should be return the location where the download must be stored, and takes three arguments: the session, the download task, and location where is stored the file.
  329. *
  330. */
  331. - (void)setDownloadTaskComleteBlock: (NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block;
  332. ///-----------------------------------
  333. /// @name Set Download Task Did Get Body Data Block
  334. ///-----------------------------------
  335. /**
  336. * Sets a block that get callbacks of the NSURLDownloadSessionTask progress
  337. *
  338. * @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes four arguments: the session, the download task, the number of the bytes read, the total bytes expected to read. This block may be called multiple times, and will execute on the main thread.
  339. */
  340. - (void) setDownloadTaskDidGetBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite)) block;
  341. ///-----------------------------------
  342. /// @name Upload File
  343. ///-----------------------------------
  344. /**
  345. * Method to upload a file. All the files will be upload one by one in a queue. The files upload also in background when the system close the app.
  346. *
  347. * This method download a file of a path and returns blocks
  348. *
  349. * progress: get the download inputs about the progress of the download
  350. * successRequest: the download it's complete
  351. * failureRequest: the download fail
  352. * failureBeforeRequest: the download fail
  353. *
  354. * @param NSString -> localPath the path where is the file that we want upload
  355. * @param NSString -> remotePath the path where we want upload the file
  356. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  357. *
  358. * @return NSURLSessionUploadTask -> You can cancel the upload using this object
  359. * Ex: [uploadTask cancel]
  360. *
  361. * @warning remember that you must to set the Credentials before call this method or any other.
  362. *
  363. * @warning this method use NSURLSession only supported in iOS 7, with iOS 6 use the previous method
  364. *
  365. */
  366. - (NSURLSessionUploadTask *) uploadFileSession:(NSString *) localPath toDestiny:(NSString *) remotePath onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress successRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer, NSError *error)) failureRequest failureBeforeRequest:(void(^)(NSError *error)) failureBeforeRequest;
  367. ///-----------------------------------
  368. /// @name Set Task Did Complete Block
  369. ///-----------------------------------
  370. /**
  371. *
  372. * Method to set the callbaks block of the pending background tasks.
  373. *
  374. * @param block A block object to be executed when a session task is completed. The blockhas not return value, and takes three arguments: the session, the task, and any error that occurred in the process of executing the task.
  375. *
  376. */
  377. - (void) setTaskDidCompleteBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, NSError *error)) block;
  378. ///-----------------------------------
  379. /// @name Set Task Did Send Body Data Block
  380. ///-----------------------------------
  381. /**
  382. * Sets a block that get callbacks of the NSURLSessionTask progress
  383. *
  384. * @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes five arguments: the session, the task, the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread.
  385. */
  386. - (void) setTaskDidSendBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend)) block;
  387. ///-----------------------------------
  388. /// @name Search
  389. ///-----------------------------------
  390. - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName depth:(NSString *)depth dateLastModified:(NSString *)dateLastModified withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
  391. ///-----------------------------------
  392. /// @name Setting favorite
  393. ///-----------------------------------
  394. - (void)settingFavoriteServer:(NSString *)path andFileOrFolderPath:(NSString *)filePath favorite:(BOOL)favorite withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
  395. ///-----------------------------------
  396. /// @name Listing favorites
  397. ///-----------------------------------
  398. - (void)listingFavorites:(NSString *)path folder:(NSString *)folder withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
  399. #pragma mark - OC API Calls
  400. ///-----------------------------------
  401. /// @name getCurrentServerVersion
  402. ///-----------------------------------
  403. /**
  404. * Method to get the current version without request if this feature has been checked by other request as: getServerVersionWithPath,
  405. * hasServerShareSupport, hasServerCookiesSupport and hasServerForbiddenCharactersSupport methods
  406. *
  407. * @return serverVersion as NSString.
  408. */
  409. - (NSString *) getCurrentServerVersion;
  410. ///-----------------------------------
  411. /// @name getServerVersionWithPath
  412. ///-----------------------------------
  413. /**
  414. * Method to get the current version of a server. This method update the currentServerVersion property of the class
  415. *
  416. *
  417. * @param path -> NSString server path
  418. *
  419. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  420. *
  421. * @return serverVersion as NSString.
  422. */
  423. - (void) getServerVersionWithPath:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  424. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success
  425. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure;
  426. ///-----------------------------------
  427. /// @name requestForUserNameByCookie
  428. ///-----------------------------------
  429. /**
  430. * Method to get the User name by the cookie of the session. Used with SAML servers.
  431. *
  432. * @param cookieString -> NSString The cookie of the session
  433. *
  434. * @param path -> NSString server path
  435. *
  436. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  437. */
  438. - (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication:
  439. (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
  440. failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure;
  441. ///-----------------------------------
  442. /// @name Get Features Supported By Server
  443. ///-----------------------------------
  444. /**
  445. * Method get the features supported by the path server using the version string.
  446. *
  447. * Right now support:
  448. * - Share API
  449. * - Sharee API
  450. * - Cookies
  451. * - Forbidden character manage by the server side
  452. * - Capabilities
  453. *
  454. * @param path -> NSString server path
  455. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  456. *
  457. * @return BOOL in the success about the support of Share (hasShareSupport) ,Sharee (hasShareeSupport) APIs,
  458. * Cookies (hasCookiesSupport), Forbidden character (hasForbiddenCharactersSupport) and Capabilities (hasCapabilitiesSupport)
  459. *
  460. */
  461. - (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  462. successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success
  463. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure;
  464. ///-----------------------------------
  465. /// @name readSharedByServer
  466. ///-----------------------------------
  467. /**
  468. * Method to return all the files and folders shareds on the server by the current user
  469. *
  470. * @param path -> NSString server path
  471. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  472. *
  473. * @return NSArray with all the OCSharedDto of shareds files
  474. *
  475. */
  476. - (void) readSharedByServer: (NSString *) path
  477. onCommunication:(OCCommunication *)sharedOCCommunication
  478. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  479. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  480. ///-----------------------------------
  481. /// @name readSharedByServer
  482. ///-----------------------------------
  483. /**
  484. * Method to return the files and folders shareds on a concrete path by the current user
  485. *
  486. * @param serverPath -> NSString server path
  487. * @param path -> Path of the folder that we want to know that shareds that contain
  488. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  489. *
  490. * @return NSArray with all the OCSharedDto of shareds files
  491. *
  492. */
  493. - (void) readSharedByServer: (NSString *) serverPath andPath: (NSString *) path
  494. onCommunication:(OCCommunication *)sharedOCCommunication
  495. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  496. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  497. ///-----------------------------------
  498. /// @name shareFileOrFolderByServer
  499. ///-----------------------------------
  500. /**
  501. * Method to share a file or folder with password
  502. *
  503. * @param serverPath -> NSString server path
  504. * @param filePath -> path of the file that we want to share. Ex: /file.pdf <- If the file is on the root folder
  505. * @param password -> password
  506. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  507. *
  508. * @return shareLink or token of the file that we shared. URL or Ex:572d48de3814c90117fbca6442f2f3b2
  509. *
  510. * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  511. */
  512. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password
  513. onCommunication:(OCCommunication *)sharedOCCommunication
  514. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
  515. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  516. ///-----------------------------------
  517. /// @name shareFileOrFolderByServer
  518. ///-----------------------------------
  519. /**
  520. * Method to share a file or folder
  521. *
  522. * @param serverPath -> NSString server path
  523. * @param filePath -> path of the file that we want to share. Ex: /file.pdf <- If the file is on the root folder
  524. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  525. *
  526. * @return shareLink or token of the file that we shared. URL or Ex:572d48de3814c90117fbca6442f2f3b2
  527. *
  528. * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  529. */
  530. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath
  531. onCommunication:(OCCommunication *)sharedOCCommunication
  532. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *shareLink, NSString *redirectedServer)) successRequest
  533. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest ;
  534. ///-----------------------------------
  535. /// @name shareWith
  536. ///-----------------------------------
  537. /**
  538. * Method to share a file or folder with user or group
  539. *
  540. * @param userOrGroup -> NSString user or group name
  541. * @param shareeType -> NSInteger: to set the type of sharee (user/group/federated)
  542. * @param serverPath -> NSString server path
  543. * @param filePath -> path of the file that we want to share. Ex: /file.pdf <- If the file is on the root folder
  544. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  545. *
  546. * @return request response, error if exists and redirected server if exist.
  547. *
  548. * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  549. */
  550. - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andFileOrFolderPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication
  551. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  552. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest;
  553. ///-----------------------------------
  554. /// @name unShareFileOrFolderByServer
  555. ///-----------------------------------
  556. /**
  557. * Method to share a file or folder
  558. *
  559. * @param path -> NSString server path
  560. * @param idRemoteShared -> id number of the shared. Value obtained on the idRemoteSHared of OCSharedDto
  561. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  562. *
  563. */
  564. - (void) unShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  565. onCommunication:(OCCommunication *)sharedOCCommunication
  566. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  567. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  568. ///-----------------------------------
  569. /// @name isShareFileOrFolderByServer
  570. ///-----------------------------------
  571. /**
  572. * Method to know if a share item still shared
  573. *
  574. * @param path -> NSString server path
  575. * @param idRemoteShared -> id number of the shared. Value obtained on the idRemoteSHared of OCSharedDto
  576. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  577. *
  578. */
  579. - (void) isShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  580. onCommunication:(OCCommunication *)sharedOCCommunication
  581. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, BOOL isShared, id shareDto)) successRequest
  582. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  583. ///-----------------------------------
  584. /// @name UpdteShared
  585. ///-----------------------------------
  586. /**
  587. * Method to update a shared file with password and expiration time
  588. *
  589. * @param shareID -> NSInteger share id, you can get this data of these calls (readSharedByServer...)
  590. * @param serverPath -> NSString server path
  591. * @param filePath -> path of the file that we want to share. Ex: /file.pdf <- If the file is on the root folder
  592. * @param password -> password
  593. * @param permissions -> NSInteger 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
  594. * @param expirationTime -> expirationTime in format "YYYY-MM-dd"
  595. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  596. *
  597. * @return token of the file that we shared. Ex:572d48de3814c90117fbca6442f2f3b2
  598. *
  599. * @warning it only can be updated one parameter for each request so if you want to update the password the date must be nil and the permission 0
  600. * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  601. */
  602. - (void) updateShare:(NSInteger)shareId ofServerPath:(NSString *)serverPath withPasswordProtect:(NSString*)password andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions
  603. onCommunication:(OCCommunication *)sharedOCCommunication
  604. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  605. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  606. ///-----------------------------------
  607. /// @name Search Users And Groups
  608. ///-----------------------------------
  609. /**
  610. * Method to get users and groups using a search string
  611. *
  612. * @param searchString -> NSString search string
  613. * @param page -> NInsteger: Number of page (pagination support)
  614. * @param resultsPerPage -> NSInteger: Number of results per page (pagination support)
  615. * @param serverPath -> NSString server path
  616. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  617. *
  618. * @return itemList -> list of OCShareUser objects and default -> request response, error if exists and redirected server if exist
  619. *
  620. * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  621. */
  622. - (void) searchUsersAndGroupsWith:(NSString *)searchString forPage:(NSInteger)page with:(NSInteger)resultsPerPage ofServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *itemList, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  623. ///-----------------------------------
  624. /// @name Get the server capabilities
  625. ///-----------------------------------
  626. /**
  627. * Method read the capabilities of the server
  628. *
  629. * @param serverPath -> NSString server
  630. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  631. *
  632. * @return capabilities -> OCCapabilities
  633. *
  634. */
  635. - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  636. #pragma mark - Remote thumbnails
  637. ///-----------------------------------
  638. /// @name Get the thumbnail for a file
  639. ///-----------------------------------
  640. /**
  641. * Method to get the remote thumbnail for a file
  642. *
  643. * In order to support thumbnails for videos it is necessary to install video package on the server
  644. * and add the following lines in the config.php files
  645. *the following types on the config.php file
  646. * 'enabledPreviewProviders' => array(
  647. * 'OC\Preview\Movie'
  648. * )
  649. *
  650. * @param serverPath -> NSString server, without encoding
  651. * @param filePath -> NSString file path, without encoding
  652. * @param fileWidth -> NSInteger with the width size
  653. * @param fileHeight -> NSInteger with the height size
  654. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  655. *
  656. * @return nsData -> thumbnail of the file with the size requested
  657. * @return NSURLSessionTask -> You can cancel the download using this object
  658. *
  659. */
  660. - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCComunication
  661. successRequest:(void(^)(NSHTTPURLResponse *response, NSData *thumbnail, NSString *redirectedServer)) successRequest
  662. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  663. #pragma mark - Server Notification
  664. ///-----------------------------------
  665. /// @name Get the server Notification
  666. ///-----------------------------------
  667. /**
  668. * Method read the notification of the server
  669. *
  670. * @param serverPath -> NSString server
  671. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  672. *
  673. * @return listOfNotifications -> OCNotification
  674. *
  675. */
  676. - (void) getNotificationServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  677. ///-----------------------------------
  678. /// @name Set the server Notification
  679. ///-----------------------------------
  680. /**
  681. * Method read the notification of the server
  682. *
  683. * @param serverPath -> NSString server
  684. * @param type -> NSString "POST" "DELETE"
  685. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  686. *
  687. */
  688. - (void) setNotificationServer:(NSString*)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  689. ///-----------------------------------
  690. /// @name Subscribing at the Nextcloud server
  691. ///-----------------------------------
  692. /**
  693. * Method subscribing at the Nextcloud server for the push
  694. *
  695. * @param serverPath -> NSString server
  696. * @param pushTokenHash -> NSString sha512 hash of the PushToken for Apple Push Notification Service
  697. * @param devicePublicKey -> NSString devicePublicKey
  698. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  699. *
  700. */
  701. - (void)subscribingNextcloudServerPush:(NSString *)serverPath pushTokenHash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey proxyServerPath:(NSString *)proxyServerPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *deviceIdentifier, NSString *signature, NSString *redirectedServer))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest;
  702. - (void)subscribingPushProxy:(NSString *)serverPath pushToken:(NSString *)pushToken deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature userPublicKey:(NSString *)userPublicKey onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest;
  703. #pragma mark - Server Activity
  704. ///-----------------------------------
  705. /// @name Get the server Activity
  706. ///-----------------------------------
  707. /**
  708. * Method read the notification of the server
  709. *
  710. * @param serverPath -> NSString server
  711. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  712. *
  713. * @return listOfActivity -> OCActivity
  714. *
  715. */
  716. - (void) getActivityServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfActivity, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  717. #pragma mark - External Sites
  718. ///-----------------------------------
  719. /// @name Get the list of External sites
  720. ///-----------------------------------
  721. /**
  722. * Method read the notification of the server
  723. *
  724. * @param serverPath -> NSString server
  725. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  726. *
  727. * @return listOfExternalSites -> OCExternalSites
  728. *
  729. */
  730. - (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  731. #pragma mark - User Profile
  732. ///-----------------------------------
  733. /// @name Get User Profile
  734. ///-----------------------------------
  735. /**
  736. * Method read the notification of the server
  737. *
  738. * @param serverPath -> NSString server
  739. * @param type -> NSString "GET"
  740. * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  741. *
  742. */
  743. - (void) getUserProfileServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
  744. @end