Browse Source

- add support for non-digit matching to trie utility functions
- supports the old method (1 to 9), and the standard ascii set (0 - 127)
- add new config variable 'match_mode' to carrierroute to configure the
prefix matching mode, the default is the old behaviour
- port userblacklist to new trie interface, this don't support the extended
matching yet


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5227 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 năm trước cách đây
mục cha
commit
cc0ba2f059

+ 45 - 26
modules/carrierroute/README

@@ -40,6 +40,7 @@ Henning Westerholt
               1.3.8. use_domain (int)
               1.3.8. use_domain (int)
               1.3.9. fallback_default (int)
               1.3.9. fallback_default (int)
               1.3.10. fetch_rows (integer)
               1.3.10. fetch_rows (integer)
+              1.3.11. match_mode (integer)
 
 
         1.4. Exported Functions
         1.4. Exported Functions
 
 
@@ -115,23 +116,24 @@ Henning Westerholt
    1.8. Set use_domain parameter
    1.8. Set use_domain parameter
    1.9. Set fallback_default parameter
    1.9. Set fallback_default parameter
    1.10. Set fetch_rows parameter
    1.10. Set fetch_rows parameter
-   1.11. cr_replace_host usage
-   1.12. cr_deactivate_host usage
-   1.13. cr_activate_host usage
-   1.14. cr_add_host usage
-   1.15. cr_delete_host usage
-   1.16. Configuration example - Routing to default tree
-   1.17. Configuration example - Routing to user tree
-   1.18. Configuration example - module configuration
-   1.19. Example database content - carrierroute table
-   1.20. Example database content - simple carrierfailureroute
+   1.11. Set match_mode parameter
+   1.12. cr_replace_host usage
+   1.13. cr_deactivate_host usage
+   1.14. cr_activate_host usage
+   1.15. cr_add_host usage
+   1.16. cr_delete_host usage
+   1.17. Configuration example - Routing to default tree
+   1.18. Configuration example - Routing to user tree
+   1.19. Configuration example - module configuration
+   1.20. Example database content - carrierroute table
+   1.21. Example database content - simple carrierfailureroute
           table
           table
 
 
-   1.21. Example database content - more complex
+   1.22. Example database content - more complex
           carrierfailureroute table
           carrierfailureroute table
 
 
-   1.22. Example database content - carrier_name table
-   1.23. Necessary extensions for the user table
+   1.23. Example database content - carrier_name table
+   1.24. Necessary extensions for the user table
    2.1. Set db_url parameter
    2.1. Set db_url parameter
    2.2. Set carrierroute_table parameter
    2.2. Set carrierroute_table parameter
    2.3. Set carrierroute_id_col parameter
    2.3. Set carrierroute_id_col parameter
@@ -380,6 +382,23 @@ modparam("carrierroute", "fallback_default", 1)
 modparam("carrierroute", "fetch_rows", 3000)
 modparam("carrierroute", "fetch_rows", 3000)
 ...
 ...
 
 
+1.3.11. match_mode (integer)
+
+   The number of individual characters that are used for matching.
+   Valid values are 10 or 128. When you specifiy 10, only digits
+   will be used for matching, this operation mode is equivalent to
+   the old behaviour. When configured with 128, all standard ascii
+   chars are available for matching. Please be aware that memory
+   requirements for storing the routing tree in shared memory will
+   also increase by a factor of 12.8.
+
+   Default value is "10".
+
+   Example 1.11. Set match_mode parameter
+...
+modparam("carrierroute", "match_mode", 10)
+...
+
 1.4. Exported Functions
 1.4. Exported Functions
 
 
    Previous versions of carrierroute had some more function. All
    Previous versions of carrierroute had some more function. All
@@ -564,7 +583,7 @@ reply_code, dstavp)
 
 
    Use the "null" prefix to specify an empty prefix.
    Use the "null" prefix to specify an empty prefix.
 
 
-   Example 1.11. cr_replace_host usage
+   Example 1.12. cr_replace_host usage
 ...
 ...
 kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
 kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
 ...
 ...
