Macros | Functions
DATA: Database for header cache

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...
 

Detailed Description

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.

Function Documentation

◆ db_add()

int db_add ( const char *  group,
core_anum_t  anum,
const char *  header,
size_t  len 
)

Add entry.

Parameters
[in]groupNewsgroup of article
[in]anumArticle ID
[in]headerPointer to article header
[in]lenLength of article header
Returns
  • 0 on success
  • Negative value on error

Definition at line 458 of file database.c.

◆ db_clear()

int db_clear ( void  )

Delete all database content.

Returns
  • 0 on success
  • Negative value on error

Definition at line 341 of file database.c.

◆ db_delete()

int db_delete ( const char *  group,
core_anum_t  start,
core_anum_t  end 
)

Delete entries.

Parameters
[in]groupNewsgroup of article
[in]startStart ID of article range
[in]endEnd 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.

Returns
  • 0 on success
  • Negative value on error

Definition at line 658 of file database.c.

References core_anum_t.

◆ db_exit()

int db_exit ( void  )

Shutdown database.

Returns
  • 0 on success
  • Negative value on error

Definition at line 317 of file database.c.

◆ db_init()

int db_init ( void  )

Init database.

Returns
  • 0 on success
  • Negative value on error

Definition at line 293 of file database.c.

◆ db_read()

int db_read ( const char *  group,
core_anum_t  anum,
char **  header,
size_t *  len 
)

Read entry.

Parameters
[in]groupNewsgroup of article
[in]anumArticle ID
[out]headerPointer to article header buffer
[out]lenPointer to length of article header buffer (not content!)

On success, the caller is responsible to free the memory allocated for the article header buffer.

Returns
  • 0 on success
  • Negative value on error

Definition at line 576 of file database.c.

◆ db_update_groups()

int db_update_groups ( size_t  groupcount,
const char **  grouplist 
)

Delete database content for all groups that are not specified.

Parameters
[in]groupcountNumber of group names in array grouplist
[in]grouplistArray 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 .

Returns
  • 0 on success
  • Negative value on error

Definition at line 375 of file database.c.


Generated at 2024-04-27 using  doxygen