UtilsFramework.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //
  2. // UtilsFramework.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. #import <Foundation/Foundation.h>
  24. @interface UtilsFramework : NSObject
  25. /*
  26. * Method that return a unique Id.
  27. * The global ID for the process includes the host name, process ID, and a time stamp,
  28. * which ensures that the ID is unique for the network
  29. * @return -> Unique Id (token)
  30. */
  31. + (NSString *) getUserSessionToken;
  32. /*
  33. * Method that check the file name or folder name to find forbidden characters
  34. * This is the forbidden characters in server: "\", "/","<",">",":",""","|","?","*"
  35. * @fileName -> file name
  36. *
  37. * @isFCSupported -> From ownCloud 8.1 the forbidden characters are controller by the server except the '/'
  38. */
  39. + (BOOL) isForbiddenCharactersInFileName:(NSString*)fileName withForbiddenCharactersSupported:(BOOL)isFCSupported;
  40. /*
  41. * Get error code with the errorCode and message of the server
  42. *
  43. */
  44. + (NSError *) getErrorWithCode:(NSInteger)errorCode andCustomMessageFromTheServer:(NSString *)message;
  45. /*
  46. * Get error for the same errors in the share api
  47. *
  48. * Statuscodes:
  49. * 100 - successful
  50. * 400 - wrong or no update parameter given
  51. * 403 - public upload disabled by the admin
  52. * 404 - couldn’t update share
  53. *
  54. */
  55. + (NSError *) getShareAPIErrorByCode:(NSInteger)errorCode;
  56. ///-----------------------------------
  57. /// @name getErrorByCodeId
  58. ///-----------------------------------
  59. /**
  60. * Method to return a NSError based on the Error Code Enum
  61. *
  62. * @param int errorCode to Enum to identify the error code
  63. *
  64. * @return NSError
  65. */
  66. + (NSError *) getErrorByCodeId:(int) errorCode;
  67. ///-----------------------------------
  68. /// @name getFileNameOrFolderByPath
  69. ///-----------------------------------
  70. /**
  71. * Method that return a filename from a path
  72. *
  73. * @param NSString -> path of the file (including the file)
  74. *
  75. * @return NSString -> fileName
  76. *
  77. */
  78. + (NSString *) getFileNameOrFolderByPath:(NSString *) path;
  79. /*
  80. * Method that return a boolean that indicate if is the same url
  81. */
  82. + (BOOL) isTheSameFileOrFolderByNewURLString:(NSString *) newURLString andOriginURLString:(NSString *) originalURLString;
  83. /*
  84. * Method that return a boolean that indicate if newUrl is under the original Url
  85. */
  86. + (BOOL) isAFolderUnderItByNewURLString:(NSString *) newURLString andOriginURLString:(NSString *) originalURLString;
  87. /**
  88. * Method to return the size of a file by a path
  89. *
  90. * @param NSString -> path of the file
  91. *
  92. * @return long long -> size of the file in the path
  93. */
  94. + (long long) getSizeInBytesByPath:(NSString *) path;
  95. ///-----------------------------------
  96. /// @name isURLWithSamlFragment:
  97. ///-----------------------------------
  98. /**
  99. * Method to check a url string to looking for a SAML fragment
  100. *
  101. * @param urlString -> url from redirect server
  102. *
  103. * @return BOOL -> the result about if exist the SAML fragment or not
  104. */
  105. + (BOOL) isURLWithSamlFragment:(NSString*)urlString;
  106. ///-----------------------------------
  107. /// @name AFBase64EncodedStringFromString:
  108. ///-----------------------------------
  109. /**
  110. * Method encode a string to base64 in order to set the credentials
  111. *
  112. * @param string -> string to be encoding
  113. *
  114. * @return NSString -> the result of the encoded string
  115. */
  116. + (NSString *) AFBase64EncodedStringFromString:(NSString *) string;
  117. //-----------------------------------
  118. /// @name addCookiesToStorageFromResponse
  119. ///-----------------------------------
  120. #pragma mark - Manage Cookies
  121. /**
  122. * Method to storage all the cookies from a response in order to use them in future requests
  123. *
  124. * @param NSHTTPURLResponse -> response
  125. * @param NSURL -> url
  126. *
  127. */
  128. + (void) addCookiesToStorageFromResponse: (NSURLResponse *) response andPath:(NSURL *) url;
  129. //-----------------------------------
  130. /// @name getRequestWithCookiesByRequest
  131. ///-----------------------------------
  132. /**
  133. * Method to return a request with all the necessary cookies of the original url without redirection
  134. *
  135. * @param NSMutableURLRequest -> request
  136. * @param NSString -> originalUrlServer
  137. *
  138. * @return request
  139. *
  140. */
  141. + (NSMutableURLRequest *) getRequestWithCookiesByRequest: (NSMutableURLRequest *) request andOriginalUrlServer:(NSString *) originalUrlServer;
  142. //-----------------------------------
  143. /// @name deleteAllCookies
  144. ///-----------------------------------
  145. /**
  146. * Method to clean the CookiesStorage
  147. *
  148. */
  149. + (void) deleteAllCookies;
  150. //-----------------------------------
  151. /// @name isServerVersionHigherThanLimitVersion
  152. ///-----------------------------------
  153. /**
  154. * Method to detect if a server version is higher than a limit version.
  155. * This method is used for example to know if the server have share API or support Cookies
  156. *
  157. * @param NSString -> serverVersion
  158. * @param NSArray -> limitVersion
  159. *
  160. * @return BOOL
  161. *
  162. */
  163. + (BOOL) isServerVersion:(NSString *) serverVersionString higherThanLimitVersion:(NSArray *) limitVersion;
  164. //-----------------------------------
  165. /// @name getPermissionsValueByCanCreate
  166. ///-----------------------------------
  167. /**
  168. * Method know the value of the permissions of a share file or folder.
  169. * This method is used to calculate the value of a permission parameter to share a file or document
  170. *
  171. * @param BOOL -> canEdit
  172. * @param BOOL -> canCreate
  173. * @param BOOL -> canChange
  174. * @param BOOL -> canDelete
  175. * @param BOOL -> canShare
  176. * @param BOOL -> isFolder
  177. *
  178. * @return NSInteger
  179. *
  180. */
  181. + (NSInteger) getPermissionsValueByCanEdit:(BOOL)canEdit andCanCreate:(BOOL)canCreate andCanChange:(BOOL)canChange andCanDelete:(BOOL)canDelete andCanShare:(BOOL)canShare andIsFolder:(BOOL) isFolder;
  182. //-----------------------------------
  183. /// @name isPermissionToCanCreate
  184. ///-----------------------------------
  185. /**
  186. * Method know if we have permission to create by the permissionValue of the OCShareDto
  187. *
  188. * @param NSInteger -> permissionValue
  189. *
  190. * @return BOOL
  191. *
  192. */
  193. + (BOOL) isPermissionToCanCreate:(NSInteger) permissionValue;
  194. //-----------------------------------
  195. /// @name isPermissionToCanChange
  196. ///-----------------------------------
  197. /**
  198. * Method know if we have permission to Change by the permissionValue of the OCShareDto
  199. *
  200. * @param NSInteger -> permissionValue
  201. *
  202. * @return BOOL
  203. *
  204. */
  205. + (BOOL) isPermissionToCanChange:(NSInteger) permissionValue;
  206. //-----------------------------------
  207. /// @name isPermissionToCanDelete
  208. ///-----------------------------------
  209. /**
  210. * Method know if we have permission to Delete by the permissionValue of the OCShareDto
  211. *
  212. * @param NSInteger -> permissionValue
  213. *
  214. * @return BOOL
  215. *
  216. */
  217. + (BOOL) isPermissionToCanDelete:(NSInteger) permissionValue;
  218. //-----------------------------------
  219. /// @name isPermissionToCanShare
  220. ///-----------------------------------
  221. /**
  222. * Method know if we have permission to Share by the permissionValue of the OCShareDto
  223. *
  224. * @param NSInteger -> permissionValue
  225. *
  226. * @return BOOL
  227. *
  228. */
  229. + (BOOL) isPermissionToCanShare:(NSInteger) permissionValue;
  230. //-----------------------------------
  231. /// @name isAnyPermissionToEdit
  232. ///-----------------------------------
  233. /**
  234. * Method to know if any permission related to edit (canCreate, canChange and canDelete) is active by the permissionValue of the OCShareDto
  235. *
  236. * @param NSInteger -> permissionValue
  237. *
  238. * @return BOOL
  239. *
  240. */
  241. + (BOOL) isAnyPermissionToEdit:(NSInteger) permissionValue;
  242. //-----------------------------------
  243. /// @name isPermissionToRead
  244. ///-----------------------------------
  245. /**
  246. * Method to know if we have permission to Read by the permissionValue of the OCShareDto
  247. *
  248. * @param NSInteger -> permissionValue
  249. *
  250. * @return BOOL
  251. *
  252. */
  253. + (BOOL) isPermissionToRead:(NSInteger) permissionValue;
  254. //---------------------------------------------------
  255. /// @name isPermissionToReadCreateUpdate
  256. ///--------------------------------------------------
  257. /**
  258. * Method to know if we have permissions to read,create and update by the permissionValue of the OCShareDto
  259. *
  260. * @param NSInteger -> permissionValue
  261. *
  262. * @return BOOL
  263. *
  264. */
  265. + (BOOL) isPermissionToReadCreateUpdate:(NSInteger) permissionValue;
  266. @end