[cvslog] (2006-09-12 01:51:01 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Mon Sep 11 19:51:03 CST 2006


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2006-09-12 01:51:01 UTC
Commited by: sven

Modified files:
     lib/eggdrop/dns.c lib/eggdrop/dns.h lib/eggdrop/net.c
     lib/eggdrop/script.c lib/eggdrop/script.h
     modules/dccparty/dccparty.c modules/ircparty/ircparty.c
     modules/script/scriptdns.c modules/server/dcc.c
     modules/server/egg_server_internal.h
     modules/telnetparty/telnetparty.c

Log message:

Attached an owner to dns queries. A module should now be able to kill all
pending queries on unload.
Moved parts of the scriptdns stuff from the module to the core because an
event can only have one owner (the scripting language module) not two (the
language module and the script module).

Now this thing is kinda ugly but it's the best I could come up with. :/

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/dns.c
diff -u eggdrop1.9/lib/eggdrop/dns.c:1.17 eggdrop1.9/lib/eggdrop/dns.c:1.18
--- eggdrop1.9/lib/eggdrop/dns.c:1.17	Fri Aug 25 12:22:50 2006
+++ eggdrop1.9/lib/eggdrop/dns.c	Mon Sep 11 20:50:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dns.c,v 1.17 2006-08-25 17:22:50 sven Exp $";
+static const char rcsid[] = "$Id: dns.c,v 1.18 2006-09-12 01:50:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -45,6 +45,7 @@
 	dns_answer_t answer;
 	dns_callback_t callback;
 	void *client_data;
+	event_owner_t *owner;
 } dns_query_t;
 
 typedef struct {
@@ -169,7 +170,7 @@
 /* Perform an async dns lookup. This is host -> ip. For ip -> host, use
  * egg_dns_reverse(). We return a dns id that you can use to cancel the
  * lookup. */
-int egg_dns_lookup(const char *host, int timeout, dns_callback_t callback, void *client_data)
+int egg_dns_lookup(const char *host, int timeout, dns_callback_t callback, void *client_data, event_owner_t *owner)
 {
 	char buf[512];
 	dns_query_t *q;
@@ -183,6 +184,7 @@
 		answer_add(&answer, host);
 		callback(client_data, host, answer.list);
 		answer_free(&answer);
+		if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 		return(-1);
 	}
 	
@@ -191,6 +193,7 @@
 	if (cache_id >= 0) {
 		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
 		callback(client_data, host, cache[cache_id].answer.list);
+		if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 		return(-1);
 	}
 
@@ -203,6 +206,7 @@
 			answer_add(&answer, hosts[i].ip);
 			callback(client_data, host, answer.list);
 			answer_free(&answer);
+			if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 			return(-1);
 		}
 	}
@@ -214,6 +218,7 @@
 	q->query = strdup(host);
 	q->callback = callback;
 	q->client_data = client_data;
+	q->owner = owner;
 	q->next = query_head;
 	query_head = q;
 
@@ -243,7 +248,7 @@
 /* Perform an async dns reverse lookup. This does ip -> host. For host -> ip
  * use egg_dns_lookup(). We return a dns id that you can use to cancel the
  * lookup. */
-int egg_dns_reverse(const char *ip, int timeout, dns_callback_t callback, void *client_data)
+int egg_dns_reverse(const char *ip, int timeout, dns_callback_t callback, void *client_data, event_owner_t *owner)
 {
 	dns_query_t *q;
 	char buf[512], *reversed_ip;
@@ -252,6 +257,7 @@
 	if (!socket_valid_ip(ip)) {
 		/* If it's not a valid ip, don't even make the request. */
 		callback(client_data, ip, NULL);
+		if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 		return(-1);
 	}
 
@@ -264,6 +270,7 @@
 			answer_add(&answer, hosts[i].host);
 			callback(client_data, ip, answer.list);
 			answer_free(&answer);
+			if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 			return(-1);
 		}
 	}
@@ -273,6 +280,7 @@
 	if (cache_id >= 0) {
 		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
 		callback(client_data, ip, cache[cache_id].answer.list);
+		if (owner && owner->on_delete) owner->on_delete(owner, client_data);
 		return(-1);
 	}
 
