[eggheads-patches] PATCH: rfc2.patch

Fabian Knittel fknittel at gmx.de
Wed Oct 6 14:40:32 CST 1999


[ rfc2.patch ]

This patch changes the RFC_COMPLIANT compile-time flag into
a dynamic run-time variable. The rfc_ function pointers are
updated as soon as the rfc-compliant variable is modified.

It also fixes delhost_by_handle() to correctly remove every
matching host. Without this fix, it would only delete all
matching hosts if the very first matching host was the second
in the host list... and it was may, raining, and the stars
where in the right position.

This will probably conflict with the assert patch by rtc in
a few places.

Fabian
-------------- next part --------------
diff -urN eggdrop1.3~/Makefile.in eggdrop1.3/Makefile.in
--- eggdrop1.3~/Makefile.in	Tue Oct  5 16:39:48 1999
+++ eggdrop1.3/Makefile.in	Wed Oct  6 13:19:02 1999
@@ -14,7 +14,7 @@
 #                      usually detects this anyway now)
 #   -DEBUG_MEM       to be able to debug memory allocation (.debug)
 # this can now be set by using 'make debugmem'
-CFLGS = -DRFC_COMPLIANT
+CFLGS = 
 
 # configure SHOULD set these...you may need to tweak them to get modules
 # to compile .. if you do...let the devel-team know the working settings
diff -urN eggdrop1.3~/configure eggdrop1.3/configure
--- eggdrop1.3~/configure	Tue Oct  5 11:26:18 1999
+++ eggdrop1.3/configure	Wed Oct  6 13:19:03 1999
@@ -3080,9 +3080,5 @@
 echo ""
 echo "Configure is done."
 echo ""
-echo "If your bot will be on Dalnet, or a network that uses their server"
-echo "code, please edit the Makefile and remove \"-DRFC_COMPLIANT\" from"
-echo "the \"CFLGS=\" line."
-echo ""
 echo "Type 'make' to create the bot"
 echo ""
diff -urN eggdrop1.3~/configure.in eggdrop1.3/configure.in
--- eggdrop1.3~/configure.in	Tue Oct  5 11:26:18 1999
+++ eggdrop1.3/configure.in	Wed Oct  6 13:19:03 1999
@@ -574,9 +574,5 @@
 echo ""
 echo "Configure is done."
 echo ""
-echo "If your bot will be on Dalnet, or a network that uses their server"
-echo "code, please edit the Makefile and remove \"-DRFC_COMPLIANT\" from"
-echo "the \"CFLGS=\" line."
-echo ""
 echo "Type 'make' to create the bot"
 echo ""
diff -urN eggdrop1.3~/doc/UPDATES1.3 eggdrop1.3/doc/UPDATES1.3
--- eggdrop1.3~/doc/UPDATES1.3	Tue Oct  5 23:11:10 1999
+++ eggdrop1.3/doc/UPDATES1.3	Wed Oct  6 13:20:24 1999
@@ -4,6 +4,8 @@
 
 1.3.29
 Foundby   Fixedby   What....
+ 	  Fabian/   Changed RFC_COMPLIANT flag to dynamic variable setting
+	  drummer
 SuperS	  Fabian    if run with '-n', eggdrop now only prints every line once
 mc	  Fabian    distributed Makefile now only issues a warning instead of
 		    automatically starting to configure and compile
diff -urN eggdrop1.3~/eggdrop.conf.dist eggdrop1.3/eggdrop.conf.dist
--- eggdrop1.3~/eggdrop.conf.dist	Tue Oct  5 14:52:03 1999
+++ eggdrop1.3/eggdrop.conf.dist	Wed Oct  6 13:19:04 1999
@@ -943,6 +943,11 @@
 # Only use this if you set net-type 5
 #set use-354 0
 
+# [0/1] use rfc 1459 compliant string matching routines?
+# All networks apart from Dalnet comply with rfc 1459, so you should only
+# disable it on Dalnet or networks which use Dalnet's code.
+#set rfc-compliant 1
+
 
 
 ##### TRANSFER MODULE #####
diff -urN eggdrop1.3~/src/Makefile eggdrop1.3/src/Makefile
--- eggdrop1.3~/src/Makefile	Tue Oct  5 11:26:41 1999
+++ eggdrop1.3/src/Makefile	Wed Oct  6 13:19:04 1999
@@ -167,6 +167,8 @@
    users.h
 net.o: \
    main.h
