/* callback for a failure during a dialog. */ static void cdr_on_failed( struct dlg_cell* dialog, int type, struct dlg_cb_params* params) { struct sip_msg* msg = 0; if( !dialog || !params) { LM_ERR("invalid values\n!"); return; } if( params->rpl && params->rpl != FAKED_REPLY) { msg = params->rpl; } else if( params->req) { msg = params->req; } else { LM_ERR( "request and response are invalid!"); return; } if( write_cdr( dialog, msg) != 0) { LM_ERR( "failed to write cdr!\n"); return; } }
static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; const char *template_str = NULL; char *expanded_vars = NULL, *sql = NULL; if (globals.shutdown) { return SWITCH_STATUS_SUCCESS; } if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) { if ((globals.legs & CDR_LEG_A)) { if (switch_channel_get_originator_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } else { if (switch_channel_get_originatee_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } } if (globals.debug) { switch_event_t *event; if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { char *buf; switch_channel_event_set_data(channel, event); switch_event_serialize(event, &buf, SWITCH_FALSE); switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); switch_event_destroy(&event); switch_safe_free(buf); } } template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template); if (!template_str) { template_str = default_template; } expanded_vars = switch_channel_expand_variables(channel, template_str); if (!expanded_vars) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error expanding CDR variables.\n"); return SWITCH_STATUS_FALSE; } sql = switch_mprintf("INSERT INTO %s VALUES (%s)", globals.db_table, expanded_vars); assert(sql); write_cdr(sql); switch_safe_free(sql); if (expanded_vars != template_str) { switch_safe_free(expanded_vars); } return status; }
/* callback for an expired dialog. */ static void cdr_on_expired( struct dlg_cell* dialog, int type, struct dlg_cb_params* params) { if( !dialog || !params) { LM_ERR("invalid values\n!"); return; } LM_DBG("dialog '%p' expired!\n", dialog); /* compute duration for timed out acknowledged dialog */ if ( params && params->dlg_data ) { if ( (void*)CONFIRMED_DIALOG_STATE == params->dlg_data) { if( set_end_time( dialog) != 0) { LM_ERR( "failed to set end time!\n"); return; } if( set_duration( dialog) != 0) { LM_ERR( "failed to set duration!\n"); return; } } } if( cdr_expired_dlg_enable && (write_cdr( dialog, 0) != 0)) { LM_ERR( "failed to write cdr!\n"); return; } }
void write_cdr(SE *e) { if(e==NIL){c_out(")"); return;} _write_se(car(e)); if(cdr(e)==NIL){c_out(")"); return;} if(type(cdr(e))!=CONS) { c_out(" . "); _write_se(cdr(e)); c_out(")"); return; } c_out(" "); write_cdr(cdr(e)); }
void _write_se(SE *e) { char numbuf[23]; if(e==NIL) { c_out("()"); return; } switch(type(e)) { case NUM: sprintf(numbuf,"%d",numval(e)); c_out(numbuf); break; case SYM: c_out(symval(e)); break; case CONS: c_out("("); write_cdr(e); break; } }
/* callback for the finish of a dialog (reply to BYE). */ void cdr_on_end_confirmed( struct dlg_cell* dialog, int type, struct dlg_cb_params* params) { if( !dialog || !params || !params->req) { LM_ERR("invalid values\n!"); return; } if( write_cdr( dialog, params->req) != 0) { LM_ERR( "failed to write cdr!\n"); return; } }
/* callback for an expired dialog. */ static void cdr_on_expired( struct dlg_cell* dialog, int type, struct dlg_cb_params* params) { if( !dialog || !params) { LM_ERR("invalid values\n!"); return; } LM_DBG("dialog '%p' expired!\n", dialog); if( cdr_expired_dlg_enable && (write_cdr( dialog, 0) != 0)) { LM_ERR( "failed to write cdr!\n"); return; } }
static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL; char *log_line, *path = NULL; if (globals.shutdown) { return SWITCH_STATUS_SUCCESS; } if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) { if ((globals.legs & CDR_LEG_A)) { if (switch_channel_get_originator_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } else { if (switch_channel_get_originatee_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } } if (!(log_dir = switch_channel_get_variable(channel, "cdr_csv_base"))) { log_dir = globals.log_dir; } if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", log_dir); return SWITCH_STATUS_FALSE; } if (globals.debug) { switch_event_t *event; if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { char *buf; switch_channel_event_set_data(channel, event); switch_event_serialize(event, &buf, SWITCH_FALSE); switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); switch_event_destroy(&event); free(buf); } } g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template); if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) { a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode); } if (!g_template_str) { g_template_str = "\"${accountcode}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${caller_id}\",\"${channel_name}\",\"${bridge_channel}\",\"${last_app}\",\"${last_arg}\",\"${start_stamp}\",\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${amaflags}\",\"${uuid}\",\"${userfield}\";"; } if (!a_template_str) { a_template_str = g_template_str; } log_line = switch_channel_expand_variables(channel, a_template_str); if ((accountcode) && (!globals.masterfileonly)) { path = switch_mprintf("%s%s%s.csv", log_dir, SWITCH_PATH_SEPARATOR, accountcode); assert(path); write_cdr(path, log_line); free(path); } if (g_template_str != a_template_str) { if (log_line != a_template_str) { switch_safe_free(log_line); } log_line = switch_channel_expand_variables(channel, g_template_str); } if (!log_line) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating cdr\n"); return SWITCH_STATUS_FALSE; } path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR); assert(path); write_cdr(path, log_line); free(path); if (log_line != g_template_str) { free(log_line); } return status; }
static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL; char *log_line, *path = NULL,*file = NULL; const char *start_stamp = NULL; char *lbuf = NULL; char *argv[4] = { 0 }; int argc = 0; char *start_day=NULL; char *dargv[8] = {0}; int dargc = 0; char *Y,*M,*D; if (globals.shutdown) { return SWITCH_STATUS_SUCCESS; } if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) { if ((globals.legs & CDR_LEG_A)) { if (switch_channel_get_originator_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } else { if (switch_channel_get_originatee_caller_profile(channel)) { return SWITCH_STATUS_SUCCESS; } } } get_var(start_stamp); if(!start_stamp){ return SWITCH_STATUS_SUCCESS; } fire_cdr_event(channel); if(!(lbuf = strdup(start_stamp))){ return SWITCH_STATUS_SUCCESS; } argc = switch_separate_string(lbuf,' ',argv,(sizeof(argv)/sizeof(argv[0]))); if(argc < 1){ goto done; } if(!(start_day = strdup(argv[0]))){ goto done; } dargc = switch_separate_string(start_day,'-',dargv,(sizeof(dargv)/sizeof(dargv[0]))); if(dargc < 3){ goto done; } Y = dargv[0]; M = dargv[1]; D = dargv[2]; if (!(log_dir = switch_channel_get_variable(channel, "cdr_csv_base"))) { log_dir = globals.log_dir; } if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", log_dir); //return SWITCH_STATUS_FALSE; goto done; } /*if (globals.debug) { switch_event_t *event; if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { char *buf; switch_channel_event_set_data(channel, event); switch_event_serialize(event, &buf, SWITCH_FALSE); switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); switch_event_destroy(&event); free(buf); } }*/ g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template); if (!(accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) { accountcode = switch_channel_get_variable(channel,"dialed_extension"); } if(accountcode){ a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode); } if (!g_template_str) { g_template_str = "\"${accountcode}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${caller_id}\",\"${channel_name}\",\"${bridge_channel}\",\"${last_app}\",\"${last_arg}\",\"${start_stamp}\",\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${amaflags}\",\"${uuid}\",\"${userfield}\";"; } if (!a_template_str) { a_template_str = g_template_str; } if ((accountcode) && (!globals.masterfileonly)) { log_line = switch_channel_expand_variables(channel, a_template_str); if (!log_line) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating cdr\n"); //return SWITCH_STATUS_FALSE; goto done; } path = switch_mprintf("%s%s%s%s%s-%s",log_dir,SWITCH_PATH_SEPARATOR,accountcode,SWITCH_PATH_SEPARATOR,Y,M); assert(path); if (switch_dir_make_recursive(path, SWITCH_DEFAULT_DIR_PERMS| SWITCH_FPROT_WREAD | SWITCH_FPROT_WEXECUTE, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", path); //return SWITCH_STATUS_FALSE; free(path); goto done; } //free(path); file = switch_mprintf("%s%s%s.csv", path, SWITCH_PATH_SEPARATOR, D); assert(file); write_cdr(file, log_line); free(file); free(path); if (log_line != a_template_str) { free(log_line); } } else{ log_line = switch_channel_expand_variables(channel, g_template_str); if (!log_line) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating cdr\n"); //return SWITCH_STATUS_FALSE; goto done; } path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR); assert(path); write_cdr(path, log_line); free(path); if (log_line != g_template_str) { free(log_line); } } done: switch_safe_free(start_day); switch_safe_free(lbuf); return status; }