[NeoStats-Devel] [Commits] r2815 - in trunk: . src

[email protected] Wed, 14 Sep 2005 06:06:00 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Mark
Date: Wed Sep 14 04:05:56 2005
New Revision: 2815

Modified:
   trunk/ChangeLog
   trunk/makeconf
   trunk/src/nsevents.c
Log:
fix event code compile and clean up code path

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Wed Sep 14 04:05:56 2005
@@ -4,6 +4,7 @@
 Fish (F), Mark (M), DeadNotBuried (D)
 ===============================================================================
 * NeoStats * Version 3.0.a3-dev
+ - Fix OSX changes which prevent NeoStats running any any platform. (M)
  - Fix a potential security vulnerbility with user supplied strings (F)
  - NeoStats now compiles and runs on Mac OSX (Tiger) (F)
  - Introduce module override to allow a module bot to become the primary source

Modified: trunk/makeconf
==============================================================================
--- trunk/makeconf	(original)
+++ trunk/makeconf	Wed Sep 14 04:05:56 2005
@@ -56,21 +56,21 @@
 
 # If Settings exist, load the info, otherwise tell them to run configure.
 
-if [ -r config.h ]; then
-	echo "Starting configuration.. "
-else if [ -r include/config.h ]; then
-	echo "Starting configuration.. "
-else
-	echo "Configuration failed!"
-	echo "You have not run configure yet!"
-	echo "You probably should read the README file too"
-	echo ""
-	echo "Type ./configure"
-	echo "(If you need help read the README before asking us)"
-	echo ""
-	exit 1
-fi
-fi
+#if [ -r config.h ]; then
+#	echo "Starting configuration.. "
+#else if [ -r include/config.h ]; then
+#	echo "Starting configuration.. "
+#else
+#	echo "Configuration failed!"
+#	echo "You have not run configure yet!"
+#	echo "You probably should read the README file too"
+#	echo ""
+#	echo "Type ./configure"
+#	echo "(If you need help read the README before asking us)"
+#	echo ""
+#	exit 1
+#fi
+#fi
 CONF=$NEOSTATSCONF
 
 if [ -r "$CONF" ]; then

Modified: trunk/src/nsevents.c
==============================================================================
--- trunk/src/nsevents.c	(original)
+++ trunk/src/nsevents.c	Wed Sep 14 04:05:56 2005
@@ -106,6 +106,78 @@
 	"EVENT_COUNT",
 };
 
