Anope IRC Services  Version 1.8
datafiles.h
Go to the documentation of this file.
1 /* Database file descriptor structure and file handling routine prototypes.
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 
14 #ifndef DATAFILES_H
15 #define DATAFILES_H
16 
17 #ifndef _WIN32
18 #include <sys/param.h>
19 #endif
20 
21 /*************************************************************************/
22 
23 typedef struct dbFILE_ dbFILE;
24 struct dbFILE_ {
25  int mode; /* 'r' for reading, 'w' for writing */
26  FILE *fp; /* The normal file descriptor */
27  FILE *backupfp; /* Open file pointer to a backup copy of
28  * the database file (if non-NULL) */
29  char filename[MAXPATHLEN]; /* Name of the database file */
30  char backupname[MAXPATHLEN]; /* Name of the backup file */
31 };
32 
33 /*************************************************************************/
34 
35 /* Prototypes and macros: */
36 
37 E void check_file_version(dbFILE *f);
38 E int get_file_version(dbFILE *f);
40 
41 E dbFILE *open_db(const char *service, const char *filename, const char *mode, uint32 version);
42 E void restore_db(dbFILE *f); /* Restore to state before open_db() */
43 E void close_db(dbFILE *f);
44 E void backup_databases(void);
45 
46 #define read_db(f,buf,len) (fread((buf),1,(len),(f)->fp))
47 #define write_db(f,buf,len) (fwrite((buf),1,(len),(f)->fp))
48 #define getc_db(f) (fgetc((f)->fp))
49 
50 E int read_int16(uint16 *ret, dbFILE *f);
51 E int write_int16(uint16 val, dbFILE *f);
52 E int read_int32(uint32 *ret, dbFILE *f);
53 E int write_int32(uint32 val, dbFILE *f);
54 E int read_ptr(void **ret, dbFILE *f);
55 E int write_ptr(const void *ptr, dbFILE *f);
56 E int read_string(char **ret, dbFILE *f);
57 E int write_string(const char *s, dbFILE *f);
58 
59 #define read_int8(ret,f) ((*(ret)=fgetc((f)->fp))==EOF ? -1 : 0)
60 #define write_int8(val,f) (fputc((val),(f)->fp)==EOF ? -1 : 0)
61 #define read_buffer(buf,f) (read_db((f),(buf),sizeof(buf)) == sizeof(buf))
62 #define write_buffer(buf,f) (write_db((f),(buf),sizeof(buf)) == sizeof(buf))
63 #define read_buflen(buf,len,f) (read_db((f),(buf),(len)) == (len))
64 #define write_buflen(buf,len,f) (write_db((f),(buf),(len)) == (len))
65 #define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var))
66 #define write_variable(var,f) (write_db((f),&(var),sizeof(var)) == sizeof(var))
67 
68 /*************************************************************************/
69 
70 #endif /* DATAFILES_H */
char filename[MAXPATHLEN]
Definition: datafiles.h:29
E int write_ptr(const void *ptr, dbFILE *f)
Definition: db-merger.c:1798
E void backup_databases(void)
Definition: datafiles.c:679
E int read_ptr(void **ret, dbFILE *f)
Definition: db-merger.c:1787
E int read_int16(uint16 *ret, dbFILE *f)
Definition: datafiles.c:405
char backupname[MAXPATHLEN]
Definition: datafiles.h:30
E int write_file_version(dbFILE *f, uint32 version)
Definition: db-merger.c:1869
FILE * fp
Definition: datafiles.h:26
E int read_string(char **ret, dbFILE *f)
Definition: db-merger.c:1806
E int get_file_version(dbFILE *f)
Definition: datafiles.c:30
E int write_int16(uint16 val, dbFILE *f)
Definition: db-merger.c:1737
E void close_db(dbFILE *f)
Definition: db-merger.c:1706
E void restore_db(dbFILE *f)
Definition: datafiles.c:318
u_int32_t uint32
Definition: db-merger.c:123
E dbFILE * open_db(const char *service, const char *filename, const char *mode, uint32 version)
Definition: datafiles.c:295
int mode
Definition: datafiles.h:25
#define E
Definition: extern.h:18
FILE * backupfp
Definition: datafiles.h:27
E void check_file_version(dbFILE *f)
char version[1024]
Definition: version.sh.c:24
E int read_int32(uint32 *ret, dbFILE *f)
Definition: datafiles.c:444
E int write_string(const char *s, dbFILE *f)
Definition: db-merger.c:1826
E int write_int32(uint32 val, dbFILE *f)
Definition: db-merger.c:1773
u_int16_t uint16
Definition: db-merger.c:121