@@ -586,7 +605,7 @@ kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
 
 
    Use the "null" prefix to specify an empty prefix.
    Use the "null" prefix to specify an empty prefix.
 
 
-   Example 1.12. cr_deactivate_host usage
+   Example 1.13. cr_deactivate_host usage
 ...
 ...
 kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
 kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
 ...
 ...
@@ -602,7 +621,7 @@ kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
 
 
    Use the "null" prefix to specify an empty prefix.
    Use the "null" prefix to specify an empty prefix.
 
 
-   Example 1.13. cr_activate_host usage
+   Example 1.14. cr_activate_host usage
 ...
 ...
 kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
 kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
 ...
 ...
@@ -622,7 +641,7 @@ kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
 
 
    Use the "null" prefix to specify an empty prefix.
    Use the "null" prefix to specify an empty prefix.
 
 
-   Example 1.14. cr_add_host usage
+   Example 1.15. cr_add_host usage
 ...
 ...
 kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
 kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
 ...
 ...
@@ -643,14 +662,14 @@ kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
 
 
    Use the "null" prefix to specify an empty prefix.
    Use the "null" prefix to specify an empty prefix.
 
 
-   Example 1.15. cr_delete_host usage
+   Example 1.16. cr_delete_host usage
 ...
 ...
 kamctl fifo cr_delete_host "-d proxy -p 49 -h proxy1 -w 0.25"
 kamctl fifo cr_delete_host "-d proxy -p 49 -h proxy1 -w 0.25"
 ...
 ...
 
 
 1.6. Examples
 1.6. Examples
 
 
