• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 ACCESSTOKEN_LOG_H
17 #define ACCESSTOKEN_LOG_H
18 
19 #ifdef HILOG_ENABLE
20 
21 #include "hilog/log.h"
22 
23 /* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */
24 #undef LOG_TAG
25 #undef LOG_DOMAIN
26 
27 static constexpr unsigned int SECURITY_DOMAIN_ACCESSTOKEN = 0xD005A01;
28 static constexpr unsigned int SECURITY_DOMAIN_PRIVACY = 0xD005A02;
29 
30 #define ACCESSTOKEN_LOG_FATAL(label, fmt, ...)            \
31     ((void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, \
32     "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
33 #define ACCESSTOKEN_LOG_ERROR(label, fmt, ...)            \
34     ((void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, \
35     "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
36 #define ACCESSTOKEN_LOG_WARN(label, fmt, ...)            \
37     ((void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, \
38     "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
39 #define ACCESSTOKEN_LOG_INFO(label, fmt, ...)            \
40     ((void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, \
41     "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
42 #define ACCESSTOKEN_LOG_DEBUG(label, fmt, ...)            \
43     ((void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, \
44     "[%{public}s:%{public}d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
45 
46 #define IF_FALSE_RETURN_VALUE_LOG(label, cond, retVal, fmt, ...) \
47     do { \
48         if (!(cond)) { \
49             ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \
50             return retVal; \
51         } \
52     } while (0)
53 #else
54 
55 #include <stdarg.h>
56 #include <stdio.h>
57 
58 /* define LOG_TAG as "security_*" at your submodule, * means your submodule name such as "security_dac" */
59 #undef LOG_TAG
60 
61 #define ACCESSTOKEN_LOG_DEBUG(fmt, ...) printf("[%s] debug: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__)
62 #define ACCESSTOKEN_LOG_INFO(fmt, ...) printf("[%s] info: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__)
63 #define ACCESSTOKEN_LOG_WARN(fmt, ...) printf("[%s] warn: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__)
64 #define ACCESSTOKEN_LOG_ERROR(fmt, ...) printf("[%s] error: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__)
65 #define ACCESSTOKEN_LOG_FATAL(fmt, ...) printf("[%s] fatal: %s: " fmt "\n", LOG_TAG, __func__, ##__VA_ARGS__)
66 
67 #define IF_FALSE_RETURN_VALUE_LOG(cond, retVal, fmt, ...) \
68     do { \
69         if (!(cond)) { \
70             ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \
71             return retVal; \
72         } \
73     } while (0)
74 #endif // HILOG_ENABLE
75 
76 #endif // ACCESSTOKEN_LOG_H
77