Qsmtp  0.23svn
Typedefs | Functions
include/control.h File Reference

headers of functions for control file handling More...

#include <sys/types.h>

Go to the source code of this file.

Typedefs

typedef int(* checkfunc )(const char *)

Functions

size_t lloadfilefd (int, char **, const int striptab)
int loadintfd (int, unsigned long *, const unsigned long def)
size_t loadoneliner (const char *, char **, const int optional)
size_t loadonelinerfd (int fd, char **buf)
int loadlistfd (int, char **, char ***, checkfunc)
int finddomainfd (int, const char *, const int)
int finddomainmm (const char *, const off_t, const char *)

Detailed Description

headers of functions for control file handling


Function Documentation

int finddomainfd ( int  fd,
const char *  domain,
const int  cl 
)

mmap a file and search a domain entry in it

Parameters:
fdfile descriptor
domaindomain name to find
clclose fd or not
Return values:
1on match
0if none
-1on error

trainling spaces and tabs in a line are ignored, lines beginning with '#' are ignored, CR in file will cause trouble

int finddomainmm ( const char *  map,
const off_t  size,
const char *  domain 
)

search a domain entry in a mmaped memory area

Parameters:
mapmemory region where file ist mmapped to
sizesize of mmapped area
domaindomain name to find
Return values:
1on match
0if none
-1on error

trailing spaces and tabs in a line are ignored, lines beginning with '#' are ignored, CR in file will cause trouble

size_t lloadfilefd ( int  fd,
char **  buf,
const int  striptab 
)

load a text file into a buffer using locked IO

Parameters:
fdfile descriptor of the file to load
bufthe contents of the file will go here, memory will be malloced
striptab2: strip trailing whitespace 1: compact {'\0'}* to a single '\0' 0: do nothing but load the file into the buffer
Returns:
length of buffer
Return values:
-1on error (errno is set)

if the file is empty (size 0 or only comments and blank lines) 0 is returned and buf is set to NULL

Warning:
if lloadfilefd can't get a lock on the input file (e.g. currently opened for writing by another process) the file is treated as non existent

The input file will be closed before this function returns.

striptab == 2 means: the only whitespace in a non-comment line may be immediately before the line break, in any amount.

int loadintfd ( int  fd,
unsigned long *  result,
const unsigned long  def 
)

read a control file containing a single integer

Parameters:
fdfile descriptor to read from (will be closed)
resultvalue will be stored here
defdefault value if file does not exist
Return values:
0on success
-1on error, parse errors in the file will set errno to EINVAL
int loadlistfd ( int  fd,
char **  buf,
char ***  bufa,
checkfunc  cf 
)

read a list from config file and validate entries

Parameters:
fdfile descriptor to read from (is closed on exit!)
bufthe buffer where the data should be stored (memory will be malloced)
bufaarray to be build from buf (memory will be malloced)
cffunction to check if an entry is valid or NULL if not to
Return values:
0on success
-1on error

if the file does not exist or has no content *buf and *bufa will be set to NULL

size_t loadoneliner ( const char *  filename,
char **  buf,
const int  optional 
)

read a configuration file that only may contain one line

Parameters:
filenamedon't know what this can ever mean ;)
bufthe buffer where the contents of the file will go, memory will be malloced
optionalif set to 0 write an error message to syslog if the file does not exist
Returns:
length of the string
Return values:
-1on error
size_t loadonelinerfd ( int  fd,
char **  buf 
)

read a configuration file that only may contain one line

Parameters:
fdopened file descriptor
bufthe buffer where the contents of the file will go, memory will be malloced
Returns:
length of the string
Return values:
-1on error

fd will be closed.