The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
sql.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <ctype.h>
#include "rlm_sql.h"
+ Include dependency graph for sql.c:

Go to the source code of this file.

Macros

#define LOG_PREFIX   inst->name
 

Functions

sql_rcode_t rlm_sql_fetch_row (rlm_sql_row_t *out, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle)
 Call the driver's sql_fetch_row function. More...
 
void rlm_sql_print_error (rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, bool force_debug)
 Retrieve any errors from the SQL driver. More...
 
sql_rcode_t rlm_sql_query (rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, char const *query)
 Call the driver's sql_query method, reconnecting if necessary. More...
 
void rlm_sql_query_log (rlm_sql_t const *inst, char const *filename, char const *query)
 
sql_rcode_t rlm_sql_select_query (rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, char const *query)
 Call the driver's sql_select_query method, reconnecting if necessary. More...
 
int sql_get_map_list (TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t **handle, map_list_t *out, char const *query, fr_dict_attr_t const *list)
 
void * sql_mod_conn_create (TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
 

Variables

fr_table_num_sorted_t const sql_rcode_description_table []
 
size_t sql_rcode_description_table_len = NUM_ELEMENTS(sql_rcode_description_table)
 
fr_table_num_sorted_t const sql_rcode_table []
 
size_t sql_rcode_table_len = NUM_ELEMENTS(sql_rcode_table)
 

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   inst->name

Definition at line 29 of file sql.c.

Function Documentation

◆ rlm_sql_fetch_row()

sql_rcode_t rlm_sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t **  handle 
)

Call the driver's sql_fetch_row function.

Calls the driver's sql_fetch_row logging any errors. On success, will write row data to (*handle)->row.

Parameters
outWhere to write row data.
instInstance of rlm_sql_t.
requestThe Current request, may be NULL.
handleHandle to retrieve errors for.
Returns

Definition at line 299 of file sql.c.

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

◆ rlm_sql_print_error()

void rlm_sql_print_error ( rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t handle,
bool  force_debug 
)

Retrieve any errors from the SQL driver.

Retrieves errors from the driver from the last operation and writes them to to request/global log, in the ERROR, WARN, INFO and DEBUG categories.

Parameters
instInstance of rlm_sql.
requestCurrent request, may be NULL.
handleHandle to retrieve errors for.
force_debugForce all errors to be logged as debug messages.

Definition at line 337 of file sql.c.

+ Here is the caller graph for this function:

◆ rlm_sql_query()

sql_rcode_t rlm_sql_query ( rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t **  handle,
char const *  query 
)

Call the driver's sql_query method, reconnecting if necessary.

Note
Caller must call (inst->driver->sql_finish_query)(handle, &inst->config); after they're done with the result.
Parameters
handleto query the database with. *handle should not be NULL, as this indicates previous reconnection attempt has failed.
requestCurrent request.
instrlm_sql_t instance data.
queryto execute. Should not be zero length.
Returns

Definition at line 392 of file sql.c.

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

◆ rlm_sql_query_log()

void rlm_sql_query_log ( rlm_sql_t const *  inst,
char const *  filename,
char const *  query 
)

Definition at line 613 of file sql.c.

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

◆ rlm_sql_select_query()

sql_rcode_t rlm_sql_select_query ( rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t **  handle,
char const *  query 
)

Call the driver's sql_select_query method, reconnecting if necessary.

Note
Caller must call (inst->driver->sql_finish_select_query)(handle, &inst->config); after they're done with the result.
Parameters
instrlm_sql_t instance data.
requestCurrent request.
handleto query the database with. *handle should not be NULL, as this indicates previous reconnection attempt has failed.
queryto execute. Should not be zero length.
Returns

Definition at line 493 of file sql.c.

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

◆ sql_get_map_list()

int sql_get_map_list ( TALLOC_CTX *  ctx,
rlm_sql_t const *  inst,
request_t request,
rlm_sql_handle_t **  handle,
map_list_t *  out,
char const *  query,
fr_dict_attr_t const *  list 
)

Definition at line 559 of file sql.c.

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

◆ sql_mod_conn_create()

void* sql_mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
fr_time_delta_t  timeout 
)

Definition at line 65 of file sql.c.

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

Variable Documentation

◆ sql_rcode_description_table

fr_table_num_sorted_t const sql_rcode_description_table[]
Initial value:
= {
{ L("need alt query"), RLM_SQL_ALT_QUERY },
{ L("no connection"), RLM_SQL_RECONNECT },
{ L("no more rows"), RLM_SQL_NO_MORE_ROWS },
{ L("query invalid"), RLM_SQL_QUERY_INVALID },
{ L("server error"), RLM_SQL_ERROR },
{ L("success"), RLM_SQL_OK }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ RLM_SQL_QUERY_INVALID
Query syntax error.
Definition: rlm_sql.h:43
@ RLM_SQL_ALT_QUERY
Key constraint violation, use an alternative query.
Definition: rlm_sql.h:47
@ RLM_SQL_RECONNECT
Stale connection, should reconnect.
Definition: rlm_sql.h:46
@ RLM_SQL_ERROR
General connection/server error.
Definition: rlm_sql.h:44
@ RLM_SQL_OK
Success.
Definition: rlm_sql.h:45
@ RLM_SQL_NO_MORE_ROWS
No more rows available.
Definition: rlm_sql.h:48

Definition at line 45 of file sql.c.

◆ sql_rcode_description_table_len

size_t sql_rcode_description_table_len = NUM_ELEMENTS(sql_rcode_description_table)

Definition at line 53 of file sql.c.

◆ sql_rcode_table

fr_table_num_sorted_t const sql_rcode_table[]
Initial value:
= {
{ L("alternate"), RLM_SQL_ALT_QUERY },
{ L("empty"), RLM_SQL_NO_MORE_ROWS },
{ L("error"), RLM_SQL_ERROR },
{ L("invalid"), RLM_SQL_QUERY_INVALID },
{ L("ok"), RLM_SQL_OK },
{ L("reconnect"), RLM_SQL_RECONNECT }
}

Definition at line 55 of file sql.c.

◆ sql_rcode_table_len

size_t sql_rcode_table_len = NUM_ELEMENTS(sql_rcode_table)

Definition at line 63 of file sql.c.