[cvslog] (2002-10-11 06:56:12 UTC) Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Fri Oct 11 01:57:01 CST 2002


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2002-10-11 06:56:12 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/compat/compat.h lib/compat/strdup.h lib/eggdrop/Makefile.am
     lib/eggdrop/flags.h lib/eggdrop/users.c lib/eggdrop/users.h
     src/scriptuser.c

Log message:

* Made 'uset' bind to intercept user settings, and 'uflag' bind for user flags. Next comes 'uhost' I guess.

---------------------- diff included ----------------------
Index: eggdrop1.7/lib/compat/compat.h
diff -u eggdrop1.7/lib/compat/compat.h:1.8 eggdrop1.7/lib/compat/compat.h:1.9
--- eggdrop1.7/lib/compat/compat.h:1.8	Sat May 18 02:41:33 2002
+++ eggdrop1.7/lib/compat/compat.h	Fri Oct 11 01:56:02 2002
@@ -21,11 +21,16 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 /*
- * $Id: compat.h,v 1.8 2002/05/18 07:41:33 stdarg Exp $
+ * $Id: compat.h,v 1.9 2002/10/11 06:56:02 stdarg Exp $
  */
 
 #ifndef _EGG_COMPAT_H
 #define _EGG_COMPAT_H
+
+/* Include config.h */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 /*
  * Include prototypes
Index: eggdrop1.7/lib/compat/strdup.h
diff -u eggdrop1.7/lib/compat/strdup.h:1.3 eggdrop1.7/lib/compat/strdup.h:1.4
--- eggdrop1.7/lib/compat/strdup.h:1.3	Sun May  5 11:40:32 2002
+++ eggdrop1.7/lib/compat/strdup.h	Fri Oct 11 01:56:02 2002
@@ -21,18 +21,18 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 /*
- * $Id: strdup.h,v 1.3 2002/05/05 16:40:32 tothwolf Exp $
+ * $Id: strdup.h,v 1.4 2002/10/11 06:56:02 stdarg Exp $
  */
 
 #ifndef _EGG_STRDUP_H
 #define _EGG_STRDUP_H
 
 #ifdef HAVE_CONFIG_H
-# include "config.h"
+# include <config.h>
 #endif
 
 #ifndef HAVE_STRDUP
-const char *strdup(const char *);
+char *strdup(const char *);
 #endif
 
 #endif				/* !_EGG_STRDUP_H */
Index: eggdrop1.7/lib/eggdrop/Makefile.am
diff -u eggdrop1.7/lib/eggdrop/Makefile.am:1.11 eggdrop1.7/lib/eggdrop/Makefile.am:1.12
--- eggdrop1.7/lib/eggdrop/Makefile.am:1.11	Wed Oct  9 23:41:58 2002
+++ eggdrop1.7/lib/eggdrop/Makefile.am	Fri Oct 11 01:56:02 2002
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.11 2002/10/10 04:41:58 stdarg Exp $
+# $Id: Makefile.am,v 1.12 2002/10/11 06:56:02 stdarg Exp $
 
 MAINTAINERCLEANFILES	= Makefile.in
 
@@ -16,6 +16,7 @@
 			eggnet.h eggnet.c \
 			eggtimer.c eggtimer.h \
 			fileutil.c fileutil.h \
+			flags.c flags.h \
 			hash_table.c hash_table.h \
 			ircmasks.c ircmasks.h \
 			linemode.c linemode.h \
Index: eggdrop1.7/lib/eggdrop/flags.h
diff -u eggdrop1.7/lib/eggdrop/flags.h:1.2 eggdrop1.7/lib/eggdrop/flags.h:1.3
--- eggdrop1.7/lib/eggdrop/flags.h:1.2	Wed Oct  9 04:09:40 2002
+++ eggdrop1.7/lib/eggdrop/flags.h	Fri Oct 11 01:56:02 2002
@@ -6,4 +6,9 @@
 	int udef;
 } flags_t;
 
+/* str should be at least 26+26+1 = 53 bytes. */
+int flag_to_str(flags_t *flags, char *str);
+int flag_merge_str(flags_t *flags, char *str);
+int flag_from_str(flags_t *flags, char *str);
+
 #endif
Index: eggdrop1.7/lib/eggdrop/users.c
diff -u eggdrop1.7/lib/eggdrop/users.c:1.3 eggdrop1.7/lib/eggdrop/users.c:1.4
--- eggdrop1.7/lib/eggdrop/users.c:1.3	Wed Oct  9 23:41:59 2002
+++ eggdrop1.7/lib/eggdrop/users.c	Fri Oct 11 01:56:02 2002
@@ -2,13 +2,17 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "eggdrop.h"
+#include "binds.h"
+#include "flags.h"
 #include "users.h"
 #include "ircmasks.h"
 #include "hash_table.h"
 #include "xml.h"
