1 /*
2 * Copyright (c) 2024 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 "ipc_internal_utils.h"
17 #include "ipc_inner_object.h"
18 #include "log_tags.h"
19 #include "ipc_debug.h"
20
21 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, OHOS::LOG_ID_IPC_CAPI, "IPCInternalUtils" };
22
IsIPCParcelValid(const OHIPCParcel * parcel,const char * promot)23 bool IsIPCParcelValid(const OHIPCParcel *parcel, const char *promot)
24 {
25 if (parcel == nullptr || parcel->msgParcel == nullptr) {
26 ZLOGE(LOG_LABEL, "%{public}s: parcel is null!", promot);
27 return false;
28 }
29 return true;
30 }
31
IsIPCRemoteProxyValid(const OHIPCRemoteProxy * proxy,const char * promot)32 bool IsIPCRemoteProxyValid(const OHIPCRemoteProxy *proxy, const char *promot)
33 {
34 if (proxy == nullptr || proxy->remote == nullptr) {
35 ZLOGE(LOG_LABEL, "%{public}s: proxy object is invalid!", promot);
36 return false;
37 }
38 return true;
39 }
40
IsMemoryParamsValid(char ** str,int32_t * len,OH_IPC_MemAllocator allocator,const char * promot)41 bool IsMemoryParamsValid(char **str, int32_t *len, OH_IPC_MemAllocator allocator, const char *promot)
42 {
43 if (str == nullptr || len == nullptr || allocator == nullptr) {
44 ZLOGE(LOG_LABEL, "%{public}s: mem param is invalid!", promot);
45 return false;
46 }
47 return true;
48 }
49