[cvslog] (2005-07-31 05:51:17 UTC) Module eggdrop1.7: Change committed!

cvslog cvs at tsss.org
Sat Jul 30 23:51:17 CST 2005


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2005-07-31 05:51:17 UTC
Commited by: Will Buckner <wcc at techmonkeys.org>

Modified files:
     README doc/html/readme.html src/botmsg.c src/cmds.c src/dccutil.c
     src/dns.c src/main.c src/net.c src/patch.h src/tcl.c
     src/tclhash.c src/tclhash.h src/mod/filesys.mod/filesys.c

Log message:

* If this compiles, I am going to cry with joy.

---------------------- diff included ----------------------
Index: eggdrop1.7/README
diff -u eggdrop1.7/README:1.4 eggdrop1.7/README:1.5
--- eggdrop1.7/README:1.4	Thu Jan 20 19:43:37 2005
+++ eggdrop1.7/README	Sun Jul 31 00:51:06 2005
@@ -1,4 +1,4 @@
-$Id: README,v 1.4 2005/01/21 01:43:37 wcc Exp $
+$Id: README,v 1.5 2005/07/31 05:51:06 wcc Exp $
 
 Readme
 Last revised: August 24, 2004
@@ -489,10 +489,10 @@
     The files "match.c", "net.c", and "blowfish.c" are exempt from the above
     restrictions. "match.c" is original code by Chris Fuller (email:
     crf at cfox.bchs.uh.edu) and has been placed by him into the public domain.
-    "net.c" is by me, and I [who?] also choose to place it in the public
-    domain. "blowfish.c" is by various sources and is in the public domain
-    as well. All 3 files contain useful functions that could easily be
-    ported to other applications.
+    "net.c" is by me, and I [Robey Pointer] also choose to place it in the
+    public domain. "blowfish.c" is by various sources and is in the public
+    domain as well. All 3 files contain useful functions that could easily
+    be ported to other applications.
 
     Tcl is by John Ousterhout and is in no way affiliated with Eggdrop. It
     likely has its own set of copyrights and whatnots.
Index: eggdrop1.7/doc/html/readme.html
diff -u eggdrop1.7/doc/html/readme.html:1.3 eggdrop1.7/doc/html/readme.html:1.4
--- eggdrop1.7/doc/html/readme.html:1.3	Thu Jan 20 19:43:38 2005
+++ eggdrop1.7/doc/html/readme.html	Sun Jul 31 00:51:06 2005
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!-- $Id: readme.html,v 1.3 2005/01/21 01:43:38 wcc Exp $ -->
+<!-- $Id: readme.html,v 1.4 2005/07/31 05:51:06 wcc Exp $ -->
 
 <html>
   <head>
@@ -449,9 +449,9 @@
       &quot;blowfish.c&quot; are exempt from the above restrictions.
       &quot;match.c&quot; is original code by Chris Fuller (email:
       crf at cfox.bchs.uh.edu) and has been placed by him into the public
-      domain. &quot;net.c&quot; is by me, and I [who?] also choose to place
-      it in the public domain. &quot;blowfish.c&quot; is by various sources
-      and is in the public domain as well. All 3 files contain useful
+      domain. &quot;net.c&quot; is by me, and I [Robey Pointer] also choose
+      to place it in the public domain. &quot;blowfish.c&quot; is by various
+      sources and is in the public domain as well. All 3 files contain useful
       functions that could easily be ported to other applications.</p>
 
       <p>Tcl is by John Ousterhout and is in no way affiliated with Eggdrop.
Index: eggdrop1.7/src/botmsg.c
diff -u eggdrop1.7/src/botmsg.c:1.9 eggdrop1.7/src/botmsg.c:1.10
--- eggdrop1.7/src/botmsg.c:1.9	Thu Jan 20 19:43:39 2005
+++ eggdrop1.7/src/botmsg.c	Sun Jul 31 00:51:06 2005
@@ -19,7 +19,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: botmsg.c,v 1.9 2005/01/21 01:43:39 wcc Exp $
+ * $Id: botmsg.c,v 1.10 2005/07/31 05:51:06 wcc Exp $
  */
 
 #include "main.h"
@@ -784,9 +784,7 @@
 }
 
 /* This part of add_note is more relevant to the botnet than
- * to the notes file. If idx is -1, the note will be stored
- * and the user will not be notified. If idx is -2, the note
- * will not be stored.
+ * to the notes file
  */
 int add_note(char *to, char *from, char *msg, int idx, int echo)
 {
@@ -794,14 +792,12 @@
   char *p, botf[81], ss[81], ssf[81];
   struct userrec *u;
 
-  /* Notes have a length limit. Note + PRIVMSG header + nick + date must
-   * be < 512 */
+  /* note length + PRIVMSG header + nickname + date  must be <512  */
   if (strlen(msg) > 450)
-    msg[450] = 0;
+    msg[450] = 0;               /* Notes have a limit */
 
-  /* Cross-bot note? */
   p = strchr(to, '@');
-  if (p != NULL) {
+  if (p != NULL) {              /* Cross-bot note */
     char x[21];
 
     *p = 0;
@@ -819,17 +815,17 @@
 
       if (strchr(from, '@')) {
         strcpy(botf, from);
-      } else {
+      } else
         sprintf(botf, "%s@%s", from, botnetnick);
-      }
-    } else {
+
+    } else
       strcpy(botf, botnetnick);
-    }
 
     i = nextbot(p);
     if (i < 0) {
       if (idx >= 0)
         dprintf(idx, BOT_NOTHERE);
+
       return NOTE_ERROR;
     }
 
