54 #define DATE_FORMAT "%Y-%m-%d %T" 56 static const char name[] =
"ODBC";
75 char sqlcmd[2048] =
"", timestr[128], new_columns[120] =
"", new_values[7] =
"";
84 snprintf(new_columns,
sizeof(new_columns),
"%s",
",peeraccount,linkedid,sequence");
85 snprintf(new_values,
sizeof(new_values),
"%s",
",?,?,?");
89 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s " 90 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp," 91 "lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield%s) " 92 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,?%s)",
table, new_columns, timestr, new_values);
94 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s " 95 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata," 96 "duration,billsec,disposition,amaflags,accountcode%s) " 97 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?%s)",
table, new_columns, timestr, new_values);
100 ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, obj->
con, &stmt);
102 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
104 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
108 SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
clid), 0, cdr->
clid, 0, NULL);
109 SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
src), 0, cdr->
src, 0, NULL);
110 SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dst), 0, cdr->
dst, 0, NULL);
111 SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dcontext), 0, cdr->
dcontext, 0, NULL);
112 SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
channel), 0, cdr->
channel, 0, NULL);
113 SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dstchannel), 0, cdr->
dstchannel, 0, NULL);
114 SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastapp), 0, cdr->
lastapp, 0, NULL);
115 SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastdata), 0, cdr->
lastdata, 0, NULL);
118 double hrbillsec = 0.0;
126 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrduration, 0, NULL);
127 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrbillsec, 0, NULL);
129 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
duration, 0, NULL);
130 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
billsec, 0, NULL);
136 SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(disposition) + 1, 0, disposition, 0, NULL);
138 SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
disposition, 0, NULL);
140 SQLBindParameter(stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
amaflags, 0, NULL);
141 SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
accountcode), 0, cdr->
accountcode, 0, NULL);
145 SQLBindParameter(stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
uniqueid), 0, cdr->
uniqueid, 0, NULL);
146 SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
userfield), 0, cdr->
userfield, 0, NULL);
151 SQLBindParameter(stmt, i, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
peeraccount), 0, cdr->
peeraccount, 0, NULL);
152 SQLBindParameter(stmt, i + 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
linkedid), 0, cdr->
linkedid, 0, NULL);
153 SQLBindParameter(stmt, i + 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
sequence, 0, NULL);
158 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
159 ast_log(
LOG_WARNING,
"cdr_odbc: Error in ExecDirect: %d, query is: %s\n", ODBC_res, sqlcmd);
160 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
182 SQLRowCount(stmt, &rows);
183 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
235 ast_debug(1,
"cdr_odbc: Logging uniqueid\n");
238 ast_debug(1,
"cdr_odbc: Not logging uniqueid\n");
243 ast_debug(1,
"cdr_odbc: Logging in GMT\n");
246 ast_debug(1,
"cdr_odbc: Logging in local time\n");
251 ast_debug(1,
"cdr_odbc: Logging billsec and duration fields as floats\n");
254 ast_debug(1,
"cdr_odbc: Logging billsec and duration fields as integers\n");
279 ast_debug(1,
"cdr_odbc: Add new cdr columns\n");
282 ast_debug(1,
"cdr_odbc: Not add new cdr columns\n");
331 .requires =
"cdr,res_odbc",
static int unload_module(void)
int ast_cdr_backend_suspend(const char *name)
Suspend a CDR backend temporarily.
char accountcode[AST_MAX_ACCOUNT_CODE]
Asterisk main include file. File version handling, generic pbx functions.
static const char config_file[]
int ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
static int odbc_load_module(int reload)
char dstchannel[AST_MAX_EXTENSION]
static struct ast_flags config
#define ast_test_flag(p, flag)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
#define ast_set_flag(p, flag)
int ast_cdr_backend_unsuspend(const char *name)
Unsuspend a CDR backend.
#define CONFIG_STATUS_FILEINVALID
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_strdup(str)
A wrapper for strdup()
static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
char lastdata[AST_MAX_EXTENSION]
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_config_load(filename, flags)
Load a config file.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
General Asterisk PBX channel definitions.
char linkedid[AST_MAX_UNIQUEID]
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define ast_strdupa(s)
duplicate a string in memory from the stack
char uniqueid[AST_MAX_UNIQUEID]
char dst[AST_MAX_EXTENSION]
char channel[AST_MAX_EXTENSION]
static int load_module(void)
static int odbc_log(struct ast_cdr *cdr)
#define CONFIG_STATUS_FILEUNCHANGED
Responsible for call detail data.
char lastapp[AST_MAX_EXTENSION]
const char * ast_cdr_disp2str(int disposition)
Disposition to a string.
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".
#define ast_odbc_request_obj(a, b)
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...
Structure used to handle boolean flags.
#define ast_clear_flag(p, flag)
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",)
char src[AST_MAX_EXTENSION]
char peeraccount[AST_MAX_ACCOUNT_CODE]
SQLRETURN ast_odbc_execute_sql(struct odbc_obj *obj, SQLHSTMT *stmt, const char *sql)
Execute a nonprepared SQL query.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
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]
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 userfield[AST_MAX_USER_FIELD]