1 /*
2  * Copyright (C) 2021 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 "dhcp_c_utils.h"
17 #include <map>
18 #include "ipc_skeleton.h"
19 #include "kits/c/dhcp_error_code.h"
20 
21 namespace OHOS {
22 namespace DHCP {
23 
24 static std::map<ErrCode, DhcpErrorCode> g_ErrCodeMap = {
25     {DHCP_E_SUCCESS, DHCP_SUCCESS},
26     {DHCP_E_FAILED, DHCP_FAILED},
27     {DHCP_E_INVALID_PARAM, DHCP_INVALID_PARAM},
28     {DHCP_E_NON_SYSTEMAPP, DHCP_NON_SYSTEMAPP},
29     {DHCP_E_PERMISSION_DENIED, DHCP_PERMISSION_DENIED},
30     {DHCP_E_INVALID_CONFIG, DHCP_INVALID_CONFIG},
31     {DHCP_E_UNKNOWN, DHCP_UNKNOWN_ERROR}
32 };
33 
GetCErrorCode(ErrCode errCode)34 DhcpErrorCode GetCErrorCode(ErrCode errCode)
35 {
36     std::map<ErrCode, DhcpErrorCode>::const_iterator iter = g_ErrCodeMap.find(errCode);
37     return iter == g_ErrCodeMap.end() ? DHCP_UNKNOWN_ERROR : iter->second;
38 }
39 
GetCallingPid()40 int GetCallingPid()
41 {
42 #ifndef OHOS_ARCH_LITE
43     return IPCSkeleton::GetCallingPid();
44 #else
45     return 0;
46 #endif
47 }
48 
GetCallingUid()49 int GetCallingUid()
50 {
51 #ifndef OHOS_ARCH_LITE
52     return IPCSkeleton::GetCallingUid();
53 #else
54     return 0;
55 #endif
56 }
57 
GetCallingTokenId()58 int GetCallingTokenId()
59 {
60 #ifndef OHOS_ARCH_LITE
61     return IPCSkeleton::GetCallingTokenID();
62 #else
63     return 0;
64 #endif
65 }
66 
67 }  // namespace DHCP
68 }  // namespace OHOS