All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
rlm_sql_sqlite.c File Reference

SQLite driver. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sqlite3.h>
#include "rlm_sql.h"
#include "config.h"
+ Include dependency graph for rlm_sql_sqlite.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_sqlite_config
 
struct  rlm_sql_sqlite_conn
 

Macros

#define BOOTSTRAP_MAX   (1048576 * 10)
 
#define SQLITE_OPEN_NOMUTEX   0
 

Typedefs

typedef struct
rlm_sql_sqlite_config 
rlm_sql_sqlite_config_t
 
typedef typedef sqlite3_int64
sqlite_int64 struct
rlm_sql_sqlite_conn 
rlm_sql_sqlite_conn_t
 

Functions

static void _sql_greatest (sqlite3_context *ctx, int num_values, sqlite3_value **values)
 
static int _sql_socket_destructor (rlm_sql_sqlite_conn_t *conn)
 
static void CC_HINT (nonnull(3))
 
static int CC_HINT (nonnull)
 
static int mod_instantiate (CONF_SECTION *conf, rlm_sql_config_t *config)
 
static int sql_affected_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_check_error (sqlite3 *db, int status)
 Determine if an error occurred, and what type of error it was. More...
 
static size_t sql_error (UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 Retrieves any errors associated with the connection handle. More...
 
static sql_rcode_t sql_error_to_rcode (int status)
 Convert an sqlite status code to an sql_rcode_t. More...
 
static sql_rcode_t sql_fetch_row (rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_fields (char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_finish_query (rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static int sql_num_fields (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static void sql_print_error (sqlite3 *db, int status, char const *fmt,...) CC_HINT(format(printf
 Print an error to the global debug log. More...
 
static sql_rcode_t sql_query (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
 
static sql_rcode_t sql_select_query (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
 

Variables

static const CONF_PARSER driver_config []
 
rlm_sql_module_t rlm_sql_sqlite
 

Detailed Description

SQLite driver.

Id:
4f367721ef891cec2f263af3bf1ede039d3db190

Definition in file rlm_sql_sqlite.c.


Data Structure Documentation

struct rlm_sql_sqlite_config

Definition at line 57 of file rlm_sql_sqlite.c.

Data Fields
uint32_t busy_timeout
char const * filename
struct rlm_sql_sqlite_conn

Definition at line 51 of file rlm_sql_sqlite.c.

Data Fields
int col_count
sqlite3 * db
sqlite3_stmt * statement

Macro Definition Documentation

#define BOOTSTRAP_MAX   (1048576 * 10)

Definition at line 38 of file rlm_sql_sqlite.c.

#define SQLITE_OPEN_NOMUTEX   0

Definition at line 44 of file rlm_sql_sqlite.c.

Typedef Documentation

typedef typedef sqlite3_int64 sqlite_int64 struct rlm_sql_sqlite_conn rlm_sql_sqlite_conn_t

Function Documentation

static void _sql_greatest ( sqlite3_context *  ctx,
int  num_values,
sqlite3_value **  values 
)
static

Definition at line 511 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static int _sql_socket_destructor ( rlm_sql_sqlite_conn_t conn)
static

Definition at line 496 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static void CC_HINT ( nonnull(3)  )
static int CC_HINT ( nonnull  )
static

Definition at line 526 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

static int mod_instantiate ( CONF_SECTION conf,
rlm_sql_config_t config 
)
static

Definition at line 370 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

static int sql_affected_rows ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 785 of file rlm_sql_sqlite.c.

static sql_rcode_t sql_check_error ( sqlite3 *  db,
int  status 
)
static

Determine if an error occurred, and what type of error it was.

Parameters
dbhandle to extract error from (may be NULL).
statusto check (if unused, set to SQLITE_OK).
Returns
  • RLM_SQL_OK - If no errors found.
  • RLM_SQL_ERROR - If a known, non-fatal, error occurred.
  • RLM_SQL_ALT_QUERY - If a constraints violation occurred.
  • RLM_SQL_RECONNECT - Anything else. We assume the connection can no longer be used.

Definition at line 123 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static size_t sql_error ( UNUSED TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Retrieves any errors associated with the connection handle.

Note
Caller will free any memory allocated in ctx.
Parameters
ctxto allocate temporary error buffers in.
outArray of sql_log_entrys to fill.
outlenLength of out array.
handlerlm_sql connection handle.
configrlm_sql config.
Returns
number of errors written to the sql_log_entry_t array.

Definition at line 763 of file rlm_sql_sqlite.c.

static sql_rcode_t sql_error_to_rcode ( int  status)
static

Convert an sqlite status code to an sql_rcode_t.

Parameters
statusto convert.
Returns
  • RLM_SQL_OK - If no errors found.
  • RLM_SQL_ERROR - If a known, non-fatal, error occurred.
  • RLM_SQL_ALT_QUERY - If a constraints violation occurred.
  • RLM_SQL_RECONNECT - Anything else, we assume the connection can no longer be used.

Definition at line 77 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static sql_rcode_t sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 645 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_fields ( char const **  out[],
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 627 of file rlm_sql_sqlite.c.

static sql_rcode_t sql_finish_query ( rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 780 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_free_result ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 730 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static int sql_num_fields ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 618 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static void sql_print_error ( sqlite3 *  db,
int  status,
char const *  fmt,
  ... 
)
static

Print an error to the global debug log.

If status does not indicate success, write an error to the global error log.

Note
The error code will be appended to the fmt string in the format ": code 0x<hex> (<int>)[: <string>]".
Parameters
dbhandle to extract error from (may be NULL).
statusto check (if unused, set to SQLITE_OK).
fmtto preprend.
...arguments to fmt.

Definition at line 171 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

static sql_rcode_t sql_query ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config,
char const *  query 
)
static

Definition at line 598 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_select_query ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config,
char const *  query 
)
static

Definition at line 580 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

Variable Documentation

const CONF_PARSER driver_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("busy_timeout", PW_TYPE_INTEGER, rlm_sql_sqlite_config_t, busy_timeout), .dflt = "200" },
}
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
32 Bit unsigned integer.
Definition: radius.h:34
#define PW_TYPE_FILE_OUTPUT
File matching value must exist, and must be writeable.
Definition: conffile.h:205
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: conffile.h:200

Definition at line 62 of file rlm_sql_sqlite.c.

rlm_sql_module_t rlm_sql_sqlite
Initial value:
= {
.name = "rlm_sql_sqlite",
.mod_instantiate = mod_instantiate,
.sql_socket_init = sql_socket_init,
.sql_query = sql_query,
.sql_select_query = sql_select_query,
.sql_num_fields = sql_num_fields,
.sql_affected_rows = sql_affected_rows,
.sql_fetch_row = sql_fetch_row,
.sql_fields = sql_fields,
.sql_free_result = sql_free_result,
.sql_error = sql_error,
.sql_finish_query = sql_finish_query,
.sql_finish_select_query = sql_finish_query
}
static sql_rcode_t sql_finish_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
Definition: rlm_sql.h:164
static sql_rcode_t sql_free_result(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
static sql_rcode_t sql_fetch_row(rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
static int sql_num_fields(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
Retrieves any errors associated with the connection handle.
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config, char const *query)
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_fields(char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)

Definition at line 800 of file rlm_sql_sqlite.c.