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 #include "net_dns_result_callback_stub.h"
17 #include "netnative_log_wrapper.h"
18 #include "netsys_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace NetsysNative {
22 static constexpr int32_t MAX_SIZE = 65535;
NetDnsResultCallbackStub()23 NetDnsResultCallbackStub::NetDnsResultCallbackStub()
24 {
25 memberFuncMap_[static_cast<uint32_t>(NetDnsResultInterfaceCode::ON_DNS_RESULT_REPORT)] =
26 &NetDnsResultCallbackStub::CmdDnsResultReport;
27 }
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t NetDnsResultCallbackStub::OnRemoteRequest(
30 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32 NETNATIVE_LOG_D("Stub call start, code:[%{public}d]", code);
33 std::u16string myDescripter = NetDnsResultCallbackStub::GetDescriptor();
34 std::u16string remoteDescripter = data.ReadInterfaceToken();
35 if (myDescripter != remoteDescripter) {
36 NETNATIVE_LOGE("Descriptor checked failed");
37 return ERR_FLATTEN_OBJECT;
38 }
39
40 auto itFunc = memberFuncMap_.find(code);
41 if (itFunc != memberFuncMap_.end()) {
42 auto requestFunc = itFunc->second;
43 if (requestFunc != nullptr) {
44 return (this->*requestFunc)(data, reply);
45 }
46 }
47
48 NETNATIVE_LOGI("Stub default case, need check");
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51
CmdDnsResultReport(MessageParcel & data,MessageParcel & reply)52 int32_t NetDnsResultCallbackStub::CmdDnsResultReport(MessageParcel &data, MessageParcel &reply)
53 {
54 std::list<NetDnsResultReport> dnsResultReport;
55
56 uint32_t size = data.ReadUint32();
57 size = size > MAX_SIZE ? MAX_SIZE : size;
58 for (uint32_t i = 0; i < size; ++i) {
59 NetDnsResultReport report;
60 if (!NetDnsResultReport::Unmarshalling(data, report)) {
61 return -1;
62 }
63 dnsResultReport.push_back(report);
64 }
65
66 int32_t result = OnDnsResultReport(size, dnsResultReport);
67 if (!reply.WriteInt32(result)) {
68 NETNATIVE_LOGE("Write parcel failed");
69 return result;
70 }
71
72 return ERR_NONE;
73 }
74
OnDnsResultReport(uint32_t size,std::list<NetDnsResultReport> dnsResultReport)75 int32_t NetDnsResultCallbackStub::OnDnsResultReport(uint32_t size, std::list<NetDnsResultReport> dnsResultReport)
76 {
77 return 0;
78 }
79 } // namespace NetsysNative
80 } // namespace OHOS
81