@@ -305,6 +313,7 @@
 	q->query = strdup(ip);
 	q->callback = callback;
 	q->client_data = client_data;
+	q->owner = owner;
 	q->next = query_head;
 	query_head = q;
 
@@ -559,6 +568,7 @@
 	else query_head = q->next;
 
 	if (issue_callback) q->callback(q->client_data, q->query, NULL);
+	if (q->owner && q->owner->on_delete) q->owner->on_delete(q->owner, q->client_data);
 	free(q);
 	return(0);
 }
@@ -680,6 +690,7 @@
 	cache_add(q->query, &q->answer);
 
 	q->callback(q->client_data, q->query, q->answer.list);
+	if (q->owner && q->owner->on_delete) q->owner->on_delete(q->owner, q->client_data);
 	answer_free(&q->answer);
 	free(q->query);
 	free(q);
Index: eggdrop1.9/lib/eggdrop/dns.h
diff -u eggdrop1.9/lib/eggdrop/dns.h:1.2 eggdrop1.9/lib/eggdrop/dns.h:1.3
--- eggdrop1.9/lib/eggdrop/dns.h:1.2	Tue Jun 22 13:47:27 2004
+++ eggdrop1.9/lib/eggdrop/dns.h	Mon Sep 11 20:50:50 2006
@@ -16,7 +16,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: dns.h,v 1.2 2004-06-22 18:47:27 wingman Exp $
+ * $Id: dns.h,v 1.3 2006-09-12 01:50:50 sven Exp $
  */
 
 #ifndef _EGG_DNS_H_
@@ -34,8 +34,8 @@
 int egg_dns_shutdown(void);
 
 void egg_dns_send(char *query, int len);
-int egg_dns_lookup(const char *host, int timeout, dns_callback_t callback, void *client_data);
-int egg_dns_reverse(const char *ip, int timeout, dns_callback_t callback, void *client_data);
+int egg_dns_lookup(const char *host, int timeout, dns_callback_t callback, void *client_data, event_owner_t *owner);
+int egg_dns_reverse(const char *ip, int timeout, dns_callback_t callback, void *client_data, event_owner_t *owner);
 int egg_dns_cancel(int id, int issue_callback);
 
 #endif /* !_EGG_DNS_H_ */
Index: eggdrop1.9/lib/eggdrop/net.c
diff -u eggdrop1.9/lib/eggdrop/net.c:1.6 eggdrop1.9/lib/eggdrop/net.c:1.7
--- eggdrop1.9/lib/eggdrop/net.c:1.6	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/lib/eggdrop/net.c	Mon Sep 11 20:50:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: net.c,v 1.6 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: net.c,v 1.7 2006-09-12 01:50:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -112,7 +112,7 @@
 
 	/* Resolve the hostname. */
 	connect_info = attach(idx, host, port, timeout);
-	connect_info->dns_id = egg_dns_lookup(host, -1, connect_host_resolved, connect_info);
+	connect_info->dns_id = egg_dns_lookup(host, -1, connect_host_resolved, connect_info, NULL);
 	return(idx);
 }
 
Index: eggdrop1.9/lib/eggdrop/script.c
diff -u eggdrop1.9/lib/eggdrop/script.c:1.22 eggdrop1.9/lib/eggdrop/script.c:1.23
--- eggdrop1.9/lib/eggdrop/script.c:1.22	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/lib/eggdrop/script.c	Mon Sep 11 20:50:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: script.c,v 1.22 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: script.c,v 1.23 2006-09-12 01:50:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -32,6 +32,13 @@
 	void *key;
 } journal_event_t;
 
+typedef struct {
+	script_callback_t *callback;
+	int id;
+	char *text;
+	int len;
+} script_dns_callback_data_t;
+
 static journal_event_t *journal_events = NULL;
 static int njournal_events = 0;
 
@@ -521,3 +528,59 @@
 	list->len++;
 	return(0);
 }