+/** @brief SendEvent
+ *
+ *	Call event handler
+ *  Event subsystem use only
+ *
+ *  @param event to send
+ *  @param cmdparams
+ *  @param module_ptr pointer to module to raise event for
+ *
+ *  @return none
+ */
+
+static void SendEvent( ModuleEvent *eventptr, Event event, CmdParams *cmdparams, Module *module_ptr )
+{
+	if( !eventptr )
+	{
+		dlog( DEBUG5, "SendModuleEvent: %s has no event handler for %s", module_ptr->info->name, EventStrings[event] );
+		return;
+	}
+	/* If we are not yet synched, check that the module supports 
+	 * the event before we are synched. */
+	if( !IsModuleSynched( module_ptr ) && !( eventptr->flags & EVENT_FLAG_IGNORE_SYNCH ) )
+	{
+		dlog( DEBUG5, "Skipping module %s for %s since module is not yet synched", module_ptr->info->name, EventStrings[event] );
+		return;
+	}
+	if( ( eventptr->flags & EVENT_FLAG_DISABLED ) )
+	{
+		dlog( DEBUG5, "Skipping module %s for %s since it is disabled", module_ptr->info->name, EventStrings[event] );
+		return;
+	}
+	if( ( eventptr->flags & EVENT_FLAG_EXCLUDE_ME ) && IsMe( cmdparams->source ) )
+	{
+		dlog( DEBUG5, "Skipping module %s for %s since %s is excluded as a NeoStats client", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
+		return;
+	}
+	if( eventptr->flags & EVENT_FLAG_EXCLUDE_MODME )
+	{
+		if( cmdparams->source && cmdparams->source->user && cmdparams->source->user->bot && cmdparams->source->user->bot->moduleptr == module_ptr )
+		{
+			dlog( DEBUG5, "Skipping module %s for %s since %s is excluded as a Module client", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
+			return;
+		}
+	}			
+	if( ( eventptr->flags & EVENT_FLAG_USE_EXCLUDE ) && IsExcluded( cmdparams->source ) )
+	{
+		dlog( DEBUG5, "Skipping module %s for %s since %s is excluded", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
+		return;
+	}			
+	dlog( DEBUG1, "Running module %s with %s", module_ptr->info->name, EventStrings[event] );
+	SET_SEGV_LOCATION();
+#ifdef USE_PERL
+	if( ( eventptr->flags & EVENT_FLAG_PERLCALL ) )
+	{
+		SET_RUN_LEVEL( module_ptr );
+		perl_event_cb( event, cmdparams, module_ptr );
+		RESET_RUN_LEVEL();
+		return;
+	}			
+#endif
+	if( setjmp( sigvbuf ) == 0 )
+	{
+		SET_RUN_LEVEL( module_ptr );
+		module_ptr->event_list[event]->handler( cmdparams );
+		RESET_RUN_LEVEL();
+	}
+	else
+	{
+		nlog( LOG_CRITICAL, "SendModuleEvent: setjmp() failed, not calling module %s", module_ptr->info->name );
+	}
+}
+
 /** @brief SendModuleEvent
  *
  *	Call event handler for a specific module
@@ -120,113 +192,15 @@
 
 void SendModuleEvent( Event event, CmdParams *cmdparams, Module *module_ptr )
 {
-	ModuleEvent **evt;
-#ifdef USE_PERL
-	int inperl = 0;
-#endif
 	SET_SEGV_LOCATION();
 	dlog( DEBUG5, "SendModuleEvent: %s to module %s", EventStrings[event], module_ptr->info->name );
 
-	/* if the C event list isn't populated */
-	if( !module_ptr->event_list) {
-#ifdef USE_PERL
-		/* and the Perl event list isn't populated either */
-		if (!(module_ptr->pm && module_ptr->pm->event_list))
-#endif
-		{
-			/* then bail out */
-			dlog( DEBUG5, "SendModuleEvent: module %s has no events associated with it", module_ptr->info->name );
-			return;
-		} else {
-			/* otherwise, we have a perl event, but not a C Event */
-			evt = module_ptr->pm->event_list;
-			inperl = 1;
-		}
-	} else {
-		/* we have a C event, so process this first, and at the bottom, switch to perl events */
-		evt = module_ptr->event_list;
-	}
-	while (1) {
-		if( evt[event] )
-		{
-			/* If we are not yet synched, check that the module supports 
-			* the event before we are synched. */
-			if( !IsModuleSynched( module_ptr ) && !( evt[event]->flags & EVENT_FLAG_IGNORE_SYNCH ) )
-			{
-				dlog( DEBUG5, "Skipping module %s for %s since module is not yet synched", module_ptr->info->name, EventStrings[event] );
-				return;
-			}
-			if( ( evt[event]->flags & EVENT_FLAG_DISABLED ) )
-			{
-				dlog( DEBUG5, "Skipping module %s for %s since it is disabled", module_ptr->info->name, EventStrings[event] );
-				return;
-			}
-			if( ( evt[event]->flags & EVENT_FLAG_EXCLUDE_ME ) && IsMe( cmdparams->source ) )
-			{
-				dlog( DEBUG5, "Skipping module %s for %s since %s is excluded as a NeoStats client", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
-				return;
-			}
-			if( evt[event]->flags & EVENT_FLAG_EXCLUDE_MODME )
-			{
-				if( cmdparams->source && cmdparams->source->user && cmdparams->source->user->bot && cmdparams->source->user->bot->moduleptr == module_ptr )
-				{
-					dlog( DEBUG5, "Skipping module %s for %s since %s is excluded as a Module client", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
-					return;
-				}
-			}			
-			if( ( evt[event]->flags & EVENT_FLAG_USE_EXCLUDE ) && IsExcluded( cmdparams->source ) )
-			{
-				dlog( DEBUG5, "Skipping module %s for %s since %s is excluded", module_ptr->info->name, EventStrings[event], cmdparams->source->name );
-				return;
-			}			
-			dlog( DEBUG1, "Running module %s with %s", module_ptr->info->name, EventStrings[event] );
-			SET_SEGV_LOCATION();
-#ifdef USE_PERL
-			/* is this a C event */
-			if( inperl == 0 )
-#endif
-			{
-				if( setjmp( sigvbuf ) == 0 )
-				{
-					SET_RUN_LEVEL( module_ptr );
-					module_ptr->event_list[event]->handler( cmdparams );
-					RESET_RUN_LEVEL();
-				}
-				else
-				{
-					nlog( LOG_CRITICAL, "SendModuleEvent: setjmp() failed, not calling module %s", module_ptr->info->name );
-				}
-			}
-#if USE_PERL
-			/* no, it must be a perl event */
-			else if( inperl == 1)
-			{
-				SET_RUN_LEVEL( module_ptr );
-				perl_event_cb( event, cmdparams, module_ptr );
-				RESET_RUN_LEVEL();
-			}			
-#endif
-		}
+	if( module_ptr->event_list )
+		SendEvent( module_ptr->event_list[event], event, cmdparams, module_ptr );
 #ifdef USE_PERL
-		if (inperl == 0) {
-			/* if we just ran a C event list then check if the perl has a event list */
-			if (module_ptr->pm && module_ptr->pm->event_list) {
-				/* and if it does, process it */
-				evt = module_ptr->pm->event_list;
-				inperl = 1;
-			} else {
-				/* otherwise return, nothing else to do */
-				return;
-			}
-		} else {
-			/* if we are here, it means perl events have already run */
-			return;
-		}
-#else
-	return;
+	if( ( module_ptr->pm && module_ptr->pm->event_list ) )
+		SendEvent( module_ptr->pm->event_list[event], event, cmdparams, module_ptr );
 #endif
-	}
-	dlog( DEBUG5, "SendModuleEvent: %s has no event handler for %s", module_ptr->info->name, EventStrings[event] );
 }
 
 /** @brief SendAllModuleEventHandler
@@ -244,8 +218,7 @@
 {
 	ModuleAllEvent *mae = (ModuleAllEvent *)v;
 
-	if( module_ptr->event_list || (module_ptr->pm && module_ptr->pm->event_list))
-		SendModuleEvent( mae->event, mae->cmdparams, module_ptr );
+	SendModuleEvent( mae->event, mae->cmdparams, module_ptr );
 	return NS_FALSE;
 }
 
@@ -291,12 +264,18 @@
 		return;
 	}
 	mod_ptr = GET_CUR_MODULE();
-
 	dlog( DEBUG5, "AddEvent: adding %s to %s", EventStrings[eventptr->event], mod_ptr->info->name );
-
-	/* only standard modules have a handler, perl mods use a custom callback */
-	if (!(eventptr->flags & EVENT_FLAG_PERLCALL)) {
-		if(!eventptr->handler )
+#ifdef USE_PERL
+	if( ( eventptr->flags & EVENT_FLAG_PERLCALL ) )
+	{
+		if( ( mod_ptr->pm && !mod_ptr->pm->event_list ) )
+			mod_ptr->pm->event_list = ns_calloc( sizeof( ModuleEvent * ) * EVENT_COUNT );
+		mod_ptr->pm->event_list[eventptr->event] = eventptr;
+	}
+	else
+#endif
+	{
+		if( !eventptr->handler )
 		{
 			nlog( LOG_ERROR, "AddEvent: missing handler for %s in module %s", EventStrings[eventptr->event], mod_ptr->info->name );
 			return;
@@ -304,12 +283,7 @@
 		if( !mod_ptr->event_list )
 			mod_ptr->event_list = ns_calloc( sizeof( ModuleEvent * ) * EVENT_COUNT );
 		mod_ptr->event_list[eventptr->event] = eventptr;
-	} else {
-		if( (mod_ptr->pm && !mod_ptr->pm->event_list) )
-			mod_ptr->pm->event_list = ns_calloc( sizeof( ModuleEvent * ) * EVENT_COUNT );
-		mod_ptr->pm->event_list[eventptr->event] = eventptr;
 	}
-	
 	if( eventptr->event == EVENT_NICKIP )
 		me.want_nickip = 1; 		
 }
@@ -405,9 +379,9 @@
 		mod_ptr->event_list = NULL;
 	}
 #ifdef USE_PERL
-	if ( mod_ptr->pm && mod_ptr->pm->event_list)
+	if( mod_ptr->pm && mod_ptr->pm->event_list )
 	{
-		ns_free(mod_ptr->pm->event_list);
+		ns_free( mod_ptr->pm->event_list );
 		mod_ptr->pm->event_list = NULL;
 	}
 #endif