[Freeswitch-svn] [commit] r1602 - in freeswitch/branches/mishehu/src/mod: endpoints/mod_portaudio loggers/mod_cdr
mishehu at freeswitch.org
mishehu at freeswitch.org
Mon Jun 12 01:12:25 EDT 2006
Author: mishehu
Date: Mon Jun 12 01:12:25 2006
New Revision: 1602
Modified:
freeswitch/branches/mishehu/src/mod/endpoints/mod_portaudio/mod_portaudio.c
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.h
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.h
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.h
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema-update.mysql
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema.sql
Log:
Added in channel variable handling now. Code for handling it in BaseCDR, and AnthmCDR implements it. Merged to trunk r1601.
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 Mon Jun 12 01:12:25 2006
@@ -886,7 +886,7 @@
void *val;
int i = 0;
- for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
+ for (hi = switch_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
tech_pvt = val;
channel = switch_core_session_get_channel(tech_pvt->session);
@@ -977,7 +977,7 @@
switch_hash_index_t *hi;
void *val;
if (!callid || !strcasecmp(callid, "all")) {
- for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
+ for (hi = switch_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
tech_pvt = val;
print_info(tech_pvt, stream);
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.cpp Mon Jun 12 01:12:25 2006
@@ -16,7 +16,7 @@
memset(formattedcallanswerdate,0,100);
memset(formattedcallendate,0,100);
- if(channel != 0)
+ if(newchannel != 0)
{
switch_time_exp_t tempcallstart, tempcallanswer, tempcallend;
memset(&tempcallstart,0,sizeof(tempcallstart));
@@ -34,16 +34,24 @@
switch_strftime(formattedcallenddate,&retsizeced,sizeof(formattedcallenddate),format,&tempcallend);
}
- outputfile_name = outputfiile_path;
+ outputfile_name = outputfile_path;
outputfile_name.append("/");
outputfile_name.append(myuuid); // The goal is to have a resulting filename of "/path/to/myuuid"
outputfile_name.append(".atm"); // The extension is in honor of anthm
outputfile.open(outputfile_name);
+
+ process_channel_variables(chanvars_list,newchannel->channel);
}
-bool AnthmCDR::activated;
-bool AnthmCDR::connectionstate;
+AnthmCDR::~AnthmCDR()
+{
+ outputfile.close();
+}
+
+bool AnthmCDR::activated=0;
+bool AnthmCDR::logchanvars=0;
+bool AnthmCDR::connectionstate=0;
std::string AnthmCDR::outputfile_path;
std::list<std::string> AnthmCDR::chanvars_list;
@@ -70,6 +78,11 @@
{
std::string unparsed;
unparsed = val;
+ if(unparsed.size() > 0)
+ {
+ chanvars_list = parse_channel_variables_xconfig(unparsed);
+ logchanvars=1;
+ };
}
}
@@ -82,11 +95,45 @@
{
bool retval = 0;
if(!outputfile)
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AnthmCDR::process_record(): Unable to open file %s to commit the call record to. Invalid path name, invalid permissions, or no space available?\n",outputfile_name.cstr());
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AnthmCDR::process_record(): Unable to open file %s to commit the call record to. Invalid path name, invalid permissions, or no space available?\n",outputfile_name.c_str());
else
{
// Format the call record and proceed from here...
-
+ outputfile << "$VAR1 = {" << std::endl;
+ outputfile << "\t\'callstartdate\' = \'" << callstartdate << "\'," << std::endl;
+ outputfile << "\t\'callanswerdate\' = " << callanswerdate << "\'," << std::endl;
+ outputfile << "\t\'callenddate\' = " << callenddate << "\'," << std::endl;
+ outputfile << "\t\'hangupcause\' = " << hangupcause_text << "\'," << std::endl;
+ outputfile << "\t\'hangupcausecode\' = " << hangcause << "\'," << std::endl;
+ outputfile << "\t\'clid\' = " << clid << "\'," << std::endl;
+ outputfile << "\t\'originated\' = " << originated << "\'," << std::endl;
+ outputfile << "\t\'dialplan\' = " << dialplan << "\'," << std::endl;
+ outputfile << "\t\'myuuid\' = " << myuuid << "\'," << std::endl;
+ outputfile << "\t\'destuuid\' = " << destuuid << "\'," << std::endl;
+ outputfile << "\t\'src\' = " << src << "\'," << std::endl;
+ outputfile << "\t\'dst\' = " << dst << "\'," << std::endl;
+ outputfile << "\t\'srcchannel\' = " << srcchannel << "\'," << std::endl;
+ outputfile << "\t\'dstchannel\' = " << dstchannel << "\'," << std::endl;
+ outputfile << "\t\'ani\' = " << ani << "\'," << std::endl;
+ outputfile << "\t\'ani2\' = " << ani2 << "\'," << std::endl;
+ outputfile << "\t\'network_addr\' = " << network_addr << "\'," << std::endl;
+ outputfile << "\t\'lastapp\' = " << lastapp << "\'," << std::endl;
+ outputfile << "\t\'lastdata\' = " << lastdata << "\'," << std::endl;
+ outputfile << "\t\'billusec\' = " << billusec << "\'," << std::endl;
+ outputfile << "\t\'disposition\' = " << disposition << "\'," << std::endl;
+ outputfile << "\t\'amaflags\' = " << amaflags << "\'," << std::endl;
+
+ // Now to process chanvars
+ outputfile << "\t\'chanvars\' => {" << std::endl;
+ if(chanvars.size() > 0 )
+ {
+ std::map<std::string,std::string>::iterator iItr,iBeg,iEnd;
+ iBeg = chanvars.begin();
+ iEnd = chanvars.end();
+ for(iItr = iBeg; iItr != iEnd; iItr++)
+ outputfile << "\t\t\'" << iItr->first << "\' = \'" << iItr.second << "\'," << std::endl;
+ }
+ outputfile << "\t}," << std::endl << "};" << std::endl << std::endl;
}
}
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.h (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.h Mon Jun 12 01:12:25 2006
@@ -5,6 +5,7 @@
// #include <fcntl.h>
#include <iostream>
#include <ofstream>
+#include <list>
#ifndef ANTHMCDR
#define ANTHMCDR
@@ -25,6 +26,7 @@
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
+ static bool logchanvars;
static std::string outputfile_path; // The directory we'll dump these into
static std::list<std::string> chanvars_list; // A list containing the list of chanvars to capture
char formattedcallstartdate[100];
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.cpp Mon Jun 12 01:12:25 2006
@@ -142,6 +142,68 @@
}
-void BaseCDR::process_channel()
+std::list<std::string>& BaseCDR::parse_channel_variables_xconfig(std::string& unparsed)
{
+ std::list<std::string> stringlist;
+ std::string tempstring;
+ long j = 0;
+ for(std::string::size_type i = 0; j != -1; )
+ {
+ j = string1.find(',',i);
+ if(j > 0)
+ {
+ tempstring = unparsed.substr(i,(j-i));
+ stringlist.push(tempstring);
+ i =j+1;
+ }
+ else
+ {
+ tempstring = unparsed.substr(i);
+ stringlist.push(tempstring);
+ }
+ }
+
+ // Now we need to clean up in case somebody put in a '*' and still left in other nonsense too
+ std::list<std::string>::iterator iBeg,iItr,iEnd;
+ iBeg = stringlist.begin();
+ iEnd = stringlist.end();
+ for(bool testvalue = 1; iItr = stringlist.begin(); iItr != iEnd && testvalue ; iItr++)
+ {
+ if(iItr == "*")
+ {
+ std::string tempstring = "*";
+ stringlist.clear();
+ stringlist.push(tempstring);
+ testvalue = 0;
+ }
+ }
+ return stringlist;
+}
+
+void BaseCDR::process_channel_variables(const std::list<std::string>& stringlist, switch_channel_t *channel)
+{
+ if(stringlist.front() == "*")
+ {
+ switch_hash_index_t *hi;
+ char *var,*val;
+
+ for (hi = switch_hash_first(0, channel->variables); hi; hi = switch_hash_next(hi))
+ {
+ switch_hash_this(hi, &var, NULL, &val);
+ chanvars[*var] = *val;
+ }
+ }
+ else
+ {
+ std::list<std::string>::iterator iBeg,iItr,iEnd;
+ iBeg = stringlist.begin();
+ iEnd = stringlist.end();
+
+ for(iItr = stringlist.begin(); iItr != iEnd; iItr++)
+ {
+ std::string tempstring = switch_channel_get_variable(channel,iItr->c_str());
+ if(tempstring.size() > 0)
+ chanvars[*iItr] = tempstring;
+ }
+ }
}
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.h (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/basecdr.h Mon Jun 12 01:12:25 2006
@@ -15,6 +15,8 @@
#ifdef __cplusplus
#include <vector>
+#include <list>
+#include <queue>
#include <switch.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -44,8 +46,9 @@
virtual void tempdump_record() = 0;
virtual void reread_tempdumped_records() = 0;
protected:
- void process_channel_variables();
- switch_channel_t *tempchannel;
+ std::list<std::string>& parse_channel_variables_xconfig(std::string& unparsed);
+ void process_channel_variables(const std::list<std::string>& stringlist,switch_channel_t *channel);
+ //switch_channel_t *tempchannel;
switch_time_t callstartdate;
switch_time_t callanswerdate;
switch_time_t callenddate;
@@ -68,6 +71,7 @@
switch_time_t billusec; // Yes, you heard me, we're measuring in microseconds
int disposition; // Currently 0 = Busy/Unanswered, 1 = Answered
int amaflags;
+ std::map<std::string,std::string> chanvars;
/*
This is what happens when you base the ideas off of Asterisk... you end up with an inconvenient asteriskism.
char accountcode[20];
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 Mon Jun 12 01:12:25 2006
@@ -31,10 +31,14 @@
}
bool MysqlCDR::connectionstate = 0;
+bool MysqlCDR::logchanvars = 0;
+std::list<std::string> MysqlCDR::chanvars_list;
bool MysqlCDR::activated = 0;
char MysqlCDR::sql_query[1024] = "";
+char MysqlCDR::sql_query_chanvars[1024] = "";
MYSQL* MysqlCDR:: conn = 0;
MYSQL_STMT* MysqlCDR::stmt=0;
+MYSQL_STMT* MysqlCDR::stmt_chanvars=0;
char MysqlCDR::hostname[255] = "";
char MysqlCDR::username[255] ="";
char MysqlCDR::dbname[255] = "";
@@ -46,11 +50,11 @@
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "MysqlCDR::connect() - Trying to connect to the server.\n");
activated = 0; // Set it as inactive initially
connectionstate = 0; // Initialize it to false to show that we aren't yet connected.
- char tmpsql_query[] = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,ani2,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,amaflags) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ 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));
- if ((*settings = switch_xml_child(*cfg, "anthmcdr")))
+ if ((*settings = switch_xml_child(*cfg, "mysqlcdr")))
{
for (param = switch_xml_child(*settings, "param"); *param; *param = (*param)->next)
{
@@ -65,6 +69,11 @@
strncpy(password,val,strlen(val));
else if(!strcmp(var,"dbname"))
strncpy(dbname,val,strlen(val));
+ else if(!strcmp(var,"chanvars")
+ {
+ logchanvars = 1;
+
+ }
}
activated = 1;
@@ -169,6 +178,7 @@
add_string_parameter(lastdata,lastdata_length,MYSQL_TYPE_VAR_STRING,0);
add_parameter(billusec,MYSQL_TYPE_LONGLONG,0);
add_parameter(disposition,MYSQL_TYPE_TINY,0);
+ add_parameter(hangupcause,MYSQL_TYPE_LONG,0);
add_parameter(amaflags,MYSQL_TYPE_TINY,0);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "MysqlCDR::process_record() - Trying to process, bindme has %d elements.\n",bindme.size());
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 Mon Jun 12 01:12:25 2006
@@ -1,4 +1,5 @@
#include "baseregistry.h"
+#include <list>
#include <mysql.h>
#ifndef MYSQLCDR
@@ -20,9 +21,13 @@
private:
static bool activated;
static char sql_query[1024];
+ static char sql_query_chanvars[1024];
static MYSQL *conn;
static MYSQL_STMT *stmt;
+ static MYSQL_STMT *stmt_chanvars;
static bool connectionstate;
+ static bool logchanvars;
+ static std::list<std::string> chanvars_list;
static char hostname[255];
static char username[255];
static char dbname[255];
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema-update.mysql
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema-update.mysql (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema-update.mysql Mon Jun 12 01:12:25 2006
@@ -1,2 +1,5 @@
ALTER TABLE freeswitchcdr modify callid bigint unsigned auto_increment;
ALTER TABLE freeswitchcdr Engine=InnoDB;
+
+ALTER TABLE chanvars modify callid bigint unsigned auto_increment;
+ALTER TABLE chanvars Engine=InnoDB;
\ No newline at end of file
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema.sql
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema.sql (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/schema.sql Mon Jun 12 01:12:25 2006
@@ -18,6 +18,7 @@
lastdata varchar(255) default "",
billusec bigint default 0,
disposition tinyint default 0, /* 0 = Busy or Unanswered, 1 = Answered */
+ hangupcause int default 0,
amaflags tinyint default 0,
/*
This section not needed, because it was an old asteriskism. A chan_var table is to replace it perhaps.
@@ -29,3 +30,11 @@
create index myuuid_index on freeswitchcdr (myuuid);
create index destuuid_index on freeswitchcdr (destuuid);
+
+create table chanvars (
+ callid bigint unsigned default 0,
+ varname varchar(80) NOT NULL,
+ varval varchar(255) NOT NULL
+);
+
+create index callid_index on chanvars(callid);
\ No newline at end of file
More information about the Freeswitch-svn
mailing list