blob: 44ac742f0a987a6ed8e375b2ccdf933e8948f392 [file] [log] [blame]
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -07001/*
2 * Copyright (C) 2012-2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LOGD_LOG_UTILS_H__
18#define _LOGD_LOG_UTILS_H__
19
Mark Salyzynd048f112016-02-08 10:28:12 -080020#include <sys/cdefs.h>
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070021#include <sys/types.h>
22
Mark Salyzynaeaaf812016-09-30 13:30:33 -070023#include <private/android_logger.h>
Mark Salyzyn083b0372015-12-04 10:59:45 -080024#include <sysutils/SocketClient.h>
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070025
26// Hijack this header as a common include file used by most all sources
27// to report some utilities defined here and there.
28
29namespace android {
30
31// Furnished in main.cpp. Caller must own and free returned value
32char *uidToName(uid_t uid);
Mark Salyzynd048f112016-02-08 10:28:12 -080033void prdebug(const char *fmt, ...) __printflike(1, 2);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070034
35// Furnished in LogStatistics.cpp. Caller must own and free returned value
36char *pidToName(pid_t pid);
37char *tidToName(pid_t tid);
38
39// Furnished in main.cpp. Thread safe.
Mark Salyzyn807e40e2016-09-22 09:56:51 -070040const char *tagToName(size_t *len, uint32_t tag);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070041
42}
43
Mark Salyzyn083b0372015-12-04 10:59:45 -080044// Furnished in LogCommand.cpp
45bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
46bool clientHasLogCredentials(SocketClient *cli);
47
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070048static inline bool worstUidEnabledForLogid(log_id_t id) {
Mark Salyzyn6a066942016-07-14 15:34:30 -070049 return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) ||
50 (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070051}
52
Mark Salyzynddda2122015-10-02 09:22:52 -070053template <int (*cmp)(const char *l, const char *r, const size_t s)>
54static inline int fast(const char *l, const char *r, const size_t s) {
55 return (*l != *r) || cmp(l + 1, r + 1, s - 1);
56}
57
58template <int (*cmp)(const void *l, const void *r, const size_t s)>
59static inline int fast(const void *lv, const void *rv, const size_t s) {
60 const char *l = static_cast<const char *>(lv);
61 const char *r = static_cast<const char *>(rv);
62 return (*l != *r) || cmp(l + 1, r + 1, s - 1);
63}
64
65template <int (*cmp)(const char *l, const char *r)>
66static inline int fast(const char *l, const char *r) {
67 return (*l != *r) || cmp(l + 1, r + 1);
68}
69
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070070#endif // _LOGD_LOG_UTILS_H__