Browse code

userblocklist: renaming userblacklist module

Lucian Balaceanu authored on 06/11/2020 16:13:30
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,166 +0,0 @@
1
-/*
2
- * Copyright (C) 2007 1&1 Internet AG
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-
21
-/*!
22
- * \file
23
- * \brief USERBLACKLIST :: database access
24
- * \ingroup userblacklist
25
- * - Module: \ref userblacklist
26
- */
27
-
28
-#include "db.h"
29
-#include "db_userblacklist.h"
30
-
31
-#include "../../lib/srdb1/db.h"
32
-#include "../../core/mem/mem.h"
33
-#include "../../core/ut.h"
34
-#include "../../lib/trie/dtrie.h"
35
-
36
-
37
-
38
-/**
39
- * Builds a d-tree using database entries.
40
- * \return negative on failure, postive on success, indicating the number of d-tree entries
41
- */
42
-
43
-extern int match_mode;
44
-
45
-int db_build_userbl_tree(const str *username, const str *domain,
46
-		const str *dbtable, struct dtrie_node_t *root, int use_domain)
47
-{
48
-	db_key_t columns[2] = { &userblacklist_prefix_col, &userblacklist_whitelist_col };
49
-	db_key_t key[2] = { &userblacklist_username_col, &userblacklist_domain_col };
50
-
51
-	db_val_t val[2];
52
-	db1_res_t *res;
53
-	int i;
54
-	int n = 0;
55
-	void *nodeflags;
56
-	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB1_STR;
57
-	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
58
-	VAL_STR(val).s = username->s;
59
-	VAL_STR(val).len = username->len;
60
-	VAL_STR(val + 1).s = domain->s;
61
-	VAL_STR(val + 1).len = domain->len;
62
-
63
-	if (userblacklist_dbf.use_table(userblacklist_dbh, dbtable) < 0) {
64
-		LM_ERR("cannot use db table '%.*s'.\n", dbtable->len, dbtable->s);
65
-		return -1;
66
-	}
67
-	if (userblacklist_dbf.query(userblacklist_dbh, key, 0, val, columns,
68
-				(!use_domain) ? (1) : (2), 2, 0, &res) < 0) {
69
-		LM_ERR("error while executing query on db table '%.*s'\n",
70
-				dbtable->len, dbtable->s);
71
-		return -1;
72
-	}
73
-
74
-	dtrie_clear(root, NULL, match_mode);
75
-
76
-	if (RES_COL_N(res) > 1) {
77
-		for(i = 0; i < RES_ROW_N(res); i++) {
78
-			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
79
-				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
80
-					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {
81
-
82
-					/* LM_DBG("insert into tree prefix %s, whitelist %d",
83
-						RES_ROWS(res)[i].values[0].val.string_val,
84
-						RES_ROWS(res)[i].values[1].val.int_val); */
85
-					if (RES_ROWS(res)[i].values[1].val.int_val == 0) {
86
-						nodeflags=(void *)MARK_BLACKLIST;
87
-					} else {
88
-						nodeflags=(void *)MARK_WHITELIST;
89
-					}
90
-
91
-					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
92
-								strlen(RES_ROWS(res)[i].values[0].val.string_val),
93
-								nodeflags, match_mode) < 0)
94
-						LM_ERR("could not insert values into trie.\n");
95
-
96
-					n++;
97
-				}
98
-				else {
99
-					LM_ERR("got invalid result type from query.\n");
100
-				}
101
-			}
102
-		}
103
-	}
104
-	userblacklist_dbf.free_result(userblacklist_dbh, res);
105
-
106
-	return n;
107
-}
108
-
109
-
110
-/**
111
- * Rebuild d-tree using database entries
112
- * \return negative on failure, positive on success, indicating the number of d-tree entries
113
- */
114
-int db_reload_source(const str *dbtable, struct dtrie_node_t *root)
115
-{
116
-	db_key_t columns[2] = { &globalblacklist_prefix_col, &globalblacklist_whitelist_col };
117
-	db1_res_t *res;
118
-	int i;
119
-	int n = 0;
120
-	void *nodeflags;
121
-
122
-	if (userblacklist_dbf.use_table(userblacklist_dbh, dbtable) < 0) {
123
-		LM_ERR("cannot use db table '%.*s'\n", dbtable->len, dbtable->s);
124
-		return -1;
125
-	}
126
-	if (userblacklist_dbf.query(userblacklist_dbh, NULL, NULL, NULL,
127
-				columns, 0, 2, NULL, &res) < 0) {
128
-		LM_ERR("error while executing query on db table '%.*s'\n",
129
-				dbtable->len, dbtable->s);
130
-		return -1;
131
-	}
132
-
133
-	dtrie_clear(root, NULL, match_mode);
134
-
135
-	if (RES_COL_N(res) > 1) {
136
-		for(i = 0; i < RES_ROW_N(res); i++) {
137
-			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
138
-				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
139
-					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {
140
-
141
-					/* LM_DBG("insert into tree prefix %s, whitelist %d",
142
-						RES_ROWS(res)[i].values[0].val.string_val,
143
-						RES_ROWS(res)[i].values[1].val.int_val); */
144
-					if (RES_ROWS(res)[i].values[1].val.int_val == 0) {
145
-						nodeflags=(void *)MARK_BLACKLIST;
146
-					} else {
147
-						nodeflags=(void *)MARK_WHITELIST;
148
-					}
149
-
150
-					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
151
-								strlen(RES_ROWS(res)[i].values[0].val.string_val),
152
-								nodeflags, match_mode) < 0)
153
-						LM_ERR("could not insert values into trie.\n");
154
-
155
-					n++;
156
-				}
157
-				else {
158
-					LM_ERR("got invalid result type from query.\n");
159
-				}
160
-			}
161
-		}
162
-	}
163
-	userblacklist_dbf.free_result(userblacklist_dbh, res);
164
-
165
-	return n;
166
-}
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -29,8 +29,8 @@
29 29
 #include "db_userblacklist.h"
