您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

uthash_strcase.h 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef UTHASH_STRCASE_H_
  17. #define UTHASH_STRCASE_H_
  18. #ifdef UTHASH_H
  19. #error Invalid include order: uthash is already included
  20. #endif
  21. #include "libcryptobox/cryptobox.h"
  22. #include "libutil/util.h"
  23. /* Utils for uthash tuning */
  24. #ifndef HASH_CASELESS
  25. #define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
  26. hashv = (__typeof (hashv))rspamd_cryptobox_fast_hash(key, keylen, rspamd_hash_seed ()); \
  27. bkt = (hashv) & (num_bkts-1); \
  28. } while (0)
  29. #define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
  30. #else
  31. #define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
  32. unsigned _len = keylen; \
  33. rspamd_cryptobox_fast_hash_state_t _hst; \
  34. unsigned _leftover = keylen % 8; \
  35. unsigned _fp, _i; \
  36. const uint8_t* _s = (const uint8_t*)(key); \
  37. union { \
  38. struct { \
  39. unsigned char c1, c2, c3, c4, c5, c6, c7, c8; \
  40. } c; \
  41. uint64_t pp; \
  42. } _u; \
  43. _fp = _len - _leftover; \
  44. rspamd_cryptobox_fast_hash_init (&_hst, rspamd_hash_seed ()); \
  45. for (_i = 0; _i != _fp; _i += 8) { \
  46. _u.c.c1 = _s[_i], _u.c.c2 = _s[_i + 1], _u.c.c3 = _s[_i + 2], _u.c.c4 = _s[_i + 3]; \
  47. _u.c.c5 = _s[_i + 4], _u.c.c6 = _s[_i + 5], _u.c.c7 = _s[_i + 6], _u.c.c8 = _s[_i + 7]; \
  48. _u.c.c1 = lc_map[_u.c.c1]; \
  49. _u.c.c2 = lc_map[_u.c.c2]; \
  50. _u.c.c3 = lc_map[_u.c.c3]; \
  51. _u.c.c4 = lc_map[_u.c.c4]; \
  52. _u.c.c1 = lc_map[_u.c.c5]; \
  53. _u.c.c2 = lc_map[_u.c.c6]; \
  54. _u.c.c3 = lc_map[_u.c.c7]; \
  55. _u.c.c4 = lc_map[_u.c.c8]; \
  56. rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \
  57. } \
  58. _u.pp = 0; \
  59. switch (_leftover) { \
  60. case 7: \
  61. /* fallthrough */ _u.c.c7 = lc_map[(unsigned char)_s[_i++]]; \
  62. case 6: \
  63. /* fallthrough */ _u.c.c6 = lc_map[(unsigned char)_s[_i++]]; \
  64. case 5: \
  65. /* fallthrough */ _u.c.c5 = lc_map[(unsigned char)_s[_i++]]; \
  66. case 4: \
  67. /* fallthrough */ _u.c.c4 = lc_map[(unsigned char)_s[_i++]]; \
  68. case 3: \
  69. /* fallthrough */ _u.c.c3 = lc_map[(unsigned char)_s[_i++]]; \
  70. case 2: \
  71. /* fallthrough */ _u.c.c2 = lc_map[(unsigned char)_s[_i++]]; \
  72. case 1: \
  73. /* fallthrough */ _u.c.c1 = lc_map[(unsigned char)_s[_i]]; \
  74. rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \
  75. break; \
  76. } \
  77. hashv = (__typeof (hashv))rspamd_cryptobox_fast_hash_final (&_hst); \
  78. bkt = (hashv) & (num_bkts-1); \
  79. } while (0)
  80. #define HASH_KEYCMP(a,b,len) rspamd_lc_cmp(a,b,len)
  81. #endif
  82. #include "uthash.h"
  83. #endif /* UTHASH_STRCASE_H_ */