• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ACCESS_URI_EXT_H
17 #define FILE_ACCESS_URI_EXT_H
18 
19 #include <string>
20 #include "uri.h"
21 
22 namespace OHOS {
23 namespace FileAccessFwk {
24 namespace {
25     const std::string NOT_CACHED = "NOT VALID";
26     const std::string EMPTY = "";
27     const std::size_t NOT_FOUND = std::string::npos;
28     const int NOT_CALCULATED = -2;
29     const int PORT_NONE = -1;
30     const char SCHEME_SEPARATOR = ':';
31     const char SCHEME_FRAGMENT = '#';
32     const char LEFT_SEPARATOR = '/';
33     const char RIGHT_SEPARATOR = '\\';
34     const char QUERY_FLAG = '?';
35     const char USER_HOST_SEPARATOR = '@';
36     const char PORT_SEPARATOR = ':';
37     const std::size_t POS_INC = 1;
38     const std::size_t POS_INC_MORE = 2;
39     const std::size_t POS_INC_AGAIN = 3;
40 }  // namespace
41 
42 class Urie : public OHOS::Uri {
43 public:
44     Urie();
45     Urie(const std::string& uriString);
46     ~Urie();
47 
48     OHOS::Uri ConvertToUri(Urie &urie);
49     std::string GetScheme();
50     std::string GetSchemeSpecificPart();
51     std::string GetAuthority();
52     std::string GetHost();
53     int GetPort();
54     std::string GetUserInfo();
55     std::string GetQuery();
56     std::string GetPath();
57     void GetPathSegments(std::vector<std::string>& segments);
58     std::string GetFragment();
59     bool IsHierarchical();
60     bool IsAbsolute();
61     bool IsRelative();
62     bool Equals(const Urie& other) const;
63     int CompareTo(const Urie& other) const;
64     std::string ToString() const;
65     bool operator==(const Urie& other) const;
66     virtual bool Marshalling(Parcel& parcel) const override;
67     static Urie* Unmarshalling(Parcel& parcel);
68 
69 private:
70     bool CheckScheme();
71     std::string ParseScheme();
72     std::string ParseSsp();
73     std::string ParseAuthority();
74     std::string ParseUserInfo();
75     std::string ParseHost();
76     int ParsePort();
77     std::string ParsePath(std::size_t ssi);
78     std::string ParsePath();
79     std::string ParseQuery();
80     std::string ParseFragment();
81     std::size_t FindSchemeSeparator();
82     std::size_t FindFragmentSeparator();
83 
84     std::string uriString_;
85     std::string scheme_;
86     std::string ssp_;
87     std::string authority_;
88     std::string host_;
89     int port_;
90     std::string userInfo_;
91     std::string query_;
92     std::string path_;
93     std::string fragment_;
94     std::size_t cachedSsi_;
95     std::size_t cachedFsi_;
96 };
97 } // namespace FileAccessFwk
98 } // namespace OHOS
99 #endif  // FILE_ACCESS_URI_EXT_H
100