Browse code

SER 2.0 database api moved to lib/srdb2.

Jan Janak authored on 12/02/2009 13:11:53
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,51 +0,0 @@
1
-/*
2
- * $Id$
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- * Copyright (C) 2006-2007 iptelorg GmbH
6
- *
7
- * This file is part of ser, a free SIP server.
8
- *
9
- * ser is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
13
- *
14
- * For a license to use the ser software under conditions
15
- * other than those described here, or to purchase support for this
16
- * software, please contact iptel.org by e-mail at the following addresses:
17
- *    info@iptel.org
18
- *
19
- * ser is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
- * GNU General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License 
25
- * along with this program; if not, write to the Free Software 
26
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
- */
28
- /*
29
-  * History:
30
-  * --------
31
-  *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
32
-  */
33
-
34
-/** \ingroup DB_API
35
- * @{
36
- */
37
-
38
-#include "db.h"
39
-
40
-#include "db_drv.h"
41
-
42
-#include "../dprint.h"
43
-#include "../sr_module.h"
44
-#include "../mem/mem.h"
45
-#include "../str.h"
46
-#include "../ut.h"
47
-#include "../list.h"
48
-
49
-struct _db_root db_root = DBLIST_INITIALIZER(db_root);
50
-
51
-/** @} */
Browse code

- reordered included header files for better detection of missing headers

