Commit 40480ec2 authored by Shawn Webb's avatar Shawn Webb
Browse files

Further support for SQLite3 context object flags



While here, also start the work for logging queries.
Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
issue:		#2
parent c771ced5
......@@ -44,6 +44,10 @@ typedef struct _sqlite_ctx sqlite_ctx_t;
#define LATTUTIL_LOG_VERBOSITY_DEFAULT 1000
#define LATTUTIL_LOG_DEFAULT_NAME "lattutil"
#define LATTUTIL_SQL_FLAG_LOG_QUERY 0x1
#define LATTUTIL_SQL_FLAG_ISSET(q, f) (((q)->lsq_flags & f) == f)
typedef ssize_t (*log_cb)(struct _lllog *, int, const char *, ...);
typedef void (*log_close)(struct _lllog *);
......@@ -317,6 +321,40 @@ lattutil_sqlite_ctx_t *lattutil_sqlite_ctx_new(const char *, lattutil_log_t *,
*/
void lattutil_sqlite_ctx_free(lattutil_sqlite_ctx_t **);
/**
* Get the flags of the SQLite3 context object
*
* @param The context object
* @return The flags of the context object
*/
uint64_t lattutil_sqlite_ctx_get_flags(lattutil_sqlite_ctx_t *);
/**
* Return the flags of the context object associated with a query
*
* @param The query object
* @return The flags of the context object associtated with the query
*/
uint64_t lattutil_sql_query_get_flags(lattutil_sqlite_query_t *);
/**
* Set the flags of a sqlite3 context object
*
* @param The sqlite3 context object
* @param The flags
* @return The old flags
*/
uint64_t lattutil_sqlite_ctx_set_flags(lattutil_sqlite_ctx_t *, uint64_t);
/**
* Set a single flag of a sqlite3 context object
*
* @param The sqlite3 context object
* @param The flag
* @return The old flags
*/
uint64_t lattutil_sqlite_ctx_set_flag(lattutil_sqlite_ctx_t *, uint64_t);
/**
* Set the auxiliary members of the sqlite context object
*
......@@ -353,6 +391,9 @@ uint64_t lattutil_sqlite_get_version(lattutil_sqlite_ctx_t *);
lattutil_sqlite_query_t *lattutil_sqlite_prepare(lattutil_sqlite_ctx_t *,
const char *);
lattutil_sqlite_ctx_t *lattutil_sqlite_query_get_ctx(
lattutil_sqlite_query_t *);
/**
* Free a query object
*
......
......@@ -69,6 +69,8 @@ lattutil_sqlite_ctx_new(const char *path, lattutil_log_t *logger,
return (NULL);
}
ctx->lsq_flags = flags;
return (ctx);
}
......@@ -94,6 +96,64 @@ lattutil_sqlite_ctx_free(lattutil_sqlite_ctx_t **ctx)
*ctx = NULL;
}
EXPORTED_SYM
uint64_t
lattutil_sqlite_ctx_get_flags(lattutil_sqlite_ctx_t *ctx)
{
if (ctx == NULL) {
return (0);
}
return (ctx->lsq_flags);
}
EXPORTED_SYM
uint64_t
lattutil_sqlite_ctx_set_flags(lattutil_sqlite_ctx_t *ctx, uint64_t flags)
{
uint64_t old_flags;
if (ctx == NULL) {
return (0);
}
old_flags = ctx->lsq_flags;
ctx->lsq_flags = flags;
return (old_flags);
}
EXPORTED_SYM
uint64_t
lattutil_sqlite_ctx_set_flag(lattutil_sqlite_ctx_t *ctx, uint64_t flag)
{
uint64_t old_flags;
if (ctx == NULL) {
return (0);
}
old_flags = ctx->lsq_flags;
ctx->lsq_flags |= flag;
return (old_flags);
}
EXPORTED_SYM
uint64_t
lattutil_sql_query_get_flags(lattutil_sqlite_query_t *query)
{
if (query == NULL || query->lsq_sql_ctx == NULL) {
return (0);
}
return (lattutil_sqlite_ctx_get_flags(query->lsq_sql_ctx));
}
EXPORTED_SYM
void
lattutil_sqlite_ctx_set_aux(lattutil_sqlite_ctx_t *ctx, void *aux, size_t sz)
......@@ -183,6 +243,18 @@ lattutil_sqlite_prepare(lattutil_sqlite_ctx_t *ctx, const char *query_string)
return (query);
}
EXPORTED_SYM
lattutil_sqlite_ctx_t *
lattutil_sqlite_query_get_ctx(lattutil_sqlite_query_t *query)
{
if (query == NULL) {
return (NULL);
}
return (query->lsq_sql_ctx);
}
EXPORTED_SYM
void
lattutil_sqlite_query_free(lattutil_sqlite_query_t **query)
......@@ -293,6 +365,15 @@ lattutil_sqlite_exec(lattutil_sqlite_query_t *query)
logger = QUERY_GETLOGGER(query);
if (QUERY_CANLOG(query) &&
LATTUTIL_SQL_FLAG_ISSET(query->lsq_sql_ctx,
LATTUTIL_SQL_FLAG_LOG_QUERY)) {
logger->ll_log_debug(logger, -1, "SQL query: %s",
query->lsq_querystr);
} else {
fprintf(stderr, "[-] Not set to log queries\n");
}
ret = true;
while (true) {
......
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