[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Tue Oct 16 22:34:10 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-17 03:28:27 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     src/chanprog.c src/dns.c src/main.c src/tcl.c src/tclegg.h
     src/tclhash.c src/tclmisc.c

Log message:

Removed old timer code.
Updated dns.c to use new script interface.

---------------------- diff included ----------------------
Index: eggdrop1.7/src/chanprog.c
diff -u eggdrop1.7/src/chanprog.c:1.32 eggdrop1.7/src/chanprog.c:1.33
--- eggdrop1.7/src/chanprog.c:1.32	Sun Oct 14 06:08:10 2001
+++ eggdrop1.7/src/chanprog.c	Tue Oct 16 22:28:16 2001
@@ -5,7 +5,7 @@
  *   telling the current programmed settings
  *   initializing a lot of stuff and loading the tcl scripts
  *
- * $Id: chanprog.c,v 1.32 2001/10/14 11:08:10 tothwolf Exp $
+ * $Id: chanprog.c,v 1.33 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -474,115 +474,6 @@
   noshare = 0;
   userlist = NULL;
   chanprog();
-}
-
-/*
- *    Brief venture into timers
- */
-
-/* Add a timer
- */
-unsigned long add_timer(tcl_timer_t **stack, int elapse, char *cmd,
-			unsigned long prev_id)
-{
-  tcl_timer_t *old = (*stack);
-
-  *stack = (tcl_timer_t *) malloc(sizeof(tcl_timer_t));
-  (*stack)->next = old;
-  (*stack)->mins = elapse;
-  malloc_strcpy((*stack)->cmd, cmd);
-
-  /* If it's just being added back and already had an id,
-   * don't create a new one.
-  */
-  if (prev_id > 0)
-    (*stack)->id = prev_id;
-  else
-    (*stack)->id = timer_id++;
-  return (*stack)->id;
-}
-
-/* Remove a timer, by id
- */
-int remove_timer(tcl_timer_t **stack, unsigned long id)
-{
-  tcl_timer_t *old;
-  int ok = 0;
-
-  while (*stack) {
-    if ((*stack)->id == id) {
-      ok++;
-      old = *stack;
-      *stack = ((*stack)->next);
-      free(old->cmd);
-      free(old);
-    } else
-      stack = &((*stack)->next);
-  }
-  return ok;
-}
-
-/* Check timers, execute the ones that have expired.
- */
-void do_check_timers(tcl_timer_t **stack)
-{
-  tcl_timer_t *mark = *stack, *old = NULL;
-  char x[16];
-
-  /* New timers could be added by a Tcl script inside a current timer
-   * so i'll just clear out the timer list completely, and add any
-   * unexpired timers back on.
-   */
-  *stack = NULL;
-  while (mark) {
-    if (mark->mins > 0)
-      mark->mins--;
-    old = mark;
-    mark = mark->next;
-    if (!old->mins) {
-      egg_snprintf(x, sizeof x, "timer%lu", old->id);
-      do_tcl(x, old->cmd);
-      free(old->cmd);
-      free(old);
-    } else {
-      old->next = *stack;
-      *stack = old;
-    }
-  }
-}
-
-/* Wipe all timers.
- */
-void wipe_timers(Tcl_Interp *irp, tcl_timer_t **stack)
-{
-  tcl_timer_t *mark = *stack, *old;
-
-  while (mark) {
-    old = mark;
-    mark = mark->next;
-    free(old->cmd);
-    free(old);
-  }
-  *stack = NULL;
-}
-
-/* Return list of timers
- */
-void list_timers(Tcl_Interp *irp, tcl_timer_t *stack)
-{
-  tcl_timer_t *mark;
-  char mins[10], id[16], *argv[3], *x;
-
-  for (mark = stack; mark; mark = mark->next) {
-    egg_snprintf(mins, sizeof mins, "%u", mark->mins);
-    egg_snprintf(id, sizeof id, "timer%lu", mark->id);
-    argv[0] = mins;
-    argv[1] = mark->cmd;
-    argv[2] = id;
-    x = Tcl_Merge(3, argv);
-    Tcl_AppendElement(irp, x);
-    Tcl_Free((char *) x);
-  }
 }
 
 /* Oddly enough, written by proton (Emech's coder)
Index: eggdrop1.7/src/dns.c
diff -u eggdrop1.7/src/dns.c:1.27 eggdrop1.7/src/dns.c:1.28
--- eggdrop1.7/src/dns.c:1.27	Thu Oct 11 08:01:35 2001
+++ eggdrop1.7/src/dns.c	Tue Oct 16 22:28:16 2001
@@ -2,9 +2,9 @@
  * dns.c -- handles:
  *   DNS resolve calls and events
  *   provides the code used by the bot if the DNS module is not loaded
- *   DNS Tcl commands
+ *   DNS script commands
  *
- * $Id: dns.c,v 1.27 2001/10/11 13:01:35 tothwolf Exp $
+ * $Id: dns.c,v 1.28 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Written by Fabian Knittel <fknittel at gmx.de>
@@ -35,13 +35,14 @@
 
 #include "dns.h"
 #include "adns/adns.h"
+#include "script_api.h"
+#include "script.h"
 
 extern struct dcc_t	*dcc;
 extern int		 dcc_total;
 extern int		 resolve_timeout;
 extern time_t		 now;
 extern jmp_buf		 alarmret;
-extern Tcl_Interp	*interp;
 
 devent_t		*dns_events = NULL;
 
@@ -52,6 +53,19 @@
  *   DCC functions
  */
 