@@ -839,14 +835,13 @@
     if (idx >= 0) {
       sprintf(ssf, "%lu:%s", dcc[idx].sock, botf);
       botnet_send_priv(i, ssf, x, p, "%s", msg);
-    } else {
+    } else
       botnet_send_priv(i, botf, x, p, "%s", msg);
-    }
 
-    return NOTE_OK; /* Forwarded to the right bot. */
+    return NOTE_OK;             /* Forwarded to the right bot */
   }
 
-  /* Might be form "sock:nick". */
+  /* Might be form "sock:nick" */
   splitc(ssf, from, ':');
   rmspace(ssf);
   splitc(ss, to, ':');
@@ -856,11 +851,12 @@
   else
     sock = atoi(ss);
 
-  /* Notes from bots don't trigger it. */
-  if (idx != -2) {
+  /* Don't process if there's a note binding for it */
+  if (idx != -2) {            /* Notes from bots don't trigger it */
     if (check_tcl_note(from, to, msg)) {
       if (idx >= 0 && echo)
         dprintf(idx, "-> %s: %s\n", to, msg);
+
       return NOTE_TCL;
     }
   }
@@ -870,6 +866,7 @@
   if (!u) {
     if (idx >= 0)
       dprintf(idx, USERF_UNKNOWN);
+
     return NOTE_ERROR;
   }
 
@@ -877,68 +874,74 @@
   if (is_bot(u)) {
     if (idx >= 0)
       dprintf(idx, BOT_NONOTES);
+
     return NOTE_ERROR;
   }
 
-  /* Is user ignoring notes from this source? */
+  /* Is user rejecting notes from this source? */
   if (match_noterej(u, from)) {
     if (idx >= 0)
       dprintf(idx, "%s rejected your note.\n", u->handle);
+
     return NOTE_REJECT;
   }
 
   status = NOTE_STORED;
   iaway = 0;
 
-  /* Online right now? Don't bother if idx == -1. */
-  if (idx != -1) {
-    for (i = 0; i < dcc_total; i++) {
-      if ((dcc[i].type->flags & DCT_GETNOTES) &&
-          (sock == -1 || sock == dcc[i].sock) &&
-          !egg_strcasecmp(dcc[i].nick, to)) {
-        int aok = 1;
-
-        if (dcc[i].type == &DCC_CHAT) {
-          /* Don't check away if from a bot. */
-          if (dcc[i].u.chat->away != NULL && idx != -2) {
-            aok = 0;
-            if (idx >= 0)
-              dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
-                      dcc[i].u.chat->away);
-            if (!iaway)
-              iaway = i;
-            status = NOTE_AWAY;
-          }
+  /* Online right now? */
+  for (i = 0; i < dcc_total; i++) {
+    if ((dcc[i].type->flags & DCT_GETNOTES) &&
+        (sock == -1 || sock == dcc[i].sock) &&
+        !egg_strcasecmp(dcc[i].nick, to)) {
+      int aok = 1;
+
+      if (dcc[i].type == &DCC_CHAT) {
+
+        /* Only check away if it's not from a bot */
+        if (dcc[i].u.chat->away != NULL && idx != -2) {
+          aok = 0;
+
+          if (idx >= 0)
+            dprintf(idx, "%s %s: %s\n", dcc[i].nick, BOT_USERAWAY,
+                    dcc[i].u.chat->away);
+
+          if (!iaway)
+            iaway = i;
+          status = NOTE_AWAY;
         }
+      }
 
-        if (aok) {
-          char *p, *fr = from, work[1024];
-          int l = 0;
-
-          while (*msg == '<' || *msg == '>') {
-            p = newsplit(&msg);
-            if (*p == '<')
-              l += simple_sprintf(work + l, "via %s, ", p + 1);
-            else if (*from == '@')
-              fr = p + 1;
-          }
-
-          if (idx == -2 || !egg_strcasecmp(from, botnetnick))
-            dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
-          else
-            dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
-          if (idx >= 0 && echo)
-            dprintf(idx, "-> %s: %s\n", to, msg);
-          return NOTE_OK;
+      if (aok) {
+        char *p, *fr = from, work[1024];
+        int l = 0;
+
+        while (*msg == '<' || *msg == '>') {
+          p = newsplit(&msg);
+
+          if (*p == '<')
+            l += simple_sprintf(work + l, "via %s, ", p + 1);
+          else if (*from == '@')
+            fr = p + 1;
         }
+
+        if (idx == -2 || !egg_strcasecmp(from, botnetnick))
+          dprintf(i, "*** [%s] %s%s\n", fr, l ? work : "", msg);
+        else
+          dprintf(i, "%cNote [%s]: %s%s\n", 7, fr, l ? work : "", msg);
+
+        if (idx >= 0 && echo)
+          dprintf(idx, "-> %s: %s\n", to, msg);
+
+        return NOTE_OK;
       }
     }
   }
 
   if (idx == -2)
-    return NOTE_OK; /* Error msg from a tandembot: don't store. */
+    return NOTE_OK;             /* Error msg from a tandembot: don't store */
 
-  /* Prepare to call tcl_storenote. */
+  /* Call tcl_storenote */
   Tcl_SetVar(interp, "_from", from, 0);
   Tcl_SetVar(interp, "_to", to, 0);
   Tcl_SetVar(interp, "_data", msg, 0);
@@ -946,19 +949,20 @@
     simple_sprintf(ss, "%d", dcc[idx].sock);
   else
     simple_sprintf(ss, "%d", -1);
+
   Tcl_SetVar(interp, "_idx", ss, 0);
 
-  /* Store the note. */
-  if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) == TCL_OK) {
+  if (Tcl_VarEval(interp, "storenote", " $_from $_to $_data $_idx", NULL) ==
+      TCL_OK) {
+
     if (interp->result && interp->result[0])
       status = NOTE_FWD;
 
-    if (status == NOTE_AWAY) {
-      /* User is away in all sessions -- just notify the user that a
-       * message arrived and was stored. (only oldest session is notified.)
-       */
+    /* User is away in all sessions -- just notify the user that a
+     * message arrived and was stored. (only oldest session is notified.)
+     */
+    if (status == NOTE_AWAY)
       dprintf(iaway, "*** %s.\n", BOT_NOTEARRIVED);
-    }
 
     return status;
   }
Index: eggdrop1.7/src/cmds.c
diff -u eggdrop1.7/src/cmds.c:1.18 eggdrop1.7/src/cmds.c:1.19
--- eggdrop1.7/src/cmds.c:1.18	Thu Jan 20 19:43:39 2005
+++ eggdrop1.7/src/cmds.c	Sun Jul 31 00:51:06 2005
@@ -17,7 +17,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: cmds.c,v 1.18 2005/01/21 01:43:39 wcc Exp $
+ * $Id: cmds.c,v 1.19 2005/07/31 05:51:06 wcc Exp $
  */
 
 #include "main.h"
@@ -2875,7 +2875,7 @@
   {"handle",    "",     (Function) cmd_handle,     NULL},
   {"nick",      "",     (Function) cmd_handle,     NULL},
   {"page",      "",     (Function) cmd_page,       NULL},
-  {"quit",      "",     (Function) NULL,           NULL},
+  {"quit",      "",     (Function) CMD_LEAVE,      NULL},
   {"rehash",    "m",    (Function) cmd_rehash,     NULL},
   {"relay",     "o",    (Function) cmd_relay,      NULL},
   {"reload",    "m|m",  (Function) cmd_reload,     NULL},
Index: eggdrop1.7/src/dccutil.c
diff -u eggdrop1.7/src/dccutil.c:1.10 eggdrop1.7/src/dccutil.c:1.11
--- eggdrop1.7/src/dccutil.c:1.10	Thu Jan 20 19:43:40 2005
+++ eggdrop1.7/src/dccutil.c	Sun Jul 31 00:51:06 2005
@@ -17,7 +17,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: dccutil.c,v 1.10 2005/01/21 01:43:40 wcc Exp $
+ * $Id: dccutil.c,v 1.11 2005/07/31 05:51:06 wcc Exp $
  */
 
 #include <sys/stat.h>
@@ -536,7 +536,6 @@
 void *_get_data_ptr(int size, char *file, int line)
 {
   char *p;
-
 #ifdef DEBUG_MEM
   char x[1024];
 
Index: eggdrop1.7/src/dns.c
diff -u eggdrop1.7/src/dns.c:1.8 eggdrop1.7/src/dns.c:1.9
--- eggdrop1.7/src/dns.c:1.8	Thu Jan 20 19:43:40 2005
+++ eggdrop1.7/src/dns.c	Sun Jul 31 00:51:06 2005
@@ -18,7 +18,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.c,v 1.8 2005/01/21 01:43:40 wcc Exp $
+ * $Id: dns.c,v 1.9 2005/07/31 05:51:06 wcc Exp $
  */
 
 #include "main.h"
@@ -40,7 +40,7 @@
 extern int dcc_total;
 extern int resolve_timeout;
 extern time_t now;
-extern jmp_buf alarmret;
+extern sigjmp_buf alarmret;
 extern Tcl_Interp *interp;
 
 devent_t *dns_events = NULL;
@@ -450,7 +450,7 @@
   unsigned long addr = htonl(ip);
   static char s[UHOSTLEN];
 
-  if (!setjmp(alarmret)) {
+  if (!sigsetjmp(alarmret, 1)) {
     alarm(resolve_timeout);
     hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
     alarm(0);
@@ -476,7 +476,7 @@
     call_ipbyhost(host, ntohl(inaddr.s_addr), 1);
     return;
   }
-  if (!setjmp(alarmret)) {
+  if (!sigsetjmp(alarmret, 1)) {
     struct hostent *hp;
     struct in_addr *in;
     IP ip = 0;
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.20 eggdrop1.7/src/main.c:1.21
--- eggdrop1.7/src/main.c:1.20	Sat Jul 30 22:49:35 2005
+++ eggdrop1.7/src/main.c	Sun Jul 31 00:51:06 2005
@@ -19,7 +19,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: main.c,v 1.20 2005/07/31 03:49:35 wcc Exp $
+ * $Id: main.c,v 1.21 2005/07/31 05:51:06 wcc Exp $
  */
 
 #include "main.h"
@@ -86,7 +86,7 @@
 extern module_entry *module_list;
 extern Tcl_Interp *interp;
 extern tcl_timer_t *timer, *utimer;
-extern jmp_buf alarmret;
+extern sigjmp_buf alarmret;
 
 #ifdef DEBUG_CONTEXT
 extern char cx_file[16][30], cx_note[16][256];
@@ -258,7 +258,7 @@
 /* A call to resolver (gethostbyname, etc) timed out. */
 static void got_alarm(int z)
 {
-  longjmp(alarmret, 1);
+  siglongjmp(alarmret, 1);
   /* Never reached. */
 }
 
Index: eggdrop1.7/src/mod/filesys.mod/filesys.c
diff -u eggdrop1.7/src/mod/filesys.mod/filesys.c:1.7 eggdrop1.7/src/mod/filesys.mod/filesys.c:1.8
--- eggdrop1.7/src/mod/filesys.mod/filesys.c:1.7	Sat Jul 30 22:49:35 2005
+++ eggdrop1.7/src/mod/filesys.mod/filesys.c	Sun Jul 31 00:51:07 2005
@@ -2,7 +2,7 @@
  * filesys.c -- part of filesys.mod
  *   main file of the filesys eggdrop module
  *
- * $Id: filesys.c,v 1.7 2005/07/31 03:49:35 wcc Exp $
+ * $Id: filesys.c,v 1.8 2005/07/31 05:51:07 wcc Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -164,8 +164,11 @@
     dprintf(idx, "What?  You need 'help'\n");
     return 0;
   }
-  if (x == BIND_QUIT)
+
+  /* We return 1 to leave the filesys. */
+  if (x == BIND_QUIT) /* CMD_LEAVE, 'quit' */
     return 1;
+
   if (x == BIND_EXEC_LOG)
     putlog(LOG_FILES, "*", "#%s# files: %s %s", dcc[idx].nick, cmd, args);
   return 0;
@@ -507,16 +510,22 @@
 
   BADARGS(4, 4, " hand idx param");
 
+  CHECKVALIDITY(builtin_fil);
   idx = findanyidx(atoi(argv[2]));
   if (idx < 0 && dcc[idx].type != &DCC_FILES) {
     Tcl_AppendResult(irp, "invalid idx", NULL);
     return TCL_ERROR;
   }
+
+  /* FIXME: This is an ugly hack. It is not documented as a
+   *        'feature' because it will eventually go away.
+   */
   if (F == CMD_LEAVE) {
     Tcl_AppendResult(irp, "break", NULL);
     return TCL_OK;
   }
-  (F) (idx, argv[3]);
+
+  F(idx, argv[3]);
   Tcl_ResetResult(irp);
   return TCL_OK;
 }
Index: eggdrop1.7/src/net.c
diff -u eggdrop1.7/src/net.c:1.13 eggdrop1.7/src/net.c:1.14
--- eggdrop1.7/src/net.c:1.13	Mon May 30 17:11:47 2005
+++ eggdrop1.7/src/net.c	Sun Jul 31 00:51:07 2005
@@ -3,7 +3,23 @@
  * This is hereby released into the public domain.
  * Robey Pointer, robey at netcom.com
  *
- * $Id: net.c,v 1.13 2005/05/30 22:11:47 wcc Exp $
+ * Changes after Feb 23, 1999 Copyright Eggheads Development Team
+ *
+ * Copyright (C) 1999 - 2005 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.
  */
 
 #include <fcntl.h>
@@ -46,7 +62,7 @@
 
 sock_list *socklist = NULL;
 int MAXSOCKS = 0;
-jmp_buf alarmret;             /* Env buffer for alarm() returns.              */
+sigjmp_buf alarmret;             /* Env buffer for alarm() returns.              */
 
 /* Types of proxies */
 #define PROXY_NONE    0
@@ -327,7 +343,7 @@
       egg_memcpy(x, &ip, 4);
     } else {
       /* no, must be host.domain */
-      if (!setjmp(alarmret)) {
+      if (!sigsetjmp(alarmret, 1)) {
         alarm(resolve_timeout);
         hp = gethostbyname(host);
         alarm(0);
@@ -408,7 +424,7 @@
   else {
     /* No, must be host.domain */
     debug0("WARNING: open_telnet_raw() is about to block in gethostbyname()!");
-    if (!setjmp(alarmret)) {
+    if (!sigsetjmp(alarmret, 1)) {
       alarm(resolve_timeout);
       hp = gethostbyname(host);
       alarm(0);
Index: eggdrop1.7/src/patch.h
diff -u eggdrop1.7/src/patch.h:1.35 eggdrop1.7/src/patch.h:1.36
--- eggdrop1.7/src/patch.h:1.35	Sat Jul 30 22:49:35 2005
+++ eggdrop1.7/src/patch.h	Sun Jul 31 00:51:07 2005
@@ -10,7 +10,7 @@
  * statement, leave the rest of the file alone, this allows better
  * overlapping patches.
  *
- * $Id: patch.h,v 1.35 2005/07/31 03:49:35 wcc Exp $
+ * $Id: patch.h,v 1.36 2005/07/31 05:51:07 wcc Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,12 +41,12 @@
  *
  *
  */
-patch("1122781920");            /* current unixtime */
+patch("1122789039");            /* current unixtime */
 /*
  *
  *
  */
-patch("sync4");
+patch("sync5-complete");
 /*
  *
  *
Index: eggdrop1.7/src/tcl.c
diff -u eggdrop1.7/src/tcl.c:1.13 eggdrop1.7/src/tcl.c:1.14
--- eggdrop1.7/src/tcl.c:1.13	Sat Jul 23 16:57:36 2005
+++ eggdrop1.7/src/tcl.c	Sun Jul 31 00:51:07 2005
@@ -17,7 +17,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: tcl.c,v 1.13 2005/07/23 21:57:36 wcc Exp $
+ * $Id: tcl.c,v 1.14 2005/07/31 05:51:07 wcc Exp $
  */
 
 #include <stdlib.h>             /* getenv()                             */
@@ -233,6 +233,10 @@
   int *right; /* right side */
 } coupletinfo;
 
+/* FIXME: tcl_eggcouplet() should be redesigned so we can use
+ * TCL_TRACE_WRITES | TCL_TRACE_READS as the bit mask instead
+ * of 2 calls as is done in add_tcl_coups().
+ */
 /* Read/write integer couplets (int1:int2) */
 static char *tcl_eggcouplet(ClientData cdata, Tcl_Interp *irp,
                             EGG_CONST char *name1,
@@ -422,7 +426,6 @@
  */
 
 #ifdef USE_TCL_BYTE_ARRAYS
-
 static int utf_converter(ClientData cdata, Tcl_Interp *myinterp, int objc,
                          Tcl_Obj *CONST objv[])
 {
@@ -462,7 +465,9 @@
   nfree(cdata);
   clientdata_stuff -= sizeof(void *) * 2;
 }
+#endif /* USE_TCL_BYTE_ARRAYS */
 
+#ifdef USE_TCL_BYTE_ARRAYS
 void add_tcl_commands(tcl_cmds *table)
 {
   void **cdata;
@@ -478,6 +483,18 @@
   }
 }
 
+#else /* USE_TCL_BYTE_ARRAYS */
+
+void add_tcl_commands(tcl_cmds *table)
+{
+  int i;
+
+  for (i = 0; table[i].name; i++)
+    Tcl_CreateCommand(interp, table[i].name, table[i].func, NULL, NULL);
+}
+#endif /* USE_TCL_BYTE_ARRAYS */
+
+#ifdef USE_TCL_BYTE_ARRAYS
 void add_cd_tcl_cmds(cd_tcl_cmd *table)
 {
   void **cdata;
@@ -495,14 +512,6 @@
 
 #else /* USE_TCL_BYTE_ARRAYS */
 
-void add_tcl_commands(tcl_cmds *table)
-{
-  int i;
-
-  for (i = 0; table[i].name; i++)
-    Tcl_CreateCommand(interp, table[i].name, table[i].func, NULL, NULL);
-}
-
 void add_cd_tcl_cmds(cd_tcl_cmd *table)
 {
   while (table->name) {
@@ -511,7 +520,6 @@
     table++;
   }
 }
-
 #endif /* USE_TCL_BYTE_ARRAYS */
 
 void rem_tcl_commands(tcl_cmds *table)
@@ -530,16 +538,16 @@
   }
 }
 
+#ifdef USE_TCL_OBJ
 void add_tcl_objcommands(tcl_cmds *table)
 {
-#ifdef USE_TCL_OBJ
   int i;
 
   for (i = 0; table[i].name; i++)
     Tcl_CreateObjCommand(interp, table[i].name, table[i].func, (ClientData) 0,
                          NULL);
-#endif /* USE_TCL_OBJ */
 }
+#endif /* USE_TCL_OBJ */
 
 static tcl_strings def_tcl_strings[] = {
   {"botnet-nick",     botnetnick,     HANDLEN,                 0},
@@ -774,7 +782,9 @@
   add_tcl_commands(tcluser_cmds);
   add_tcl_commands(tcldcc_cmds);
   add_tcl_commands(tclmisc_cmds);
+#ifdef USE_TCL_OBJ
   add_tcl_objcommands(tclmisc_objcmds);
+#endif /* USE_TCL_OBJ */
   add_tcl_commands(tcldns_cmds);
 }
 
@@ -782,7 +792,6 @@
 {
   int code;
   char *result;
-
 #ifdef USE_TCL_ENCODING
   Tcl_DString dstr;
 #endif
Index: eggdrop1.7/src/tclhash.c
diff -u eggdrop1.7/src/tclhash.c:1.16 eggdrop1.7/src/tclhash.c:1.17
--- eggdrop1.7/src/tclhash.c:1.16	Sat Jul 30 22:49:35 2005
+++ eggdrop1.7/src/tclhash.c	Sun Jul 31 00:51:07 2005
@@ -17,7 +17,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: tclhash.c,v 1.16 2005/07/31 03:49:35 wcc Exp $
+ * $Id: tclhash.c,v 1.17 2005/07/31 05:51:07 wcc Exp $
  */
 
 #include "main.h"
@@ -646,165 +646,200 @@
     Tcl_AppendResult(irp, "invalid idx", NULL);
     return TCL_ERROR;
   }
-  if (F == NULL) {
+  /* FIXME: This is an ugly hack. It is not documented as a
+   *        'feature' because it will eventually go away.
+   */ 
+  if (F == CMD_LEAVE) {
     Tcl_AppendResult(irp, "break", NULL);
     return TCL_OK;
   }
+
   /* Check if it's a password change, if so, don't show the password. We
    * don't need pretty formats here, as it's only for debugging purposes.
    */
   debug4("tcl: builtin dcc call: %s %s %s %s", argv[0], argv[1], argv[2],
          (!strcmp(argv[0] + 5, "newpass") || !strcmp(argv[0] + 5, "chpass")) ?
          "[something]" : argv[3]);
-  (F) (dcc[idx].user, idx, argv[3]);
+  F(dcc[idx].user, idx, argv[3]);
   Tcl_ResetResult(irp);
   Tcl_AppendResult(irp, "0", NULL);
   return TCL_OK;
 }
 
-/* trigger (execute) a proc */
-static int trigger_bind(const char *proc, const char *param)
+
+/* Trigger (execute) a Tcl proc
+ *
+ * Note: This is INLINE code for check_tcl_bind().
+ */
+static inline int trigger_bind(const char *proc, const char *param,
+                               char *mask)
 {
   int x;
+  #ifdef DEBUG_CONTEXT
+  const char *msg = "Tcl proc: %s, param: %s";
+  char *buf;
 
   /* We now try to debug the Tcl_VarEval() call below by remembering both
    * the called proc name and it's parameters. This should render us a bit
    * less helpless when we see context dumps.
    */
-  {
-    const char *msg = "Tcl proc: %s, param: %s";
-    char *buf;
-
-    Context;
-    buf = nmalloc(strlen(msg) + (proc ? strlen(proc) : 6)
-                  + (param ? strlen(param) : 6) + 1);
-    sprintf(buf, msg, proc ? proc : "<null>", param ? param : "<null>");
-    ContextNote(buf);
-    nfree(buf);
-  }
+  Context;
+  buf = nmalloc(strlen(msg) + (proc ? strlen(proc) : 6)
+                + (param ? strlen(param) : 6) + 1);
+  sprintf(buf, msg, proc ? proc : "<null>", param ? param : "<null>");
+  ContextNote(buf);
+  nfree(buf);
+#endif /* DEBUG_CONTEXT */
+  Tcl_SetVar(interp, "lastbind", (char *) mask, TCL_GLOBAL_ONLY);
   x = Tcl_VarEval(interp, proc, param, NULL);
   Context;
+
+
   if (x == TCL_ERROR) {
     /* FIXME: we really should be able to log longer errors */
     if (strlen(interp->result) > 400)
       interp->result[400] = 0;
-    putlog(LOG_TCLERROR, "*", "Tcl error [%s]: %s", proc, interp->result);
+
+    putlog(LOG_MISC, "*", "Tcl error [%s]: %s", proc, interp->result);
+
     return BIND_EXECUTED;
-  } else {
-    if (!strcmp(interp->result, "break"))
-      return BIND_QUIT;
-    return (atoi(interp->result) > 0) ? BIND_EXEC_LOG : BIND_EXECUTED;
   }
+
+  /* FIXME: This is an ugly hack. It is not documented as a
+   *        'feature' because it will eventually go away.
+   */
+  if (!strcmp(interp->result, "break"))
+    return BIND_QUIT;
+
+  return (atoi(interp->result) > 0) ? BIND_EXEC_LOG : BIND_EXECUTED;
+}
+
+
+/* Find out whether this bind matches the mask or provides the
+ * requested attributes, depending on the specified requirements.
+ *
+ * Note: This is INLINE code for check_tcl_bind().
+ */
+static inline int check_bind_match(const char *match, char *mask,
+                                   int match_type)
+{
+  switch (match_type & 0x03) {
+  case MATCH_PARTIAL:
+    return (!egg_strncasecmp(match, mask, strlen(match)));
+    break;
+  case MATCH_EXACT:
+    return (!egg_strcasecmp(match, mask));
+    break;
+  case MATCH_CASE:
+    return (!strcmp(match, mask));
+    break;
+  case MATCH_MASK:
+    return (wild_match_per(mask, match));
+    break;
+  default:
+    /* Do nothing */
+    break;
+  }
+  return 0;
+}
+
+
+/* Check if the provided flags suffice for this command/trigger.
+ *
+ * Note: This is INLINE code for check_tcl_bind().
+ */
+static inline int check_bind_flags(struct flag_record *flags,
+                                   struct flag_record *atr, int match_type)
+{
+  if (match_type & BIND_USE_ATTR) {
+    if (match_type & BIND_HAS_BUILTINS)
+      return (flagrec_ok(flags, atr));
+    else
+      return (flagrec_eq(flags, atr));
+  } else
+    return 1;
+  return 0;
 }
 
-/* FIXME: this function is very ugly and really should be redesigned */
+
+/* Check for and process Tcl binds */
 int check_tcl_bind(tcl_bind_list_t *tl, const char *match,
                    struct flag_record *atr, const char *param, int match_type)
 {
+  int x, result = 0, cnt = 0, finish = 0;
+  char *proc = NULL, *mask = NULL;
   tcl_bind_mask_t *tm, *tm_last = NULL, *tm_p = NULL;
-  int cnt = 0, result = 0, finish = 0, atrok, x, ok;
-  char *proc = NULL, *fullmatch = NULL;
   tcl_cmd_t *tc, *htc = NULL;
 
   for (tm = tl->first; tm && !finish; tm_last = tm, tm = tm->next) {
+
     if (tm->flags & TBM_DELETED)
-      continue;
+      continue;                 /* This bind mask was deleted */
 
-    /* Find out whether this bind matches the mask or provides
-     * the the requested atcributes, depending on the specified
-     * requirements.
-     */
-    switch (match_type & 0x03) {
-    case MATCH_PARTIAL:
-      ok = !egg_strncasecmp(match, tm->mask, strlen(match));
-      break;
-    case MATCH_EXACT:
-      ok = !egg_strcasecmp(match, tm->mask);
-      break;
-    case MATCH_CASE:
-      ok = !strcmp(match, tm->mask);
-      break;
-    case MATCH_MASK:
-      ok = wild_match_per(tm->mask, match);
-      break;
-    default:
-      ok = 0;
-    }
-    if (!ok)
+    if (!check_bind_match(match, tm->mask, match_type))
       continue;                 /* This bind does not match. */
 
-    if (match_type & BIND_STACKABLE) {
+    for (tc = tm->first; tc; tc = tc->next) {
 
-      /* Could be multiple commands/triggers. */
-      for (tc = tm->first; tc; tc = tc->next) {
-        if (match_type & BIND_USE_ATTR) {
+      /* Search for valid entry. */
+      if (!(tc->attributes & TC_DELETED)) {
+
+        /* Check if the provided flags suffice for this command. */
+        if (check_bind_flags(&tc->flags, atr, match_type)) {
+          cnt++;
+          tm_p = tm_last;
+
+          /* Not stackable */
+          if (!(match_type & BIND_STACKABLE)) {
+
+            /* Remember information about this bind. */
+            proc = tc->func_name;
+            mask = tm->mask;
+            htc = tc;
+
+            /* Either this is a non-partial match, which means we
+             * only want to execute _one_ bind ...
+             */
+            if ((match_type & 0x03) != MATCH_PARTIAL ||
+              /* ... or this happens to be an exact match. */
+              !egg_strcasecmp(match, tm->mask)) {
+              cnt = 1;
+              finish = 1;
+            }
+
+            /* We found a match so break out of the inner loop. */
+            break;
+          }
 
-          /* Check whether the provided flags suffice for
-           * this command/trigger.
+          /*
+           * Stackable; could be multiple commands/triggers.
+           * Note: This code assumes BIND_ALTER_ARGS, BIND_WANTRET, and
+           *       BIND_STACKRET will only be used for stackable binds.
            */
-          if (match_type & BIND_HAS_BUILTINS)
-            atrok = flagrec_ok(&tc->flags, atr);
-          else
-            atrok = flagrec_eq(&tc->flags, atr);
-        } else
-          atrok = 1;
 
-        if (atrok) {
-          cnt++;
           tc->hits++;
-          tm_p = tm_last;
           Tcl_SetVar(interp, "lastbind", (char *) tm->mask, TCL_GLOBAL_ONLY);
-          x = trigger_bind(tc->func_name, param);
+          x = trigger_bind(tc->func_name, param, tm->mask);
+
           if (match_type & BIND_ALTER_ARGS) {
+
             if (interp->result == NULL || !interp->result[0])
               return x;
+
           } else if ((match_type & BIND_STACKRET) && x == BIND_EXEC_LOG) {
 
-            /* If we have multiple commands/triggers,
-             * and if any of the commands return 1, we accept it.
+            /* If we have multiple commands/triggers, and if any of the
+             * commands return 1, we store the result so we can return it
+             * after processing all stacked binds.
              */
             if (!result)
               result = x;
             continue;
-          } else if ((match_type & BIND_WANTRET) && x == BIND_EXEC_LOG)
-            return x;
-        }
-      }
-    } else {
 
-      /* Search for valid entry. */
-      for (tc = tm->first; tc; tc = tc->next)
-        if (!(tc->attributes & TC_DELETED))
-          break;
-      if (tc) {
-
-        /* Check if the provided flags suffice for this command/trigger. */
-        if (match_type & BIND_USE_ATTR) {
-          if (match_type & BIND_HAS_BUILTINS)
-            atrok = flagrec_ok(&tc->flags, atr);
-          else
-            atrok = flagrec_eq(&tc->flags, atr);
-        } else
-          atrok = 1;
-
-        if (atrok) {
-          cnt++;
-
-          /* Remember information about this bind and its only
-           * command/trigger.
-           */
-          proc = tc->func_name;
-          fullmatch = tm->mask;
-          htc = tc;
-          tm_p = tm_last;
+          } else if ((match_type & BIND_WANTRET) && x == BIND_EXEC_LOG)
 
-          /* Either this is a non-partial match, which means we
-           * only want to execute _one_ bind ...
-           */
-          if ((match_type & 3) != MATCH_PARTIAL ||
-              /* ... or this is happens to be an exact match. */
-              !egg_strcasecmp(match, tm->mask))
-            cnt = finish = 1;
+            /* Return immediately if any commands return 1 */
+            return x;
         }
       }
     }
@@ -839,10 +874,10 @@
   if (cnt > 1)
     return BIND_AMBIGUOUS;
 
-  Tcl_SetVar(interp, "lastbind", (char *) fullmatch, TCL_GLOBAL_ONLY);
-  return trigger_bind(proc, param);
+  return trigger_bind(proc, param, mask);
 }
 
+
 /* Check for tcl-bound dcc command, return 1 if found
  * dcc: proc-name <handle> <sock> <args...>
  */
@@ -867,8 +902,11 @@
     dprintf(idx, MISC_NOSUCHCMD);
     return 0;
   }
-  if (x == BIND_QUIT)
-    return 1;                   /* quit */
+
+  /* We return 1 to leave the partyline */
+  if (x == BIND_QUIT)           /* CMD_LEAVE, 'quit' */
+    return 1;
+
   if (x == BIND_EXEC_LOG)
     putlog(LOG_CMDS, "*", "#%s# %s %s", dcc[idx].nick, cmd, args);
   return 0;
Index: eggdrop1.7/src/tclhash.h
diff -u eggdrop1.7/src/tclhash.h:1.3 eggdrop1.7/src/tclhash.h:1.4
--- eggdrop1.7/src/tclhash.h:1.3	Thu Jan 20 19:43:40 2005
+++ eggdrop1.7/src/tclhash.h	Sun Jul 31 00:51:07 2005
@@ -17,7 +17,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: tclhash.h,v 1.3 2005/01/21 01:43:40 wcc Exp $
+ * $Id: tclhash.h,v 1.4 2005/07/31 05:51:07 wcc Exp $
  */
 
 #ifndef _EGG_TCLHASH_H
@@ -32,6 +32,7 @@
 
   struct flag_record flags;
   char *func_name;              /* Proc name. */
+  /* FIXME: 'hits' could overflow if a bind is triggered enough. */
   int hits;                     /* Number of times this proc was triggered. */
   u_8bit_t attributes;          /* Flags for this entry. TC_* */
 } tcl_cmd_t;
@@ -44,7 +45,7 @@
 
   tcl_cmd_t *first;             /* List of commands registered for this bind. */
   char *mask;
-  u_8bit_t flags;               /* Flags for this entry. TBM_*  */
+  u_8bit_t flags;               /* Flags for this entry. TBM_* */
 } tcl_bind_mask_t;
 
 
@@ -54,9 +55,8 @@
 typedef struct tcl_bind_list_b {
   struct tcl_bind_list_b *next;
 
-  tcl_bind_mask_t *first;       /* Pointer to registered binds
-                                 * for this list.               */
-  char name[5];                 /* Name of the bind.            */
+  tcl_bind_mask_t *first;       /* Pointer to registered binds for this list. */
+  char name[5];                 /* Name of the bind. */
   u_8bit_t flags;               /* Flags for this element. HT_* */
   Function func;                /* Function used as the Tcl calling interface
                                  * for procs actually representing C functions. */
----------------------- End of diff -----------------------



More information about the Changes mailing list