[cvslog] (2006-12-02 04:05:22 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Fri Dec 1 22:05:22 CST 2006


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2006-12-02 04:05:21 UTC
Commited by: sven

Modified files:
     lib/eggdrop/botnet.c lib/eggdrop/module.c
     lib/eggdrop/partymember.c modules/oldbotnet/oldbotnet.c
     src/core_party.c

Log message:

 * Added a .unlink partyline command (but it only works on local connections
   right now.
 * Fixed a module loading bug that prevented them from being unloaded again.
 * Added some error checking to module unloading that would have made locating
   the above bug much easier.

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/botnet.c
diff -u eggdrop1.9/lib/eggdrop/botnet.c:1.2 eggdrop1.9/lib/eggdrop/botnet.c:1.3
--- eggdrop1.9/lib/eggdrop/botnet.c:1.2	Mon Nov 20 19:38:41 2006
+++ eggdrop1.9/lib/eggdrop/botnet.c	Fri Dec  1 22:05:11 2006
@@ -28,7 +28,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.2 2006-11-21 01:38:41 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.3 2006-12-02 04:05:11 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -333,10 +333,10 @@
  * \param bot The bot to get rid of.
  * \param reason Some kind of explanation.
  *
- * \return Always 0.
+ * \return 0 on success, -1 if the bot's uplink doesn't have an on_unlink
+ *         handler, -2 if we don't want to unlink.
  *
- * \todo Return something useful or void. Do some kind of check if we really
- *       want the unlink.
+ * \todo Do some kind of check if we really want the unlink.
  */
 
 int botnet_unlink(partymember_t *from, botnet_bot_t *bot, const char *reason)
@@ -344,16 +344,15 @@
 	char obuf[512];
 
 	if (bot->direction != bot) {
-		if (bot->direction->handler && bot->direction->handler->on_unlink) {
-			bot->direction->handler->on_unlink(bot->direction->client_data, from, bot, reason);
-		}
+		if (!bot->direction->handler || !bot->direction->handler->on_unlink) return -1;
+		bot->direction->handler->on_unlink(bot->direction->client_data, from, bot, reason);
 		return 0;
 	}
 
-	if (from->nick) snprintf(obuf, sizeof(obuf), "%s (%s@%s)", reason, from->nick, from->bot ? from->bot->name : botname);
-	else snprintf(obuf, sizeof(obuf), "%s (%s)", reason, from->bot ? from->bot->name : botname);
+	snprintf(obuf, sizeof(obuf), "%s (%s)", reason, from->full_name);
 
 	if (bot->handler && bot->handler->on_lost_bot) bot->handler->on_lost_bot(bot->client_data, bot, obuf);
+	if (from->nick) partymember_msg(from, 0, _("Unlinked from %s."), bot->name);
 	botnet_delete(bot, reason);
 
 	return 0;
Index: eggdrop1.9/lib/eggdrop/module.c
diff -u eggdrop1.9/lib/eggdrop/module.c:1.11 eggdrop1.9/lib/eggdrop/module.c:1.12
--- eggdrop1.9/lib/eggdrop/module.c:1.11	Mon Oct  2 23:02:12 2006
+++ eggdrop1.9/lib/eggdrop/module.c	Fri Dec  1 22:05:11 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: module.c,v 1.11 2006-10-03 04:02:12 sven Exp $";
+static const char rcsid[] = "$Id: module.c,v 1.12 2006-12-02 04:05:11 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -84,6 +84,22 @@
 	return(0);
 }
 
+/*!
+ * \brief Load a module.
+ *
+ * This function loads a module and executes its start function. If the module
+ * name does not contain a path the default paths will be searched. If it does
+ * have an extenteion the plattforms default library extentions will be added.
+ *
+ * \param name The name of the module to load.
+ *
+ * \return 0 on success. (This will be logged.)
+ * \return -1 if the module is already loaded. (Nothing will be logged.)
+ * \return -2 if the module could not be opened. (This will be logged.)
+ * \return -3 if no start function is present. (Nothing will be logged.)
+ * \return -4 if the start function returned an error. (Nothing will be logged.)
+ */
+
 int module_load(const char *name)
 {
 	lt_dlhandle hand;
@@ -118,6 +134,7 @@
 	entry = calloc(1, sizeof(*entry));
 	entry->next = module_list_head;
 	entry->refcount = 0;
+	entry->hand = hand;
 	module_list_head = entry;
 
 	if (startfunc(&entry->modinfo)) {
@@ -132,10 +149,31 @@
 	return(0);
 }
 
+/*!
+ * \brief Unload a module.
+ *
+ * If a module's reference count is 0 its closing function will be executed.
+ * If the closing function did not veto the unloading all of the modules
+ * asyncronous events will be canceled. Finally the module itself is unloaded.
+ *
+ * \param name The name of the module to unload.
+ * \param why The reason this function was called: ::MODULE_USER,
+ *            ::MODULE_RESTART or ::MODULE_SHUTDOWN.
+ *
+ * \return 0 on success. (This will be logged.)
+ * \return -1 if the module is not loaded. (Nothing will be logged.)
+ * \return -2 if the module is in use by another module. (Nothing will be logged.)
+ * \return -3 if the module's closing function vetoed. (Nothing will be logged.)
+ * \return -4 on a ltdl error. (This will be logged.)
+ *
+ * \bug Not all events have owners right now: scripting functions and sockbufs will \b not be unloaded!
+ */
+
 int module_unload(const char *name, int why)
 {
 	module_list_t *entry, *prev;
-	int retval;
+	int retval, errors;
+	const char *error;
 
 	for (entry = module_list_head, prev = NULL; entry; prev = entry, entry = entry->next) {
 		if (!strcasecmp(entry->modinfo.name, name)) break;
@@ -143,12 +181,17 @@
 	if (!entry) return(-1);
 	if (entry->refcount > 0) return(-2);
 	if (entry->modinfo.close_func) {
-		retval = (entry->modinfo.close_func)(why);
+		retval = entry->modinfo.close_func(why);
 		if (retval) return(-3);
 	}
 	script_remove_events_by_owner(&entry->modinfo, 0);
 
-	lt_dlclose(entry->hand);
+	errors = lt_dlclose(entry->hand);
+	if (errors) {
+		putlog(LOG_MISC, "*", "Error unloading %s!", name);
+		while ((error = lt_dlerror())) putlog(LOG_MISC, "*", "ltdlerror: %s", error);
+		return -4;
+	}
 	if (prev) prev->next = entry->next;
 	else module_list_head = entry->next;
 	free(entry);
Index: eggdrop1.9/lib/eggdrop/partymember.c
diff -u eggdrop1.9/lib/eggdrop/partymember.c:1.22 eggdrop1.9/lib/eggdrop/partymember.c:1.23
--- eggdrop1.9/lib/eggdrop/partymember.c:1.22	Tue Nov 14 08:51:23 2006
+++ eggdrop1.9/lib/eggdrop/partymember.c	Fri Dec  1 22:05:11 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partymember.c,v 1.22 2006-11-14 14:51:23 sven Exp $";
+static const char rcsid[] = "$Id: partymember.c,v 1.23 2006-12-02 04:05:11 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -308,7 +308,7 @@
 
 	if (len < 0) len = strlen(text);
 	if (p->handler && p->handler->on_privmsg)
-		(p->handler->on_privmsg)(p->client_data, p, src, text, len);
+		p->handler->on_privmsg(p->client_data, p, src, text, len);
 	return(0);
 }
 
Index: eggdrop1.9/modules/oldbotnet/oldbotnet.c
diff -u eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.13 eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.14
--- eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.13	Tue Nov 14 08:51:24 2006
+++ eggdrop1.9/modules/oldbotnet/oldbotnet.c	Fri Dec  1 22:05:11 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: oldbotnet.c,v 1.13 2006-11-14 14:51:24 sven Exp $";
+static const char rcsid[] = "$Id: oldbotnet.c,v 1.14 2006-12-02 04:05:11 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -289,7 +289,8 @@
 {
 	oldbotnet_t *obot = client_data;
 
-	egg_iprintf(obot->idx, "un %s %s\n", bot->name, reason);
+	if (bot == obot->bot) egg_iprintf(obot->idx, "bye %s", reason);
+	else egg_iprintf(obot->idx, "un %s %s\n", bot->name, reason);
 
 	return 0;
 }
Index: eggdrop1.9/src/core_party.c
diff -u eggdrop1.9/src/core_party.c:1.52 eggdrop1.9/src/core_party.c:1.53
--- eggdrop1.9/src/core_party.c:1.52	Tue Nov 14 08:51:24 2006
+++ eggdrop1.9/src/core_party.c	Fri Dec  1 22:05:11 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: core_party.c,v 1.52 2006-11-14 14:51:24 sven Exp $";
+static const char rcsid[] = "$Id: core_party.c,v 1.53 2006-12-02 04:05:11 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -440,6 +440,29 @@
 	return(0);
 }
 
+static int party_unlink(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
+{
+	char *botname;
+	const char *reason;
+	botnet_bot_t *bot;
+
+	egg_get_arg(text, &reason, &botname);
+	if (!botname || !*botname) {
+		partymember_printf(p, _("Syntax: unlink <handle> [reason]"));
+		free(botname);
+		return 0;
+	}
+
+	bot = botnet_lookup(botname);
+	free(botname);
+	if (!bot) {
+		partymember_printf(p, _("Not connected to that bot."));
+		return 0;
+	}
+	botnet_unlink(p, bot, reason);
+	return 0;
+}
+
 static int party_link(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
 	int error;
@@ -945,6 +968,7 @@
 	{"n", "restart", party_restart},	/* DDD	*/ /* m|- */
 	{"n", "+user", party_plus_user},	/* DDC	*/ /* m|- */
 	{"n", "-user", party_minus_user},	/* DDC	*/ /* m|- */
+	{"n", "unlink", party_unlink},        /* DDD  */ /* t|- */
 	{"n", "link", party_link},        /* DDD  */ /* t|- */
 	{"n", "chattr", party_chattr},		/* DDC	*/ /* m|m */
 	{"n", "modules", party_modules},	/* DDD	*/ /* n|- */
----------------------- End of diff -----------------------



More information about the Changes mailing list