1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup fileUri 18 * @{ 19 * 20 * @brief This module provides URI format validation and URI conversion processing, 21 * as well as obtaining URI-related information 22 * 23 * @since 12 24 */ 25 26 /** 27 * @file oh_file_uri.h 28 * @kit CoreFileKit 29 * 30 * @brief uri verification and conversion 31 * This class is mainly for URI format verification and URI conversion processing; 32 * The conversion and operation of the media library type URI is not supported, 33 * and the class only converts according to the existing specifications, 34 * and there is no guarantee that the conversion result will actually exist. 35 * @library libohfileuri.so 36 * @syscap SystemCapability.FileManagement.AppFileService 37 * @since 12 38 */ 39 40 #ifndef FILE_MANAGEMENT_OH_FILE_URI_H 41 #define FILE_MANAGEMENT_OH_FILE_URI_H 42 43 #include "error_code.h" 44 #include <stdbool.h> 45 #include <stdio.h> 46 #include <stdlib.h> 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /** 52 * @brief Get uri From path. 53 * 54 * @param path Input a pointer to the path string. 55 * @param length The length of the input path. 56 * @param result Output a pointer to a uri string. Please use free() to clear the resource. 57 * @return Returns the status code of the execution. 58 * {@link ERR_PARAMS} 401 - Invalid input parameter. 59 * {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output uri string is 0. 60 * {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory. 61 * {@link ERR_OK} 0 - This operation was successfully executed. 62 * @syscap SystemCapability.FileManagement.AppFileService 63 * @since 12 64 */ 65 FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result); 66 67 /** 68 * @brief Get path From uri. 69 * 70 * @param uri Input a pointer to the uri string. 71 * @param length The length of the input uri. 72 * @param result Output a pointer to a path string. Please use free() to clear the resource. 73 * @return Returns the status code of the execution. 74 * {@link ERR_PARAMS} 401 - Invalid input parameter. 75 * {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output path string is 0. 76 * {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory. 77 * {@link ERR_OK} 0 - This operation was successfully executed. 78 * @syscap SystemCapability.FileManagement.AppFileService 79 * @since 12 80 */ 81 FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result); 82 83 /** 84 * @brief Gets the uri of the path or directory where the uri is located. 85 * 86 * @param uri Input a pointer to the uri string. 87 * @param length The length of the input uri. 88 * @param result Output a pointer to a uri string. Please use free() to clear the resource. 89 * @return Returns the status code of the execution. 90 * {@link ERR_PARAMS} 401 - Invalid input parameter. 91 * {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory. 92 * {@link ERR_ENOENT} 13900002 - No such file or directory. 93 * {@link ERR_UNKNOWN} - Unknow error. The length of the output path string is 0. 94 * {@link ERR_OK} 0 - This operation was successfully executed. 95 * @syscap SystemCapability.FileManagement.AppFileService 96 * @since 12 97 */ 98 FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri(const char *uri, unsigned int length, char **result); 99 100 /** 101 * @brief Check that the incoming uri is valid 102 * 103 * @param uri Input a pointer to the uri string. 104 * @param length The length of the input uri. 105 * @return Returns true: Valid incoming uri, false: Invalid incoming uri. 106 * @syscap SystemCapability.FileManagement.AppFileService 107 * @since 12 108 */ 109 bool OH_FileUri_IsValidUri(const char *uri, unsigned int length); 110 111 /** 112 * @brief Gets the fileName From uri. 113 * This function obtains that the last segment of the URI string is the return value of the function, 114 * and the URI of the media type is not supported 115 * @param uri Input a pointer to the uri string. 116 * @param length The length of the input uri. 117 * @param result Output a pointer to a FileName string. Please use free() to clear the resource. 118 * @return Returns the status code of the execution. 119 * {@link ERR_PARAMS} 401 - Invalid input parameter. 120 * {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory. 121 * {@link ERR_OK} 0 - This operation was successfully executed. 122 * @syscap SystemCapability.FileManagement.AppFileService 123 * @since 13 124 */ 125 FileManagement_ErrCode OH_FileUri_GetFileName(const char *uri, unsigned int length, char **result); 126 #ifdef __cplusplus 127 }; 128 #endif 129 /** @} */ 130 #endif // FILE_MANAGEMENT_OH_FILE_URI_H 131