+
+static int script_dns_delete(struct event_owner_b *event, void *client_data)
+{
+	script_dns_callback_data_t *data = client_data;
+
+	if (data->callback->owner && data->callback->owner->on_delete) data->callback->owner->on_delete(data->callback->owner, data->callback);
+	if (data->text) free(data->text);
+	free(data);
+
+	free(event);
+
+	return 51896; /* Why do these callbacks have to return something? */
+}
+
+static int script_dns_callback(void *client_data, const char *query, char **result)
+{
+	byte_array_t bytes;
+	script_dns_callback_data_t *data = client_data;
+
+	bytes.bytes = data->text;
+	bytes.len = data->len;
+	bytes.do_free = 0;
+
+	if (!bytes.bytes) bytes.bytes = "";
+	if (bytes.len <= 0) bytes.len = strlen(bytes.bytes);
+
+	data->callback->callback(data->callback, data->id, query, result, &bytes);
+
+	return 0; /* what exactly should this function return? the return value is always ignored */
+}
+
+int script_dns_query(dns_function_t *function, const char *host, script_callback_t *callback, char *text, int len)
+{
+	int id;
+	event_owner_t *event;
+	script_dns_callback_data_t *data;
+
+	event = malloc(sizeof(*event));
+	memcpy(event, callback->owner, sizeof(*event));
+	event->on_delete = script_dns_delete;
+
+	callback->syntax = strdup("isSb");
+	data = malloc(sizeof(*data));
+	data->callback = callback;
+	data->id = -1;
+	data->text = text;
+	data->len = len;
+	id = function(host, -1, script_dns_callback, data, event);
+	if (id == -1) {
+		/* the query was cached, the callback has already been called and data has been freed */
+		return -1;
+	}
+	data->id = id;
+	return id;
+}
+
Index: eggdrop1.9/lib/eggdrop/script.h
diff -u eggdrop1.9/lib/eggdrop/script.h:1.17 eggdrop1.9/lib/eggdrop/script.h:1.18
--- eggdrop1.9/lib/eggdrop/script.h:1.17	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/lib/eggdrop/script.h	Mon Sep 11 20:50:50 2006
@@ -16,7 +16,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: script.h,v 1.17 2005-12-28 17:27:31 sven Exp $
+ * $Id: script.h,v 1.18 2006-09-12 01:50:50 sven Exp $
  */
 
 #ifndef _EGG_SCRIPT_H_
@@ -205,10 +205,13 @@
 	int (*get_arg)(void *client_data, script_args_t *args, int num, script_var_t *var, int type);
 } script_module_t;
 
+typedef int dns_function_t(const char *query, int timeout, dns_callback_t callback, void *data, event_owner_t *event);
+
 extern int script_register_module(script_module_t *module);
 extern int script_unregister_module(script_module_t *module);
 extern int script_playback(script_module_t *module);
 extern int script_linked_var_on_write(script_linked_var_t *var, script_var_t *newval);
+extern int script_dns_query(dns_function_t *function, const char *host, script_callback_t *callback, char *text, int len);
 
 END_C_DECLS
 
Index: eggdrop1.9/modules/dccparty/dccparty.c
diff -u eggdrop1.9/modules/dccparty/dccparty.c:1.11 eggdrop1.9/modules/dccparty/dccparty.c:1.12
--- eggdrop1.9/modules/dccparty/dccparty.c:1.11	Thu Dec  1 11:43:47 2005
+++ eggdrop1.9/modules/dccparty/dccparty.c	Mon Sep 11 20:50:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dccparty.c,v 1.11 2005-12-01 17:43:47 stdarg Exp $";
+static const char rcsid[] = "$Id: dccparty.c,v 1.12 2006-09-12 01:50:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -36,6 +36,12 @@
 	{0}
 };
 
+static event_owner_t dcc_owner = {
+	"dccparty", 0,
+	0, 0,
+	0
+};
+
 EXPORT_SCOPE int dccparty_LTX_start(egg_module_t *modinfo);
 static int dccparty_close(int why);
 
@@ -115,7 +121,7 @@
 
 	/* Start lookups. */
 	session->ident_id = egg_ident_lookup(peer_ip, peer_port, our_port, -1, ident_result, session);
-	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session);
+	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session, &dcc_owner);
 
 	return(0);
 }
