提交 840208ff authored 作者: Brian West's avatar Brian West

moving

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6326 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 073a49c9
AM_CFLAGS = $(SWITCH_AM_CFLAGS)
AM_CPPFLAGS = $(SWITCH_AM_CXXFLAGS)
AM_LDFLAGS = $(SWITCH_AM_LDFLAGS)
#we should set all these vars from configure, no reason to have these in each Makefile.am
LIBTOOL = echo "`link=\`echo $@|grep .la;echo $@|grep .so;echo $@|grep .dll\`;if test -n "$$link"; then echo Creating $@;fi`";`if test -z "$(VERBOSE)" ; \
then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(SHELL) $(switch_builddir)/libtool; fi`
AM_MAKEFLAGS=`test -n "$(VERBOSE)" || echo -s`
# Dirty trick to override the link output
LIBS+=> $(MODNAME).log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat $(MODNAME).log;fi;if test "$$error" = "yes";then exit 1;fi
moddir=$(prefix)/mod
MODNAME=mod_cdr
mod_LTLIBRARIES = mod_cdr.la
mod_cdr_la_SOURCES = mod_cdr.cpp cdrcontainer.cpp basecdr.cpp baseregistry.cpp pddcdr.cpp csvcdr.cpp xmlcdr.cpp sqlitecdr.cpp
mod_cdr_la_CFLAGS = $(AM_CFLAGS)
mod_cdr_la_CPPFLAGS = $(AM_CPPFLAGS)
mod_cdr_la_LIBADD=$(switch_builddir)/libfreeswitch.la
mod_cdr_la_LDFLAGS=-module -avoid-version -no-undefined -export-symbols-regex ^switch_module_.*$ -rpath $(PREFIX)/$(libdir)
#Build mysqlcdr if we have mysql client
if HAVE_MYSQL
mod_cdr_la_CFLAGS += $(MYSQL_CFLAGS)
mod_cdr_la_CPPFLAGS += $(MYSQL_CFLAGS)
mod_cdr_la_LDFLAGS += $(MYSQL_LDFLAGS)
mod_cdr_la_SOURCES += mysqlcdr.cpp
endif
#mod_cdr_la_CFLAGS += -DSWITCH_QUEUE_ENHANCED
#mod_cdr_la_LDFLAGS += -lcurl
#Override the linstall target so we just install the .so/.dylib
install-data-am: $(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN)
$(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).la
@echo installing $(MODNAME).$(DYNAMIC_LIB_EXTEN)
@if [ -f .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) ] ; then \
$(LIBTOOL) --mode=install $(INSTALL) .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
else \
$(LIBTOOL) --mode=install $(INSTALL) $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
fi
差异被折叠。
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This header describes the switch_mod_cdr_newchannel_t struct, the BaseCDR base class that all
* CDR loggers will inherit from, and the switch_mod_cdr_sql_types_t enum for use with the SQL type loggers
* (i.e. MySQL). This is part of the mod_cdr module for Freeswitch by Anthony Minnesale and friends.
*
* basecdr.h
*
*/
#ifndef BASECDR
#define BASECDR
#ifdef __cplusplus
#include <vector>
#include <list>
#include <vector>
#include <map>
#include <switch.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
struct switch_mod_cdr_newchannel_t {
switch_core_session_t *session;
switch_channel_t *channel;
//switch_channel_timetable_t *timetable;
switch_caller_extension_t *callerextension;
switch_caller_profile_t *callerprofile;
//switch_caller_profile_t *originateprofile;
//bool originate;
};
enum switch_mod_cdr_sql_types_t { CDR_INTEGER, CDR_STRING, CDR_DECIMAL, CDR_DOUBLE, CDR_TINY };
#ifdef WIN32
#define STDCALL __stdcall
#else
#define STDCALL
#endif
typedef switch_status_t (STDCALL * modcdr_time_convert_t) (switch_time_exp_t *, switch_time_t);
class BaseCDR {
public:
BaseCDR();
virtual ~ BaseCDR();
BaseCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param) = 0;
virtual void disconnect() = 0;
virtual bool process_record() = 0;
virtual bool is_activated() = 0;
virtual void tempdump_record() = 0;
virtual void reread_tempdumped_records() = 0;
virtual std::string get_display_name() = 0; // Get the module name
protected:
void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, bool fixed);
void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, std::vector < switch_mod_cdr_sql_types_t > &chanvars_fixed_types); // Typically used for SQL types
void process_channel_variables(const std::list < std::string > &stringlist, const std::list < std::string > &fixedlist, switch_channel_t *channel, bool repeat = 1); //This is used for supplemental chanvars
void process_channel_variables(const std::list < std::string > &stringlist, switch_channel_t *channel); // This is used for fixed chanvars
void escape_string(std::string & src);
std::string escape_chararray(char *src);
switch_time_t callstartdate;
switch_time_t callanswerdate;
switch_time_t callenddate;
switch_time_t calltransferdate;
switch_call_cause_t hangupcause;
const char *hangupcause_text;
char clid[80];
bool originated; // Did they originate this call?
char dialplan[80];
char myuuid[37]; // 36 + 1 to hold \0
char destuuid[37];
char src[80];
char dst[80];
char srcchannel[80];
char dstchannel[80];
char ani[80];
char aniii[80];
char network_addr[40];
char lastapp[80];
char lastdata[255];
switch_time_t billusec; // Yes, you heard me, we're measuring in microseconds
int disposition; // Currently 0 = Busy/Unanswered, 1 = Answered
int amaflags;
switch_core_session_t *coresession;
std::list < std::pair < std::string, std::string > >chanvars_fixed;
std::map < std::string, std::string > chanvars_supp;
bool errorstate; // True if there is an error writing the log
};
#endif
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ source describes the BaseRegistry and BaseRegistration classes that implement
* the factory routine with the aid of the templated base_factory() function.
*
* baseregistry.cpp
*
*/
#include "baseregistry.h"
BaseRegistry& BaseRegistry::get()
{
static BaseRegistry instance;
return instance;
}
void BaseRegistry::add(basecdr_creator creator)
{
m_bases.push_back(creator);
}
BaseRegistry::iterator BaseRegistry::begin()
{
return m_bases.begin();
}
BaseRegistry::iterator BaseRegistry::end()
{
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);
}
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: BaseRegistry and BaseRegistration classes and AUTO_REGISTER_BASECDR macro provided in part by David
* Terrell from his blog posting http://meat.net/2006/03/cpp-runtime-class-registration/ Much thanks to him
* for his help.
*
* baseregistry.h
*
*/
#include "basecdr.h"
#include <iostream>
#ifndef BASECDRREGISTRY
#define BASECDRREGISTRY
#ifdef __cplusplus
#include <vector>
template < class T > BaseCDR * basecdr_factory(switch_mod_cdr_newchannel_t * newchannel)
{
return new T(newchannel);
}
typedef BaseCDR *(*basecdr_creator) (switch_mod_cdr_newchannel_t * newchannel);
class BaseRegistry {
private:
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 {
public:
BaseRegistration(basecdr_creator);
};
#define AUTO_REGISTER_BASECDR(basecdr) BaseRegistration _basecdr_registration_ ## basecdr(&basecdr_factory<basecdr>);
#endif // ifdef __cplusplus
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Marcel Barbulescu <marcelbarbulescu@gmail.com>
*
* Description: This C++ source file describes the CDRContainer singleton object used by mod_cdr to control
* the creation, processing, and destruction of various CDR logger objects.
*
* cdrcontainer.cpp
*
*/
#include "cdrcontainer.h"
#include "baseregistry.h"
CDRContainer::CDRContainer()
{
}
CDRContainer::CDRContainer(switch_memory_pool_t *module_pool)
{
// Create the APR threadsafe queue, though I don't know if this is the current memory pool.
switch_queue_create(&cdrqueue,5224288, module_pool);
queue_paused = 0;
strcpy(configfile,"cdr.conf");
switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
newchannel = 0;
if (!(xml = switch_xml_open_cfg(configfile, &cfg, NULL)))
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", configfile);
else
{
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
ptr->connect(cfg,xml,settings,param);
if(ptr->is_activated())
registry.add_active(it);
}
}
switch_xml_free(xml);
}
CDRContainer::~CDRContainer()
{
if(switch_queue_size(cdrqueue) > 0)
process_records();
switch_mod_cdr_newchannel_t *newchannel; //= new switch_mod_cdr_newchannel_t;
newchannel = 0;
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
ptr->disconnect();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mod_cdr shutdown gracefully.");
}
#ifdef SWITCH_QUEUE_ENHANCED
void CDRContainer::reload(switch_stream_handle_t *stream)
{
// The queue can't be paused otherwise it will never be able to reload safely.
if(queue_paused)
{
stream->write_function(stream,"The queue is currently paused, resuming it.\n");
queue_resume(stream);
}
// Something tells me I still need to figure out what to do if there are items still in queue after reload that are no longer active in the configuration.
switch_queue_isempty(cdrqueue); // Waits for the queue to be empty
switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
newchannel = 0;
const char *err;
switch_xml_t xml_root;
if ((xml_root = switch_xml_open_root(1, &err))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Reloading the XML file...\n");
switch_xml_free(xml_root);
}
if (!(xml = switch_xml_open_cfg(configfile, &cfg, NULL)))
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "open of %s failed\n", configfile);
else
{
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
ptr->disconnect();
}
registry.reset_active();
for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
ptr->connect(cfg,xml,settings,param);
if(ptr->is_activated())
registry.add_active(it);
}
}
switch_xml_free(xml);
switch_queue_unblockpop(cdrqueue);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mod_cdr configuration reloaded.");
}
void CDRContainer::queue_pause(switch_stream_handle_t *stream)
{
if(queue_paused)
stream->write_function(stream,"Queue is already paused.\n");
else
{
queue_paused = 1;
switch_queue_blockpop(cdrqueue);
stream->write_function(stream,"CDR queue is now paused. Beware that this can waste resources the longer you keep it paused.\n");
}
}
void CDRContainer::queue_resume(switch_stream_handle_t *stream)
{
if(!queue_paused)
stream->write_function(stream,"Queue is currently running, no need to resume it.\n");
else
{
queue_paused = 0;
switch_queue_unblockpop(cdrqueue);
stream->write_function(stream,"CDR queue has now resumed processing CDR records.\n");
}
}
#endif
void CDRContainer::active(switch_stream_handle_t *stream)
{
switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
newchannel = 0;
stream->write_function(stream,"The following mod_cdr logging backends are currently marked as active:\n");
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
stream->write_function(stream,"%s\n",ptr->get_display_name().c_str());
}
}
void CDRContainer::available(switch_stream_handle_t *stream)
{
switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
newchannel = 0;
stream->write_function(stream,"The following mod_cdr logging backends are currently avaible for use (providing you configure them):\n");
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.begin(); it != registry.end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* _ptr = func(newchannel);
std::auto_ptr<BaseCDR> ptr(_ptr);
stream->write_function(stream,"%s\n",ptr->get_display_name().c_str());
}
}
void CDRContainer::add_cdr(switch_core_session_t *session)
{
switch_mod_cdr_newchannel_t *newchannel = new switch_mod_cdr_newchannel_t;
memset(newchannel,0,sizeof(*newchannel));
newchannel->channel = switch_core_session_get_channel(session);
assert(newchannel->channel != 0);
newchannel->session = session;
newchannel->callerextension = switch_channel_get_caller_extension(newchannel->channel);
newchannel->callerprofile = switch_channel_get_caller_profile(newchannel->channel);
while (newchannel->callerprofile)
{
BaseRegistry& registry(BaseRegistry::get());
for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
{
basecdr_creator func = *it;
BaseCDR* newloggerobject = func(newchannel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Adding a new logger object to the queue.\n");
switch_queue_push(cdrqueue,newloggerobject);
}
newchannel->callerprofile = newchannel->callerprofile->next;
if(newchannel->callerextension)
newchannel->callerextension = newchannel->callerextension->next;
}
delete newchannel;
}
void CDRContainer::process_records()
{
BaseCDR *tempnewloggerobject = 0, *newloggerobject = 0;
while(switch_queue_pop(cdrqueue,reinterpret_cast< void** > (&tempnewloggerobject))== SWITCH_STATUS_SUCCESS)
{
newloggerobject = tempnewloggerobject;
newloggerobject->process_record();
delete newloggerobject;
}
}
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ header file describes the CDRContainer singleton object used by mod_cdr to control
* the creation, processing, and destruction of various CDR logger objects.
*
* cdrcontainer.h
*
*/
#ifndef CDRCONTAINER
#define CDRCONTAINER
#ifdef __cplusplus
#include <cstring>
#include <iostream>
#endif
#include "basecdr.h"
#include <switch.h>
/*
The CDRContainer Class will serve as a central receptacle for all CDR methods. CDRContainer::CDRContainer() will initialize the system, and CDRContainer::add_cdr() will add a new object of each CDR type to a queue for "later processing" by the other thread.
CDRContainer::process_records() will iterate thru the queue and commit the records to the respective backends.
*/
#ifdef __cplusplus
extern "C" {
#endif
class CDRContainer {
public:
CDRContainer();
CDRContainer(switch_memory_pool_t *module_pool);
~CDRContainer();
void add_cdr(switch_core_session_t *session);
void process_records();
#ifdef SWITCH_QUEUE_ENHANCED
void reload(switch_stream_handle_t *stream);
void queue_pause(switch_stream_handle_t *stream);
void queue_resume(switch_stream_handle_t *stream);
#endif
void active(switch_stream_handle_t *stream);
void available(switch_stream_handle_t *stream);
protected:
private:
switch_xml_t cfg, xml, settings, param;
switch_queue_t *cdrqueue;
std::string tempfilepath;
char configfile[13];
bool queue_paused;
};
#ifdef __cplusplus
}
#endif
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ header file describes the CsvCDR class that handles processing CDRs to a CSV format.
* This is the standard CSV module, and has a list of predefined variables to log out which can be
* added to, but never have the default ones removed. If you want to use one that allows you to explicity
* set all data variables to be logged and in what order, then this is not the class you want to use, and
* one will be coming in the future to do just that.
*
* csvcdr.h
*
*/
#include "baseregistry.h"
#include <switch.h>
#include <iostream>
#include <fstream>
#include <list>
#ifndef CSVCDR
#define CSVCDR
class CsvCDR:public BaseCDR {
public:
CsvCDR();
CsvCDR(switch_mod_cdr_newchannel_t * newchannel);
//CsvCDR(const CsvCDR& copyFrom);
virtual ~ CsvCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static bool repeat_fixed_in_supp; // Repeat the fixed chanvars in the supplemental?
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
static std::ofstream outputfile;
static std::ofstream::pos_type filesize_limit;
void check_file_size_and_open(); // Checks the size of the file, and if it's greater than size allowed, rotates it.
void open_file();
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* This code is largely derived from csvcdr.cpp with minor code snippets from mod_xml_curl.c and edited by
* Bret McDanel <trixter AT 0xdecafbad.com>
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Bret McDanel <trixter AT 0xdecafbad.com>
* Anthony Minessale II <anthmct@yahoo.com>
*
* Description: This C++ source file describes the CurlCDR class that handles processing CDRs to HTTP endpoint.
* This is the standard Curl module, and has a list of predefined variables to log out which can be
* added to, but never have the default ones removed. If you want to use one that allows you to explicity
* set all data variables to be logged and in what order, then this is not the class you want to use, and
* one will be coming in the future to do just that.
*
* curlcdr.h
*
*/
#include "baseregistry.h"
#include <switch.h>
#include <iostream>
#include <fstream>
#include <list>
#include <sstream>
#ifndef CURLCDR
#define CURLCDR
class CurlCDR:public BaseCDR {
public:
CurlCDR();
CurlCDR(switch_mod_cdr_newchannel_t * newchannel);
//CurlCDR(const CurlCDR& copyFrom);
virtual ~ CurlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
virtual std::string itos(int i);
virtual std::string lltos(long long ll);
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static const char *gateway_url; // The URL to send data to
static const char *gateway_credentials; // The credentials for http auth
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
static std::string postdata;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Marcel Barbulescu <marcelbarbulescu@gmail.com>
*
* Description: This source file describes the most basic portions of the CDR module. These are the functions
* and structures that the Freeswitch core looks for when opening up the DSO file to create the load, shutdown
* and runtime threads as necessary.
*
* mod_cdr.cpp
*
*/
#include "cdrcontainer.h"
#include <switch.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_cdr_runtime);
SWITCH_MODULE_DEFINITION(mod_cdr, mod_cdr_load, mod_cdr_shutdown, mod_cdr_runtime);
static int RUNNING = 0;
static CDRContainer *newcdrcontainer;
static switch_memory_pool_t *module_pool;
static switch_status_t my_on_hangup(switch_core_session_t *session);
static switch_status_t modcdr_reload(const char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
static switch_status_t modcdr_queue_pause(const char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
static switch_status_t modcdr_queue_resume(const char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
static switch_status_t modcdr_show_active(const char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
static switch_status_t modcdr_show_available(const char *dest, switch_core_session_t *isession, switch_stream_handle_t *stream);
static switch_thread_rwlock_t *cdr_rwlock;
/* Now begins the glue that will tie this into the system.
*/
static const switch_state_handler_table_t state_handlers = {
/*.on_init */ NULL,
/*.on_ring */ NULL,
/*.on_execute */ NULL,
/*.on_hangup */ my_on_hangup,
/*.on_loopback */ NULL,
/*.on_transmit */ NULL
};
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_thread_rwlock_rdlock(cdr_rwlock);
newcdrcontainer->add_cdr(session);
switch_thread_rwlock_unlock(cdr_rwlock);
return SWITCH_STATUS_SUCCESS;
}
#define AVAIL_DESCR "Displays the currently compiled-in mod_cdr backend loggers."
#define ACTIVE_DESCR "Displays the currently active mod_cdr backend loggers."
#define RESUME_DESCR "Manually resumes the popping of objects from the queue."
#define PAUSE_DESCR "Manually pauses the popping of objects from the queue. (DANGER: Can suck your memory away rather quickly.)"
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_load)
{
switch_api_interface_t *api_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "modcdr_reload", "Reload mod_cdr's configuration", modcdr_reload, "");
SWITCH_ADD_API(api_interface, "modcdr_queue_pause", PAUSE_DESCR, modcdr_queue_pause, "");
SWITCH_ADD_API(api_interface, "modcdr_queue_resume", RESUME_DESCR, modcdr_queue_resume, "");
SWITCH_ADD_API(api_interface, "modcdr_show_active", ACTIVE_DESCR, modcdr_show_active, "");
SWITCH_ADD_API(api_interface, "modcdr_show_available", AVAIL_DESCR, modcdr_show_available, "");
switch_core_add_state_handler(&state_handlers);
module_pool = pool;
switch_thread_rwlock_create(&cdr_rwlock,module_pool);
newcdrcontainer = new CDRContainer(module_pool); // Instantiates the new object, automatically loads config
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_RUNTIME_FUNCTION(mod_cdr_runtime)
{
RUNNING = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mod_cdr made it to runtime. Wee!\n");
newcdrcontainer->process_records();
return RUNNING ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_TERM;
}
SWITCH_STANDARD_API(modcdr_reload)
{
#ifdef SWITCH_QUEUE_ENHANCED
switch_thread_rwlock_wrlock(cdr_rwlock);
newcdrcontainer->reload(stream);
switch_thread_rwlock_unlock(cdr_rwlock);
stream->write_function(stream, "XML Reloaded and mod_cdr reloaded.\n");
#else
stream->write_function(stream,"modcdr_reload is only supported with the apr_queue_t enhancements and SWITCH_QUEUE_ENHANCED defined.\n");
#endif
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(modcdr_queue_pause)
{
#ifdef SWITCH_QUEUE_ENHANCED
newcdrcontainer->queue_pause(stream);
#else
stream->write_function(stream,"modcdr_queue_pause is only supported with the apr_queue_t enhancements and SWITCH_QUEUE_ENHANCED defined.\n");
#endif
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(modcdr_queue_resume)
{
#ifdef SWITCH_QUEUE_ENHANCED
newcdrcontainer->queue_resume(stream);
#else
stream->write_function(stream,"modcdr_queue_pause is only supported with the apr_queue_t enhancements and SWITCH_QUEUE_ENHANCED defined.\n");
#endif
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(modcdr_show_active)
{
newcdrcontainer->active(stream);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(modcdr_show_available)
{
newcdrcontainer->available(stream);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_shutdown)
{
delete newcdrcontainer;
switch_thread_rwlock_destroy(cdr_rwlock);
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="mod_cdr"
ProjectGUID="{3D1EED36-A510-4EDB-B4D9-4E0F4A5EC2A8}"
RootNamespace="mod_cdr"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\include&quot;"
UsePrecompiledHeader="0"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\include&quot;"
UsePrecompiledHeader="0"
/>
</Configuration>
<Configuration
Name="Debug with MySql|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\include&quot;"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="mysqlclient.lib ws2_32.lib"
AdditionalLibraryDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\lib\debug&quot;"
/>
</Configuration>
<Configuration
Name="Release with MySql|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\include&quot;"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="mysqlclient.lib ws2_32.lib"
AdditionalLibraryDirectories="&quot;C:\Program Files\MySQL\MySQL Server 5.0\lib\opt&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\basecdr.cpp"
>
</File>
<File
RelativePath=".\baseregistry.cpp"
>
</File>
<File
RelativePath=".\cdrcontainer.cpp"
>
</File>
<File
RelativePath=".\csvcdr.cpp"
>
</File>
<File
RelativePath=".\mod_cdr.cpp"
>
</File>
<File
RelativePath=".\mysqlcdr.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\pddcdr.cpp"
>
</File>
<File
RelativePath=".\sqlitecdr.cpp"
>
</File>
<File
RelativePath=".\xmlcdr.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\basecdr.h"
>
</File>
<File
RelativePath=".\baseregistry.h"
>
</File>
<File
RelativePath=".\cdrcontainer.h"
>
</File>
<File
RelativePath=".\csvcdr.h"
>
</File>
<File
RelativePath=".\mysqlcdr.h"
>
</File>
<File
RelativePath=".\pddcdr.h"
>
</File>
<File
RelativePath=".\sqlitecdr.h"
>
</File>
<File
RelativePath=".\xmlcdr.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ header file describes the MysqlCDR class which handles formatting a CDR out to
* a MySQL 4.1.x or greater server using prepared statements.
*
* mysqlcdr.h
*
*/
#include "baseregistry.h"
#include <list>
#include <sstream>
#include <mysql.h>
#include <errmsg.h>
#ifndef MYSQLCDR
#define MYSQLCDR
class MysqlCDR:public BaseCDR {
public:
MysqlCDR();
MysqlCDR(switch_mod_cdr_newchannel_t * newchannel);
//MysqlCDR(const MysqlCDR& copyFrom);
virtual ~ MysqlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
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;
static bool connectionstate;
static bool logchanvars;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static modcdr_time_convert_t convert_time;
static std::string display_name;
//static fstream tmpfile;
std::vector < MYSQL_BIND > bindme;
//MYSQL_BIND *bindme;
MYSQL_TIME my_callstartdate;
MYSQL_TIME my_callanswerdate;
MYSQL_TIME my_calltransferdate;
MYSQL_TIME my_callenddate;
// Why all these long unsigned int's? MySQL's prep statement API expects these to actually exist and not just be params passed to the function calls. The are to measure the length of actual data in the char* arrays.
long unsigned int clid_length;
long unsigned int dialplan_length;
long unsigned int myuuid_length;
long unsigned int destuuid_length;
long unsigned int src_length;
long unsigned int dst_length;
long unsigned int srcchannel_length;
long unsigned int dstchannel_length;
long unsigned int ani_length;
long unsigned int aniii_length;
long unsigned int lastapp_length;
long unsigned int lastdata_length;
long unsigned int network_addr_length;
// Now a couple internal methods
template < typename T > void add_parameter(T & param, enum_field_types type, bool * is_null = 0);
void add_string_parameter(char *param, long unsigned int &param_length, enum_field_types type, bool * is_null = 0);
void set_mysql_time(switch_time_exp_t & param, MYSQL_TIME & destination);
void connect_to_database();
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ header file describes the OdbcCDR class which handles formatting a CDR out to
* an ODBC backend using prepared statements.
*
* odbccdr.h
*
*/
#include "baseregistry.h"
#include <switch.h>
#include <iostream>
#include <list>
#include <sstream>
#ifndef __CYGWIN__
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#else
#include <windows.h>
#include <w32api/sql.h>
#include <w32api/sqlext.h>
#include <w32api/sqltypes.h>
#endif
#ifndef ODBCCDR
#define ODBCCDR
class OdbcCDR:public BaseCDR {
public:
OdbcCDR();
OdbcCDR(switch_mod_cdr_newchannel_t * newchannel);
//OdbcCDR(const MysqlCDR& copyFrom);
virtual ~ OdbcCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
static modcdr_time_convert_t convert_time;
static std::string display_name;
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[355];
static char sql_query_ping[10];
static bool connectionstate;
static bool logchanvars;
static SQLHENV ODBC_env; /* global ODBC Environment */
static SQLHDBC ODBC_con; /* global ODBC Connection Handle */
static SQLHSTMT ODBC_stmt;
static SQLHSTMT ODBC_stmt_chanvars;
static SQLHSTMT ODBC_stmt_ping;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char dsn[255];
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static char tablename[255];
static char tablename_chanvars[255];
//static fstream tmpfile;
char odbc_callstartdate[128];
char odbc_callanswerdate[128];
char odbc_calltransferdate[128];
char odbc_callenddate[128];
void disconnect_stage_1();
void connect_to_database();
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Bret McDanel <trixter AT 0xdecafbad.com>
*
* Description: This C++ header file describes the PddCDR class which handles formatting a CDR out to
* individual text files in a Perl Data Dumper format.
*
* pddcdr.h
*
*/
#include "baseregistry.h"
#include <switch.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <list>
#ifndef PDDCDR
#define PDDMCDR
class PddCDR:public BaseCDR {
public:
PddCDR();
PddCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual ~ PddCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
ALTER TABLE freeswitchcdr modify callid bigint unsigned auto_increment;
ALTER TABLE freeswitchcdr Engine=InnoDB;
ALTER TABLE chanvars Engine=InnoDB;
\ No newline at end of file
ALTER TABLE freeswitchcdr DROP callid;
ALTER TABLE chanvars DROP callid;
ALTER TABLE chanvars ADD myuuid char(36) NOT NULL FIRST;
\ No newline at end of file
create table freeswitchcdr (
callid bigint unsigned default 0 primary key, /* This will need to be handled specially for auto increment, as that might not be standard */
callstartdate datetime NOT NULL,
callanswerdate datetime NOT NULL,
calltransferdate datetime NOT NULL,
callenddate datetime NOT NULL,
originated tinyint default 0,
clid varchar(80) default "Freeswitch - Unknown",
src varchar(80) NOT NULL,
dst varchar(80) NOT NULL,
ani varchar(80) default "",
aniii varchar(80) default "",
dialplan varchar(80) default "",
myuuid char(36) NOT NULL,
destuuid char(36) NOT NULL,
srcchannel varchar(80) NOT NULL,
dstchannel varchar(80) NOT NULL, /* Need to decide - this might be redundant as you can link the records via uuid */
network_addr varchar(40) default "",
lastapp varchar(80) default "",
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
);
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,
varvalue varchar(255) default ""
);
create index callid_index on chanvars(callid,varname);
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
*
* Description: This C++ header file describes the SqliteCDR class which handles formatting a CDR out to
* a SQLite database using prepared statements.
*
* sqlitecdr.h
*
*/
#include "baseregistry.h"
#include <list>
#include <sstream>
#ifndef SQLITECDR
#define SQLITECDR
class SqliteCDR:public BaseCDR {
public:
SqliteCDR();
SqliteCDR(switch_mod_cdr_newchannel_t * newchannel);
//SqliteCDR(const SqliteCDR& copyFrom);
virtual ~ SqliteCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
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 std::string db_filename;
static bool use_utc_time;
switch_time_t sqlite_callstartdate;
switch_time_t sqlite_callanswerdate;
switch_time_t sqlite_calltransferdate;
switch_time_t sqlite_callenddate;
static switch_core_db_t *db;
static switch_core_db_stmt_t *stmt;
static switch_core_db_stmt_t *stmt_chanvars;
static switch_core_db_stmt_t *stmt_begin;
static switch_core_db_stmt_t *stmt_commit;
static bool connectionstate;
static bool logchanvars;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static std::string display_name;
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
* Copyright 2006, Author: Yossi Neiman of Cartis Solutions, Inc. <freeswitch AT cartissolutions.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application Call Detail Recorder module
*
* The Initial Developer of the Original Code is
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Yossi Neiman <freeswitch AT cartissolutions.com>
* Ken Rice, Asteria Solutions Group, Inc. <ken AT asteriasgi.com>
*
* Description: This C++ header file describes the XmlCDR class which handles formatting a CDR out to
* individual text files in a XML format.
*
* xmlcdr.h
*
*/
#include "baseregistry.h"
#include <switch.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <list>
#ifndef XMLCDR
#define XMLCDR
class XmlCDR:public BaseCDR {
public:
XmlCDR();
XmlCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual ~ XmlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
};
#endif
/* For Emacs:
* Local Variables:
* mode:c++
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论