prefix_tree.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2005-2009 Voice Sistem SRL
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio 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. * Kamailio 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. * History:
  23. * ---------
  24. * 2005-02-20 first version (cristian)
  25. * 2005-02-27 ported to 0.9.0 (bogdan)
  26. */
  27. #ifndef prefix_tree_h
  28. #define prefix_tree_h
  29. #include "../../str.h"
  30. #include "../../ip_addr.h"
  31. #include "dr_time.h"
  32. #define PTREE_CHILDREN 10
  33. #define IS_DECIMAL_DIGIT(d) \
  34. (((d)>='0') && ((d)<= '9'))
  35. extern int tree_size;
  36. #define INIT_PTREE_NODE(p, n) \
  37. do {\
  38. (n) = (ptree_t*)shm_malloc(sizeof(ptree_t));\
  39. if(NULL == (n))\
  40. goto err_exit;\
  41. tree_size+=sizeof(ptree_t);\
  42. memset((n), 0, sizeof(ptree_t));\
  43. (n)->bp=(p);\
  44. }while(0);
  45. /* list of PSTN gw */
  46. typedef struct pgw_addr_ {
  47. struct ip_addr ip;
  48. unsigned short port;
  49. int type;
  50. int strip;
  51. struct pgw_addr_ *next;
  52. }pgw_addr_t;
  53. /* list of PSTN gw */
  54. typedef struct pgw_ {
  55. /* id matching the one in db */
  56. long id;
  57. str pri;
  58. int strip;
  59. str ip;
  60. int type;
  61. str attrs;
  62. struct pgw_ *next;
  63. }pgw_t;
  64. /**/
  65. typedef struct pgw_list_ {
  66. pgw_t *pgw;
  67. int grpid;
  68. }pgw_list_t;
  69. /* element containing routing information */
  70. typedef struct rt_info_ {
  71. unsigned int priority;
  72. tmrec_t *time_rec;
  73. /* array of pointers into the PSTN gw list */
  74. pgw_list_t *pgwl;
  75. /* length of the PSTN gw array */
  76. unsigned short pgwa_len;
  77. /* how many list link this element */
  78. unsigned short ref_cnt;
  79. /* script route to be executed */
  80. int route_idx;
  81. } rt_info_t;
  82. typedef struct rt_info_wrp_ {
  83. rt_info_t *rtl;
  84. struct rt_info_wrp_ *next;
  85. } rt_info_wrp_t;
  86. typedef struct rg_entry_ {
  87. unsigned int rgid;
  88. rt_info_wrp_t *rtlw;
  89. } rg_entry_t;
  90. typedef struct ptree_node_ {
  91. unsigned int rg_len;
  92. unsigned int rg_pos;
  93. rg_entry_t *rg;
  94. struct ptree_ *next;
  95. } ptree_node_t;
  96. typedef struct ptree_ {
  97. /* backpointer */
  98. struct ptree_ *bp;
  99. ptree_node_t ptnode[PTREE_CHILDREN];
  100. } ptree_t;
  101. void
  102. print_interim(
  103. int,
  104. int,
  105. ptree_t*
  106. );
  107. int
  108. del_tree(
  109. ptree_t *
  110. );
  111. int
  112. add_prefix(
  113. ptree_t*,
  114. /* prefix */
  115. str*,
  116. rt_info_t *,
  117. unsigned int
  118. );
  119. rt_info_t*
  120. get_prefix(
  121. ptree_t *ptree,
  122. str* prefix,
  123. unsigned int rgid
  124. );
  125. int
  126. add_rt_info(
  127. ptree_node_t*,
  128. rt_info_t*,
  129. unsigned int
  130. );
  131. pgw_t*
  132. get_pgw(
  133. pgw_t*,
  134. long
  135. );
  136. void
  137. del_rt_list(
  138. rt_info_wrp_t *rl
  139. );
  140. void print_rt(
  141. rt_info_t*
  142. );
  143. void
  144. free_rt_info(
  145. rt_info_t*
  146. );
  147. rt_info_t*
  148. check_rt(
  149. ptree_node_t *ptn,
  150. unsigned int rgid
  151. );
  152. #endif