[cvslog] (2006-08-25 17:23:01 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Fri Aug 25 11:23:01 CST 2006


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2006-08-25 17:23:01 UTC
Commited by: sven

Modified files:
     lib/eggdrop/dns.c lib/eggdrop/socket.c modules/script/Makefile.am
     modules/script/egg_script_internal.h modules/script/scriptmod.c

Added files:
     modules/script/scriptdns.c

Log message:

 * fixed a bug with IPv6 reverse lookups
 * added dns lookup functions to the scripting interface   

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/dns.c
diff -u eggdrop1.9/lib/eggdrop/dns.c:1.16 eggdrop1.9/lib/eggdrop/dns.c:1.17
--- eggdrop1.9/lib/eggdrop/dns.c:1.16	Mon Jun 19 10:47:33 2006
+++ eggdrop1.9/lib/eggdrop/dns.c	Fri Aug 25 12:22:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dns.c,v 1.16 2006-06-19 15:47:33 stdarg Exp $";
+static const char rcsid[] = "$Id: dns.c,v 1.17 2006-08-25 17:22:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -190,8 +190,8 @@
 	cache_id = cache_find(host);
 	if (cache_id >= 0) {
 		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
-	        callback(client_data, host, cache[cache_id].answer.list);
-	        return(-1);
+		callback(client_data, host, cache[cache_id].answer.list);
+		return(-1);
 	}
 
 	/* Ok, now see if it's in our host cache. */
@@ -272,19 +272,19 @@
 	cache_id = cache_find(ip);
 	if (cache_id >= 0) {
 		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
-        	callback(client_data, ip, cache[cache_id].answer.list);
-	        return(-1);
+		callback(client_data, ip, cache[cache_id].answer.list);
+		return(-1);
 	}
 
 	/* We need to transform the ip address into the proper form
 	 * for reverse lookup. */
 	if (strchr(ip, ':')) {
-		char temp[65];
+		char temp[64];
 
 		socket_ipv6_to_dots(ip, temp);
 		reversed_ip = malloc(strlen(temp) + 10);
 		reverse_ip(temp, reversed_ip);
-		strcat(reversed_ip, ".in6.arpa");
+		strcat(reversed_ip, ".ip6.arpa");
 	}
 	else {
 		reversed_ip = malloc(strlen(ip) + 14);
Index: eggdrop1.9/lib/eggdrop/socket.c
diff -u eggdrop1.9/lib/eggdrop/socket.c:1.12 eggdrop1.9/lib/eggdrop/socket.c:1.13
--- eggdrop1.9/lib/eggdrop/socket.c:1.12	Sun May 21 14:32:19 2006
+++ eggdrop1.9/lib/eggdrop/socket.c	Fri Aug 25 12:22:50 2006
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: socket.c,v 1.12 2006-05-21 19:32:19 stdarg Exp $";
+static const char rcsid[] = "$Id: socket.c,v 1.13 2006-08-25 17:22:50 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -311,7 +311,7 @@
 }
 
 /* Converts shorthand ipv6 notation (123:456::789) into long dotted-decimal
- * notation. 'dots' must be 16*4+1 = 65 bytes long. */
+ * notation. 'dots' must be 32*2 = 64 bytes long. */
 int socket_ipv6_to_dots(const char *ip, char *dots)
 {
 #ifndef DO_IPV6
@@ -322,15 +322,23 @@
 
 	dots[0] = 0;
 	if (inet_pton(AF_INET6, ip, &buf) <= 0) return(-1);
-	sprintf(dots, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u",
-		buf.s6_addr[0], buf.s6_addr[1],
-		buf.s6_addr[2], buf.s6_addr[3],
-		buf.s6_addr[4], buf.s6_addr[5],
-		buf.s6_addr[6], buf.s6_addr[7],
-		buf.s6_addr[8], buf.s6_addr[9],
-		buf.s6_addr[10], buf.s6_addr[11],
-		buf.s6_addr[12], buf.s6_addr[13],
-		buf.s6_addr[14], buf.s6_addr[15]
+	sprintf(dots, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x",
+		buf.s6_addr[0] >> 4, buf.s6_addr[0] & 0xf,
+		buf.s6_addr[1] >> 4, buf.s6_addr[1] & 0xf,
+		buf.s6_addr[2] >> 4, buf.s6_addr[2] & 0xf,
+		buf.s6_addr[3] >> 4, buf.s6_addr[3] & 0xf,
+		buf.s6_addr[4] >> 4, buf.s6_addr[4] & 0xf,
+		buf.s6_addr[5] >> 4, buf.s6_addr[5] & 0xf,
+		buf.s6_addr[6] >> 4, buf.s6_addr[6] & 0xf,
+		buf.s6_addr[7] >> 4, buf.s6_addr[7] & 0xf,
+		buf.s6_addr[8] >> 4, buf.s6_addr[8] & 0xf,
+		buf.s6_addr[9] >> 4, buf.s6_addr[9] & 0xf,
+		buf.s6_addr[10] >> 4, buf.s6_addr[10] & 0xf,
+		buf.s6_addr[11] >> 4, buf.s6_addr[11] & 0xf,
+		buf.s6_addr[12] >> 4, buf.s6_addr[12] & 0xf,
+		buf.s6_addr[13] >> 4, buf.s6_addr[13] & 0xf,
+		buf.s6_addr[14] >> 4, buf.s6_addr[14] & 0xf,
+		buf.s6_addr[15] >> 4, buf.s6_addr[15] & 0xf
 	);
 	return(0);
 #endif
Index: eggdrop1.9/modules/script/Makefile.am
diff -u eggdrop1.9/modules/script/Makefile.am:1.6 eggdrop1.9/modules/script/Makefile.am:1.7
--- eggdrop1.9/modules/script/Makefile.am:1.6	Thu Jun 17 08:32:44 2004
+++ eggdrop1.9/modules/script/Makefile.am	Fri Aug 25 12:22:50 2006
@@ -1,9 +1,9 @@
-# $Id: Makefile.am,v 1.6 2004-06-17 13:32:44 wingman Exp $
+# $Id: Makefile.am,v 1.7 2006-08-25 17:22:50 sven Exp $
 
 include $(top_srcdir)/$(ac_aux_dir)/module.mk
 
 pkglib_LTLIBRARIES	= script.la
-script_la_SOURCES	= scriptconfig.c scriptlog.c scriptmod.c scriptbind.c scriptnet.c scriptuser.c scriptparty.c scripttimer.c scriptmisc.c
+script_la_SOURCES	= scriptconfig.c scriptlog.c scriptmod.c scriptbind.c scriptnet.c scriptdns.c scriptuser.c scriptparty.c scripttimer.c scriptmisc.c
 script_la_LDFLAGS	= -module -avoid-version -no-undefined
 script_la_LIBADD	= @LIBS@ \
 			$(top_builddir)/lib/eggdrop/libeggdrop.la
Index: eggdrop1.9/modules/script/egg_script_internal.h
diff -u eggdrop1.9/modules/script/egg_script_internal.h:1.1 eggdrop1.9/modules/script/egg_script_internal.h:1.2
--- eggdrop1.9/modules/script/egg_script_internal.h:1.1	Thu Dec  1 15:22:11 2005
+++ eggdrop1.9/modules/script/egg_script_internal.h	Fri Aug 25 12:22:50 2006
@@ -8,6 +8,7 @@
 #define start script_LTX_start
 #define script_misc_cmds script_LTX_script_misc_cmds
 #define script_net_cmds script_LTX_script_net_cmds
+#define script_dns_cmds script_LTX_script_dns_cmds
 #define script_new_user_cmds script_LTX_script_new_user_cmds
 #define script_party_cmds script_LTX_script_party_cmds
 #define script_timer_cmds script_LTX_script_timer_cmds
Index: eggdrop1.9/modules/script/scriptdns.c
diff -u /dev/null eggdrop1.9/modules/script/scriptdns.c:1.1
--- /dev/null	Fri Aug 25 12:23:01 2006
+++ eggdrop1.9/modules/script/scriptdns.c	Fri Aug 25 12:22:50 2006
@@ -0,0 +1,109 @@
+/* scriptdns.c: dns-related scripting commands
+ *
+ * Copyright (C) 2002, 2003, 2004 Eggheads Development Team
+ *
+ * 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.
+ */
+
+#ifndef lint
+static const char rcsid[] = "$Id: scriptdns.c,v 1.1 2006-08-25 17:22:50 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;
+}
+
+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;
+}
+
+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 */
+	{0}
+};
Index: eggdrop1.9/modules/script/scriptmod.c
diff -u eggdrop1.9/modules/script/scriptmod.c:1.13 eggdrop1.9/modules/script/scriptmod.c:1.14
--- eggdrop1.9/modules/script/scriptmod.c:1.13	Thu Dec  1 15:22:11 2005
+++ eggdrop1.9/modules/script/scriptmod.c	Fri Aug 25 12:22:51 2006
@@ -18,13 +18,13 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scriptmod.c,v 1.13 2005-12-01 21:22:11 stdarg Exp $";
+static const char rcsid[] = "$Id: scriptmod.c,v 1.14 2006-08-25 17:22:51 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
 #include "egg_script_internal.h"
 
-extern script_command_t script_bind_cmds[], script_net_cmds[], script_new_user_cmds[], script_party_cmds[], script_timer_cmds[],
+extern script_command_t script_bind_cmds[], script_net_cmds[], script_dns_cmds[], script_new_user_cmds[], script_party_cmds[], script_timer_cmds[],
        script_log_cmds[], script_config_cmds[], script_misc_cmds[];
 
 static int script_module_unload(char *name)
@@ -53,6 +53,7 @@
 	script_create_commands(script_log_cmds);
 	script_create_commands(script_bind_cmds);
 	script_create_commands(script_net_cmds);
+	script_create_commands(script_dns_cmds);
 	script_create_commands(script_new_user_cmds);
 	script_create_commands(script_party_cmds);
 	script_create_commands(script_timer_cmds);
----------------------- End of diff -----------------------



More information about the Changes mailing list