+static int script_dnslookup(char *iporhost, script_callback_t *callback);
+
+static script_simple_command_t scriptdns_cmds[] = {
+	{"", NULL, NULL, NULL, 0},
+	{"dnslookup", script_dnslookup, "sc", "ip-address/hostname callback", SCRIPT_INTEGER},
+	0
+};
+
+void dns_init()
+{
+	script_create_simple_cmd_table(scriptdns_cmds);
+}
+
 void dcc_dnswait(int idx, char *buf, int len)
 {
   /* Ignore anything now. */
@@ -214,38 +228,30 @@
 
 
 /*
- *   Tcl events
+ *   Script events
  */
 
-static void dns_tcl_iporhostres(char *ip, char *hostn, int ok, void *other)
+static void dns_script_iporhostres(char *ip, char *hostn, int ok, void *other)
 {
-  devent_tclinfo_t *tclinfo = (devent_tclinfo_t *) other;
-
-  if (Tcl_VarEval(interp, tclinfo->proc, " ", ip, " ",
-		  hostn, ok ? " 1" : " 0", tclinfo->paras, NULL) == TCL_ERROR)
-    putlog(LOG_MISC, "*", _("Tcl error [%s]: %s"), tclinfo->proc, interp->result);
+  script_callback_t *callback = (script_callback_t *)other;
 
-  /* Free the memory. It will be unused after this event call. */
-  free(tclinfo->proc);
-  if (tclinfo->paras)
-    free(tclinfo->paras);
-  free(tclinfo);
+  callback->callback(callback, ip, hostn, ok);
+  callback->delete(callback);
 }
 
-devent_type DNS_TCLEVENT_HOSTBYIP = {
-  "TCLEVENT_HOSTBYIP",
-  dns_tcl_iporhostres
+devent_type DNS_SCRIPTEVENT_HOSTBYIP = {
+  "SCRIPTEVENT_HOSTBYIP",
+  dns_script_iporhostres
 };
 
-devent_type DNS_TCLEVENT_IPBYHOST = {
-  "TCLEVENT_IPBYHOST",
-  dns_tcl_iporhostres
+devent_type DNS_SCRIPTEVENT_IPBYHOST = {
+  "SCRIPTEVENT_IPBYHOST",
+  dns_script_iporhostres
 };
 
-static void tcl_dnsipbyhost(char *hostn, char *proc, char *paras)
+static void script_dnsipbyhost(char *hostn, script_callback_t *callback)
 {
   devent_t *de;
-  devent_tclinfo_t *tclinfo;
 
   de = calloc(1, sizeof(devent_t));
 
@@ -253,27 +259,19 @@
   de->next = dns_events;
   dns_events = de;
 
-  de->type = &DNS_TCLEVENT_IPBYHOST;
+  de->type = &DNS_SCRIPTEVENT_IPBYHOST;
   de->lookup = RES_IPBYHOST;
   malloc_strcpy(de->hostname, hostn);
-
-  /* Store additional data. */
-  tclinfo = malloc(sizeof(devent_tclinfo_t));
-  malloc_strcpy(tclinfo->proc, proc);
-  if (paras)
-    malloc_strcpy(tclinfo->paras, paras);
-  else
-    tclinfo->paras = NULL;
-  de->other = tclinfo;
+  malloc_strcpy(callback->syntax, "ssi");
+  de->other = callback;
 
   /* Send request. */
   dns_ipbyhost(hostn);
 }
 
-static void tcl_dnshostbyip(char *ip, char *proc, char *paras)
+static void script_dnshostbyip(char *ip, script_callback_t *callback)
 {
   devent_t *de;
-  devent_tclinfo_t *tclinfo;
 
   de = calloc(1, sizeof(devent_t));
 
@@ -281,18 +279,11 @@
   de->next = dns_events;
   dns_events = de;
 
-  de->type = &DNS_TCLEVENT_HOSTBYIP;
+  de->type = &DNS_SCRIPTEVENT_HOSTBYIP;
   de->lookup = RES_HOSTBYIP;
   malloc_strcpy(de->hostname, ip);
-
-  /* Store additional data. */
-  tclinfo = malloc(sizeof(devent_tclinfo_t));
-  malloc_strcpy(tclinfo->proc, proc);
-  if (paras)
-    malloc_strcpy(tclinfo->paras, paras);
-  else
-    tclinfo->paras = NULL;
-  de->other = tclinfo;
+  malloc_strcpy(callback->syntax, "ssi");
+  de->other = callback;
 
   /* Send request. */
   dns_hostbyip(ip);
@@ -464,57 +455,28 @@
 #endif
 
 /*
- *   Tcl functions
+ *   Script functions
  */
 
 /* dnslookup <ip-address> <proc> */
-static int tcl_dnslookup STDVAR
+static int script_dnslookup(char *iporhost, script_callback_t *callback)
 {
   struct in_addr inaddr;
 #ifdef IPV6
   struct in6_addr inaddr6;
 #endif
-  char *paras = NULL;
-
-  if (argc < 3) {
-    Tcl_AppendResult(irp, "wrong # args: should be \"", argv[0],
-		     " ip-address/hostname proc ?args...?\"", NULL);
-    return TCL_ERROR;
-  }
 
-  if (argc > 3) {
-    int l = 0, p;
-
-    /* Create a string with a leading space out of all provided
-     * additional parameters.
-     */
-    paras = calloc(1, 1);
-    for (p = 3; p < argc; p++) {
-      l += strlen(argv[p]) + 1;
-      paras = realloc(paras, l + 1);
-      strcat(paras, " ");
-      strcat(paras, argv[p]);
-    }
-  }
-
-  if (egg_inet_aton(argv[1], &inaddr)
+  if (egg_inet_aton(iporhost, &inaddr)
 #ifdef IPV6
-	|| egg_inet_pton(AF_INET6, argv[1], &inaddr6)
+	|| egg_inet_pton(AF_INET6, iporhost, &inaddr6)
 #endif
       )
-    tcl_dnshostbyip(argv[1], argv[2], paras);
+    script_dnshostbyip(iporhost, callback);
   else
-    tcl_dnsipbyhost(argv[1], argv[2], paras);
-  if (paras)
-    free(paras);
-  return TCL_OK;
+    script_dnsipbyhost(iporhost, callback);
+  return(0);
 }
 
-tcl_cmds tcldns_cmds[] =
-{
-  {"dnslookup",	tcl_dnslookup},
-  {NULL,	NULL}
-};
 
 /*********** ADNS support ***********/
 
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.87 eggdrop1.7/src/main.c:1.88
--- eggdrop1.7/src/main.c:1.87	Mon Oct 15 04:54:01 2001
+++ eggdrop1.7/src/main.c	Tue Oct 16 22:28:16 2001
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.87 2001/10/15 09:54:01 stdarg Exp $
+ * $Id: main.c,v 1.88 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -489,7 +489,6 @@
   int miltime;
 
   call_hook(HOOK_SECONDLY);	/* Will be removed later */
-  do_check_timers(&utimer);	/* Secondly timers */
   cnt++;
   if (cnt >= 10) {		/* Every 10 seconds */
     cnt = 0;
@@ -633,6 +632,7 @@
 int init_dcc_max(), init_userent(), init_misc(), init_net(),
  init_modules(), init_tcl(int, char **);
 void botnet_init();
+void dns_init();
 void script_init();
 void binds_init();
 
@@ -751,6 +751,7 @@
     fatal(_("ERROR: Eggdrop will not run as root!"), 0);
 
   script_init();
+  dns_init();
   binds_init();
   core_binds_init();
   init_dcc_max();
Index: eggdrop1.7/src/tcl.c
diff -u eggdrop1.7/src/tcl.c:1.46 eggdrop1.7/src/tcl.c:1.47
--- eggdrop1.7/src/tcl.c:1.46	Sat Oct 13 23:44:36 2001
+++ eggdrop1.7/src/tcl.c	Tue Oct 16 22:28:16 2001
@@ -4,7 +4,7 @@
  *   Tcl initialization
  *   getting and setting Tcl/eggdrop variables
  *
- * $Id: tcl.c,v 1.46 2001/10/14 04:44:36 stdarg Exp $
+ * $Id: tcl.c,v 1.47 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -472,7 +472,7 @@
   Tcl_DeleteInterp(interp);
 }
 
-extern tcl_cmds tcluser_cmds[], tcldcc_cmds[], tclmisc_cmds[], tclmisc_objcmds[], tcldns_cmds[];
+extern tcl_cmds tcluser_cmds[], tcldcc_cmds[], tclmisc_cmds[], tclmisc_objcmds[];
 
 /* Not going through Tcl's crazy main() system (what on earth was he
  * smoking?!) so we gotta initialize the Tcl interpreter
@@ -529,7 +529,6 @@
   add_tcl_commands(tcldcc_cmds);
   add_tcl_commands(tclmisc_cmds);
   add_tcl_objcommands(tclmisc_objcmds);
-  add_tcl_commands(tcldns_cmds);
 }
 
 void do_tcl(char *whatzit, char *script)
Index: eggdrop1.7/src/tclegg.h
diff -u eggdrop1.7/src/tclegg.h:1.13 eggdrop1.7/src/tclegg.h:1.14
--- eggdrop1.7/src/tclegg.h:1.13	Wed Jul 25 23:07:49 2001
+++ eggdrop1.7/src/tclegg.h	Tue Oct 16 22:28:16 2001
@@ -2,7 +2,7 @@
  * tclegg.h
  *   stuff used by tcl.c and tclhash.c
  *
- * $Id: tclegg.h,v 1.13 2001/07/26 04:07:49 guppy Exp $
+ * $Id: tclegg.h,v 1.14 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -83,12 +83,6 @@
 	}								\
 } while (0)
 
-
-unsigned long add_timer(tcl_timer_t **, int, char *, unsigned long);
-int remove_timer(tcl_timer_t **, unsigned long);
-void list_timers(Tcl_Interp *, tcl_timer_t *);
-void wipe_timers(Tcl_Interp *, tcl_timer_t **);
-void do_check_timers(tcl_timer_t **);
 
 typedef struct _tcl_strings {
   char *name;
Index: eggdrop1.7/src/tclhash.c
diff -u eggdrop1.7/src/tclhash.c:1.47 eggdrop1.7/src/tclhash.c:1.48
--- eggdrop1.7/src/tclhash.c:1.47	Tue Oct 16 19:19:16 2001
+++ eggdrop1.7/src/tclhash.c	Tue Oct 16 22:28:16 2001
@@ -7,7 +7,7 @@
  *   (non-Tcl) procedure lookups for msg/dcc/file commands
  *   (Tcl) binding internal procedures to msg/dcc/file commands
  *
- * $Id: tclhash.c,v 1.47 2001/10/17 00:19:16 stdarg Exp $
+ * $Id: tclhash.c,v 1.48 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -532,27 +532,6 @@
   tm->first = tc;
 
   return 1;
-}
-
-static int tcl_getbinds(tcl_bind_list_t *tl_kind, const char *name)
-{
-  tcl_bind_mask_t	*tm;
-
-  for (tm = tl_kind->first; tm; tm = tm->next) {
-    if (tm->flags & TBM_DELETED)
-      continue;
-    if (!egg_strcasecmp(tm->mask, name)) {
-      tcl_cmd_t		*tc;
-
-      for (tc = tm->first; tc; tc = tc->next) {
-	if (tc->attributes & TC_DELETED)
-	  continue;
-	Tcl_AppendElement(interp, tc->func_name);
-      }
-      break;
-    }
-  }
-  return TCL_OK;
 }
 
 static int script_bind(char *table_name, char *flags, char *mask, script_callback_t *callback)
Index: eggdrop1.7/src/tclmisc.c
diff -u eggdrop1.7/src/tclmisc.c:1.31 eggdrop1.7/src/tclmisc.c:1.32
--- eggdrop1.7/src/tclmisc.c:1.31	Sun Oct 14 18:13:33 2001
+++ eggdrop1.7/src/tclmisc.c	Tue Oct 16 22:28:16 2001
@@ -3,7 +3,7 @@
  *   Tcl stubs for file system commands
  *   Tcl stubs for everything else
  *
- * $Id: tclmisc.c,v 1.31 2001/10/14 23:13:33 stdarg Exp $
+ * $Id: tclmisc.c,v 1.32 2001/10/17 03:28:16 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -229,40 +229,24 @@
 static int tcl_killtimer STDVAR
 {
   BADARGS(2, 2, " timerID");
-  if (strncmp(argv[1], "timer", 5)) {
-    Tcl_AppendResult(irp, "argument is not a timerID", NULL);
-    return TCL_ERROR;
-  }
-  if (remove_timer(&timer, atol(&argv[1][5])))
-    return TCL_OK;
-  Tcl_AppendResult(irp, "invalid timerID", NULL);
-  return TCL_ERROR;
+  return TCL_OK;
 }
 
 static int tcl_killutimer STDVAR
 {
   BADARGS(2, 2, " timerID");
-  if (strncmp(argv[1], "timer", 5)) {
-    Tcl_AppendResult(irp, "argument is not a timerID", NULL);
-    return TCL_ERROR;
-  }
-  if (remove_timer(&utimer, atol(&argv[1][5])))
-    return TCL_OK;
-  Tcl_AppendResult(irp, "invalid timerID", NULL);
-  return TCL_ERROR;
+  return TCL_OK;
 }
 
 static int tcl_timers STDVAR
 {
   BADARGS(1, 1, "");
-  list_timers(irp, timer);
   return TCL_OK;
 }
 
 static int tcl_utimers STDVAR
 {
   BADARGS(1, 1, "");
-  list_timers(irp, utimer);
   return TCL_OK;
 }
 
----------------------- End of diff -----------------------



More information about the Changes mailing list