-   Example 1.16. Configuration example - Routing to default tree
+   Example 1.17. Configuration example - Routing to default tree
 ...
 ...
 route {
 route {
         # route calls based on hash over callid
         # route calls based on hash over callid
@@ -684,7 +703,7 @@ failure_route[2] {
 }
 }
 
 
 
 
-   Example 1.17. Configuration example - Routing to user tree
+   Example 1.18. Configuration example - Routing to user tree
 ...
 ...
 route[1] {
 route[1] {
         cr_user_carrier("$fU", "$fd", "$avp(s:carrier)");
         cr_user_carrier("$fU", "$fd", "$avp(s:carrier)");
@@ -724,7 +743,7 @@ failure_route[1] {
 }
 }
 ...
 ...
 
 
-   Example 1.18. Configuration example - module configuration
+   Example 1.19. Configuration example - module configuration
 
 
    The following config file specifies within the default carrier
    The following config file specifies within the default carrier
    two domains, each with an prefix that contains two hosts. It is
    two domains, each with an prefix that contains two hosts. It is
@@ -804,7 +823,7 @@ domain register {
    For a minimal configuration either use the config file given
    For a minimal configuration either use the config file given
    above, or insert some data into the tables of the module.
    above, or insert some data into the tables of the module.
 
 
-   Example 1.19. Example database content - carrierroute table
+   Example 1.20. Example database content - carrierroute table
 ...
 ...
 +----+---------+--------+-------------+-------+------+---------------+
 +----+---------+--------+-------------+-------+------+---------------+
 | id | carrier | domain | scan_prefix | flags | prob | rewrite_host  |
 | id | carrier | domain | scan_prefix | flags | prob | rewrite_host  |
@@ -843,7 +862,7 @@ domain register {
    this flags are not set, the other two rules are used. The
    this flags are not set, the other two rules are used. The
    "strip", "mask" and "comment" colums are omitted for brevity.
    "strip", "mask" and "comment" colums are omitted for brevity.
 
 
-   Example 1.20. Example database content - simple
+   Example 1.21. Example database content - simple
    carrierfailureroute table
    carrierfailureroute table
 ...
 ...
 +----+---------+--------+---------------+------------+-------------+
 +----+---------+--------+---------------+------------+-------------+
@@ -865,7 +884,7 @@ domain register {
    corresponding entry in the carrierroute table, otherwise the
    corresponding entry in the carrierroute table, otherwise the
    module will not load the routing data.
    module will not load the routing data.
 
 
-   Example 1.21. Example database content - more complex
+   Example 1.22. Example database content - more complex
    carrierfailureroute table
    carrierfailureroute table
 ...
 ...
 +----+---------+-----------+------------+--------+-----+-------------+
 +----+---------+-----------+------------+--------+-----+-------------+
@@ -892,7 +911,7 @@ domain register {
    holds domain entries for this routing rules. Not all table
    holds domain entries for this routing rules. Not all table
    colums are show here for brevity.
    colums are show here for brevity.
 
 
-   Example 1.22. Example database content - carrier_name table
+   Example 1.23. Example database content - carrier_name table
 ...
 ...
 +----+----------+
 +----+----------+
 | id | carrier  |
 | id | carrier  |
@@ -911,7 +930,7 @@ domain register {
    that you specified as modul parameter) to choose the actual
    that you specified as modul parameter) to choose the actual
    carrier for the users.
    carrier for the users.
 
 
-   Example 1.23. Necessary extensions for the user table
+   Example 1.24. Necessary extensions for the user table
 
 
    Suggested changes:
    Suggested changes:
 ...
 ...

+ 7 - 0
modules/carrierroute/carrierroute.c

@@ -74,6 +74,7 @@ int mode = 0;
 int use_domain = 0;
 int use_domain = 0;
 int fallback_default = 1;
 int fallback_default = 1;
 int cr_fetch_rows = 2000;
 int cr_fetch_rows = 2000;
+int cr_match_mode = 10;
 
 
 
 
 /************* Declaration of Interface Functions **************************/
 /************* Declaration of Interface Functions **************************/
@@ -114,6 +115,7 @@ static param_export_t params[]= {
 	{"use_domain",             INT_PARAM, &use_domain },
 	{"use_domain",             INT_PARAM, &use_domain },
 	{"fallback_default",       INT_PARAM, &fallback_default },
 	{"fallback_default",       INT_PARAM, &fallback_default },
 	{"fetch_rows",             INT_PARAM, &cr_fetch_rows },
 	{"fetch_rows",             INT_PARAM, &cr_fetch_rows },
+	{"match_mode",             INT_PARAM, &cr_match_mode },
 	{0,0,0}
 	{0,0,0}
 };
 };
 
 
@@ -163,6 +165,11 @@ static int mod_init(void) {
 
 
 	carrierroute_db_vars();
 	carrierroute_db_vars();
 
 
+	if (cr_match_mode != 10 && cr_match_mode != 128) {
+		LM_ERR("invalid matching mode specific, please use 10 or 128");
+		return -1;
+	}
+
 	if (strcmp(config_source, "db") == 0) {
 	if (strcmp(config_source, "db") == 0) {
 		mode = CARRIERROUTE_MODE_DB;
 		mode = CARRIERROUTE_MODE_DB;
 
 

+ 1 - 0
modules/carrierroute/carrierroute.h

@@ -54,5 +54,6 @@ extern int mode;
 extern int use_domain;
 extern int use_domain;
 extern int fallback_default;
 extern int fallback_default;
 extern int cr_fetch_rows;
 extern int cr_fetch_rows;
+extern int cr_match_mode;
 
 
 #endif
 #endif

+ 1 - 1
modules/carrierroute/cr_config.c

@@ -411,7 +411,7 @@ static int save_route_data_recursor(struct dtrie_node_t * node, FILE * outfile)
 		}
 		}
 		fprintf(outfile, "\t}\n");
 		fprintf(outfile, "\t}\n");
 	}
 	}
-	for (i = 0; i < 10; i++) {
+	for (i = 0; i < cr_match_mode; i++) {
 		if (node->child[i]) {
 		if (node->child[i]) {
 			if (save_route_data_recursor(node->child[i], outfile) < 0) {
 			if (save_route_data_recursor(node->child[i], outfile) < 0) {
 				return -1;
 				return -1;

+ 1 - 1
modules/carrierroute/cr_data.c

@@ -629,7 +629,7 @@ static int rule_fixup_recursor(struct dtrie_node_t *node) {
 		}
 		}
 	}
 	}
 
 
-	for (i=0; i<10; i++) {
+	for (i=0; i<cr_match_mode; i++) {
 		if (node->child[i]) {
 		if (node->child[i]) {
 			ret += rule_fixup_recursor(node->child[i]);
 			ret += rule_fixup_recursor(node->child[i]);
 		}
 		}

+ 11 - 9
modules/carrierroute/cr_domain.c

@@ -32,6 +32,7 @@
 #include "../../ut.h"
 #include "../../ut.h"
 #include "cr_domain.h"
 #include "cr_domain.h"
 #include "cr_rule.h"
 #include "cr_rule.h"
+#include "carrierroute.h"
 
 
 
 
 /**
 /**
@@ -86,12 +87,12 @@ struct domain_data_t * create_domain_data(int domain_id, str * domain_name) {
 	memset(tmp, 0, sizeof(struct domain_data_t));
 	memset(tmp, 0, sizeof(struct domain_data_t));
 	tmp->id = domain_id;
 	tmp->id = domain_id;
 	tmp->name = domain_name;
 	tmp->name = domain_name;
-	if ((tmp->tree = dtrie_init()) == NULL) {
+	if ((tmp->tree = dtrie_init(cr_match_mode)) == NULL) {
 		shm_free(tmp);
 		shm_free(tmp);
 		return NULL;
 		return NULL;
 	}
 	}
-	if ((tmp->failure_tree = dtrie_init()) == NULL) {
-		dtrie_destroy(&tmp->tree, NULL);
+	if ((tmp->failure_tree = dtrie_init(cr_match_mode)) == NULL) {
+		dtrie_destroy(&tmp->tree, NULL, cr_match_mode);
 		shm_free(tmp);
 		shm_free(tmp);
 		return NULL;
 		return NULL;
 	}
 	}
@@ -106,8 +107,9 @@ struct domain_data_t * create_domain_data(int domain_id, str * domain_name) {
  */
  */
 void destroy_domain_data(struct domain_data_t *domain_data) {
 void destroy_domain_data(struct domain_data_t *domain_data) {
 	if (domain_data) {
 	if (domain_data) {
-		dtrie_destroy(&domain_data->tree, destroy_route_flags_list);
-		dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list);
+		dtrie_destroy(&domain_data->tree, destroy_route_flags_list, cr_match_mode);
+		dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list,
+				cr_match_mode);
 		shm_free(domain_data);
 		shm_free(domain_data);
 	}
 	}
 }
 }
@@ -152,7 +154,7 @@ int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
 	void **ret;
 	void **ret;
 	struct route_flags *rf;
 	struct route_flags *rf;
 
 
-	ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len);
+	ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 
 
 	rf = add_route_flags((struct route_flags **)ret, flags, mask);
 	rf = add_route_flags((struct route_flags **)ret, flags, mask);
 	if (rf == NULL) {
 	if (rf == NULL) {
@@ -162,7 +164,7 @@ int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
 
 
 	if (ret == NULL) {
 	if (ret == NULL) {
 		/* node does not exist */
 		/* node does not exist */
-		if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf) != 0) {
+		if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 0) {
 			LM_ERR("cannot insert route flags into d-trie\n");
 			LM_ERR("cannot insert route flags into d-trie\n");
 			return -1;
 			return -1;
 		}
 		}
@@ -201,7 +203,7 @@ int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * sc
 	void **ret;
 	void **ret;
 	struct failure_route_rule *frr;
 	struct failure_route_rule *frr;
 
 
-	ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len);
+	ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 
 
 	frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 	frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 	if (frr == NULL) {
 	if (frr == NULL) {
@@ -211,7 +213,7 @@ int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * sc
 
 
 	if (ret == NULL) {
 	if (ret == NULL) {
 		/* node does not exist */
 		/* node does not exist */
-		if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr) != 0) {
+		if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 0) {
 			LM_ERR("cannot insert failure route rule into d-trie\n");
 			LM_ERR("cannot insert failure route rule into d-trie\n");
 			return -1;
 			return -1;
 		}
 		}

+ 2 - 2
modules/carrierroute/cr_fifo.c

@@ -408,7 +408,7 @@ static int dump_tree_recursor (struct mi_node* msg, struct dtrie_node_t *node, c
 	strcpy (s, prefix);
 	strcpy (s, prefix);
 	p = s + strlen (s);
 	p = s + strlen (s);
 	p[1] = '\0';
 	p[1] = '\0';
-	for (i = 0; i < 10; ++i) {
+	for (i = 0; i < cr_match_mode; ++i) {
 		if (node->child[i] != NULL) {
 		if (node->child[i] != NULL) {
 			*p = i + '0';
 			*p = i + '0';
 			dump_tree_recursor (msg->next, node->child[i], s);
 			dump_tree_recursor (msg->next, node->child[i], s);
@@ -866,7 +866,7 @@ static int update_route_data_recursor(struct dtrie_node_t *node, str * act_domai
 			}
 			}
 		}
 		}
 	}
 	}
-	for (i=0; i<10; i++) {
+	for (i=0; i<cr_match_mode; i++) {
 		if (node->child[i]) {
 		if (node->child[i]) {
 			if (update_route_data_recursor(node->child[i], act_domain, opts) < 0) {
 			if (update_route_data_recursor(node->child[i], act_domain, opts) < 0) {
 				return -1;
 				return -1;

+ 2 - 2
modules/carrierroute/cr_func.c

@@ -219,7 +219,7 @@ static int set_next_domain_recursor(struct dtrie_node_t *failure_node,
 		++re_uri.s;
 		++re_uri.s;
 		--re_uri.len;
 		--re_uri.len;
 	}
 	}
-	ret = dtrie_longest_match(failure_node, re_uri.s, re_uri.len, NULL);
+	ret = dtrie_longest_match(failure_node, re_uri.s, re_uri.len, NULL, cr_match_mode);
 
 
 	if (ret == NULL) {
 	if (ret == NULL) {
 		LM_INFO("URI or prefix tree nodes empty, empty rule list\n");
 		LM_INFO("URI or prefix tree nodes empty, empty rule list\n");
@@ -458,7 +458,7 @@ static int rewrite_uri_recursor(struct dtrie_node_t * node,
 		++re_pm.s;
 		++re_pm.s;
 		--re_pm.len;
 		--re_pm.len;
 	}
 	}
-	ret = dtrie_longest_match(node, re_pm.s, re_pm.len, NULL);
+	ret = dtrie_longest_match(node, re_pm.s, re_pm.len, NULL, cr_match_mode);
 
 
 	if (ret == NULL) {
 	if (ret == NULL) {
 		LM_INFO("URI or prefix tree nodes empty, empty rule list\n");
 		LM_INFO("URI or prefix tree nodes empty, empty rule list\n");

+ 26 - 0
modules/carrierroute/doc/carrierroute_admin.xml

@@ -319,7 +319,33 @@ modparam("carrierroute", "fetch_rows", 3000)
 		</example>
 		</example>
 	</section>
 	</section>
 
 
+	<section>
+		<title><varname>match_mode</varname> (integer)</title>
+		<para>
+		The number of individual characters that are used for matching.
+		Valid values are 10 or 128. When you specifiy 10, only digits
+		will be used for matching, this operation mode is equivalent to
+		the old behaviour. When configured with 128, all standard ascii
+		chars are available for matching. Please be aware that memory
+		requirements for storing the routing tree in shared memory
+		will also increase by a factor of 12.8.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>10</quote>.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>match_mode</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("carrierroute", "match_mode", 10)
+...
+</programlisting>
+		</example>
+	</section>
 </section>
 </section>
+
     <section>
     <section>
 	<title>Exported Functions</title>
 	<title>Exported Functions</title>
 	<para>
 	<para>