Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Functions | Variables
cel_tds.c File Reference

FreeTDS CEL logger http://www.freetds.org/. More...

#include "asterisk.h"
#include <time.h>
#include <math.h>
#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/cel.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include <sqlfront.h>
#include <sybdb.h>
Include dependency graph for cel_tds.c:

Go to the source code of this file.

Data Structures

struct  cel_tds_config
 

Macros

#define DATE_FORMAT   "%Y/%m/%d %T"
 
#define TDS_BACKEND_NAME   "CEL TDS logging backend"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static char * anti_injection (const char *, int)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int execute_and_consume (DBPROCESS *dbproc, const char *fmt,...)
 
static void get_date (char *, size_t len, struct timeval)
 
static int load_module (void)
 
static int mssql_connect (void)
 
static int mssql_disconnect (void)
 
static int reload (void)
 
static int tds_error_handler (DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
 
static int tds_load_module (int reload)
 
static void tds_log (struct ast_event *event)
 
static int tds_message_handler (DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
 
static int tds_unload_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "FreeTDS CEL Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cel", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static char * config = "cel_tds.conf"
 
static struct cel_tds_configsettings
 
static ast_mutex_t tds_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 

Detailed Description

FreeTDS CEL logger http://www.freetds.org/.

Definition in file cel_tds.c.

Macro Definition Documentation

◆ DATE_FORMAT

#define DATE_FORMAT   "%Y/%m/%d %T"
 *
 * Table Structure for `cel`
 *

CREATE TABLE [dbo].[cel] (
    [accountcode] [varchar] (20) NULL ,
    [cidname] [varchar] (80) NULL ,
    [cidnum] [varchar] (80) NULL ,
    [cidani] [varchar] (80) NULL ,
    [cidrdnis] [varchar] (80) NULL ,
    [ciddnid] [varchar] (80) NULL ,
    [exten] [varchar] (80) NULL ,
    [context] [varchar] (80) NULL ,
    [channame] [varchar] (80) NULL ,
    [appname] [varchar] (80) NULL ,
    [appdata] [varchar] (80) NULL ,
    [eventtime] [datetime] NULL ,
    [eventtype] [varchar] (32) NULL ,
    [uniqueid] [varchar] (32) NULL ,
    [linkedid] [varchar] (32) NULL ,
    [amaflags] [varchar] (16) NULL ,
    [userfield] [varchar] (32) NULL ,
    [peer] [varchar] (32) NULL
) ON [PRIMARY]

Definition at line 77 of file cel_tds.c.

◆ TDS_BACKEND_NAME

#define TDS_BACKEND_NAME   "CEL TDS logging backend"

Definition at line 79 of file cel_tds.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 581 of file cel_tds.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 581 of file cel_tds.c.

◆ anti_injection()

static char * anti_injection ( const char *  str,
int  len 
)
static

Definition at line 257 of file cel_tds.c.

258{
259 /* Reference to http://www.nextgenss.com/papers/advanced_sql_injection.pdf */
260 char *buf;
261 char *buf_ptr, *srh_ptr;
262 char *known_bad[] = {"select", "insert", "update", "delete", "drop", ";", "--", "\0"};
263 int idx;
264
265 if (!(buf = ast_calloc(1, len + 1))) {
266 ast_log(LOG_ERROR, "Out of memory\n");
267 return NULL;
268 }
269
270 buf_ptr = buf;
271
272 /* Escape single quotes */
273 for (; *str && strlen(buf) < len; str++) {
274 if (*str == '\'') {
275 *buf_ptr++ = '\'';
276 }
277 *buf_ptr++ = *str;
278 }
279 *buf_ptr = '\0';
280
281 /* Erase known bad input */
282 for (idx = 0; *known_bad[idx]; idx++) {
283 while ((srh_ptr = strcasestr(buf, known_bad[idx]))) {
284 memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
285 }
286 }
287 return buf;
288}
const char * str
Definition: app_jack.c:147
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * strcasestr(const char *, const char *)
#define LOG_ERROR
#define NULL
Definition: resample.c:96

References ast_calloc, ast_log, buf, len(), LOG_ERROR, NULL, str, and strcasestr().

Referenced by tds_log().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 581 of file cel_tds.c.

◆ execute_and_consume()

static int execute_and_consume ( DBPROCESS *  dbproc,
const char *  fmt,
  ... 
)
static

Definition at line 302 of file cel_tds.c.

303{
304 va_list ap;
305 char *buffer;
306
307 va_start(ap, fmt);
308 if (ast_vasprintf(&buffer, fmt, ap) < 0) {
309 va_end(ap);
310 return 1;
311 }
312 va_end(ap);
313
314 if (dbfcmd(dbproc, buffer) == FAIL) {
315 ast_free(buffer);
316 return 1;
317 }
318
319 ast_free(buffer);
320
321 if (dbsqlexec(dbproc) == FAIL) {
322 return 1;
323 }
324
325 /* Consume the result set (we don't really care about the result, though) */
326 while (dbresults(dbproc) != NO_MORE_RESULTS) {
327 while (dbnextrow(dbproc) != NO_MORE_ROWS);
328 }
329
330 return 0;
331}
#define ast_free(a)
Definition: astmm.h:180
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:278

References ast_free, and ast_vasprintf.

Referenced by mssql_connect().

◆ get_date()

static void get_date ( char *  dateField,
size_t  len,
struct timeval  when 
)
static

Definition at line 290 of file cel_tds.c.

291{
292 /* To make sure we have date variable if not insert null to SQL */
293 if (!ast_tvzero(when)) {
294 struct ast_tm tm;
295 ast_localtime(&when, &tm, NULL);
296 ast_strftime(dateField, len, "'" DATE_FORMAT "'", &tm);
297 } else {
298 ast_copy_string(dateField, "null", len);
299 }
300}
#define DATE_FORMAT
Definition: cel_tds.c:77
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
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...
Definition: localtime.c:2524
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:117

References ast_copy_string(), ast_localtime(), ast_strftime(), ast_tvzero(), DATE_FORMAT, len(), and NULL.

Referenced by tds_log().

◆ load_module()

static int load_module ( void  )
static

Definition at line 530 of file cel_tds.c.

531{
532 if (dbinit() == FAIL) {
533 ast_log(LOG_ERROR, "Failed to initialize FreeTDS db-lib\n");
535 }
536
537 dberrhandle(tds_error_handler);
538 dbmsghandle(tds_message_handler);
539
541
542 if (!settings) {
543 dbexit();
545 }
546
547 if (!tds_load_module(0)) {
550 settings = NULL;
551 dbexit();
552 ast_log(LOG_WARNING,"cel_tds module had config problems; declining load\n");
554 }
555
556 /* Register MSSQL CEL handler */
558 ast_log(LOG_ERROR, "Unable to register MSSQL CEL handling\n");
561 settings = NULL;
562 dbexit();
564 }
565
567}
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition: cel.c:1783
#define TDS_BACKEND_NAME
Definition: cel_tds.c:79
static void tds_log(struct ast_event *event)
Definition: cel_tds.c:110
static struct cel_tds_config * settings
Definition: cel_tds.c:99
static int tds_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
Definition: cel_tds.c:411
static int tds_message_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
Definition: cel_tds.c:422
static int tds_load_module(int reload)
Definition: cel_tds.c:430
#define LOG_WARNING
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
Definition: stringfields.h:432
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_calloc_with_stringfields, ast_cel_backend_register(), ast_free, ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_string_field_free_memory, LOG_ERROR, LOG_WARNING, NULL, settings, TDS_BACKEND_NAME, tds_error_handler(), tds_load_module(), tds_log(), and tds_message_handler().

◆ mssql_connect()

static int mssql_connect ( void  )
static

Definition at line 344 of file cel_tds.c.

345{
346 LOGINREC *login;
347
348 if ((login = dblogin()) == NULL) {
349 ast_log(LOG_ERROR, "Unable to allocate login structure for db-lib\n");
350 return -1;
351 }
352
353 DBSETLAPP(login, "TSQL");
354 DBSETLUSER(login, (char *) settings->username);
355 DBSETLPWD(login, (char *) settings->password);
356
358 DBSETLCHARSET(login, (char *) settings->charset);
359 }
360
362 DBSETLNATLANG(login, (char *) settings->language);
363 }
364
365 if ((settings->dbproc = dbopen(login, (char *) settings->connection)) == NULL) {
366 ast_log(LOG_ERROR, "Unable to connect to %s\n", settings->connection);
367 dbloginfree(login);
368 return -1;
369 }
370
371 dbloginfree(login);
372
373 if (dbuse(settings->dbproc, (char *) settings->database) == FAIL) {
374 ast_log(LOG_ERROR, "Unable to select database %s\n", settings->database);
375 goto failed;
376 }
377
378 if (execute_and_consume(settings->dbproc, "SELECT 1 FROM [%s]", settings->table)) {
379 ast_log(LOG_ERROR, "Unable to find table '%s'\n", settings->table);
380 goto failed;
381 }
382
383 settings->connected = 1;
384
385 return 0;
386
387failed:
388 dbclose(settings->dbproc);
390 return -1;
391}
static int execute_and_consume(DBPROCESS *dbproc, const char *fmt,...)
Definition: cel_tds.c:302
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
DBPROCESS * dbproc
Definition: cel_tds.c:93
const ast_string_field charset
Definition: cel_tds.c:92
const ast_string_field language
Definition: cel_tds.c:92
const ast_string_field database
Definition: cel_tds.c:92
const ast_string_field password
Definition: cel_tds.c:92
const ast_string_field username
Definition: cel_tds.c:92
const ast_string_field table
Definition: cel_tds.c:92
unsigned int connected
Definition: cel_tds.c:94
const ast_string_field connection
Definition: cel_tds.c:92
DB * dbopen(char *fname, int flags, int mode, DBTYPE type, const void *openinfo) const

