1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1996-2009 by Andrew Church <achurch@achurch.org> |
5 |
* Copyright (c) 2012-2014 ircd-hybrid development team |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
*/ |
22 |
|
23 |
/*! \file conf_db.h |
24 |
* \brief Includes file utilities for database handling |
25 |
* \version $Id$ |
26 |
*/ |
27 |
|
28 |
#ifndef DATAFILES_H |
29 |
#define DATAFILES_H |
30 |
|
31 |
struct dbFILE |
32 |
{ |
33 |
char mode; /**< 'r' for reading, 'w' for writing */ |
34 |
FILE *fp; /**< The file pointer itself */ |
35 |
char filename[HYB_PATH_MAX + 1]; /**< Name of the database file */ |
36 |
char tempname[HYB_PATH_MAX + 1]; /**< Name of the temporary file (for writing) */ |
37 |
}; |
38 |
|
39 |
extern void check_file_version(struct dbFILE *); |
40 |
extern uint32_t get_file_version(struct dbFILE *); |
41 |
extern int write_file_version(struct dbFILE *, uint32_t); |
42 |
|
43 |
extern struct dbFILE *open_db(const char *, const char *, uint32_t); |
44 |
extern void restore_db(struct dbFILE *); /* Restore to state before open_db() */ |
45 |
extern int close_db(struct dbFILE *); |
46 |
extern void backup_databases(void); |
47 |
|
48 |
#define read_db(f,buf,len) (fread((buf),1,(len),(f)->fp)) |
49 |
#define write_db(f,buf,len) (fwrite((buf),1,(len),(f)->fp)) |
50 |
#define getc_db(f) (fgetc((f)->fp)) |
51 |
|
52 |
extern int read_uint8(uint8_t *, struct dbFILE *); |
53 |
extern int write_uint8(uint8_t, struct dbFILE *); |
54 |
extern int read_uint16(uint16_t *, struct dbFILE *); |
55 |
extern int write_uint16(uint16_t, struct dbFILE *); |
56 |
extern int read_uint32(uint32_t *, struct dbFILE *); |
57 |
extern int write_uint32(uint32_t, struct dbFILE *); |
58 |
extern int read_uint64(uint64_t *, struct dbFILE *); |
59 |
extern int write_uint64(uint64_t, struct dbFILE *); |
60 |
extern int read_ptr(void **, struct dbFILE *); |
61 |
extern int write_ptr(const void *, struct dbFILE *); |
62 |
extern int read_string(char **, struct dbFILE *); |
63 |
extern int write_string(const char *, struct dbFILE *); |
64 |
|
65 |
extern void load_kline_database(void); |
66 |
extern void save_kline_database(void); |
67 |
extern void load_dline_database(void); |
68 |
extern void save_dline_database(void); |
69 |
extern void load_gline_database(void); |
70 |
extern void save_gline_database(void); |
71 |
extern void load_xline_database(void); |
72 |
extern void save_xline_database(void); |
73 |
extern void load_resv_database(void); |
74 |
extern void save_resv_database(void); |
75 |
extern void save_all_databases(void *); |
76 |
|
77 |
#define read_buffer(buf,f) (read_db((f),(buf),sizeof(buf)) == sizeof(buf)) |
78 |
#define write_buffer(buf,f) (write_db((f),(buf),sizeof(buf)) == sizeof(buf)) |
79 |
#define read_buflen(buf,len,f) (read_db((f),(buf),(len)) == (len)) |
80 |
#define write_buflen(buf,len,f) (write_db((f),(buf),(len)) == (len)) |
81 |
#define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var)) |
82 |
#define write_variable(var,f) (write_db((f),&(var),sizeof(var)) == sizeof(var)) |
83 |
|
84 |
#define DATABASE_UPDATE_TIMEOUT 300 |
85 |
#define KLINE_DB_VERSION 1 |
86 |
#endif |