Jan Janak authored on 16/01/2008 14:13:54
Showing 1 changed files
... ...
@@ -35,14 +35,16 @@
35 35
  * @{
36 36
  */
37 37
 
38
+#include "db.h"
39
+
40
+#include "db_drv.h"
41
+
38 42
 #include "../dprint.h"
39 43
 #include "../sr_module.h"
40 44
 #include "../mem/mem.h"
41 45
 #include "../str.h"
42 46
 #include "../ut.h"
43 47
 #include "../list.h"
44
-#include "db_drv.h"
45
-#include "db.h"
46 48
 
47 49
 struct _db_root db_root = DBLIST_INITIALIZER(db_root);
48 50
 
Browse code

- the root db structure renamed to avoid conflicts with variables in modules - database flags added

Jan Janak authored on 05/04/2007 11:37:52
Showing 1 changed files
... ...
@@ -44,6 +44,6 @@
44 44
 #include "db_drv.h"
45 45
 #include "db.h"
46 46
 
47
-struct db_root db = DBLIST_INITIALIZER(db);
47
+struct _db_root db_root = DBLIST_INITIALIZER(db_root);
48 48
 
49 49
 /** @} */
Browse code

- new db api, revision 2.0

Jan Janak authored on 04/04/2007 09:06:43
Showing 1 changed files
... ...
@@ -31,6 +31,9 @@
31 31
   *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
32 32
   */
33 33
 
34
+/** \ingroup DB_API
35
+ * @{
36
+ */
34 37
 
35 38
 #include "../dprint.h"
36 39
 #include "../sr_module.h"
... ...
@@ -42,3 +45,5 @@
42 45
 #include "db.h"
43 46
 
44 47
 struct db_root db = DBLIST_INITIALIZER(db);
48
+
49
+/** @} */
Browse code

- global db api data

Jan Janak authored on 29/03/2007 11:22:24
Showing 1 changed files
... ...
@@ -2,6 +2,7 @@
2 2
  * $Id$
3 3
  *
4 4
  * Copyright (C) 2001-2003 FhG Fokus
5
+ * Copyright (C) 2006-2007 iptelorg GmbH
5 6
  *
6 7
  * This file is part of ser, a free SIP server.
7 8
  *
... ...
@@ -36,170 +37,8 @@
36 37
 #include "../mem/mem.h"
37 38
 #include "../str.h"
38 39
 #include "../ut.h"
39
-#include "db_cap.h"
40
+#include "../list.h"
41
+#include "db_drv.h"
40 42
 #include "db.h"
41 43
 
42
-
43
-
44
-/* fills mydbf with the corresponding db module callbacks
45
- * returns 0 on success, -1 on error
46
- * on error mydbf will contain only 0s */
47
-int bind_dbmod(char* mod, db_func_t* mydbf)
48
-{
49
-	char* tmp, *p;
50
-	int len;
51
-	db_func_t dbf;
52
-
53
-	if (!mod) {
54
-		LOG(L_CRIT, "BUG: bind_dbmod(): null database module name\n");
55
-		return -1;
56
-	}
57
-	if (mydbf==0) {
58
-		LOG(L_CRIT, "BUG: bind_dbmod(): null dbf parameter\n");
59
-		return -1;
60
-	}
61
-	/* for safety we initialize mydbf with 0 (this will cause
62
-	 *  a segfault immediately if someone tries to call a function
63
-	 *  from it without checking the return code from bind_dbmod -- andrei */
64
-	memset((void*)mydbf, 0, sizeof(db_func_t));
65
-
66
-	p = strchr(mod, ':');
67
-	if (p) {
68
-		len = p - mod;
69
-		tmp = (char*)pkg_malloc(len + 1);
70
-		if (!tmp) {
71
-			LOG(L_ERR, "ERROR: bind_dbmod(): No memory left\n");
72
-			return -1;
73
-		}
74
-		memcpy(tmp, mod, len);
75
-		tmp[len] = '\0';
76
-	} else {
77
-		tmp = mod;
78
-	}
79
-
80
-	dbf.cap = 0;
81
-
82
-	if (find_module_by_name(tmp) == 0) {
83
-		ERR("Database driver '%s' not found\n", tmp);
84
-		goto err;
85
-	}
86
-
87
-	     /* All modules must export db_use_table */
88
-	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
89
-	if (dbf.use_table == 0) {
90
-		LOG(L_ERR, "bind_dbmod: Module %s does not export db_use_table function\n", tmp);
91
-		goto err;
92
-	}
93
-
94
-	     /* All modules must export db_init */
95
-	dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
96
-	if (dbf.init == 0) {
97
-		LOG(L_ERR, "bind_dbmod: Module %s does not export db_init function\n", tmp);
98
-		goto err;
99
-	}
100
-
101
-	     /* All modules must export db_close */
102
-	dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
103
-	if (dbf.close == 0) {
104
-		LOG(L_ERR, "bind_dbmod: Module %s does not export db_close function\n", tmp);
105
-		goto err;
106
-	}
107
-
108
-	dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
109
-	if (dbf.query) {
110
-		dbf.cap |= DB_CAP_QUERY;
111
-	}
112
-
113
-	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
114
-	if (dbf.raw_query) {
115
-		dbf.cap |= DB_CAP_RAW_QUERY;
116
-	}
117
-
118
-	     /* Free result must be exported if DB_CAP_QUERY 
119
-	      * or DB_CAP_RAW_QUERY is set
120
-	      */
121
-	dbf.free_result = (db_free_result_f)find_mod_export(tmp, "db_free_result", 2, 0);
122
-	if ((dbf.cap & (DB_CAP_QUERY | DB_CAP_RAW_QUERY))
123
-	    && (dbf.free_result == 0)) {
124
-		LOG(L_ERR, "bind_dbmod: Module %s supports quries but does not export free_result function\n", tmp);
125
-		goto err;
126
-	}
127
-
128
-	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
129
-	if (dbf.insert) {
130
-		dbf.cap |= DB_CAP_INSERT;
131
-	}
132
-
133
-	dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
134
-	if (dbf.delete) {
135
-		dbf.cap |= DB_CAP_DELETE;
136
-	}
137
-
138
-	dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
139
-	if (dbf.update) {
140
-		dbf.cap |= DB_CAP_UPDATE;
141
-	}
142
-
143
-	dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
144
-	if (dbf.replace) {
145
-		dbf.cap |= DB_CAP_REPLACE;
146
-	}
147
-
148
-	*mydbf=dbf; /* copy */
149
-	return 0;
150
-
151
- err:
152
-	if (tmp != mod) pkg_free(tmp);
153
-	return -1;
154
-}
155
-
156
-
157
-/*
158
- * Get version of a table
159
- * If there is no row for the given table, return version 0
160
- */
161
-int table_version(db_func_t* dbf, db_con_t* connection, const str* table)
162
-{
163
-	db_key_t key[1], col[1];
164
-	db_val_t val[1];
165
-	db_res_t* res;
166
-	int ret;
167
-
168
-	if (!dbf||!connection || !table) {
169
-		LOG(L_CRIT, "BUG: table_version(): Invalid parameter value\n");
170
-		return -1;
171
-	}
172
-
173
-	if (dbf->use_table(connection, VERSION_TABLE) < 0) {
174
-		LOG(L_ERR, "table_version(): Error while changing table\n");
175
-		return -1;
176
-	}
177
-
178
-	key[0] = TABLENAME_COLUMN;
179
-
180
-	VAL_TYPE(val) = DB_STR;
181
-	VAL_NULL(val) = 0;
182
-	VAL_STR(val) = *table;
183
-	
184
-	col[0] = VERSION_COLUMN;
185
-	
186
-	if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
187
-		LOG(L_ERR, "table_version(): Error in db_query\n");
188
-		return -1;
189
-	}
190
-
191
-	if (RES_ROW_N(res) == 0) {
192
-		DBG("table_version(): No row for table %.*s found\n", table->len, ZSW(table->s));
193
-		return 0;
194
-	}
195
-
196
-	if (RES_ROW_N(res) != 1) {
197
-		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
198
-		dbf->free_result(connection, res);
199
-		return -1;
200
-	}
201
-
202
-	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
203
-	dbf->free_result(connection, res);
204
-	return ret;
205
-}
44
+struct db_root db = DBLIST_INITIALIZER(db);
Browse code

