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 24 25 #ifndef _MTREE_H_ 26 #define _MTREE_H_ 27 28 #include "../../core/str.h" 29 #include "../../core/parser/msg_parser.h" 30 #include "../../core/rpc.h" 31 32 #define MT_TREE_SVAL 0 33 #define MT_TREE_DW 1 34 #define MT_TREE_IVAL 2 35 36 typedef union { 37 int n; 38 str s; 39 } is_t; 40 41 typedef struct _mt_dw 42 { 43 unsigned int dstid; 44 unsigned int weight; 45 struct _mt_dw *next; 46 } mt_dw_t; 47 48 typedef struct _mt_is 49 { 50 is_t tvalue; 51 struct _mt_is *next; 52 } mt_is_t; 53 54 typedef struct _mt_node 55 { 56 mt_is_t *tvalues; 57 void *data; 58 struct _mt_node *child; 59 } mt_node_t; 60 61 #define MT_MAX_DEPTH 64 62 63 #define MT_NODE_SIZE mt_char_list.len 64 65 #define MT_MAX_COLS 8 66 typedef struct _m_tree 67 { 68 str tname; 69 str dbtable; 70 int type; 71 int multi; 72 int ncols; 73 str scols[MT_MAX_COLS]; 74 char pack[4]; 75 unsigned int nrnodes; 76 unsigned int nritems; 77 unsigned int memsize; 78 unsigned int reload_count; 79 unsigned int reload_time; 80 mt_node_t *head; 81 struct _m_tree *next; 82 } m_tree_t; 83 84 85 /* prefix tree operations */ 86 int mt_add_to_tree(m_tree_t *pt, str *tprefix, str *svalue); 87 88 m_tree_t* mt_get_tree(str *tname); 89 m_tree_t* mt_get_first_tree(); 90 91 is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch, int *len); 92 int mt_match_prefix(struct sip_msg *msg, m_tree_t *pt, 93 str *tomatch, int mode); 94 95 m_tree_t* mt_init_tree(str* tname, str* dbtable, str *scols, int type, 96 int multi); 97 void mt_free_tree(m_tree_t *pt); 98 int mt_print_tree(m_tree_t *pt); 99 void mt_free_node(mt_node_t *pn, int type); 100 101 void mt_char_table_init(void); 102 int mt_node_set_payload(mt_node_t *node, int type); 103 int mt_node_unset_payload(mt_node_t *node, int type); 104 105 int mt_table_spec(char* val); 106 void mt_destroy_trees(void); 107 int mt_defined_trees(void); 108 109 m_tree_t *mt_swap_list_head(m_tree_t *ntree); 110 int mt_init_list_head(void); 111 m_tree_t *mt_add_tree(m_tree_t **dpt, str *tname, str *dbtable, 112 str *cols, int type, int multi); 113 114 int mt_rpc_match_prefix(rpc_t* rpc, void* ctx, m_tree_t *pt, 115 str *tomatch, int mode); 116 #endif 117 118