Added missing files
This commit is contained in:
parent
5f0037b23c
commit
20201f4346
|
@ -0,0 +1,192 @@
|
|||
/* $Id: mysqldb.c,v 1.1 1998/04/06 15:45:18 keil Exp $
|
||||
*
|
||||
* Interface for mySQL-Database for isdn4linux. (db-module)
|
||||
*
|
||||
* by Sascha Matzke (sascha@bespin.escape.de)
|
||||
* based on postgres.c by Markus Leist (markus@hal.dirnet.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Log: mysqldb.c,v $
|
||||
* Revision 1.1 1998/04/06 15:45:18 keil
|
||||
* Added missing files
|
||||
*
|
||||
* Revision 0.2 1998/02/25 12:10.00 matzke
|
||||
* Fixed date bug
|
||||
*
|
||||
* Revision 0.1 1998/02/25 09:45.00 matzke
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef MYSQLDB
|
||||
#define _MYSQL_C_
|
||||
|
||||
#include "mysqldb.h"
|
||||
|
||||
MYSQL mysql;
|
||||
|
||||
int mysql_dbOpen(void)
|
||||
{
|
||||
|
||||
/* get strings from macros */
|
||||
|
||||
mysql_db_Host = NULL;
|
||||
if ( DB_HOST )
|
||||
{
|
||||
mysql_db_Host = malloc( strlen( DB_HOST));
|
||||
strcpy( mysql_db_Host, DB_HOST);
|
||||
}
|
||||
|
||||
mysql_db_User = NULL;
|
||||
if ( DB_USER )
|
||||
{
|
||||
mysql_db_User = malloc( strlen( DB_USER));
|
||||
strcpy( mysql_db_User, DB_USER);
|
||||
}
|
||||
|
||||
mysql_db_Passwd = NULL;
|
||||
if ( DB_PASSWD )
|
||||
{
|
||||
mysql_db_Passwd = malloc( strlen( DB_PASSWD));
|
||||
strcpy( mysql_db_Passwd, DB_PASSWD);
|
||||
}
|
||||
|
||||
mysql_db_Name = NULL;
|
||||
if ( DB_NAME )
|
||||
{
|
||||
mysql_db_Name = malloc( strlen( DB_NAME));
|
||||
strcpy( mysql_db_Name, DB_NAME);
|
||||
}
|
||||
|
||||
mysql_db_Table = NULL;
|
||||
if ( DB_TABLE )
|
||||
{
|
||||
mysql_db_Table = malloc( strlen( DB_TABLE));
|
||||
strcpy( mysql_db_Table, DB_TABLE);
|
||||
}
|
||||
|
||||
/* make a connection to the database daemon */
|
||||
|
||||
if (!(mysql_connect(&mysql, mysql_db_Host, mysql_db_User, mysql_db_Passwd)))
|
||||
{
|
||||
syslog( LOG_ERR, "%s", "Connection to mySQL failed.");
|
||||
syslog( LOG_ERR, "%s", mysql_error( &mysql ));
|
||||
return( -1);
|
||||
}
|
||||
|
||||
/* select database */
|
||||
|
||||
if (mysql_select_db(&mysql, mysql_db_Name))
|
||||
{
|
||||
syslog( LOG_ERR, "%s", "Databaseselection failed.");
|
||||
syslog( LOG_ERR, "%s", mysql_error( &mysql ));
|
||||
return( -1);
|
||||
}
|
||||
|
||||
return( 0);
|
||||
}
|
||||
|
||||
int mysql_dbClose(void)
|
||||
{
|
||||
mysql_close(&mysql);
|
||||
|
||||
if ( mysql_db_Host)
|
||||
free( mysql_db_Host);
|
||||
|
||||
if ( mysql_db_User)
|
||||
free( mysql_db_User);
|
||||
|
||||
if ( mysql_db_Passwd)
|
||||
free( mysql_db_User);
|
||||
|
||||
if ( mysql_db_Name)
|
||||
free( mysql_db_Name);
|
||||
|
||||
if ( mysql_db_Table)
|
||||
free( mysql_db_Table);
|
||||
|
||||
return( 0);
|
||||
}
|
||||
|
||||
int mysql_dbAdd( mysql_DbStrIn *in)
|
||||
{
|
||||
MYSQL_RES *res;
|
||||
char out_txt[400];
|
||||
struct tm *tm;
|
||||
|
||||
assert( (int)in);
|
||||
|
||||
if ( mysql_dbStatus() ) /* returns -1 when not open */
|
||||
if ( mysql_dbOpen() ) /* returns -1 when error appears */
|
||||
return( -1);
|
||||
|
||||
tm = localtime( (__const time_t *) &(in->connect));
|
||||
|
||||
sprintf( out_txt
|
||||
, "INSERT INTO %s "
|
||||
"( sdate, stime, calling, called, charge, dir, "
|
||||
" in_bytes, out_bytes, msec, sec, status, service, "
|
||||
" source, vrsion, factor, currency, pay, provider) values "
|
||||
"( \'%d-%02d-%02d\', \'%02d:%02d:%02d\', "
|
||||
"\'%s\', \'%s\', %d, \'%c\', "
|
||||
"%ld, %ld, %d, %d, %d, %d, "
|
||||
"%d, %d, %5.4f, \'%s\', %5.4f, \'%s\')",
|
||||
mysql_db_Table,
|
||||
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
||||
in->calling, in->called,
|
||||
in->aoce, in->dialin,
|
||||
in->ibytes, in->obytes,
|
||||
in->hduration, in->duration,
|
||||
in->cause, in->si1, in->si11,
|
||||
in->version, in->currency_factor,
|
||||
in->currency, in->pay, in->provider);
|
||||
|
||||
/* execute query */
|
||||
|
||||
mysql_query(&mysql, out_txt);
|
||||
|
||||
/*
|
||||
{
|
||||
syslog( LOG_ERR, "%s", mysql_error( &mysql ));
|
||||
return( -1);
|
||||
}
|
||||
*/
|
||||
|
||||
res = mysql_store_result(&mysql);
|
||||
|
||||
/*
|
||||
{
|
||||
syslog( LOG_ERR, "%s", mysql_error( &mysql ));
|
||||
return( -1);
|
||||
}
|
||||
*/
|
||||
|
||||
mysql_free_result(res);
|
||||
|
||||
return( 0);
|
||||
}
|
||||
|
||||
int mysql_dbStatus( void)
|
||||
{
|
||||
if ( &mysql != NULL)
|
||||
return( 0);
|
||||
else
|
||||
return( -1);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/* $Id: mysqldb.h,v 1.1 1998/04/06 15:45:19 keil Exp $
|
||||
*
|
||||
* Interface for mySQL-Database for isdn4linux.
|
||||
*
|
||||
* by Sascha Matzke (sascha@bespin.escape.de)
|
||||
* based on postgres.h by Markus Leist (markus@hal.dirnet.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Log: mysqldb.h,v $
|
||||
* Revision 1.1 1998/04/06 15:45:19 keil
|
||||
* Added missing files
|
||||
*
|
||||
* Revision 0.1 1998/02/25 11:50:56 admin
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _MYSQL_H_
|
||||
#define _MYSQL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
#include <syslog.h>
|
||||
#include <assert.h>
|
||||
#include <mysql.h> /* functions for mysql */
|
||||
|
||||
|
||||
/* */
|
||||
#define DB_HOST "localhost" /* host name of backend-server */
|
||||
#define DB_USER "isdn" /* mysql_db user */
|
||||
#define DB_PASSWD "isdn" /* mysql_db password */
|
||||
#define DB_NAME "isdn" /* name of database */
|
||||
#define DB_TABLE "isdnlog" /* name of table in database */
|
||||
|
||||
#define NUMSIZE 20
|
||||
|
||||
|
||||
struct _DbStrIn
|
||||
{
|
||||
time_t connect; /* Zeitpunkt des Verbindungsaufbaues */
|
||||
char calling[NUMSIZE]; /* Telefonnummer des Anrufers */
|
||||
char called[NUMSIZE]; /* Telefonnummer des Gegners */
|
||||
int duration; /* Dauer der Verbindung in Sekunden */
|
||||
int hduration; /* Dauer der Verbindung in 1/100 Sekunden */
|
||||
int aoce; /* Anzahl zu zahlender Gebuehreneinheiten (AOC-D) */
|
||||
int dialin; /* "I" fuer incoming call, "O" fuer outgoing call */
|
||||
int cause; /* Kam eine Verbindung nicht zustande ist hier der Grund */
|
||||
long ibytes; /* Summe der uebertragenen Byte _von_ draussen (incoming) */
|
||||
long obytes; /* Summe der uebertragenen Byte _nach_ draussen (outgoing) */
|
||||
int version; /* Versionsnummer (LOG_VERSION) dieses Eintrages */
|
||||
int si1; /* Dienstkennung fuer diese Verbindung (1=Speech, 7=Data usw.) */
|
||||
int si11; /* Bei Dienstkennung 1=Speech -> analog oder digital ? */
|
||||
double currency_factor; /* Der Currency Factor fuer diese Verbinung (hier z.Zt. 0,12) */
|
||||
char currency[32]; /* (16) Die Waehrung fuer diese Verbindung (in Deutschland "DM") */
|
||||
double pay; /* Der Endbetrag i.d. jeweiligen Landeswaehrung fuer diese Verbindung */
|
||||
char provider[NUMSIZE]; /* Der Provider der Verbindung */
|
||||
};
|
||||
|
||||
typedef struct _DbStrIn mysql_DbStrIn;
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef _MYSQL_C_
|
||||
#define _EXTERN
|
||||
#else
|
||||
#define _EXTERN extern
|
||||
#endif
|
||||
_EXTERN int mysql_dbOpen( void);
|
||||
_EXTERN int mysql_dbClose( void);
|
||||
_EXTERN int mysql_dbAdd( mysql_DbStrIn *in);
|
||||
_EXTERN int mysql_dbStatus( void);
|
||||
#undef _EXTERN
|
||||
|
||||
#ifdef _MYSQL_C_
|
||||
#define _EXTERN static
|
||||
#else
|
||||
#define _EXTERN extern
|
||||
#endif
|
||||
_EXTERN char *mysql_db_Host, *mysql_db_User, *mysql_db_Passwd;
|
||||
_EXTERN char *mysql_db_Name, *mysql_db_Table;
|
||||
/* _EXTERN MYSQL *mysql; */
|
||||
#undef _EXTERN
|
||||
|
||||
|
||||
#endif /* _MYSQL_H_ */
|
Loading…
Reference in New Issue