73#ifdef FREETDS_PRE_0_62
74#warning "You have older TDS, you should upgrade!"
77#define DATE_FORMAT "%Y/%m/%d %T"
79#define TDS_BACKEND_NAME "CEL TDS logging backend"
102static void get_date(
char *,
size_t len,
struct timeval);
105 __attribute__((format(printf, 2, 3)));
113 char *accountcode_ai, *clidnum_ai, *exten_ai, *context_ai, *clid_ai, *channel_ai, *app_ai, *appdata_ai, *uniqueid_ai, *linkedid_ai, *cidani_ai, *cidrdnis_ai, *ciddnid_ai, *peer_ai, *userfield_ai;
200 settings->
table, accountcode_ai, clidnum_ai, clid_ai, cidani_ai, cidrdnis_ai,
201 ciddnid_ai, exten_ai, context_ai, channel_ai, app_ai, appdata_ai, start,
205 userfield_ai, peer_ai);
213 ast_log(
LOG_ERROR,
"Failed to build INSERT statement, no CEL was logged.\n");
224 ast_log(
LOG_ERROR,
"Failed to execute INSERT statement, no CEL was logged.\n");
261 char *buf_ptr, *srh_ptr;
262 char *known_bad[] = {
"select",
"insert",
"update",
"delete",
"drop",
";",
"--",
"\0"};
282 for (idx = 0; *known_bad[idx]; idx++) {
284 memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
290static void get_date(
char *dateField,
size_t len,
struct timeval when)
314 if (dbfcmd(dbproc, buffer) == FAIL) {
321 if (dbsqlexec(dbproc) == FAIL) {
326 while (dbresults(dbproc) != NO_MORE_RESULTS) {
327 while (dbnextrow(dbproc) != NO_MORE_ROWS);
348 if ((login = dblogin()) ==
NULL) {
353 DBSETLAPP(login,
"TSQL");
415 if (oserr != DBNOERR) {
424 ast_debug(1,
"Msg %d, Level %d, State %d, Line %d\n", msgno,
severity, msgstate, line);
433 const char *ptr =
NULL;
460 ast_log(
LOG_ERROR,
"Failed to connect: Database connection name not specified.\n");
484 ast_log(
LOG_ERROR,
"Failed to connect: Database password not specified.\n");
532 if (dbinit() == FAIL) {
Asterisk main include file. File version handling, generic pbx functions.
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r)
Fill in an ast_cel_event_record from a CEL event.
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
static char * anti_injection(const char *, int)
static int mssql_connect(void)
static void tds_log(struct ast_event *event)
static struct cel_tds_config * settings
static void get_date(char *, size_t len, struct timeval)
static int tds_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
static int execute_and_consume(DBPROCESS *dbproc, const char *fmt,...)
static int tds_message_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
static ast_mutex_t tds_lock
static int mssql_disconnect(void)
static int tds_unload_module(void)
static int load_module(void)
static int unload_module(void)
static int tds_load_module(int reload)
static char language[MAX_LANGUAGE]
General Asterisk PBX channel definitions.
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * strcasestr(const char *, const char *)
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
@ CONFIG_FLAG_FILEUNCHANGED
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
#define ast_mutex_unlock(a)
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
enum ast_security_event_severity severity
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Helper struct for getting the fields out of a CEL event.
const char * caller_id_dnid
const char * application_data
const char * account_code
const char * caller_id_rdnis
const char * caller_id_num
const char * channel_name
enum ast_cel_event_type event_type
const char * user_defined_name
const char * application_name
struct timeval event_time
uint32_t version
struct ABI version
const char * caller_id_ani
const char * caller_id_name
Structure used to handle boolean flags.
const ast_string_field charset
const ast_string_field language
const ast_string_field database
const ast_string_field password
const ast_string_field username
const ast_string_field table
const ast_string_field connection
Time-related functions and macros.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
DB * dbopen(char *fname, int flags, int mode, DBTYPE type, const void *openinfo) const