1 /* 2 * Copyright (C) 2021 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 URI_HELPER_H 17 #define URI_HELPER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <string_view> 22 #include <map> 23 #include <unistd.h> 24 #include <fcntl.h> 25 #include "nocopyable.h" 26 27 namespace OHOS { 28 namespace Media { 29 /** 30 * The simple utility is designed to facilitate the uri processing. 31 */ 32 class __attribute__((visibility("default"))) UriHelper : public NoCopyable { 33 public: 34 enum UriType : uint8_t { 35 URI_TYPE_FILE, 36 URI_TYPE_FD, 37 URI_TYPE_HTTP, 38 URI_TYPE_UNKNOWN, 39 }; 40 41 enum UriAccessMode : uint8_t { 42 URI_READ = 1 << 0, 43 URI_WRITE = 1 << 1, 44 }; 45 46 explicit UriHelper(const std::string_view &uri); 47 UriHelper(int32_t fd, int64_t offset, int64_t size); 48 ~UriHelper(); 49 50 uint8_t UriType() const; 51 std::string FormattedUri() const; 52 bool AccessCheck(uint8_t flag) const; 53 54 private: 55 void FormatMeForUri(const std::string_view &uri) noexcept; 56 void FormatMeForFd() noexcept; 57 bool ParseFdUri(std::string_view uri); 58 bool CorrectFdParam(); 59 60 std::string formattedUri_ = ""; 61 std::string_view rawFileUri_ = ""; 62 uint8_t type_ = 0; 63 int32_t fd_ = -1; 64 int64_t offset_ = 0; 65 int64_t size_ = 0; 66 }; 67 } // namespace Media 68 } // namespace OHOS 69 70 #endif