1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License.
5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at
6b1b8bc3fSopenharmony_ci *
7b1b8bc3fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8b1b8bc3fSopenharmony_ci *
9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and
13b1b8bc3fSopenharmony_ci * limitations under the License.
14b1b8bc3fSopenharmony_ci */
15b1b8bc3fSopenharmony_ci
16b1b8bc3fSopenharmony_ci#include "netfirewall_callback_stub.h"
17b1b8bc3fSopenharmony_ci#include "net_manager_constants.h"
18b1b8bc3fSopenharmony_ci#include "netnative_log_wrapper.h"
19b1b8bc3fSopenharmony_ci#include "netsys_ipc_interface_code.h"
20b1b8bc3fSopenharmony_ci
21b1b8bc3fSopenharmony_cinamespace OHOS {
22b1b8bc3fSopenharmony_cinamespace NetsysNative {
23b1b8bc3fSopenharmony_ciNetFirewallCallbackStub::NetFirewallCallbackStub()
24b1b8bc3fSopenharmony_ci{
25b1b8bc3fSopenharmony_ci    memberFuncMap_[static_cast<uint32_t>(NetFirewallfaceCode::ON_INTERCEPT)] = &NetFirewallCallbackStub::CmdOnIntercept;
26b1b8bc3fSopenharmony_ci}
27b1b8bc3fSopenharmony_ci
28b1b8bc3fSopenharmony_ciint32_t NetFirewallCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
29b1b8bc3fSopenharmony_ci    MessageOption &option)
30b1b8bc3fSopenharmony_ci{
31b1b8bc3fSopenharmony_ci    NETNATIVE_LOGI("Stub call start, code:[%{public}d]", code);
32b1b8bc3fSopenharmony_ci    std::u16string myDescriptor = NetFirewallCallbackStub::GetDescriptor();
33b1b8bc3fSopenharmony_ci    std::u16string remoteDescriptor = data.ReadInterfaceToken();
34b1b8bc3fSopenharmony_ci    if (myDescriptor != remoteDescriptor) {
35b1b8bc3fSopenharmony_ci        NETNATIVE_LOGE("Descriptor checked failed");
36b1b8bc3fSopenharmony_ci        return NetManagerStandard::NETMANAGER_ERR_DESCRIPTOR_MISMATCH;
37b1b8bc3fSopenharmony_ci    }
38b1b8bc3fSopenharmony_ci
39b1b8bc3fSopenharmony_ci    auto itFunc = memberFuncMap_.find(code);
40b1b8bc3fSopenharmony_ci    if (itFunc != memberFuncMap_.end()) {
41b1b8bc3fSopenharmony_ci        auto requestFunc = itFunc->second;
42b1b8bc3fSopenharmony_ci        if (requestFunc != nullptr) {
43b1b8bc3fSopenharmony_ci            return (this->*requestFunc)(data, reply);
44b1b8bc3fSopenharmony_ci        }
45b1b8bc3fSopenharmony_ci    }
46b1b8bc3fSopenharmony_ci
47b1b8bc3fSopenharmony_ci    NETNATIVE_LOGE("Stub default case, need check");
48b1b8bc3fSopenharmony_ci    return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49b1b8bc3fSopenharmony_ci}
50b1b8bc3fSopenharmony_ci
51b1b8bc3fSopenharmony_ciint32_t NetFirewallCallbackStub::CmdOnIntercept(MessageParcel &data, MessageParcel &reply)
52b1b8bc3fSopenharmony_ci{
53b1b8bc3fSopenharmony_ci    sptr<NetManagerStandard::InterceptRecord> recored = NetManagerStandard::InterceptRecord::Unmarshalling(data);
54b1b8bc3fSopenharmony_ci    int32_t result = OnIntercept(recored);
55b1b8bc3fSopenharmony_ci    if (!reply.WriteInt32(result)) {
56b1b8bc3fSopenharmony_ci        return NetManagerStandard::NETMANAGER_ERR_WRITE_REPLY_FAIL;
57b1b8bc3fSopenharmony_ci    }
58b1b8bc3fSopenharmony_ci    return NetManagerStandard::NETMANAGER_SUCCESS;
59b1b8bc3fSopenharmony_ci}
60b1b8bc3fSopenharmony_ci} // namespace NetsysNative
61b1b8bc3fSopenharmony_ci} // namespace OHOS
62