72#define DATE_FORMAT "%Y/%m/%d %T"
74static const char name[] =
"FreeTDS (MSSQL)";
75static const char config[] =
"cdr_tds.conf";
98static void get_date(
char *,
size_t len,
struct timeval);
101 __attribute__((format(printf, 2, 3)));
109 char *
accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid, *userfield =
NULL;
125 get_date(start,
sizeof(start), cdr->start);
150 double hrbillsec = 0.0;
154 hrbillsec = (double)(
ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0);
156 hrduration = (double)(
ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0);
161 "accountcode, src, dst, dcontext, clid, channel, "
162 "dstchannel, lastapp, lastdata, start, answer, [end], duration, "
163 "billsec, disposition, amaflags, uniqueid, userfield"
167 "'%s', '%s', '%s', '%s', '%s', '%s', "
168 "'%s', '%s', '%s', %s, %s, %s, %lf, "
169 "%lf, '%s', '%s', '%s', '%s'"
173 dstchannel, lastapp, lastdata, start,
answer,
end, hrduration,
181 "accountcode, src, dst, dcontext, clid, channel, "
182 "dstchannel, lastapp, lastdata, start, answer, [end], duration, "
183 "billsec, disposition, amaflags, uniqueid, userfield"
187 "'%s', '%s', '%s', '%s', '%s', '%s', "
188 "'%s', '%s', '%s', %s, %s, %s, %ld, "
189 "%ld, '%s', '%s', '%s', '%s'"
193 dstchannel, lastapp, lastdata, start,
answer,
end, cdr->duration,
200 double hrbillsec = 0.0;
204 hrbillsec = (double)(
ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0);
206 hrduration = (double)(
ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0);
211 "accountcode, src, dst, dcontext, clid, channel, "
212 "dstchannel, lastapp, lastdata, start, answer, [end], duration, "
213 "billsec, disposition, amaflags, uniqueid"
217 "'%s', '%s', '%s', '%s', '%s', '%s', "
218 "'%s', '%s', '%s', %s, %s, %s, %lf, "
219 "%lf, '%s', '%s', '%s'"
223 dstchannel, lastapp, lastdata, start,
answer,
end, hrduration,
230 "accountcode, src, dst, dcontext, clid, channel, "
231 "dstchannel, lastapp, lastdata, start, answer, [end], duration, "
232 "billsec, disposition, amaflags, uniqueid"
236 "'%s', '%s', '%s', '%s', '%s', '%s', "
237 "'%s', '%s', '%s', %s, %s, %s, %ld, "
238 "%ld, '%s', '%s', '%s'"
242 dstchannel, lastapp, lastdata, start,
answer,
end, cdr->duration,
254 ast_log(
LOG_ERROR,
"Failed to build INSERT statement, no CDR was logged.\n");
265 ast_log(
LOG_ERROR,
"Failed to execute INSERT statement, no CDR was logged.\n");
303 char *buf_ptr, *srh_ptr;
304 char *known_bad[] = {
"select",
"insert",
"update",
"delete",
"drop",
";",
"--",
"\0"};
324 for (idx = 0; *known_bad[idx]; idx++) {
326 memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
333static void get_date(
char *dateField,
size_t len,
struct timeval when)
357 if (dbfcmd(dbproc, buffer) == FAIL) {
364 if (dbsqlexec(dbproc) == FAIL) {
369 while (dbresults(dbproc) != NO_MORE_RESULTS) {
370 while (dbnextrow(dbproc) != NO_MORE_ROWS);
392 if ((login = dblogin()) ==
NULL) {
397 DBSETLAPP(login,
"TSQL");
463 if (oserr != DBNOERR) {
472 ast_debug(1,
"Msg %d, Level %d, State %d, Line %d\n", msgno,
severity, msgstate, line);
481 const char *ptr =
NULL;
512 ast_log(
LOG_ERROR,
"Failed to connect: Database server connection not specified.\n");
537 ast_log(
LOG_ERROR,
"Failed to connect: Database password not specified.\n");
567 ast_log(
LOG_NOTICE,
"High Resolution Time not found, using integers for billsec and duration fields by default.\n");
596 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_cdr_unregister(const char *name)
Unregister a CDR handling engine.
const char * ast_cdr_disp2str(int disposition)
Disposition to a string.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
static char * anti_injection(const char *, int)
static int mssql_connect(void)
static int tds_log(struct ast_cdr *cdr)
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 struct cdr_tds_config * settings
static int execute_and_consume(DBPROCESS *dbproc, const char *fmt,...)
static const char config[]
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]
static char accountcode[AST_MAX_ACCOUNT_CODE]
static int answer(void *data)
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.
#define AST_MAX_USER_FIELD
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
#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)
static char hostname[MAXHOSTNAMELEN]
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
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Responsible for call detail data.
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 hrtime
const ast_string_field password
const ast_string_field username
const ast_string_field table
unsigned int has_userfield
const ast_string_field hostname
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
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