1 /*
2  * Copyright (c) 2022-2023 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 REMOTE_URI_H
17 #define REMOTE_URI_H
18 
19 #include <string>
20 #include <fcntl.h>
21 #include <set>
22 #include "uri.h"
23 
24 namespace OHOS {
25 namespace DistributedFS {
26 namespace ModuleRemoteUri {
27 
28 using namespace std;
29 
30 const string FRAGMENT_TAG = "#";
31 const string FD_TAG = "=";
32 const string REMOTE_URI_TAG = "fdFromBinder";
33 const string SCHEME_TAG = ":";
34 const string SCHEME = "datashare";
35 const string SCHEME_FILE = "file";
36 const string MEDIALIBRARY_FILE_URI_PREFIX = "file://media";
37 const string ZERO_FD = "0";
38 const string MEDIA = "/media/";
39 const string PATH_SYMBOL = "/";
40 const int MAX_URI_SIZE  = 128;
41 class RemoteUri : public OHOS::Uri {
42     static set<int>fdFromBinder;
43     static void RemoveFd(int fd);
44 public:
RemoteUri(const std::string & uriString)45     explicit RemoteUri(const std::string& uriString): Uri(uriString) {}
46     static bool IsRemoteUri(const string& path, int &fd, const int& flags = O_RDONLY);
47     static int ConvertUri(const int &fd, string &remoteUri);
48     static int OpenRemoteUri(const string &remoteUri);
49     static bool IsMediaUri(const string &uriString);
50     static bool IsFileUri(const string &uriString);
~RemoteUri()51     ~RemoteUri() {}
52 };
53 std::set<int>RemoteUri::fdFromBinder;
54 } // namespace ModuleRemoteUri
55 } // namespace DistributedFS
56 } // namespace OHOS
57 
58 #endif