123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- //
- // UtilsFramework.h
- // Owncloud iOs Client
- //
- // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #import <Foundation/Foundation.h>
- @interface UtilsFramework : NSObject
- /*
- * Method that return a unique Id.
- * The global ID for the process includes the host name, process ID, and a time stamp,
- * which ensures that the ID is unique for the network
- * @return -> Unique Id (token)
- */
- + (NSString *) getUserSessionToken;
- /*
- * Method that check the file name or folder name to find forbidden characters
- * This is the forbidden characters in server: "\", "/","<",">",":",""","|","?","*"
- * @fileName -> file name
- *
- * @isFCSupported -> From ownCloud 8.1 the forbidden characters are controller by the server except the '/'
- */
- + (BOOL) isForbiddenCharactersInFileName:(NSString*)fileName withForbiddenCharactersSupported:(BOOL)isFCSupported;
- /*
- * Get error code with the errorCode and message of the server
- *
- */
- + (NSError *) getErrorWithCode:(NSInteger)errorCode andCustomMessageFromTheServer:(NSString *)message;
- /*
- * Get error for the same errors in the share api
- *
- * Statuscodes:
- * 100 - successful
- * 400 - wrong or no update parameter given
- * 403 - public upload disabled by the admin
- * 404 - couldn’t update share
- *
- */
- + (NSError *) getShareAPIErrorByCode:(NSInteger)errorCode;
- ///-----------------------------------
- /// @name getErrorByCodeId
- ///-----------------------------------
- /**
- * Method to return a NSError based on the Error Code Enum
- *
- * @param int errorCode to Enum to identify the error code
- *
- * @return NSError
- */
- + (NSError *) getErrorByCodeId:(int) errorCode;
- ///-----------------------------------
- /// @name getFileNameOrFolderByPath
- ///-----------------------------------
- /**
- * Method that return a filename from a path
- *
- * @param NSString -> path of the file (including the file)
- *
- * @return NSString -> fileName
- *
- */
- + (NSString *) getFileNameOrFolderByPath:(NSString *) path;
- /*
- * Method that return a boolean that indicate if is the same url
- */
- + (BOOL) isTheSameFileOrFolderByNewURLString:(NSString *) newURLString andOriginURLString:(NSString *) originalURLString;
- /*
- * Method that return a boolean that indicate if newUrl is under the original Url
- */
- + (BOOL) isAFolderUnderItByNewURLString:(NSString *) newURLString andOriginURLString:(NSString *) originalURLString;
- /**
- * Method to return the size of a file by a path
- *
- * @param NSString -> path of the file
- *
- * @return long long -> size of the file in the path
- */
- + (long long) getSizeInBytesByPath:(NSString *) path;
- ///-----------------------------------
- /// @name isURLWithSamlFragment:
- ///-----------------------------------
- /**
- * Method to check a url string to looking for a SAML fragment
- *
- * @param urlString -> url from redirect server
- *
- * @return BOOL -> the result about if exist the SAML fragment or not
- */
- + (BOOL) isURLWithSamlFragment:(NSString*)urlString;
- ///-----------------------------------
- /// @name AFBase64EncodedStringFromString:
- ///-----------------------------------
- /**
- * Method encode a string to base64 in order to set the credentials
- *
- * @param string -> string to be encoding
- *
- * @return NSString -> the result of the encoded string
- */
- + (NSString *) AFBase64EncodedStringFromString:(NSString *) string;
- //-----------------------------------
- /// @name addCookiesToStorageFromResponse
- ///-----------------------------------
- #pragma mark - Manage Cookies
- /**
- * Method to storage all the cookies from a response in order to use them in future requests
- *
- * @param NSHTTPURLResponse -> response
- * @param NSURL -> url
- *
- */
- + (void) addCookiesToStorageFromResponse: (NSURLResponse *) response andPath:(NSURL *) url;
- //-----------------------------------
- /// @name getRequestWithCookiesByRequest
- ///-----------------------------------
- /**
- * Method to return a request with all the necessary cookies of the original url without redirection
- *
- * @param NSMutableURLRequest -> request
- * @param NSString -> originalUrlServer
- *
- * @return request
- *
- */
- + (NSMutableURLRequest *) getRequestWithCookiesByRequest: (NSMutableURLRequest *) request andOriginalUrlServer:(NSString *) originalUrlServer;
- //-----------------------------------
- /// @name deleteAllCookies
- ///-----------------------------------
- /**
- * Method to clean the CookiesStorage
- *
- */
- + (void) deleteAllCookies;
- //-----------------------------------
- /// @name isServerVersionHigherThanLimitVersion
- ///-----------------------------------
- /**
- * Method to detect if a server version is higher than a limit version.
- * This method is used for example to know if the server have share API or support Cookies
- *
- * @param NSString -> serverVersion
- * @param NSArray -> limitVersion
- *
- * @return BOOL
- *
- */
- + (BOOL) isServerVersion:(NSString *) serverVersionString higherThanLimitVersion:(NSArray *) limitVersion;
- //-----------------------------------
- /// @name getPermissionsValueByCanCreate
- ///-----------------------------------
- /**
- * Method know the value of the permissions of a share file or folder.
- * This method is used to calculate the value of a permission parameter to share a file or document
- *
- * @param BOOL -> canEdit
- * @param BOOL -> canCreate
- * @param BOOL -> canChange
- * @param BOOL -> canDelete
- * @param BOOL -> canShare
- * @param BOOL -> isFolder
- *
- * @return NSInteger
- *
- */
- + (NSInteger) getPermissionsValueByCanEdit:(BOOL)canEdit andCanCreate:(BOOL)canCreate andCanChange:(BOOL)canChange andCanDelete:(BOOL)canDelete andCanShare:(BOOL)canShare andIsFolder:(BOOL) isFolder;
- //-----------------------------------
- /// @name isPermissionToCanCreate
- ///-----------------------------------
- /**
- * Method know if we have permission to create by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToCanCreate:(NSInteger) permissionValue;
- //-----------------------------------
- /// @name isPermissionToCanChange
- ///-----------------------------------
- /**
- * Method know if we have permission to Change by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToCanChange:(NSInteger) permissionValue;
- //-----------------------------------
- /// @name isPermissionToCanDelete
- ///-----------------------------------
- /**
- * Method know if we have permission to Delete by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToCanDelete:(NSInteger) permissionValue;
- //-----------------------------------
- /// @name isPermissionToCanShare
- ///-----------------------------------
- /**
- * Method know if we have permission to Share by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToCanShare:(NSInteger) permissionValue;
- //-----------------------------------
- /// @name isAnyPermissionToEdit
- ///-----------------------------------
- /**
- * Method to know if any permission related to edit (canCreate, canChange and canDelete) is active by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isAnyPermissionToEdit:(NSInteger) permissionValue;
- //-----------------------------------
- /// @name isPermissionToRead
- ///-----------------------------------
- /**
- * Method to know if we have permission to Read by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToRead:(NSInteger) permissionValue;
- //---------------------------------------------------
- /// @name isPermissionToReadCreateUpdate
- ///--------------------------------------------------
- /**
- * Method to know if we have permissions to read,create and update by the permissionValue of the OCShareDto
- *
- * @param NSInteger -> permissionValue
- *
- * @return BOOL
- *
- */
- + (BOOL) isPermissionToReadCreateUpdate:(NSInteger) permissionValue;
- @end
|