[commit] r1720 - in freeswitch/branches/mishehu/src: . mod/endpoints/mod_portaudio mod/loggers/mod_cdr
Author: mishehu Date: Sat Jul 1 03:08:24 2006 New Revision: 1720 Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/mod_portaudio.c freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.h freeswitch/branches/mishehu/src/switch.c freeswitch/branches/mishehu/src/switch_ivr.c Log: Fixed up MysqlCDR to work again, at least it does with no chanvars or with only chanvars_supp. Still need to test the chanvars_fixed for logging direct to the main table in a more normalized fashion. Merged to trunk r1719. Modified: freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/mod_portaudio.c ============================================================================== --- freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/mod_portaudio.c (original) +++ freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/mod_portaudio.c Sat Jul 1 03:08:24 2006 @@ -163,6 +163,7 @@ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call_id", tech_pvt->call_id); switch_channel_event_set_data(channel, event); switch_event_fire(&event); } Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp ============================================================================== --- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp (original) +++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp Sat Jul 1 03:08:24 2006 @@ -26,6 +26,13 @@ lastapp_length = strlen(lastapp); lastdata_length = strlen(lastdata); + if(chanvars_fixed_list.size() > 0) + process_channel_variables(chanvars_fixed_list,newchannel->channel); + + if(chanvars_supp_list.size() > 0) + process_channel_variables(chanvars_supp_list,chanvars_fixed_list,newchannel->channel,repeat_fixed_in_supp); + + process_channel_variables(chanvars_fixed_list,newchannel->channel); } } @@ -37,13 +44,14 @@ bool MysqlCDR::connectionstate = 0; bool MysqlCDR::logchanvars = 0; -bool MysqlCDR::repeat_fixed_in_supp_chanvars = 0; +bool MysqlCDR::repeat_fixed_in_supp = 0; std::list<std::string> MysqlCDR::chanvars_fixed_list; std::list<std::string> MysqlCDR::chanvars_supp_list; std::string MysqlCDR::chanvars_fixed_types; bool MysqlCDR::activated = 0; -char MysqlCDR::sql_query[1024] = ""; -char MysqlCDR::sql_query_chanvars[1024] = ""; +char* MysqlCDR::sql_query = 0; +std::string MysqlCDR::tmp_sql_query; +char MysqlCDR::sql_query_chanvars[100] = ""; MYSQL* MysqlCDR:: conn = 0; MYSQL_STMT* MysqlCDR::stmt=0; MYSQL_STMT* MysqlCDR::stmt_chanvars=0; @@ -55,6 +63,9 @@ void MysqlCDR::connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param) { + if(activated) + disconnect(); + activated = 0; // Set it as inactive initially connectionstate = 0; // Initialize it to false to show that we aren't yet connected. @@ -106,7 +117,7 @@ { std::cout << std::endl << "Shall we parse the fixed chanvars list for MysqlCDR?" << std::endl; parse_channel_variables_xconfig(unparsed,chanvars_fixed_list,chanvars_fixed_types); - logchanvars=1; + //logchanvars=1; } } else if(!strcmp(var,"chanvars_supp")) @@ -115,6 +126,7 @@ { std::string unparsed = val; bool fixed = 0; + logchanvars = 1; std::cout << std::endl << "Shall we parse the supplementary chanvars list for MysqlCDR?" << std::endl; parse_channel_variables_xconfig(unparsed,chanvars_supp_list,fixed); } @@ -125,7 +137,7 @@ { std::string repeat = val; if(repeat == "Y" || repeat == "y" || repeat == "1") - repeat_fixed_in_supp_chanvars = 1; + repeat_fixed_in_supp = 1; } } } @@ -137,12 +149,33 @@ if(activated) { - char tmpsql_query[] = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,ani2,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - memset(sql_query,0,1024); - strncpy(sql_query,tmpsql_query,strlen(tmpsql_query)); + tmp_sql_query = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,ani2,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags"; + if(chanvars_fixed_list.size() > 0 ) + { + std::list<std::string>::iterator iItr, iEnd; + for(iItr = chanvars_fixed_list.begin(), iEnd = chanvars_fixed_list.end(); iItr != iEnd; iItr++) + { + tmp_sql_query.append(","); + tmp_sql_query.append(*iItr); + } + } + + tmp_sql_query.append(") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?"); + + if(chanvars_fixed_list.size() > 0 ) + { + for(switch_size_t i = 0; i < chanvars_fixed_list.size(); i++) + tmp_sql_query.append(",?"); + } + + tmp_sql_query.append(")"); + + std::vector<char> tempfirstvector(tmp_sql_query.begin(), tmp_sql_query.end()); + tempfirstvector.push_back('\0'); + sql_query = &tempfirstvector[0]; char tempsql_query_chanvars[] = "INSERT INTO chanvars (callid,varname,varvalue) VALUES(?,?,?)"; - memset(sql_query_chanvars,0,1024); + memset(sql_query_chanvars,0,100); strncpy(sql_query_chanvars,tempsql_query_chanvars,strlen(tempsql_query_chanvars)); conn = mysql_init(NULL); @@ -254,6 +287,77 @@ add_parameter(hangupcause,MYSQL_TYPE_LONG,0); add_parameter(amaflags,MYSQL_TYPE_TINY,0); + std::list<void*> temp_chanvars_holder; // This is used for any fixed chanvars, as we don't want things out of scope + + if(chanvars_fixed_list.size() > 0) + { + switch_size_t i = 0; // temporary variable, i is current spot on the string of types + std::list<std::pair<std::string,std::string> >::iterator iItr, iEnd; + for(iItr = chanvars_fixed.begin(), iEnd = chanvars_fixed.end(); iItr != iEnd; iItr++) + { + if(chanvars_fixed_types[i] == 'i') + { + int x; + x = 0; + bool is_null = 0; + if(iItr->second.size() > 0) + { + std::istringstream istring(iItr->second); + istring >> x; + } + else + is_null = 1; + temp_chanvars_holder.push_back(&x); + add_parameter(x,MYSQL_TYPE_LONG,is_null); + } + else if(chanvars_fixed_types[i] == 'd') + { + double x; + x = 0; + bool is_null = 0; + if(iItr->second.size() > 0) + { + std::istringstream istring(iItr->second); + istring >> x; + } + else + is_null = 1; + temp_chanvars_holder.push_back(&x); + add_parameter(x,MYSQL_TYPE_DOUBLE,is_null); + } + else if(chanvars_fixed_types[i] == 't') + { + short x; + x = 0; + bool is_null = 0; + if(iItr->second.size() > 0) + { + std::istringstream istring(iItr->second); + istring >> x; + } + else + is_null = 1; + temp_chanvars_holder.push_back(&x); + add_parameter(x,MYSQL_TYPE_TINY,is_null); + } + else if(chanvars_fixed_types[i] == 's' || chanvars_fixed_types[i] == 'x') + { + long unsigned int stringlength = iItr->second.size(); + char x[(stringlength+1)]; + strncpy(x,iItr->second.c_str(),stringlength); + + temp_chanvars_holder.push_back(&stringlength); + temp_chanvars_holder.push_back(&x); + if(chanvars_fixed_types[i] == 's') + add_string_parameter(x,stringlength,MYSQL_TYPE_VAR_STRING,0); + else + add_string_parameter(x,stringlength,MYSQL_TYPE_DECIMAL,0); + } + + i++; + } + } + MYSQL_BIND *bindmetemp; bindmetemp = new MYSQL_BIND[bindme.size()]; copy(bindme.begin(), bindme.end(), bindmetemp); @@ -264,11 +368,11 @@ const char* bah2 = mysql_stmt_error(stmt); switch_console_printf(SWITCH_CHANNEL_LOG,"MySQL encountered error: %s\n",bah2); - - long long insertid = mysql_stmt_insert_id(stmt); - + if(logchanvars && chanvars_supp.size() > 0) { + long long insertid = mysql_stmt_insert_id(stmt); + std::map<std::string,std::string>::iterator iItr,iBeg,iEnd; iEnd = chanvars_supp.end(); for(iItr = chanvars_supp.begin(); iItr != iEnd; iItr++) @@ -329,6 +433,7 @@ */ delete [] bindmetemp; + temp_chanvars_holder.clear(); return 1; } @@ -336,8 +441,16 @@ void MysqlCDR::disconnect() { mysql_stmt_close(stmt); - mysql_stmt_close(stmt_chanvars); + if(logchanvars) + mysql_stmt_close(stmt_chanvars); mysql_close(conn); + activated = 0; + logchanvars = 0; + chanvars_fixed_list.clear(); + chanvars_supp_list.clear(); + chanvars_fixed_types.clear(); + connectionstate = 0; + tmp_sql_query.clear(); } Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.h ============================================================================== --- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.h (original) +++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.h Sat Jul 1 03:08:24 2006 @@ -1,5 +1,6 @@ #include "baseregistry.h" #include <list> +#include <sstream> #include <mysql.h> #ifndef MYSQLCDR @@ -20,8 +21,9 @@ private: static bool activated; - static char sql_query[1024]; - static char sql_query_chanvars[1024]; + static char *sql_query; + static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql + static char sql_query_chanvars[100]; static MYSQL *conn; static MYSQL_STMT *stmt; static MYSQL_STMT *stmt_chanvars; @@ -30,7 +32,7 @@ static std::list<std::string> chanvars_fixed_list; static std::string chanvars_fixed_types; static std::list<std::string> chanvars_supp_list; // The supplemental list - static bool repeat_fixed_in_supp_chanvars; + static bool repeat_fixed_in_supp; static char hostname[255]; static char username[255]; static char dbname[255]; Modified: freeswitch/branches/mishehu/src/switch.c ============================================================================== --- freeswitch/branches/mishehu/src/switch.c (original) +++ freeswitch/branches/mishehu/src/switch.c Sat Jul 1 03:08:24 2006 @@ -81,7 +81,7 @@ SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); #else int pid; - //nice(-20); + nice(-20); #endif #ifdef HAVE_MLOCKALL Modified: freeswitch/branches/mishehu/src/switch_ivr.c ============================================================================== --- freeswitch/branches/mishehu/src/switch_ivr.c (original) +++ freeswitch/branches/mishehu/src/switch_ivr.c Sat Jul 1 03:08:24 2006 @@ -1123,6 +1123,7 @@ switch_channel_get_name(caller_channel), switch_channel_get_name(peer_channel) ); + switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER); } return status;
participants (1)
-
Freeswitch SVN