References ast_log, ast_strlen_zero(), cel_tds_config::charset, cel_tds_config::connected, cel_tds_config::connection, cel_tds_config::database, dbopen(), cel_tds_config::dbproc, execute_and_consume(), cel_tds_config::language, LOG_ERROR, NULL, cel_tds_config::password, settings, cel_tds_config::table, and cel_tds_config::username.

Referenced by tds_load_module(), and tds_log().

◆ mssql_disconnect()

static int mssql_disconnect ( void  )
static

Definition at line 333 of file cel_tds.c.

334{
335 if (settings->dbproc) {
336 dbclose(settings->dbproc);
338 }
339 settings->connected = 0;
340
341 return 0;
342}

References cel_tds_config::connected, cel_tds_config::dbproc, NULL, and settings.

Referenced by tds_load_module(), tds_log(), and tds_unload_module().

◆ reload()

static int reload ( void  )
static

Definition at line 525 of file cel_tds.c.

526{
527 return tds_load_module(1);
528}

References tds_load_module().

Referenced by tds_load_module().

◆ tds_error_handler()

static int tds_error_handler ( DBPROCESS *  dbproc,
int  severity,
int  dberr,
int  oserr,
char *  dberrstr,
char *  oserrstr 
)
static

Definition at line 411 of file cel_tds.c.

