If anyone is interested ... just in case! :-)... I have tried to write , based on the cdr_mysql.so module, an Sybase module. To compile you can use something like that: export SYBPLATFORM=linux export SYBASE=/opt/sybase cc -I$SYBASE/include -c -o cdr_sybase.o cdr_sybase.c cc -shared -Xlinker -x -o cdr_sybase.so cdr_sybase.o -lsybdb -lm -L$SYBASE/lib (anyone could write the corect Makefile inside the cdr dir.?) So here it is: * * Asterisk -- A telephony toolkit for Linux. * * Sybase CDR logger * * Cristian Vasiliu <cvasiliu@accessnet.ro> * * This program is free software, distributed under the terms of * the GNU General Public License. * */ #include <asterisk/config.h> #include <asterisk/options.h> #include <asterisk/channel.h> #include <asterisk/cdr.h> #include <asterisk/module.h> #include <asterisk/logger.h> #include "../asterisk.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <time.h> #include <sybfront.h> #include <sybdb.h> #define DATE_FORMAT "%Y-%m-%d %T" static char *desc = "Sybase CDR Backend"; static char *name = "sybase"; static char *config = "cdr_sybase.conf"; static DBPROCESS *dbproc; static LOGINREC *login; static struct tm _date(struct timeval tv) { struct tm tm; time_t t; t = tv.tv_sec; localtime_r(&t,&tm); return tm; } static int sybase_log(struct ast_cdr *cdr) { struct tm tm, end, start, answer; struct timeval tv; struct timezone tz; char *sqlcmd, timestr[128], timestart[128], timeend[128], timeanswer[128]; time_t t; sqlcmd = (char *)malloc(2048); memset(sqlcmd,0,2048); start = _date(cdr->start); end = _date(cdr->end); answer = _date(cdr->answer); gettimeofday(&tv,&tz); t = tv.tv_sec; localtime_r(&t,&tm); strftime(timestr,128,DATE_FORMAT,&tm); strftime(timeend,128,DATE_FORMAT,&end); strftime(timeanswer,128,DATE_FORMAT,&answer); strftime(timestart,128,DATE_FORMAT,&start); ast_log(LOG_WARNING,timeend); ast_log(LOG_WARNING,timestart); ast_log(LOG_WARNING,timeanswer); ast_log(LOG_DEBUG,"cdr_sybase: inserting a CDR record.\n"); sprintf(sqlcmd,"INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,start,end,answer) VALUES ('%s','%s','%s','%s','%s', '%s','%s','%s','%s',%i,%i,%i,%i,'%s','%s','%s','%s')",timestr,cdr->clid,cdr->src, cdr->dst, cdr->dcontext,cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata,cdr->duration,cdr->billsec,cdr->disposition,cdr->amaflags, cdr->accountcode, timestart, timeend, timeanswer); dbcmd(dbproc,sqlcmd); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCESS) { ast_log(LOG_WARNING,"cdr_sybase: Could not insert cdr: %s\n",sqlcmd); return -1; } return 0; } char *description(void) { return desc; } int unload_module(void) { dbexit(); ast_cdr_unregister(name); return 0; } int load_module(void) { int res; struct ast_config *cfg; struct ast_variable *var; char *dbuser, *password, *dbserver, *application; cfg = ast_load(config); if (!cfg) { ast_log(LOG_WARNING, "Unable to load config for sybase CDR's: %s\n", config); return 0; } var = ast_variable_browse(cfg, "global"); if (!var) { return 0; } dbuser = ast_variable_retrieve(cfg,"global","dbuser"); password = ast_variable_retrieve(cfg,"global","password"); dbserver = ast_variable_retrieve(cfg,"global","dbserver"); application = ast_variable_retrieve(cfg,"global","application"); ast_log(LOG_DEBUG,"cdr_sybase: got dbserver of %s\n",dbserver); ast_log(LOG_DEBUG,"cdr_sybase: got dbuser of %s\n",dbuser); ast_log(LOG_DEBUG,"cdr_sybase: got password of %s\n",password); ast_log(LOG_DEBUG,"cdr_sybase: got application of %s\n",application); if (dbserver == NULL) { ast_log(LOG_ERROR,"Database server not specified.\n"); return -1; } if (dbuser == NULL) { ast_log(LOG_ERROR,"Database dbuser not specified.\n"); return -1; } if (password == NULL) { ast_log(LOG_ERROR,"Database password not specified.\n"); return -1; } if (application == NULL) { ast_log(LOG_ERROR,"Application not specified.\n"); return -1; } /* Initialize DB-Library. */ if (dbinit() == FAIL ) { ast_log(LOG_ERROR,"Can not initialize DB-library.\n"); return -1; } login = dblogin(); DBSETLUSER(login,dbuser); DBSETLPWD(login,password); DBSETLAPP(login,application); dbproc = dbopen(login,dbserver); if (dbproc == NULL) { ast_log(LOG_WARNING, "Failed to connect to sybase database.\n"); return -1; } else { ast_log(LOG_DEBUG,"Successfully connected to sybase database.\n"); } res = ast_cdr_register(name, desc, sybase_log); if (res) { ast_log(LOG_ERROR, "Unable to register Sybase CDR handling\n"); } return res; } int reload(void) { struct ast_config *cfg; struct ast_variable *var; char *hostname, *dbname, *password, *dbuser; cfg = ast_load(config); if (!cfg) { ast_log(LOG_WARNING, "Unable to load Sybase CDR config %s\n", config); return 0; } var = ast_variable_browse(cfg, "global"); if (!var) { /* nothing configured */ return 0; } hostname = ast_variable_retrieve(cfg,"global","hostname"); dbname = ast_variable_retrieve(cfg,"global","dbname"); dbuser = ast_variable_retrieve(cfg,"global","user"); password = ast_variable_retrieve(cfg,"global","password"); ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname); ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname); ast_log(LOG_DEBUG,"cdr_mysql: got dbuser of %s\n",dbuser); ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password); if (hostname == NULL) { ast_log(LOG_ERROR,"Database server hostname not specified.\n"); return -1; } if (dbname == NULL) { ast_log(LOG_ERROR,"Database dbname not specified.\n"); return -1; } if (dbuser == NULL) { ast_log(LOG_ERROR,"Database dbuser not specified.\n"); return -1; } if (password == NULL) { ast_log(LOG_ERROR,"Database password not specified.\n"); return -1; } return 0; } int usecount(void) { return 0; } char *key() { return ASTERISK_GPL_KEY; }
nice this can probably be used with mssql as well :) our developers only uses that On Friday 11 July 2003 21:56, cvasiliu wrote:> If anyone is interested ... just in case! :-)... I have tried to write , > based on the cdr_mysql.so module, an Sybase module. > To compile you can use something like that: > > export SYBPLATFORM=linux > export SYBASE=/opt/sybase > cc -I$SYBASE/include -c -o cdr_sybase.o cdr_sybase.c > cc -shared -Xlinker -x -o cdr_sybase.so cdr_sybase.o -lsybdb -lm > -L$SYBASE/lib > > (anyone could write the corect Makefile inside the cdr dir.?) > > So here it is: > > * > * Asterisk -- A telephony toolkit for Linux. > * > * Sybase CDR logger > * > * Cristian Vasiliu <cvasiliu@accessnet.ro> > * > * This program is free software, distributed under the terms of > * the GNU General Public License. > * > */ > > > #include <asterisk/config.h> > #include <asterisk/options.h> > #include <asterisk/channel.h> > #include <asterisk/cdr.h> > #include <asterisk/module.h> > #include <asterisk/logger.h> > #include "../asterisk.h" > > #include <stdio.h> > #include <string.h> > > #include <stdlib.h> > #include <unistd.h> > #include <time.h> > > #include <sybfront.h> > #include <sybdb.h> > > #define DATE_FORMAT "%Y-%m-%d %T" > > static char *desc = "Sybase CDR Backend"; > static char *name = "sybase"; > static char *config = "cdr_sybase.conf"; > > static DBPROCESS *dbproc; > static LOGINREC *login; > > > static struct tm _date(struct timeval tv) > { > struct tm tm; > time_t t; > t = tv.tv_sec; > localtime_r(&t,&tm); > return tm; > } > > > static int sybase_log(struct ast_cdr *cdr) > { > struct tm tm, end, start, answer; > struct timeval tv; > struct timezone tz; > char *sqlcmd, timestr[128], timestart[128], timeend[128], > timeanswer[128]; time_t t; > > sqlcmd = (char *)malloc(2048); > memset(sqlcmd,0,2048); > > start = _date(cdr->start); > end = _date(cdr->end); > answer = _date(cdr->answer); > > gettimeofday(&tv,&tz); > t = tv.tv_sec; > localtime_r(&t,&tm); > strftime(timestr,128,DATE_FORMAT,&tm); > strftime(timeend,128,DATE_FORMAT,&end); > strftime(timeanswer,128,DATE_FORMAT,&answer); > strftime(timestart,128,DATE_FORMAT,&start); > > ast_log(LOG_WARNING,timeend); > ast_log(LOG_WARNING,timestart); > ast_log(LOG_WARNING,timeanswer); > > > ast_log(LOG_DEBUG,"cdr_sybase: inserting a CDR record.\n"); > sprintf(sqlcmd,"INSERT INTO cdr > (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duratio >n,billsec,disposition,amaflags,accountcode,start,end,answer) VALUES > ('%s','%s','%s','%s','%s', > '%s','%s','%s','%s',%i,%i,%i,%i,'%s','%s','%s','%s')",timestr,cdr->clid,cdr >->src, cdr->dst, cdr->dcontext,cdr->channel, cdr->dstchannel, cdr->lastapp, > cdr->lastdata,cdr->duration,cdr->billsec,cdr->disposition,cdr->amaflags, > cdr->accountcode, timestart, timeend, timeanswer); > dbcmd(dbproc,sqlcmd); > dbsqlexec(dbproc); > if (dbresults(dbproc) != SUCCESS) { > ast_log(LOG_WARNING,"cdr_sybase: Could not insert cdr: > %s\n",sqlcmd); > return -1; > } > return 0; > } > > > > char *description(void) > { > return desc; > } > > int unload_module(void) > { > dbexit(); > ast_cdr_unregister(name); > return 0; > } > > int load_module(void) > { > int res; > struct ast_config *cfg; > struct ast_variable *var; > > char *dbuser, *password, *dbserver, *application; > > cfg = ast_load(config); > if (!cfg) { > ast_log(LOG_WARNING, "Unable to load config for sybase CDR's: %s\n", > config); > return 0; > } > > var = ast_variable_browse(cfg, "global"); > if (!var) { > return 0; > } > > dbuser = ast_variable_retrieve(cfg,"global","dbuser"); > password = ast_variable_retrieve(cfg,"global","password"); > dbserver = ast_variable_retrieve(cfg,"global","dbserver"); > application = ast_variable_retrieve(cfg,"global","application"); > > ast_log(LOG_DEBUG,"cdr_sybase: got dbserver of %s\n",dbserver); > ast_log(LOG_DEBUG,"cdr_sybase: got dbuser of %s\n",dbuser); > ast_log(LOG_DEBUG,"cdr_sybase: got password of %s\n",password); > ast_log(LOG_DEBUG,"cdr_sybase: got application of %s\n",application); > > if (dbserver == NULL) > { > ast_log(LOG_ERROR,"Database server not specified.\n"); > return -1; > } > > if (dbuser == NULL) > { > ast_log(LOG_ERROR,"Database dbuser not specified.\n"); > return -1; > } > if (password == NULL) > { > ast_log(LOG_ERROR,"Database password not specified.\n"); > return -1; > } > if (application == NULL) > { > ast_log(LOG_ERROR,"Application not specified.\n"); > return -1; > } > > /* Initialize DB-Library. */ > if (dbinit() == FAIL ) > { > ast_log(LOG_ERROR,"Can not initialize DB-library.\n"); > return -1; > } > > > login = dblogin(); > DBSETLUSER(login,dbuser); > DBSETLPWD(login,password); > DBSETLAPP(login,application); > dbproc = dbopen(login,dbserver); > > if (dbproc == NULL) { > ast_log(LOG_WARNING, "Failed to connect to sybase database.\n"); > > return -1; > } else { > ast_log(LOG_DEBUG,"Successfully connected to sybase database.\n"); > } > > > res = ast_cdr_register(name, desc, sybase_log); > if (res) { > ast_log(LOG_ERROR, "Unable to register Sybase CDR handling\n"); > } > return res; > } > > int reload(void) > { > > struct ast_config *cfg; > struct ast_variable *var; > > char *hostname, *dbname, *password, *dbuser; > > > cfg = ast_load(config); > if (!cfg) { > ast_log(LOG_WARNING, "Unable to load Sybase CDR config %s\n", config); > return 0; > } > > var = ast_variable_browse(cfg, "global"); > if (!var) { > /* nothing configured */ > return 0; > } > > hostname = ast_variable_retrieve(cfg,"global","hostname"); > dbname = ast_variable_retrieve(cfg,"global","dbname"); > dbuser = ast_variable_retrieve(cfg,"global","user"); > password = ast_variable_retrieve(cfg,"global","password"); > ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname); > ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname); > ast_log(LOG_DEBUG,"cdr_mysql: got dbuser of %s\n",dbuser); > ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password); > > if (hostname == NULL) > { > ast_log(LOG_ERROR,"Database server hostname not specified.\n"); > return -1; > } > if (dbname == NULL) > { > ast_log(LOG_ERROR,"Database dbname not specified.\n"); > return -1; > } > if (dbuser == NULL) > { > ast_log(LOG_ERROR,"Database dbuser not specified.\n"); > return -1; > } > > if (password == NULL) > { > ast_log(LOG_ERROR,"Database password not specified.\n"); > return -1; > } > > > > > > return 0; > } > > int usecount(void) > { > return 0; > } > > char *key() > { > return ASTERISK_GPL_KEY; > } > > > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users-- Roy Sigurd Karlsbakk, Datavaktmester ProntoTV AS - http://www.pronto.tv/ Tel: +47 9801 3356 Computers are like air conditioners. They stop working when you open Windows.
> -----Original Message----- > From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users- > admin@lists.digium.com] On Behalf Of Roy Sigurd Karlsbakk > Sent: Monday, July 14, 2003 3:16 AM > To: asterisk-users@lists.digium.com; cvasiliu > Subject: Re: [Asterisk-Users] module : cdr_sybase.so > > nice > this can probably be used with mssql as well :) > our developers only uses thatImplementing this with FreeTDS would be a better choice for the standard distribution since it has no dependencies on non-free software libraries like Sybase "Open Client" (sic) libs. I have had no problems doing anything I needed to with Sybase and SQL Server using FreeTDS, so for CDR logging (just inserts) it should be more than sufficient. Have a look at www.freetds.org John> On Friday 11 July 2003 21:56, cvasiliu wrote: > > If anyone is interested ... just in case! :-)... I have tried towrite ,> > based on the cdr_mysql.so module, an Sybase module. > > To compile you can use something like that: > > > > export SYBPLATFORM=linux > > export SYBASE=/opt/sybase > > cc -I$SYBASE/include -c -o cdr_sybase.o cdr_sybase.c > > cc -shared -Xlinker -x -o cdr_sybase.so cdr_sybase.o -lsybdb -lm > > -L$SYBASE/lib > > > > (anyone could write the corect Makefile inside the cdr dir.?)
Agreed. I have programmed against FreeTDS a lot. It is a good stable product. It should not take any major effort to put in a cdr_tds.so This way we could connect to Sybase and MS SQL Server. If there is a demand for this kind of feature maybe we should make such a module. Erik> -----Original Message----- > From: asterisk-users-admin@lists.digium.com > [mailto:asterisk-users-admin@lists.digium.com]On Behalf Of John Laur > Sent: Monday, July 14, 2003 9:04 AM > To: asterisk-users@lists.digium.com > Subject: RE: [Asterisk-Users] module : cdr_sybase.so > > > > -----Original Message----- > > From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users- > > admin@lists.digium.com] On Behalf Of Roy Sigurd Karlsbakk > > Sent: Monday, July 14, 2003 3:16 AM > > To: asterisk-users@lists.digium.com; cvasiliu > > Subject: Re: [Asterisk-Users] module : cdr_sybase.so > > > > nice > > this can probably be used with mssql as well :) > > our developers only uses that > > Implementing this with FreeTDS would be a better choice for the standard > distribution since it has no dependencies on non-free software libraries > like Sybase "Open Client" (sic) libs. I have had no problems doing > anything I needed to with Sybase and SQL Server using FreeTDS, so for > CDR logging (just inserts) it should be more than sufficient. Have a > look at www.freetds.org > > John > > > On Friday 11 July 2003 21:56, cvasiliu wrote: > > > If anyone is interested ... just in case! :-)... I have tried to > write , > > > based on the cdr_mysql.so module, an Sybase module. > > > To compile you can use something like that: > > > > > > export SYBPLATFORM=linux > > > export SYBASE=/opt/sybase > > > cc -I$SYBASE/include -c -o cdr_sybase.o cdr_sybase.c > > > cc -shared -Xlinker -x -o cdr_sybase.so cdr_sybase.o -lsybdb -lm > > > -L$SYBASE/lib > > > > > > (anyone could write the corect Makefile inside the cdr dir.?) > > > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users >
It would seem to me that you should program to the ODBC iterface. There are free UNIX ODBC libraries. Then you could write CDR to anything that supports ODBC which is basically _anything_ as there are even ODBC drivers for flat ASCII files for DBMSes and even XML files --- Erik Anderson <eanders@midco.net> wrote:> Agreed. > > I have programmed against FreeTDS a lot. It is a good stable > product. > > It should not take any major effort to put in a > > cdr_tds.so > > This way we could connect to Sybase and MS SQL Server. > > If there is a demand for this kind of feature maybe we should make > such a > module. > > Erik====Chris Albertson Home: 310-376-1029 chrisalbertson90278@yahoo.com Cell: 310-990-7550 Office: 310-336-5189 Christopher.J.Albertson@aero.org KG6OMK __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com