-#include "flags.h"
 #include "match.h"
 
+static FILE *fp = NULL;
+
 /* When we walk along irchost_cache_ht, we pass along this struct so the
  * function can keep track of modified entries. */
 typedef struct {
@@ -34,6 +38,10 @@
 /* List to keep all users' ircmasks in. */
 static ircmask_list_t ircmask_list = {NULL};
 
+/* Bind tables. */
+static bind_table_t *BT_uflags = NULL,	/* user flags */
+	*BT_uset = NULL;	/* settings */
+
 /* Prototypes for internal functions. */
 static user_t *real_user_new(const char *handle, int uid);
 static int user_get_uid();
@@ -43,12 +51,16 @@
 
 int user_init()
 {
+	fp = fopen("users.log", "a");
+
 	/* Create hash tables. */
 	handle_ht = hash_table_create(NULL, NULL, USER_HASH_SIZE, HASH_TABLE_STRINGS);
 	uid_ht = hash_table_create(NULL, NULL, USER_HASH_SIZE, HASH_TABLE_INTS);
 	irchost_cache_ht = hash_table_create(NULL, NULL, HOST_HASH_SIZE, HASH_TABLE_STRINGS);
 
 	/* And bind tables. */
+	BT_uflags = bind_table_add("uflag", 4, "ssss", MATCH_MASK, 0);
+	BT_uset = bind_table_add("uset", 4, "ssss", MATCH_MASK, 0);
 	return(0);
 }
 
@@ -75,10 +87,6 @@
 		xml_node_get_int(&uid, user_node, "uid", 0, 0);
 		if (!handle || !uid) break;
 		u = real_user_new(handle, uid);
-		xml_node_get_str(&u->pass, user_node, "password", 0, 0);
-		if (u->pass) u->pass = strdup(u->pass);
-		xml_node_get_str(&u->salt, user_node, "salt", 0, 0);
-		if (u->salt) u->salt = strdup(u->salt);
 		for (j = 0; ; j++) {
 			xml_node_get_str(&ircmask, user_node, "ircmask", j, 0);
 			if (!ircmask) break;
@@ -93,8 +101,8 @@
 			u->settings = realloc(u->settings, sizeof(*u->settings) * (j+1));
 			u->nsettings++;
 			setting = u->settings+j;
-			xml_node_get_int(&setting->flags, setting_node, "flags", 0, 0);
-			xml_node_get_int(&setting->udef_flags, setting_node, "udef_flags", 0, 0);
+			xml_node_get_int(&setting->flags.builtin, setting_node, "builtin_flags", 0, 0);
+			xml_node_get_int(&setting->flags.udef, setting_node, "udef_flags", 0, 0);
 			setting->nextended = 0;
 			setting->extended = NULL;
 			xml_node_get_str(&chan, setting_node, "chan", 0, 0);
@@ -134,16 +142,14 @@
 	user_node->name = strdup("user");
 	xml_node_set_str(u->handle, user_node, "handle", 0, 0);
 	xml_node_set_int(u->uid, user_node, "uid", 0, 0);
-	if (u->pass) xml_node_set_str(u->pass, user_node, "password", 0, 0);
-	if (u->salt) xml_node_set_str(u->salt, user_node, "salt", 0, 0);
 	for (i = 0; i < u->nircmasks; i++) {
 		xml_node_set_str(u->ircmasks[i], user_node, "ircmask", i, 0);
 	}
 	for (i = 0; i < u->nsettings; i++) {
 		setting = u->settings+i;
 		if (setting->chan) xml_node_set_str(setting->chan, user_node, "setting", i, "chan", 0, 0);
-		xml_node_set_int(u->settings[i].flags, user_node, "setting", i, "flags", 0, 0);
-		xml_node_set_int(u->settings[i].udef_flags, user_node, "setting", i, "udef_flags", 0, 0);
+		xml_node_set_int(u->settings[i].flags.builtin, user_node, "setting", i, "builtin_flags", 0, 0);
+		xml_node_set_int(u->settings[i].flags.udef, user_node, "setting", i, "udef_flags", 0, 0);
 		for (j = 0; j < setting->nextended; j++) {
 			xml_node_set_str(setting->extended[j].name, user_node, "setting", i, "extended", j, "name", 0, 0);
 			xml_node_set_str(setting->extended[j].value, user_node, "setting", i, "extended", j, "value", 0, 0);
@@ -201,10 +207,6 @@
 	if (!uid) uid = user_get_uid();
 	u->uid = uid;
 
-	/* All users have the global setting by default. */
-	u->settings = calloc(1, sizeof(*u->settings));
-	u->nsettings = 1;
-
 	hash_table_insert(handle_ht, u->handle, u);
 	hash_table_insert(uid_ht, (void *)u->uid, u);
 	hash_table_check_resize(&handle_ht);
@@ -215,9 +217,16 @@
 user_t *user_new(const char *handle)
 {
 	int uid;
+	user_t *u;
 
 	uid = user_get_uid();
-	return real_user_new(handle, uid);
+	u = real_user_new(handle, uid);
+
+	/* All users have the global setting by default. */
+	u->settings = calloc(1, sizeof(*u->settings));
+	u->nsettings = 1;
+
+	return(u);
 }
 
 int user_delete(user_t *u)
@@ -238,12 +247,6 @@
 	u->ircmasks = NULL;
 	u->nircmasks = 0;
 
-	/* The password. */
-	if (u->pass) free(u->pass);
-	if (u->salt) free(u->salt);
-	u->pass = NULL;
-	u->salt = NULL;
-
 	/* And all of the settings. */
 	for (i = 0; i < u->nsettings; i++) {
 		setting = u->settings+i;
@@ -403,7 +406,7 @@
 	return(0);
 }
 
-static int get_flags(user_t *u, const char *chan, int **flags, int **udef)
+static int get_flags(user_t *u, const char *chan, flags_t **flags)
 {
 	int i;
 
@@ -415,27 +418,60 @@
 		if (i == u->nsettings) return(-1);
 	}
 	*flags = &u->settings[i].flags;
-	*udef = &u->settings[i].udef_flags;
 	return(0);
 }
 
 int user_get_flags(user_t *u, const char *chan, flags_t *flags)
 {
-	int *builtin, *udef;
+	flags_t *uflags;
+
+	if (get_flags(u, chan, &uflags)) return(-1);
+
+	flags->builtin = uflags->builtin;
+	flags->udef = uflags->udef;
+	return(0);
+}
+
+int check_flag_change(user_t *u, const char *chan, flags_t *oldflags, flags_t *newflags)
+{
+	char oldstr[64], newstr[64], *change;
+	int r;
+
+	flag_to_str(oldflags, oldstr);
+	flag_to_str(newflags, newstr);
+	change = egg_msprintf(NULL, 0, NULL, "%s %s %s", chan ? chan : "", oldstr, newstr);
+	r = bind_check(BT_uflags, change, u->handle, chan, oldstr, newstr);
+	free(change);
 
-	if (get_flags(u, chan, &builtin, &udef)) return(-1);
-	flags->builtin = *builtin;
-	flags->udef = *udef;
+	/* Does a callback want to cancel this flag change? */
+	if (r & BIND_RET_BREAK) return(-1);
 	return(0);
 }
 
 int user_set_flags(user_t *u, const char *chan, flags_t *flags)
 {
-	int *builtin, *udef;
+	flags_t *oldflags, newflags;
 
-	if (get_flags(u, chan, &builtin, &udef)) return(-1);
-	*builtin = flags->builtin;
-	*udef = flags->udef;
+	if (get_flags(u, chan, &oldflags)) return(-1);
+	newflags.builtin = flags->builtin;
+	newflags.udef = flags->udef;
+	if (check_flag_change(u, chan, oldflags, &newflags)) return(0);
+	oldflags->builtin = newflags.builtin;
+	oldflags->udef = newflags.udef;
+	return(0);
+}
+
+int user_set_flag_str(user_t *u, const char *chan, const char *flags)
+{
+	flags_t *oldflags, newflags;
+
+	if (get_flags(u, chan, &oldflags)) return(-1);
+	newflags.builtin = oldflags->builtin;
+	newflags.udef = oldflags->udef;
+	flag_merge_str(&newflags, flags);
+	if (check_flag_change(u, chan, oldflags, &newflags)) return(0);
+	oldflags->builtin = newflags.builtin;
+	oldflags->udef = newflags.udef;
 	return(0);
 }
 
@@ -475,9 +511,15 @@
 
 int user_set_setting(user_t *u, const char *chan, const char *setting, const char *newvalue)
 {
-	int i, j;
-	char **value;
+	int i, j, r;
+	char **value, *change;
 	user_setting_t *setptr;
+
+	change = egg_msprintf(NULL, 0, NULL, "%s %s", chan ? chan : "", setting);
+	r = bind_check(BT_uset, change, u->handle, chan, setting, newvalue);
+	free(change);
+
+	if (r & BIND_RET_BREAK) return(0);
 
 	if (find_setting(u, chan, setting, &i, &j) < 0) {
 		/* See if we need to add the channel. */
Index: eggdrop1.7/lib/eggdrop/users.h
diff -u eggdrop1.7/lib/eggdrop/users.h:1.1 eggdrop1.7/lib/eggdrop/users.h:1.2
--- eggdrop1.7/lib/eggdrop/users.h:1.1	Mon Oct  7 17:33:54 2002
+++ eggdrop1.7/lib/eggdrop/users.h	Fri Oct 11 01:56:02 2002
@@ -14,7 +14,7 @@
 	char *chan;
 
 	/* Builtin flags and user defined flags. */
-	int flags, udef_flags;
+	flags_t flags;
 
 	/* Extended settings done by modules/scripts. */
 	extended_setting_t *extended;
@@ -26,9 +26,6 @@
 	char *handle;
 	int uid;
 
-	/* The encrypted password and its salt (initialization vector). */
-	char *pass, *salt;
-
 	/* Masks that the user is recognized by on irc (nick!user at host). */
 	char **ircmasks;
 	int nircmasks;
@@ -40,6 +37,7 @@
 
 int user_init();
 int user_load(const char *fname);
+int user_save(const char *fname);
 user_t *user_new(const char *handle);
 int user_delete(user_t *u);
 user_t *user_lookup_by_handle(const char *handle);
@@ -50,5 +48,8 @@
 int user_del_ircmask(user_t *u, const char *ircmask);
 int user_get_setting(user_t *u, const char *chan, const char *setting, char **valueptr);
 int user_set_setting(user_t *u, const char *chan, const char *setting, const char *newvalue);
+int user_get_flags(user_t *u, const char *chan, flags_t *flags);
+int user_set_flags(user_t *u, const char *chan, flags_t *flags);
+int user_set_flag_str(user_t *u, const char *chan, const char *flags);
 
 #endif
Index: eggdrop1.7/src/scriptuser.c
diff -u eggdrop1.7/src/scriptuser.c:1.2 eggdrop1.7/src/scriptuser.c:1.3
--- eggdrop1.7/src/scriptuser.c:1.2	Wed Oct  9 23:41:59 2002
+++ eggdrop1.7/src/scriptuser.c	Fri Oct 11 01:56:02 2002
@@ -1,4 +1,5 @@
 #include "main.h"
+#include <eggdrop/flags.h>
 #include <eggdrop/users.h>
 
 static char *script_uid_to_handle(int uid)
@@ -112,16 +113,21 @@
 		chan = NULL;
 	}
 
-	//user_setflags(u, chan, flags);
+	user_set_flag_str(u, chan, flags);
 	return(0);
 }
 
 static char *script_getflags(int uid, char *chan)
 {
 	user_t *u;
+	flags_t flags;
+	char flagstr[64];
 
 	u = user_lookup_by_uid(uid);
-	if (!u) return(-1);
+	if (!u) return(NULL);
+	if (user_get_flags(u, chan, &flags)) return(NULL);
+	flag_to_str(&flags, flagstr);
+	return strdup(flagstr);
 }
 
 script_command_t script_new_user_cmds[] = {
@@ -134,6 +140,9 @@
 	{"", "user_find", script_user_find, NULL, 1, "s", "irchost", SCRIPT_STRING, 0},
 	{"", "user_get", script_user_get, NULL, 2, "iss", "uid ?channel? setting", SCRIPT_STRING, SCRIPT_VAR_ARGS | SCRIPT_PASS_COUNT},
 	{"", "user_set", script_user_set, NULL, 3, "isss", "uid ?channel? setting value", SCRIPT_INTEGER, SCRIPT_VAR_ARGS | SCRIPT_PASS_COUNT},
+	{"", "user_getflags", script_getflags, NULL, 1, "is", "uid ?chan?", SCRIPT_STRING | SCRIPT_FREE, SCRIPT_VAR_ARGS},
+	{"", "user_setflags", script_setflags, NULL, 2, "iss", "uid ?chan? flags", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
+	{"", "user_load", user_save, NULL, 0, "s", "?fname?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
 	{"", "user_save", script_user_save, NULL, 0, "s", "?fname?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
 	{0}
 };
----------------------- End of diff -----------------------



More information about the Changes mailing list