412{
413 ast_log(LOG_ERROR, "%s (%d)\n", dberrstr, dberr);
414
415 if (oserr != DBNOERR) {
416 ast_log(LOG_ERROR, "%s (%d)\n", oserrstr, oserr);
417 }
418
419 return INT_CANCEL;
420}

References ast_log, and LOG_ERROR.

Referenced by load_module().

◆ tds_load_module()

static int tds_load_module ( int  reload)
static

Definition at line 430 of file cel_tds.c.

431{
432 struct ast_config *cfg;
433 const char *ptr = NULL;
434 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
435
436 cfg = ast_config_load(config, config_flags);
437 if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
438 ast_log(LOG_NOTICE, "Unable to load TDS config for CELs: %s\n", config);
439 return 0;
440 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
441 return 0;
442 }
443
444 if (!ast_variable_browse(cfg, "global")) {
445 /* nothing configured */
447 ast_log(LOG_NOTICE, "cel_tds has no global category, nothing to configure.\n");
448 return 0;
449 }
450
452
453 /* Clear out any existing settings */
455
456 ptr = ast_variable_retrieve(cfg, "global", "connection");
457 if (ptr) {
458 ast_string_field_set(settings, connection, ptr);
459 } else {
460 ast_log(LOG_ERROR, "Failed to connect: Database connection name not specified.\n");
461 goto failed;
462 }
463
464 ptr = ast_variable_retrieve(cfg, "global", "dbname");
465 if (ptr) {
466 ast_string_field_set(settings, database, ptr);
467 } else {
468 ast_log(LOG_ERROR, "Failed to connect: Database dbname not specified.\n");
469 goto failed;
470 }
471
472 ptr = ast_variable_retrieve(cfg, "global", "user");
473 if (ptr) {
474 ast_string_field_set(settings, username, ptr);
475 } else {
476 ast_log(LOG_ERROR, "Failed to connect: Database dbuser not specified.\n");
477 goto failed;
478 }
479
480 ptr = ast_variable_retrieve(cfg, "global", "password");
481 if (ptr) {
482 ast_string_field_set(settings, password, ptr);
483 } else {
484 ast_log(LOG_ERROR, "Failed to connect: Database password not specified.\n");
485 goto failed;
486 }
487
488 ptr = ast_variable_retrieve(cfg, "global", "charset");
489 if (ptr) {
491 }
492
493 ptr = ast_variable_retrieve(cfg, "global", "language");
494 if (ptr) {
496 }
497
498 ptr = ast_variable_retrieve(cfg, "global", "table");
499 if (ptr) {
501 } else {
502 ast_log(LOG_NOTICE, "Table name not specified, using 'cel' by default.\n");
504 }
505
507
508 if (mssql_connect()) {
509 /* We failed to connect (mssql_connect takes care of logging it) */
510 goto failed;
511 }
512
515
516 return 1;
517
518failed:
521
522 return 0;
523}
static char * table
Definition: cdr_odbc.c:55
static int mssql_connect(void)
Definition: cel_tds.c:344
static char * config
Definition: cel_tds.c:81
static ast_mutex_t tds_lock
Definition: cel_tds.c:97
static int mssql_disconnect(void)
Definition: cel_tds.c:333
static int reload(void)
Definition: cel_tds.c:525
static char language[MAX_LANGUAGE]
Definition: chan_iax2.c:324
charset
Definition: chan_unistim.c:336
#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.
Definition: extconf.c:1289
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:784
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1215
@ CONFIG_FLAG_FILEUNCHANGED
#define LOG_NOTICE
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
Structure used to handle boolean flags.
Definition: utils.h:199

