Skyld AV  0.6
On access virus scanning for Linux
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ScanCache.h
Go to the documentation of this file.
1 /*
2  * File: ScanCache.h
3  *
4  * Copyright 2013 Heinrich Schuchardt <xypron.glpk@gmx.de>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
24 #ifndef SCANCACHE_H
25 #define SCANCACHE_H
26 
27 #include <pthread.h>
28 #include <set>
29 #include <sys/stat.h>
30 #include <sys/types.h>
31 #include "Environment.h"
32 
33 class Environment;
34 
38 struct ScanResult {
39 public:
43  dev_t dev;
47  ino_t ino; /* inode number */
51  time_t mtime; /* time of last modification */
55  unsigned int response; /* FAN_ALLOW or FAN_DENY */
59  time_t age;
68 };
69 
74 public:
75 
82  bool operator() (ScanResult *value1, ScanResult *value2) const {
83  if (value1->dev < value2->dev) {
84  return 1;
85  } else if (value1->dev > value2->dev) {
86  return 0;
87  } else if (value1->ino < value2->ino) {
88  return 1;
89  } else {
90  return 0;
91  };
92  }
93 };
94 
95 
108 class ScanCache {
109 public:
113  static const unsigned int CACHE_MISS = 0xfffd;
115  void add(const struct stat *, const unsigned int);
116  void clear();
117  int get(const struct stat *);
118  void remove(const struct stat *);
119  virtual ~ScanCache();
120 private:
124  std::set<ScanResult *, ScanResultComperator> *s;
128  pthread_mutex_t mutex;
136  unsigned long long misses;
140  unsigned long long hits;
145 
146  // Do not allow copying.
147  ScanCache(const ScanCache&);
148 };
149 
150 #endif /* SCANCACHE_H */
151 
ScanCache(Environment *)
Definition: ScanCache.cc:34
unsigned int response
Result of scan.
Definition: ScanCache.h:55
bool operator()(ScanResult *value1, ScanResult *value2) const
Compares two ScanResults.
Definition: ScanCache.h:82
std::set< ScanResult *, ScanResultComperator > * s
Definition: ScanCache.h:124
ScanResult * left
Left neighbour in double linked list.
Definition: ScanCache.h:63
ScanResult root
Root for double linked list.
Definition: ScanCache.h:144
time_t age
Time when this record entered the cache.
Definition: ScanCache.h:59
void clear()
Removes all entries from the cache.
Definition: ScanCache.cc:104
Result of scanning a file for viruses.
Definition: ScanCache.h:38
Compares two ScanResults.
Definition: ScanCache.h:73
virtual ~ScanCache()
Definition: ScanCache.cc:187
void add(const struct stat *, const unsigned int)
Adds scan result to cache.
Definition: ScanCache.cc:50
time_t mtime
Time of last modification.
Definition: ScanCache.h:51
unsigned long long misses
Number of cache misses.
Definition: ScanCache.h:136
Cache for virus scanning results.
Definition: ScanCache.h:108
dev_t dev
ID of device containing file.
Definition: ScanCache.h:43
ScanResult * right
Right neighbour in double linked list.
Definition: ScanCache.h:67
Envronment.
static const unsigned int CACHE_MISS
No matching element found in cache.
Definition: ScanCache.h:113
Environment * e
Environment.
Definition: ScanCache.h:132
The environment holds variables that are shared by instances of multiple classes. ...
Definition: Environment.h:38
pthread_mutex_t mutex
Mutex used when reading from or writing to the cache.
Definition: ScanCache.h:128
unsigned long long hits
Number of cache hits.
Definition: ScanCache.h:140
ino_t ino
Inode number.
Definition: ScanCache.h:47