Location of article header database: $XDG_CONFIG_HOME/$CFG_NAME/headers
.
More...
Macros | |
#define | MAIN_ERR_PREFIX "DATA: " |
Message prefix for DATABASE module. | |
#define | DB_PERM (posix_mode_t) (POSIX_S_IRUSR | POSIX_S_IWUSR) |
Permissions for database content files. | |
Functions | |
int | db_init (void) |
Init database. More... | |
int | db_exit (void) |
Shutdown database. More... | |
int | db_clear (void) |
Delete all database content. More... | |
int | db_update_groups (size_t groupcount, const char **grouplist) |
Delete database content for all groups that are not specified. More... | |
int | db_add (const char *group, core_anum_t anum, const char *header, size_t len) |
Add entry. More... | |
int | db_read (const char *group, core_anum_t anum, char **header, size_t *len) |
Read entry. More... | |
int | db_delete (const char *group, core_anum_t start, core_anum_t end) |
Delete entries. More... | |
Location of article header database: $XDG_CONFIG_HOME/$CFG_NAME/headers
.
This database use no special data structures, instead a subdirectory is created for every group. Inside this directory, for every entry a regular file that contains the article header is created with the article watermark as its name.
Every new entry is first written to a temporary file .tmp , then pushed to disk and finally merged into the database by atomically renaming the temporary file.
All this together makes this database slow and inefficient, but very robust. The data structures should never become damaged - even if the program crash while currently writing to the database it does not become corrupt and no special recovery is necessary to make it usable again.
int db_add | ( | const char * | group, |
core_anum_t | anum, | ||
const char * | header, | ||
size_t | len | ||
) |
Add entry.
[in] | group | Newsgroup of article |
[in] | anum | Article ID |
[in] | header | Pointer to article header |
[in] | len | Length of article header |
Definition at line 458 of file database.c.
int db_clear | ( | void | ) |
Delete all database content.
Definition at line 341 of file database.c.
int db_delete | ( | const char * | group, |
core_anum_t | start, | ||
core_anum_t | end | ||
) |
Delete entries.
[in] | group | Newsgroup of article |
[in] | start | Start ID of article range |
[in] | end | End ID of article range |
To delete all entries of group , specify both start and end as 0.
To delete anything from the beginning up to end, specify 1 for start and this function determines the first entry automatically without trying to delete (in worst case) billions of nonexistent entries one by one.
Definition at line 658 of file database.c.
References core_anum_t.
int db_exit | ( | void | ) |
Shutdown database.
Definition at line 317 of file database.c.
int db_init | ( | void | ) |
Init database.
Definition at line 293 of file database.c.
int db_read | ( | const char * | group, |
core_anum_t | anum, | ||
char ** | header, | ||
size_t * | len | ||
) |
Read entry.
[in] | group | Newsgroup of article |
[in] | anum | Article ID |
[out] | header | Pointer to article header buffer |
[out] | len | Pointer to length of article header buffer (not content!) |
On success, the caller is responsible to free the memory allocated for the article header buffer.
Definition at line 576 of file database.c.
int db_update_groups | ( | size_t | groupcount, |
const char ** | grouplist | ||
) |
Delete database content for all groups that are not specified.
[in] | groupcount | Number of group names in array grouplist |
[in] | grouplist | Array of group names |
If groupcount is zero, the database content for all groups is deleted. The parameter grouplist is ignored in this case and may be NULL
.
Definition at line 375 of file database.c.