diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-11-27 19:46:15 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-11-27 19:46:15 +0300 |
commit | f1fdc9c6c1fa897f6eac5abc4cd193b55d31e7bc (patch) | |
tree | e63407c93bdd172baa3fc8091d4ba2a0ab681bef /src/statfile.h | |
parent | 4c758549545a91b2088678d8ba6ba5cf3e92d6ac (diff) | |
download | rspamd-f1fdc9c6c1fa897f6eac5abc4cd193b55d31e7bc.tar.gz rspamd-f1fdc9c6c1fa897f6eac5abc4cd193b55d31e7bc.zip |
* Add initial implementation of statistics files handling API
Diffstat (limited to 'src/statfile.h')
-rw-r--r-- | src/statfile.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/statfile.h b/src/statfile.h new file mode 100644 index 000000000..801d1dae2 --- /dev/null +++ b/src/statfile.h @@ -0,0 +1,61 @@ +/* + * Describes common methods in accessing statistics files and caching them in memory + */ + +#ifndef RSPAMD_STATFILE_H +#define RSPAMD_STATFILE_H + +#include "config.h" +#include <sys/types.h> +#include <glib.h> + +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#include "mem_pool.h" + +struct stat_file_header { + u_char magic[3]; + u_char version[2]; + uint64_t create_time; +}; + +struct stat_file_block { + uint32_t hash1; + uint32_t hash2; + uint32_t value; /* In fact this is float */ + uint32_t last_access; +}; + +struct stat_file { + struct stat_file_header header; + struct stat_file_block blocks[1]; +}; + +typedef struct stat_file_s { + char *filename; + int fd; + void *map; + time_t open_time; + time_t access_time; + size_t len; + /* Length is in blocks */ + size_t blocks; + gint *lock; +} stat_file_t; + +typedef struct statfile_pool_s { + GHashTable *files; + int opened; + size_t max; + size_t occupied; + memory_pool_t *pool; +} statfile_pool_t; + +statfile_pool_t* statfile_pool_new (size_t max_size); +int statfile_pool_open (statfile_pool_t *pool, char *filename); +int statfile_pool_create (statfile_pool_t *pool, char *filename, size_t len); +int statfile_pool_close (statfile_pool_t *pool, char *filename); +void statfile_pool_delete (statfile_pool_t *pool); + +#endif |