| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* |
| 4 |
* Copyright (C) 1996-2002 by Andrew Church <achurch@achurch.org> |
| 5 |
* Copyright (C) 2012 by the 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 |
int mode; /**< 'r' for reading, 'w' for writing */ |
| 34 |
FILE *fp; /**< The normal file descriptor */ |
| 35 |
FILE *backupfp; /**< Open file pointer to a backup copy of |
| 36 |
* the database file (if non-NULL) */ |
| 37 |
char filename[PATH_MAX + 1]; /**< Name of the database file */ |
| 38 |
char backupname[PATH_MAX + 1]; /**< Name of the backup file */ |
| 39 |
}; |
| 40 |
|
| 41 |
extern void check_file_version(struct dbFILE *); |
| 42 |
extern uint32_t get_file_version(struct dbFILE *); |
| 43 |
extern int write_file_version(struct dbFILE *, uint32_t); |
| 44 |
|
| 45 |
extern struct dbFILE *open_db(const char *, const char *, const char *, uint32_t); |
| 46 |
extern void restore_db(struct dbFILE *); /* Restore to state before open_db() */ |
| 47 |
extern void close_db(struct dbFILE *); |
| 48 |
extern void backup_databases(void); |
| 49 |
|
| 50 |
#define read_db(f,buf,len) (fread((buf),1,(len),(f)->fp)) |
| 51 |
#define write_db(f,buf,len) (fwrite((buf),1,(len),(f)->fp)) |
| 52 |
#define getc_db(f) (fgetc((f)->fp)) |
| 53 |
|
| 54 |
extern int read_uint8(uint8_t *, struct dbFILE *); |
| 55 |
extern int write_uint8(uint8_t, struct dbFILE *); |
| 56 |
extern int read_uint16(uint16_t *, struct dbFILE *); |
| 57 |
extern int write_uint16(uint16_t, struct dbFILE *); |
| 58 |
extern int read_uint32(uint32_t *, struct dbFILE *); |
| 59 |
extern int write_uint32(uint32_t, struct dbFILE *); |
| 60 |
extern int read_uint64(uint64_t *, struct dbFILE *); |
| 61 |
extern int write_uint64(uint64_t, struct dbFILE *); |
| 62 |
extern int read_ptr(void **, struct dbFILE *); |
| 63 |
extern int write_ptr(const void *, struct dbFILE *); |
| 64 |
extern int read_string(char **, struct dbFILE *); |
| 65 |
extern int write_string(const char *, struct dbFILE *); |
| 66 |
|
| 67 |
extern void load_kline_database(void); |
| 68 |
extern void save_kline_database(void); |
| 69 |
extern void load_dline_database(void); |
| 70 |
extern void save_dline_database(void); |
| 71 |
extern void load_gline_database(void); |
| 72 |
extern void save_gline_database(void); |
| 73 |
extern void load_xline_database(void); |
| 74 |
extern void save_xline_database(void); |
| 75 |
extern void load_resv_database(void); |
| 76 |
extern void save_resv_database(void); |
| 77 |
extern void save_all_databases(void *); |
| 78 |
|
| 79 |
#define read_buffer(buf,f) (read_db((f),(buf),sizeof(buf)) == sizeof(buf)) |
| 80 |
#define write_buffer(buf,f) (write_db((f),(buf),sizeof(buf)) == sizeof(buf)) |
| 81 |
#define read_buflen(buf,len,f) (read_db((f),(buf),(len)) == (len)) |
| 82 |
#define write_buflen(buf,len,f) (write_db((f),(buf),(len)) == (len)) |
| 83 |
#define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var)) |
| 84 |
#define write_variable(var,f) (write_db((f),&(var),sizeof(var)) == sizeof(var)) |
| 85 |
|
| 86 |
#define DATABASE_UPDATE_TIMEOUT 300 |
| 87 |
#define KLINE_DB_VERSION 1 |
| 88 |
#endif |