routing.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 #ifndef routing_h
00030 #define routing_h
00031 
00032 #include "../../str.h"
00033 #include "../../usr_avp.h"
00034 #include "prefix_tree.h"
00035 #include "dr_time.h"
00036 
00037 #define RG_HASH_SIZE
00038 #define RG_INIT_LEN 4;
00039 
00040 /* the buckets for the rt_data rg_hash */
00041 typedef struct hb_ {
00042         int rgid;
00043         ptree_t *pt;
00044         struct hb_*next;
00045 } hb_t;
00046 
00047 /* routing data is comprised of:
00048         - a list of PSTN gw
00049         - a hash over routing groups containing 
00050         pointers to the coresponding prefix trees
00051 */
00052 typedef struct rt_data_ {
00053         /* list of PSTN gw */
00054         pgw_t *pgw_l;
00055         /* list of IP addr for PSTN gw */
00056         pgw_addr_t *pgw_addr_l;
00057         /* default routing list for prefixless rules */
00058         ptree_node_t noprefix;
00059         /* hash table with routing prefixes */
00060         ptree_t *pt;
00061 }rt_data_t;
00062 
00063 typedef struct _dr_group {
00064         /* 0 - use grp ; 1 - use AVP */
00065         int type;
00066         union {
00067                 unsigned int grp_id;
00068                 struct _avp_id{
00069                         int_str name;
00070                         unsigned short type;
00071                 }avp_id;
00072         }u;
00073 } dr_group_t;
00074 
00075 /* init new rt_data structure */
00076 rt_data_t*
00077 build_rt_data( void );
00078 
00079 
00080 /* add a PSTN gw in the list */
00081 int
00082 add_dst(
00083         rt_data_t*,
00084         /* id */
00085         int ,
00086         /* ip address */ 
00087         char*,
00088         /* strip len */
00089         int,
00090         /* pri prefix */
00091         char*,
00092         /* dst type*/
00093         int,
00094         /* dst attrs*/
00095         char*
00096         );
00097 
00098 /* build a routing info list element */
00099 rt_info_t*
00100 build_rt_info(
00101         int priority,
00102         tmrec_t* time,
00103         /* ser routing table id */
00104         int route_id,
00105         /* list of destinations indexes */
00106         char* dstlst,
00107         pgw_t* pgw_l
00108 );
00109 
00110 void
00111 del_pgw_list(
00112                 pgw_t *pgw_l
00113                 );
00114 
00115 void 
00116 free_rt_data(
00117                 rt_data_t*,
00118                 int
00119                 );
00120 #endif