smf_core.h File Reference

Various helper functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * smf_core_strstrip (char *s)
 Removes leading and trailing whitespace from a string. This function doesn't allocate or reallocate any memory; it modifies string in place. The pointer to string is returned to allow the nesting of functions.
 
char * smf_core_strlwc (char *s)
 Convert a string to lowercase.
 
char * smf_core_strcat_printf (char **s, const char *fmt,...)
 Append format string to string and reallocate memory. The pointer to string is returned to allow the nesting of functions.
 
char ** smf_core_strsplit (const char *s, char *sep, int *nelems)
 Split a given string.
 
int smf_core_gen_queue_file (const char *queue_dir, char **tempname, const char *sid)
 Generate a new queue file name.
 
char * smf_core_md5sum (const char *data)
 Generate md5 hexdigest for string.
 
char * smf_core_get_maildir_filename (void)
 Generates a unique maildir filename.
 
int smf_core_expand_string (const char *format, const char *addr, char **buf)
 expands placeholders in a user querystring
 
int smf_core_copy_file (const char *source, const char *dest)
 Copies the content of the source file into dest.
 
int smf_core_copy_to_fd (const char *source, int dest)
 Copies the content of the source file into an already open file-descriptor. This function is similar to smf_core_copy_file(). But rather than opening the destination file, this function uses an already open file-descriptor as a destination.
 

Detailed Description

Various helper functions.

Function Documentation

int smf_core_copy_file ( const char *  source,
const char *  dest 
)

Copies the content of the source file into dest.

Parameters
sourcePath of the source file
destPath of the destination file. If file already exists, then the current content is replaced with the content of the source file.
Returns
the number of bytes copied
int smf_core_copy_to_fd ( const char *  source,
int  dest 
)

Copies the content of the source file into an already open file-descriptor. This function is similar to smf_core_copy_file(). But rather than opening the destination file, this function uses an already open file-descriptor as a destination.

Parameters
sourcePath of the source file
destOn open file-descriptior, where the content is written into.
Returns
the number of bytes copied
int smf_core_expand_string ( const char *  format,
const char *  addr,
char **  buf 
)

expands placeholders in a user querystring

Parameters
formatformat string to use as input
addremail address to use for replacements
bufpointer to unallocated buffer for expanded format string, needs to free'd by caller if not required anymore
Returns
the number of replacements made or -1 in case of error
int smf_core_gen_queue_file ( const char *  queue_dir,
char **  tempname,
const char *  sid 
)

Generate a new queue file name.

Parameters
queue_dirpath to queue directory
tempnamepointer to unallocated buffer for filename, needs to free'd by caller if not required anymore
sidcurrent session id
Returns
0 on success or -1 in case of error
char* smf_core_get_maildir_filename ( void  )

Generates a unique maildir filename.

Returns
newly allocated pointer with generated filename or NULL in case of error
char* smf_core_md5sum ( const char *  data)

Generate md5 hexdigest for string.

Parameters
dataString to generate md5sum for
Returns
Pointer to hexdigest string on success, NULL on error
char* smf_core_strcat_printf ( char **  s,
const char *  fmt,
  ... 
)

Append format string to string and reallocate memory. The pointer to string is returned to allow the nesting of functions.

Parameters
sstring to append to
fmtformat string
Returns
new appended string
char* smf_core_strlwc ( char *  s)

Convert a string to lowercase.

Parameters
sString to convert.
Returns
ptr to string
char** smf_core_strsplit ( const char *  s,
char *  sep,
int *  nelems 
)

Split a given string.

Parameters
sString to split
sepseparator
nelemsIf set to non-NULL, then the function stores here the number of elements in the resulting array.
Returns
a newly-allocated NULL-terminated array of strings.
char* smf_core_strstrip ( char *  s)

Removes leading and trailing whitespace from a string. This function doesn't allocate or reallocate any memory; it modifies string in place. The pointer to string is returned to allow the nesting of functions.

Parameters
sString to parse.
Returns
intput string