domains.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG FOKUS
  5. * Copyright (C) 2008 iptelorg GmbH
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #ifndef _DOMAINS_H_
  29. #define _DOMAINS_H_
  30. #include "../../str.h"
  31. #define MAX_HSIZE_TWO_POW 20
  32. #define MAX_HASH_SIZE 1<<MAX_HSIZE_TWO_POW
  33. #define PDT_ADD 1
  34. #define PDT_DELETE 2
  35. #define get_hash_entry(c,s) (c)&((s)-1)
  36. typedef struct _pd
  37. {
  38. str prefix;
  39. str domain;
  40. int flag;
  41. unsigned int dhash;
  42. struct _pd *p;
  43. struct _pd *n;
  44. } pd_t;
  45. typedef struct _pd_entry
  46. {
  47. gen_lock_t lock;
  48. pd_t *e;
  49. } pd_entry_t;
  50. typedef struct _pd_op
  51. {
  52. pd_t *cell;
  53. int op;
  54. int id;
  55. int count;
  56. struct _pd_op *p;
  57. struct _pd_op *n;
  58. } pd_op_t;
  59. typedef struct _pdt_hash
  60. {
  61. pd_entry_t* dhash;
  62. unsigned int hash_size;
  63. pd_op_t *diff;
  64. gen_lock_t diff_lock;
  65. int max_id;
  66. int workers;
  67. } pdt_hash_t;
  68. pd_t* new_cell(str* p, str *d);
  69. void free_cell(pd_t *cell);
  70. pd_op_t* new_pd_op(pd_t *cell, int id, int op);
  71. void free_pd_op(pd_op_t *pdo);
  72. int pdt_add_to_hash(pdt_hash_t *ph, str *sp, str *sd);
  73. int pdt_remove_from_hash(pdt_hash_t *ph, str *sd);
  74. str* pdt_get_prefix(pdt_hash_t *ph, str* sd);
  75. int pdt_check_pd(pdt_hash_t *ph, str *sp, str *sd);
  76. void pdt_print_hash(pdt_hash_t *ph);
  77. pdt_hash_t* pdt_init_hash(int hash_size);
  78. void pdt_free_hash(pdt_hash_t* ph);
  79. unsigned int pdt_compute_hash(char *s);
  80. #endif