Anope IRC Services  Version 1.8
Data Structures | Macros | Typedefs | Functions
datafiles.h File Reference
#include <sys/param.h>
Include dependency graph for datafiles.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dbFILE_
 

Macros

#define read_db(f, buf, len)   (fread((buf),1,(len),(f)->fp))
 
#define write_db(f, buf, len)   (fwrite((buf),1,(len),(f)->fp))
 
#define getc_db(f)   (fgetc((f)->fp))
 
#define read_int8(ret, f)   ((*(ret)=fgetc((f)->fp))==EOF ? -1 : 0)
 
#define write_int8(val, f)   (fputc((val),(f)->fp)==EOF ? -1 : 0)
 
#define read_buffer(buf, f)   (read_db((f),(buf),sizeof(buf)) == sizeof(buf))
 
#define write_buffer(buf, f)   (write_db((f),(buf),sizeof(buf)) == sizeof(buf))
 
#define read_buflen(buf, len, f)   (read_db((f),(buf),(len)) == (len))
 
#define write_buflen(buf, len, f)   (write_db((f),(buf),(len)) == (len))
 
#define read_variable(var, f)   (read_db((f),&(var),sizeof(var)) == sizeof(var))
 
#define write_variable(var, f)   (write_db((f),&(var),sizeof(var)) == sizeof(var))
 

Typedefs

typedef struct dbFILE_ dbFILE
 

Functions

E void check_file_version (dbFILE *f)
 
E int get_file_version (dbFILE *f)
 
E int write_file_version (dbFILE *f, uint32 version)
 
E dbFILEopen_db (const char *service, const char *filename, const char *mode, uint32 version)
 
E void restore_db (dbFILE *f)
 
E void close_db (dbFILE *f)
 
E void backup_databases (void)
 
E int read_int16 (uint16 *ret, dbFILE *f)
 
E int write_int16 (uint16 val, dbFILE *f)
 
E int read_int32 (uint32 *ret, dbFILE *f)
 
E int write_int32 (uint32 val, dbFILE *f)
 
E int read_ptr (void **ret, dbFILE *f)
 
E int write_ptr (const void *ptr, dbFILE *f)
 
E int read_string (char **ret, dbFILE *f)
 
E int write_string (const char *s, dbFILE *f)
 

Macro Definition Documentation

#define getc_db (   f)    (fgetc((f)->fp))
#define read_buffer (   buf,
 
)    (read_db((f),(buf),sizeof(buf)) == sizeof(buf))
#define read_buflen (   buf,
  len,
 
)    (read_db((f),(buf),(len)) == (len))

Definition at line 63 of file datafiles.h.

#define read_db (   f,
  buf,
  len 
)    (fread((buf),1,(len),(f)->fp))

Definition at line 46 of file datafiles.h.

#define read_int8 (   ret,
 
)    ((*(ret)=fgetc((f)->fp))==EOF ? -1 : 0)

Definition at line 59 of file datafiles.h.

#define read_variable (   var,
 
)    (read_db((f),&(var),sizeof(var)) == sizeof(var))

Definition at line 65 of file datafiles.h.

#define write_buffer (   buf,
 
)    (write_db((f),(buf),sizeof(buf)) == sizeof(buf))
#define write_buflen (   buf,
  len,
 
)    (write_db((f),(buf),(len)) == (len))

Definition at line 64 of file datafiles.h.

#define write_db (   f,
  buf,
  len 
)    (fwrite((buf),1,(len),(f)->fp))

Definition at line 47 of file datafiles.h.

#define write_int8 (   val,
 
)    (fputc((val),(f)->fp)==EOF ? -1 : 0)
#define write_variable (   var,
 
)    (write_db((f),&(var),sizeof(var)) == sizeof(var))

Definition at line 66 of file datafiles.h.

Typedef Documentation

typedef struct dbFILE_ dbFILE

Definition at line 23 of file datafiles.h.

Function Documentation

E void backup_databases ( void  )
E void check_file_version ( dbFILE f)
void close_db ( dbFILE f)

Close a database file. If the file was opened for write, remove the backup we (may have) created earlier.

Parameters
dbFilestruct
Returns
void

Definition at line 1706 of file db-merger.c.