- display proper error message when a database driver is not found

Jan Janak authored on 16/02/2006 14:49:30
Showing 1 changed files
... ...
@@ -79,6 +79,11 @@ int bind_dbmod(char* mod, db_func_t* mydbf)
79 79
 
80 80
 	dbf.cap = 0;
81 81
 
82
+	if (find_module_by_name(tmp) == 0) {
83
+		ERR("Database driver '%s' not found\n", tmp);
84
+		goto err;
85
+	}
86
+
82 87
 	     /* All modules must export db_use_table */
83 88
 	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
84 89
 	if (dbf.use_table == 0) {
Browse code

- typo fixed

Jan Janak authored on 28/02/2005 20:34:34
Showing 1 changed files
... ...
@@ -135,7 +135,7 @@ int bind_dbmod(char* mod, db_func_t* mydbf)
135 135
 		dbf.cap |= DB_CAP_UPDATE;
136 136
 	}
137 137
 
138
-	dbf.replace = (db_update_f)find_mod_export(tmp, "db_replace", 2, 0);
138
+	dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
139 139
 	if (dbf.replace) {
140 140
 		dbf.cap |= DB_CAP_REPLACE;
141 141
 	}
Browse code

- DB_REPLACE capability added

Jan Janak authored on 28/02/2005 18:52:32
Showing 1 changed files
... ...
@@ -135,6 +135,11 @@ int bind_dbmod(char* mod, db_func_t* mydbf)
135 135
 		dbf.cap |= DB_CAP_UPDATE;
136 136
 	}
137 137
 
138
+	dbf.replace = (db_update_f)find_mod_export(tmp, "db_replace", 2, 0);
139
+	if (dbf.replace) {
140
+		dbf.cap |= DB_CAP_REPLACE;
141
+	}
142
+
138 143
 	*mydbf=dbf; /* copy */
139 144
 	return 0;
140 145
 
Browse code

Database capability vector. It allows database modules to export just a subset of database interface and modules can query the capability of a particular database module.

Jan Janak authored on 14/09/2004 10:38:02
Showing 1 changed files
... ...
@@ -31,12 +31,13 @@
31 31
   */
32 32
 
33 33
 
34
-#include "db.h"
35 34
 #include "../dprint.h"
36 35
 #include "../sr_module.h"
37 36
 #include "../mem/mem.h"
38 37
 #include "../str.h"
39 38
 #include "../ut.h"
39
+#include "db_cap.h"
40
+#include "db.h"
40 41
 
41 42
 
42 43
 
... ...
@@ -76,33 +77,63 @@ int bind_dbmod(char* mod, db_func_t* mydbf)
76 77
 		tmp = mod;
77 78
 	}
78 79
 
80
+	dbf.cap = 0;
81
+
82
+	     /* All modules must export db_use_table */
79 83
 	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
80
-	if (dbf.use_table == 0) goto err;
84
+	if (dbf.use_table == 0) {
85
+		LOG(L_ERR, "bind_dbmod: Module %s does not export db_use_table function\n", tmp);
86
+		goto err;
87
+	}
81 88
 
89
+	     /* All modules must export db_init */
82 90
 	dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
83
-	if (dbf.init == 0) goto err;
91
+	if (dbf.init == 0) {
92
+		LOG(L_ERR, "bind_dbmod: Module %s does not export db_init function\n", tmp);
93
+		goto err;
94
+	}
84 95
 
96
+	     /* All modules must export db_close */
85 97
 	dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
86
-	if (dbf.close == 0) goto err;
98
+	if (dbf.close == 0) {
99
+		LOG(L_ERR, "bind_dbmod: Module %s does not export db_close function\n", tmp);
100
+		goto err;
101
+	}
87 102
 
