msg_mclass_hash.h 1.84 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef MSG_MCLASS_HASH_H
Pekka Pessi's avatar
Pekka Pessi committed
26
/** Defined when <sofia-sip/msg_mclass_hash.h> has been included. */
27
#define MSG_MCLASS_HASH_H
Pekka Pessi's avatar
Pekka Pessi committed
28

Pekka Pessi's avatar
Pekka Pessi committed
29
/**@ingroup msg_parser
Pekka Pessi's avatar
Pekka Pessi committed
30
 * @file sofia-sip/msg_mclass_hash.h
Pekka Pessi's avatar
Pekka Pessi committed
31 32 33 34 35 36
 *
 * Hash function for header names.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Tue Aug 21 16:03:45 2001 ppessi
37
 *
Pekka Pessi's avatar
Pekka Pessi committed
38 39
 */

40
#include <sofia-sip/su_config.h>
41

Pekka Pessi's avatar
Pekka Pessi committed
42
#ifndef BNF_H
43
#include <sofia-sip/bnf.h>
Pekka Pessi's avatar
Pekka Pessi committed
44 45
#endif

46 47
SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
48 49 50 51
/** Hash the header name */
#define MC_HASH(s, n)     (msg_header_name_hash(s, NULL) % (unsigned)(n))

/** Hash header name */
52
su_inline
53
unsigned short msg_header_name_hash(char const *s, isize_t *llen)
Pekka Pessi's avatar
Pekka Pessi committed
54 55
{
  unsigned short hash = 0;
56
  size_t i;
Pekka Pessi's avatar
Pekka Pessi committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

  for (i = 0; s[i]; i++) {
    unsigned char c = s[i];
    if (!(_bnf_table[c] & bnf_token))
      break;
    if (c >= 'A' && c <= 'Z')
      hash += (c + 'a' - 'A');
    else
      hash += c;
    hash *= 38501U;
  }

  if (llen)
    *llen = i;

  return hash;
}

75 76
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
77
#endif /** MSG_MCLASS_HASH_H */