[Freeswitch-svn] [commit] r1653 - freeswitch/branches/mishehu/src/mod/loggers/mod_cdr
mishehu at freeswitch.org
mishehu at freeswitch.org
Wed Jun 21 01:10:27 EDT 2006
Author: mishehu
Date: Wed Jun 21 01:10:27 2006
New Revision: 1653
Modified:
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/anthmcdr.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.h
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/cdrcontainer.cpp
freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/mysqlcdr.cpp
Log:
Added functionality to only create objects that are active in an efficient manner. Fixed loading to mark modules as active or not properly. Merged to trunk r1652
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 Wed Jun 21 01:10:27 2006
@@ -66,7 +66,7 @@
if ((settings = switch_xml_child(cfg, "anthmcdr")))
{
- int tempcount = 0;
+ int count_config_params = 0; // Need to make sure all params are set before we load
for (param = switch_xml_child(settings, "param"); param; param = param->next)
{
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -74,23 +74,29 @@
if (!strcmp(var, "path"))
{
- outputfile_path = val;
- tempcount++;
+ if(val != 0)
+ outputfile_path = val;
+ count_config_params++;
}
else if (!strcmp(var, "chanvars"))
{
- std::string unparsed;
- unparsed = val;
- if(unparsed.size() > 0)
+ if(val != 0)
{
- chanvars_list = parse_channel_variables_xconfig(unparsed);
- logchanvars=1;
+ std::string unparsed;
+ unparsed = val;
+ if(unparsed.size() > 0)
+ {
+ chanvars_list = parse_channel_variables_xconfig(unparsed);
+ logchanvars=1;
+ }
}
}
}
- //if(tmpcount > 0)
- activated = 1;
+ if(count_config_params > 0)
+ activated = 1;
+ else
+ switch_console_printf(SWITCH_CHANNEL_LOG,"AnthmCDR::connect(): You did not specify the minimum parameters for using this module. You must specify at least a path to have the records logged to.\n");
}
}
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.cpp Wed Jun 21 01:10:27 2006
@@ -21,6 +21,26 @@
return m_bases.end();
}
+void BaseRegistry::reset_active()
+{
+ active_bases.clear();
+}
+
+void BaseRegistry::add_active(iterator tempobject)
+{
+ active_bases.push_back(*tempobject);
+}
+
+BaseRegistry::iterator BaseRegistry::active_begin()
+{
+ return active_bases.begin();
+}
+
+BaseRegistry::iterator BaseRegistry::active_end()
+{
+ return active_bases.end();
+}
+
BaseRegistration::BaseRegistration(basecdr_creator creator)
{
BaseRegistry::get().add(creator);
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.h (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/baseregistry.h Wed Jun 21 01:10:27 2006
@@ -1,4 +1,5 @@
#include "basecdr.h"
+#include <iostream>
#ifndef BASECDRREGISTRY
#define BASECDRREGISTRY
@@ -16,13 +17,18 @@
class BaseRegistry
{
private:
- std::vector<basecdr_creator> m_bases;
+ std::vector<basecdr_creator> m_bases; // Stores all modules
+ std::vector<basecdr_creator> active_bases; // Stores only active modules
public:
typedef std::vector<basecdr_creator>::iterator iterator;
static BaseRegistry& get();
void add(basecdr_creator);
+ void reset_active(); // Clears the active vector for reloading of configuration.
+ void add_active(iterator);
iterator begin();
iterator end();
+ iterator active_begin();
+ iterator active_end();
};
class BaseRegistration
Modified: freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/cdrcontainer.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/cdrcontainer.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/loggers/mod_cdr/cdrcontainer.cpp Wed Jun 21 01:10:27 2006
@@ -30,6 +30,9 @@
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
ptr->connect(cfg,xml,settings,param);
+
+ if(ptr->is_activated())
+ registry.add_active(it);
}
}
@@ -48,7 +51,7 @@
newchannel = 0;
BaseRegistry& registry(BaseRegistry::get());
- for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
+ for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
@@ -77,7 +80,7 @@
newchannel->originateprofile = switch_channel_get_originator_caller_profile(newchannel->channel);
BaseRegistry& registry(BaseRegistry::get());
- for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
+ for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
/*
First time it might be originator profile, or originatee. Second and
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 Wed Jun 21 01:10:27 2006
@@ -62,6 +62,7 @@
memset(sql_query_chanvars,0,1024);
strncpy(sql_query_chanvars,tempsql_query_chanvars,strlen(tempsql_query_chanvars));
+ int count_config_params = 0; // Need to make sure all params are set before we load
if ((settings = switch_xml_child(cfg, "mysqlcdr")))
{
for (param = switch_xml_child(settings, "param"); param; param = param->next)
@@ -70,13 +71,37 @@
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "hostname"))
- strncpy(hostname,val,strlen(val));
+ {
+ if(val != 0)
+ {
+ strncpy(hostname,val,strlen(val));
+ count_config_params++;
+ }
+ }
else if (!strcmp(var, "username"))
- strncpy(username,val,strlen(val));
+ {
+ if(val != 0)
+ {
+ strncpy(username,val,strlen(val));
+ count_config_params++;
+ }
+ }
else if (!strcmp(var,"password"))
- strncpy(password,val,strlen(val));
+ {
+ if(val != 0)
+ {
+ strncpy(password,val,strlen(val));
+ count_config_params++;
+ }
+ }
else if(!strcmp(var,"dbname"))
- strncpy(dbname,val,strlen(val));
+ {
+ if(val != 0)
+ {
+ strncpy(dbname,val,strlen(val));
+ count_config_params++;
+ }
+ }
else if(!strcmp(var,"chanvars"))
{
std::string unparsed;
@@ -89,29 +114,35 @@
}
}
- activated = 1;
- conn = mysql_init(NULL);
- mysql_options(conn, MYSQL_READ_DEFAULT_FILE, "");
- if(mysql_real_connect(conn,hostname,username,password,dbname,0,NULL,0) == NULL)
- {
- char *error1 = "Cannot connect to MySQL Server. The error was: ";
- const char *error2 = mysql_error(conn);
- strncat(error1,error2,strlen(error2));
- switch_console_printf(SWITCH_CHANNEL_LOG,error1);
- }
+ if (count_config_params==4)
+ activated = 1;
else
- connectionstate = 1;
-
- mysql_autocommit(conn,0);
- stmt = mysql_stmt_init(conn);
+ switch_console_printf(SWITCH_CHANNEL_LOG,"You did not specify the minimum parameters for using this module. You must specify a hostname, username, password, and database to use MysqlCDR. You only supplied %d parameters.\n",count_config_params);
- mysql_stmt_prepare(stmt,sql_query,strlen(sql_query));
-
- // Temporary commenting out for debugging
- if(logchanvars)
+ if(activated)
{
- stmt_chanvars = mysql_stmt_init(conn);
- mysql_stmt_prepare(stmt_chanvars,sql_query_chanvars,strlen(sql_query_chanvars));
+ conn = mysql_init(NULL);
+ mysql_options(conn, MYSQL_READ_DEFAULT_FILE, "");
+ if(mysql_real_connect(conn,hostname,username,password,dbname,0,NULL,0) == NULL)
+ {
+ char *error1 = "Cannot connect to MySQL Server. The error was: ";
+ const char *error2 = mysql_error(conn);
+ strncat(error1,error2,strlen(error2));
+ switch_console_printf(SWITCH_CHANNEL_LOG,error1);
+ }
+ else
+ connectionstate = 1;
+
+ mysql_autocommit(conn,0);
+ stmt = mysql_stmt_init(conn);
+
+ mysql_stmt_prepare(stmt,sql_query,strlen(sql_query));
+
+ if(logchanvars)
+ {
+ stmt_chanvars = mysql_stmt_init(conn);
+ mysql_stmt_prepare(stmt_chanvars,sql_query_chanvars,strlen(sql_query_chanvars));
+ }
}
}
}
More information about the Freeswitch-svn
mailing list