X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fhash.c;h=113133d20c7f75019b35297aba13904cf32e4c79;hp=d6cb516a002161a8b616998dd75ad91154b9a025;hb=4ef23df8137557cee0e657d5b05fa09c4c61c6ca;hpb=b422b11865a6243c070983e3a80ea226904f0edc diff --git a/src/ngircd/hash.c b/src/ngircd/hash.c index d6cb516a..113133d2 100644 --- a/src/ngircd/hash.c +++ b/src/ngircd/hash.c @@ -1,52 +1,62 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) + * Copyright (c)2001-2010 Alexander Barton (alex@barton.de) * - * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen - * der GNU General Public License (GPL), wie von der Free Software Foundation - * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2 - * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version. - * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste - * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. - * - * $Id: hash.c,v 1.2 2002/03/14 15:49:36 alex Exp $ - * - * hash.c: Hash-Werte berechnen + * 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. + * Please read the file COPYING, README and AUTHORS for more information. */ - #include "portab.h" +/** + * @file + * Hash calculation + */ + #include "imp.h" #include +#include + +#include "defines.h" +#include "tool.h" #include "exp.h" #include "hash.h" +static UINT32 jenkins_hash PARAMS((register UINT8 *k, register UINT32 length, + register UINT32 initval)); -LOCAL UINT32 jenkins_hash( register UINT8 *k, register UINT32 length, register UINT32 initval); - - -GLOBAL UINT32 Hash( CHAR *String ) +/** + * Calculate hash value for a given string. + * + * @param String Input string + * @return 32 bit hash value + */ +GLOBAL UINT32 +Hash( const char *String ) { - /* Hash-Wert ueber String berechnen */ - return jenkins_hash( String, strlen( String ), 42 ); -} /* Hash */ + char buffer[LINE_LEN]; + strlcpy(buffer, String, sizeof(buffer)); + return jenkins_hash((UINT8 *)ngt_LowerStr(buffer), + (UINT32)strlen(buffer), 42); +} /* Hash */ /* - * Die hier verwendete Hash-Funktion stammt aus lookup2.c von Bob Jenkins - * (URL: ). Aus dem Header: + * This hash function originates from lookup2.c of Bob Jenkins + * (URL: ): * -------------------------------------------------------------------- * lookup2.c, by Bob Jenkins, December 1996, Public Domain. * hash(), hash2(), hash3, and mix() are externally useful functions. * Routines to test the hash are included if SELF_TEST is defined. * You can use this free for any purpose. It has no warranty. * -------------------------------------------------------------------- - * nicht alle seiner Funktionen werden hier genutzt. + * Not all of his functions are used here. */ - #define hashsize(n) ((UINT32)1<<(n)) #define hashmask(n) (hashsize(n)-1) @@ -63,8 +73,8 @@ GLOBAL UINT32 Hash( CHAR *String ) c -= a; c -= b; c ^= (b>>15); \ } /* mix */ - -LOCAL UINT32 jenkins_hash( register UINT8 *k, register UINT32 length, register UINT32 initval) +static UINT32 +jenkins_hash( register UINT8 *k, register UINT32 length, register UINT32 initval ) { /* k: the key * length: length of the key @@ -90,7 +100,7 @@ LOCAL UINT32 jenkins_hash( register UINT8 *k, register UINT32 length, register U /* handle the last 11 bytes */ c += length; - switch(len) /* all the case statements fall through */ + switch( (int)len ) /* all the case statements fall through */ { case 11: c+=((UINT32)k[10]<<24); case 10: c+=((UINT32)k[9]<<16); @@ -112,5 +122,4 @@ LOCAL UINT32 jenkins_hash( register UINT8 *k, register UINT32 length, register U return c; } /* jenkins_hash */ - /* -eof- */