Browse code

- extend generic trie (preparations for carrierroute changes): delete functions can now use a delete function to cleanup the payload, match functions now return a pointer to the payload pointer to enable later modifications - adapt userblacklist module to this changes - credits goes to Hardy Kahl, hardy dot kahl at 1und1 dot de - log errors in userblacklist DB functions, if the trie insert fails

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

Henning Westerholt authored on 22/10/2008 14:20:37
Showing 2 changed files
... ...
@@ -67,7 +67,7 @@ int db_build_userbl_tree(const str *username, const str *domain, const str *tabl
67 67
 		return -1;
68 68
 	}
69 69
 
70
-	dtrie_clear(root);
70
+	dtrie_clear(root, NULL);
71 71
 
72 72
 	if (RES_COL_N(res) > 1) {
73 73
 		for(i = 0; i < RES_ROW_N(res); i++) {
... ...
@@ -79,8 +79,8 @@ int db_build_userbl_tree(const str *username, const str *domain, const str *tabl
79 79
 						RES_ROWS(res)[i].values[0].val.string_val,
80 80
 						RES_ROWS(res)[i].values[1].val.int_val); */
81 81
 					if (RES_ROWS(res)[i].values[1].val.int_val == 0) nodeflags=(void *)MARK_BLACKLIST;
82
-					dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
83
-						nodeflags);
82
+					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
83
+						nodeflags) < 0) LM_ERR("could not insert values into trie.\n");
84 84
 					n++;
85 85
 				}
86 86
 				else {
... ...
@@ -116,7 +116,7 @@ int db_reload_source(const str *table, struct dtrie_node_t *root)
116 116
 		return -1;
117 117
 	}
118 118
 
119
-	dtrie_clear(root);
119
+	dtrie_clear(root, NULL);
120 120
 
121 121
 	if (RES_COL_N(res) > 1) {
122 122
 		for(i = 0; i < RES_ROW_N(res); i++) {
... ...
@@ -129,8 +129,8 @@ int db_reload_source(const str *table, struct dtrie_node_t *root)
129 129
 						RES_ROWS(res)[i].values[1].val.int_val); */
130 130
 					if (RES_ROWS(res)[i].values[1].val.int_val == 0) nodeflags=(void *) MARK_BLACKLIST;
131 131
 					else nodeflags=(void *)MARK_WHITELIST;
132
-					dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
133
-						nodeflags);
132
+					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
133
+						nodeflags) < 0) LM_ERR("could not insert values into trie.\n");
134 134
 					n++;
135 135
 				}
136 136
 				else {
... ...
@@ -207,7 +207,7 @@ static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, cha
207 207
 	str table = { .len = 0, .s = NULL};
208 208
 	str number = { .len = 0, .s = NULL};
209 209
 
210
-	void *nodeflags;
210
+	void **nodeflags;
211 211
 	char *ptr;
212 212
 	char req_number[MAXNUMBERLEN+1];
213 213
 
... ...
@@ -278,8 +278,9 @@ static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, cha
278 278
 		ptr = ptr + 1;
279 279
 	}
280 280
 
281
-	if (dtrie_longest_match(dtrie_root, ptr, strlen(ptr), &nodeflags) >= 0) {
282
-		if (nodeflags == (void *)MARK_WHITELIST) {
281
+	nodeflags = dtrie_longest_match(dtrie_root, ptr, strlen(ptr), NULL);
282
+	if (nodeflags) {
283
+		if (*nodeflags == (void *)MARK_WHITELIST) {
283 284
 			/* LM_ERR("whitelisted"); */
284 285
 			return 1; /* found, but is whitelisted */
285 286
 		}
... ...
@@ -394,7 +395,7 @@ static int check_blacklist_fixup(void **arg, int arg_no)
394 395
 
395 396
 static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg1)
396 397
 {
397
-	void *nodeflags;
398
+	void **nodeflags;
398 399
 	char *ptr;
399 400
 	char req_number[MAXNUMBERLEN+1];
400 401
 	int ret = -1;
... ...
@@ -426,8 +427,9 @@ static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg
426 427
 
427 428
 	/* avoids dirty reads when updating d-tree */
428 429
 	lock_get(lock);
429
-	if (dtrie_longest_match(arg1->dtrie_root, ptr, strlen(ptr), &nodeflags) >= 0) {
430
-		if (nodeflags == (void *)MARK_WHITELIST) {
430
+	nodeflags = dtrie_longest_match(arg1->dtrie_root, ptr, strlen(ptr), NULL);
431
+	if (nodeflags) {
432
+		if (*nodeflags == (void *)MARK_WHITELIST) {
431 433
 			/* LM_DBG("whitelisted"); */
432 434
 			ret = 1; /* found, but is whitelisted */
433 435
 		}
... ...
@@ -496,7 +498,7 @@ static void destroy_source_list(void)
496 498
 			sources->head = src->next;
497 499
 
498 500
 			if (src->table) shm_free(src->table);
499
-			dtrie_destroy(&(src->dtrie_root));
501
+			dtrie_destroy(&(src->dtrie_root), NULL);
500 502
 			shm_free(src);
501 503
 		}
502 504
 
... ...
@@ -591,5 +593,5 @@ static void mod_destroy(void)
591 593
 	destroy_source_list();
592 594
 	destroy_shmlock();
593 595
 	userblacklist_db_close();
594
-	dtrie_destroy(&dtrie_root);
596
+	dtrie_destroy(&dtrie_root, NULL);
595 597
 }