axa  2.2.0
Farsight Security Advanced Exchange Access (AXA)
axa_axa

Detailed Description

axa_axa contains top-level macros, datatype definitions and function declarations.

Data Structures

struct  axa_emsg_t
 AXA error message datatype. More...
 

Macros

#define AXA_DIM(_a)   ((int)((sizeof(_a) / sizeof((_a)[0]))))
 Return the number of elements in an array. More...
 
#define AXA_LAST(_a)   (&(_a)[AXA_DIM(_a)-1])
 Return a pointer to the last item of an array. More...
 
#define AXA_OFFSET(_p, _s, _t)
 Produce a pointer to a byte in a buffer that corresponds to a structure tag. More...
 
#define AXA_IS_WHITE(c)
 Test a char to see if it's whitespace. More...
 
#define AXA_IS_UPPER(c)   ({char _c = (c); _c >= 'A' && _c <= 'Z';})
 test if char is uppercase More...
 
#define AXA_IS_LOWER(c)   ({char _c = (c); _c >= 'a' && _c <= 'z';})
 test if char is lowercase More...
 
#define AXA_IS_DIGIT(c)   ({char _c = (c); _c >= '0' && _c <= '9';})
 test if char is base 10 digit More...
 
#define AXA_TO_LOWER(c)   ({char _l = (c); AXA_IS_UPPER(_l) ? (_l+'a'-'A') : _l;})
 convert char to lowercase More...
 
#define AXA_TO_UPPER(c)   ({char _u = (c); AXA_IS_LOWER(_u) ? (_u-'a'-'A') : _u;})
 convert char to uppercase More...
 
#define AXA_UNUSED   __attribute__((unused))
 Tell the compiler not to complain about an unused parameter. More...
 
#define AXA_PF(f, l)   __attribute__((format(printf,f,l)))
 Tell the compiler to check an actual format string against the other actual parameters. More...
 
#define AXA_NORETURN   __attribute__((__noreturn__))
 Tell the compiler that this function will never return. More...
 
#define dcl_max(a, b)   ((a) >= (b) ? (a) : (b))
 Return the larger of two scalar values. More...
 
#define AXA_CLITCMP(_b, _s)   (strncasecmp((_b), (_s), sizeof(_s)-1) == 0)
 Case compare two NULL terminated strings, comparing at most sizeof(_s - 1) characters. More...
 
#define AXA_SALLOC(t)   ((t *)axa_zalloc(sizeof(t)))
 A calloc() wrapper that returns zero-filled memory of size sizeof (t) that is cast to (t *). More...
 
#define AXA_DEBUG_WATCH   2
 generate trace syslog messages about watches, anomalies, and channels More...
 
#define AXA_DEBUG_TRACE   3
 also generate trace syslog messages about client AXA messages and non-routine AXA messages More...
 
#define AXA_DEBUG_MORE_TRACE   4
 also generate trace syslog messages about routine AXA messages and transport related messages such as from ssh More...
 
#define AXA_DEBUG_NMSG   5
 also generate trace syslog messages from libnmsg and client-to-server rate limiting or congestion More...
 
#define AXA_DEBUG_TO_NMSG(lvl)
 convert AXA debug level to NMSG debug level More...
 
#define AXA_DEBUG_MAX   10
 maximum debugging level More...
 
#define AXA_ASSERT_MSG(c, p, ...)
 Crash with a message if a condition is false. More...
 
#define AXA_ASSERT(c)   AXA_ASSERT_MSG((c), "\""#c"\" is false")
 Crash if a condition is false. More...
 
#define AXA_FAIL(...)   axa_fatal_msg(0, __VA_ARGS__)
 Crash with a message. More...
 
#define AXA_DAY_SECS   (24*60*60)
 one day of seconds More...
 
#define AXA_DAY_MS   (AXA_DAY_SECS*1000)
 one day of milliseconds More...
 

Enumerations

enum  axa_syslog_type_t
 AXA syslog types. More...
 

Functions

const char * axa_domain_to_str (const uint8_t *src, size_t src_len, char *dst, size_t dst_len)
 Convert a domain name to a canonical string. More...
 