88 103
 	dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
89
-	if (dbf.query == 0) goto err;
104
+	if (dbf.query) {
105
+		dbf.cap |= DB_CAP_QUERY;
106
+	}
90 107
 
91 108
 	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
92
-	if (dbf.raw_query == 0) goto err;
109
+	if (dbf.raw_query) {
110
+		dbf.cap |= DB_CAP_RAW_QUERY;
111
+	}
93 112
 
94
-	dbf.free_result = (db_free_result_f)find_mod_export(tmp, "db_free_result", 2,
95
-														0);
96
-	if (dbf.free_result == 0) goto err;
113
+	     /* Free result must be exported if DB_CAP_QUERY 
114
+	      * or DB_CAP_RAW_QUERY is set
115
+	      */
116
+	dbf.free_result = (db_free_result_f)find_mod_export(tmp, "db_free_result", 2, 0);
117
+	if ((dbf.cap & (DB_CAP_QUERY | DB_CAP_RAW_QUERY))
118
+	    && (dbf.free_result == 0)) {
119
+		LOG(L_ERR, "bind_dbmod: Module %s supports quries but does not export free_result function\n", tmp);
120
+		goto err;
121
+	}
97 122
 
98 123
 	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
99
-	if (dbf.insert == 0) goto err;
124
+	if (dbf.insert) {
125
+		dbf.cap |= DB_CAP_INSERT;
126
+	}
100 127
 
101 128
 	dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
102
-	if (dbf.delete == 0) goto err;
129
+	if (dbf.delete) {
130
+		dbf.cap |= DB_CAP_DELETE;
131
+	}
103 132
 
104 133
 	dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
105
-	if (dbf.update == 0) goto err;
134
+	if (dbf.update) {
135
+		dbf.cap |= DB_CAP_UPDATE;
136
+	}
106 137
 
107 138
 	*mydbf=dbf; /* copy */
108 139
 	return 0;
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:45:09
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * $Id$
3 3
  *
4
- * Copyright (C) 2001-2003 Fhg Fokus
4
+ * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6 6
  * This file is part of ser, a free SIP server.
7 7
  *
Browse code

free_query changed to free_result

Jan Janak authored on 04/08/2004 14:26:24
Showing 1 changed files
... ...
@@ -91,9 +91,9 @@ int bind_dbmod(char* mod, db_func_t* mydbf)
91 91
 	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
92 92
 	if (dbf.raw_query == 0) goto err;
93 93
 
94
-	dbf.free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2,
94
+	dbf.free_result = (db_free_result_f)find_mod_export(tmp, "db_free_result", 2,
95 95
 														0);
96
-	if (dbf.free_query == 0) goto err;
96
+	if (dbf.free_result == 0) goto err;
97 97
 
98 98
 	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
99 99
 	if (dbf.insert == 0) goto err;
... ...
@@ -154,11 +154,11 @@ int table_version(db_func_t* dbf, db_con_t* connection, const str* table)
154 154
 
155 155
 	if (RES_ROW_N(res) != 1) {
156 156
 		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
157
-		dbf->free_query(connection, res);
157
+		dbf->free_result(connection, res);
158 158
 		return -1;
159 159
 	}
160 160
 
161 161
 	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
162
-	dbf->free_query(connection, res);
162
+	dbf->free_result(connection, res);
163 163
 	return ret;
164 164
 }
Browse code

- changed db api: now several db modules can be used simultaneously; all the modules were updated to use the new api - small cleaups, like using static db related variables in modules (were it was possible) - changed version no.

Andrei Pelinescu-Onciul authored on 08/06/2004 10:55:29
Showing 1 changed files
... ...
@@ -24,6 +24,11 @@
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+ /*
28
+  * History:
29
+  * --------
30
+  *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
31
+  */
27 32
 
28 33
 
29 34
 #include "db.h"
... ...
@@ -33,25 +38,36 @@
33 38
 #include "../str.h"
34 39
 #include "../ut.h"
35 40
 
36
-db_func_t dbf;
37 41
 
38 42
 
39
-int bind_dbmod(char* mod)
43
+/* fills mydbf with the corresponding db module callbacks
44
+ * returns 0 on success, -1 on error
45
+ * on error mydbf will contain only 0s */
46
+int bind_dbmod(char* mod, db_func_t* mydbf)
40 47
 {
41 48
 	char* tmp, *p;
42 49
 	int len;
50
+	db_func_t dbf;
43 51
 
44 52
 	if (!mod) {
45
-		LOG(L_ERR, "bind_dbmod(): Invalid database module name\n");
53
+		LOG(L_CRIT, "BUG: bind_dbmod(): null database module name\n");
46 54
 		return -1;
47 55
 	}
56
+	if (mydbf==0) {
57
+		LOG(L_CRIT, "BUG: bind_dbmod(): null dbf parameter\n");
58
+		return -1;
59
+	}
60
+	/* for safety we initialize mydbf with 0 (this will cause
61
+	 *  a segfault immediately if someone tries to call a function
62
+	 *  from it without checking the return code from bind_dbmod -- andrei */
63
+	memset((void*)mydbf, 0, sizeof(db_func_t));
48 64
 
49 65
 	p = strchr(mod, ':');
50 66
 	if (p) {
51 67
 		len = p - mod;
52 68
 		tmp = (char*)pkg_malloc(len + 1);
53 69
 		if (!tmp) {
54
-			LOG(L_ERR, "bind_dbmod(): No memory left\n");
70
+			LOG(L_ERR, "ERROR: bind_dbmod(): No memory left\n");
55 71
 			return -1;
56 72
 		}
57 73
 		memcpy(tmp, mod, len);
... ...
@@ -60,33 +76,35 @@ int bind_dbmod(char* mod)
60 76
 		tmp = mod;
61 77
 	}
62 78
 
63
-	db_use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
64
-	if (db_use_table == 0) goto err;
79
+	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
80
+	if (dbf.use_table == 0) goto err;
65 81
 
66
-	db_init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
67
-	if (db_init == 0) goto err;
82
+	dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
83
+	if (dbf.init == 0) goto err;
68 84
 
69
-	db_close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
70
-	if (db_close == 0) goto err;
85
+	dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
86
+	if (dbf.close == 0) goto err;
71 87
 
72
-	db_query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
73
-	if (db_query == 0) goto err;
88
+	dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
89
+	if (dbf.query == 0) goto err;
74 90
 
75
-	db_raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
76
-	if (db_raw_query == 0) goto err;
91
+	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
92
+	if (dbf.raw_query == 0) goto err;
77 93
 
78
-	db_free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2, 0);
79
-	if (db_free_query == 0) goto err;
94
+	dbf.free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2,
95
+														0);
96
+	if (dbf.free_query == 0) goto err;
80 97
 
81
-	db_insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
82
-	if (db_insert == 0) goto err;
98
+	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
99
+	if (dbf.insert == 0) goto err;
83 100
 
84
-	db_delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
85
-	if (db_delete == 0) goto err;
101
+	dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
102
+	if (dbf.delete == 0) goto err;
86 103
 
87
-	db_update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
88
-	if (db_update == 0) goto err;
104
+	dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
105
+	if (dbf.update == 0) goto err;
89 106
 
107
+	*mydbf=dbf; /* copy */
90 108
 	return 0;
91 109
 
92 110
  err:
... ...
@@ -99,19 +117,19 @@ int bind_dbmod(char* mod)
99 117
  * Get version of a table
100 118
  * If there is no row for the given table, return version 0
101 119
  */
