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 3 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;
... ...
@@ -134,6 +134,7 @@ typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _
134 134
 
135 135
 
136 136
 typedef struct db_func {
137
+	unsigned int     cap;          /* Capability vector of the database transport */
137 138
 	db_use_table_f   use_table;    /* Specify table name */
138 139
 	db_init_f        init;         /* Initialize database connection */
139 140
 	db_close_f       close;        /* Close database connection */
140 141
new file mode 100644
... ...
@@ -0,0 +1,44 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2004 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
26
+ */
27
+
28
+#ifndef DB_CAP_H
29
+#define DB_CAP_H
30
+
31
+
32
+/*
33
+ * Database capabilities
34
+ */
35
+typedef enum db_cap {
36
+	DB_CAP_QUERY =     1 << 0,  /* Database driver can query database */
37
+	DB_CAP_RAW_QUERY = 1 << 1,  /* Database driver can perform raw queries */
38
+	DB_CAP_INSERT =    1 << 2,  /* Database driver can insert data into database */
39
+	DB_CAP_DELETE =    1 << 3,  /* Database driver can delete data from database */
40
+	DB_CAP_UPDATE =    1 << 4   /* Database driver can update data in the database */
41
+} db_cap_t;
42
+	
43
+
44
+#endif /* DB_CAP_H */