void * axa_malloc (size_t s)
 A malloc() wrapper that crashes immediately (via AXA_ASSERT()) on malloc failures. More...
 
void * axa_zalloc (size_t s)
 A calloc() wrapper that crashes immediately (via AXA_ASSERT()) on malloc failures. More...
 
char * axa_strdup (const char *s)
 A strdup() wrapper that crashes immediately (via AXA_ASSERT()) on failure. More...
 
char * axa_strndup (const char *s, size_t len)
 A strndup() wrapper that crashes immediately (via AXA_ASSERT()) on failure. More...
 
void axa_vasprintf (char **bufp, const char *p, va_list args)
 A vasprintf() wrapper that crashes immediately (via AXA_ASSERT()) on vasprintf failures. More...
 
void axa_asprintf (char **bufp, const char *p,...) AXA_PF(2
 An asprintf() wrapper that crashes immediately (via AXA_ASSERT()) on asprintf failures. More...
 
void void axa_set_core (void)
 Try to enable core files. More...
 
void axa_set_me (const char *me)
 Set the global program name before axa_syslog_init() is called. More...
 
bool axa_parse_log_opt (axa_emsg_t *emsg, const char *arg)
 Parse and set logging options before calling axa_syslog_init() More...
 
void axa_syslog_init (void)
 Initialize the AXA syslog interface. More...
 
void axa_buf_print (char **bufp, size_t *buf_lenp, const char *p,...) AXA_PF(3
 Add text to an error or other message buffer. More...
 
void void axa_clean_stdio (void)
 prevent surprises via use of stdio FDs by ensuring that the FDs are open to at least /dev/null More...
 
void axa_vpemsg (axa_emsg_t *emsg, const char *msg, va_list args)
 Generate an error message string in a buffer, if we have a buffer. More...
 
void axa_pemsg (axa_emsg_t *emsg, const char *msg,...) AXA_PF(2
 axa_vpemsg() wrapper using the variadic stdarg macros (va_start(), va_end()). More...
 
void axa_vlog_msg (axa_syslog_type_t type, bool fatal, const char *p, va_list args)
 Log an AXA message. More...
 
void axa_verror_msg (const char *p, va_list args)
 Log or print an error message. More...
 
void axa_error_msg (const char *p,...) AXA_PF(1
 Log or print an error message. More...
 
void void axa_io_error (const char *op, const char *src, ssize_t len)
 Log an error message for an I/O function that has returned either a negative read or write length or the wrong length. More...
 
void axa_vtrace_msg (const char *p, va_list args)
 Log a trace message in the tracing syslog stream as opposed to the error syslog stream. More...
 
void axa_trace_msg (const char *p,...) AXA_PF(1
 Log a trace message in the tracing stream or AXA_SYSLOG_TRACE as opposed to the error or AXA_SYSLOG_ERROR stream. More...
 
void void axa_vfatal_msg (int ex_code, const char *p, va_list args) AXA_NORETURN
 Log a serious error message and either exit with a specified exit code or crash if the exit code is EX_SOFTWARE. More...
 
void axa_fatal_msg (int ex_code, const char *p,...) AXA_PF(2
 Log a serious error message and either exit with a specified exit code or crash if the exit code is EX_SOFTWARE. More...
 
char * axa_fgetln (FILE *f, const char *file_name, uint *line_num, char **bufp, size_t *buf_sizep)
 Get a logical line from a stdio stream, with leading and trailing whitespace trimmed and "\\\n" deleted as a continuation. More...
 
const char * axa_strip_white (const char *str, size_t *lenp)
 Strip leading and trailing white space. More...
 
ssize_t axa_get_token (char *token, size_t token_len, const char **stringp, const char *seps)
 Copy the next token from a string to a buffer and return the size of the string put into the buffer. More...
 
uint32_t axa_hash_divisor (uint32_t initial, bool smaller)
 Get a modulus for a hash function that is tolerably likely to be relatively prime to most inputs. More...
 
bool axa_parse_ch (axa_emsg_t *emsg, uint16_t *chp, const char *str, size_t str_len, bool all_ok, bool number_ok)
 Parse a channel string into a binary channel in host byte order. More...
 
time_t axa_tv_diff2ms (const struct timeval *tv1, const struct timeval *tv2)
 Compute (tv1 - tv2) in milliseconds, but limited or clamped to 1 day. More...
 
time_t axa_elapsed_ms (const struct timeval *now, struct timeval *then)
 Compute the positive elapsed time between two timevals in milliseconds, but limited or clamped to at least 0 ms and at most 1 day. More...
 
const char * axa_get_version (void)
 Retrieve the semantic library version as a string. More...
 
uint32_t axa_get_version_number (void)
 Retrieve the semantic library version as a packed integer. More...
 

Variables

void AXA_NORETURN
 

Macro Definition Documentation

◆ AXA_DIM

#define AXA_DIM (   _a)    ((int)((sizeof(_a) / sizeof((_a)[0]))))

Return the number of elements in an array.

Parameters
[in]_athe array to size up
Returns
the size of the array as an int instead of size_t

◆ AXA_LAST

#define AXA_LAST (   _a)    (&(_a)[AXA_DIM(_a)-1])

Return a pointer to the last item of an array.

Parameters
[in]_athe array containing the item
Returns
a pointer to the last item

◆ AXA_OFFSET

#define AXA_OFFSET (   _p,
  _s,
  _t 
)
Value:
((uint8_t *)(_p) \
+ ((uint8_t *)&((_s *)0)->_t - (uint8_t *)0))

Produce a pointer to a byte in a buffer that corresponds to a structure tag.

This works where a cast to the structure would not work or would give the wrong answer because of word mis-alignment of the buffer or other reasons.

Parameters
[in]_ppointer to source data
[in]_sname of desired structure
[in]_tdesired tag in the structure
Return values
pointerto byte in source data corresponding to the tag. The pointer might not be properly aligned.

◆ AXA_IS_WHITE

#define AXA_IS_WHITE (   c)
Value:
({char _c = (c); _c == ' ' || _c == '\t' \
|| _c == '\r' || _c == '\n';})

Test a char to see if it's whitespace.

AXA ignores locales to get consistent results on all systems, and because the AXA control files are ASCII.

Parameters
[in]cchar to test
Return values
1if whitespace
0if not

◆ AXA_IS_UPPER

#define AXA_IS_UPPER (   c)    ({char _c = (c); _c >= 'A' && _c <= 'Z';})

test if char is uppercase

Parameters
[in]cchar to test
Return values
1if uppercase char
0if not

◆ AXA_IS_LOWER

#define AXA_IS_LOWER (   c)    ({char _c = (c); _c >= 'a' && _c <= 'z';})

test if char is lowercase

Parameters
[in]cchar to test
Return values
1if lowercase
0if not

◆ AXA_IS_DIGIT

#define AXA_IS_DIGIT (   c)    ({char _c = (c); _c >= '0' && _c <= '9';})

test if char is base 10 digit

Parameters
[in]cchar to test
Return values
1if base 10 digit
0if not

◆ AXA_TO_LOWER

#define AXA_TO_LOWER (   c)    ({char _l = (c); AXA_IS_UPPER(_l) ? (_l+'a'-'A') : _l;})

convert char to lowercase

Parameters
[in]cchar to convert
Returns
the converted char if it was previously uppercase, c if not

◆ AXA_TO_UPPER

#define AXA_TO_UPPER (   c)    ({char _u = (c); AXA_IS_LOWER(_u) ? (_u-'a'-'A') : _u;})

convert char to uppercase

Parameters
[in]cchar to convert
Returns
the converted char if it was previously lowercase, c if not

◆ AXA_UNUSED

#define AXA_UNUSED   __attribute__((unused))

Tell the compiler not to complain about an unused parameter.

◆ AXA_PF

#define AXA_PF (   f,
 
)    __attribute__((format(printf,f,l)))

Tell the compiler to check an actual format string against the other actual parameters.

Parameters
[in]fthe number of the "format string" parameter
[in]lthe number of the first variadic parameter

◆ AXA_NORETURN

#define AXA_NORETURN   __attribute__((__noreturn__))

Tell the compiler that this function will never return.

◆ dcl_max

#define dcl_max (   a,
 
)    ((a) >= (b) ? (a) : (b))

Return the larger of two scalar values.

This macro is for declarations where ({}) is not allowed and side effects can't happen.

Parameters
[in]afirst value to compare
[in]bsecond value to compare
Returns
the larger of the two values, if they are equal, return a

◆ AXA_CLITCMP

#define AXA_CLITCMP (   _b,
  _s 
)    (strncasecmp((_b), (_s), sizeof(_s)-1) == 0)

Case compare two NULL terminated strings, comparing at most sizeof(_s - 1) characters.

Parameters
[in]_bconst char * first, not necessarily null terminated string to compare
[in]_sconst char * null terminated second string to compare
Returns
same semantics as strncasecmp()

◆ AXA_SALLOC

#define AXA_SALLOC (   t)    ((t *)axa_zalloc(sizeof(t)))

A calloc() wrapper that returns zero-filled memory of size sizeof (t) that is cast to (t *).

Parameters
[in]tobject to allocate memory for
Returns
pointer to the allocated memory

◆ AXA_DEBUG_WATCH

#define AXA_DEBUG_WATCH   2

generate trace syslog messages about watches, anomalies, and channels

◆ AXA_DEBUG_TRACE

#define AXA_DEBUG_TRACE   3

also generate trace syslog messages about client AXA messages and non-routine AXA messages

◆ AXA_DEBUG_MORE_TRACE

#define AXA_DEBUG_MORE_TRACE   4

also generate trace syslog messages about routine AXA messages and transport related messages such as from ssh

◆ AXA_DEBUG_NMSG

#define AXA_DEBUG_NMSG   5

also generate trace syslog messages from libnmsg and client-to-server rate limiting or congestion

◆ AXA_DEBUG_TO_NMSG

#define AXA_DEBUG_TO_NMSG (   lvl)
Value:
nmsg_set_debug((lvl) <= AXA_DEBUG_NMSG \
? 0 : ((lvl)-AXA_DEBUG_NMSG))

convert AXA debug level to NMSG debug level

◆ AXA_DEBUG_MAX

#define AXA_DEBUG_MAX   10

maximum debugging level

◆ AXA_ASSERT_MSG

#define AXA_ASSERT_MSG (   c,
  p,
  ... 
)
Value:
((c) ? 0 \
: axa_fatal_msg(0, __FILE__":%d " p, \
__LINE__, ##__VA_ARGS__))

Crash with a message if a condition is false.

AXA_ASSERT_MSG() can have required side effects such as stopping on a fatal condition, and so cannot be #ifdef'ed out.

Parameters
[in]ccondition to assert
[in]ppattern or message
[in]...optional variadic arguments for pattern parameters)

◆ AXA_ASSERT

#define AXA_ASSERT (   c)    AXA_ASSERT_MSG((c), "\""#c"\" is false")

Crash if a condition is false.

AXA_ASSERT() can have required side effects, usually stopping on a fatal condition.

Parameters
[in]ccondition to assert

◆ AXA_FAIL

#define AXA_FAIL (   ...)    axa_fatal_msg(0, __VA_ARGS__)

Crash with a message.

Parameters
[in]...variadic arguments

◆ AXA_DAY_SECS

#define AXA_DAY_SECS   (24*60*60)

one day of seconds

◆ AXA_DAY_MS

#define AXA_DAY_MS   (AXA_DAY_SECS*1000)

one day of milliseconds

Enumeration Type Documentation

◆ axa_syslog_type_t

AXA syslog types.

Enumerator
AXA_SYSLOG_TRACE 

trace

AXA_SYSLOG_ERROR 

error

AXA_SYSLOG_ACCT 

accounting

Function Documentation

◆ axa_domain_to_str()

const char* axa_domain_to_str ( const uint8_t *  src,
size_t  src_len,
char *  dst,
size_t  dst_len 
)

Convert a domain name to a canonical string.

Sane wrapper for wdns_domain_to_str(). dst_len must be >=NS_MAXDNAME because wdns_domain_to_str() does not check.

Parameters
[in]srcdomain name in wire format
[in]src_lenlength of domain name in bytes
[out]dstcaller allocated string buffer that should be of size NS_MAXDNAME
[in]dst_lensize of the dst buffer
Returns
the value of dst

◆ axa_malloc()

void* axa_malloc ( size_t  s)

A malloc() wrapper that crashes immediately (via AXA_ASSERT()) on malloc failures.

Parameters
[in]ssize of memory to allocate
Returns
pointer to the allocated memory

◆ axa_zalloc()

void* axa_zalloc ( size_t  s)

A calloc() wrapper that crashes immediately (via AXA_ASSERT()) on malloc failures.

The memory region will be zero-filled.

Parameters
[in]ssize of memory to allocate
Returns
pointer to the allocated memory

◆ axa_strdup()

char* axa_strdup ( const char *  s)

A strdup() wrapper that crashes immediately (via AXA_ASSERT()) on failure.

The caller must free() the result.

Parameters
[in]sthe string to duplicate
Returns
pointer to the duplicated string

◆ axa_strndup()

char* axa_strndup ( const char *  s,
size_t  len 
)

A strndup() wrapper that crashes immediately (via AXA_ASSERT()) on failure.

The caller must free() the result.

Parameters
[in]sthe string to duplicate
[in]lenlength of string
Returns
pointer to the duplicated string

◆ axa_vasprintf()

void axa_vasprintf ( char **  bufp,
const char *  p,
va_list  args 
)

A vasprintf() wrapper that crashes immediately (via AXA_ASSERT()) on vasprintf failures.

When you're done with it, bufp should be freed.

Parameters
[out]bufpa pointer to the newly minted and formatted string
[in]pthe format string
[in]argsa var args list

◆ axa_asprintf()

void axa_asprintf ( char **  bufp,
const char *  p,
  ... 
)

An asprintf() wrapper that crashes immediately (via AXA_ASSERT()) on asprintf failures.

When you're done with it, bufp should be freed.

Parameters
[out]bufpa pointer to the newly minted and formatted string
[in]pthe format string
[in]...a var args list

◆ axa_set_core()

void void axa_set_core ( void  )

Try to enable core files.

Wraps getrlimit() and setrlimit().

◆ axa_set_me()

void axa_set_me ( const char *  me)

Set the global program name before axa_syslog_init() is called.

Parameters
[in]meargv[0]

◆ axa_parse_log_opt()

bool axa_parse_log_opt ( axa_emsg_t emsg,
const char *  arg 
)

Parse and set logging options before calling axa_syslog_init()

Parameters
[out]emsgerror message if something is wrong
[in]argcomma separated string with the following options: {trace|error|acct},{off|FACILITY.LEVEL}[,{none,stderr,stdout}] {trace|error|acct} selects one of three streams of information "off" or "FACILITY.LEVEL" disable or turn on syslog for the chosen "trace", "error" and "acct" streams. {none,stderr,stdout} directs the stream independently of how it is sent to the system log. A stream can be sent to either, both, or neither the system log and stderr or stdout.

The following settings for "trace", "error" and "acct" are assumed to send the "trace" and "error" streams to the system log and stderr and the "acct" stream to only the system log: trace,LOG_DEBUG.LOG_DAEMON error.LOG_ERR,LOG_DAEMON acct,LOG_NOTICE.LOG_AUTH,none

Return values
trueif string is valid
falseif not

◆ axa_syslog_init()

void axa_syslog_init ( void  )

Initialize the AXA syslog interface.

Call this function after calling axa_parse_log_opt() and axa_set_me(), and before calling any AXA logging, accounting, or tracing function.

◆ axa_buf_print()

void axa_buf_print ( char **  bufp,
size_t *  buf_lenp,
const char *  p,
  ... 
)

Add text to an error or other message buffer.

If we run out of room, add "...".

Parameters
[in,out]bufpin: the original string, out: the concatenated strings
[in,out]buf_lenpin: the length of bufp string, out: new length
[in]pthe format string to copy over
[in]...va_args business

◆ axa_clean_stdio()

void void axa_clean_stdio ( void  )

prevent surprises via use of stdio FDs by ensuring that the FDs are open to at least /dev/null

◆ axa_vpemsg()

void axa_vpemsg ( axa_emsg_t emsg,
const char *  msg,
va_list  args 
)

Generate an error message string in a buffer, if we have a buffer.

Log or print the message with axa_vlog_msg() if there is no buffer.

Parameters
[out]emsgif something goes wrong, this will contain the reason
[in]msgmessage
[in]argsarguments to p

◆ axa_pemsg()

void axa_pemsg ( axa_emsg_t emsg,
const char *  msg,
  ... 
)

axa_vpemsg() wrapper using the variadic stdarg macros (va_start(), va_end()).

Parameters
[out]emsgif something goes wrong, this will contain the reason
[in]msgmessage
[in]...variable length argument list

◆ axa_vlog_msg()

void axa_vlog_msg ( axa_syslog_type_t  type,
bool  fatal,
const char *  p,
va_list  args 
)

Log an AXA message.

Depending on type and calls to axa_parse_log_opt(), this function could write to stdout stderr, and/or syslog.

Parameters
[in]typeone of axa_syslog_type_t
[in]fatalif true and fatal verbiage will be prepended to message
[in]pmessage
[in]argsvariadic argument list

◆ axa_verror_msg()

void axa_verror_msg ( const char *  p,
va_list  args 
)

Log or print an error message.

This is a wrapper for axa_vlog_msg() with type of AXA_SYSLOG_ERROR with fatal == false.

Parameters
[in]pmessage
[in]argsvariadic argument list

◆ axa_error_msg()

void axa_error_msg ( const char *  p,
  ... 
)

Log or print an error message.

This is a variadic wrapper for axa_vlog_msg() with type of AXA_SYSLOG_ERROR with fatal == false.

Parameters
[in]pmessage
[in]...variable length argument list

◆ axa_io_error()

void void axa_io_error ( const char *  op,
const char *  src,
ssize_t  len 
)

Log an error message for an I/O function that has returned either a negative read or write length or the wrong length.

Complain about a non-negative length or decode errno for a negative length.

Parameters
[in]opcanonical string referring to the I/O event that caused the error
[in]srcerror message
[in]lenlength of src

◆ axa_vtrace_msg()

void axa_vtrace_msg ( const char *  p,
va_list  args 
)

Log a trace message in the tracing syslog stream as opposed to the error syslog stream.

Parameters
[in]pmessage
[in]argsvariadic argument list

◆ axa_trace_msg()

void axa_trace_msg ( const char *  p,
  ... 
)

Log a trace message in the tracing stream or AXA_SYSLOG_TRACE as opposed to the error or AXA_SYSLOG_ERROR stream.

Parameters
[in]pmessage
[in]...variable length argument list

◆ axa_vfatal_msg()

void void axa_vfatal_msg ( int  ex_code,
const char *  p,
va_list  args 
)

Log a serious error message and either exit with a specified exit code or crash if the exit code is EX_SOFTWARE.

Parameters
[in]ex_codeexit code
[in]pmessage
[in]argsvariadic argument list

◆ axa_fatal_msg()

void axa_fatal_msg ( int  ex_code,
const char *  p,
  ... 
)

Log a serious error message and either exit with a specified exit code or crash if the exit code is EX_SOFTWARE.

Parameters
[in]ex_codeexit code
[in]pour last words
[in]...va_args business

◆ axa_fgetln()

char* axa_fgetln ( FILE *  f,
const char *  file_name,
uint *  line_num,
char **  bufp,
size_t *  buf_sizep 
)

Get a logical line from a stdio stream, with leading and trailing whitespace trimmed and "\\\n" deleted as a continuation.

If the buffer is NULL or it is not big enough, it is freed and a new buffer is allocated. This must be freed by the caller after the last use of this function.

Except at error or EOF, the start of the next line is returned, which might not be at the start of the buffer.

Parameters
[in]fthe file to read from (for error reporting)
[in]file_namename of the file (for error reporting)
[in,out]line_numline number of file, will be progressively updated
[in,out]bufpbuffer to store line, can be NULL
[in,out]buf_sizepsize of buffer pointed to by bufp
Returns
The return value is NULL and emsg->c[0]=='\0' at EOF or NULL and emsg->c[0]!='\0' after an error.

◆ axa_strip_white()

const char* axa_strip_white ( const char *  str,
size_t *  lenp 
)

Strip leading and trailing white space.

Parameters
[in,out]strin: string to cleanse, out: cleansed string
[in,out]lenpin: length of the string, out: new length
Returns
the string cleansed of whitespace

◆ axa_get_token()

ssize_t axa_get_token ( char *  token,
size_t  token_len,
const char **  stringp,
const char *  seps 
)

Copy the next token from a string to a buffer and return the size of the string put into the buffer.

Honor quotes and backslash. The caller must skip leading token separators (e.g. blanks) if necessary. When the separators include whitespace and whitespace ends the token, then all trailing whitespace is skipped.

Parameters
[in,out]tokentoken goes here
[in,out]token_lenlength of the token
[in,out]stringpinput string
[in,out]sepsstring of token separators
Returns
the size of the string, -1 on error

◆ axa_hash_divisor()

uint32_t axa_hash_divisor ( uint32_t  initial,
bool  smaller 
)

Get a modulus for a hash function that is tolerably likely to be relatively prime to most inputs.

We get a prime for initial values not larger than 1 million. We often get a prime after that. This works well in practice for hash tables up to at least 100 million and better than a multiplicative hash.

The algorithm starts by finding either the smallest prime number that is larger than the initial parameter value and not larger than 1009 or the largest prime smaller than the initial value and not larger than 1009. The algorithm is finished if the initial value is at most 1009. Otherwise, it finds the smallest (or largest) number that is relatively prime to all prime numbers <=1009.

Parameters
[in]initialis the starting point for searching for number with no small divisors. That is usually the previous size of an expanding hash table or the initial guess for a new hash table.
[in]smallerfalse if you want a value smaller than the initial value.
Returns
the modulus

◆ axa_parse_ch()

bool axa_parse_ch ( axa_emsg_t emsg,
uint16_t *  chp,
const char *  str,
size_t  str_len,
bool  all_ok,
bool  number_ok 
)

Parse a channel string into a binary channel in host byte order.

Parameters
[out]emsgif something goes wrong, this will contain the reason
[out]chppointer to a axa_p_ch_t channel in host byte order
[in,out]strstring containing channel number or "all" keyword
[in,out]str_lenlength of str
[in]all_okboolean indicating "all" is allowed
[in]number_okboolean indicating "202 is the same as ch202"
Return values
trueif no errors were encountered, chp will contain the channel
falseerror was was encountered, emsg will contain the reason

◆ axa_tv_diff2ms()

time_t axa_tv_diff2ms ( const struct timeval *  tv1,
const struct timeval *  tv2 
)

Compute (tv1 - tv2) in milliseconds, but limited or clamped to 1 day.

Parameters
[in]tv1const struct timeval * to first time value
[in]tv2const struct timeval * to second time value
Returns
the difference between the two tv_sec values, in ms

◆ axa_elapsed_ms()

time_t axa_elapsed_ms ( const struct timeval *  now,
struct timeval *  then 
)

Compute the positive elapsed time between two timevals in milliseconds, but limited or clamped to at least 0 ms and at most 1 day.

Negative elapsed time implies that the system clock was set back. In that case, set the 'then' timestamp to 'now' and return 0.

Parameters
[in]nowconst struct timeval * current time
[in]thenstruct timeval * past value, which will be set to the current time if it in the future of the current time.
Returns
the difference between the two tv_sec values, in ms

◆ axa_get_version()

const char* axa_get_version ( void  )

Retrieve the semantic library version as a string.

◆ axa_get_version_number()

uint32_t axa_get_version_number ( void  )

Retrieve the semantic library version as a packed integer.

The number is a combination of the major, minor, and patchelevel numbers as per: MAJOR * 1000000 + MINOR * 1000 + PATCHLEVEL.