References ast_config_destroy(), ast_config_load, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_string_field_init, ast_string_field_set, ast_variable_browse(), ast_variable_retrieve(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, language, LOG_ERROR, LOG_NOTICE, mssql_connect(), mssql_disconnect(), NULL, reload(), settings, table, and tds_lock.

Referenced by load_module(), and reload().

◆ tds_log()

static void tds_log ( struct ast_event event)
static

Definition at line 110 of file cel_tds.c.

111{
112 char start[80];
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;
114 RETCODE erc;
115 int attempt = 1;
116 struct ast_cel_event_record record = {
118 };
119
120 if (ast_cel_fill_record(event, &record)) {
121 return;
122 }
123
125
126 accountcode_ai = anti_injection(record.account_code, 20);
127 clidnum_ai = anti_injection(record.caller_id_num, 80);
128 clid_ai = anti_injection(record.caller_id_name, 80);
129 cidani_ai = anti_injection(record.caller_id_ani, 80);
130 cidrdnis_ai = anti_injection(record.caller_id_rdnis, 80);
131 ciddnid_ai = anti_injection(record.caller_id_dnid, 80);
132 exten_ai = anti_injection(record.extension, 80);
133 context_ai = anti_injection(record.context, 80);
134 channel_ai = anti_injection(record.channel_name, 80);
135 app_ai = anti_injection(record.application_name, 80);
136 appdata_ai = anti_injection(record.application_data, 80);
137 uniqueid_ai = anti_injection(record.unique_id, 32);
138 linkedid_ai = anti_injection(record.linked_id, 32);
139 userfield_ai = anti_injection(record.user_field, 32);
140 peer_ai = anti_injection(record.peer, 32);
141
142 get_date(start, sizeof(start), record.event_time);
143
144retry:
145 /* Ensure that we are connected */
146 if (!settings->connected) {
147 ast_log(LOG_NOTICE, "Attempting to reconnect to %s (Attempt %d)\n", settings->connection, attempt);
148 if (mssql_connect()) {
149 /* Connect failed */
150 if (attempt++ < 3) {
151 goto retry;
152 }
153 goto done;
154 }
155 }
156
157 erc = dbfcmd(settings->dbproc,
158 "INSERT INTO %s "
159 "("
160 "accountcode,"
161 "cidnum,"
162 "cidname,"
163 "cidani,"
164 "cidrdnis,"
165 "ciddnid,"
166 "exten,"
167 "context,"
168 "channel,"
169 "appname,"
170 "appdata,"
171 "eventtime,"
172 "eventtype,"
173 "amaflags, "
174 "uniqueid,"
175 "linkedid,"
176 "userfield,"
177 "peer"
178 ") "
179 "VALUES "
180 "("
181 "'%s'," /* accountcode */
182 "'%s'," /* clidnum */
183 "'%s'," /* clid */
184 "'%s'," /* cid-ani */
185 "'%s'," /* cid-rdnis */
186 "'%s'," /* cid-dnid */
187 "'%s'," /* exten */
188 "'%s'," /* context */
189 "'%s'," /* channel */
190 "'%s'," /* app */
191 "'%s'," /* appdata */
192 "%s, " /* eventtime */
193 "'%s'," /* eventtype */
194 "'%s'," /* amaflags */
195 "'%s'," /* uniqueid */
196 "'%s'," /* linkedid */
197 "'%s'," /* userfield */
198 "'%s'" /* peer */
199 ")",
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,
203 ? record.user_defined_name : record.event_name,
204 ast_channel_amaflags2string(record.amaflag), uniqueid_ai, linkedid_ai,
205 userfield_ai, peer_ai);
206
207 if (erc == FAIL) {
208 if (attempt++ < 3) {
209 ast_log(LOG_NOTICE, "Failed to build INSERT statement, retrying...\n");
211 goto retry;
212 } else {
213 ast_log(LOG_ERROR, "Failed to build INSERT statement, no CEL was logged.\n");
214 goto done;
215 }
216 }
217
218 if (dbsqlexec(settings->dbproc) == FAIL) {
219 if (attempt++ < 3) {
220 ast_log(LOG_NOTICE, "Failed to execute INSERT statement, retrying...\n");
222 goto retry;
223 } else {
224 ast_log(LOG_ERROR, "Failed to execute INSERT statement, no CEL was logged.\n");
225 goto done;
226 }
227 }
228
229 /* Consume any results we might get back (this is more of a sanity check than
230 * anything else, since an INSERT shouldn't return results). */
231 while (dbresults(settings->dbproc) != NO_MORE_RESULTS) {
232 while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
233 }
234
235done:
237
238 ast_free(accountcode_ai);
239 ast_free(clidnum_ai);
240 ast_free(clid_ai);
241 ast_free(cidani_ai);
242 ast_free(cidrdnis_ai);
243 ast_free(ciddnid_ai);
244 ast_free(exten_ai);
245 ast_free(context_ai);
246 ast_free(channel_ai);
247 ast_free(app_ai);
248 ast_free(appdata_ai);
249 ast_free(uniqueid_ai);
250 ast_free(linkedid_ai);
251 ast_free(userfield_ai);
252 ast_free(peer_ai);
253
254 return;
255}
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition: cel.h:69
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.
Definition: cel.c:822
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Definition: cel.h:143
static char * anti_injection(const char *, int)
Definition: cel_tds.c:257
static void get_date(char *, size_t len, struct timeval)
Definition: cel_tds.c:290
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
Definition: channel.c:4392
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:138
const char * caller_id_dnid
Definition: cel.h:157
const char * application_data
Definition: cel.h:162
const char * account_code
Definition: cel.h:163
const char * caller_id_rdnis
Definition: cel.h:156
const char * extension
Definition: cel.h:158
const char * caller_id_num
Definition: cel.h:154
const char * channel_name
Definition: cel.h:160
const char * linked_id
Definition: cel.h:166
const char * peer
Definition: cel.h:170
enum ast_cel_event_type event_type
Definition: cel.h:149
const char * unique_id
Definition: cel.h:165
const char * user_defined_name
Definition: cel.h:152
const char * context
Definition: cel.h:159
const char * application_name
Definition: cel.h:161
struct timeval event_time
Definition: cel.h:150
uint32_t version
struct ABI version
Definition: cel.h:148
const char * user_field
Definition: cel.h:169
const char * caller_id_ani
Definition: cel.h:155
const char * caller_id_name
Definition: cel.h:153
const char * event_name
Definition: cel.h:151
Definition: astman.c:222
int done
Definition: test_amihooks.c:48

References ast_cel_event_record::account_code, ast_cel_event_record::amaflag, anti_injection(), ast_cel_event_record::application_data, ast_cel_event_record::application_name, AST_CEL_EVENT_RECORD_VERSION, ast_cel_fill_record(), AST_CEL_USER_DEFINED, ast_channel_amaflags2string(), ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_cel_event_record::caller_id_ani, ast_cel_event_record::caller_id_dnid, ast_cel_event_record::caller_id_name, ast_cel_event_record::caller_id_num, ast_cel_event_record::caller_id_rdnis, ast_cel_event_record::channel_name, cel_tds_config::connected, cel_tds_config::connection, ast_cel_event_record::context, cel_tds_config::dbproc, done, ast_cel_event_record::event_name, ast_cel_event_record::event_time, ast_cel_event_record::event_type, ast_cel_event_record::extension, get_date(), ast_cel_event_record::linked_id, LOG_ERROR, LOG_NOTICE, mssql_connect(), mssql_disconnect(), ast_cel_event_record::peer, settings, cel_tds_config::table, tds_lock, ast_cel_event_record::unique_id, ast_cel_event_record::user_defined_name, ast_cel_event_record::user_field, and ast_cel_event_record::version.

Referenced by load_module().

◆ tds_message_handler()

static int tds_message_handler ( DBPROCESS *  dbproc,
DBINT  msgno,
int  msgstate,
int  severity,
char *  msgtext,
char *  srvname,
char *  procname,
int  line 
)
static

Definition at line 422 of file cel_tds.c.

423{
424 ast_debug(1, "Msg %d, Level %d, State %d, Line %d\n", msgno, severity, msgstate, line);
425 ast_log(LOG_NOTICE, "%s\n", msgtext);
426
427 return 0;
428}
#define ast_debug(level,...)
Log a DEBUG message.
enum ast_security_event_severity severity

References ast_debug, ast_log, LOG_NOTICE, and severity.

Referenced by load_module().

◆ tds_unload_module()

static int tds_unload_module ( void  )
static

Definition at line 393 of file cel_tds.c.

394{
396
397 if (settings) {
401
404 }
405
406 dbexit();
407
408 return 0;
409}
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
Definition: cel.c:1771

References ast_cel_backend_unregister(), ast_free, ast_mutex_lock, ast_mutex_unlock, ast_string_field_free_memory, mssql_disconnect(), settings, TDS_BACKEND_NAME, and tds_lock.

Referenced by unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 569 of file cel_tds.c.

570{
571 return tds_unload_module();
572}
static int tds_unload_module(void)
Definition: cel_tds.c:393

References tds_unload_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "FreeTDS CEL Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cel", }
static

Definition at line 581 of file cel_tds.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 581 of file cel_tds.c.

◆ config

char* config = "cel_tds.conf"
static

Definition at line 81 of file cel_tds.c.

Referenced by tds_load_module().

◆ settings

struct cel_tds_config* settings
static

◆ tds_lock

ast_mutex_t tds_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

Definition at line 97 of file cel_tds.c.

Referenced by tds_load_module(), tds_log(), and tds_unload_module().