Commit 54eba552 authored by Shawn Webb's avatar Shawn Webb
Browse files

Add auxiliary members to the config, log, and sqlite3 context objects



Applications that consumes these objects may want to attach arbitrary
data to them. The liblattutil library will never make use of these
members.
Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent 3e9c6672
......@@ -58,12 +58,16 @@ typedef struct _llconfig {
int l_fd;
struct ucl_parser *l_parser;
const ucl_object_t *l_rootobj;
void *l_aux;
size_t l_auxsz;
} lattutil_config_path_t;
typedef struct _lllog {
uint64_t ll_version;
int ll_verbosity;
char *ll_path;
void *ll_aux;
size_t ll_auxsz;
log_cb ll_log_debug;
log_cb ll_log_err;
......@@ -79,6 +83,8 @@ typedef struct _lattutil_sql_ctx {
char *lsq_path;
uint64_t lsq_flags;
lattutil_log_t *lsq_logger;
void *lsq_aux;
size_t lsq_auxsz;
} lattutil_sqlite_ctx_t;
typedef struct _lattutil_sql_res {
......@@ -127,6 +133,25 @@ lattutil_config_path_t *lattutil_find_config(const char **, size_t, const char *
*/
void lattutil_free_config_path(lattutil_config_path_t **);
/**
* Set the auxiliary members of the config context object
*
* @param The config object
* @param The auxiliary data
* @param The size of the auxiliary data
*/
void lattutil_config_set_aux(lattutil_config_path_t *, void *, size_t);
/**
* Get the auxiliary members of the config context object
*
* @param The config object
* @param[out] Optional output variable to store the recorded size of
* the auxiliary member.
* @return The auxiliary member
*/
void *lattutil_config_get_aux(lattutil_config_path_t *, size_t *);
/**
* Get the ABI version of the config path object
*
......@@ -251,6 +276,25 @@ int lattutil_log_verbosity(lattutil_log_t *);
*/
int lattutil_log_set_verbosity(lattutil_log_t *, int);
/**
* Set the auxiliary members of the logging context object
*
* @param The logging object
* @param The auxiliary data
* @param The size of the auxiliary data
*/
void lattutil_log_set_aux(lattutil_log_t *, void *, size_t);
/**
* Get the auxiliary members of the logging context object
*
* @param The logging object
* @param[out] Optional output variable to store the recorded size of
* the auxiliary member.
* @return The auxiliary member
*/
void *lattutil_log_get_aux(lattutil_log_t *, size_t *);
/**
* Create new SQLite3 context object
*
......@@ -263,19 +307,38 @@ lattutil_sqlite_ctx_t *lattutil_sqlite_ctx_new(const char *, lattutil_log_t *,
uint64_t);
/**
* Get the ABI version number of the sqlite wrapper
* Free The SQLite3 context object
*
* @param The lattutil sqlite context object
* @return The ABI version number
* @param Double pointer to the context object
*/
uint64_t lattutil_sqlite_get_version(lattutil_sqlite_ctx_t *);
void lattutil_sqlite_ctx_free(lattutil_sqlite_ctx_t **);
/**
* Free The SQLite3 context object
* Set the auxiliary members of the sqlite context object
*
* @param Double pointer to the context object
* @param The sqlite context object
* @param The auxiliary data
* @param The size of the auxiliary data
*/
void lattutil_sqlite_ctx_free(lattutil_sqlite_ctx_t **);
void lattutil_sqlite_ctx_set_aux(lattutil_sqlite_ctx_t *, void *, size_t);
/**
* Get the auxiliary members of the sqlite context object
*
* @param The sqlite context object
* @param[out] Optional output variable to store the recorded size of
* the auxiliary member.
* @return The auxiliary member
*/
void *lattutil_sqlite_ctx_get_aux(lattutil_sqlite_ctx_t *, size_t *);
/**
* Get the ABI version number of the sqlite wrapper
*
* @param The lattutil sqlite context object
* @return The ABI version number
*/
uint64_t lattutil_sqlite_get_version(lattutil_sqlite_ctx_t *);
/**
* Prepare a new query
......
......@@ -123,6 +123,35 @@ lattutil_free_config_path(lattutil_config_path_t **obj)
*obj = NULL; /* Prevent UAF */
}
EXPORTED_SYM
void
lattutil_config_set_aux(lattutil_config_path_t *obj, void *aux, size_t sz)
{
if (obj == NULL) {
return;
}
obj->l_aux = aux;
obj->l_auxsz = sz;
}
EXPORTED_SYM
void *
lattutil_config_get_aux(lattutil_config_path_t *obj, size_t *sz)
{
if (obj == NULL) {
return (NULL);
}
if (sz != NULL) {
*sz = obj->l_auxsz;
}
return (obj->l_aux);
}
EXPORTED_SYM
uint64_t
lattutil_config_get_version(lattutil_config_path_t *obj)
......
......@@ -143,3 +143,32 @@ lattutil_log_set_verbosity(lattutil_log_t *logp, int verbosity)
return (old);
}
EXPORTED_SYM
void
lattutil_log_set_aux(lattutil_log_t *logp, void *aux, size_t auxsz)
{
if (logp == NULL) {
return;
}
logp->ll_aux = aux;
logp->ll_auxsz = auxsz;
}
EXPORTED_SYM
void *
lattutil_log_get_aux(lattutil_log_t *logp, size_t *auxsz)
{
if (logp == NULL) {
return (NULL);
}
if (auxsz != NULL) {
*auxsz = logp->ll_auxsz;
}
return (logp->ll_aux);
}
......@@ -94,6 +94,35 @@ lattutil_sqlite_ctx_free(lattutil_sqlite_ctx_t **ctx)
*ctx = NULL;
}
EXPORTED_SYM
void
lattutil_sqlite_ctx_set_aux(lattutil_sqlite_ctx_t *ctx, void *aux, size_t sz)
{
if (ctx == NULL) {
return;
}
ctx->lsq_aux = aux;
ctx->lsq_auxsz = sz;
}
EXPORTED_SYM
void *
lattutil_sqlite_ctx_get_aux(lattutil_sqlite_ctx_t *ctx, size_t *sz)
{
if (ctx == NULL) {
return (NULL);
}
if (sz != NULL) {
*sz = ctx->lsq_auxsz;
}
return (ctx->lsq_aux);
}
EXPORTED_SYM
uint64_t
lattutil_sqlite_get_version(lattutil_sqlite_ctx_t *ctx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment