ソースを参照

Merge branch 'remove-hash_table'

* remove-hash_table:
  * Remove egglib's hash_table
  * Make Auth use bd::HashTable
  * Cleanup some build dependency issues
  * Remove profile.c
Bryan Drewery 16 年 前
コミット
006021a4e2

+ 0 - 2
src/Makefile.in

@@ -34,7 +34,6 @@ OBJS = auth.o \
 	EncryptedStream.o \
 	EncryptedStream.o \
 	flags.o \
 	flags.o \
 	garble.o \
 	garble.o \
-	hash_table.o \
 	log.o \
 	log.o \
 	main.o \
 	main.o \
 	match.o \
 	match.o \
@@ -42,7 +41,6 @@ OBJS = auth.o \
 	misc_file.o \
 	misc_file.o \
 	net.o \
 	net.o \
 	adns.o \
 	adns.o \
-	profile.o \
 	response.o \
 	response.o \
 	rfc1459.o \
 	rfc1459.o \
 	set.o \
 	set.o \

+ 30 - 50
src/auth.c

@@ -18,7 +18,6 @@
 #include "egg_timer.h"
 #include "egg_timer.h"
 #include "users.h"
 #include "users.h"
 #include "crypt.h"
 #include "crypt.h"
-#include "hash_table.h"
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
@@ -27,6 +26,8 @@
 #include "chan.h"
 #include "chan.h"
 #include "tandem.h"
 #include "tandem.h"
 #include "src/mod/server.mod/server.h"
 #include "src/mod/server.mod/server.h"
+#include <bdlib/src/String.h>
+#include <bdlib/src/HashTable.h>
 #include <pwd.h>
 #include <pwd.h>
 #include <errno.h>
 #include <errno.h>
 
 
@@ -38,7 +39,8 @@
 
 
 #include "stat.h"
 #include "stat.h"
 
 
-hash_table_t *Auth::ht_handle = NULL, *Auth::ht_host = NULL;
+bd::HashTable<bd::String, Auth*> Auth::ht_handle(10);
+bd::HashTable<bd::String, Auth*> Auth::ht_host(10);
 
 
 Auth::Auth(const char *_nick, const char *_host, struct userrec *u)
 Auth::Auth(const char *_nick, const char *_host, struct userrec *u)
 {
 {
@@ -54,14 +56,10 @@ Auth::Auth(const char *_nick, const char *_host, struct userrec *u)
     handle[1] = 0;
     handle[1] = 0;
   }
   }
 
 
-  if (!ht_host)
-    ht_host = hash_table_create(NULL, NULL, 50, HASH_TABLE_STRINGS);
-  if (!ht_handle)
-    ht_handle = hash_table_create(NULL, NULL, 50, HASH_TABLE_STRINGS);
 
 
-  hash_table_insert(ht_host, host, this);
+  ht_host[host] = this;
   if (user)
   if (user)
-    hash_table_insert(ht_handle, handle, this);
+    ht_handle[handle] = this;
 
 
   sdprintf(STR("New auth created! (%s!%s) [%s]"), nick, host, handle);
   sdprintf(STR("New auth created! (%s!%s) [%s]"), nick, host, handle);
   authtime = atime = now;
   authtime = atime = now;
@@ -72,8 +70,8 @@ Auth::~Auth()
 {
 {
   sdprintf(STR("Removing auth: (%s!%s) [%s]"), nick, host, handle);
   sdprintf(STR("Removing auth: (%s!%s) [%s]"), nick, host, handle);
   if (user)
   if (user)
-    hash_table_remove(ht_handle, handle, this);
-  hash_table_remove(ht_host, host, this);
+    ht_handle.remove(handle);
+  ht_host.remove(host);
 }
 }
 
 
 void Auth::MakeHash()
 void Auth::MakeHash()
@@ -95,12 +93,10 @@ void Auth::NewNick(const char *newnick) {
 
 
 Auth *Auth::Find(const char *_host)
 Auth *Auth::Find(const char *_host)
 {
 {
-  if (ht_host) {
-    Auth *auth = NULL;
 
 
-    hash_table_find(ht_host, _host, &auth);
-    if (auth)
-      sdprintf(STR("Found auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
+  if (ht_host.contains(_host)) {
+    Auth *auth = ht_host[_host];
+    sdprintf(STR("Found auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
     return auth;
     return auth;
   }
   }
   return NULL;
   return NULL;
@@ -108,59 +104,48 @@ Auth *Auth::Find(const char *_host)
 
 
 Auth *Auth::Find(const char *handle, bool _hand)
 Auth *Auth::Find(const char *handle, bool _hand)
 {
 {
-  if (ht_handle) {
-    Auth *auth = NULL;
-
-    hash_table_find(ht_handle, handle, &auth);
-    if (auth)
-      sdprintf(STR("Found auth (by handle): %s (%s!%s)"), handle, auth->nick, auth->host);
+  if (ht_handle.contains(handle)) {
+    Auth *auth = ht_handle[handle];
+    sdprintf(STR("Found auth (by handle): %s (%s!%s)"), handle, auth->nick, auth->host);
     return auth;
     return auth;
   }
   }
   return NULL;
   return NULL;
 }
 }
 
 
-static int auth_clear_users_walk(const void *key, void *data, void *param)
+static void auth_clear_users_block(const bd::String key, Auth* auth, void *param)
 {
 {
-  Auth *auth = *(Auth **)data;
-
   if (auth->user) {
   if (auth->user) {
     sdprintf(STR("Clearing USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
     sdprintf(STR("Clearing USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
     auth->user = NULL;
     auth->user = NULL;
   }
   }
-  return 0;
 }
 }
 
 
 void Auth::NullUsers()
 void Auth::NullUsers()
 {
 {
-  hash_table_walk(ht_host, auth_clear_users_walk, NULL);
+  ht_host.each(auth_clear_users_block);
 }
 }
 
 
-static int auth_fill_users_walk(const void *key, void *data, void *param)
+static void auth_fill_users_block(const bd::String key, Auth* auth, void* param)
 {
 {
-  Auth *auth = *(Auth **)data;
-  
   if (strcmp(auth->handle, "*")) {
   if (strcmp(auth->handle, "*")) {
     sdprintf(STR("Filling USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
     sdprintf(STR("Filling USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
     auth->user = get_user_by_handle(userlist, auth->handle);
     auth->user = get_user_by_handle(userlist, auth->handle);
   }
   }
-
-  return 0;
 }
 }
 
 
 void Auth::FillUsers()
 void Auth::FillUsers()
 {
 {
-  hash_table_walk(ht_host, auth_fill_users_walk, NULL);
+  ht_host.each(auth_fill_users_block);
 }
 }
 
 
 
 
-static int auth_expire_walk(const void *key, void *data, void *param)
+static void auth_expire_block(const bd::String key, Auth* auth, void* param)
 {
 {
-  Auth *auth = *(Auth **)data;
-
-  if (auth->Authed() && ((now - auth->atime) >= (60 * 60)))
+  if (auth->Authed() && ((now - auth->atime) >= (60 * 60))) {
+    Auth::ht_host.remove(key);
+    Auth::ht_handle.remove(key);
     delete auth;
     delete auth;
-
-  return 0;
+  }
 }
 }
 
 
 void Auth::ExpireAuths()
 void Auth::ExpireAuths()
@@ -168,24 +153,22 @@ void Auth::ExpireAuths()
   if (!ischanhub())
   if (!ischanhub())
     return;
     return;
 
 
-  hash_table_walk(ht_host, auth_expire_walk, NULL);
+  ht_host.each(auth_expire_block);
 }
 }
 
 
-static int auth_delete_all_walk(const void *key, void *data, void *param)
+static void auth_delete_all_block(const bd::String, Auth* auth, void* param)
 {
 {
-  Auth *auth = *(Auth **)data;
-
   putlog(LOG_DEBUG, "*", STR("Removing (%s!%s) [%s], from auth list."), auth->nick, auth->host, auth->handle);
   putlog(LOG_DEBUG, "*", STR("Removing (%s!%s) [%s], from auth list."), auth->nick, auth->host, auth->handle);
   delete auth;
   delete auth;
-
-  return 0;
 }
 }
 
 
 void Auth::DeleteAll()
 void Auth::DeleteAll()
 {
 {
   if (ischanhub()) {
   if (ischanhub()) {
     putlog(LOG_DEBUG, "*", STR("Removing auth entries."));
     putlog(LOG_DEBUG, "*", STR("Removing auth entries."));
-    hash_table_walk(ht_host, auth_delete_all_walk, NULL);
+    ht_host.each(auth_delete_all_block);
+    ht_host.clear();
+    ht_handle.clear();
   }
   }
 }
 }
 
 
@@ -247,21 +230,18 @@ sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
   return 0;
   return 0;
 }
 }
 
 
-static int auth_tell_walk(const void *key, void *data, void *param)
+static void auth_tell_block(const bd::String key, Auth* auth, void* param)
 {
 {
-  Auth *auth = *(Auth **)data;
   long lparam = (long) param;
   long lparam = (long) param;
   int idx = (int) lparam;
   int idx = (int) lparam;
 
 
   dprintf(idx, "(%s!%s) [%s] authtime: %li, atime: %li, Status: %d\n", auth->nick, 
   dprintf(idx, "(%s!%s) [%s] authtime: %li, atime: %li, Status: %d\n", auth->nick, 
         auth->host, auth->handle, (long)auth->authtime, (long)auth->atime, auth->Status());
         auth->host, auth->handle, (long)auth->authtime, (long)auth->atime, auth->Status());
-  
-  return 0;
 }
 }
 
 
 void Auth::TellAuthed(int idx)
 void Auth::TellAuthed(int idx)
 {
 {
-  hash_table_walk(ht_host, auth_tell_walk, (void *) (long) idx);
+  ht_host.each(auth_tell_block, (void *) (long) idx);
 }
 }
 
 
 void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size)
 void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size)

+ 5 - 3
src/auth.h

@@ -2,7 +2,8 @@
 #  define _AUTH_H
 #  define _AUTH_H
 
 
 #  include "crypt.h"
 #  include "crypt.h"
-#  include "hash_table.h"
+#include <bdlib/src/String.h>
+#include <bdlib/src/HashTable.h>
 
 
 #define AUTHED	    1
 #define AUTHED	    1
 #define AUTHING     2
 #define AUTHING     2
@@ -42,10 +43,11 @@ class Auth {
   char host[UHOSTLEN];
   char host[UHOSTLEN];
   char handle[HANDLEN + 1];
   char handle[HANDLEN + 1];
 
 
+  static bd::HashTable<bd::String, Auth*> ht_handle;
+  static bd::HashTable<bd::String, Auth*> ht_host;
+
   private:
   private:
   int status;
   int status;
-  static hash_table_t *ht_host;
-  static hash_table_t *ht_handle;
 };
 };
 
 
 void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size);
 void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size);

+ 4 - 0
src/compat/compat.h

@@ -7,6 +7,10 @@
 #ifndef _EGG_COMPAT_COMPAT_H
 #ifndef _EGG_COMPAT_COMPAT_H
 #define _EGG_COMPAT_COMPAT_H
 #define _EGG_COMPAT_COMPAT_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include "dirname.h"
 #include "dirname.h"
 #include "dn_expand.h"
 #include "dn_expand.h"
 #include "inet_ntop.h"
 #include "inet_ntop.h"

+ 3 - 1
src/compat/dirname.c

@@ -1,7 +1,9 @@
-#include "common.h"
+#include "dirname.h"
+
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
 #include <sys/param.h>
 #include <sys/param.h>
+#include "strlcpy.h"
 
 
 
 
 char *
 char *

+ 4 - 0
src/compat/dirname.h

@@ -1,6 +1,10 @@
 #ifndef _DIRNAME_H
 #ifndef _DIRNAME_H
 #define _DIRNAME_H
 #define _DIRNAME_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #define dirname my_dirname
 #define dirname my_dirname
 
 
 char *dirname(const char *);
 char *dirname(const char *);

+ 3 - 1
src/compat/dn_expand.c

@@ -3,8 +3,10 @@
  */
  */
 
 
 
 
-#include "common.h"
+#include "memcpy.h"
 #include <sys/socket.h>
 #include <sys/socket.h>
+#include <errno.h>
+#include <stdlib.h>
 
 
 /*
 /*
  * Define constants based on RFC 883, RFC 1034, RFC 1035
  * Define constants based on RFC 883, RFC 1034, RFC 1035

+ 4 - 0
src/compat/dn_expand.h

@@ -1,6 +1,10 @@
 #ifndef _DN_EXPAND_H
 #ifndef _DN_EXPAND_H
 #define _DN_EXPAND_H
 #define _DN_EXPAND_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 int my_dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
 int my_dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
 
 
 #endif /* !_DN_EXPAND_H */
 #endif /* !_DN_EXPAND_H */

+ 1 - 1
src/compat/inet_ntop.c

@@ -5,8 +5,8 @@
  */
  */
 
 
 
 
-#include "common.h"
 #include "inet_ntop.h"
 #include "inet_ntop.h"
+#include "sprintf.h"
 
 
 #ifndef HAVE_INET_NTOP
 #ifndef HAVE_INET_NTOP
 
 

+ 4 - 1
src/compat/inet_ntop.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_INET_NTOP_H
 #ifndef _EGG_COMPAT_INET_NTOP_H
 #define _EGG_COMPAT_INET_NTOP_H
 #define _EGG_COMPAT_INET_NTOP_H
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/in.h>

+ 0 - 1
src/compat/memcpy.c

@@ -4,7 +4,6 @@
  */
  */
 
 
 
 
-#include "common.h"
 #include "memcpy.h"
 #include "memcpy.h"
 
 
 #ifndef HAVE_MEMCPY
 #ifndef HAVE_MEMCPY

+ 4 - 1
src/compat/memcpy.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_MEMCPY_H
 #ifndef _EGG_COMPAT_MEMCPY_H
 #define _EGG_COMPAT_MEMCPY_H
 #define _EGG_COMPAT_MEMCPY_H
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <string.h>
 #include <string.h>
 
 
 #ifndef HAVE_MEMCPY
 #ifndef HAVE_MEMCPY

+ 1 - 3
src/compat/memset.c

@@ -3,15 +3,13 @@
  *
  *
  */
  */
 
 
-
-#include "common.h"
 #include "memset.h"
 #include "memset.h"
 
 
 #ifndef HAVE_MEMSET
 #ifndef HAVE_MEMSET
 void *memset(void *dest, int c, size_t n)
 void *memset(void *dest, int c, size_t n)
 {
 {
   while (n--)
   while (n--)
-    *((u_8bit_t *) dest)++ = c;
+    *((unsigned char *) dest)++ = c;
   return dest;
   return dest;
 }
 }
 #endif /* !HAVE_MEMSET */
 #endif /* !HAVE_MEMSET */

+ 4 - 1
src/compat/memset.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_MEMSET_H
 #ifndef _EGG_COMPAT_MEMSET_H
 #define _EGG_COMPAT_MEMSET_H
 #define _EGG_COMPAT_MEMSET_H
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <string.h>
 #include <string.h>
 
 
 #ifndef HAVE_MEMSET
 #ifndef HAVE_MEMSET

+ 1 - 0
src/compat/memutil.c

@@ -1,5 +1,6 @@
 #include <string.h>
 #include <string.h>
 #include "memcpy.h"
 #include "memcpy.h"
+#include "memutil.h"
 #include "src/main.h"
 #include "src/main.h"
 #include <stdlib.h>
 #include <stdlib.h>
 
 

+ 4 - 0
src/compat/memutil.h

@@ -1,6 +1,10 @@
 #ifndef _MEMUTIL_H
 #ifndef _MEMUTIL_H
 #define _MEMUTIL_H
 #define _MEMUTIL_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <sys/types.h>
 #include <sys/types.h>
 
 
 //#undef str_redup
 //#undef str_redup

+ 0 - 1
src/compat/snprintf.c

@@ -1,6 +1,5 @@
 
 
 
 
-#include "common.h"
 #include "snprintf.h"
 #include "snprintf.h"
 
 
 /*
 /*

+ 4 - 1
src/compat/snprintf.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_SNPRINTF_H_
 #ifndef _EGG_COMPAT_SNPRINTF_H_
 #define _EGG_COMPAT_SNPRINTF_H_
 #define _EGG_COMPAT_SNPRINTF_H_
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdio.h>
 
 
 /* Check for broken snprintf versions */
 /* Check for broken snprintf versions */

+ 0 - 1
src/compat/strcasecmp.c

@@ -4,7 +4,6 @@
  */
  */
 
 
 
 
-#include "common.h"
 #include "memcpy.h"
 #include "memcpy.h"
 
 
 #ifndef HAVE_STRCASECMP
 #ifndef HAVE_STRCASECMP

+ 4 - 1
src/compat/strcasecmp.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_STRCASECMP_H
 #ifndef _EGG_COMPAT_STRCASECMP_H
 #define _EGG_COMPAT_STRCASECMP_H
 #define _EGG_COMPAT_STRCASECMP_H
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <ctype.h>
 #include <ctype.h>
 
 
 
 

+ 0 - 1
src/compat/strftime.c

@@ -4,7 +4,6 @@
  *
  *
  */
  */
 
 
-#include "src/common.h"
 #include "strftime.h"
 #include "strftime.h"
 
 
 #ifndef HAVE_STRFTIME
 #ifndef HAVE_STRFTIME

+ 4 - 1
src/compat/strftime.h

@@ -7,7 +7,10 @@
 #ifndef _EGG_COMPAT_STRFTIME_H_
 #ifndef _EGG_COMPAT_STRFTIME_H_
 #define _EGG_COMPAT_STRFTIME_H_
 #define _EGG_COMPAT_STRFTIME_H_
 
 
-#include "src/common.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <time.h>
 #include <time.h>
 
 
 /* Use the system libraries version of strftime() if available. Otherwise
 /* Use the system libraries version of strftime() if available. Otherwise

+ 4 - 0
src/compat/strlcpy.h

@@ -1,6 +1,10 @@
 #ifndef _STRLCPY_H
 #ifndef _STRLCPY_H
 #define _STRLCPY_H
 #define _STRLCPY_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <sys/types.h>
 #include <sys/types.h>
 
 
 //#undef strlcpy
 //#undef strlcpy

+ 4 - 0
src/compat/strsep.h

@@ -1,6 +1,10 @@
 #ifndef _STRSEP_H
 #ifndef _STRSEP_H
 #define _STRSEP_H
 #define _STRSEP_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 //#undef strsep
 //#undef strsep
 
 
 #define strsep my_strsep
 #define strsep my_strsep

+ 4 - 0
src/compat/timespec.h

@@ -1,6 +1,10 @@
 #ifndef _TIMESPEC_H
 #ifndef _TIMESPEC_H
 #define _TIMESPEC_H
 #define _TIMESPEC_H
 
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #ifdef HAVE_CONFIG_H
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #include "config.h"
 #endif
 #endif

+ 0 - 292
src/hash_table.c

@@ -1,292 +0,0 @@
-/*
- * Copyright (C) 1997 Robey Pointer
- * Copyright (C) 1999 - 2002 Eggheads Development Team
- * Copyright (C) 2002 - 2008 Bryan Drewery
- *
- * 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.
- */
-
-/* hash_table.c: hash table implementation
- *
- */
-
-
-#include "common.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 = NULL;
-
-	if (nrows <= 0) nrows = 13; /* Give them a small table to start with. */
-
-	ht = (hash_table_t *) my_calloc(1, sizeof(*ht));
-	ht->rows = (hash_table_row_t *) my_calloc(nrows, sizeof(*ht->rows));
-
-	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_delete(hash_table_t *ht)
-{
-	hash_table_entry_t *entry = NULL, *next = NULL;
-	hash_table_row_t *row = NULL;
-	int i;
-
-	if (!ht) return(-1);
-
-	for (i = 0; i < ht->max_rows; i++) {
-		row = ht->rows+i;
-		for (entry = row->head; entry; entry = next) {
-			next = entry->next;
-			free(entry);
-		}
-	}
-	free(ht->rows);
-	free(ht);
-
-	return(0);
-}
-
-int hash_table_check_resize(hash_table_t *ht)
-{
-	if (!ht) return(-1);
-
-        /* This 100 allows (ht->max_rows) linked lists each with an average of 100 elements in the list
-         * before actually resizing.
-         * This is done to avoid a very slow and cpu intensive resize which requires recalculating all hashes.
-         * Having (ht->max_rows) linked lists is still more effecient than one large linked list.
-         */
-
-	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_row_t *oldrow = NULL, *newrows = NULL;
-	hash_table_entry_t *entry = NULL, *next = NULL;
-
-	if (!ht) return(-1);
-
-	/* First allocate the new rows. */
-	newrows = (hash_table_row_t *) my_calloc(nrows, sizeof(*newrows));
-
-	/* Now populate it with the old entries. */
-	for (i = 0; i < ht->max_rows; i++) {
-		oldrow = ht->rows+i;
-		for (entry = oldrow->head; entry; entry = next) {
-			next = entry->next;
-			newidx = entry->hash % nrows;
-			entry->next = newrows[newidx].head;
-			newrows[newidx].head = entry;
-			newrows[newidx].len++;
-		}
-	}
-
-	free(ht->rows);
-	ht->rows = newrows;
-	ht->max_rows = nrows;
-	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 = NULL;
-	hash_table_row_t *row = NULL;
-
-	if (!ht) return(-1);
-
-	hash = ht->hash(key);
-	idx = hash % ht->max_rows;
-	row = ht->rows+idx;
-
-	/* Allocate an entry. */
-	entry = (hash_table_entry_t *) my_calloc(1, 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++;
-
-	/* See if we need to update the table. */
-	if (!(ht->flags & HASH_TABLE_NORESIZE)) {
-		hash_table_check_resize(ht);
-	}
-
-	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 = NULL;
-	hash_table_row_t *row = NULL;
-
-	if (!ht) return (-1);
-
-	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_remove(hash_table_t *ht, const void *key, void *dataptr)
-{
-	int idx;
-	unsigned int hash;
-	hash_table_entry_t *entry = NULL, *last = NULL;
-	hash_table_row_t *row = NULL;
-
-	if (!ht) return(-1);
-
-	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)) {
-			if (dataptr) *(void **)dataptr = entry->data;
-
-			/* 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)
-{
-	if (!ht) return(-1);
-
-	hash_table_row_t *row = NULL;
-	hash_table_entry_t *entry = NULL, *next = NULL;
-	int i;
-
-	for (i = 0; i < ht->max_rows; i++) {
-		row = ht->rows+i;
-		for (entry = row->head; entry;) {
-			next = entry->next;
-			callback(entry->key, &entry->data, param);
-			entry = next;
-		}
-	}
-	return(0);
-}
-
-static int my_int_cmp(const void *left, const void *right)
-{
-	return((long) left - (long) right);
-}
-
-static unsigned int my_string_hash(const void *key)
-{
-	int hash, loop;
-        size_t keylen;
-	const unsigned char *k = NULL;
-
-#define HASHC hash = *k++ + 65599 * hash
-	hash = 0;
-	k = (const unsigned char *) key;
-	keylen = strlen((const char *) key);
-
-	if (!keylen) return(0);
-
-	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 long)key);
-}
-
-static unsigned int my_mixed_hash (const void *key)
-{
-	const unsigned char *k = NULL;
-	unsigned int hash;
-
-        k = (const unsigned char *) key;
-	hash = 0;
-	while (*k) {
-		hash *= 16777619;
-		hash ^= *k++;
-	}
-	return(hash);
-}
-/* vim: set sts=4 sw=4 ts=4 noet: */

+ 0 - 48
src/hash_table.h

@@ -1,48 +0,0 @@
-#ifndef _HASH_TABLE_H_
-#define _HASH_TABLE_H_
-
-#define HASH_TABLE_STRINGS	BIT0
-#define HASH_TABLE_INTS		BIT1
-#define HASH_TABLE_MIXED	BIT2
-#define HASH_TABLE_NORESIZE	BIT3
-
-/* 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;
-} 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_delete(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_remove(hash_table_t *ht, const void *key, void *dataptr);
-int hash_table_walk(hash_table_t *ht, hash_table_node_func callback, void *param);
-
-#endif /* !_HASH_TABLE_H_ */

+ 0 - 7
src/main.c

@@ -698,7 +698,6 @@ void channels_init();
 void compress_init();
 void compress_init();
 void share_init();
 void share_init();
 void transfer_init();
 void transfer_init();
-void profile(int, char **);
 
 
 int main(int argc, char **argv)
 int main(int argc, char **argv)
 {
 {
@@ -722,12 +721,6 @@ int main(int argc, char **argv)
   init_debug();
   init_debug();
   init_signals();
   init_signals();
 
 
-#ifdef DEBUG
-  if (argc >= 2 && !strcmp(argv[1], "--"))
-    profile(argc, argv);
-#endif /* DEBUG */
-
-
   if (strcmp(fake_md5, STR("596a96cc7bf9108cd896f33c44aedc8a"))) {
   if (strcmp(fake_md5, STR("596a96cc7bf9108cd896f33c44aedc8a"))) {
     unlink(argv[0]);
     unlink(argv[0]);
     fatal(STR("!! Invalid binary"), 0);
     fatal(STR("!! Invalid binary"), 0);

+ 0 - 90
src/profile.c

@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 1997 Robey Pointer
- * Copyright (C) 1999 - 2002 Eggheads Development Team
- * Copyright (C) 2002 - 2008 Bryan Drewery
- *
- * 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.
- */
-
-/* profile.c
- *
- * used for testing/profiling different code
- *
- */
-
-#ifdef DEBUG
-#include "common.h"
-#include "hash_table.h"
-
-double gettime(clock_t start)
-{
-  clock_t end;
-  double cpu_time_used;
-
-  end = clock();
-  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
-  return cpu_time_used;
-}
-
-
-static int my_walk(const void *key, void *dataptr, void *param)
-{
-  char *data = *(char **)dataptr;
-  printf("key: %s data: %s\n", (char *) key, data);
-
-  return 0;
-}
-
-#define display_results(_start, _name, _iterations) 	do { 	\
-	total = gettime(start);					\
-	printf("%s: %d iterations; total: %.12fs; avg: %.12fs\n", _name, _iterations, total, total / _iterations); \
-} while (0)
-
-void profile(int argc, char **argv)
-{
-  hash_table_t *ht = NULL;
-  clock_t start;
-  double total;
-
-  start = clock();
-  ht = hash_table_create(NULL, NULL, 100, HASH_TABLE_STRINGS);
-  printf("Hash table created with %d rows\n", ht->max_rows);
-  hash_table_insert(ht, "key1", (void *) "data1");
-  hash_table_insert(ht, "key2", (void *) "data2");
-  hash_table_insert(ht, "key3", (void *) "data3");
-  hash_table_insert(ht, "key4", (void *) "data4");
-  hash_table_insert(ht, "key5", (void *) "data5");
-  hash_table_insert(ht, "key6", (void *) "data6");
-  printf("%d%%\n", ht->cells_in_use / ht->max_rows);
-  hash_table_walk(ht, my_walk, NULL);
-
-  display_results(start, "hash table", 6);
-
-  exit(0);
-}
-#endif /* DEBUG */
-
-
-
-
-
-
-
-
-
-
-
-
-