Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_WHITE_BLACK_LIST_H__ |
| 18 | #define _LOGD_LOG_WHITE_BLACK_LIST_H__ |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | |
Mark Salyzyn | 7c528d9 | 2015-08-20 10:01:44 -0700 | [diff] [blame] | 22 | #include <string.h> |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 23 | #include <list> |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 24 | |
Mark Salyzyn | 7c7c39a | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 25 | #include "LogBufferElement.h" |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 26 | |
| 27 | // White and Blacklist |
| 28 | |
| 29 | class Prune { |
| 30 | friend class PruneList; |
| 31 | |
| 32 | const uid_t mUid; |
| 33 | const pid_t mPid; |
| 34 | int cmp(uid_t uid, pid_t pid) const; |
| 35 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 36 | public: |
| 37 | static const uid_t uid_all = (uid_t)-1; |
| 38 | static const pid_t pid_all = (pid_t)-1; |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 39 | |
| 40 | Prune(uid_t uid, pid_t pid); |
| 41 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 42 | uid_t getUid() const { |
| 43 | return mUid; |
| 44 | } |
| 45 | pid_t getPid() const { |
| 46 | return mPid; |
| 47 | } |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 48 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 49 | int cmp(LogBufferElement* e) const { |
| 50 | return cmp(e->getUid(), e->getPid()); |
| 51 | } |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 52 | |
Mark Salyzyn | 7c528d9 | 2015-08-20 10:01:44 -0700 | [diff] [blame] | 53 | std::string format(); |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Mark Salyzyn | 266f858 | 2015-08-19 13:31:31 -0700 | [diff] [blame] | 56 | typedef std::list<Prune> PruneCollection; |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 57 | |
| 58 | class PruneList { |
| 59 | PruneCollection mNaughty; |
| 60 | PruneCollection mNice; |
| 61 | bool mWorstUidEnabled; |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 62 | bool mWorstPidOfSystemEnabled; |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 63 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 64 | public: |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 65 | PruneList(); |
| 66 | ~PruneList(); |
| 67 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 68 | int init(const char* str); |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 69 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 70 | bool naughty(LogBufferElement* element); |
| 71 | bool naughty(void) { |
| 72 | return !mNaughty.empty(); |
| 73 | } |
| 74 | bool nice(LogBufferElement* element); |
| 75 | bool nice(void) { |
| 76 | return !mNice.empty(); |
| 77 | } |
| 78 | bool worstUidEnabled() const { |
| 79 | return mWorstUidEnabled; |
| 80 | } |
| 81 | bool worstPidOfSystemEnabled() const { |
| 82 | return mWorstPidOfSystemEnabled; |
| 83 | } |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 84 | |
Mark Salyzyn | 7c528d9 | 2015-08-20 10:01:44 -0700 | [diff] [blame] | 85 | std::string format(); |
Mark Salyzyn | 62a5b9d | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 88 | #endif // _LOGD_LOG_WHITE_BLACK_LIST_H__ |