+rfc1459.o: \
+   main.h
 tcl.o: \
    main.h
 tcldcc.o: \
diff -urN eggdrop1.3~/src/main.h eggdrop1.3/src/main.h
--- eggdrop1.3~/src/main.h	Tue Oct  5 11:27:11 1999
+++ eggdrop1.3/src/main.h	Wed Oct  6 13:33:30 1999
@@ -39,7 +39,6 @@
 #include "tclhash.h"
 #include "chan.h"
 #include "users.h"
-#include "rfc1459.h"
 
 #ifndef MAKING_MODS
 extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_SCRIPT, DCC_BOT_NEW,
diff -urN eggdrop1.3~/src/match.c eggdrop1.3/src/match.c
--- eggdrop1.3~/src/match.c	Tue Oct  5 11:26:44 1999
+++ eggdrop1.3/src/match.c	Wed Oct  6 13:19:04 1999
@@ -23,9 +23,9 @@
 
 /* This will get us around most of the mess and replace the chunk that
  * was removed from the middle of this file.   --+ Dagmar */
-/* You'll also want to grab the two rfc1459.* files to make this work
- * with ircII derivatives now, as if it weren't obvious already.  ;) */
-#include "rfc1459.h"
+/* You'll also want to grab the rfc1459.c file or change all rfc_*()
+ * calls to the standard library call to make this work with ircII
+ * derivatives now. */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
diff -urN eggdrop1.3~/src/mod/irc.mod/irc.c eggdrop1.3/src/mod/irc.mod/irc.c
--- eggdrop1.3~/src/mod/irc.mod/irc.c	Tue Oct  5 11:26:33 1999
+++ eggdrop1.3/src/mod/irc.mod/irc.c	Wed Oct  6 13:33:15 1999
@@ -56,6 +56,9 @@
 static int prevent_mixing=1; /* to prevent mixing old/new modes */
 static int revenge_mode = 1;	/* 0 = deop, 1 = and +d, 2 = and kick,
 				 * 3 = and ban */
+static int rfc_compliant = 1; /* net-type changing modify this, but
+			       * requires ircmod reload. drummer/9/12/1999 */
+
 
 #include "chan.c"
 #include "mode.c"
@@ -882,6 +885,7 @@
   {"keep-nick", &keepnick, 0},	/* guppy */
   {"prevent-mixing", &prevent_mixing, 0},
   {"revenge-mode", &revenge_mode, 0},
+  {"rfc-compliant", &rfc_compliant, 0},
   {0, 0, 0}			/* arthur2 */
 };
 
@@ -950,6 +954,7 @@
     use_silence = 0;
     use_exempts = 0;
     use_invites = 0;
+    rfc_compliant = 1;
     break;
   case 1:		/* Ircnet */
     kick_method = 4;
@@ -958,6 +963,7 @@
     use_silence = 0;
     use_exempts = 1;
     use_invites = 1;
+    rfc_compliant = 1;
     break;
   case 2:		/* Undernet */
     kick_method = 1;
@@ -966,6 +972,7 @@
     use_silence = 1;
     use_exempts = 0;
     use_invites = 0;
+    rfc_compliant = 1;
     break;
   case 3:		/* Dalnet */
     kick_method = 1;
@@ -974,6 +981,7 @@
     use_silence = 0;
     use_exempts = 0;
     use_invites = 0;
+    rfc_compliant = 0;
     break;
   case 4:		/* new +e/+I Efnet hybrid */
     kick_method = 1;
@@ -982,10 +990,13 @@
     use_silence = 0;
     use_exempts = 1;
     use_invites = 1;
+    rfc_compliant = 1;
     break;
   default:
     break;
   }
+  /* Update all rfc_ function pointers */
+  add_hook(HOOK_RFC_CASECMP, (void *) rfc_compliant);
 }
 
 static char *traced_nettype(ClientData cdata, Tcl_Interp * irp, char *name1,
@@ -995,6 +1006,16 @@
   return NULL;
 }
 
