diff options
Diffstat (limited to 'src/vmod-binlog.h')
-rw-r--r-- | src/vmod-binlog.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/vmod-binlog.h b/src/vmod-binlog.h new file mode 100644 index 0000000..db6c7f0 --- /dev/null +++ b/src/vmod-binlog.h | |||
@@ -0,0 +1,71 @@ | |||
1 | /* This file is part of vmod-binlog | ||
2 | Copyright (C) 2013 Sergey Poznyakoff | ||
3 | |||
4 | Vmod-binlog is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Vmod-binlog is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <stdint.h> | ||
19 | |||
20 | #define SIZE_T_MAX ((size_t)~0) | ||
21 | |||
22 | #ifndef BINLOG_SIZE | ||
23 | # define BINLOG_SIZE (1024*1024*1024) | ||
24 | #endif | ||
25 | |||
26 | #ifndef BINLOG_PATTERN | ||
27 | # define BINLOG_PATTERN "%Y/%m/%d.log" | ||
28 | #endif | ||
29 | |||
30 | #ifndef BINLOG_INTERVAL | ||
31 | # define BINLOG_INTERVAL 86400 | ||
32 | #endif | ||
33 | |||
34 | #ifndef BINLOG_UMASK | ||
35 | # define BINLOG_UMASK 0077 | ||
36 | #endif | ||
37 | |||
38 | struct binlog_record { | ||
39 | long nid; /* node ID */ | ||
40 | long aid; /* article ID */ | ||
41 | time_t ts; /* timestamp */ | ||
42 | }; | ||
43 | |||
44 | #define BINLOG_MAGIC_STR "NXCBINLOG" | ||
45 | #define BINLOG_MAGIC_LEN (sizeof(BINLOG_MAGIC_STR) - 1) | ||
46 | #define BINLOG_VERSION 0x00010000UL | ||
47 | |||
48 | struct binlog_file_header { | ||
49 | char magic[BINLOG_MAGIC_LEN]; | ||
50 | char pad[16 - BINLOG_MAGIC_LEN]; | ||
51 | uint32_t version; | ||
52 | size_t recsize; | ||
53 | size_t recnum; | ||
54 | }; | ||
55 | |||
56 | #define BINLOG_HEADER_SIZE \ | ||
57 | ((sizeof(struct binlog_file_header) + sizeof(struct binlog_record) - 1) / \ | ||
58 | sizeof(struct binlog_record)) | ||
59 | |||
60 | union binlog_header { | ||
61 | struct binlog_file_header hdr; | ||
62 | struct binlog_record pad[BINLOG_HEADER_SIZE]; | ||
63 | }; | ||
64 | |||
65 | #define binlog_size(conf) \ | ||
66 | (sizeof(union binlog_header) + \ | ||
67 | (conf)->recidx * sizeof(struct binlog_record)) | ||
68 | #define binlog_recnum(conf) \ | ||
69 | (((conf)->size - sizeof(union binlog_header)) / \ | ||
70 | sizeof(struct binlog_record)) | ||
71 | |||