Browse code

- 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 authored on 19/11/2008 13:16:15
Showing 9 changed files
... ...
@@ -40,6 +40,7 @@ Henning Westerholt
40 40
               1.3.8. use_domain (int)
41 41
               1.3.9. fallback_default (int)
42 42
               1.3.10. fetch_rows (integer)
43
+              1.3.11. match_mode (integer)
43 44
 
44 45
         1.4. Exported Functions
45 46
 
... ...
@@ -115,23 +116,24 @@ Henning Westerholt
115 116
    1.8. Set use_domain parameter
116 117
    1.9. Set fallback_default parameter
117 118
    1.10. Set fetch_rows parameter
118
-   1.11. cr_replace_host usage
119
-   1.12. cr_deactivate_host usage
120
-   1.13. cr_activate_host usage
121
-   1.14. cr_add_host usage
122
-   1.15. cr_delete_host usage
123
-   1.16. Configuration example - Routing to default tree
124
-   1.17. Configuration example - Routing to user tree
125
-   1.18. Configuration example - module configuration
126
-   1.19. Example database content - carrierroute table
127
-   1.20. Example database content - simple carrierfailureroute
119
+   1.11. Set match_mode parameter
120
+   1.12. cr_replace_host usage
121
+   1.13. cr_deactivate_host usage
122
+   1.14. cr_activate_host usage
123
+   1.15. cr_add_host usage
124
+   1.16. cr_delete_host usage
125
+   1.17. Configuration example - Routing to default tree
126
+   1.18. Configuration example - Routing to user tree
127
+   1.19. Configuration example - module configuration
128
+   1.20. Example database content - carrierroute table
129
+   1.21. Example database content - simple carrierfailureroute
128 130
           table
129 131
 
130
-   1.21. Example database content - more complex
132
+   1.22. Example database content - more complex
131 133
           carrierfailureroute table
132 134
 
133
-   1.22. Example database content - carrier_name table
134
-   1.23. Necessary extensions for the user table
135
+   1.23. Example database content - carrier_name table
136
+   1.24. Necessary extensions for the user table
135 137
    2.1. Set db_url parameter
136 138
    2.2. Set carrierroute_table parameter
137 139
    2.3. Set carrierroute_id_col parameter
... ...
@@ -380,6 +382,23 @@ modparam("carrierroute", "fallback_default", 1)
380 382
 modparam("carrierroute", "fetch_rows", 3000)
381 383
 ...
382 384
 
385
+1.3.11. match_mode (integer)
386
+
387
+   The number of individual characters that are used for matching.
388
+   Valid values are 10 or 128. When you specifiy 10, only digits
389
+   will be used for matching, this operation mode is equivalent to
390
+   the old behaviour. When configured with 128, all standard ascii
391
+   chars are available for matching. Please be aware that memory
392
+   requirements for storing the routing tree in shared memory will
393
+   also increase by a factor of 12.8.
394
+
395
+   Default value is "10".
396
+
397
+   Example 1.11. Set match_mode parameter
398
+...
399
+modparam("carrierroute", "match_mode", 10)
400
+...
401
+
383 402
 1.4. Exported Functions
384 403
 
385 404
    Previous versions of carrierroute had some more function. All
... ...
@@ -564,7 +583,7 @@ reply_code, dstavp)
564 583
 
565 584
    Use the "null" prefix to specify an empty prefix.
566 585
 
567
-   Example 1.11. cr_replace_host usage
586
+   Example 1.12. cr_replace_host usage
568 587
 ...
569 588
 kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
570 589
 ...
... ...
@@ -586,7 +605,7 @@ kamctl fifo cr_replace_host "-d proxy -p 49 -h proxy1 -t proxy2"
586 605
 
587 606
    Use the "null" prefix to specify an empty prefix.
588 607
 
589
-   Example 1.12. cr_deactivate_host usage
608
+   Example 1.13. cr_deactivate_host usage
590 609
 ...
591 610
 kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
592 611
 ...
... ...
@@ -602,7 +621,7 @@ kamctl fifo cr_deactivate_host "-d proxy -p 49 -h proxy1"
602 621
 
603 622
    Use the "null" prefix to specify an empty prefix.
604 623
 
605
-   Example 1.13. cr_activate_host usage
624
+   Example 1.14. cr_activate_host usage
606 625
 ...
