/[svn]/ircd-hybrid/trunk/include/conf_db.h
ViewVC logotype

Contents of /ircd-hybrid/trunk/include/conf_db.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1620 - (show annotations)
Wed Oct 31 22:54:58 2012 UTC (7 years, 10 months ago) by michael
File MIME type: text/x-csrc
File size: 3112 byte(s)
- Added conf_db.c based on ircservice's binary database for later use

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: conf_db.h 1569 2012-10-16 18:46:53Z michael $
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 int 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(unsigned char *, struct dbFILE *);
55 extern int write_uint8(unsigned char, 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
68 #define read_buffer(buf,f) (read_db((f),(buf),sizeof(buf)) == sizeof(buf))
69 #define write_buffer(buf,f) (write_db((f),(buf),sizeof(buf)) == sizeof(buf))
70 #define read_buflen(buf,len,f) (read_db((f),(buf),(len)) == (len))
71 #define write_buflen(buf,len,f) (write_db((f),(buf),(len)) == (len))
72 #define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var))
73 #define write_variable(var,f) (write_db((f),&(var),sizeof(var)) == sizeof(var))
74 #endif

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28