40 #include "asterisk/config.h"
46 #define DATE_FORMAT "%Y-%m-%d %T"
48 static const char name[] =
"ODBC";
66 char sqlcmd[2048] =
"", timestr[128];
74 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s "
75 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
76 "lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
77 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr);
79 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s "
80 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,"
81 "duration,billsec,disposition,amaflags,accountcode) "
82 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?)", table, timestr);
85 ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, obj->
con, &stmt);
87 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
88 ast_verb(11,
"cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
89 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
93 SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
clid), 0, cdr->
clid, 0, NULL);
94 SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
src), 0, cdr->
src, 0, NULL);
95 SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dst), 0, cdr->
dst, 0, NULL);
96 SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dcontext), 0, cdr->
dcontext, 0, NULL);
97 SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
channel), 0, cdr->
channel, 0, NULL);
98 SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dstchannel), 0, cdr->
dstchannel, 0, NULL);
99 SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastapp), 0, cdr->
lastapp, 0, NULL);
100 SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastdata), 0, cdr->
lastdata, 0, NULL);
103 double hrbillsec = 0.0;
111 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrduration, 0, NULL);
112 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrbillsec, 0, NULL);
114 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
duration, 0, NULL);
115 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
billsec, 0, NULL);
121 SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
disposition, 0, NULL);
122 SQLBindParameter(stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
amaflags, 0, NULL);
123 SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
accountcode), 0, cdr->
accountcode, 0, NULL);
126 SQLBindParameter(stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
uniqueid), 0, cdr->
uniqueid, 0, NULL);
127 SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
userfield), 0, cdr->
userfield, 0, NULL);
130 ODBC_res = SQLExecDirect(stmt, (
unsigned char *)sqlcmd, SQL_NTS);
132 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
133 ast_verb(11,
"cdr_odbc: Error in ExecDirect: %d\n", ODBC_res);
134 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
156 SQLRowCount(stmt, &rows);
157 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
178 ast_log(
LOG_WARNING,
"cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config_file);
209 ast_debug(1,
"cdr_odbc: Logging uniqueid\n");
212 ast_debug(1,
"cdr_odbc: Not logging uniqueid\n");
217 ast_debug(1,
"cdr_odbc: Logging in GMT\n");
220 ast_debug(1,
"cdr_odbc: Logging in local time\n");
225 ast_debug(1,
"cdr_odbc: Logging billsec and duration fields as floats\n");
228 ast_debug(1,
"cdr_odbc: Logging billsec and duration fields as integers\n");
243 ast_verb(3,
"cdr_odbc: dsn is %s\n", dsn);
244 ast_verb(3,
"cdr_odbc: table is %s\n", table);
277 ast_verb(11,
"cdr_odbc: free dsn\n");
281 ast_verb(11,
"cdr_odbc: free table\n");
static int unload_module(void)
char accountcode[AST_MAX_ACCOUNT_CODE]
Asterisk main include file. File version handling, generic pbx functions.
static const char config_file[]
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
static int odbc_load_module(int reload)
char dstchannel[AST_MAX_EXTENSION]
static struct ast_flags config
#define ast_test_flag(p, flag)
#define ast_set_flag(p, flag)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char dcontext[AST_MAX_EXTENSION]
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Structure for variables, used for configurations and for channel variables.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
char lastdata[AST_MAX_EXTENSION]
#define ast_debug(level,...)
Log a DEBUG message.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
General Asterisk PBX channel definitions.
#define ast_config_load(filename, flags)
Load a config file.
char dst[AST_MAX_EXTENSION]
char channel[AST_MAX_EXTENSION]
static int load_module(void)
static int odbc_log(struct ast_cdr *cdr)
Responsible for call detail data.
char lastapp[AST_MAX_EXTENSION]
SQLHSTMT ast_odbc_direct_execute(struct odbc_obj *obj, SQLHSTMT(*exec_cb)(struct odbc_obj *obj, void *data), void *data)
Executes an non prepared statement and returns the resulting statement handle.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ast_odbc_request_obj(a, b)
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...
Structure used to handle boolean flags.
#define ast_clear_flag(p, flag)
char src[AST_MAX_EXTENSION]
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
char clid[AST_MAX_EXTENSION]
#define CONFIG_STATUS_FILEINVALID
void ast_odbc_release_obj(struct odbc_obj *obj)
Releases an ODBC object previously allocated by ast_odbc_request_obj()
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
char * ast_cdr_disp2str(int disposition)
Disposition to a string.
void ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
char userfield[AST_MAX_USER_FIELD]
#define CONFIG_STATUS_FILEUNCHANGED