ht_api.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. *
  3. * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com)
  4. *
  5. * This file is part of kamailio, a free SIP server.
  6. *
  7. * Kamailio is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef _HT_API_H_
  22. #define _HT_API_H_
  23. #include <time.h>
  24. #include "../../usr_avp.h"
  25. #include "../../locking.h"
  26. #include "../../pvar.h"
  27. #include "../../atomic_ops.h"
  28. #define ht_compute_hash(_s) core_case_hash(_s,0,0)
  29. #define ht_get_entry(_h,_size) (_h)&((_size)-1)
  30. typedef struct _ht_cell
  31. {
  32. unsigned int cellid;
  33. unsigned int msize;
  34. int flags;
  35. str name;
  36. int_str value;
  37. time_t expire;
  38. struct _ht_cell *prev;
  39. struct _ht_cell *next;
  40. } ht_cell_t;
  41. typedef struct _ht_entry
  42. {
  43. unsigned int esize; /* number of items in the slot */
  44. ht_cell_t *first; /* first item in the slot */
  45. gen_lock_t lock; /* mutex to access items in the slot */
  46. atomic_t locker_pid; /* pid of the process that holds the lock */
  47. int rec_lock_level; /* recursive lock count */
  48. } ht_entry_t;
  49. typedef struct _ht
  50. {
  51. str name;
  52. unsigned int htid;
  53. unsigned int htexpire;
  54. str dbtable;
  55. int dbmode;
  56. int flags;
  57. int_str initval;
  58. int updateexpire;
  59. unsigned int htsize;
  60. int dmqreplicate;
  61. int evrt_expired;
  62. ht_entry_t *entries;
  63. struct _ht *next;
  64. } ht_t;
  65. typedef struct _ht_pv {
  66. str htname;
  67. ht_t *ht;
  68. pv_elem_t *pve;
  69. } ht_pv_t, *ht_pv_p;
  70. int ht_add_table(str *name, int autoexp, str *dbtable, int size, int dbmode,
  71. int itype, int_str *ival, int updateexpire, int dmqreplicate);
  72. int ht_init_tables(void);
  73. int ht_destroy(void);
  74. int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode);
  75. int ht_del_cell(ht_t *ht, str *name);
  76. ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
  77. ht_cell_t *old);
  78. int ht_dbg(void);
  79. ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old);
  80. int ht_cell_pkg_free(ht_cell_t *cell);
  81. int ht_cell_free(ht_cell_t *cell);
  82. int ht_table_spec(char *spec);
  83. ht_t* ht_get_table(str *name);
  84. int ht_db_load_tables(void);
  85. int ht_db_sync_tables(void);
  86. int ht_has_autoexpire(void);
  87. void ht_timer(unsigned int ticks, void *param);
  88. void ht_handle_expired_record(ht_t *ht, ht_cell_t *cell);
  89. void ht_expired_run_event_route(int routeid);
  90. int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val);
  91. int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val);
  92. int ht_rm_cell_re(str *sre, ht_t *ht, int mode);
  93. int ht_count_cells_re(str *sre, ht_t *ht, int mode);
  94. ht_t *ht_get_root(void);
  95. int ht_reset_content(ht_t *ht);
  96. void ht_iterator_init(void);
  97. int ht_iterator_start(str *iname, str *hname);
  98. int ht_iterator_next(str *iname);
  99. int ht_iterator_end(str *iname);
  100. ht_cell_t* ht_iterator_get_current(str *iname);
  101. void ht_slot_lock(ht_t *ht, int idx);
  102. void ht_slot_unlock(ht_t *ht, int idx);
  103. #endif