1 /*
2  * Copyright (c) 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 NETWORKVPN_SERVICE_STUB_H
17 #define NETWORKVPN_SERVICE_STUB_H
18 
19 #include <map>
20 
21 #include "i_networkvpn_service.h"
22 #include "iremote_stub.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 class NetworkVpnServiceStub : public IRemoteStub<INetworkVpnService> {
27     using NetworkVpnServiceFunc = int32_t (NetworkVpnServiceStub::*)(MessageParcel &, MessageParcel &);
28 
29     struct ServicePermissionAndFunc {
30         std::string strPermission;
31         NetworkVpnServiceFunc serviceFunc;
32     };
33 
34 public:
35     NetworkVpnServiceStub();
36     ~NetworkVpnServiceStub() = default;
37     int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
38 
39 private:
40     int32_t ReplyPrepare(MessageParcel &data, MessageParcel &reply);
41     int32_t ReplySetUpVpn(MessageParcel &data, MessageParcel &reply);
42     int32_t ReplyProtect(MessageParcel &data, MessageParcel &reply);
43     int32_t ReplyDestroyVpn(MessageParcel &data, MessageParcel &reply);
44 #ifdef SUPPORT_SYSVPN
45     int32_t ReplyAddSysVpnConfig(MessageParcel &data, MessageParcel &reply);
46     int32_t ReplyDeleteSysVpnConfig(MessageParcel &data, MessageParcel &reply);
47     int32_t ReplyGetSysVpnConfigList(MessageParcel &data, MessageParcel &reply);
48     int32_t ReplyGetSysVpnConfig(MessageParcel &data, MessageParcel &reply);
49     int32_t ReplyGetConnectedSysVpnConfig(MessageParcel &data, MessageParcel &reply);
50 #endif // SUPPORT_SYSVPN
51     int32_t ReplyRegisterVpnEvent(MessageParcel &data, MessageParcel &reply);
52     int32_t ReplyUnregisterVpnEvent(MessageParcel &data, MessageParcel &reply);
53     int32_t ReplyCreateVpnConnection(MessageParcel &data, MessageParcel &reply);
54     int32_t ReplyFactoryResetVpn(MessageParcel &data, MessageParcel &reply);
55     int32_t ReplyRegisterBundleName(MessageParcel &data, MessageParcel &reply);
56     int32_t ReplyGetSelfAppName(MessageParcel &data, MessageParcel &reply);
57 
58     int32_t CheckVpnPermission(std::string &strPermission);
59 
60 private:
61     std::map<INetworkVpnService::MessageCode, ServicePermissionAndFunc> permissionAndFuncMap_;
62 };
63 } // namespace NetManagerStandard
64 } // namespace OHOS
65 #endif // NETWORKVPN_SERVICE_STUB_H
66