@@ -247,6 +253,8 @@
 {
 	void *config_root;
 
+	dcc_owner.module = modinfo;
+
 	modinfo->name = "dccparty";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/modules/ircparty/ircparty.c
diff -u eggdrop1.9/modules/ircparty/ircparty.c:1.14 eggdrop1.9/modules/ircparty/ircparty.c:1.15
--- eggdrop1.9/modules/ircparty/ircparty.c:1.14	Sun Nov 13 22:44:43 2005
+++ eggdrop1.9/modules/ircparty/ircparty.c	Mon Sep 11 20:50:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ircparty.c,v 1.14 2005-11-14 04:44:43 wcc Exp $";
+static const char rcsid[] = "$Id: ircparty.c,v 1.15 2006-09-12 01:50:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -34,6 +34,12 @@
 	{0}
 };
 
+static event_owner_t irc_owner = {
+	"ircparty", 0,
+	0, 0,
+	0
+};
+
 EXPORT_SCOPE int ircparty_LTX_start(egg_module_t *modinfo);
 static int ircparty_close(int why);
 
@@ -133,7 +139,7 @@
 
 	/* Start lookups. */
 	session->ident_id = egg_ident_lookup(peer_ip, peer_port, irc_port, -1, ident_result, session);
-	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session);
+	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session, &irc_owner);
 
 	return(0);
 }
