[NeoStats-Devel] [Commits] r38 - trunk

[email protected] Tue, 9 Aug 2005 16:12:04 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: DNB
Date: Tue Aug  9 14:11:58 2005
New Revision: 38

Modified:
   trunk/ChangeLog
   trunk/events.c
   trunk/seen.c
   trunk/seenserv.c
   trunk/seenserv.h
   trunk/seenserv_help.c
Log:
add option to allow lookups from DB only, using im memory list as cache only until data saved (not tested 100% yet)
update copyright info

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Tue Aug  9 14:11:58 2005
@@ -2,6 +2,7 @@
 Fish (F), Mark (M), DeadNotBuried (D)
 ==============================================================================
 3.0.a3-dev
+ - add option to use DB only or in memory list for lookups (D)
  - save records to db on configurable timer (D)
  - remove records based on age if they are displayed by a request (D)
  - more optimising of limit and expiry checks (D)

Modified: trunk/events.c
==============================================================================
--- trunk/events.c	(original)
+++ trunk/events.c	Tue Aug  9 14:11:58 2005
@@ -1,5 +1,5 @@
 /* SeenServ - Nickname Seen Service - NeoStats Addon Module
-** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, DeadNotBuried
+** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
 **
 **  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

Modified: trunk/seen.c
==============================================================================
--- trunk/seen.c	(original)
+++ trunk/seen.c	Tue Aug  9 14:11:58 2005
@@ -1,5 +1,5 @@
 /* SeenServ - Nickname Seen Service - NeoStats Addon Module
-** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, DeadNotBuried
+** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
 **
 **  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
@@ -33,6 +33,7 @@
 static char currentlyconnectedtext[SS_GENCHARLEN];
 static char seenentrynick[SEEN_ENTRY_NICK_SIZE];
 static char matchednickstr[SS_MESSAGESIZE];
+static char nicklower[MAXNICK];
 
 /** @brief findnick
  *
@@ -102,6 +103,8 @@
 
 /*
  * Save Data to DB on timer
+ * 
+ * remove records from list if set to work from DB only
 */
 int dbsavetimer(void) 
 {
@@ -113,14 +116,29 @@
 	while ( ln )
 	{
 		sd = lnode_get( ln );
+		ln2 = list_prev( seenlist, ln );
 		if (sd->recordsaved == 0)
 		{
 			sd->recordsaved = 1;
-			DBAStore( "seendata", sd->nick,( void * )sd, sizeof( SeenData ) );
-			ln = list_prev( seenlist, ln );
+			strlcpy( nicklower, sd->nick, MAXNICK );
+			DBAStore( "seendata", strlwr(nicklower),( void * )sd, sizeof( SeenData ) );
+			if( !SeenServ.memorylist )
+			{
+				ns_free( sd );
+				list_delete( seenlist, ln );
+				lnode_destroy( ln );
+			}
 		} else {
-			return NS_SUCCESS;
+			if( !SeenServ.memorylist )
+			{
+				ns_free( sd );
+				list_delete( seenlist, ln );
+				lnode_destroy( ln );
+			} else {
+				return NS_SUCCESS;
+			}
 		}		
+		ln = ln2;
 	}
 	return NS_SUCCESS;
 }
@@ -167,9 +185,13 @@
 	return NS_FALSE;
 }
 
-void loadseendata(void)
+void createseenlist(void)
 {
 	seenlist = list_create( -1 );
+}
+
+void loadseendata(void)
+{
 	DBAFetchRows( "seendata", loadseenrecords );
 	list_sort( seenlist, sortlistbytime );
 	return;
@@ -245,6 +267,9 @@
 	Client *u;
 
 	SET_SEGV_LOCATION();
+	/* do lookup on nick only if working from DB and not memory list */
+	if( !SeenServ.memorylist )
+		return sns_cmd_seennick(cmdparams);
 	if( SeenAvailable( cmdparams ) == NS_FALSE )
 		return NS_SUCCESS;
 	/* ensure DB is saved before doing lookup */
@@ -362,43 +387,51 @@
 		else
 			ircsnprintf(matchstr, USERHOSTLEN, "*%s*", cmdparams->av[0]);
 	}
