00001 /* 00002 * $Id: cr_domain.h 5299 2008-12-04 18:12:33Z henningw $ 00003 * 00004 * Copyright (C) 2007-2008 1&1 Internet AG 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 00023 /** 00024 * \file cr_domain.h 00025 * \brief Contains the functions to manage routing domains. 00026 * \ingroup carrierroute 00027 * - Module; \ref carrierroute 00028 */ 00029 00030 #ifndef CR_DOMAIN_H 00031 #define CR_DOMAIN_H 00032 00033 #include "../../str.h" 00034 #include "../../flags.h" 00035 #include "../../trie/dtrie.h" 00036 00037 00038 /** 00039 * The struct for the domain. 00040 * Contains the head of each prefix tree. 00041 */ 00042 struct domain_data_t { 00043 int id; /*!< the numerical id of the routing tree */ 00044 str * name; /*!< the name of the routing tree. This points to the name in domain_map to avoid duplication. */ 00045 struct dtrie_node_t * tree; /*!< the root node of the routing tree. Payload is of type (struct route_flags *) */ 00046 struct dtrie_node_t * failure_tree; /*!< the root node of the failure routing tree. Payload is of type (struct failure_route_rule *) */ 00047 }; 00048 00049 00050 /** 00051 * Create a new domain in shared memory and set it up. 00052 * 00053 * @param domain_id the id of the domain 00054 * @param domain_name the name of the domain 00055 * 00056 * @return a pointer to the newly allocated domain data or NULL on 00057 * error, in which case it LOGs an error message. 00058 */ 00059 struct domain_data_t * create_domain_data(int id, str * domain); 00060 00061 00062 /** 00063 * Destroys the given domain and frees the used memory. 00064 * 00065 * @param domain_data the to the structure to be destroyed. 00066 */ 00067 void destroy_domain_data(struct domain_data_t *domain_data); 00068 00069 00070 /** 00071 * Adds the given route information to the prefix tree identified by 00072 * node. scan_prefix identifies the number for which the information 00073 * is. The rewrite_* parameters define what to do in case of a match. 00074 * prob gives the probability with which this rule applies if there are 00075 * more than one for a given prefix. 00076 * 00077 * @param node the root of the routing tree 00078 * @param scan_prefix the prefix for which to add the rule (must not contain non-digits) 00079 * @param flags user defined flags 00080 * @param mask mask for user defined flags 00081 * @param full_prefix the whole scan prefix 00082 * @param max_targets the number of targets 00083 * @param prob the weight of the rule 00084 * @param rewrite_hostpart the rewrite_host of the rule 00085 * @param strip the number of digits to be stripped off userpart before prepending prefix 00086 * @param rewrite_local_prefix the rewrite prefix 00087 * @param rewrite_local_suffix the rewrite suffix 00088 * @param status the status of the rule 00089 * @param hash_index the hash index of the rule 00090 * @param backup indicates if the route is backed up by another. only 00091 useful if status==0, if set, it is the hash value 00092 of another rule 00093 * @param backed_up an -1-termintated array of hash indices of the route 00094 for which this route is backup 00095 * @param comment a comment for the route rule 00096 * 00097 * @return 0 on success, -1 on failure 00098 * 00099 * @see add_route() 00100 */ 00101 int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix, 00102 flag_t flags, flag_t mask, const str * full_prefix, int max_targets, double prob, 00103 const str * rewrite_hostpart, int strip, const str * rewrite_local_prefix, 00104 const str * rewrite_local_suffix, int status, int hash_index, 00105 int backup, int * backed_up, const str * comment); 00106 00107 00108 /** 00109 * Adds the given failure route information to the failure prefix tree identified by 00110 * failure_node. scan_prefix, host, reply_code, flags identifies the number for which 00111 * the information is and the next_domain parameters defines where to continue 00112 * routing in case of a match. 00113 * 00114 * @param failure_node the root of the failure routing tree 00115 * @param scan_prefix the prefix for which to add the rule (must not contain non-digits) 00116 * @param full_prefix the whole scan prefix 00117 * @param host the hostname last tried 00118 * @param reply_code the reply code 00119 * @param flags user defined flags 00120 * @param mask mask for user defined flags 00121 * @param next_domain continue routing with this domain id 00122 * @param comment a comment for the route rule 00123 * 00124 * @return 0 on success, -1 on failure 00125 * 00126 * @see add_route() 00127 */ 00128 int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * scan_prefix, 00129 const str * full_prefix, const str * host, const str * reply_code, 00130 const flag_t flags, const flag_t mask, const int next_domain, const str * comment); 00131 00132 00133 /** 00134 * Compares the IDs of two domain data structures. 00135 * A NULL pointer is always greater than any ID. 00136 * 00137 * @return -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2 00138 */ 00139 int compare_domain_data(const void *v1, const void *v2); 00140 00141 00142 #endif
1.5.6