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#ifndef FILE_MANAGEMENT_OH_FILE_URI_H
17#define FILE_MANAGEMENT_OH_FILE_URI_H
18
19/**
20 * @file oh_file_uri.h
21 * @kit CoreFileKit
22 *
23 * @brief uri verification and conversion
24 * This class is mainly for URI format verification and URI conversion processing;
25 * The conversion and operation of the media library type URI is not supported,
26 * and the class only converts according to the existing specifications,
27 * and there is no guarantee that the conversion result will actually exist.
28 * @library libohfileuri.so
29 * @syscap SystemCapability.FileManagement.AppFileService
30 * @since 12
31 */
32
33#include "error_code.h"
34#include <stdbool.h>
35#include <stdio.h>
36#include <stdlib.h>
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * @brief Get uri From path.
43 *
44 * @param path Input a pointer to the path string.
45 * @param length The length of the input path.
46 * @param result Output a pointer to a uri string. Please use free() to clear the resource.
47 * @return Returns the status code of the execution.
48 *         {@link ERR_PARAMS}  401 - Invalid input parameter.
49 *         {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output uri string is 0.
50 *         {@link ERR_ENOMEM}  13900011 - Failed to apply for memory or failed to copy memory.
51 *         {@link ERR_OK} 0 - This operation was successfully executed.
52 * @syscap SystemCapability.FileManagement.AppFileService
53 * @since 12
54 */
55FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result);
56
57/**
58 * @brief Get path From uri.
59 *
60 * @param uri Input a pointer to the uri string.
61 * @param length The length of the input uri.
62 * @param result Output a pointer to a path string. Please use free() to clear the resource.
63 * @return Returns the status code of the execution.
64 *         {@link ERR_PARAMS} 401 - Invalid input parameter.
65 *         {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output path string is 0.
66 *         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
67 *         {@link ERR_OK} 0 - This operation was successfully executed.
68 * @syscap SystemCapability.FileManagement.AppFileService
69 * @since 12
70 */
71FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result);
72
73/**
74 * @brief Gets the uri of the path or directory where the uri is located.
75 *
76 * @param uri Input a pointer to the uri string.
77 * @param length  The length of the input uri.
78 * @param result Output a pointer to a uri string. Please use free() to clear the resource.
79 * @return Returns the status code of the execution.
80 *         {@link ERR_PARAMS} 401 - Invalid input parameter.
81 *         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
82 *         {@link ERR_ENOENT} 13900002 - No such file or directory.
83 *         {@link ERR_UNKNOWN} - Unknow error. The length of the output path string is 0.
84 *         {@link ERR_OK} 0 - This operation was successfully executed.
85 * @syscap SystemCapability.FileManagement.AppFileService
86 * @since 12
87 */
88FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri(const char *uri, unsigned int length, char **result);
89
90/**
91 * @brief Check that the incoming uri is valid
92 *
93 * @param uri Input a pointer to the uri string.
94 * @param length The length of the input uri.
95 * @return Returns true: Valid incoming uri, false: Invalid incoming uri.
96 * @syscap SystemCapability.FileManagement.AppFileService
97 * @since 12
98 */
99bool OH_FileUri_IsValidUri(const char *uri, unsigned int length);
100
101/**
102* @brief Gets the fileName From uri.
103* This function obtains that the last segment of the URI string is the return value of the function,
104* and the URI of the media type is not supported
105* @param uri Input a pointer to the uri string.
106* @param length  The length of the input uri.
107* @param result Output a pointer to a FileName string. Please use free() to clear the resource.
108* @return Returns the status code of the execution.
109*         {@link ERR_PARAMS} 401 - Invalid input parameter.
110*         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
111*         {@link ERR_OK} 0 - This operation was successfully executed.
112* @syscap SystemCapability.FileManagement.AppFileService
113* @since 13
114 */
115FileManagement_ErrCode OH_FileUri_GetFileName(const char *uri, unsigned int length, char **result);
116#ifdef __cplusplus
117};
118#endif
119#endif // FILE_MANAGEMENT_OH_FILE_URI_H
120