mtree.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * This file is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * This file is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. #ifndef _MTREE_H_
  24. #define _MTREE_H_
  25. #include "../../str.h"
  26. #include "../../parser/msg_parser.h"
  27. #include "../../lib/kmi/mi.h"
  28. #include "../../rpc.h"
  29. #define MT_TREE_SVAL 0
  30. #define MT_TREE_DW 1
  31. #define MT_TREE_IVAL 2
  32. typedef union {
  33. int n;
  34. str s;
  35. } is_t;
  36. typedef struct _mt_dw
  37. {
  38. unsigned int dstid;
  39. unsigned int weight;
  40. struct _mt_dw *next;
  41. } mt_dw_t;
  42. typedef struct _mt_is
  43. {
  44. is_t tvalue;
  45. struct _mt_is *next;
  46. } mt_is_t;
  47. typedef struct _mt_node
  48. {
  49. mt_is_t *tvalues;
  50. void *data;
  51. struct _mt_node *child;
  52. } mt_node_t;
  53. #define MT_MAX_DEPTH 32
  54. #define MT_NODE_SIZE mt_char_list.len
  55. typedef struct _m_tree
  56. {
  57. str tname;
  58. str dbtable;
  59. int type;
  60. int multi;
  61. unsigned int nrnodes;
  62. unsigned int nritems;
  63. unsigned int memsize;
  64. unsigned int reload_count;
  65. unsigned int reload_time;
  66. mt_node_t *head;
  67. struct _m_tree *next;
  68. } m_tree_t;
  69. /* prefix tree operations */
  70. int mt_add_to_tree(m_tree_t *pt, str *tprefix, str *svalue);
  71. m_tree_t* mt_get_tree(str *tname);
  72. m_tree_t* mt_get_first_tree();
  73. is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch, int *len);
  74. int mt_match_prefix(struct sip_msg *msg, m_tree_t *pt,
  75. str *tomatch, int mode);
  76. m_tree_t* mt_init_tree(str* tname, str* dbtable, int type, int multi);
  77. void mt_free_tree(m_tree_t *pt);
  78. int mt_print_tree(m_tree_t *pt);
  79. void mt_free_node(mt_node_t *pn, int type);
  80. void mt_char_table_init(void);
  81. int mt_node_set_payload(mt_node_t *node, int type);
  82. int mt_node_unset_payload(mt_node_t *node, int type);
  83. int mt_table_spec(char* val);
  84. void mt_destroy_trees(void);
  85. int mt_defined_trees(void);
  86. m_tree_t *mt_swap_list_head(m_tree_t *ntree);
  87. int mt_init_list_head(void);
  88. m_tree_t *mt_add_tree(m_tree_t **dpt, str *tname, str *dbtable,
  89. int type, int multi);
  90. int mt_mi_match_prefix(struct mi_node *rpl, m_tree_t *pt,
  91. str *tomatch, int mode);
  92. int mt_rpc_match_prefix(rpc_t* rpc, void* ctx, m_tree_t *pt,
  93. str *tomatch, int mode);
  94. #endif