Common definitions and functions. More...
Go to the source code of this file.
Defines | |
#define | RAWDATA_PTR void* |
A pointer to typeless binary data. | |
#define | RAWDATA_RPTR void** |
A pointer to returned typeless binary data. | |
#define | bool int |
In C-environment, define 'bool' as 'int'. | |
#define | PATH_SEP "/" |
The path separator used in pathnames. | |
#define | DLOG_TO_CONSOLE 17 |
A special value to give to init_dlogger to make all debug output in stdout. | |
#define | bare_file_name(s) strrchr(s,'/')?strrchr(s,'/')+1:s |
Return the file name part of a pathname. | |
#define | AEGIS_ERROR(format, args...) |
If defined, all error messages are printed to the stderr in stead of being logged. | |
#define | AEGIS_DEBUG(level, format, args...) |
Send a debug message to the dlog server. | |
#define | AEGIS_ENTER |
#define | AEGIS_EXIT |
#define | GETENV(name, deflt) ({char* c = getenv(name); c?c:deflt;}) |
Get environment value or the default if not found. | |
Typedefs | |
typedef int | aegis_callback (int nbr, void *item, void *context) |
A generic callback function type. A function of this type is called in the various iterate_*-functions in this library. | |
Functions | |
bool | file_exists (const char *name) |
Test if a file exists. | |
bool | directory_exists (const char *name) |
Test if a directory exists. | |
int | create_directory (const char *path, int mode) |
Create a new directory. Create also all missing intermediate directories in the path, if they do not exist already. | |
int | iterate_files (const char *in_directory, const char *matching_names, aegis_callback *cb_func, void *ctx) |
Iterate through the files in a directory. | |
void | init_dlogger (int enabled, int use_signal, int other_signal) |
Init debug logging. | |
void | dlog_message (const char *format,...) |
Send a debug or error message to the dlog. | |
const char * | dynhex (const void *d, size_t len) |
Return a hexdump of the given data. No need to allocate, but there can be at most 10 such strings in use at any point of time. They are released when to calling process terminates. | |
char * | base64_encode (const RAWDATA_PTR data, size_t len) |
Base-64 encode. | |
size_t | base64_decode (const char *string, RAWDATA_RPTR to_buf) |
Base-64 decode. |
Common definitions and functions.
#define AEGIS_DEBUG | ( | level, | ||
format, | ||||
args... | ||||
) |
Send a debug message to the dlog server.
level | (in) The detail level. Only those messages are actually printed thatb have the detail level less than or equal than the current value of the debug_level variable. | |
format,args | (in) Format string and a list of optional arguments as in "printf". |
#define AEGIS_ERROR | ( | format, | ||
args... | ||||
) |
do { \ syslog(LOG_ERR, "%s(%d): ERROR " format, \ bare_file_name(__FILE__), __LINE__ \ ,##args); \ } while (0)
If defined, all error messages are printed to the stderr in stead of being logged.
def AEGIS_SHOW_ERRORS This macro is undefined by default. You can define it in command line utilities.
Report an error to the dlog server.
format,args | Format string and a list of optional arguments as in "printf". |
#define bare_file_name | ( | s | ) | strrchr(s,'/')?strrchr(s,'/')+1:s |
Return the file name part of a pathname.
s | a path name |
#define GETENV | ( | name, | ||
deflt | ||||
) | ({char* c = getenv(name); c?c:deflt;}) |
Get environment value or the default if not found.
name | of the environment variable | |
deflt | of the environment variable |
#define RAWDATA_PTR void* |
A pointer to typeless binary data.
This data type is used as a parameter type with such arguments that refer to a given piece of memory, for instance data buffers given as input.
#define RAWDATA_RPTR void** |
A pointer to returned typeless binary data.
This data type is used as a parameter type with such arguments that the called function allocates a buffer for to return variable length output. All such values should be release by the caller with aegis_crypto_free when no longer needed.
typedef int aegis_callback(int nbr, void *item, void *context) |
A generic callback function type. A function of this type is called in the various iterate_*-functions in this library.
nbr | (in) The order number of the item, starting from 0 | |
item | (in) An item in the collection. The actual type depends on the type of the collection and is documentd for each iterate-function separately. | |
context | (in) A generic context pointer, relayed from the iterate-function call. |
size_t base64_decode | ( | const char * | string, | |
RAWDATA_RPTR | to_buf | |||
) |
Base-64 decode.
string | (in) base64 encoded NULL-terminated string | |
to_buf | (out) a pointer to a pointer to store the data use free to release when no longer needed. |
char* base64_encode | ( | const RAWDATA_PTR | data, | |
size_t | len | |||
) |
Base-64 encode.
data | (in) the data to be encoded | |
len | (in) length of data in bytes |
int create_directory | ( | const char * | path, | |
int | mode | |||
) |
Create a new directory. Create also all missing intermediate directories in the path, if they do not exist already.
path | (in) pathname of the directory | |
mode | (in) access control bits of the directory |
bool directory_exists | ( | const char * | name | ) |
Test if a directory exists.
name | (in) directory name |
const char* dynhex | ( | const void * | d, | |
size_t | len | |||
) |
Return a hexdump of the given data. No need to allocate, but there can be at most 10 such strings in use at any point of time. They are released when to calling process terminates.
d | (in) the data | |
len | (in) number of bytes |
bool file_exists | ( | const char * | name | ) |
Test if a file exists.
name | (in) filename |
void init_dlogger | ( | int | enabled, | |
int | use_signal, | |||
int | other_signal | |||
) |
Init debug logging.
enabled | (in) if zero or more, dispatch debug messages up to this level (LOG_ERR, LOG_WARN, LOG_DEBUG, LOG_INFO etc.). -1 means that all debug output is disabled. DLOG_TO_CONSOLE makes all debug output to be printed to stdout. | |
use_signal | (in) if non-zero, install a handler for the given signal to turn on debugging info on the fly. Usually SIGUSR1. | |
other_signal | (in) if use_signal was non-zero, this is the signal to turn off debugging info. SIGUSR2. |
int iterate_files | ( | const char * | in_directory, | |
const char * | matching_names, | |||
aegis_callback * | cb_func, | |||
void * | ctx | |||
) |
Iterate through the files in a directory.
in_directory | (in) the name of the directory | |
matching_names | (in) a regular expression matched against the filenames | |
cb_func | (in) a callback function which is called for each file in the given directory that has a name matching with the given expression. The item parameter is a NUL-terminated filename. | |
ctx | (in) the context pointer |