[IRC-Dev CVS] [CVS] Module ircd-ircdev: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2005-03-23 18:37:07
|
CVSROOT : /cvsroot/irc-dev Module : ircd-ircdev Commit time: 2005-03-23 18:35:03 UTC Modified files: ChangeLog ChangeLog.es config.h.in configure configure.in include/client.h include/ddb.h include/hash.h include/ircd_features.h include/ircd_log.h include/msg.h include/patchlevel.h include/struct.h ircd/Makefile.in ircd/ddb.c ircd/hash.c ircd/ircd.c ircd/ircd_features.c ircd/ircd_log.c ircd/m_account.c ircd/m_db.c ircd/m_dbq.c ircd/parse.c ircd/s_bsd.c ircd/s_debug.c ircd/s_serv.c ircd/s_stats.c Added files: ircd/ddb_db_template.c Log message: Author: zoltan <zo...@ir...> Log message: 2005-03-23 Toni García <zo...@ir...> 1.0.alpha22 * Soporte de Bases de Datos Distribuidas en memoria * Comando DB * Comando DBQ * STATS B ---------------------- diff included ---------------------- Index: ircd-ircdev/ChangeLog diff -u ircd-ircdev/ChangeLog:1.23 ircd-ircdev/ChangeLog:1.24 --- ircd-ircdev/ChangeLog:1.23 Mon Mar 21 10:38:47 2005 +++ ircd-ircdev/ChangeLog Wed Mar 23 10:34:15 2005 @@ -1,10 +1,16 @@ # # ChangeLog for ircd-ircdev # -# $Id: ChangeLog,v 1.23 2005/03/21 18:38:47 zolty Exp $ +# $Id: ChangeLog,v 1.24 2005/03/23 18:34:15 zolty Exp $ # # Insert new changes at beginning of the change list. # +2005-03-23 Toni García <zo...@ir...> 1.0.alpha22 + * Distributed DataBase support in memory + * DB command + * DBQ command + * STATS B + 2005-03-21 Toni García <zo...@ir...> 1.0.alpha21 * Spelling correction in commentaries * Undernet synchronization Index: ircd-ircdev/ChangeLog.es diff -u ircd-ircdev/ChangeLog.es:1.23 ircd-ircdev/ChangeLog.es:1.24 --- ircd-ircdev/ChangeLog.es:1.23 Mon Mar 21 10:38:47 2005 +++ ircd-ircdev/ChangeLog.es Wed Mar 23 10:34:15 2005 @@ -1,10 +1,16 @@ # # Log de Cambios para ircd-ircdev # -# $Id: ChangeLog.es,v 1.23 2005/03/21 18:38:47 zolty Exp $ +# $Id: ChangeLog.es,v 1.24 2005/03/23 18:34:15 zolty Exp $ # # Insertar los nuevos cambios al principio de esta lista de cambios. # +2005-03-23 Toni García <zo...@ir...> 1.0.alpha22 + * Soporte de Bases de Datos Distribuidas en memoria + * Comando DB + * Comando DBQ + * STATS B + 2005-03-21 Toni García <zo...@ir...> 1.0.alpha21 * Corrección de ortografía en comentarios * Sincronización Undernet Index: ircd-ircdev/config.h.in diff -u ircd-ircdev/config.h.in:1.6 ircd-ircdev/config.h.in:1.7 --- ircd-ircdev/config.h.in:1.6 Mon Jan 10 04:32:42 2005 +++ ircd-ircdev/config.h.in Wed Mar 23 10:34:16 2005 @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: config.h.in,v 1.6 2005/01/10 12:32:42 zolty Exp $ + * $Id: config.h.in,v 1.7 2005/03/23 18:34:16 zolty Exp $ * */ #ifndef INCLUDED_config_h @@ -93,6 +93,9 @@ /* Configuration file name */ #undef CPATH +/* DDB Environment (Distributed DataBase) */ +#undef DDB + /* Enable debugging code */ #undef DEBUGMODE @@ -229,6 +232,9 @@ /* Define if you have POSIX signals. */ #undef POSIX_SIGNALS +/* Services Environment (Ex-TerraIRCU) */ +#undef SERVICES + /* The size of a `int', as computed by sizeof. */ #undef SIZEOF_INT @@ -262,6 +268,9 @@ /* Define to 1 if your <sys/time.h> declares `struct tm'. */ #undef TM_IN_SYS_TIME +/* UnderNet Environment */ +#undef UNDERNET + /* Define to enable the /dev/poll engine */ #undef USE_DEVPOLL Index: ircd-ircdev/configure diff -u ircd-ircdev/configure:1.13 ircd-ircdev/configure:1.14 --- ircd-ircdev/configure:1.13 Wed Mar 9 10:12:30 2005 +++ ircd-ircdev/configure Wed Mar 23 10:34:18 2005 @@ -1326,6 +1326,7 @@ + echo "$as_me:$LINENO: checking for installation prefix" >&5 echo $ECHO_N "checking for installation prefix... $ECHO_C" >&6 if test "${unet_cv_prefix+set}" = set; then @@ -10193,8 +10194,21 @@ _ACEOF + + + + + + +cat >>confdefs.h <<\_ACEOF +#define DDB +_ACEOF + + ac_config_files="$ac_config_files Makefile ircd/Makefile ircd/test/Makefile doc/Makefile" + ac_config_commands="$ac_config_commands default" + cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -10714,9 +10728,16 @@ _ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +# +# INIT-COMMANDS section. +# +_ACEOF + + cat >>$CONFIG_STATUS <<\_ACEOF for ac_config_target in $ac_config_targets @@ -11502,10 +11523,17 @@ echo "" echo " Maximum connections: $unet_cv_with_maxcon" echo " Domain: $unet_cv_with_domain" -#echo " IRC Environment: DDB (Distributed DataBase)" -#echo " IRC Environment: Services (Ex TerraIRCU)" -#echo " IRC Environment: Undernet" -#echo " IRC Environment: None (BUG, mail to zo...@ir...)" echo "" +if test x"$ircdev_cv_environment_ddb" = xyes; then +echo " IRC Environment: DDB (Distributed DataBase)" +elif test x"$ircdev_cv_environment_services" = xyes; then +echo " IRC Environment: Services (Ex TerraIRCU)" +elif test x"$ircdev_cv_environment_unet" = xyes; then +echo " IRC Environment: Undernet" +else +echo " IRC Environment: None (BUG, mail to zo...@ir...)" +fi +echo "" +echo "Type \"make\" to compile IRC-Dev IRCD" Index: ircd-ircdev/configure.in diff -u ircd-ircdev/configure.in:1.13 ircd-ircdev/configure.in:1.14 --- ircd-ircdev/configure.in:1.13 Wed Mar 9 10:12:30 2005 +++ ircd-ircdev/configure.in Wed Mar 23 10:34:23 2005 @@ -22,12 +22,13 @@ dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl -dnl $Id: configure.in,v 1.13 2005/03/09 18:12:30 zolty Exp $ +dnl $Id: configure.in,v 1.14 2005/03/23 18:34:23 zolty Exp $ dnl dnl Make sure we are in the correct directory (someone could have run dnl 'configure' with a wrong '--srcdir'). -AC_INIT(ircd/ircd.c) +AC_INIT +AC_CONFIG_SRCDIR([ircd/ircd.c]) dnl Set the default prefix AC_PREFIX_DEFAULT([$HOME]) @@ -46,7 +47,7 @@ AC_CONFIG_HEADER([config.h]) dnl Demand at least version 2.50 of autoconf -AC_PREREQ(2.50) +AC_PREREQ(2.59) dnl Find out what type of system we are AC_CANONICAL_HOST @@ -756,8 +757,51 @@ AC_DEFINE_UNQUOTED(MAXCONNECTIONS, $unet_cv_with_maxcon, [Maximum number of network connections]) + +dnl IRC Network environment +dnl Default DDB +dnl ircdev_cv_environment_ddb=yes; + +dnl --with-ddb-environment allows us to use DDB Environment +dnl AC_MSG_CHECKING([whether to use DDB Environment (Distributed DataBase)]) +dnl AC_ARG_WITH([ddb-environment], +dnl [ --with-ddb-environment Use the DDB Environment (Distributed DataBase)], +dnl [ircdev_cv_environment_ddb=$with_ddb_environment], +dnl [AC_CACHE_VAL(ircdev_cv_environment_ddb, +dnl [ircdev_cv_environment_ddb=no])]) +dnl AC_MSG_RESULT([$ircdev_cv_environment_ddb]) + +dnl LO COMENTO PORQUE NO EXISTE AUN! +dnl --with-services-environment allows us to use Services Environment +dnl AC_MSG_CHECKING([whether to use Services Environment (Ex TerraIRCU)]) +dnl AC_ARG_WITH([services-environment], +dnl [ --with-services-environment Use the Services Environment (Ex TerraIRCU)], +dnl [ircdev_cv_environment_services=$with_services_environment], +dnl [AC_CACHE_VAL(ircdev_cv_environment_services, +dnl [ircdev_cv_environment_services=no])]) +dnl AC_MSG_RESULT([$ircdev_cv_environment_services]) + +dnl --with-undernet-environment allows us to use Undernet Environment +dnl AC_MSG_CHECKING([whether to use Undernet Environment]) +dnl AC_ARG_WITH([undernet-environment], +dnl [ --with-undernet-environment Use the Undernet Environment], +dnl [ircdev_cv_environment_undernet=$with_undernet_environment], +dnl [AC_CACHE_VAL(ircdev_cv_environment_undernet, +dnl [ircdev_cv_environment_undernet=no])]) +dnl AC_MSG_RESULT([$ircdev_cv_environment_undernet]) + +dnl if test x"$ircdev_cv_environment_ddb" != "xno" ; then + AC_DEFINE([DDB], , [DDB Environment (Distributed DataBase)]) +dnl else if x"$ircdev_cv_environment_services" != "xno" ; then +dnl AC_DEFINE([SERVICES], , [Services Environment (Ex-TerraIRCU)]) +dnl else if if x"$ircdev_cv_environment_undernet" != "xno" ; then +dnl AC_DEFINE([UNDERNET], , [UnderNet Environment]) +dnl fi + dnl Finally really generate all output files: -AC_OUTPUT(Makefile ircd/Makefile ircd/test/Makefile doc/Makefile, [echo timestamp > stamp-h]) +AC_CONFIG_FILES([Makefile ircd/Makefile ircd/test/Makefile doc/Makefile]) +AC_CONFIG_COMMANDS([default],[[echo timestamp > stamp-h]],[[]]) +AC_OUTPUT dnl Report configuration echo "IRC-Dev ircd is now hopefully configured for your system." @@ -799,10 +843,17 @@ echo "" echo " Maximum connections: $unet_cv_with_maxcon" echo " Domain: $unet_cv_with_domain" -#echo " IRC Environment: DDB (Distributed DataBase)" -#echo " IRC Environment: Services (Ex TerraIRCU)" -#echo " IRC Environment: Undernet" -#echo " IRC Environment: None (BUG, mail to zo...@ir...)" echo "" +if test x"$ircdev_cv_environment_ddb" = xyes; then +echo " IRC Environment: DDB (Distributed DataBase)" +elif test x"$ircdev_cv_environment_services" = xyes; then +echo " IRC Environment: Services (Ex TerraIRCU)" +elif test x"$ircdev_cv_environment_unet" = xyes; then +echo " IRC Environment: Undernet" +else +echo " IRC Environment: None (BUG, mail to zo...@ir...)" +fi +echo "" +echo "Type \"make\" to compile IRC-Dev IRCD" Index: ircd-ircdev/include/client.h diff -u ircd-ircdev/include/client.h:1.11 ircd-ircdev/include/client.h:1.12 --- ircd-ircdev/include/client.h:1.11 Wed Mar 9 10:12:33 2005 +++ ircd-ircdev/include/client.h Wed Mar 23 10:34:24 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Structures and functions for handling local clients. - * @version $Id: client.h,v 1.11 2005/03/09 18:12:33 zolty Exp $ + * @version $Id: client.h,v 1.12 2005/03/23 18:34:24 zolty Exp $ */ #ifndef INCLUDED_client_h #define INCLUDED_client_h @@ -128,6 +128,9 @@ PRIV_LIST_CHAN, /**< oper can list secret channels */ PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */ PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */ +#if defined(DDB) + PRIV_DBQ, /**< oper can use DBQ (DataBase Query) */ +#endif PRIV_APASS_OPMODE, /**< can hack modes +A/-A/+U/-U */ PRIV_LAST_PRIV /**< number of privileges */ }; Index: ircd-ircdev/include/ddb.h diff -u ircd-ircdev/include/ddb.h:1.2 ircd-ircdev/include/ddb.h:1.3 --- ircd-ircdev/include/ddb.h:1.2 Mon Jan 10 04:21:59 2005 +++ ircd-ircdev/include/ddb.h Wed Mar 23 10:34:25 2005 @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ddb.h,v 1.2 2005/01/10 12:21:59 zolty Exp $ + * $Id: ddb.h,v 1.3 2005/03/23 18:34:25 zolty Exp $ * */ #ifndef INCLUDED_ddb_h @@ -27,13 +27,17 @@ #include "config.h" #include "client.h" +#include <sys/stat.h> + #if defined(DDB) /* * General defines */ - +/* Las tablas con los registros, serie, version */ #define DDB_TABLE_MAX 256 +/*Numero de peticiones de registros antes de que haya que empezar a reciclar */ +#define DDB_BUF_CACHE 32 /* * Distributed DataBase Tables @@ -55,48 +59,98 @@ struct Ddb *next; }; +#if 0 +struct portable_stat +{ + dev_t dev; /* ID of device containing a directory entry for this file */ + ino_t ino; /* Inode number */ + off_t size; /* File size in bytes */ + time_t mtime; /* Time of last data modification */ +} +#endif + + struct ddb_memory_table { - char *position; - unsigned int len; - char *point_r; - char *point_w; + struct stat status; + char *position; /* Posicion */ + char *point_r; /* Lectura */ +#if 0 + char *point_w; /* Escritura */ +#endif }; +#if 0 +struct db_file__ { + char *map_p; lo mismo que position + struct stat estado; + char *read_p; +}; +estado.st_size + +struct stat +{ + st_size + st_mtime +} + +struct portable_stat +{ + dev_t dev; /* ID of device containing a directory +entry for this file */ + ino_t ino; /* Inode number */ + off_t size; /* File size in bytes */ + time_t mtime; /* Time of last data modification */ +} +#endif + +#define DdbMalloc(x) MyMalloc(x) +#define DdbFree(x) MyFree(x) /* * Prototypes */ extern struct Ddb **ddb_data_table[DDB_TABLE_MAX]; -extern int ddb_resident_table[DDB_TABLE_MAX]; -extern unsigned long int ddb_count_table[DDB_TABLE_MAX]; -extern unsigned long int ddb_id_table[DDB_TABLE_MAX]; -extern unsigned long int ddb_hashtable_hi[DDB_TABLE_MAX]; -extern unsigned long int ddb_hashtable_lo[DDB_TABLE_MAX]; +extern unsigned int ddb_resident_table[DDB_TABLE_MAX]; +extern unsigned int ddb_count_table[DDB_TABLE_MAX]; +extern unsigned int ddb_id_table[DDB_TABLE_MAX]; +extern unsigned int ddb_hashtable_hi[DDB_TABLE_MAX]; +extern unsigned int ddb_hashtable_lo[DDB_TABLE_MAX]; +extern int ddb_hash_register(char *key, int hash_size); extern int ddb_table_is_resident(unsigned char table); -extern unsigned long int ddb_id_in_table(unsigned char table); -extern unsigned long int ddb_count_in_table(unsigned char table); +extern unsigned int ddb_id_in_table(unsigned char table); +extern unsigned int ddb_count_in_table(unsigned char table); extern void ddb_init(void); -extern int ddb_open(unsigned int registry, char *buf, unsigned char table, - struct ddb_memory_table *dump); + + +/* extern int ddb_read(struct ddb_memory_table *dump, char *buf); -extern void ddb_add(char *registry, unsigned char table, int save_disk); -extern void ddb_del(char *registry, unsigned char table); +*/ +extern void ddb_new_register(struct Client *cptr, unsigned char table, char *mask, unsigned int id, char *key, char *content); extern void ddb_drop(unsigned char table); -extern void ddb_close(struct ddb_memory_table *dump); -extern void ddb_hash_write(unsigned char table); -extern struct Ddb *ddb_find_reg(unsigned char table, char *key); -extern int ddb_is_member(unsigned char table, char *key, char *subcadena); -extern char *ddb_get_botname(char *bot); +extern void ddb_drop_memory(unsigned char table, int events); +extern void ddb_burst(struct Client *cptr); +extern int ddb_table_burst(struct Client *cptr, unsigned char table, unsigned int id); -extern struct Ddb *ddb_iterator_init(unsigned char table); -extern struct Ddb *ddb_iterator_next(void); +extern struct Ddb *ddb_iterator_first(unsigned char table); +extern struct Ddb *ddb_iterator_next(void); +extern struct Ddb *ddb_find_key(unsigned char table, char *key); +extern char *ddb_get_botname(char *bot); +extern void ddb_splithubs_butone(struct Client *cptr, char *exitmsg); extern void ddb_reload(void); -extern void ddb_die(char *msg, unsigned char table); -extern void ddb_burst(struct Client *cptr); -extern void report_ddb(struct Client *cptr); +extern void ddb_die(const char *pattern, ...); +extern void ddb_report_stats(struct Client* to, const struct StatDesc* sd, char* param); + +/* Externs de ddb_db_*.c */ +extern int ddb_db_open(unsigned char table, unsigned int id, struct ddb_memory_table *mt); +extern void ddb_db_close(struct ddb_memory_table *mt); +extern void ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content); +extern void ddb_db_drop(unsigned char table); +extern void ddb_compact(unsigned char table, char *mask, unsigned int id, char *comment); +extern void ddb_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo); +extern void ddb_hash_write(unsigned char table); #endif /* defined(DDB) */ Index: ircd-ircdev/include/hash.h diff -u ircd-ircdev/include/hash.h:1.5 ircd-ircdev/include/hash.h:1.6 --- ircd-ircdev/include/hash.h:1.5 Mon Jan 10 04:21:59 2005 +++ ircd-ircdev/include/hash.h Wed Mar 23 10:34:25 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief Hash table management APIs. - * @version $Id: hash.h,v 1.5 2005/01/10 12:21:59 zolty Exp $ + * @version $Id: hash.h,v 1.6 2005/03/23 18:34:25 zolty Exp $ */ #ifndef INCLUDED_hash_h #define INCLUDED_hash_h @@ -38,7 +38,7 @@ /** Size of client and channel hash tables. * Both must be of the same size. */ -#define HASHSIZE 32000 +#define HASHSIZE 32768 /* * Structures Index: ircd-ircdev/include/ircd_features.h diff -u ircd-ircdev/include/ircd_features.h:1.9 ircd-ircdev/include/ircd_features.h:1.10 --- ircd-ircdev/include/ircd_features.h:1.9 Mon Jan 10 04:21:59 2005 +++ ircd-ircdev/include/ircd_features.h Wed Mar 23 10:34:25 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Public interfaces and declarations for dealing with configurable features. - * @version $Id: ircd_features.h,v 1.9 2005/01/10 12:21:59 zolty Exp $ + * @version $Id: ircd_features.h,v 1.10 2005/03/23 18:34:25 zolty Exp $ */ #ifndef INCLUDED_features_h #define INCLUDED_features_h @@ -112,6 +112,9 @@ FEAT_HIS_STATS_l, FEAT_HIS_STATS_L, FEAT_HIS_STATS_a, +#if defined(DDB) + FEAT_HIS_STATS_b, +#endif FEAT_HIS_STATS_c, FEAT_HIS_STATS_g, FEAT_HIS_STATS_h, Index: ircd-ircdev/include/ircd_log.h diff -u ircd-ircdev/include/ircd_log.h:1.5 ircd-ircdev/include/ircd_log.h:1.6 --- ircd-ircdev/include/ircd_log.h:1.5 Mon Jan 10 04:22:00 2005 +++ ircd-ircdev/include/ircd_log.h Wed Mar 23 10:34:25 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief IRC logging interface. - * @version $Id: ircd_log.h,v 1.5 2005/01/10 12:22:00 zolty Exp $ + * @version $Id: ircd_log.h,v 1.6 2005/03/23 18:34:25 zolty Exp $ */ #ifndef INCLUDED_ircd_log_h #define INCLUDED_ircd_log_h @@ -61,6 +61,9 @@ LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */ LS_WHO, /**< Use of extended WHO privileges. */ LS_NETWORK, /**< New server connections. */ +#ifdef DDB + LS_DDB, /**< Distributed DataBase errors and warnings */ +#endif LS_OPERKILL, /**< Kills by IRC operators. */ LS_SERVKILL, /**< Kills by servers. */ LS_USER, /**< User exits. */ Index: ircd-ircdev/include/msg.h diff -u ircd-ircdev/include/msg.h:1.9 ircd-ircdev/include/msg.h:1.10 --- ircd-ircdev/include/msg.h:1.9 Mon Jan 10 04:22:00 2005 +++ ircd-ircdev/include/msg.h Wed Mar 23 10:34:26 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Command and token declarations and structures. - * @version $Id: msg.h,v 1.9 2005/01/10 12:22:00 zolty Exp $ + * @version $Id: msg.h,v 1.10 2005/03/23 18:34:26 zolty Exp $ */ #ifndef INCLUDED_msg_h #define INCLUDED_msg_h @@ -371,9 +371,11 @@ #define MSG_DB "DB" /* DB */ #define TOK_DB "DB" +#define CMD_DB MSG_DB, TOK_DB #define MSG_DBQ "DBQ" /* DBQ */ #define TOK_DBQ "DBQ" +#define CMD_DBQ MSG_DBQ, TOK_DBQ /* Index: ircd-ircdev/include/patchlevel.h diff -u ircd-ircdev/include/patchlevel.h:1.23 ircd-ircdev/include/patchlevel.h:1.24 --- ircd-ircdev/include/patchlevel.h:1.23 Mon Mar 21 10:39:04 2005 +++ ircd-ircdev/include/patchlevel.h Wed Mar 23 10:34:26 2005 @@ -17,10 +17,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: patchlevel.h,v 1.23 2005/03/21 18:39:04 zolty Exp $ + * $Id: patchlevel.h,v 1.24 2005/03/23 18:34:26 zolty Exp $ * */ -#define PATCHLEVEL ".alpha21" +#define PATCHLEVEL ".alpha22" #define RELEASE "1.0" Index: ircd-ircdev/include/struct.h diff -u ircd-ircdev/include/struct.h:1.7 ircd-ircdev/include/struct.h:1.8 --- ircd-ircdev/include/struct.h:1.7 Mon Jan 10 04:22:00 2005 +++ ircd-ircdev/include/struct.h Wed Mar 23 10:34:27 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief Structure definitions for users and servers. - * @version $Id: struct.h,v 1.7 2005/01/10 12:22:00 zolty Exp $ + * @version $Id: struct.h,v 1.8 2005/03/23 18:34:27 zolty Exp $ */ #ifndef INCLUDED_struct_h #define INCLUDED_struct_h @@ -61,6 +61,10 @@ int asll_to; /**< AsLL upstream lag */ int asll_from; /**< AsLL downstream lag */ +#if defined(DDB) + unsigned long ddb_open; /**< DDB database open */ +#endif + char *last_error_msg; /**< Allocated memory with last message receive with an ERROR */ char by[NICKLEN + 1]; /**< Numnick of client who requested the link */ }; Index: ircd-ircdev/ircd/Makefile.in diff -u ircd-ircdev/ircd/Makefile.in:1.19 ircd-ircdev/ircd/Makefile.in:1.20 --- ircd-ircdev/ircd/Makefile.in:1.19 Mon Mar 21 10:39:05 2005 +++ ircd-ircdev/ircd/Makefile.in Wed Mar 23 10:34:27 2005 @@ -18,7 +18,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -# $Id: Makefile.in,v 1.19 2005/03/21 18:39:05 zolty Exp $ +# $Id: Makefile.in,v 1.20 2005/03/23 18:34:27 zolty Exp $ #### Start of system configuration section. #### @@ -57,6 +57,7 @@ MPATH = ${DPATH}/ircd.motd RPATH = ${DPATH}/remote.motd + CC = @CC@ CFLAGS = @CFLAGS@ CPPFLAGS = -I. -I.. -I${top_srcdir}/include @CPPFLAGS@ @@ -86,6 +87,15 @@ memdebug.c \ umkpasswd.c +UNDERNET_SRC = \ + m_account.c \ + +DDB_SRC = \ + ddb.c \ + ddb_db_template.c \ + m_db.c \ + m_dbq.c + IRCD_SRC = \ IPcheck.c \ channel.c \ @@ -93,7 +103,6 @@ client.c \ crule.c \ dbuf.c \ - ddb.c \ destruct_event.c \ fileio.c \ gline.c \ @@ -117,7 +126,6 @@ lex.yy.c \ list.c \ listener.c \ - m_account.c \ m_admin.c \ m_asll.c \ m_away.c \ @@ -128,8 +136,6 @@ m_connect.c \ m_cprivmsg.c \ m_create.c \ - m_db.c \ - m_dbq.c \ m_defaults.c \ m_destruct.c \ m_desynch.c \ @@ -223,13 +229,15 @@ whowas.c \ y.tab.c -SRC = ${IRCD_SRC} ${ENGINE_C} ${CRYPTO_SRC} +#SRC = ${IRCD_SRC} ${ENGINE_C} ${CRYPTO_SRC} +#SRC = ${IRCD_SRC} ${UNDERNET_SRC} ${ENGINE_C} ${CRYPTO_SRC} +SRC = ${IRCD_SRC} ${DDB_SRC} ${ENGINE_C} ${CRYPTO_SRC} OBJS = ${SRC:%.c=%.o} UMKPASSWD_OBJS = ${UMKPASSWD_SRC:%.c=%.o} -DEP_SRC = ${IRCD_SRC} ${ENGINE_SRC} ${CRYPTO_SRC} +DEP_SRC = ${IRCD_SRC} ${UNDERNET_SRC} ${DDB} ${ENGINE_SRC} ${CRYPTO_SRC} all: ( cd ..; make -f Makefile ) Index: ircd-ircdev/ircd/ddb.c diff -u ircd-ircdev/ircd/ddb.c:1.3 ircd-ircdev/ircd/ddb.c:1.4 --- ircd-ircdev/ircd/ddb.c:1.3 Mon Jan 10 04:22:58 2005 +++ ircd-ircdev/ircd/ddb.c Wed Mar 23 10:34:46 2005 @@ -18,7 +18,634 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ddb.c,v 1.3 2005/01/10 12:22:58 zolty Exp $ - * + */ +/** @file + * @brief Implementation of Distributed DataBase. + * @version $Id: ddb.c,v 1.4 2005/03/23 18:34:46 zolty Exp $ */ #include "config.h" + +#include "ddb.h" +#include "ircd.h" +#include "ircd_alloc.h" +#include "ircd_chattr.h" +#include "ircd_log.h" +#include "ircd_reply.h" +#include "ircd_string.h" +#include "ircd_tea.h" +#include "list.h" +#include "match.h" +#include "msg.h" +#include "numeric.h" +#include "s_bsd.h" +#include "s_debug.h" +#include "s_misc.h" +#include "send.h" + +/* #include <assert.h> -- Now using assert in ircd_log.h */ +#include <stdarg.h> +#include <stdio.h> +/*#include <stdlib.h> */ +#include <string.h> +#include <time.h> + +static struct Ddb ddb_buf_cache[DDB_BUF_CACHE]; +static int ddb_buf_cache_i = 0; + +struct Ddb **ddb_data_table[DDB_TABLE_MAX]; +short ddb_corrupt_table[DDB_TABLE_MAX]; +unsigned int ddb_resident_table[DDB_TABLE_MAX]; +unsigned int ddb_count_table[DDB_TABLE_MAX]; +unsigned int ddb_id_table[DDB_TABLE_MAX]; +unsigned int ddb_hashtable_hi[DDB_TABLE_MAX]; +unsigned int ddb_hashtable_lo[DDB_TABLE_MAX]; +struct ddb_memory_table ddb_memorytable[DDB_TABLE_MAX]; + +static struct Ddb *ddb_iterator_key = NULL; +static struct Ddb **ddb_iterator_content = NULL; +static int ddb_iterator_hash_pos = 0; +static int ddb_iterator_hash_len = 0; + +static void ddb_table_init(unsigned char table); +static void ddb_add_key(unsigned char table, char *key, char *content); +static void ddb_del_key(unsigned char table, char *key); + + +int ddb_table_is_resident(unsigned char table) +{ + return ddb_resident_table[table] ? 1 : 0; +} + +/* +unsigned int ddb_id_in_table(unsigned char table) +{ + return ddb_id_in_table[table]; +} + +unsigned int ddb_count_in_table(unsigned char table) +{ + return ddb_count_in_table[table]; +} +*/ + +static void DdbCopyMalloc(char *buf, int len, char **p) +{ + char *p2; + + p2 = *p; + if ((p2) && (strlen(p2) < len)) + { + MyFree(p2); + p2 = NULL; + } + if (!p2) + { + p2 = MyMalloc(len + 1); /* El '\0' final */ + *p = p2; + } + memcpy(p2, buf, len); + p2[len] = '\0'; +} + +static void ddb_hash_calculate(unsigned char table, unsigned int id, char *mask, char *key, char *content) +{ + unsigned int buffer[129 * sizeof(unsigned int)]; + unsigned int *p = buffer; + unsigned int x[2], v[2], k[2]; + char *p2; + char buf[1024]; + + /* ID Mask Key Content */ + if (content) + sprintf(buf, "%u %s %s %s", id, mask, key, content); + else + sprintf(buf, "%u %s %s", id, mask, key); + memset(buffer, 0, sizeof(buffer)); + strncpy((char *)buffer, buf, sizeof(buffer) - 1); + + + /* Parece que no es necesario, comprobarlo */ + while ((p2 = strchr((char *)buffer, '\n'))) + *p2 = '\0'; + while ((p2 = strchr((char *)buffer, '\r'))) + *p2 = '\0'; + + k[0] = k[1] = 0; + x[0] = ddb_hashtable_hi[table]; + x[1] = ddb_hashtable_lo[table] = x[1]; + + while (*p) + { + v[0] = ntohl(*p++); + v[1] = ntohl(*p++); + ircd_tea(v, k, x); + } + ddb_hashtable_hi[table] = x[0]; + ddb_hashtable_lo[table] = x[1]; +} + + +/** initialize Distributed DataBase + */ +void +ddb_init(void) +{ + unsigned char table; + + /* ddb_events_init(); */ + + memset(ddb_resident_table, 0, sizeof(ddb_resident_table)); + + /* + * Las longitudes DEBEN ser potencias de 2, + * y no deben ser superiores a HASHSIZE, ya que ello + * solo desperdiciaria memoria. + */ + ddb_resident_table[DDB_NICKDB] = 32768; + + for (table = DDB_INIT; table <= DDB_END; table++) + ddb_table_init(table); + + /* + * La operacion anterior puede ser una operacion larga. + * Resincronizamos tiempo. + */ + CurrentTime = time(NULL); +} + +static void ddb_table_init(unsigned char table) +{ + + ddb_drop_memory(table, 0); + /* Leer Datos */ + + /* Leer Hash */ + +} + +void +ddb_new_register(struct Client *cptr, unsigned char table, char *mask, unsigned int id, char *key, char *content) +{ + static char *keytemp = NULL; + static int key_len = 0; + + assert(0 != table); + assert(0 != key); + + ddb_hash_calculate(table, id, mask, key, content); + + /* Al iniciar, cptr no existe y por lo tanto no se escribe */ + if (cptr) + { + ddb_db_write(table, mask, id, key, content); + ddb_hash_write(table); + } + + ddb_id_table[table] = id; + + /* Solo ponemos en memoria registros cuya mascara + * concuerda con el servidor. + * Y por supuesto, que sean residentes + */ + if (!ddb_resident_table[table]) + return; + + /* Usamos collapse+match por un bug en lastNNServer del find_match_server */ + collapse(mask); + if (!match(mask, cli_name(&me))) + { + int i = 0; + + /* pasamos el key en minusculas */ + if ((strlen(key) + 1 > key_len) || (!keytemp)) + { + key_len = strlen(key) + 1; + if (keytemp) + MyFree(keytemp); + keytemp = MyMalloc(key_len); + + assert(0 != keytemp); + } + strcpy(keytemp, key); + while (keytemp[i]) + { +/* keytemp[i] = toLower(keytemp[i]); */ + i++; + } + + if (content) + ddb_add_key(table, keytemp, content); + else + ddb_del_key(table, keytemp); + +#if 0 + /* Ejecutamos los eventos */ + if (!cptr && ddb_event_tables[table]) + ddb_event_parse[table](key, content); +#endif + } + +} + +static void +ddb_add_key(unsigned char table, char *key, char *content) +{ + struct Ddb *ddb; + char *k, *c; + int hashi; + + ddb_iterator_key = NULL; + + ddb_del_key(table, key); + + ddb = DdbMalloc(sizeof(struct Ddb) + strlen(key) + strlen(content) + 2); + assert(0 != ddb); + + k = (char *)ddb + sizeof(struct Ddb); + c = k + strlen(key) + 1; + + strcpy(k, key); + strcpy(c, content); + + /* paso a minusculas */ +/* + while (c[i] != 0) + { + k[i] = toLower(c[i]); + i++; + } +*/ + + ddb->key = k; + ddb->content = c; +// strcpy(ddb->key, key); +// strcpy(ddb->content, content); + ddb->next = NULL; + + hashi = ddb_hash_register(ddb->key, ddb_resident_table[table]); + + Debug((DEBUG_INFO, "Inserto T='%c' K='%s' C='%s' H=%u",table, ddb->key, ddb->content, hashi)); + + ddb->next = ddb_data_table[table][hashi]; + ddb_data_table[table][hashi] = ddb; + ddb_count_table[table]++; + + /* EVENTOS DE ALTA */ +} + +static void +ddb_del_key(unsigned char table, char *key) +{ + struct Ddb *ddb, *ddb2, **ddb3; + int hashi; + + ddb_iterator_key = NULL; + + hashi = ddb_hash_register(key, ddb_resident_table[table]); + ddb3 = &ddb_data_table[table][hashi]; + + for (ddb = *ddb3; ddb; ddb = ddb2) + { + ddb2 = ddb->next; + if (!strcmp(ddb->key, key)) + { + *ddb3 = ddb2; + /* EVENTOS de BAJA */ + DdbFree(ddb); + ddb_count_table[table]--; + break; + } + ddb3 = &(ddb->next); + } +} + + +void +ddb_drop(unsigned char table) +{ + + /* Borramos el fichero de la tabla */ + /* TODO-ZOLTAN: Comento, para only-read */ +/* ddb_db_drop(table); */ + + /* Borramos la tabla en la memoria */ + ddb_drop_memory(table, 0); + +/* TODO-ZOLTAN: Comento, para only-read */ +/* ddb_hash_write(table); */ + ddb_corrupt_table[table] = 0; +/* + tabla_modificado[tabla] = time(NULL); +*/ +} + +void ddb_drop_memory(unsigned char table, int events) +{ + struct Ddb *ddb, *ddb2; + int i; + + if (!ddb_resident_table[table]) + return; + + if (ddb_data_table[table]) + { + for (i = 0; i < ddb_resident_table[table]; i++) + { + for (ddb = ddb_data_table[table][i]; ddb; ddb = ddb2) + { + ddb2 = ddb->next; +#if 0 + if (events && ddb_event_tables[table]) + ddb_event_parse[table](ddb->key, NULL); +#endif + DdbFree(ddb); + } + } + } + else + { + ddb_data_table[table] = DdbMalloc(ddb_resident_table[table] * sizeof(struct Ddb *)); + assert(ddb_data_table[table]); + } + + for (i = 0; i < ddb_resident_table[table]; i++) + { + ddb_data_table[table][i] = NULL; + } + + ddb_count_table[table] = 0; + ddb_id_table[table] = 0; + ddb_hashtable_hi[table] = 0; + ddb_hashtable_lo[table] = 0; +/* + tabla_corrupta[tabla] = 0; + tabla_modificado[tabla] = time(NULL); +*/ +} + + +void +ddb_burst(struct Client *cptr) +{ + int i; + + for (i = DDB_INIT; i <= DDB_END; i++) + sendcmdto_one(&me, CMD_DB, cptr, "* 0 J %u %c", + ddb_id_table[i], i); +} + +int +ddb_table_burst(struct Client *cptr, unsigned char table, unsigned int id) +{ + return 1; + +#if 0 + int cont = 1000; + /* Leer Datos */ + + do + { + + if (content) + sendcmdto_one(&me, CMD_DB, cptr, "%s %u %s %s :%s", mask, id, table, key, content); + else + sendcmdto_one(&me, CMD_DB, cptr, "%s %u %s %s", mask, id, table, key); + + if (!(--cont)) + break; + } while (leer) + + if (cont) + { + cli_serv(cptr)->ddb_open |= ((unsigned int)1) << (table - DDB_INIT); + return 1; + } + else + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 B %u %c", mask, ddb_id_table[table], table); + + return 0; +#endif +} + + +static struct Ddb * +ddb_iterator_init(void) +{ + struct Ddb *ddb; + + if (ddb_iterator_key) + { + ddb_iterator_key = ddb_iterator_key->next; + if (ddb_iterator_key) + { + return ddb_iterator_key; + } + } + + /* + * Indica el PROXIMO valor a utilizar. + */ + while (ddb_iterator_hash_pos < ddb_iterator_hash_len) + { + ddb = ddb_iterator_content[ddb_iterator_hash_pos++]; + if (ddb) { + ddb_iterator_key = ddb; + return ddb; + } + } + + ddb_iterator_key = NULL; + ddb_iterator_content = NULL; + ddb_iterator_hash_pos = 0; + ddb_iterator_hash_len = 0; + + return NULL; +} + +struct Ddb * +ddb_iterator_first(unsigned char table) +{ + assert((table >= DDB_INIT) && (table <= DDB_END)); + + ddb_iterator_hash_len = ddb_resident_table[table]; + assert(ddb_iterator_hash_len); + + ddb_iterator_hash_pos = 0; + ddb_iterator_content = ddb_data_table[table]; + ddb_iterator_key = NULL; + + return ddb_iterator_init(); +} + +struct Ddb * +ddb_iterator_next(void) +{ + assert(ddb_iterator_key); + assert(ddb_iterator_content); + assert(ddb_iterator_hash_len); + + return ddb_iterator_init(); +} + + +static struct Ddb *ddb_find_registry_table(unsigned char table, char *key) +{ + struct Ddb *ddb; + static char *k = 0; + static int k_len = 0; + int i, hashi; + + if ((strlen(key) + 1 > k_len) || (!k)) + { + k_len = strlen(key) + 1; + if (k) + MyFree(k); + k = MyMalloc(k_len); + if (!k) + return 0; + } + strcpy(k, key); + /* paso a minusculas */ + i = 0; + while (k[i]) + { +/* k[i] = ToLower(k[i]); */ + i++; + } + + hashi = ddb_hash_register(k, ddb_resident_table[table]); + + for (ddb = ddb_data_table[table][hashi]; ddb; ddb = ddb->next) + { +/* if (!strcmp(ddb->key, k)) */ + if (!ircd_strcmp(ddb->key, k)) + return ddb; + } + return NULL; +} + +struct Ddb *ddb_find_key(unsigned char table, char *key) +{ + struct Ddb *ddb; + char *key_init; + char *key_end; + char *content_init; + char *content_end; + + if (!ddb_resident_table[table]) + return NULL; + + ddb = ddb_find_registry_table(table, key); + if (!ddb) + return NULL; + + /* Lo que sigue lo sustituye */ + key_init = ddb->key; + key_end = key_init + strlen(key_init); + content_init = ddb->content; + content_end = content_init + strlen(content_init); + + DdbCopyMalloc(key_init, key_end - key_init, + &ddb_buf_cache[ddb_buf_cache_i].key); + DdbCopyMalloc(content_init, content_end - content_init, + &ddb_buf_cache[ddb_buf_cache_i].content); + if (++ddb_buf_cache_i >= DDB_BUF_CACHE) + ddb_buf_cache_i = 0; + + return ddb; +} + +char * +ddb_get_botname(char *bot) +{ + return cli_name(&me); +} + + +void +ddb_reload(void) +{ + sendto_opmask_butone(0, SNO_OLDSNO, "Reload Distributed DataBase..."); + log_write(LS_DDB, L_INFO, 0, "Reload Distributed DataBase..."); + + ddb_init(); +} + + +/** Split all Hubs but one. + * @param[in] cptr Client that is not closed. + * @param[in] exitmsg SQUIT message. + */ +void +ddb_splithubs_butone(struct Client *cptr, char *exitmsg) +{ + struct DLink *lp, *lp2; + struct Client *acptr; + + for (lp = cli_serv(&me)->down; lp; lp = lp2) + { + lp2 = lp->next; + + acptr = lp->value.cptr; + if ((acptr != cptr) && (IsHub(acptr))) + exit_client(acptr, acptr, &me, exitmsg); + } +} + +/** Die the server with an DDB error. + * @param[in] pattern Format string of message. + */ +void +ddb_die(const char *pattern, ...) +{ + struct Client *acptr; + char exitmsg[1024], exitmsg2[1024]; + va_list vl; + int i; + + va_start(vl, pattern); + vsprintf(exitmsg2, pattern, vl); + va_end(vl); + + sprintf(exitmsg, "DDB Error: %s", exitmsg2); + + for (i = 0; i <= HighestFd; i++) + { + if (!(acptr = LocalClientArray[i])) + continue; + if (IsUser(acptr)) + sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Server Terminating. %s", + acptr, exitmsg); + else if (IsServer(acptr)) + sendcmdto_one(&me, CMD_ERROR, acptr, ":Terminated by %s", exitmsg); + } + server_die(exitmsg); +} + + +/** Report all F-lines to a user. + * @param[in] to Client requesting statistics. + * @param[in] sd Stats descriptor for request (ignored). + * @param[in] param Extra parameter from user (ignored). + */ +void +ddb_report_stats(struct Client* to, const struct StatDesc* sd, char* param) +{ + unsigned char table; + + for (table = DDB_INIT; table <= DDB_END; table++) + { + if (ddb_table_is_resident(table)) + send_reply(to, SND_EXPLICIT | RPL_STATSDEBUG, + "b :Table '%c' S=%lu R=%lu", table, + (unsigned long)ddb_id_table[table], + (unsigned long)ddb_count_table[table]); + else + { + if (ddb_id_table[table]) + send_reply(to, SND_EXPLICIT | RPL_STATSDEBUG, + "b :Table '%c' S=%lu NoResident", table, + (unsigned long)ddb_id_table[table]); + } + } +} Index: ircd-ircdev/ircd/ddb_db_template.c diff -u /dev/null ircd-ircdev/ircd/ddb_db_template.c:1.1 --- /dev/null Wed Mar 23 10:36:27 2005 +++ ircd-ircdev/ircd/ddb_db_template.c Wed Mar 23 10:34:47 2005 @@ -0,0 +1,79 @@ +/* + * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/ddb_db_example.c + * + * Copyright (C) 2002-2005 IRC-Dev Development Team <de...@ir...> + * Copyright (C) 2004-2005 Toni Garcia (zoltan) <zo...@ir...> + * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> + * + * 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 + * + */ +/** @file + * @brief Implementation of Distributed DataBase. + * @version $Id: ddb_db_template.c,v 1.1 2005/03/23 18:34:47 zolty Exp $ + */ +#include "config.h" + +#include "ddb.h" +#include "numnicks.h" + +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> + +int +ddb_db_open(unsigned char table, unsigned int id, struct ddb_memory_table *mt) +{ + return 1; +} + + +void ddb_db_close(struct ddb_memory_table *mt) +{ +} + +int ddb_db_read(struct ddb_memory_table *mt, char *mask, char *id, char *key, char *content) +{ + return 1; +} + +void ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content) +{ +} + +void ddb_db_drop(unsigned char table) +{ +} + +void +ddb_db_compact(unsigned char table, char *mask, unsigned int id, char *comment) +{ + +} + + + +void ddb_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo) +{ +} + +void ddb_hash_write(unsigned char table) +{ +} + Index: ircd-ircdev/ircd/hash.c diff -u ircd-ircdev/ircd/hash.c:1.7 ircd-ircdev/ircd/hash.c:1.8 --- ircd-ircdev/ircd/hash.c:1.7 Mon Mar 21 10:39:07 2005 +++ ircd-ircdev/ircd/hash.c Wed Mar 23 10:34:47 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief Hash table management. - * @version $Id: hash.c,v 1.7 2005/03/21 18:39:07 zolty Exp $ + * @version $Id: hash.c,v 1.8 2005/03/23 18:34:47 zolty Exp $ * * This file used to use some very complicated hash function. Now it * uses CRC-32, but effectively remaps each input byte according to a @@ -33,6 +33,7 @@ #include "hash.h" #include "client.h" #include "channel.h" +#include "ddb.h" #include "ircd_alloc.h" #include "ircd_chattr.h" #include "ircd_log.h" @@ -520,3 +521,14 @@ send_reply(cptr, RPL_LISTEND); } } + +#if defined(DDB) + +/** Calculates a hash of one key. + */ +int ddb_hash_register(char *key, int hash_size) +{ + return (unsigned int)(strhash(key) & (hash_size - 1)); +} + +#endif /* DDB */ Index: ircd-ircdev/ircd/ircd.c diff -u ircd-ircdev/ircd/ircd.c:1.13 ircd-ircdev/ircd/ircd.c:1.14 --- ircd-ircdev/ircd/ircd.c:1.13 Mon Mar 21 10:39:07 2005 +++ ircd-ircdev/ircd/ircd.c Wed Mar 23 10:34:47 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Entry point and other initialization functions for the daemon. - * @version $Id: ircd.c,v 1.13 2005/03/21 18:39:07 zolty Exp $ + * @version $Id: ircd.c,v 1.14 2005/03/23 18:34:47 zolty Exp $ */ #include "config.h" @@ -30,6 +30,7 @@ #include "class.h" #include "client.h" #include "crule.h" +#include "ddb.h" #include "destruct_event.h" #include "hash.h" #include "ircd_alloc.h" @@ -723,6 +724,10 @@ Debug((DEBUG_NOTICE, "Server ready...")); log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready"); +#if defined(DDB) + ddb_init(); +#endif + event_loop(); return 0; Index: ircd-ircdev/ircd/ircd_features.c diff -u ircd-ircdev/ircd/ircd_features.c:1.11 ircd-ircdev/ircd/ircd_features.c:1.12 --- ircd-ircdev/ircd/ircd_features.c:1.11 Mon Mar 21 10:39:07 2005 +++ ircd-ircdev/ircd/ircd_features.c Wed Mar 23 10:34:48 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Implementation of configurable feature support. - * @version $Id: ircd_features.c,v 1.11 2005/03/21 18:39:07 zolty Exp $ + * @version $Id: ircd_features.c,v 1.12 2005/03/23 18:34:48 zolty Exp $ */ #include "config.h" @@ -352,6 +352,9 @@ F_B(HIS_STATS_l, 0, 1, 0), F_B(HIS_STATS_L, 0, 1, 0), F_B(HIS_STATS_a, 0, 1, 0), +#if defined(DDB) + F_B(HIS_STATS_b, 0, 1, 0), +#endif F_B(HIS_STATS_c, 0, 1, 0), F_B(HIS_STATS_g, 0, 1, 0), F_B(HIS_STATS_h, 0, 1, 0), Index: ircd-ircdev/ircd/ircd_log.c diff -u ircd-ircdev/ircd/ircd_log.c:1.8 ircd-ircdev/ircd/ircd_log.c:1.9 --- ircd-ircdev/ircd/ircd_log.c:1.8 Mon Mar 21 10:39:07 2005 +++ ircd-ircdev/ircd/ircd_log.c Wed Mar 23 10:34:48 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief IRC logging implementation. - * @version $Id: ircd_log.c,v 1.8 2005/03/21 18:39:07 zolty Exp $ + * @version $Id: ircd_log.c,v 1.9 2005/03/23 18:34:48 zolty Exp $ */ #include "config.h" @@ -156,6 +156,9 @@ S(JUPE, -1, SNO_NETWORK), S(WHO, -1, 0), S(NETWORK, -1, SNO_NETWORK), +#ifdef DDB + S(DDB, -1, 0), +#endif S(OPERKILL, -1, 0), S(SERVKILL, -1, 0), S(USER, -1, 0), Index: ircd-ircdev/ircd/m_account.c diff -u ircd-ircdev/ircd/m_account.c:1.8 ircd-ircdev/ircd/m_account.c:1.9 --- ircd-ircdev/ircd/m_account.c:1.8 Mon Mar 21 10:39:08 2005 +++ ircd-ircdev/ircd/m_account.c Wed Mar 23 10:34:49 2005 @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: m_account.c,v 1.8 2005/03/21 18:39:08 zolty Exp $ + * $Id: m_account.c,v 1.9 2005/03/23 18:34:49 zolty Exp $ * */ @@ -105,7 +105,6 @@ int ms_account(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { -#if defined(UNDERNET) struct Client *acptr; if (parc < 3) @@ -146,10 +145,4 @@ cli_user(acptr)->acc_create); return 0; - -#else /* !defined(UNDERNET) */ - - return protocol_violation(cptr, "ACCOUNT command is disabled (NO Undernet Environment)"); - -#endif /* defined(UNDERNET) */ } Index: ircd-ircdev/ircd/m_db.c diff -u ircd-ircdev/ircd/m_db.c:1.2 ircd-ircdev/ircd/m_db.c:1.3 --- ircd-ircdev/ircd/m_db.c:1.2 Mon Jan 10 04:23:01 2005 +++ ircd-ircdev/ircd/m_db.c Wed Mar 23 10:34:50 2005 @@ -2,7 +2,8 @@ * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/m_db.c * * Copyright (C) 2002-2005 IRC-Dev Development Team <de...@ir...> - * Copyright (C) 2004 Toni Garcia (zoltan) <zo...@ir...> + * Copyright (C) 2004-2005 Toni Garcia (zoltan) <zo...@ir...> + * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> * * 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 @@ -18,111 +19,366 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: m_db.c,v 1.2 2005/01/10 12:23:01 zolty Exp $ */ - -/* - * m_functions execute protocol messages on this server: - * - * cptr is always NON-NULL, pointing to a *LOCAL* client - * structure (with an open socket connected!). This - * identifies the physical socket where the message - * originated (or which caused the m_function to be - * executed--some m_functions may call others...). - * - * sptr is the source of the message, defined by the - * prefix part of the message if present. If not - * or prefix not found, then sptr==cptr. - * - * (!IsServer(cptr)) => (cptr == sptr), because - * prefixes are taken *only* from servers... - * - * (IsServer(cptr)) - * (sptr == cptr) => the message didn't - * have the prefix. - * - * (sptr != cptr && IsServer(sptr) means - * the prefix specified servername. (?) - * - * (sptr != cptr && !IsServer(sptr) means - * that message originated from a remote - * user (not local). - * - * combining - * - * (!IsServer(sptr)) means that, sptr can safely - * taken as defining the target structure of the - * message in this server. - * - * *Always* true (if 'parse' and others are working correct): - * - * 1) sptr->from == cptr (note: cptr->from == cptr) - * - * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr - * *cannot* be a local connection, unless it's - * actually cptr!). [MyConnect(x) should probably - * be defined as (x == x->from) --msa ] - * - * parc number of variable parameter strings (if zero, - * parv is allowed to be NULL) - * - * parv a NULL terminated list of parameter pointers, - * - * parv[0], sender (prefix string), if not present - * this points to an empty string. - * parv[1]...parv[parc-1] - * pointers to additional parameters - * parv[parc] == NULL, *always* - * - * note: it is guaranteed that parv[0]..parv[parc-1] are all - * non-NULL pointers. +/** @file + * @brief Handlers for DB command. + * @version $Id: m_db.c,v 1.3 2005/03/23 18:34:50 zolty Exp $ */ +/* TODO-ZOLTAN + * Traducidr los comentarios al ingles */ #include "config.h" -#if defined(DDB) #include "ddb.h" #include "client.h" -/*#include "ircd_log.h" */ -#include "ircd_reply.h" -#include "msg.h" - -/* #include "ircd.h" -#include "ircd_string.h" +#include "ircd_log.h" +#include "ircd_reply.h" #include "list.h" #include "match.h" #include "msg.h" #include "numnicks.h" -#include "s_bdd.h" -#include "s_conf.h" #include "send.h" +#include "s_debug.h" -#include <fcntl.h> +/* #include <assert.h> -- Now using assert in ircd_log.h */ +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> -#include <unistd.h> -*/ -/* - * ms_db - server message handler +/** Handle a DB command from a server. * - * parv[0] = sender - * parv[1] = ignored - * parv[2] = server to query + * \a parv has the following elements: + * \a parv[1] is the destin server o servermask + * \li If a command parv has the following elements + * \li \a parv[2] is not used + * \li \a parv[3] is the command (B, D, E, H, J, Q, R) + * \li \a parv[4] is the id or token + * \li \a parv[5] is the table of DDB + * \li If not a command, it is a new register + * \li \a parv[2] is the id + * \li \a parv[3] is the table of DDB + * \li \a parv[4] is a key of register + * \li \a parv[5] is a content of register (optional) + * + * See @ref m_functions for general discussion of parameters. + * @param[in] cptr Client that sent us the message. + * @param[in] sptr Original source of message. + * @param[in] parc Number of arguments. + * @param[in] parv Argument vector. */ int ms_db(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { - if (parc > 5) + struct Client *acptr; + struct DLink *lp; + char ddb_buf[1024]; + unsigned char table = 0; + unsigned int id, ddb_mask = 0; + + assert(0 != cptr); + assert(0 != sptr); + assert(IsServer(cptr)); + + if ((parc < 5) || (*(parv[3] + 1) != '\0')) + { + protocol_violation(sptr, "Too few parameters for DB"); + return 0; + } + + id = atoi(parv[2]); + if (!id) { - protocol_violation(sptr,"DDB, too many parameters"); - return 0; + /* No es un registro */ + id = atoi(parv[4]); + if (parc == 6) + { + table = *parv[5]; + if ((table < DDB_INIT) || (table > DDB_END)) + { + /* Se pide un HASH Global de todas las tablas */ + if ((table == '*') && ((*parv[3] == 'Q') || (*parv[3] == 'R'))) + table = '*'; +#if 1 + /* COMPATIBILIDAD IRC-HISPANO */ + else if (table == '2') + table = DDB_NICKDB; +#endif + else + return protocol_violation(sptr, "Incorrect table parameter for DB"); + } + } } + if ((table >= DDB_INIT) && (table <= DDB_END)) + ddb_mask = ((unsigned int)1) << (table - DDB_INIT); + + switch (*parv[3]) + { + /* Peticion de Burst (quedan registros) */ + case 'B': + if (IsHub(cptr)) + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", parv[0], ddb_id_table[table], table); + break; + + /* Drop */ + case 'D': + { + if (!IsHub(cptr)) + break; + + /* Enviamos el mensaje al resto de servidores */ + for (lp = cli_serv(&me)->down; lp; lp = lp->next) + { + if (lp->value.cptr != cptr) + { + sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%s 0 D %s %c", + parv[1], parv[4], table); + /* TODO-ZOLTAN: Mirar si es necesario (IRC-Hispano) */ + /* cli_serv(lp->value.cptr)->ddb_open &= ~ddb_mask); */ + } + } + + /* Usamos collapse+match por un bug en lastNNServer del find_match_server() */ + collapse(parv[1]); + /* Si no es para nosotros, lo ignoramos */ + if (match(parv[1], cli_name(&me))) + break; + + /* Borramos la tabla en memoria y en disco */ + ddb_drop(table); + /* Desconectamos con todos los hubs menos el que nos envia la orden */ + log_write(LS_DDB, L_INFO, 0, "DB Drop Table %c from %#C", table, cptr); + sprintf(ddb_buf, "DB DROP Table %c from %s", table, cli_name(cptr)); + ddb_splithubs_butone(cptr, ddb_buf); + + /* Mandamos la respuesta de conformidad */ + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 E %s %c", cli_name(cptr), + parv[4], table); + + /* TODO-ZOLTAN: Cosa de ryden. Creo que hay que mandar a todos */ + cli_serv(cptr)->ddb_open &= ~ddb_mask; + + /* Solicitamos de nuevo la tabla */ + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", cli_name(cptr), + ddb_id_table[table], table); + break; + } + + /* Respuesta de Drop */ + case 'E': + /* Si no es para nosotros, lo pasamos a otros */ + if ((acptr = find_match_server(parv[1])) && (!IsMe(acptr))) + sendcmdto_one(sptr, CMD_DB, acptr, "%s 0 E %s %c", cli_name(acptr), + parv[4], table); + break; + + /* Comprobacion de Hash automatico leaf <=> hub */ + case 'H': + { + char *hash; + unsigned int hash_lo, hash_hi; + + if (IsHub(&me)) + return protocol_violation(cptr, "Don't HASH check to HUBs, table %c from %#C", table, cptr); + + hash = parv[4]; + if (strlen(hash) != 12) + return protocol_violation(cptr, "HASH check, erroneus parameters"); + + hash[6] = '\0'; + hash_lo = base64toint(hash); + hash[6] = parv[4][6]; + hash_hi = base64toint(hash + 6); + + if (!((hash_lo == ddb_hashtable_lo[table]) && (hash_hi == ddb_hashtable_hi[table]))) + { + /* El HASH es incorrecto, a borrar */ + sendto_opmask_butone(0, SNO_OLDSNO, "DB HASH Check failed, droping table %c", table); + log_write(LS_DDB, L_INFO, 0, "DB HASH Check failed, droping table %c", table); + + /* Borramos la tabla en memoria y en disco*/ + ddb_drop(table); + + /* Solicitamos de nuevo la tabla */ + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", cli_name(cptr), + ddb_id_table[table], table); + } + break; + } + + /* Join */ + case 'J': + { + if (id >= ddb_id_table[table]) + { + /* Registros individuales */ + cli_serv(cptr)->ddb_open |= ddb_mask; + break; + } + else if ((cli_serv(cptr)->ddb_open) & ddb_mask) + { + /* Grifo abierto y registros antiguos. + * Ocurre si la copia de cptr de la DDB + * esta corrupta + */ + (cli_serv(cptr)->ddb_open) &= ~ddb_mask; + + /* Borramos su DDB para curarnos en salud */ + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 D DDB_CORRUPT %c", + cli_name(cptr), table); + + break; + } + + /* En el Burst de tabla, se hacen rafagas de 1000 registros, + * se envia una en cada petición de JOIN. La funcion devuelve 1 + * si se han mandado todos los datos en el rafaga y 0 si aún hay + * datos pendientes. + * La comprobacion automatica de HASH solo se debe hacer a los + * leafs, NUNCA a HUBS, ya que si un HUB tiene la DB corrupta, + * toda la red se va a tomar por viento con un borrado masivo. + */ + if (ddb_table_burst(cptr, table, id)) + { + if (IsHub(cptr)) + break; + + inttobase64(ddb_buf, ddb_hashtable_hi[table], 6); + inttobase64(ddb_buf + 6, ddb_hashtable_lo[table], 6); + + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 H %s %c", cli_name(cptr), ddb_buf, table); + } + break; + } + + /* Query de hash para comprobaciones desde un service */ + case 'Q': + { + if (!IsHub(cptr)) + break; + + /* Usamos collapse+match por un bug en lastNNServer del find_match_server() */ + collapse(parv[1]); + /* Solo si es para nosotros si lo ignoramos */ + if (!match(parv[1], cli_name(&me))) + { + if (table == '*') + { + /* HASH de todas las tablas */ + unsigned int hashes_hi = 0; + unsigned int hashes_lo = 0; + unsigned int id_tables = 1; + unsigned int count_tables = 1; + int i; + + for (i = DDB_INIT; i <= DDB_END; i++) + { + hashes_hi ^= ddb_hashtable_hi[i]; + hashes_lo ^= ddb_hashtable_lo[i]; + + id_tables = (id_tables * (ddb_id_table[i] + 1)) & 0xfffffffful; + count_tables = (count_tables * (ddb_count_table[i] + 1)) & 0xfffffffful; + } + inttobase64(ddb_buf, hashes_hi, 6); + inttobase64(ddb_buf + 6, hashes_lo, 6); + + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 R %u-%u-%s-%s %c", + cli_name(cptr), id_tables, count_tables, + ddb_buf, parv[4], table); + } + else + { + /* Una tabla */ + inttobase64(ddb_buf, ddb_hashtable_hi[table], 6); + inttobase64(ddb_buf + 6, ddb_hashtable_lo[table], 6); + + sendcmdto_one(&me, CMD_DB, cptr, "%s 0 R %u-%u-%s-%s %c", + cli_name(cptr), ddb_id_table[table], ddb_count_table[table], + ddb_buf, parv[4], table); + } + } + + /* Enviamos la petición a los demas */ + for (lp = cli_serv(&me)->down; lp; lp = lp->next) + { + if (lp->value.cptr != cptr) + sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%s 0 Q %s %c", + parv[1], parv[4], table); + } + break; + } + + /* Respuesta de hash */ + case 'R': + /* Si no es para nosotros, lo pasamos a otros */ + if ((acptr = find_match_server(parv[1])) && (!IsMe(acptr))) + sendcmdto_one(sptr, CMD_DB, acptr, "%s 0 R %s %c", cli_name(acptr), + parv[4], table); + break; + + /* Registro nuevo, el parv[3] es la tabla */ + default: + { + int delete; + + /* Solo se aceptan registros procedentes de un HUB */ +/* Hablitarlo + if (!IsHub(cptr)) + return 0; +*/ + table = *parv[3]; + if (table < DDB_INIT || table > DDB_END) + { +#if 0 + /* COMPATIBILIDAD IRC-HISPANO */ + if (table == 'N') + table = DDB_NICKDB; +#endif + return 0; + } + + id = atoi(parv[2]); + /* Rechazamos registros con ID inferior al nuestro */ + if (id <= ddb_id_table[table]) + return 0; + + if (parc == 5) + /* Borrado del registro */ + delete = 1; + else if (parc > 5) + /* Insertado del registro */ + delete = 0; + else + /* No deberia ocurrir */ + return protocol_violation(sptr, "DB Incorrect parameters"); + + ddb_mask = ((unsigned int) 1) << (table - DDB_INIT); + /* Propagamos a nuestros servidores hijos */ + for (lp = cli_serv(&me)->down; lp; lp = lp->next) + { + if ((lp->value.cptr != cptr) && + (cli_serv(lp->value.cptr)->ddb_open & ddb_mask)) + { + if (!delete) + sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%s %u %c %s %s :%s", + parv[1], id, table, parv[4], parv[5]); + else + sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%s %u %c %s %s", + parv[1], id, table, parv[4]); + } + } + + if (strcmp(parv[4], "*")) + ddb_new_register(cptr, table, parv[1], id, parv[4], (!delete ? parv[5] : NULL)); +/* + else + ddb_compact(table, parv[1], id, parv[5]); +*/ + + break; + } + } return 0; } - -#endif /* defined(DDB) */ Index: ircd-ircdev/ircd/m_dbq.c diff -u ircd-ircdev/ircd/m_dbq.c:1.2 ircd-ircdev/ircd/m_dbq.c:1.3 --- ircd-ircdev/ircd/m_dbq.c:1.2 Mon Jan 10 04:23:02 2005 +++ ircd-ircdev/ircd/m_dbq.c Wed Mar 23 10:34:51 2005 @@ -18,125 +18,207 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: m_dbq.c,v 1.2 2005/01/10 12:23:02 zolty Exp $ */ - -/* - * m_functions execute protocol messages on this server: - * - * cptr is always NON-NULL, pointing to a *LOCAL* client - * structure (with an open socket connected!). This - * identifies the physical socket where the message - * originated (or which caused the m_function to be - * executed--some m_functions may call others...). - * - * sptr is the source of the message, defined by the - * prefix part of the message if present. If not - * or prefix not found, then sptr==cptr. - * - * (!IsServer(cptr)) => (cptr == sptr), because - * prefixes are taken *only* from servers... - * - * (IsServer(cptr)) - * (sptr == cptr) => the message didn't - * have the prefix. - * - * (sptr != cptr && IsServer(sptr) means - * the prefix specified servername. (?) - * - * (sptr != cptr && !IsServer(sptr) means - * that message originated from a remote - * user (not local). - * - * combining - * - * (!IsServer(sptr)) means that, sptr can safely - * taken as defining the target structure of the - * message in this server. - * - * *Always* true (if 'parse' and others are working correct): - * - * 1) sptr->from == cptr (note: cptr->from == cptr) - * - * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr - * *cannot* be a local connection, unless it's - * actually cptr!). [MyConnect(x) should probably - * be defined as (x == x->from) --msa ] - * - * parc number of variable parameter strings (if zero, - * parv is allowed to be NULL) - * - * parv a NULL terminated list of parameter pointers, - * - * parv[0], sender (prefix string), if not present - * this points to an empty string. - * parv[1]...parv[parc-1] - * pointers to additional parameters - * parv[parc] == NULL, *always* -... [truncated message content] |