102
-int table_version(db_con_t* connection, const str* table)
120
+int table_version(db_func_t* dbf, db_con_t* connection, const str* table)
103 121
 {
104 122
 	db_key_t key[1], col[1];
105 123
 	db_val_t val[1];
106 124
 	db_res_t* res;
107 125
 	int ret;
108 126
 
109
-	if (!connection || !table) {
110
-		LOG(L_ERR, "table_version(): Invalid parameter value\n");
127
+	if (!dbf||!connection || !table) {
128
+		LOG(L_CRIT, "BUG: table_version(): Invalid parameter value\n");
111 129
 		return -1;
112 130
 	}
113 131
 
114
-	if (db_use_table(connection, VERSION_TABLE) < 0) {
132
+	if (dbf->use_table(connection, VERSION_TABLE) < 0) {
115 133
 		LOG(L_ERR, "table_version(): Error while changing table\n");
116 134
 		return -1;
117 135
 	}
... ...
@@ -124,7 +142,7 @@ int table_version(db_con_t* connection, const str* table)
124 142
 	
125 143
 	col[0] = VERSION_COLUMN;
126 144
 	
127
-	if (db_query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
145
+	if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
128 146
 		LOG(L_ERR, "table_version(): Error in db_query\n");
129 147
 		return -1;
130 148
 	}
... ...
@@ -136,11 +154,11 @@ int table_version(db_con_t* connection, const str* table)
136 154
 
137 155
 	if (RES_ROW_N(res) != 1) {
138 156
 		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
139
-		db_free_query(connection, res);
157
+		dbf->free_query(connection, res);
140 158
 		return -1;
141 159
 	}
142 160
 
143 161
 	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
144
-	db_free_query(connection, res);
162
+	dbf->free_query(connection, res);
145 163
 	return ret;
146 164
 }
Browse code

Missing header field added

Jan Janak authored on 23/01/2004 01:01:27
Showing 1 changed files
... ...
@@ -31,6 +31,7 @@
31 31
 #include "../sr_module.h"
32 32
 #include "../mem/mem.h"
33 33
 #include "../str.h"
34
+#include "../ut.h"
34 35
 
35 36
 db_func_t dbf;
36 37
 
... ...
@@ -129,7 +130,7 @@ int table_version(db_con_t* connection, const str* table)
129 130
 	}
130 131
 
131 132
 	if (RES_ROW_N(res) == 0) {
132
-		DBG("table_version(): No row for table %s found\n", table->len, ZSW(table->s));
133
+		DBG("table_version(): No row for table %.*s found\n", table->len, ZSW(table->s));
133 134
 		return 0;
134 135
 	}
135 136
 
Browse code

table_version returns version 0 if there is no row for the given table is found in table "version".

Jan Janak authored on 22/01/2004 22:28:36
Showing 1 changed files
... ...
@@ -96,6 +96,7 @@ int bind_dbmod(char* mod)
96 96
 
97 97
 /*
98 98
  * Get version of a table
99
+ * If there is no row for the given table, return version 0
99 100
  */
100 101
 int table_version(db_con_t* connection, const str* table)
101 102
 {
... ...
@@ -127,8 +128,13 @@ int table_version(db_con_t* connection, const str* table)
127 128
 		return -1;
128 129
 	}
129 130
 
131
+	if (RES_ROW_N(res) == 0) {
132
+		DBG("table_version(): No row for table %s found\n", table->len, ZSW(table->s));
133
+		return 0;
134
+	}
135
+
130 136
 	if (RES_ROW_N(res) != 1) {
131
-		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, table->s);
137
+		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
132 138
 		db_free_query(connection, res);
133 139
 		return -1;
134 140
 	}
Browse code

- table_version function -- the function returns version of given database table

Jan Janak authored on 28/11/2003 23:47:50
Showing 1 changed files
... ...
@@ -27,8 +27,10 @@
27 27
 
28 28
 
29 29
 #include "db.h"
30
+#include "../dprint.h"
30 31
 #include "../sr_module.h"
31 32
 #include "../mem/mem.h"
33
+#include "../str.h"
32 34
 
33 35
 db_func_t dbf;
34 36
 
... ...
@@ -90,3 +92,48 @@ int bind_dbmod(char* mod)
90 92
 	if (tmp != mod) pkg_free(tmp);
91 93
 	return -1;
92 94
 }
95
+
96
+
97
+/*
98
+ * Get version of a table
99
+ */
100
+int table_version(db_con_t* connection, const str* table)
101
+{
102
+	db_key_t key[1], col[1];
103
+	db_val_t val[1];
104
+	db_res_t* res;
105
+	int ret;
106
+
107
+	if (!connection || !table) {
108
+		LOG(L_ERR, "table_version(): Invalid parameter value\n");
109
+		return -1;
110
+	}
111
+
112
+	if (db_use_table(connection, VERSION_TABLE) < 0) {
113
+		LOG(L_ERR, "table_version(): Error while changing table\n");
114
+		return -1;
115
+	}
116
+
117
+	key[0] = TABLENAME_COLUMN;
118
+
119
+	VAL_TYPE(val) = DB_STR;
120
+	VAL_NULL(val) = 0;
121
+	VAL_STR(val) = *table;
122
+	
123
+	col[0] = VERSION_COLUMN;
124
+	
125
+	if (db_query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
126
+		LOG(L_ERR, "table_version(): Error in db_query\n");
127
+		return -1;
128
+	}
129
+
130
+	if (RES_ROW_N(res) != 1) {
131
+		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, table->s);
132
+		db_free_query(connection, res);
133
+		return -1;
134
+	}
135
+
136
+	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
137
+	db_free_query(connection, res);
138
+	return ret;
139
+}
Browse code

- Removed obsolete function declarations

