[cvslog] (2002-10-09 09:09:50 UTC) Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Wed Oct 9 04:10:01 CST 2002


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

Modified files:
     lib/eggdrop/flags.h lib/eggdrop/ircmasks.c lib/eggdrop/ircmasks.h
     lib/eggdrop/users.c

Added files:
     lib/eggdrop/hash_table.c lib/eggdrop/hash_table.h

Log message:

* Forgot some files

---------------------- diff included ----------------------
Index: eggdrop1.7/lib/eggdrop/flags.h
diff -u eggdrop1.7/lib/eggdrop/flags.h:1.1 eggdrop1.7/lib/eggdrop/flags.h:1.2
--- eggdrop1.7/lib/eggdrop/flags.h:1.1	Mon Oct  7 17:33:54 2002
+++ eggdrop1.7/lib/eggdrop/flags.h	Wed Oct  9 04:09:40 2002
@@ -2,8 +2,7 @@
 #define _FLAGS_H_
 
 typedef struct {
-	int global;
-	int channel;
+	int builtin;
 	int udef;
 } flags_t;
 
Index: eggdrop1.7/lib/eggdrop/hash_table.c
diff -u /dev/null eggdrop1.7/lib/eggdrop/hash_table.c:1.1
--- /dev/null	Wed Oct  9 04:09:50 2002
+++ eggdrop1.7/lib/eggdrop/hash_table.c	Wed Oct  9 04:09:40 2002
@@ -0,0 +1,253 @@
+/*
+ * hash_table.c --
+ */
+/*
+ * Copyright (C) 2002 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: hash_table.c,v 1.1 2002/10/09 09:09:40 stdarg Exp $";
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "hash_table.h"
+
+static unsigned int my_string_hash(const void *key);
+static unsigned int my_int_hash(const void *key);
+static unsigned int my_mixed_hash (const void *key);
+static int my_int_cmp(const void *left, const void *right);
+
+hash_table_t *hash_table_create(hash_table_hash_alg alg, hash_table_cmp_alg cmp, int nrows, int flags)
+{
+	hash_table_t *ht;
+	int size;
+
+	if (nrows <= 0) nrows = 13; /* Give them a small table to start with. */
+
+	/* One of the rows is included in the struct definition. */
+	size = sizeof(*ht) + (nrows-1) * sizeof(hash_table_entry_t);
+	ht = calloc(1, size);
+
+	if (alg) ht->hash = alg;
+	else {
+		if (flags & HASH_TABLE_STRINGS) ht->hash = my_string_hash;
+		else if (flags & HASH_TABLE_INTS) ht->hash = my_int_hash;
+		else ht->hash = my_mixed_hash;
+	}
+	if (cmp) ht->cmp = cmp;
+	else {
+		if (flags & HASH_TABLE_INTS) ht->cmp = my_int_cmp;
+		else ht->cmp = (hash_table_cmp_alg) strcmp;
+	}
+	ht->flags = flags;
+	ht->max_rows = nrows;
+	return(ht);
+}
+
+int hash_table_destroy(hash_table_t *ht)
+{
+	return(0);
+}
+
+int hash_table_check_resize(hash_table_t **ht)
+{
+	if ((*ht)->cells_in_use / (*ht)->max_rows > 100) {
+		hash_table_resize(ht, (*ht)->max_rows * 3);
+	}
+	return(0);
+}
+
+int hash_table_resize(hash_table_t **ht, int nrows)
+{
+	int i, newidx;
+	hash_table_t *newht, *oldht;
+	hash_table_row_t *row, *newrow;
+	hash_table_entry_t *entry, *next;
+
+	/* First allocate a new hash table. */
+	oldht = *ht;
+	newht = hash_table_create(oldht->hash, oldht->cmp, nrows, oldht->flags);
+
+	/* Now populate it with the old entries. */
+	for (i = 0; i < oldht->max_rows; i++) {
+		row = oldht->rows+i;
+		for (entry = row->head; entry; entry = next) {
+			next = entry->next;
+			newidx = entry->hash % nrows;
+			newrow = newht->rows+newidx;
+			entry->next = newrow->head;
+			newrow->head = entry;
+			newrow->len++;
+		}
+	}
+
+	newht->cells_in_use = oldht->cells_in_use;
+	free(oldht);
+	*ht = newht;
+	return(0);
+}
+
+int hash_table_insert(hash_table_t *ht, const void *key, void *data)
+{
+	unsigned int hash;
+	int idx;
+	hash_table_entry_t *entry;
+	hash_table_row_t *row;
+
+	hash = ht->hash(key);
+	idx = hash % ht->max_rows;
+	row = ht->rows+idx;
+
+	/* Allocate an entry. */
+	entry = malloc(sizeof(*entry));
+	entry->key = key;
+	entry->data = data;
+	entry->hash = hash;
+
+	/* Insert it into the list. */
+	entry->next = row->head;
+	row->head = entry;
+
+	/* Update stats. */
+	row->len++;
+	ht->cells_in_use++;
+
+	return(0);
+}
+
+int hash_table_find(hash_table_t *ht, const void *key, void *dataptr)
+{
+	int idx;
+	unsigned int hash;
+	hash_table_entry_t *entry;
+	hash_table_row_t *row;
+
+	hash = ht->hash(key);
+	idx = hash % ht->max_rows;
+	row = ht->rows+idx;
+
+	for (entry = row->head; entry; entry = entry->next) {
+		if (hash == entry->hash && !ht->cmp(key, entry->key)) {
+			*(void **)dataptr = entry->data;
+			return(0);
+		}
+	}
+	return(-1);
+}
+
+int hash_table_delete(hash_table_t *ht, const void *key)
+{
+	int idx;
+	unsigned int hash;
+	hash_table_entry_t *entry, *last;
+	hash_table_row_t *row;
+
+	hash = ht->hash(key);
+	idx = hash % ht->max_rows;
+	row = ht->rows+idx;
+
+	last = NULL;
+	for (entry = row->head; entry; entry = entry->next) {
+		if (hash == entry->hash && !ht->cmp(key, entry->key)) {
+			/* Remove it from the row's list. */
+			if (last) last->next = entry->next;
+			else row->head = entry->next;
+
+			free(entry);
+			ht->cells_in_use--;
+			return(0);
+		}
+		last = entry;
+	}
+	return(-1);
+}
+
+int hash_table_walk(hash_table_t *ht, hash_table_node_func callback, void *param)
+{
+	hash_table_row_t *row;
+	hash_table_entry_t *entry;
+	int i;
+
+	for (i = 0; i < ht->max_rows; i++) {
+		row = ht->rows+i;
+		for (entry = row->head; entry; entry = entry->next) {
+			callback(entry->key, &entry->data, param);
+		}
+	}
+	return(0);
+}
+
+static int my_int_cmp(const void *left, const void *right)
+{
+	return((int) left - (int) right);
+}
+
+static unsigned int my_string_hash(const void *key)
+{
+	int hash, loop, keylen;
+	unsigned char *k;
+
+#define HASHC hash = *k++ + 65599 * hash
+	hash = 0;
+	k = (unsigned char *)key;
+	keylen = strlen((char *)key);
+
+	loop = (keylen + 8 - 1) >> 3;
+	switch (keylen & (8 - 1)) {
+		case 0:
+			do {
+				HASHC;
+		case 7:
+				HASHC;
+		case 6:
+				HASHC;
+		case 5:
+				HASHC;
+		case 4:
+				HASHC;
+		case 3:
+				HASHC;
+		case 2:
+				HASHC;
+		case 1:
+				HASHC;
+			} while (--loop);
+	}
+	return(hash);
+}
+
+static unsigned int my_int_hash(const void *key)
+{
+	return((unsigned int)key);
+}
+
+static unsigned int my_mixed_hash (const void *key)
+{
+	unsigned char *k;
+	unsigned int hash;
+
+        k = (unsigned char *)key;
+	hash = 0;
+	while (*k) {
+		hash *= 16777619;
+		hash ^= *k++;
+	}
+	return(hash);
+}
Index: eggdrop1.7/lib/eggdrop/hash_table.h
diff -u /dev/null eggdrop1.7/lib/eggdrop/hash_table.h:1.1
--- /dev/null	Wed Oct  9 04:09:50 2002
+++ eggdrop1.7/lib/eggdrop/hash_table.h	Wed Oct  9 04:09:40 2002
@@ -0,0 +1,47 @@
+#ifndef _EGG_HASH_TABLE_H_
+#define _EGG_HASH_TABLE_H_
+
+#define HASH_TABLE_STRINGS 1
+#define HASH_TABLE_INTS    2
+#define HASH_TABLE_MIXED   4
+
+/* Turns a key into an unsigned int. */
+typedef unsigned int (*hash_table_hash_alg)(const void *key);
+
+/* Returns -1, 0, or 1 if left is <, =, or > than right. */
+typedef int (*hash_table_cmp_alg)(const void *left, const void *right);
+
+typedef int (*hash_table_node_func)(const void *key, void *data, void *param);
+
+typedef struct hash_table_entry_b {
+	struct hash_table_entry_b *next;
+	const void *key;
+	void *data;
+	unsigned int hash;
+} hash_table_entry_t;
+
+typedef struct {
+	int len;
+	hash_table_entry_t *head;
+} hash_table_row_t;
+
+typedef struct hash_table_b {
+	int flags;
+	int max_rows;
+	int cells_in_use;
+	hash_table_hash_alg hash;
+	hash_table_cmp_alg cmp;
+	hash_table_row_t rows[1];
+} hash_table_t;
+
+hash_table_t *hash_table_create(hash_table_hash_alg alg, hash_table_cmp_alg cmp, int nrows, int flags);
+int hash_table_destroy(hash_table_t *ht);
+int hash_table_check_resize(hash_table_t **ht);
+int hash_table_resize(hash_table_t **ht, int nrows);
+int hash_table_insert(hash_table_t *ht, const void *key, void *data);
+int hash_table_replace(hash_table_t *ht, const void *key, void *data);
+int hash_table_find(hash_table_t *ht, const void *key, void *dataptr);
+int hash_table_delete(hash_table_t *ht, const void *key);
+int hash_table_walk(hash_table_t *ht, hash_table_node_func callback, void *param);
+
+#endif
Index: eggdrop1.7/lib/eggdrop/ircmasks.c
diff -u eggdrop1.7/lib/eggdrop/ircmasks.c:1.1 eggdrop1.7/lib/eggdrop/ircmasks.c:1.2
--- eggdrop1.7/lib/eggdrop/ircmasks.c:1.1	Mon Oct  7 17:33:54 2002
+++ eggdrop1.7/lib/eggdrop/ircmasks.c	Wed Oct  9 04:09:40 2002
@@ -7,6 +7,7 @@
 int ircmask_list_add(ircmask_list_t *list, const char *ircmask, void *data)
 {
 	int i, stars, len;
+	ircmask_list_entry_t *entry, *prev;
 
 	stars = 0;
 	len = strlen(ircmask);
@@ -14,15 +15,23 @@
 		if (ircmask[i] == '*') stars++;
 	}
 	len -= stars;
