permhash.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #ifndef _PERMHASH_H_
  13. #define _PERMHASH_H_
  14. #include <string.h>
  15. #include <plhash.h>
  16. #include <base/pool.h>
  17. #include <base/util.h>
  18. static void *
  19. ACL_PermAllocTable(void *pool, PRSize size)
  20. {
  21. return pool_malloc((pool_handle_t *)pool, size);
  22. }
  23. static void
  24. ACL_PermFreeTable(void *pool, void *item)
  25. {
  26. pool_free((pool_handle_t *)pool, item);
  27. }
  28. static PLHashEntry *
  29. ACL_PermAllocEntry(void *pool, const void *unused)
  30. {
  31. return ((PLHashEntry *)pool_malloc((pool_handle_t *)pool, sizeof(PLHashEntry)));
  32. }
  33. static void
  34. ACL_PermFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
  35. {
  36. if (flag == HT_FREE_ENTRY){
  37. pool_free((pool_handle_t *)pool, he);
  38. }
  39. }
  40. static PLHashAllocOps ACLPermAllocOps = {
  41. ACL_PermAllocTable,
  42. ACL_PermFreeTable,
  43. ACL_PermAllocEntry,
  44. ACL_PermFreeEntry
  45. };
  46. #ifndef NO_ACL_HASH_FUNCS
  47. static PLHashNumber
  48. PR_HashCaseString(const void *key)
  49. {
  50. PLHashNumber h;
  51. const unsigned char *s;
  52. h = 0;
  53. for (s = (const unsigned char *)key; *s; s++)
  54. h = (h >> 28) ^ (h << 4) ^ tolower(*s);
  55. return h;
  56. }
  57. static int
  58. PR_CompareCaseStrings(const void *v1, const void *v2)
  59. {
  60. const char *s1 = (const char *)v1;
  61. const char *s2 = (const char *)v2;
  62. return (strcasecmp(s1, s2) == 0);
  63. }
  64. #endif /* NO_ACL_HASH_FUNCS */
  65. #endif /* _PERMHASH_H */