Browse code

userblocklist: fix function comment, related to gh #3102

Henning Westerholt authored on 08/05/2022 15:33:56
Showing 1 changed files
... ...
@@ -61,7 +61,7 @@ void userblocklist_db_close(void) {
61 61
 
62 62
 
63 63
 /*!
64
- * Initialises the DB API, check the table version and closes the connection.
64
+ * Initialises the DB API and check the table version.
65 65
  * This should be called from the mod_init function.
66 66
  *
67 67
  * \return 0 means ok, -1 means an error occurred.
Browse code

userblocklist: fix restart errors

Stefan Mititelu authored on 05/05/2022 12:14:01 • Henning Westerholt committed on 08/05/2022 15:32:12
Showing 1 changed files
... ...
@@ -91,7 +91,6 @@ int userblocklist_db_init(void) {
91 91
 		userblocklist_db_close();
92 92
 		return -1;
93 93
 	}
94
-	userblocklist_db_close();
95 94
 	return 0;
96 95
 }
97 96
 
Browse code

userblocklist: renaming userblacklist module

Lucian Balaceanu authored on 06/11/2020 16:13:30
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,116 @@
1
+/*!
2
+ * \file
3
+ * \ingroup db
4
+ * \brief Database support for modules.
5
+ *
6
+ * Database support functions for modules.
7
+ *
8
+ * @cond
9
+ * WARNING:
10
+ * This file was autogenerated from the XML source file
11
+ * ../../modules/userblocklist/kamailio-userblocklist.xml.
12
+ * It can be regenerated by running 'make modules' in the db/schema
13
+ * directory of the source code. You need to have xsltproc and
14
+ * docbook-xsl stylesheets installed.
15
+ * ALL CHANGES DONE HERE WILL BE LOST IF THE FILE IS REGENERATED
16
+ * @endcond
17
+ */
18
+
19
+#include "db_userblocklist.h"
20
+
21
+/* database variables */
22
+/* TODO assign read-write or read-only URI, introduce a parameter in XML */
23
+
24
+//extern str userblocklist_db_url;
25
+db1_con_t * userblocklist_dbh = NULL;
26
+db_func_t userblocklist_dbf;
27
+
28
+str userblocklist_table = str_init("userblocklist");
29
+
30
+/* column names */
31
+str userblocklist_id_col = str_init("id");
32
+str userblocklist_username_col = str_init("username");
33
+str userblocklist_domain_col = str_init("domain");
34
+str userblocklist_prefix_col = str_init("prefix");
35
+str userblocklist_allowlist_col = str_init("allowlist");
36
+
37
+/* table version */
38
+const unsigned int userblocklist_version = 1;
39
+
40
+str globalblocklist_table = str_init("globalblocklist");
41
+
42
+/* column names */
43
+str globalblocklist_id_col = str_init("id");
44
+str globalblocklist_prefix_col = str_init("prefix");
45
+str globalblocklist_allowlist_col = str_init("allowlist");
46
+str globalblocklist_description_col = str_init("description");
47
+
48
+/* table version */
49
+const unsigned int globalblocklist_version = 1;
50
+
51
+
52
+/*
53
+ * Closes the DB connection.
54
+ */
55
+void userblocklist_db_close(void) {
56
+	if (userblocklist_dbh) {
57
+		userblocklist_dbf.close(userblocklist_dbh);
58
+		userblocklist_dbh = NULL;
59
+	}
60
+}
61
+
62
+
63
+/*!
64
+ * Initialises the DB API, check the table version and closes the connection.
65
+ * This should be called from the mod_init function.
66
+ *
67
+ * \return 0 means ok, -1 means an error occurred.
68
+ */
69
+int userblocklist_db_init(void) {
70
+	if (!userblocklist_db_url.s || !userblocklist_db_url.len) {
71
+		LM_ERR("you have to set the db_url module parameter.\n");
72
+		return -1;
73
+	}
74
+	if (db_bind_mod(&userblocklist_db_url, &userblocklist_dbf) < 0) {
75
+		LM_ERR("can't bind database module.\n");
76
+		return -1;
77
+	}
78
+	if ((userblocklist_dbh = userblocklist_dbf.init(&userblocklist_db_url)) == NULL) {
79
+		LM_ERR("can't connect to database.\n");
80
+		return -1;
81
+	}
82
+	if (db_check_table_version(&userblocklist_dbf, userblocklist_dbh,
83
+			&userblocklist_table, userblocklist_version) < 0) {
84
+		DB_TABLE_VERSION_ERROR(userblocklist_table);
85
+		userblocklist_db_close();
86
+		return -1;
87
+	}
88
+	if (db_check_table_version(&userblocklist_dbf, userblocklist_dbh,
89
+			&globalblocklist_table, globalblocklist_version) < 0) {
90
+		DB_TABLE_VERSION_ERROR(globalblocklist_table);
91
+		userblocklist_db_close();
92
+		return -1;
93
+	}
94
+	userblocklist_db_close();
95
+	return 0;
96
+}
97
+
98
+
99
+/*!
100
+ * Initialize the DB connection without checking the table version and DB URL.
101
+ * This should be called from child_init. An already existing database
102
+ * connection will be closed, and a new one created.
103
+ *
104
+ * \return 0 means ok, -1 means an error occurred.
105
+ */
106
+int userblocklist_db_open(void) {
107
+	if (userblocklist_dbh) {
108
+		userblocklist_dbf.close(userblocklist_dbh);
109
+	}
110
+	if ((userblocklist_dbh = userblocklist_dbf.init(&userblocklist_db_url)) == NULL) {
111
+		LM_ERR("can't connect to database.\n");
112
+		return -1;
113
+	}
114
+	return 0;
115
+}
116
+