-	for (i = 0; i < list->len; i++) {
-		if (len > list->list[i].len) break;
+	prev = NULL;
+	for (entry = list->head; entry; entry = entry->next) {
+		if (len >= entry->len) break;
+		prev = entry;
+	}
+	entry = malloc(sizeof(*entry));
+	entry->ircmask = strdup(ircmask);
+	entry->len = len;
+	entry->data = data;
+	if (prev) {
+		entry->next = prev->next;
+		prev->next = entry;
+	}
+	else {
+		entry->next = list->head;
+		list->head = entry;
 	}
-	list->list = realloc(list->list, sizeof(*list->list) * (list->len+1));
-	memmove(list->list+i+1, list->list+i, sizeof(*list->list) * (list->len-i));
-	list->list[i].ircmask = strdup(ircmask);
-	list->list[i].len = len;
-	list->list[i].data = data;
-	list->len++;
 	return(0);
 }
 
@@ -32,11 +41,11 @@
 
 int ircmask_list_find(ircmask_list_t *list, const char *irchost, void *dataptr)
 {
-	int i;
+	ircmask_list_entry_t *entry;
 
-	for (i = 0; i < list->len; i++) {
-		if (wild_match(list->list[i].ircmask, irchost) > 0) {
-			*(void **)dataptr = list->list[i].data;
+	for (entry = list->head; entry; entry = entry->next) {
+		if (wild_match(entry->ircmask, irchost) > 0) {
+			*(void **)dataptr = entry->data;
 			return(0);
 		}
 	}
Index: eggdrop1.7/lib/eggdrop/ircmasks.h
diff -u eggdrop1.7/lib/eggdrop/ircmasks.h:1.1 eggdrop1.7/lib/eggdrop/ircmasks.h:1.2
--- eggdrop1.7/lib/eggdrop/ircmasks.h:1.1	Mon Oct  7 17:33:54 2002
+++ eggdrop1.7/lib/eggdrop/ircmasks.h	Wed Oct  9 04:09:40 2002
@@ -1,15 +1,15 @@
 #ifndef _IRCMASKS_H_
 #define _IRCMASKS_H_
 
-typedef struct {
+typedef struct ircmask_list_entry {
+	struct ircmask_list_entry *next;
 	char *ircmask;
 	int len;
 	void *data;
 } ircmask_list_entry_t;
 
 typedef struct {
-	int len;
-	ircmask_list_entry_t *list;
+	ircmask_list_entry_t *head;
 } ircmask_list_t;
 
 int ircmask_list_add(ircmask_list_t *list, const char *ircmask, void *data);
Index: eggdrop1.7/lib/eggdrop/users.c
diff -u eggdrop1.7/lib/eggdrop/users.c:1.1 eggdrop1.7/lib/eggdrop/users.c:1.2
--- eggdrop1.7/lib/eggdrop/users.c:1.1	Mon Oct  7 17:33:54 2002
+++ eggdrop1.7/lib/eggdrop/users.c	Wed Oct  9 04:09:40 2002
@@ -32,7 +32,7 @@
 static hash_table_t *uid_ht = NULL;
 
 /* List to keep all users' ircmasks in. */
-static ircmask_list_t ircmask_list = {0, NULL};
+static ircmask_list_t ircmask_list = {NULL};
 
 /* Prototypes for internal functions. */
 static user_t *real_user_new(const char *handle, int uid);
@@ -43,9 +43,12 @@
 
 int user_init()
 {
+	/* 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. */
 	return(0);
 }
 
@@ -59,9 +62,15 @@
 
 	memset(&root, 0, sizeof(root));
 	xml_read(&root, fname);
-	for (i = 0; ; i++) {
-		user_node = xml_node_lookup(&root, "user", i, 0);
-		if (!user_node) break;
+	if (xml_node_get_int(&uid, &root, "next_uid", 0, 0)) {
+		xml_node_destroy(&root);
+		return(0);
+	}
+	g_uid = uid;
+	xml_node_get_int(&uid_wraparound, &root, "uid_wraparound", 0, 0);
+	for (i = 0; i < root.nchildren; i++) {
+		if (strcasecmp(root.children[i].name, "user")) continue;
+		user_node = root.children+i;
 		xml_node_get_str(&handle, user_node, "handle", 0, 0);
 		xml_node_get_int(&uid, user_node, "uid", 0, 0);
 		if (!handle || !uid) break;
@@ -194,6 +203,8 @@
 
 	hash_table_insert(handle_ht, u->handle, u);
 	hash_table_insert(uid_ht, (void *)u->uid, u);
+	hash_table_check_resize(&handle_ht);
+	hash_table_check_resize(&uid_ht);
 	return(u);
 }
 
@@ -355,6 +366,7 @@
 	/* Add the ircmask to the user entry. */
 	u->ircmasks = (char **)realloc(u->ircmasks, sizeof(char *) * (u->nircmasks+1));
 	u->ircmasks[u->nircmasks] = strdup(ircmask);
+	u->nircmasks++;
 
 	/* Put it in the big list. */
 	ircmask_list_add(&ircmask_list, ircmask, u);
@@ -378,6 +390,7 @@
 
 	/* Get rid of it. */
 	memmove(u->ircmasks+i, u->ircmasks+i+1, sizeof(char *) * (u->nircmasks - i - 1));
+	u->nircmasks--;
 
 	/* Delete matching entries of this user in the host cache. */
 	cache_user_del(u, ircmask);
@@ -385,16 +398,39 @@
 	return(0);
 }
 
-int user_get_flags(user_t *u, const char *chan, flags_t *flags)
+static int get_flags(user_t *u, const char *chan, int **flags, int **udef)
 {
 	int i;
-	flags->global = u->settings[0].flags;
-	if (chan) for (i = 1; i < u->nsettings; i++) {
-		if (!strcasecmp(chan, u->settings[i].chan)) {
-			flags->channel = u->settings[i].flags;
-			break;
+
+	if (!chan) i = 0;
+	else {
+		for (i = 1; i < u->nsettings; i++) {
+			if (!strcasecmp(chan, u->settings[i].chan)) break;
 		}
+		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;
+
+	if (get_flags(u, chan, &builtin, &udef)) return(-1);
+	flags->builtin = *builtin;
+	flags->udef = *udef;
+	return(0);
+}
+
+int user_set_flags(user_t *u, const char *chan, flags_t *flags)
+{
+	int *builtin, *udef;
+
+	if (get_flags(u, chan, &builtin, &udef)) return(-1);
+	*builtin = flags->builtin;
+	*udef = flags->udef;
 	return(0);
 }
 
----------------------- End of diff -----------------------



More information about the Changes mailing list