#include "services.h"#include "datafiles.h"#include <fcntl.h>
Go to the source code of this file.
Functions | |
| int | get_file_version (dbFILE *f) |
| int | write_file_version (dbFILE *f, uint32 version) |
| static dbFILE * | open_db_read (const char *service, const char *filename) |
| static dbFILE * | open_db_write (const char *service, const char *filename, uint32 version) |
| dbFILE * | open_db (const char *service, const char *filename, const char *mode, uint32 version) |
| void | restore_db (dbFILE *f) |
| void | close_db (dbFILE *f) |
| int | read_int16 (uint16 *ret, dbFILE *f) |
| int | write_int16 (uint16 val, dbFILE *f) |
| int | read_int32 (uint32 *ret, dbFILE *f) |
| int | write_int32 (uint32 val, dbFILE *f) |
| int | read_ptr (void **ret, dbFILE *f) |
| int | write_ptr (const void *ptr, dbFILE *f) |
| int | read_string (char **ret, dbFILE *f) |
| int | write_string (const char *s, dbFILE *f) |
| static void | rename_database (char *name, char *ext) |
| static void | remove_backups (void) |
| void | backup_databases (void) |
| void | ModuleDatabaseBackup (char *dbname) |
| void | ModuleRemoveBackups (char *dbname) |
Variables | |
| static int | curday = 0 |
| static time_t | lastwarn = 0 |
| void backup_databases | ( | void | ) |
Handles database backups.
Definition at line 679 of file datafiles.c.
References alog(), BotDBName, ChanDBName, curday, EVENT_DB_BACKUP, EVENT_START, EVENT_STOP, ExceptionDBName, HostDBName, KeepBackups, NewsDBName, NickDBName, NSEmailReg, OperDBName, PreNickDBName, remove_backups(), rename_database(), s_BotServ, s_HostServ, send_event(), and skeleton.
Referenced by save_databases().
| void close_db | ( | dbFILE * | f | ) |
Close a database file. If the file was opened for write, remove the backup we (may have) created earlier.
| dbFile | struct |
Definition at line 373 of file datafiles.c.
References dbFILE_::backupfp, dbFILE_::backupname, dbFILE_::filename, dbFILE_::fp, and dbFILE_::mode.
| 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).
| f | dbFile Struct Member |
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().
| void ModuleDatabaseBackup | ( | char * | dbname | ) |
Definition at line 732 of file datafiles.c.
References alog(), curday, debug, KeepBackups, ModuleRemoveBackups(), and rename_database().
Referenced by backup_ignoredb(), hsreqevt_db_backup(), and mBackupData().
| void ModuleRemoveBackups | ( | char * | dbname | ) |
Definition at line 755 of file datafiles.c.
References KeepBackups, and snprintf().
Referenced by ModuleDatabaseBackup().
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.
| service | If error whom to return the error as | |
| filename | File to open as the database | |
| mode | Mode for writting or reading | |
| version | Database Version |
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().
| static dbFILE* open_db_read | ( | const char * | service, | |
| const char * | filename | |||
| ) | [static] |
Open the database for reading
| service | If error whom to return the error as | |
| filename | File to open as the database |
Definition at line 85 of file datafiles.c.
References anope_cmd_global(), dbFILE_::backupfp, dbFILE_::filename, dbFILE_::fp, lastwarn, log_perror(), dbFILE_::mode, scalloc(), strerror(), strscpy(), and WarningTimeout.
| static dbFILE* open_db_write | ( | const char * | service, | |
| const char * | filename, | |||
| uint32 | version | |||
| ) | [static] |
Open the database for writting
| service | If error whom to return the error as | |
| filename | File to open as the database | |
| version | Database Version |
Definition at line 136 of file datafiles.c.
References alog(), anope_cmd_global(), dbFILE_::backupfp, dbFILE_::backupname, debug, dbFILE_::filename, dbFILE_::fp, log_perror(), dbFILE_::mode, NoBackupOkay, scalloc(), snprintf(), strscpy(), and write_file_version().
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 ) 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.
| ret | 16bit integer to write | |
| dbFile | struct |
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(), main(), and read_string().
Read a unsigned 32bit integer
| ret | unsigned 32bit integer to read | |
| dbFile | struct |
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_lang(), load_news(), load_ns_dbase(), load_ns_req_db(), load_old_akill(), load_old_ns_dbase(), load_os_dbase(), and main().
| int read_ptr | ( | void ** | ret, | |
| dbFILE * | f | |||
| ) |
Read Pointer
| ret | pointer to read | |
| dbFile | struct |
Definition at line 489 of file datafiles.c.
References c, and dbFILE_::fp.
| int read_string | ( | char ** | ret, | |
| dbFILE * | f | |||
| ) |
Read String
| ret | string | |
| dbFile | struct |
Definition at line 525 of file datafiles.c.
References dbFILE_::fp, read_int16(), and scalloc().
| static void remove_backups | ( | void | ) | [static] |
Removes old databases
Definition at line 601 of file datafiles.c.
References BotDBName, ChanDBName, ExceptionDBName, HostDBName, KeepBackups, NewsDBName, NickDBName, NSEmailReg, OperDBName, PreNickDBName, s_BotServ, s_HostServ, and snprintf().
Referenced by backup_databases().
| static void rename_database | ( | char * | name, | |
| char * | ext | |||
| ) | [static] |
Renames a database
| name | Database to name | |
| ext | Extention |
Definition at line 581 of file datafiles.c.
References alog(), anope_cmd_global(), s_OperServ, and snprintf().
Referenced by backup_databases(), and ModuleDatabaseBackup().
| 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.
| dbFile | struct |
Definition at line 318 of file datafiles.c.
References dbFILE_::backupfp, dbFILE_::backupname, dbFILE_::filename, dbFILE_::fp, log_perror(), and dbFILE_::mode.
Write the current version number to the file.
| f | dbFile Struct Member |
Definition at line 62 of file datafiles.c.
References dbFILE_::filename, dbFILE_::fp, and log_perror().
Write a 16bit integer
| ret | 16bit integer to write | |
| dbFile | struct |
Definition at line 426 of file datafiles.c.
References dbFILE_::fp.
Write a unsigned 32bit integer
| ret | unsigned 32bit integer to write | |
| dbFile | struct |
Definition at line 467 of file datafiles.c.
References dbFILE_::fp.
| int write_ptr | ( | const void * | ptr, | |
| dbFILE * | f | |||
| ) |
Write Pointer
| ret | pointer to write | |
| dbFile | struct |
Definition at line 509 of file datafiles.c.
References dbFILE_::fp.
| int write_string | ( | const char * | s, | |
| dbFILE * | f | |||
| ) |
Write String
| ret | string | |
| dbFile | struct |
Definition at line 554 of file datafiles.c.
References dbFILE_::fp, and write_int16().
int curday = 0 [static] |
Definition at line 18 of file datafiles.c.
Referenced by backup_databases(), and ModuleDatabaseBackup().
time_t lastwarn = 0 [static] |
Definition at line 19 of file datafiles.c.
Referenced by open_db_read(), save_bs_dbase(), save_cs_dbase(), save_exceptions(), save_hs_dbase(), save_news(), save_ns_dbase(), save_ns_req_dbase(), and save_os_dbase().
1.7.1