Jan Janak authored on 24/10/2003 20:33:45
Showing 1 changed files
... ...
@@ -28,38 +28,65 @@
28 28
 
29 29
 #include "db.h"
30 30
 #include "../sr_module.h"
31
+#include "../mem/mem.h"
31 32
 
32 33
 db_func_t dbf;
33 34
 
34 35
 
35
-int bind_dbmod(void)
36
+int bind_dbmod(char* mod)
36 37
 {
37
-	db_use_table = (db_use_table_f)find_export("db_use_table", 2, 0);
38
-	if (db_use_table == 0) return -1;
38
+	char* tmp, *p;
39
+	int len;
39 40
 
40
-	db_init = (db_init_f)find_export("db_init", 1, 0);
41
-	if (db_init == 0) return -1;
41
+	if (!mod) {
42
+		LOG(L_ERR, "bind_dbmod(): Invalid database module name\n");
43
+		return -1;
44
+	}
42 45
 
43
-	db_close = (db_close_f)find_export("db_close", 2, 0);
44
-	if (db_close == 0) return -1;
46
+	p = strchr(mod, ':');
47
+	if (p) {
48
+		len = p - mod;
49
+		tmp = (char*)pkg_malloc(len + 1);
50
+		if (!tmp) {
51
+			LOG(L_ERR, "bind_dbmod(): No memory left\n");
52
+			return -1;
53
+		}
54
+		memcpy(tmp, mod, len);
55
+		tmp[len] = '\0';
56
+	} else {
57
+		tmp = mod;
58
+	}
45 59
 
46
-	db_query = (db_query_f)find_export("db_query", 2, 0);
47
-	if (db_query == 0) return -1;
60
+	db_use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
61
+	if (db_use_table == 0) goto err;
48 62
 
49
-	db_raw_query = (db_raw_query_f)find_export("db_raw_query", 2, 0);
50
-	if (db_raw_query == 0) return -1;
63
+	db_init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
64
+	if (db_init == 0) goto err;
51 65
 
52
-	db_free_query = (db_free_query_f)find_export("db_free_query", 2, 0);
53
-	if (db_free_query == 0) return -1;
66
+	db_close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
67
+	if (db_close == 0) goto err;
54 68
 
55
-	db_insert = (db_insert_f)find_export("db_insert", 2, 0);
56
-	if (db_insert == 0) return -1;
69
+	db_query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
70
+	if (db_query == 0) goto err;
57 71
 
58
-	db_delete = (db_delete_f)find_export("db_delete", 2, 0);
59
-	if (db_delete == 0) return -1;
72
+	db_raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
73
+	if (db_raw_query == 0) goto err;
60 74
 
61
-	db_update = (db_update_f)find_export("db_update", 2, 0);
62
-	if (db_update == 0) return -1;
75
+	db_free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2, 0);
76
+	if (db_free_query == 0) goto err;
77
+
78
+	db_insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
79
+	if (db_insert == 0) goto err;
80
+
81
+	db_delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
82
+	if (db_delete == 0) goto err;
83
+
84
+	db_update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
85
+	if (db_update == 0) goto err;
63 86
 
64 87
 	return 0;
88
+
89
+ err:
90
+	if (tmp != mod) pkg_free(tmp);
91
+	return -1;
65 92
 }
Browse code

- Got rid of all the ~ at the beginning of functions that are not supposed to be called from scripts. It's a relict.

Jan Janak authored on 08/10/2003 13:07:21
Showing 1 changed files
... ...
@@ -34,31 +34,31 @@ db_func_t dbf;
34 34
 
35 35
 int bind_dbmod(void)
36 36
 {
37
-	db_use_table = (db_use_table_f)find_export("~db_use_table", 2, 0);
37
+	db_use_table = (db_use_table_f)find_export("db_use_table", 2, 0);
38 38
 	if (db_use_table == 0) return -1;
39 39
 
40
-	db_init = (db_init_f)find_export("~db_init", 1, 0);
40
+	db_init = (db_init_f)find_export("db_init", 1, 0);
41 41
 	if (db_init == 0) return -1;
42 42
 
43
-	db_close = (db_close_f)find_export("~db_close", 2, 0);
43
+	db_close = (db_close_f)find_export("db_close", 2, 0);
44 44
 	if (db_close == 0) return -1;
45 45
 
46
-	db_query = (db_query_f)find_export("~db_query", 2, 0);
46
+	db_query = (db_query_f)find_export("db_query", 2, 0);
47 47
 	if (db_query == 0) return -1;
48 48
 
49
-	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2, 0);
49
+	db_raw_query = (db_raw_query_f)find_export("db_raw_query", 2, 0);
50 50
 	if (db_raw_query == 0) return -1;