@@ -350,6 +356,8 @@
 {
 	void *config_root;
 
+	irc_owner.module = modinfo;
+
 	modinfo->name = "ircparty";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/modules/script/scriptdns.c
diff -u eggdrop1.9/modules/script/scriptdns.c:1.1 eggdrop1.9/modules/script/scriptdns.c:1.2
--- eggdrop1.9/modules/script/scriptdns.c:1.1	Fri Aug 25 12:22:50 2006
+++ eggdrop1.9/modules/script/scriptdns.c	Mon Sep 11 20:50:51 2006
@@ -18,92 +18,25 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scriptdns.c,v 1.1 2006-08-25 17:22:50 sven Exp $";
+static const char rcsid[] = "$Id: scriptdns.c,v 1.2 2006-09-12 01:50:51 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
 #include "egg_script_internal.h"
 
-typedef struct {
-	script_callback_t *callback;
-	int id;
-	char *text;
-	int len;
-} script_dns_callback_data_t;
-
-static int do_callback = 1;
-static char *empty_string = "";
-
-static int script_dns_callback(void *client_data, const char *query, char **result)
-{
-	byte_array_t bytes;
-	script_dns_callback_data_t *data = client_data;
-
-	bytes.bytes = data->text;
-	bytes.len = data->len;
-	bytes.do_free = 0;
-
-	if (!bytes.bytes) bytes.bytes = empty_string;
-	if (bytes.len <= 0) bytes.len = strlen(bytes.bytes);
-
-	if (do_callback) data->callback->callback(data->callback, data->id, query, result, &bytes);
-
-	if (data->text) free(data->text);
-	free(data);
-
-	return 0; /* what exactly should this function return? the return value is always ignored */
-}
-
 static int script_dns_lookup(const char *host, script_callback_t *callback, char *text, int len)
 {
-	int id;
-	script_dns_callback_data_t *data;
-
-	callback->syntax = strdup("isSb");
-	data = malloc(sizeof(*data));
-	data->callback = callback;
-	data->id = -1;
-	data->text = text;
-	data->len = len;
-	id = egg_dns_lookup(host, -1, script_dns_callback, data);
-	if (id == -1) {
-		/* the query was cached, the callback has already been called and data has been freed */
-		return -1;
-	}
-	data->id = id;
-	return id;
+	return script_dns_query(egg_dns_lookup, host, callback, text, len);
 }
 
 static int script_dns_reverse(const char *ip, script_callback_t *callback, char *text, int len)
 {
-	int id;
-	script_dns_callback_data_t *data;
-
-	callback->syntax = strdup("isSb");
-	data = malloc(sizeof(*data));
-	data->callback = callback;
-	data->id = -1;
-	data->text = text;
-	data->len = len;
-	id = egg_dns_reverse(ip, -1, script_dns_callback, data);
-	if (id == -1) {
-		/* the query was cached, the callback has already been called and data has been freed */
-		return -1;
-	}
-	data->id = id;
-	return id;
-}
-
-static int script_dns_cancel(int id, int callback)
-{
-	do_callback = callback;
-	egg_dns_cancel(id, 1);
-	do_callback = 1;
+	return script_dns_query(egg_dns_reverse, ip, callback, text, len);
 }
 
 script_command_t script_dns_cmds[] = {
 	{"", "dns_lookup", script_dns_lookup, NULL, 2, "scsi", "host callback ?callbackdata? ?len?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
 	{"", "dns_reverse", script_dns_reverse, NULL, 2, "scsi", "ip  callback ?callbackdata? ?len?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
-	{"", "dns_cancel", script_dns_cancel, NULL, 1, "ii", "id ?docallback?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
+	{"", "dns_cancel", egg_dns_cancel, NULL, 1, "ii", "id ?docallback?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},	/* DDD */
 	{0}
 };
Index: eggdrop1.9/modules/server/dcc.c
diff -u eggdrop1.9/modules/server/dcc.c:1.25 eggdrop1.9/modules/server/dcc.c:1.26
--- eggdrop1.9/modules/server/dcc.c:1.25	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/modules/server/dcc.c	Mon Sep 11 20:50:51 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dcc.c,v 1.25 2005-12-28 17:27:31 sven Exp $";
+static const char rcsid[] = "$Id: dcc.c,v 1.26 2006-09-12 01:50:51 sven Exp $";
 #endif
 
 #include <unistd.h>
@@ -118,7 +118,7 @@
 
 int dcc_dns_set(const char *host)
 {
-	egg_dns_lookup(host, 0, dcc_dns_callback, NULL);
+	egg_dns_lookup(host, 0, dcc_dns_callback, NULL, &server_owner);
 	return(0);
 }
 
Index: eggdrop1.9/modules/server/egg_server_internal.h
diff -u eggdrop1.9/modules/server/egg_server_internal.h:1.10 eggdrop1.9/modules/server/egg_server_internal.h:1.11
--- eggdrop1.9/modules/server/egg_server_internal.h:1.10	Thu Dec  1 15:22:11 2005
+++ eggdrop1.9/modules/server/egg_server_internal.h	Mon Sep 11 20:50:51 2006
@@ -96,6 +96,7 @@
 #define server_list server_LTX_server_list
 #define server_list_index server_LTX_server_list_index
 #define server_list_len server_LTX_server_list_len
+#define server_owner server_LTX_server_owner
 #define server_parse_input server_LTX_server_parse_input
 #define server_party_commands server_LTX_server_party_commands
 #define server_raw_binds server_LTX_server_raw_binds
Index: eggdrop1.9/modules/telnetparty/telnetparty.c
diff -u eggdrop1.9/modules/telnetparty/telnetparty.c:1.20 eggdrop1.9/modules/telnetparty/telnetparty.c:1.21
--- eggdrop1.9/modules/telnetparty/telnetparty.c:1.20	Sun Nov 13 22:44:43 2005
+++ eggdrop1.9/modules/telnetparty/telnetparty.c	Mon Sep 11 20:50:51 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: telnetparty.c,v 1.20 2005-11-14 04:44:43 wcc Exp $";
+static const char rcsid[] = "$Id: telnetparty.c,v 1.21 2006-09-12 01:50:51 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -35,6 +35,12 @@
 	{0}
 };
 
+static event_owner_t telnet_owner = {
+	"telnetparty", 0,
+	0, 0,
+	0
+};
+
 EXPORT_SCOPE int telnetparty_LTX_start(egg_module_t *modinfo);
 static int telnetparty_close(int why);
 
@@ -314,7 +320,7 @@
 
 	/* Start lookups. */
 	session->ident_id = egg_ident_lookup(peer_ip, peer_port, telnet_port, -1, ident_result, session);
-	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session);
+	session->dns_id = egg_dns_reverse(peer_ip, -1, dns_result, session, &telnet_owner);
 
 	return(0);
 }
@@ -616,6 +622,7 @@
 {
 	void *config_root;
 
+	telnet_owner.module = modinfo;
 	modinfo->name = "telnetparty";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
----------------------- End of diff -----------------------



More information about the Changes mailing list