The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions | Variables
rlm_sql_sqlite.c File Reference

SQLite driver. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.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_conn_t
 
struct  rlm_sql_sqlite_t
 

Macros

#define BOOTSTRAP_MAX   (1048576 * 10)
 
#define LOG_PREFIX   "sql - sqlite"
 
#define SQLITE_OPEN_NOMUTEX   0
 

Typedefs

typedef sqlite_int64 sqlite3_int64
 

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 int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int sql_affected_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *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[], NDEBUG_UNUSED size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *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 const *config)
 
static sql_rcode_t sql_fields (char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static sql_rcode_t sql_finish_query (rlm_sql_handle_t *handle, rlm_sql_config_t const *config)
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static int sql_num_fields (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
 
static void sql_print_error (sqlite3 *db, int status, char const *fmt,...))
 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 const *config, char const *query)
 
static sql_rcode_t sql_select_query (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, char const *query)
 
static sql_rcode_t sql_socket_init (rlm_sql_handle_t *handle, rlm_sql_config_t const *config, UNUSED fr_time_delta_t timeout)
 

Variables

static const conf_parser_t driver_config []
 
rlm_sql_driver_t rlm_sql_sqlite
 

Detailed Description

SQLite driver.

Id
3b5f663a6a4ed2ef31d270091af385da3a30a770

Definition in file rlm_sql_sqlite.c.


Data Structure Documentation

◆ rlm_sql_sqlite_conn_t

struct rlm_sql_sqlite_conn_t

Definition at line 52 of file rlm_sql_sqlite.c.

Data Fields
int col_count
sqlite3 * db
sqlite3_stmt * statement

◆ rlm_sql_sqlite_t

struct rlm_sql_sqlite_t

Definition at line 58 of file rlm_sql_sqlite.c.

Data Fields
bool bootstrap
char const * filename

Macro Definition Documentation

◆ BOOTSTRAP_MAX

#define BOOTSTRAP_MAX   (1048576 * 10)

Definition at line 39 of file rlm_sql_sqlite.c.

◆ LOG_PREFIX

#define LOG_PREFIX   "sql - sqlite"

Definition at line 27 of file rlm_sql_sqlite.c.

◆ SQLITE_OPEN_NOMUTEX

#define SQLITE_OPEN_NOMUTEX   0

Definition at line 45 of file rlm_sql_sqlite.c.

Typedef Documentation

◆ sqlite3_int64

typedef sqlite_int64 sqlite3_int64

Definition at line 49 of file rlm_sql_sqlite.c.

Function Documentation

◆ _sql_greatest()

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

Definition at line 381 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ _sql_socket_destructor()

static int _sql_socket_destructor ( rlm_sql_sqlite_conn_t conn)
static

Definition at line 366 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 671 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 801 of file rlm_sql_sqlite.c.

◆ sql_affected_rows()

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

Definition at line 661 of file rlm_sql_sqlite.c.

◆ sql_check_error()

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 124 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sql_error()

static size_t sql_error ( UNUSED TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
NDEBUG_UNUSED size_t  outlen,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t const *  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 639 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_error_to_rcode()

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:

◆ sql_fetch_row()

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

Definition at line 520 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_fields()

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

Definition at line 502 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_finish_query()

static sql_rcode_t sql_finish_query ( rlm_sql_handle_t handle,
rlm_sql_config_t const *  config 
)
static

Definition at line 656 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_free_result()

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

Definition at line 606 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ sql_num_fields()

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

Definition at line 493 of file rlm_sql_sqlite.c.

+ Here is the caller graph for this function:

◆ sql_print_error()

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 prepend.
...arguments to fmt.

Definition at line 172 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sql_query()

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

Definition at line 473 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_select_query()

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

Definition at line 455 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

◆ sql_socket_init()

static sql_rcode_t sql_socket_init ( rlm_sql_handle_t handle,
rlm_sql_config_t const *  config,
UNUSED fr_time_delta_t  timeout 
)
static

Definition at line 396 of file rlm_sql_sqlite.c.

+ Here is the call graph for this function:

Variable Documentation

◆ driver_config

const conf_parser_t driver_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:406
@ CONF_FLAG_FILE_OUTPUT
File matching value must exist, and must be writable.
Definition: cf_parse.h:414

Definition at line 63 of file rlm_sql_sqlite.c.

◆ rlm_sql_sqlite

rlm_sql_driver_t rlm_sql_sqlite
Initial value:
= {
.common = {
.name = "sql_sqlite",
.inst_size = sizeof(rlm_sql_sqlite_t),
.onload = mod_load,
.bootstrap = mod_bootstrap
},
.number = 4,
.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
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static const conf_parser_t config[]
Definition: base.c:188
#define RLM_SQL_RCODE_FLAGS_ALT_QUERY
Can distinguish between other errors and those.
Definition: rlm_sql.h:116
static int mod_load(void)
static sql_rcode_t sql_fetch_row(rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t const *config)
static sql_rcode_t sql_finish_query(rlm_sql_handle_t *handle, rlm_sql_config_t const *config)
static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, char const *query)
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static sql_rcode_t sql_free_result(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static const conf_parser_t driver_config[]
static sql_rcode_t sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config, char const *query)
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static int sql_num_fields(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t const *config, UNUSED fr_time_delta_t timeout)
static sql_rcode_t sql_fields(char const **out[], rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
Retrieves any errors associated with the connection handle.

Definition at line 814 of file rlm_sql_sqlite.c.