76 #ifdef FREETDS_PRE_0_62 77 #warning "You have older TDS, you should upgrade!" 80 #define DATE_FORMAT "%Y/%m/%d %T" 82 #define TDS_BACKEND_NAME "CEL TDS logging backend" 84 static char *
config =
"cel_tds.conf";
105 static void get_date(
char *,
size_t len,
struct timeval);
108 __attribute__((
format(printf, 2, 3)));
116 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;
160 erc = dbfcmd(settings->
dbproc,
203 settings->
table, accountcode_ai, clidnum_ai, clid_ai, cidani_ai, cidrdnis_ai,
204 ciddnid_ai, exten_ai, context_ai, channel_ai, app_ai, appdata_ai, start,
208 userfield_ai, peer_ai);
216 ast_log(
LOG_ERROR,
"Failed to build INSERT statement, no CEL was logged.\n");
221 if (dbsqlexec(settings->
dbproc) == FAIL) {
227 ast_log(
LOG_ERROR,
"Failed to execute INSERT statement, no CEL was logged.\n");
234 while (dbresults(settings->
dbproc) != NO_MORE_RESULTS) {
235 while (dbnextrow(settings->
dbproc) != NO_MORE_ROWS);
264 char *buf_ptr, *srh_ptr;
265 char *known_bad[] = {
"select",
"insert",
"update",
"delete",
"drop",
";",
"--",
"\0"};
276 for (; *str && strlen(buf) <
len; str++) {
285 for (idx = 0; *known_bad[idx]; idx++) {
286 while ((srh_ptr =
strcasestr(buf, known_bad[idx]))) {
287 memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
293 static void get_date(
char *dateField,
size_t len,
struct timeval when)
317 if (dbfcmd(dbproc, buffer) == FAIL) {
324 if (dbsqlexec(dbproc) == FAIL) {
329 while (dbresults(dbproc) != NO_MORE_RESULTS) {
330 while (dbnextrow(dbproc) != NO_MORE_ROWS);
339 dbclose(settings->
dbproc);
351 if ((login = dblogin()) ==
NULL) {
356 DBSETLAPP(login,
"TSQL");
357 DBSETLUSER(login, (
char *) settings->
username);
358 DBSETLPWD(login, (
char *) settings->
password);
361 DBSETLCHARSET(login, (
char *) settings->
charset);
365 DBSETLNATLANG(login, (
char *) settings->
language);
376 if (dbuse(settings->
dbproc, (
char *) settings->
database) == FAIL) {
391 dbclose(settings->
dbproc);
418 if (oserr != DBNOERR) {
427 ast_debug(1,
"Msg %d, Level %d, State %d, Line %d\n", msgno, severity, msgstate, line);
436 const char *ptr =
NULL;
463 ast_log(
LOG_ERROR,
"Failed to connect: Database connection name not specified.\n");
487 ast_log(
LOG_ERROR,
"Failed to connect: Database password not specified.\n");
535 if (dbinit() == FAIL) {
const char * account_code
const char * caller_id_name
Helper struct for getting the fields out of a CEL event.
Asterisk main include file. File version handling, generic pbx functions.
static ast_mutex_t tds_lock
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Time-related functions and macros.
const char * user_defined_name
const ast_string_field charset
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
const char * application_data
const char * application_name
#define CONFIG_STATUS_FILEINVALID
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_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
const char * caller_id_num
#define ast_mutex_lock(a)
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
static int mssql_disconnect(void)
const ast_string_field username
#define ast_strlen_zero(foo)
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_config_load(filename, flags)
Load a config file.
General Asterisk PBX channel definitions.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
static int execute_and_consume(DBPROCESS *dbproc, const char *fmt,...)
#define AST_STRING_FIELD(name)
Declare a string field.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
uint32_t version
struct ABI version
static struct cel_tds_config * settings
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
#define CONFIG_STATUS_FILEUNCHANGED
static int tds_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
enum ast_cel_event_type event_type
const ast_string_field connection
const ast_string_field database
static int load_module(void)
const char * caller_id_rdnis
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char * anti_injection(const char *, int)
static int unload_module(void)
const ast_string_field table
char * strcasestr(const char *, const char *)
#define ast_calloc(num, len)
A wrapper for calloc()
Module has failed to load, may be in an inconsistent state.
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...
const char * caller_id_ani
const ast_string_field password
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Structure used to handle boolean flags.
Support for logging to various files, console and syslog Configuration in file logger.conf.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static int tds_load_module(int reload)
enum ast_security_event_severity severity
static int mssql_connect(void)
static int tds_unload_module(void)
a user-defined event, the event name field should be set
const ast_string_field language
const char * caller_id_dnid
const char * channel_name
static void get_date(char *, size_t len, struct timeval)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static snd_pcm_format_t format
struct timeval event_time
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static int tds_message_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
DB * dbopen(char *fname, int flags, int mode, DBTYPE type, const void *openinfo) const
static void tds_log(struct ast_event *event)
#define AST_MUTEX_DEFINE_STATIC(mutex)
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_mutex_unlock(a)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.