prefix_tree.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2005-2009 Voice Sistem SRL
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021  *
00022  * History:
00023  * ---------
00024  *  2005-02-20  first version (cristian)
00025  *  2005-02-27  ported to 0.9.0 (bogdan)
00026  */
00027 
00028 
00029 
00030 #ifndef prefix_tree_h
00031 #define prefix_tree_h
00032 
00033 #include "../../str.h"
00034 #include "../../ip_addr.h"
00035 #include "dr_time.h"
00036 
00037 #define PTREE_CHILDREN 10
00038 #define IS_DECIMAL_DIGIT(d) \
00039         (((d)>='0') && ((d)<= '9'))
00040 
00041 extern int tree_size;
00042 
00043 #define INIT_PTREE_NODE(p, n) \
00044 do {\
00045         (n) = (ptree_t*)shm_malloc(sizeof(ptree_t));\
00046         if(NULL == (n))\
00047                 goto err_exit;\
00048         tree_size+=sizeof(ptree_t);\
00049         memset((n), 0, sizeof(ptree_t));\
00050         (n)->bp=(p);\
00051 }while(0);
00052 
00053 
00054 /* list of PSTN gw */
00055 typedef struct pgw_addr_ {
00056         struct ip_addr ip;
00057         unsigned short port;
00058         int type;
00059         int strip;
00060         struct pgw_addr_ *next;
00061 }pgw_addr_t;
00062 
00063 /* list of PSTN gw */
00064 typedef struct pgw_ {
00065         /* id matching the one in db */
00066         long id;
00067         str pri;
00068         int strip;
00069         str ip;
00070         int type;
00071         str attrs;
00072         struct pgw_ *next;
00073 }pgw_t;
00074 
00075 
00076 typedef struct pgw_list_ {
00077         pgw_t *pgw;
00078         int    grpid;
00079 }pgw_list_t;
00080 
00081 /* element containing routing information */
00082 typedef struct rt_info_ {
00083         unsigned int priority;
00084         tmrec_t *time_rec;
00085         /* array of pointers into the PSTN gw list */
00086         pgw_list_t *pgwl;
00087         /* length of the PSTN gw array */
00088         unsigned short pgwa_len;
00089         /* how many list link this element */
00090         unsigned short ref_cnt;
00091         /* script route to be executed */
00092         int route_idx;
00093 } rt_info_t;
00094 
00095 typedef struct rt_info_wrp_ {
00096         rt_info_t     *rtl;
00097         struct rt_info_wrp_  *next;
00098 } rt_info_wrp_t;
00099 
00100 typedef struct rg_entry_ {
00101         unsigned int rgid;
00102         rt_info_wrp_t *rtlw;
00103 } rg_entry_t;
00104 
00105 typedef struct ptree_node_ {
00106         unsigned int rg_len;
00107         unsigned int rg_pos;
00108         rg_entry_t *rg;
00109         struct ptree_ *next;
00110 } ptree_node_t;
00111 
00112 typedef struct ptree_ {
00113         /* backpointer */
00114         struct ptree_ *bp;
00115         ptree_node_t ptnode[PTREE_CHILDREN];
00116 } ptree_t;
00117 
00118 void 
00119 print_interim(
00120                 int,
00121                 int,
00122                 ptree_t*
00123                 );
00124 
00125 int
00126 del_tree(
00127         ptree_t *
00128         );
00129 
00130 int
00131 add_prefix(
00132         ptree_t*,
00133         /* prefix */
00134         str*,
00135         rt_info_t *,
00136         unsigned int
00137         );
00138 
00139 rt_info_t*
00140 get_prefix(
00141         ptree_t *ptree,
00142         str* prefix,
00143         unsigned int rgid
00144         );
00145 
00146 int
00147 add_rt_info(
00148         ptree_node_t*, 
00149         rt_info_t*,
00150         unsigned int
00151         );
00152 
00153 pgw_t*
00154 get_pgw(
00155         pgw_t*,
00156         long
00157         );
00158 
00159 void
00160 del_rt_list(
00161         rt_info_wrp_t *rl
00162         );
00163 
00164 void print_rt(
00165         rt_info_t*
00166         );
00167 
00168 void
00169 free_rt_info(
00170         rt_info_t*
00171         );
00172 
00173 rt_info_t*
00174 check_rt(
00175         ptree_node_t *ptn,
00176         unsigned int rgid
00177         );
00178 
00179 #endif