2003-05-26 09:18:31 +00:00
|
|
|
/* NeoStats - IRC Statistical Services
|
2004-01-14 11:36:37 +00:00
|
|
|
** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond
|
2003-04-09 14:29:51 +00:00
|
|
|
** http://www.neostats.net/
|
|
|
|
**
|
|
|
|
** Portions Copyright (c) 2000-2001 ^Enigma^
|
|
|
|
**
|
|
|
|
** 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 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
** USA
|
|
|
|
**
|
|
|
|
** NeoStats CVS Identification
|
2003-09-22 15:04:15 +00:00
|
|
|
** $Id$
|
2003-04-09 14:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stats.h"
|
|
|
|
#include "keeper.h"
|
|
|
|
#include "conf.h"
|
2003-04-11 09:26:31 +00:00
|
|
|
#include "log.h"
|
2003-04-09 14:29:51 +00:00
|
|
|
|
|
|
|
/** @brief Gets Config Data of Type
|
|
|
|
*/
|
2003-07-30 13:58:22 +00:00
|
|
|
int
|
|
|
|
GetConf (void **data, int type, const char *item)
|
2003-06-13 13:11:50 +00:00
|
|
|
{
|
2003-04-17 13:48:28 +00:00
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
2003-06-13 13:11:50 +00:00
|
|
|
|
2003-04-09 14:29:51 +00:00
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "g/%s:/%s", segvinmodule, item);
|
2003-04-09 14:29:51 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "g/core:/%s", item);
|
2003-04-09 14:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2003-06-13 13:11:50 +00:00
|
|
|
case CFGSTR:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_get_string (keypath, (char **) *&data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGINT:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_get_int (keypath, (int *) *&data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGFLOAT:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_get_float (keypath, (double *) *&data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGBOOL:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_get_bool (keypath, (int *) *&data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-07-30 13:58:22 +00:00
|
|
|
nlog (LOG_WARNING, LOG_CORE, "Keeper: Called GetConf with invalid datatype %d", type);
|
2003-06-13 13:11:50 +00:00
|
|
|
return -1;
|
2003-04-09 14:29:51 +00:00
|
|
|
}
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
2003-07-30 13:58:22 +00:00
|
|
|
nlog (LOG_DEBUG1, LOG_CORE, "GetConf: %s - Path: %s", kp_strerror (i), keypath);
|
2003-04-09 14:29:51 +00:00
|
|
|
return -1;
|
2003-06-13 13:11:50 +00:00
|
|
|
}
|
2003-04-09 14:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-10-07 14:26:21 +00:00
|
|
|
/* @brief return an array of strings containing all subkeys in a directory */
|
2003-04-30 13:10:51 +00:00
|
|
|
|
2003-07-30 13:58:22 +00:00
|
|
|
int
|
|
|
|
GetDir (char *item, char ***data)
|
2003-06-13 13:11:50 +00:00
|
|
|
{
|
2003-04-30 13:10:51 +00:00
|
|
|
int i;
|
|
|
|
char keypath[255];
|
|
|
|
char **data1;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "g/%s:/%s", segvinmodule, item);
|
2003-04-30 13:10:51 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "g/core:/%s", item);
|
2003-04-30 13:10:51 +00:00
|
|
|
}
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_get_dir (keypath, &data1, NULL);
|
2003-04-30 13:10:51 +00:00
|
|
|
if (i == 0) {
|
|
|
|
*data = data1;
|
|
|
|
return 1;
|
2003-06-13 13:11:50 +00:00
|
|
|
}
|
2003-04-30 13:10:51 +00:00
|
|
|
*data = NULL;
|
2003-07-30 13:58:22 +00:00
|
|
|
nlog (LOG_DEBUG1, LOG_CORE, "GetDir: %s - Path: %s", kp_strerror (i), keypath);
|
2003-04-30 13:10:51 +00:00
|
|
|
return -1;
|
2003-06-13 13:11:50 +00:00
|
|
|
|
|
|
|
}
|
2003-04-30 13:10:51 +00:00
|
|
|
|
2003-04-18 06:41:34 +00:00
|
|
|
|
|
|
|
|
2003-04-09 14:29:51 +00:00
|
|
|
/** @brief Sets Config Data of Type
|
|
|
|
*/
|
2003-07-30 13:58:22 +00:00
|
|
|
int
|
|
|
|
SetConf (void *data, int type, char *item)
|
2003-06-13 13:11:50 +00:00
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
2003-04-09 14:29:51 +00:00
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "g/%s:/%s", segvinmodule, item);
|
2003-04-09 14:29:51 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "g/core:/%s", item);
|
2003-04-09 14:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2003-06-13 13:11:50 +00:00
|
|
|
case CFGSTR:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_set_string (keypath, (char *) data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGINT:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_set_int (keypath, (int) data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGFLOAT:
|
2003-04-09 14:29:51 +00:00
|
|
|
/*
|
|
|
|
i = kp_set_float(keypath, (double *)data);
|
|
|
|
*/
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
case CFGBOOL:
|
2003-07-30 13:58:22 +00:00
|
|
|
i = kp_set_bool (keypath, (int) data);
|
2003-06-13 13:11:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-07-30 13:58:22 +00:00
|
|
|
nlog (LOG_WARNING, LOG_CORE, "Keeper: Called SetConf with invalid datatype %d", type);
|
2003-06-13 13:11:50 +00:00
|
|
|
return -1;
|
2003-04-09 14:29:51 +00:00
|
|
|
}
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
2003-07-30 13:58:22 +00:00
|
|
|
nlog (LOG_WARNING, LOG_CORE, "SetConf: %s", kp_strerror (i));
|
2003-04-09 14:29:51 +00:00
|
|
|
return -1;
|
2003-06-13 13:11:50 +00:00
|
|
|
}
|
2003-04-09 14:29:51 +00:00
|
|
|
return 1;
|
2003-06-13 13:11:50 +00:00
|
|
|
|
2003-04-09 14:29:51 +00:00
|
|
|
}
|
2003-08-01 14:32:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** @brief removes Config Data
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
DelConf (char *item)
|
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "g/%s:/%s", segvinmodule, item);
|
2003-08-01 14:32:12 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "g/core:/%s", item);
|
2003-08-01 14:32:12 +00:00
|
|
|
}
|
|
|
|
i = kp_recursive_do(keypath, (kp_func) kp_remove, 0, NULL);
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "DelConf: %s (%s)", kp_strerror (i), keypath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2003-09-12 16:52:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** @brief Gets Data of Type
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
GetData (void **data, int type, const char *table, const char *row, const char *field)
|
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "l/%s:/%s/%s/%s", segvinmodule, table, row, field);
|
2003-09-12 16:52:26 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "l/core:/%s/%s/%s", table, row, field);
|
2003-09-12 16:52:26 +00:00
|
|
|
}
|
|
|
|
switch (type) {
|
|
|
|
case CFGSTR:
|
|
|
|
i = kp_get_string (keypath, (char **) *&data);
|
|
|
|
break;
|
|
|
|
case CFGINT:
|
|
|
|
i = kp_get_int (keypath, (int *) *&data);
|
|
|
|
break;
|
|
|
|
case CFGFLOAT:
|
|
|
|
i = kp_get_float (keypath, (double *) *&data);
|
|
|
|
break;
|
|
|
|
case CFGBOOL:
|
|
|
|
i = kp_get_bool (keypath, (int *) *&data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "Keeper: Called GetData with invalid datatype %d", type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
|
|
|
nlog (LOG_DEBUG1, LOG_CORE, "GetData: %s - Path: %s", kp_strerror (i), keypath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-10-07 14:26:21 +00:00
|
|
|
/* @brief return an array of strings containing all rows in a database */
|
2003-09-12 16:52:26 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
GetTableData (char *table, char ***data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char keypath[255];
|
|
|
|
char **data1;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "l/%s:/%s", segvinmodule, table);
|
2003-09-12 16:52:26 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "l/core:/%s", table);
|
2003-09-12 16:52:26 +00:00
|
|
|
}
|
|
|
|
i = kp_get_dir (keypath, &data1, NULL);
|
|
|
|
if (i == 0) {
|
|
|
|
*data = data1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*data = NULL;
|
|
|
|
nlog (LOG_DEBUG1, LOG_CORE, "GetTableData: %s - Path: %s", kp_strerror (i), keypath);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Sets Config Data of Type
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
SetData (void *data, int type, char *table, char *row, char *field)
|
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "l/%s:/%s/%s/%s", segvinmodule, table, row, field);
|
2003-09-12 16:52:26 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "l/core:/%s/%s/%s", table, row, field);
|
2003-09-12 16:52:26 +00:00
|
|
|
}
|
|
|
|
switch (type) {
|
|
|
|
case CFGSTR:
|
|
|
|
i = kp_set_string (keypath, (char *) data);
|
|
|
|
break;
|
|
|
|
case CFGINT:
|
|
|
|
i = kp_set_int (keypath, (int) data);
|
|
|
|
break;
|
|
|
|
case CFGFLOAT:
|
|
|
|
/*
|
|
|
|
i = kp_set_float(keypath, (double *)data);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case CFGBOOL:
|
|
|
|
i = kp_set_bool (keypath, (int) data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "Keeper: Called SetData with invalid datatype %d", type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "SetData: %s", kp_strerror (i));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief removes a row from the Database
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
DelRow (char *table, char *row)
|
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "l/%s:/%s/%s", segvinmodule, table, row);
|
2003-09-12 16:52:26 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "l/core:/%s/%s", table, row);
|
2003-09-12 16:52:26 +00:00
|
|
|
}
|
|
|
|
i = kp_recursive_do(keypath, (kp_func) kp_remove, 0, NULL);
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "DelRow: %s (%s)", kp_strerror (i), keypath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief removes a row from the Database
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
DelTable (char *table)
|
|
|
|
{
|
|
|
|
char keypath[255];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* determine if its a module setting */
|
2003-11-03 13:57:11 +00:00
|
|
|
if (segvinmodule[0] != 0) {
|
|
|
|
ircsnprintf (keypath, 255, "l/%s:/%s", segvinmodule, table);
|
2003-09-12 16:52:26 +00:00
|
|
|
} else {
|
2003-11-03 13:57:11 +00:00
|
|
|
ircsnprintf (keypath, 255, "l/core:/%s", table);
|
2003-09-12 16:52:26 +00:00
|
|
|
}
|
|
|
|
i = kp_recursive_do(keypath, (kp_func) kp_remove, 0, NULL);
|
|
|
|
/* check for errors */
|
|
|
|
if (i != 0) {
|
|
|
|
nlog (LOG_WARNING, LOG_CORE, "DelTable: %s (%s)", kp_strerror (i), keypath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2003-09-15 10:39:39 +00:00
|
|
|
/** @brief flushes the Keeper Database out
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
flush_keeper() {
|
|
|
|
kp_flush();
|
2003-09-18 12:21:32 +00:00
|
|
|
}
|