-	ln = list_last(seenlist);
-	while( ln != NULL && seenentriesfound < MAX_NICK_HISTORY ) 
+	if( !SeenServ.memorylist )
 	{
-		sd = lnode_get(ln);
-		if (checktype == SS_CHECK_NICK) 
-		{
-			if( !ircstrcasecmp( cmdparams->av[0], sd->nick ) )
-				matchfound = 1;
-		} 
-		else if (checktype == SS_CHECK_WILDCARD) 
+		sdo = ns_calloc( sizeof( SeenData ) );
+		strlcpy( nicklower, cmdparams->av[0], MAXNICK );
+		if( DBAFetch( "seendata", strlwr(nicklower), ( void * )sdo, sizeof( SeenData ) ) != NS_FAILURE )
+			seenentriesfound = 1;
+	} else {
+		ln = list_last(seenlist);
+		while( ln != NULL && seenentriesfound < MAX_NICK_HISTORY ) 
 		{
-			if( isopersource )
+			sd = lnode_get(ln);
+			if (checktype == SS_CHECK_NICK) 
+			{
+				if( !ircstrcasecmp( cmdparams->av[0], sd->nick ) )
+					matchfound = 1;
+			} 
+			else if (checktype == SS_CHECK_WILDCARD) 
 			{
+				if( isopersource )
+				{
 				if ( match( matchstr, sd->userhost ) )
 					matchfound = 1;
 			}
 			if( match( matchstr, sd->uservhost ) )
 				matchfound = 1;
-		}
-		if (matchfound) 
-		{
-			oln[seenentriesfound] = ln;
-			seenentriesfound++;
-			if( seenentriesfound == 1 ) 
+			}
+			if (matchfound) 
 			{
-				sdo = sd;
-				if (checktype == SS_CHECK_NICK)
-					break;
-				else
-					strlcpy( seenentrynick, sd->nick, SEEN_ENTRY_NICK_SIZE );
-			} else {
-				strlcat( seenentrynick, ", ", SEEN_ENTRY_NICK_SIZE );
-				strlcat( seenentrynick, sd->nick, SEEN_ENTRY_NICK_SIZE );
+				oln[seenentriesfound] = ln;
+				seenentriesfound++;
+				if( seenentriesfound == 1 ) 
+				{
+					sdo = sd;
+					if (checktype == SS_CHECK_NICK)
+						break;
+					else
+						strlcpy( seenentrynick, sd->nick, SEEN_ENTRY_NICK_SIZE );
+				} else {
+					strlcat( seenentrynick, ", ", SEEN_ENTRY_NICK_SIZE );
+					strlcat( seenentrynick, sd->nick, SEEN_ENTRY_NICK_SIZE );
+				}
+				matchfound = 0;
 			}
-			matchfound = 0;
+			ln = list_prev(seenlist, ln);
 		}
-		ln = list_prev(seenlist, ln);
 	}
 	if( seenentriesfound == 0 ) 
 		return NS_FAILURE;
@@ -478,23 +511,28 @@
 		default:
 			break;
 	}
-	/* expire displayed records on age if required */
-	if( SeenServ.expiretime > 0 )
+	if( !SeenServ.memorylist )
 	{
-		maxageallowed = me.now - ( SeenServ.expiretime * TS_ONE_DAY );
-		i = 0;
-		while( i < MAX_NICK_HISTORY && oln[i] != NULL )
+		ns_free( sdo );
+	} else {
+		/* expire displayed records on age if required */
+		if( SeenServ.expiretime > 0 )
 		{
-			ln = oln[i];
-			sd = lnode_get( ln );
-			if( maxageallowed > sd->seentime )
+			maxageallowed = me.now - ( SeenServ.expiretime * TS_ONE_DAY );
+			i = 0;
+			while( i < MAX_NICK_HISTORY && oln[i] != NULL )
 			{
-				DBADelete( "seendata", sd->nick );
-				ns_free( sd );
-				list_delete( seenlist, ln );
-				lnode_destroy( ln );
+				ln = oln[i];
+				sd = lnode_get( ln );
+				if( maxageallowed > sd->seentime )
+				{
+					DBADelete( "seendata", sd->nick );
+					ns_free( sd );
+					list_delete( seenlist, ln );
+					lnode_destroy( ln );
+				}
+				i++;
 			}
-			i++;
 		}
 	}
 	return NS_SUCCESS;
@@ -542,6 +580,11 @@
 	SeenData *sd;
 
 	SET_SEGV_LOCATION();
+	if( !SeenServ.memorylist )
+	{
+		seen_report( cmdparams, "Seen Statistics Unavailable when using DB only" );
+		return NS_SUCCESS;
+	}
 	os_memset( seenstats, 0, sizeof( seenstats ) );
 	ln = list_first(seenlist);
 	while (ln) 

Modified: trunk/seenserv.c
==============================================================================
--- trunk/seenserv.c	(original)
+++ trunk/seenserv.c	Tue Aug  9 14:11:58 2005
@@ -1,5 +1,5 @@
 /* SeenServ - Nickname Seen Service - NeoStats Addon Module
-** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, DeadNotBuried
+** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
 **
 **  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
@@ -37,6 +37,7 @@
 static int sns_set_eventkick( CmdParams *cmdparams, SET_REASON reason );
 static int sns_set_expiretime (CmdParams *cmdparams, SET_REASON reason);
 static int sns_set_dbupdatetime (CmdParams *cmdparams, SET_REASON reason);
+static int sns_set_memorylist (CmdParams *cmdparams, SET_REASON reason);
 
 /** Copyright info */
 const char *sns_copyright[] = {
@@ -79,6 +80,7 @@
 	{"EVENTKICK",		&SeenServ.eventkick,		SET_TYPE_BOOLEAN,	0,	0,		NS_ULEVEL_ADMIN,	NULL,	sns_help_set_eventkick,		sns_set_eventkick,	(void *)1 },
 	{"EXPIRETIME",		&SeenServ.expiretime,		SET_TYPE_INT,		0,	1000,		NS_ULEVEL_ADMIN,	NULL,	sns_help_set_expiretime,	sns_set_expiretime,	(void *)0 },
 	{"DBUPDATETIME",	&SeenServ.dbupdatetime,		SET_TYPE_INT,		1,	900,		NS_ULEVEL_ADMIN,	NULL,	sns_help_set_dbupdatetime,	sns_set_dbupdatetime,	(void *)300 },
+	{"MEMORYLIST",		&SeenServ.memorylist,		SET_TYPE_BOOLEAN,	0,	0,		NS_ULEVEL_ADMIN,	NULL,	sns_help_set_memorylist,	sns_set_memorylist,	(void *)1 },
 	{NULL,			NULL,				0,			0,	0,		0,			NULL,	NULL,				NULL, 			NULL },
 };
 
