17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci#ifndef FILE_MANAGEMENT_OH_FILE_URI_H
177777dab0Sopenharmony_ci#define FILE_MANAGEMENT_OH_FILE_URI_H
187777dab0Sopenharmony_ci
197777dab0Sopenharmony_ci/**
207777dab0Sopenharmony_ci * @file oh_file_uri.h
217777dab0Sopenharmony_ci * @kit CoreFileKit
227777dab0Sopenharmony_ci *
237777dab0Sopenharmony_ci * @brief uri verification and conversion
247777dab0Sopenharmony_ci * This class is mainly for URI format verification and URI conversion processing;
257777dab0Sopenharmony_ci * The conversion and operation of the media library type URI is not supported,
267777dab0Sopenharmony_ci * and the class only converts according to the existing specifications,
277777dab0Sopenharmony_ci * and there is no guarantee that the conversion result will actually exist.
287777dab0Sopenharmony_ci * @library libohfileuri.so
297777dab0Sopenharmony_ci * @syscap SystemCapability.FileManagement.AppFileService
307777dab0Sopenharmony_ci * @since 12
317777dab0Sopenharmony_ci */
327777dab0Sopenharmony_ci
337777dab0Sopenharmony_ci#include "error_code.h"
347777dab0Sopenharmony_ci#include <stdbool.h>
357777dab0Sopenharmony_ci#include <stdio.h>
367777dab0Sopenharmony_ci#include <stdlib.h>
377777dab0Sopenharmony_ci#ifdef __cplusplus
387777dab0Sopenharmony_ciextern "C" {
397777dab0Sopenharmony_ci#endif
407777dab0Sopenharmony_ci
417777dab0Sopenharmony_ci/**
427777dab0Sopenharmony_ci * @brief Get uri From path.
437777dab0Sopenharmony_ci *
447777dab0Sopenharmony_ci * @param path Input a pointer to the path string.
457777dab0Sopenharmony_ci * @param length The length of the input path.
467777dab0Sopenharmony_ci * @param result Output a pointer to a uri string. Please use free() to clear the resource.
477777dab0Sopenharmony_ci * @return Returns the status code of the execution.
487777dab0Sopenharmony_ci *         {@link ERR_PARAMS}  401 - Invalid input parameter.
497777dab0Sopenharmony_ci *         {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output uri string is 0.
507777dab0Sopenharmony_ci *         {@link ERR_ENOMEM}  13900011 - Failed to apply for memory or failed to copy memory.
517777dab0Sopenharmony_ci *         {@link ERR_OK} 0 - This operation was successfully executed.
527777dab0Sopenharmony_ci * @syscap SystemCapability.FileManagement.AppFileService
537777dab0Sopenharmony_ci * @since 12
547777dab0Sopenharmony_ci */
557777dab0Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result);
567777dab0Sopenharmony_ci
577777dab0Sopenharmony_ci/**
587777dab0Sopenharmony_ci * @brief Get path From uri.
597777dab0Sopenharmony_ci *
607777dab0Sopenharmony_ci * @param uri Input a pointer to the uri string.
617777dab0Sopenharmony_ci * @param length The length of the input uri.
627777dab0Sopenharmony_ci * @param result Output a pointer to a path string. Please use free() to clear the resource.
637777dab0Sopenharmony_ci * @return Returns the status code of the execution.
647777dab0Sopenharmony_ci *         {@link ERR_PARAMS} 401 - Invalid input parameter.
657777dab0Sopenharmony_ci *         {@link ERR_UNKNOWN} 13900042 - Unknow error. The length of the output path string is 0.
667777dab0Sopenharmony_ci *         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
677777dab0Sopenharmony_ci *         {@link ERR_OK} 0 - This operation was successfully executed.
687777dab0Sopenharmony_ci * @syscap SystemCapability.FileManagement.AppFileService
697777dab0Sopenharmony_ci * @since 12
707777dab0Sopenharmony_ci */
717777dab0Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result);
727777dab0Sopenharmony_ci
737777dab0Sopenharmony_ci/**
747777dab0Sopenharmony_ci * @brief Gets the uri of the path or directory where the uri is located.
757777dab0Sopenharmony_ci *
767777dab0Sopenharmony_ci * @param uri Input a pointer to the uri string.
777777dab0Sopenharmony_ci * @param length  The length of the input uri.
787777dab0Sopenharmony_ci * @param result Output a pointer to a uri string. Please use free() to clear the resource.
797777dab0Sopenharmony_ci * @return Returns the status code of the execution.
807777dab0Sopenharmony_ci *         {@link ERR_PARAMS} 401 - Invalid input parameter.
817777dab0Sopenharmony_ci *         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
827777dab0Sopenharmony_ci *         {@link ERR_ENOENT} 13900002 - No such file or directory.
837777dab0Sopenharmony_ci *         {@link ERR_UNKNOWN} - Unknow error. The length of the output path string is 0.
847777dab0Sopenharmony_ci *         {@link ERR_OK} 0 - This operation was successfully executed.
857777dab0Sopenharmony_ci * @syscap SystemCapability.FileManagement.AppFileService
867777dab0Sopenharmony_ci * @since 12
877777dab0Sopenharmony_ci */
887777dab0Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetFullDirectoryUri(const char *uri, unsigned int length, char **result);
897777dab0Sopenharmony_ci
907777dab0Sopenharmony_ci/**
917777dab0Sopenharmony_ci * @brief Check that the incoming uri is valid
927777dab0Sopenharmony_ci *
937777dab0Sopenharmony_ci * @param uri Input a pointer to the uri string.
947777dab0Sopenharmony_ci * @param length The length of the input uri.
957777dab0Sopenharmony_ci * @return Returns true: Valid incoming uri, false: Invalid incoming uri.
967777dab0Sopenharmony_ci * @syscap SystemCapability.FileManagement.AppFileService
977777dab0Sopenharmony_ci * @since 12
987777dab0Sopenharmony_ci */
997777dab0Sopenharmony_cibool OH_FileUri_IsValidUri(const char *uri, unsigned int length);
1007777dab0Sopenharmony_ci
1017777dab0Sopenharmony_ci/**
1027777dab0Sopenharmony_ci* @brief Gets the fileName From uri.
1037777dab0Sopenharmony_ci* This function obtains that the last segment of the URI string is the return value of the function,
1047777dab0Sopenharmony_ci* and the URI of the media type is not supported
1057777dab0Sopenharmony_ci* @param uri Input a pointer to the uri string.
1067777dab0Sopenharmony_ci* @param length  The length of the input uri.
1077777dab0Sopenharmony_ci* @param result Output a pointer to a FileName string. Please use free() to clear the resource.
1087777dab0Sopenharmony_ci* @return Returns the status code of the execution.
1097777dab0Sopenharmony_ci*         {@link ERR_PARAMS} 401 - Invalid input parameter.
1107777dab0Sopenharmony_ci*         {@link ERR_ENOMEM} 13900011 - Failed to apply for memory or failed to copy memory.
1117777dab0Sopenharmony_ci*         {@link ERR_OK} 0 - This operation was successfully executed.
1127777dab0Sopenharmony_ci* @syscap SystemCapability.FileManagement.AppFileService
1137777dab0Sopenharmony_ci* @since 13
1147777dab0Sopenharmony_ci */
1157777dab0Sopenharmony_ciFileManagement_ErrCode OH_FileUri_GetFileName(const char *uri, unsigned int length, char **result);
1167777dab0Sopenharmony_ci#ifdef __cplusplus
1177777dab0Sopenharmony_ci};
1187777dab0Sopenharmony_ci#endif
1197777dab0Sopenharmony_ci#endif // FILE_MANAGEMENT_OH_FILE_URI_H
120