607 626
 kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
608 627
 ...
... ...
@@ -622,7 +641,7 @@ kamctl fifo cr_activate_host "-d proxy -p 49 -h proxy1"
622 641
 
623 642
    Use the "null" prefix to specify an empty prefix.
624 643
 
625
-   Example 1.14. cr_add_host usage
644
+   Example 1.15. cr_add_host usage
626 645
 ...
627 646
 kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
628 647
 ...
... ...
@@ -643,14 +662,14 @@ kamctl fifo cr_add_host "-d proxy -p 49 -h proxy1 -w 0.25"
643 662
 
644 663
    Use the "null" prefix to specify an empty prefix.
645 664
 
646
-   Example 1.15. cr_delete_host usage
665
+   Example 1.16. cr_delete_host usage
647 666
 ...
648 667
 kamctl fifo cr_delete_host "-d proxy -p 49 -h proxy1 -w 0.25"
649 668
 ...
650 669
 
651 670
 1.6. Examples
652 671
 
653
-   Example 1.16. Configuration example - Routing to default tree
672
+   Example 1.17. Configuration example - Routing to default tree
654 673
 ...
655 674
 route {
656 675
         # route calls based on hash over callid
... ...
@@ -684,7 +703,7 @@ failure_route[2] {
684 703
 }
685 704
 
686 705
 
687
-   Example 1.17. Configuration example - Routing to user tree
706
+   Example 1.18. Configuration example - Routing to user tree
688 707
 ...
689 708
 route[1] {
690 709
         cr_user_carrier("$fU", "$fd", "$avp(s:carrier)");
... ...
@@ -724,7 +743,7 @@ failure_route[1] {
724 743
 }
725 744
 ...
726 745
 
727
-   Example 1.18. Configuration example - module configuration
746
+   Example 1.19. Configuration example - module configuration
728 747
 
729 748
    The following config file specifies within the default carrier
730 749
    two domains, each with an prefix that contains two hosts. It is
... ...
@@ -804,7 +823,7 @@ domain register {
804 823
    For a minimal configuration either use the config file given
805 824
    above, or insert some data into the tables of the module.
806 825
 
807
-   Example 1.19. Example database content - carrierroute table
826
+   Example 1.20. Example database content - carrierroute table
808 827
 ...
809 828
 +----+---------+--------+-------------+-------+------+---------------+
810 829
 | id | carrier | domain | scan_prefix | flags | prob | rewrite_host  |
... ...
@@ -843,7 +862,7 @@ domain register {
843 862
    this flags are not set, the other two rules are used. The
844 863
    "strip", "mask" and "comment" colums are omitted for brevity.
845 864
 
846
-   Example 1.20. Example database content - simple
865
+   Example 1.21. Example database content - simple
847 866
    carrierfailureroute table
848 867
 ...
849 868
 +----+---------+--------+---------------+------------+-------------+
... ...
@@ -865,7 +884,7 @@ domain register {
865 884
    corresponding entry in the carrierroute table, otherwise the
866 885
    module will not load the routing data.
867 886
 
868
-   Example 1.21. Example database content - more complex
887
+   Example 1.22. Example database content - more complex
869 888
    carrierfailureroute table
870 889
 ...
871 890
 +----+---------+-----------+------------+--------+-----+-------------+
... ...
@@ -892,7 +911,7 @@ domain register {
892 911
    holds domain entries for this routing rules. Not all table
893 912
    colums are show here for brevity.
894 913
 
895
-   Example 1.22. Example database content - carrier_name table
914
+   Example 1.23. Example database content - carrier_name table
896 915
 ...
897 916
 +----+----------+
898 917
 | id | carrier  |
... ...
@@ -911,7 +930,7 @@ domain register {
911 930
    that you specified as modul parameter) to choose the actual
912 931
    carrier for the users.
913 932
 
914
-   Example 1.23. Necessary extensions for the user table
933
+   Example 1.24. Necessary extensions for the user table
915 934
 
916 935
    Suggested changes:
917 936
 ...
... ...
@@ -74,6 +74,7 @@ int mode = 0;
74 74
 int use_domain = 0;
75 75
 int fallback_default = 1;
76 76
 int cr_fetch_rows = 2000;
77
+int cr_match_mode = 10;
77 78
 
78 79
 
79 80
 /************* Declaration of Interface Functions **************************/
... ...
@@ -114,6 +115,7 @@ static param_export_t params[]= {
114 115
 	{"use_domain",             INT_PARAM, &use_domain },
115 116
 	{"fallback_default",       INT_PARAM, &fallback_default },
116 117
 	{"fetch_rows",             INT_PARAM, &cr_fetch_rows },
118
+	{"match_mode",             INT_PARAM, &cr_match_mode },
117 119
 	{0,0,0}
118 120
 };
119 121
 
... ...
@@ -163,6 +165,11 @@ static int mod_init(void) {
163 165
 
164 166
 	carrierroute_db_vars();
165 167
 
168
+	if (cr_match_mode != 10 && cr_match_mode != 128) {
169
+		LM_ERR("invalid matching mode specific, please use 10 or 128");
170
+		return -1;
171
+	}
172
+
166 173
 	if (strcmp(config_source, "db") == 0) {
167 174
 		mode = CARRIERROUTE_MODE_DB;
168 175
 
... ...
@@ -54,5 +54,6 @@ extern int mode;
54 54
 extern int use_domain;
55 55
 extern int fallback_default;
56 56
 extern int cr_fetch_rows;
57
+extern int cr_match_mode;
57 58
 
58 59
 #endif
... ...
@@ -411,7 +411,7 @@ static int save_route_data_recursor(struct dtrie_node_t * node, FILE * outfile)
411 411
 		}
412 412
 		fprintf(outfile, "\t}\n");
413 413
 	}
414
-	for (i = 0; i < 10; i++) {
414
+	for (i = 0; i < cr_match_mode; i++) {
415 415
 		if (node->child[i]) {
416 416
 			if (save_route_data_recursor(node->child[i], outfile) < 0) {
417 417
 				return -1;
... ...
@@ -629,7 +629,7 @@ static int rule_fixup_recursor(struct dtrie_node_t *node) {
629 629
 		}
630 630
 	}
631 631
 
632
-	for (i=0; i<10; i++) {
632
+	for (i=0; i<cr_match_mode; i++) {
633 633
 		if (node->child[i]) {
634 634
 			ret += rule_fixup_recursor(node->child[i]);
635 635
 		}
... ...
@@ -32,6 +32,7 @@
32 32
 #include "../../ut.h"
33 33
 #include "cr_domain.h"
34 34
 #include "cr_rule.h"
35
+#include "carrierroute.h"
35 36
 
36 37
 
37 38
 /**
... ...
@@ -86,12 +87,12 @@ struct domain_data_t * create_domain_data(int domain_id, str * domain_name) {
86 87
 	memset(tmp, 0, sizeof(struct domain_data_t));
87 88
 	tmp->id = domain_id;
88 89
 	tmp->name = domain_name;
89
-	if ((tmp->tree = dtrie_init()) == NULL) {
90
+	if ((tmp->tree = dtrie_init(cr_match_mode)) == NULL) {
90 91
 		shm_free(tmp);
91 92
 		return NULL;
92 93
 	}
93
-	if ((tmp->failure_tree = dtrie_init()) == NULL) {
94
-		dtrie_destroy(&tmp->tree, NULL);
94
+	if ((tmp->failure_tree = dtrie_init(cr_match_mode)) == NULL) {
95
+		dtrie_destroy(&tmp->tree, NULL, cr_match_mode);
95 96
 		shm_free(tmp);
96 97
 		return NULL;
97 98
 	}
... ...
@@ -106,8 +107,9 @@ struct domain_data_t * create_domain_data(int domain_id, str * domain_name) {
106 107
  */
107 108
 void destroy_domain_data(struct domain_data_t *domain_data) {
108 109
 	if (domain_data) {
109
-		dtrie_destroy(&domain_data->tree, destroy_route_flags_list);
110
-		dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list);
110
+		dtrie_destroy(&domain_data->tree, destroy_route_flags_list, cr_match_mode);
111
+		dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list,
112
+				cr_match_mode);
111 113
 		shm_free(domain_data);
112 114
 	}
113 115
 }
... ...
@@ -152,7 +154,7 @@ int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
152 154
 	void **ret;
153 155
 	struct route_flags *rf;
154 156
 
155
-	ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len);
157
+	ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
156 158
 
157 159
 	rf = add_route_flags((struct route_flags **)ret, flags, mask);
158 160
 	if (rf == NULL) {
... ...
@@ -162,7 +164,7 @@ int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
162 164
 
163 165
 	if (ret == NULL) {
164 166
 		/* node does not exist */
165
-		if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf) != 0) {
167
+		if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 0) {
166 168
 			LM_ERR("cannot insert route flags into d-trie\n");
167 169
 			return -1;
168 170
 		}
... ...
@@ -201,7 +203,7 @@ int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * sc
201 203
 	void **ret;
202 204
 	struct failure_route_rule *frr;
203 205
 
204
-	ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len);
206
+	ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
205 207
 
206 208
 	frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
207 209
 	if (frr == NULL) {
... ...
@@ -211,7 +213,7 @@ int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * sc
211 213
 
212 214
 	if (ret == NULL) {
213 215
 		/* node does not exist */
214
-		if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr) != 0) {
216
+		if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 0) {
215 217
 			LM_ERR("cannot insert failure route rule into d-trie\n");
216 218
 			return -1;
217 219
 		}
... ...
@@ -408,7 +408,7 @@ static int dump_tree_recursor (struct mi_node* msg, struct dtrie_node_t *node, c
408 408
 	strcpy (s, prefix);
409 409
 	p = s + strlen (s);
410 410
 	p[1] = '\0';
411
-	for (i = 0; i < 10; ++i) {
411
+	for (i = 0; i < cr_match_mode; ++i) {
412 412
 		if (node->child[i] != NULL) {
413 413
 			*p = i + '0';
414 414
 			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
866 866
 			}
867 867
 		}
868 868
 	}
869
-	for (i=0; i<10; i++) {
869
+	for (i=0; i<cr_match_mode; i++) {
870 870
 		if (node->child[i]) {
871 871
 			if (update_route_data_recursor(node->child[i], act_domain, opts) < 0) {
872 872
 				return -1;
... ...
@@ -219,7 +219,7 @@ static int set_next_domain_recursor(struct dtrie_node_t *failure_node,
219 219
 		++re_uri.s;
220 220
 		--re_uri.len;
221 221
 	}
222
-	ret = dtrie_longest_match(failure_node, re_uri.s, re_uri.len, NULL);
222
+	ret = dtrie_longest_match(failure_node, re_uri.s, re_uri.len, NULL, cr_match_mode);
223 223
 
224 224
 	if (ret == NULL) {
225 225
 		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,
458 458
 		++re_pm.s;
459 459
 		--re_pm.len;
460 460
 	}
461
-	ret = dtrie_longest_match(node, re_pm.s, re_pm.len, NULL);
461
+	ret = dtrie_longest_match(node, re_pm.s, re_pm.len, NULL, cr_match_mode);
462 462
 
463 463
 	if (ret == NULL) {
464 464
 		LM_INFO("URI or prefix tree nodes empty, empty rule list\n");
... ...
@@ -319,7 +319,33 @@ modparam("carrierroute", "fetch_rows", 3000)
319 319
 		</example>
320 320
 	</section>
321 321
 
322
+	<section>
323
+		<title><varname>match_mode</varname> (integer)</title>
324
+		<para>
325
+		The number of individual characters that are used for matching.
326
+		Valid values are 10 or 128. When you specifiy 10, only digits
327
+		will be used for matching, this operation mode is equivalent to
328
+		the old behaviour. When configured with 128, all standard ascii
329
+		chars are available for matching. Please be aware that memory
330
+		requirements for storing the routing tree in shared memory
331
+		will also increase by a factor of 12.8.
332
+		</para>
333
+		<para>
334
+		<emphasis>
335
+			Default value is <quote>10</quote>.
336
+		</emphasis>
337
+		</para>
338
+		<example>
339
+		<title>Set <varname>match_mode</varname> parameter</title>
340
+		<programlisting format="linespecific">
341
+...
342
+modparam("carrierroute", "match_mode", 10)
343
+...
344
+</programlisting>
345
+		</example>
346
+	</section>
322 347
 </section>
348
+
323 349
     <section>
324 350
 	<title>Exported Functions</title>
325 351
 	<para>