30 30
 
31 31
 #include "../../lib/srdb1/db.h"
32
-#include "../../mem/mem.h"
33
-#include "../../ut.h"
32
+#include "../../core/mem/mem.h"
33
+#include "../../core/ut.h"
34 34
 #include "../../lib/trie/dtrie.h"
35 35
 
36 36
 
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,166 @@
1
+/*
2
+ * Copyright (C) 2007 1&1 Internet AG
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/*!
22
+ * \file
23
+ * \brief USERBLACKLIST :: database access
24
+ * \ingroup userblacklist
25
+ * - Module: \ref userblacklist
26
+ */
27
+
28
+#include "db.h"
29
+#include "db_userblacklist.h"
30
+
31
+#include "../../lib/srdb1/db.h"
32
+#include "../../mem/mem.h"
33
+#include "../../ut.h"
34
+#include "../../lib/trie/dtrie.h"
35
+
36
+
37
+
38
+/**
39
+ * Builds a d-tree using database entries.
40
+ * \return negative on failure, postive on success, indicating the number of d-tree entries
41
+ */
42
+
43
+extern int match_mode;
44
+
45
+int db_build_userbl_tree(const str *username, const str *domain,
46
+		const str *dbtable, struct dtrie_node_t *root, int use_domain)
47
+{
48
+	db_key_t columns[2] = { &userblacklist_prefix_col, &userblacklist_whitelist_col };
49
+	db_key_t key[2] = { &userblacklist_username_col, &userblacklist_domain_col };
50
+
51
+	db_val_t val[2];
52
+	db1_res_t *res;
53
+	int i;
54
+	int n = 0;
55
+	void *nodeflags;
56
+	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB1_STR;
57
+	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
58
+	VAL_STR(val).s = username->s;
59
+	VAL_STR(val).len = username->len;
60
+	VAL_STR(val + 1).s = domain->s;
61
+	VAL_STR(val + 1).len = domain->len;
62
+
63
+	if (userblacklist_dbf.use_table(userblacklist_dbh, dbtable) < 0) {
64
+		LM_ERR("cannot use db table '%.*s'.\n", dbtable->len, dbtable->s);
65
+		return -1;
66
+	}
67
+	if (userblacklist_dbf.query(userblacklist_dbh, key, 0, val, columns,
68
+				(!use_domain) ? (1) : (2), 2, 0, &res) < 0) {
69
+		LM_ERR("error while executing query on db table '%.*s'\n",
70
+				dbtable->len, dbtable->s);
71
+		return -1;
72
+	}
73
+
74
+	dtrie_clear(root, NULL, match_mode);
75
+
76
+	if (RES_COL_N(res) > 1) {
77
+		for(i = 0; i < RES_ROW_N(res); i++) {
78
+			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
79
+				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
80
+					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {
81
+
82
+					/* LM_DBG("insert into tree prefix %s, whitelist %d",
83
+						RES_ROWS(res)[i].values[0].val.string_val,
84
+						RES_ROWS(res)[i].values[1].val.int_val); */
85
+					if (RES_ROWS(res)[i].values[1].val.int_val == 0) {
86
+						nodeflags=(void *)MARK_BLACKLIST;
87
+					} else {
88
+						nodeflags=(void *)MARK_WHITELIST;
89
+					}
90
+
91
+					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
92
+								strlen(RES_ROWS(res)[i].values[0].val.string_val),
93
+								nodeflags, match_mode) < 0)
94
+						LM_ERR("could not insert values into trie.\n");
95
+
96
+					n++;
97
+				}
98
+				else {
99
+					LM_ERR("got invalid result type from query.\n");
100
+				}
101
+			}
102
+		}
103
+	}
104
+	userblacklist_dbf.free_result(userblacklist_dbh, res);
105
+
106
+	return n;
107
+}
108
+
109
+
110
+/**
111
+ * Rebuild d-tree using database entries
112
+ * \return negative on failure, positive on success, indicating the number of d-tree entries
113
+ */
114
+int db_reload_source(const str *dbtable, struct dtrie_node_t *root)
115
+{
116
+	db_key_t columns[2] = { &globalblacklist_prefix_col, &globalblacklist_whitelist_col };
117
+	db1_res_t *res;
118
+	int i;
119
+	int n = 0;
120
+	void *nodeflags;
121
+
122
+	if (userblacklist_dbf.use_table(userblacklist_dbh, dbtable) < 0) {
123
+		LM_ERR("cannot use db table '%.*s'\n", dbtable->len, dbtable->s);
124
+		return -1;
125
+	}
126
+	if (userblacklist_dbf.query(userblacklist_dbh, NULL, NULL, NULL,
127
+				columns, 0, 2, NULL, &res) < 0) {
128
+		LM_ERR("error while executing query on db table '%.*s'\n",
129
+				dbtable->len, dbtable->s);
130
+		return -1;
131
+	}
132
+
133
+	dtrie_clear(root, NULL, match_mode);
134
+
135
+	if (RES_COL_N(res) > 1) {
136
+		for(i = 0; i < RES_ROW_N(res); i++) {
137
+			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
138
+				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
139
+					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {
140
+
141
+					/* LM_DBG("insert into tree prefix %s, whitelist %d",
142
+						RES_ROWS(res)[i].values[0].val.string_val,
143
+						RES_ROWS(res)[i].values[1].val.int_val); */
144
+					if (RES_ROWS(res)[i].values[1].val.int_val == 0) {
145
+						nodeflags=(void *)MARK_BLACKLIST;
146
+					} else {
147
+						nodeflags=(void *)MARK_WHITELIST;
148
+					}
149
+
150
+					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
151
+								strlen(RES_ROWS(res)[i].values[0].val.string_val),
152
+								nodeflags, match_mode) < 0)
153
+						LM_ERR("could not insert values into trie.\n");
154
+
155
+					n++;
156
+				}
157
+				else {
158
+					LM_ERR("got invalid result type from query.\n");
159
+				}
160
+			}
161
+		}
162
+	}
163
+	userblacklist_dbf.free_result(userblacklist_dbh, res);
164
+
165
+	return n;
166
+}