51 51
 
52
-	db_free_query = (db_free_query_f)find_export("~db_free_query", 2, 0);
52
+	db_free_query = (db_free_query_f)find_export("db_free_query", 2, 0);
53 53
 	if (db_free_query == 0) return -1;
54 54
 
55
-	db_insert = (db_insert_f)find_export("~db_insert", 2, 0);
55
+	db_insert = (db_insert_f)find_export("db_insert", 2, 0);
56 56
 	if (db_insert == 0) return -1;
57 57
 
58
-	db_delete = (db_delete_f)find_export("~db_delete", 2, 0);
58
+	db_delete = (db_delete_f)find_export("db_delete", 2, 0);
59 59
 	if (db_delete == 0) return -1;
60 60
 
61
-	db_update = (db_update_f)find_export("~db_update", 2, 0);
61
+	db_update = (db_update_f)find_export("db_update", 2, 0);
62 62
 	if (db_update == 0) return -1;
63 63
 
64 64
 	return 0;
Browse code

- additional parameter to find_export - find_export updated to honor flags parameter - REPLY_ROUTE defined

Jan Janak authored on 19/03/2003 23:46:09
Showing 1 changed files
... ...
@@ -34,31 +34,31 @@ db_func_t dbf;
34 34
 
35 35
 int bind_dbmod(void)
36 36
 {
37
-	db_use_table = (db_use_table_f)find_export("~db_use_table", 2);
37
+	db_use_table = (db_use_table_f)find_export("~db_use_table", 2, 0);
38 38
 	if (db_use_table == 0) return -1;
39 39
 
40
-	db_init = (db_init_f)find_export("~db_init", 1);
40
+	db_init = (db_init_f)find_export("~db_init", 1, 0);
41 41
 	if (db_init == 0) return -1;
42 42
 
43
-	db_close = (db_close_f)find_export("~db_close", 2);
43
+	db_close = (db_close_f)find_export("~db_close", 2, 0);
44 44
 	if (db_close == 0) return -1;
45 45
 
46
-	db_query = (db_query_f)find_export("~db_query", 2);
46
+	db_query = (db_query_f)find_export("~db_query", 2, 0);
47 47
 	if (db_query == 0) return -1;
48 48
 
49
-	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2);
49
+	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2, 0);
50 50
 	if (db_raw_query == 0) return -1;
51 51
 
52
-	db_free_query = (db_free_query_f)find_export("~db_free_query", 2);
52
+	db_free_query = (db_free_query_f)find_export("~db_free_query", 2, 0);
53 53
 	if (db_free_query == 0) return -1;
54 54
 
55
-	db_insert = (db_insert_f)find_export("~db_insert", 2);
55
+	db_insert = (db_insert_f)find_export("~db_insert", 2, 0);
56 56
 	if (db_insert == 0) return -1;
57 57
 
58
-	db_delete = (db_delete_f)find_export("~db_delete", 2);
58
+	db_delete = (db_delete_f)find_export("~db_delete", 2, 0);
59 59
 	if (db_delete == 0) return -1;
60 60
 
61
-	db_update = (db_update_f)find_export("~db_update", 2);
61
+	db_update = (db_update_f)find_export("~db_update", 2, 0);
62 62
 	if (db_update == 0) return -1;
63 63
 
64 64
 	return 0;
Browse code

db_query, db_delete and db_update now accept additional parameter - operator. New function added - db_raw_query which accepts a raw SQL query and executes it.

Jan Janak authored on 28/11/2002 16:53:03
Showing 1 changed files
... ...
@@ -46,6 +46,9 @@ int bind_dbmod(void)
46 46
 	db_query = (db_query_f)find_export("~db_query", 2);
47 47
 	if (db_query == 0) return -1;
48 48
 
49
+	db_raw_query = (db_raw_query_f)find_export("~db_raw_query", 2);
50
+	if (db_raw_query == 0) return -1;
51
+
49 52
 	db_free_query = (db_free_query_f)find_export("~db_free_query", 2);
50 53
 	if (db_free_query == 0) return -1;
51 54
 
Browse code

GPLization banner introduced to *.[hc] files

Jiri Kuthan authored on 19/09/2002 12:23:52
Showing 1 changed files
... ...
@@ -1,7 +1,31 @@
1 1
 /*
2 2
  * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3 26
  */
4 27