/** * Adds the given route information to the route tree identified by * route_tree. scan_prefix identifies the number for which the information * is and the rewrite_* parameters define what to do in case of a match. * prob gives the probability with which this rule applies if there are * more than one for a given prefix. * * Note that this is a recursive function. It strips off digits from the * beginning of scan_prefix and calls itself. * * @param route_tree the current route tree node * @param scan_prefix the prefix at the current position * @param flags user defined flags * @param mask mask for user defined flags * @param full_prefix the whole scan prefix * @param max_targets the number of targets * @param prob the weight of the rule * @param rewrite_hostpart the rewrite_host of the rule * @param strip the number of digits to be stripped off userpart before prepending prefix * @param rewrite_local_prefix the rewrite prefix * @param rewrite_local_suffix the rewrite suffix * @param status the status of the rule * @param hash_index the hash index of the rule * @param backup indicates if the route is backed up by another. only useful if status==0, if set, it is the hash value of another rule * @param backed_up an -1-termintated array of hash indices of the route for which this route is backup * @param comment a comment for the route rule * * @return 0 on success, -1 on failure * * @see add_route() */ int add_route_to_tree(struct route_tree_item * route_tree, const str * scan_prefix, flag_t flags, flag_t mask, const str * full_prefix, int max_targets, double prob, const str * rewrite_hostpart, int strip, const str * rewrite_local_prefix, const str * rewrite_local_suffix, int status, int hash_index, int backup, int * backed_up, const str * comment) { str next_prefix; struct route_flags *rf; if (scan_prefix->len == 0) { rf = add_route_flags(route_tree, flags, mask); if (rf==NULL) { LM_ERR("cannot add route_flags struct to route_tree\n"); return -1; } return add_route_rule(rf, full_prefix, max_targets, prob, rewrite_hostpart, strip, rewrite_local_prefix, rewrite_local_suffix, status, hash_index, backup, backed_up, comment); } else { if (route_tree->nodes[*scan_prefix->s - '0'] == NULL) { route_tree->nodes[*scan_prefix->s - '0'] = create_route_tree_item(); if (route_tree->nodes[*scan_prefix->s - '0'] == NULL) { return -1; } } next_prefix.s = scan_prefix->s + 1; next_prefix.len = scan_prefix->len - 1; return add_route_to_tree(route_tree->nodes[*scan_prefix->s - '0'], &next_prefix, flags, mask, full_prefix, max_targets, prob, rewrite_hostpart, strip, rewrite_local_prefix, rewrite_local_suffix, status, hash_index, backup, backed_up, comment); } }
/** * Adds the given route information to the route tree identified by * route_tree. scan_prefix identifies the number for which the information * is and the rewrite_* parameters define what to do in case of a match. * prob gives the probability with which this rule applies if there are * more than one for a given prefix. * * Note that this is a recursive function. It strips off digits from the * beginning of scan_prefix and calls itself. * * @param rt the current route tree node * @param scan_prefix the prefix at the current position * @param full_prefix the whole scan prefix * @param max_targets the number of targets * @param prob the weight of the rule * @param rewrite_hostpart the rewrite_host of the rule * @param strip the number of digits to be stripped off userpart before prepending prefix * @param rewrite_local_prefix the rewrite prefix * @param rewrite_local_suffix the rewrite suffix * @param status the status of the rule * @param hash_index the hash index of the rule * @param backup indicates if the route is backed up by another. only useful if status==0, if set, it is the hash value of another rule * @param backed_up an -1-termintated array of hash indices of the route for which this route is backup * @param comment a comment for the route rule * * @return 0 on success, -1 on failure * * @see add_route() */ int add_route_to_tree(struct route_tree_item * route_tree, const char * scan_prefix, const char * full_prefix, int max_targets, double prob, const char * rewrite_hostpart, int strip, const char * rewrite_local_prefix, const char * rewrite_local_suffix, int status, int hash_index, int backup, int * backed_up, const char * comment) { if (!scan_prefix || *scan_prefix == '\0') { return add_route_rule(route_tree, full_prefix, max_targets, prob, rewrite_hostpart, strip, rewrite_local_prefix, rewrite_local_suffix, status, hash_index, backup, backed_up, comment); } else { if (route_tree->nodes[*scan_prefix - '0'] == NULL) { route_tree->nodes[*scan_prefix - '0'] = create_route_tree_item(); if (route_tree->nodes[*scan_prefix - '0'] == NULL) { return -1; } } return add_route_to_tree(route_tree->nodes[*scan_prefix - '0'], scan_prefix + 1, full_prefix, max_targets, prob, rewrite_hostpart, strip, rewrite_local_prefix, rewrite_local_suffix, status, hash_index, backup, backed_up, comment); } }