cr_rule.h

Go to the documentation of this file.
00001 /*
00002  * $Id: cr_rule.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_rule.h
00025  * \brief Contains the functions to manage routing rule data.
00026  * \ingroup carrierroute
00027  * - Module; \ref carrierroute
00028  */
00029 
00030 #ifndef CR_RULE_H
00031 #define CR_RULE_H
00032 
00033 #include "../../str.h"
00034 #include "../../flags.h"
00035 
00036 
00037 /*! list of rules */
00038 struct route_rule_p_list;
00039 
00040 /**
00041  * Second stage of processing: Try to map the end of the user part of the URI
00042  * to a given suffix. Then rewrite with given parameters.
00043  */
00044 struct route_rule {
00045    int dice_to; /*!< prob * DICE_MAX */
00046    double prob; /*!< The probability for that rule, only useful when using crc32 hashing */
00047    double orig_prob; /*!< The original probability for that rule, only useful when using crc32 hashing */
00048    str host; /*!< The new target host for the request */
00049    int strip; /*!< the number of digits to be stripped off from uri befor prepending prefix */
00050    str local_prefix; /*!< the pefix to be attached to the new destination */
00051    str local_suffix; /*!< the suffix to be appended to the localpart of the new destination */
00052    str comment; /*!< A comment for the route rule */
00053    str prefix; /*!< The prefix for which the route is valid */
00054    int status; /*!< The status of the route rule, only useful when using prime number hashing */
00055    struct route_rule_p_list * backed_up; /*!< indicates if the rule is already backup route for another */
00056    struct route_rule_p_list * backup; /*!< if not NULL, it points to a route rule which shall be used instead (only used if status is 0) */
00057    int hash_index; /*!< The hash index of the route rule, only useful when using prime number hashing */
00058    struct route_rule * next; /*!< A pointer to the next route rule */
00059 };
00060 
00061 /**
00062  * list of routing rules with hash index
00063  */
00064 struct route_rule_p_list {
00065    struct route_rule * rr;
00066    int hash_index;
00067    struct route_rule_p_list * next;
00068 };
00069 
00070 /**
00071  * Use route rules only if message flags match stored mask/flags.
00072  */
00073 struct route_flags {
00074    flag_t flags;  /*!< The flags for which the route ist valid */
00075    flag_t mask;  /*!< The mask for the flags field */
00076    struct route_rule * rule_list; /*!< Each node MAY contain a rule list */
00077    struct route_rule ** rules; /*!< The array points to the rules in order of hash indices */
00078    int rule_num; /*!< The number of rules */
00079    int dice_max; /*!< The DICE_MAX value for the rule set, calculated by rule_fixup */
00080    int max_targets; /*!< upper edge of hashing via prime number algorithm, must be eqal to rule_num */
00081    struct route_flags * next; /*!< A pointer to the next route flags struct */
00082 };
00083 
00084 /**
00085  * Second stage of processing: Try to map the end of the user part of the URI
00086  * to a given suffix. Then rewrite with given parameters.
00087  */
00088 struct failure_route_rule {
00089    str host; /*!< The new target host for the request */
00090    str comment; /*!< A comment for the route rule */
00091    str prefix; /*!< The prefix for which the route ist valid */
00092    str reply_code;  /*!< The reply code for which the route ist valid */
00093    int next_domain;  /*!< The domain id where to continue routing */
00094    flag_t flags;  /*!< The flags for which the route ist valid */
00095    flag_t mask;  /*!< The mask for the flags field */
00096    struct failure_route_rule * next; /*!< A pointer to the next route rule */
00097 };
00098 
00099 
00100 /**
00101  * Adds a route rule to rf
00102  *
00103  * @param rf the current route_flags struct
00104  * @param prefix the whole scan prefix
00105  * @param max_targets the number of targets
00106  * @param prob the weight of the rule
00107  * @param rewrite_hostpart the rewrite_host of the rule
00108  * @param strip the number of digits to be stripped off userpart before prepending prefix
00109  * @param rewrite_local_prefix the rewrite prefix
00110  * @param rewrite_local_suffix the rewrite suffix
00111  * @param status the status of the rule
00112  * @param hash_index the hash index of the rule
00113  * @param backup indicates if the route is backed up by another. only
00114                  useful if status==0, if set, it is the hash value
00115                  of another rule
00116  * @param backed_up an NULL-termintated array of hash indices of the route
00117                     for which this route is backup
00118  * @param comment a comment for the route rule
00119  *
00120  * @return 0 on success, -1 on failure
00121  *
00122  * @see add_route_to_tree()
00123  */
00124 int add_route_rule(struct route_flags *rf, const str * prefix,
00125       int max_targets, double prob, const str * rewrite_hostpart, int strip,
00126       const str * rewrite_local_prefix, const str * rewrite_local_suffix,
00127       int status, int hash_index, int backup, int * backed_up,
00128       const str * comment);
00129 
00130 
00131 /**
00132  * Destroys route rule rr by freeing all its memory.
00133  *
00134  * @param rr route rule to be destroyed
00135  */
00136 void destroy_route_rule(struct route_rule * rr);
00137 
00138 
00139 /**
00140  * Try to find a matching route_flags struct in rt and return it, add it if not found.
00141  *
00142  * @param rf_head pointer to the head of the route flags list, might be changed during insert
00143  * @param flags user defined flags
00144  * @param mask mask for user defined flags
00145  *
00146  * @return pointer to the route_flags struct on success, NULL on failure.
00147  *
00148  */
00149 struct route_flags * add_route_flags(struct route_flags **rf_head, const flag_t flags, const flag_t mask);
00150 
00151 
00152 /**
00153  * Destroys route_flags in shared memory by freing all its memory.
00154  *
00155  * @param rf route_flags struct to be destroyed
00156  */
00157 void destroy_route_flags(struct route_flags *rf);
00158 
00159 
00160 /**
00161  * Adds a failure route rule to rule list. prefix, host, reply_code, and comment
00162  * must not contain NULL pointers.
00163  *
00164  * @param frr_head pointer to the head of the failure route rule list, might be changed during insert
00165  * @param prefix the whole scan prefix
00166  * @param host the hostname last tried
00167  * @param reply_code the reply code 
00168  * @param flags user defined flags
00169  * @param mask mask for user defined flags
00170  * @param next_domain continue routing with this domain
00171  * @param comment a comment for the route rule
00172  *
00173  * @return pointer to the failure_route_rul struct on success, NULL on failure.
00174  *
00175  * @see add_failure_route_to_tree()
00176  */
00177 struct failure_route_rule *add_failure_route_rule(struct failure_route_rule **frr_head,
00178       const str * prefix, const str * host, const str * reply_code,
00179       flag_t flags, flag_t mask, const int next_domain, const str * comment);
00180 
00181 
00182 /**
00183  * Destroys failure route rule frr by freeing all its memory.
00184  *
00185  * @param frr route rule to be destroyed
00186  */
00187 void destroy_failure_route_rule(struct failure_route_rule * frr);
00188 
00189 struct route_rule * find_rule_by_hash(struct route_flags * rf, int hash);
00190 
00191 struct route_rule * find_rule_by_host(struct route_flags * rf, str * host);
00192 
00193 int add_backup_rule(struct route_rule * rule, struct route_rule * backup);
00194 
00195 int remove_backed_up(struct route_rule * rule);
00196 
00197 struct route_rule * find_auto_backup(struct route_flags * rf, struct route_rule * rule);
00198 
00199 #endif

Generated on Mon May 21 18:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6