References dbFILE_::backupfp, dbFILE_::backupname, dbFILE_::filename, dbFILE_::fp, and dbFILE_::mode.

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_hs_dbase(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), load_os_dbase(), main(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_hs_dbase(), save_news(), save_ns_dbase(), save_ns_req_dbase(), and save_os_dbase().

E int get_file_version ( dbFILE f)

Return the version number on the file. Return 0 if there is no version number or the number doesn't make sense (i.e. less than 1 or greater than FILE_VERSION).

Parameters
fdbFile Struct Member
Returns
int 0 if failure, 1 > is the version number

Definition at line 30 of file datafiles.c.

References alog(), dbFILE_::filename, dbFILE_::fp, log_perror(), and version.

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_hs_dbase(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), and load_os_dbase().

E dbFILE* open_db ( const char *  service,
const char *  filename,
const char *  mode,
uint32  version 
)

Open a database file for reading (*mode == 'r') or writing (*mode == 'w'). Return the stream pointer, or NULL on error. When opening for write, it is an error for rename() to return an error (when backing up the original file) other than ENOENT, if NO_BACKUP_OKAY is not defined; it is an error if the version number cannot be written to the file; and it is a fatal error if opening the file for write fails and the backup was successfully made but cannot be restored.

Parameters
serviceIf error whom to return the error as
filenameFile to open as the database
modeMode for writting or reading
versionDatabase Version
Returns
dbFile struct

Definition at line 295 of file datafiles.c.

References open_db_read(), and open_db_write().

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_hs_dbase(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), load_os_dbase(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_hs_dbase(), save_news(), save_ns_dbase(), save_ns_req_dbase(), and save_os_dbase().

E int read_int16 ( uint16 ret,
dbFILE f 
)

Read and write 2- and 4-byte quantities, pointers, and strings. All multibyte values are stored in big-endian order (most significant byte first). A pointer is stored as a byte, either 0 if NULL or 1 if not, and read pointers are returned as either (void *)0 or (void *)1. A string is stored with a 2-byte unsigned length (including the trailing \0) first; a length of 0 indicates that the string pointer is NULL. Written strings are truncated silently at 65534 bytes, and are always null-terminated.

Parameters
ret16bit integer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 405 of file datafiles.c.

References dbFILE_::fp.

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_news(), load_ns_dbase(), load_old_akill(), load_old_ns_dbase(), load_os_dbase(), and read_string().

E int read_int32 ( uint32 ret,
dbFILE f 
)

Read a unsigned 32bit integer

Parameters
retunsigned 32bit integer to read
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 444 of file datafiles.c.

References dbFILE_::fp.

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_hs_dbase_v2(), load_hs_dbase_v3(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), and load_os_dbase().

int read_ptr ( void **  ret,
dbFILE f 
)

Read Pointer

Parameters
retpointer to read
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1787 of file db-merger.c.

References c, and dbFILE_::fp.

int read_string ( char **  ret,
dbFILE f 
)

Read String

Parameters
retstring
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1806 of file db-merger.c.

References dbFILE_::fp, read_int16(), read_uint16(), and scalloc().

Referenced by load_bs_dbase(), load_cs_dbase(), load_exceptions(), load_hs_dbase_v1(), load_hs_dbase_v2(), load_hs_dbase_v3(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), load_os_dbase(), and main().

E void restore_db ( dbFILE f)

Restore the database file to its condition before open_db(). This is identical to close_db() for files open for reading; however, for files open for writing, we first attempt to restore any backup file before closing files.

Parameters
dbFilestruct
Returns
void

Definition at line 318 of file datafiles.c.

References dbFILE_::backupfp, dbFILE_::backupname, dbFILE_::filename, dbFILE_::fp, log_perror(), and dbFILE_::mode.

int write_file_version ( dbFILE f,
uint32  version 
)

Write the current version number to the file.

Parameters
fdbFile Struct Member
Returns
0 on error, 1 on success.

Definition at line 1869 of file db-merger.c.

References dbFILE_::filename, dbFILE_::fp, and log_perror().

Referenced by open_db_write().

int write_int16 ( uint16  val,
dbFILE f 
)

Write a 16bit integer

Parameters
ret16bit integer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1737 of file db-merger.c.

References dbFILE_::fp.

Referenced by main(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_news(), save_ns_dbase(), save_os_dbase(), and write_string().

int write_int32 ( uint32  val,
dbFILE f 
)

Write a unsigned 32bit integer

Parameters
retunsigned 32bit integer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1773 of file db-merger.c.

References dbFILE_::fp.

Referenced by main(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_hs_dbase(), save_news(), save_ns_dbase(), save_ns_req_dbase(), and save_os_dbase().

int write_ptr ( const void *  ptr,
dbFILE f 
)

Write Pointer

Parameters
retpointer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1798 of file db-merger.c.

References dbFILE_::fp.

int write_string ( const char *  s,
dbFILE f 
)

Write String

Parameters
retstring
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1826 of file db-merger.c.

References dbFILE_::fp, and write_int16().

Referenced by main(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_hs_dbase(), save_news(), save_ns_dbase(), save_ns_req_dbase(), and save_os_dbase().