+static char *traced_rfccompliant(ClientData cdata, Tcl_Interp * irp,
+				 char *name1, char *name2, int flags)
+{
+  /* This hook forces eggdrop core to change the rfc_ match function
+   * links to point to the rfc compliant versions if rfc_compliant
+   * is 1, or to the normal version if it's 0 */
+  add_hook(HOOK_RFC_CASECMP, (void *) rfc_compliant);
+  return NULL;
+}
+
 static int irc_expmem()
 {
   return 0;
@@ -1033,6 +1054,9 @@
   del_hook(HOOK_5MINUTELY, log_chans);
   del_hook(HOOK_ADD_MODE, real_add_mode);
   del_hook(HOOK_IDLE, flush_modes);
+  Tcl_UntraceVar(interp, "rfc-compliant",
+		 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
+		 traced_rfccompliant, NULL);
   Tcl_UntraceVar(interp, "net-type",
 		 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 		 traced_nettype, NULL);
@@ -1101,6 +1125,9 @@
   Tcl_TraceVar(interp, "net-type",
 	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 	       traced_nettype, NULL);
+  Tcl_TraceVar(interp, "rfc-compliant",
+	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
+	       traced_rfccompliant, NULL);
   context;
   add_tcl_ints(myints);
   add_builtins(H_dcc, irc_dcc);
diff -urN eggdrop1.3~/src/mod/module.h eggdrop1.3/src/mod/module.h
--- eggdrop1.3~/src/mod/module.h	Tue Oct  5 11:26:24 1999
+++ eggdrop1.3/src/mod/module.h	Wed Oct  6 13:19:04 1999
@@ -301,8 +301,8 @@
 /* 216 - 219 */
 #define min_dcc_port (*(int *)(global[216]))	/* dcc-portrange dw/guppy */
 #define max_dcc_port (*(int *)(global[217]))
-#define rfc_casecmp ((int(*)(char *, char *))global[218])
-#define rfc_ncasecmp ((int(*)(char *, char *, int *))global[219])
+#define rfc_casecmp ((int(*)(char *, char *))(*(Function**)(global[218])))
+#define rfc_ncasecmp ((int(*)(char *, char *, int *))(*(Function**)(global[219])))
 /* 220 - 223 */
 #define global_exempts (*(maskrec **)(global[220]))
 #define global_invites (*(maskrec **)(global[221]))
@@ -318,9 +318,8 @@
 #define user_realloc(x,y) ((void *(*)(void *,int,char *,int))global[229])((x),(y),__FILE__,__LINE__)
 #define nrealloc(x,y) ((void *)(global[230]((x),(y),MODULE_NAME,__FILE__,__LINE__)))
 #define xtra_set ((int(*)(struct userrec *,struct user_entry *, void *))global[231])
-
-/* time to let modules use contextnote <cybah> */
-#define contextnote(note) (global[230](MODULE_NAME, __FILE__, __LINE__, note))
+/* 232 - 235 */
+#define contextnote(note) (global[235](MODULE_NAME, __FILE__, __LINE__, note))
 
 /* this is for blowfish module, couldnt be bothereed making a whole new .h
  * file for it ;) */
diff -urN eggdrop1.3~/src/mod/modvals.h eggdrop1.3/src/mod/modvals.h
--- eggdrop1.3~/src/mod/modvals.h	Tue Oct  5 11:26:24 1999
+++ eggdrop1.3/src/mod/modvals.h	Wed Oct  6 13:19:04 1999
@@ -19,6 +19,7 @@
 #define HOOK_QSERV               108
 #define HOOK_ADD_MODE            109
 #define HOOK_MATCH_NOTEREJ	 110
+#define HOOK_RFC_CASECMP	 111
 
 /* these are FIXED once they are in a release they STAY
  * well, unless im feeling grumpy ;) */
diff -urN eggdrop1.3~/src/modules.c eggdrop1.3/src/modules.c
--- eggdrop1.3~/src/modules.c	Tue Oct  5 11:26:45 1999
+++ eggdrop1.3/src/modules.c	Wed Oct  6 13:19:04 1999
@@ -13,6 +13,7 @@
 #include "main.h"
 #include "modules.h"
 #include "tandem.h"
+#include <ctype.h>
 #ifndef STATIC
 #ifdef HPUX_HACKS
 #include <dl.h>
@@ -134,6 +135,10 @@
 void (*qserver) (int, char *, int) = null_func;
 void (*add_mode) () = null_func;
 int (*match_noterej) (struct userrec*, char *) = false_func;
+int (*rfc_casecmp) (const char *, const char *) = _rfc_casecmp;
+int (*rfc_ncasecmp) (const char *, const char *, int) = _rfc_ncasecmp;
+int (*rfc_toupper) (int) = _rfc_toupper;
+int (*rfc_tolower) (int) = _rfc_tolower;
 
 module_entry *module_list;
 dependancy *dependancy_list = NULL;
@@ -442,13 +447,13 @@
   /* 216 - 219 */
   (Function) & min_dcc_port,	/* dw */
   (Function) & max_dcc_port,
-  (Function) rfc_casecmp,
-  (Function) rfc_ncasecmp,
- /* 220 - 223 */
-  (Function) &global_exempts,	/* struct exemptrec * */
-  (Function) &global_invites,	/* struct inviterec * */
-  (Function) &gexempt_total,	/* int */
-  (Function) &ginvite_total,	/* int */
+  (Function) & rfc_casecmp,	/* Function * */
+  (Function) & rfc_ncasecmp,	/* Function * */
+  /* 220 - 223 */
+  (Function) & global_exempts,	/* struct exemptrec * */
+  (Function) & global_invites,	/* struct inviterec * */
+  (Function) & gexempt_total,	/* int */
+  (Function) & ginvite_total,	/* int */
   /* 224 - 227 */
   (Function) & H_event,
   (Function) & use_exempts,	/* int - drummer/Jason */
@@ -874,6 +879,20 @@
     case HOOK_ADD_MODE:
       if (add_mode == null_func)
 	add_mode = func;
+      break;
+    /* special hook <drummer> */
+    case HOOK_RFC_CASECMP:
+      if (func == 0) {
+	rfc_casecmp = (void *) strcasecmp;
+	rfc_ncasecmp = (void *) strncasecmp;
+	rfc_tolower = (void *) tolower;
+	rfc_toupper = (void *) toupper;
+      } else {
+	rfc_casecmp = _rfc_casecmp;
+	rfc_ncasecmp = _rfc_ncasecmp;
+	rfc_tolower = _rfc_tolower;
+	rfc_toupper = _rfc_toupper;
+      }
       break;
     case HOOK_MATCH_NOTEREJ:
       if (match_noterej == false_func)
diff -urN eggdrop1.3~/src/proto.h eggdrop1.3/src/proto.h
--- eggdrop1.3~/src/proto.h	Tue Oct  5 11:26:45 1999
+++ eggdrop1.3/src/proto.h	Wed Oct  6 13:19:04 1999
@@ -39,8 +39,13 @@
 extern void (*encrypt_pass) (char *, char *);
 extern char *(*encrypt_string) (char *, char *);
 extern char *(*decrypt_string) (char *, char *);
-
+extern int (*rfc_casecmp) (const char *, const char *);
+extern int (*rfc_ncasecmp) (const char *, const char *, int);
+extern int (*rfc_toupper) (int);
+extern int (*rfc_tolower) (int);
+extern int (*match_noterej) (struct userrec *, char *);
 #endif
+
 /* botcmd.c */
 void bot_share(int, char *);
 int base64_to_int(char *);
@@ -80,7 +85,6 @@
 char *int_to_base10(int);
 char *unsigned_int_to_base10(unsigned int);
 char *int_to_base64(unsigned int);
-extern int (*match_noterej) (struct userrec*, char *);
 
 /* chanprog.c */
 void tell_verbose_uptime(int);
@@ -257,7 +261,9 @@
 int readuserfile(char *, struct userrec **);
 
 /* rfc1459.c */
-int rfc_casecmp(char *, char *);
-int rfc_ncasecmp(char *, char *, int);
+int _rfc_casecmp(const char *, const char *);
+int _rfc_ncasecmp(const char *, const char *, int);
+int _rfc_toupper(int);
+int _rfc_tolower(int);
 
 #endif
diff -urN eggdrop1.3~/src/rfc1459.c eggdrop1.3/src/rfc1459.c
--- eggdrop1.3~/src/rfc1459.c	Tue Oct  5 11:26:45 1999
+++ eggdrop1.3/src/rfc1459.c	Wed Oct  6 13:19:05 1999
@@ -19,12 +19,9 @@
  * ===================================================================
  */
 
-#include "rfc1459.h"
-#include <string.h>
+#include "main.h"
 
-#ifdef RFC_COMPLIANT
-
-int rfc_casecmp(char *s1, char *s2)
+int _rfc_casecmp(const char *s1, const char *s2)
 {
   register unsigned char *str1 = (unsigned char *) s1;
   register unsigned char *str2 = (unsigned char *) s2;
@@ -39,7 +36,7 @@
   return (res);
 }
 
-int rfc_ncasecmp(char *str1, char *str2, int n)
+int _rfc_ncasecmp(const char *str1, const char *str2, int n)
 {
   register unsigned char *s1 = (unsigned char *) str1;
   register unsigned char *s2 = (unsigned char *) str2;
@@ -55,6 +52,19 @@
   return (res);
 }
 
+unsigned char rfc_tolowertab[];
+unsigned char rfc_touppertab[];
+
+int _rfc_tolower(int c)
+{
+  return rfc_tolowertab[(unsigned char)(c)];
+}
+
+int _rfc_toupper(int c)
+{
+  return rfc_touppertab[(unsigned char)(c)];
+}
+
 unsigned char rfc_tolowertab[] =
 {0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
  0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
@@ -122,15 +132,3 @@
  0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
  0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
-
-#else				/* Dalnet?? */
-
-int rfc_casecmp(char *s1, char *s2) {
-  return strcasecmp(s1, s2);
-}
-
-int rfc_ncasecmp(char *s1, char *s2, int n) {
-  return strncasecmp(s1, s2, n);
-}
-
-#endif				/* RFC_COMPLIANT */
diff -urN eggdrop1.3~/src/rfc1459.h eggdrop1.3/src/rfc1459.h
--- eggdrop1.3~/src/rfc1459.h	Tue Oct  5 11:26:45 1999
+++ eggdrop1.3/src/rfc1459.h	Thu Jan  1 01:00:00 1970
@@ -1,15 +0,0 @@
-/* 
- * This should make things properly case insensitive with respect to RFC 1459
- * or at least get them doing things the same way the IRCd does.
- */
-#include <ctype.h>
-
-#ifdef RFC_COMPLIANT
-#define rfc_tolower(c) (rfc_tolowertab[(unsigned char)(c)])
-#define rfc_toupper(c) (rfc_touppertab[(unsigned char)(c)])
-extern unsigned char rfc_tolowertab[];
-extern unsigned char rfc_touppertab[];
-#else				/* Dalnet?? */
-#define rfc_tolower(c) tolower(c)
-#define rfc_toupper(c) toupper(c)
-#endif				/* RFC_COMPLIANT */
diff -urN eggdrop1.3~/src/userrec.c eggdrop1.3/src/userrec.c
--- eggdrop1.3~/src/userrec.c	Tue Oct  5 11:26:47 1999
+++ eggdrop1.3/src/userrec.c	Wed Oct  6 13:19:05 1999
@@ -709,34 +709,45 @@
 int delhost_by_handle(char *handle, char *host)
 {
   struct userrec *u;
-  struct list_type *q, *t = 0;
-  struct user_entry *e;
+  struct list_type *q, *qnext, *qprev;
+  struct user_entry *e = NULL;
   int i = 0;
 
   context;
   u = get_user_by_handle(userlist, handle);
-  if (u == NULL)
+  if (!u)
     return 0;
   q = get_user(&USERENTRY_HOSTS, u);
-  if (q && !rfc_casecmp(q->extra, host)) {
-    e = find_user_entry(&USERENTRY_HOSTS, u);
-    e->u.extra = t = q->next;
-    nfree(q->extra);
-    nfree(q);
-    i = 1;
-    q = t;
-  } else if (q)
-    while (q->next) {
-      if (!rfc_casecmp(q->next->extra, host)) {
-	t = q->next;
-	q->next = t->next;
-	nfree(t->extra);
-	nfree(t);
-	i = 1;
+  qprev = q;
+  if (q) {
+    if (!rfc_casecmp(q->extra, host)) {
+      e = find_user_entry(&USERENTRY_HOSTS, u);
+      e->u.extra = q->next;
+      nfree(q->extra);
+      nfree(q);
+      i++;
+      qprev = NULL;
+      q = e->u.extra;
+    } else
+      q = q->next;
+    while (q) {
+      qnext = q->next;
+      if (!rfc_casecmp(q->extra, host)) {
+	if (qprev)
+	  qprev->next = q->next;
+	else if (e) {
+	  e->u.extra = q->next;
+	  qprev = NULL;
+	}
+	nfree(q->extra);
+	nfree(q);
+	i++;
       } else
-	q = q->next;
+        qprev = q;
+      q = qnext;
     }
-  if (!q)
+  }
+  if (!qprev)
     set_user(&USERENTRY_HOSTS, u, "none");
   if (!noshare && i && !(u->flags & USER_UNSHARED))
     shareout(NULL, "-h %s %s\n", handle, host);


More information about the Patches mailing list