sofia-sip/msg_mclass_hash.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef MSG_MCLASS_HASH_H
00026 
00027 #define MSG_MCLASS_HASH_H 
00028 
00040 #include <sofia-sip/su_config.h>
00041 
00042 #ifndef BNF_H
00043 #include <sofia-sip/bnf.h>
00044 #endif
00045 
00046 SOFIA_BEGIN_DECLS
00047 
00049 #define MC_HASH(s, n)     (msg_header_name_hash(s, NULL) % (unsigned)(n))
00050 
00052 su_inline 
00053 unsigned short msg_header_name_hash(char const *s, isize_t *llen)
00054 {
00055   unsigned short hash = 0;
00056   size_t i;
00057 
00058   for (i = 0; s[i]; i++) {
00059     unsigned char c = s[i];
00060     if (!(_bnf_table[c] & bnf_token))
00061       break;
00062     if (c >= 'A' && c <= 'Z')
00063       hash += (c + 'a' - 'A');
00064     else
00065       hash += c;
00066     hash *= 38501U;
00067   }
00068 
00069   if (llen)
00070     *llen = i;
00071 
00072   return hash;
00073 }
00074 
00075 SOFIA_END_DECLS
00076 
00077 #endif 

Sofia-SIP 1.12.6 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.