@@ -155,6 +157,7 @@
 int ModInit( void )
 {
 	ModuleConfig (sns_settings);
+	createseenlist();
 	loadseendata();
 	return NS_SUCCESS;
 }
@@ -360,6 +363,38 @@
 }
 
 /*
+ * Check Meory List is actually changing, and perform actions as needed
+*/
+static int sns_set_memorylist (CmdParams *cmdparams, SET_REASON reason) 
+{
+	if (reason == SET_VALIDATE)
+	{
+		if( SeenServ.memorylist && !ircstrcasecmp( cmdparams->av[1], "ON" ) )
+		{
+			irc_prefmsg (sns_bot, cmdparams->source, "ERROR: MEMORYLIST is already set ON");
+			return NS_FAILURE;
+		}
+		if( !SeenServ.memorylist && !ircstrcasecmp( cmdparams->av[1], "OFF" ) )
+		{
+			irc_prefmsg (sns_bot, cmdparams->source, "ERROR: MEMORYLIST is already set OFF");
+			return NS_FAILURE;
+		}
+	}
+	if (reason == SET_CHANGE) 
+	{
+		if( SeenServ.memorylist )
+		{
+			loadseendata();
+			checkseenlistlimit(SS_LISTLIMIT_COUNT);
+			checkseenlistlimit(SS_LISTLIMIT_AGE);
+		} else {
+			dbsavetimer();
+		}
+	}
+	return NS_SUCCESS;
+}
+
+/*
  * Remove Aged Records if required
 */
 int removeagedseenrecords(void) 

Modified: trunk/seenserv.h
==============================================================================
--- trunk/seenserv.h	(original)
+++ trunk/seenserv.h	Tue Aug  9 14:11:58 2005
@@ -1,5 +1,5 @@
 /* SeenServ - Nickname Seen Service - NeoStats Addon Module
-** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, DeadNotBuried
+** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
 **
 **  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
@@ -68,6 +68,7 @@
 	int eventkick;
 	int expiretime;
 	int dbupdatetime;
+	int memorylist;
 } SeenServ;
 
 typedef struct SeenData {
@@ -95,6 +96,7 @@
 extern const char *sns_help_set_eventkick[];
 extern const char *sns_help_set_expiretime[];
 extern const char *sns_help_set_dbupdatetime[];
+extern const char *sns_help_set_memorylist[];
 extern const char *sns_help_seen[];
 extern const char *sns_help_seennick[];
 extern const char *sns_help_del[];
@@ -117,6 +119,7 @@
 void addseenentry(char *nick, char *host, char *vhost, char *message, int type);
 int dbsavetimer(void);
 void checkseenlistlimit(int checktype);
+void createseenlist(void);
 void loadseendata(void);
 int sortlistbytime(const void *key1, const void *key2);
 void destroyseenlist(void);

Modified: trunk/seenserv_help.c
==============================================================================
--- trunk/seenserv_help.c	(original)
+++ trunk/seenserv_help.c	Tue Aug  9 14:11:58 2005
@@ -1,5 +1,5 @@
 /* SeenServ - Nickname Seen Service - NeoStats Addon Module
-** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, DeadNotBuried
+** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
 **
 **  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
@@ -115,11 +115,21 @@
 	NULL
 };
 
+const char *sns_help_set_memorylist[] = {
+	"\2MEMORYLIST <ON|OFF>\2",
+	"Sets if the seen data should be queried from an",
+	"In Memory List, if set to OFF queries will be from",
+	"the DB only, and lookups will only be able to be",
+	"made via the nickname and not the userhost",
+	NULL
+};
+
 const char *sns_help_seen[] = {
 	"Displays Last Seen Nicks",
-	"Syntax: \2SEEN <host>\2",
+	"Syntax: \2SEEN <nick|userhost>\2",
 	"",
 	"Displays the last seen entry of the matching entry.",
+	"NOTE: If queries are from the DB only, then only <nick> is a valid entry.",
 	NULL
 };
 
@@ -144,5 +154,6 @@
 	"Syntax: \2STATUS\2",
 	"",
 	"Displays seenserv status information and statistics.",
+	"NOTE: Statistics Unavailable when using DB only.",
 	NULL
 };