Browse code

- Removed obsolete function declarations

Jan Janak authored on 24/10/2003 20:33:45
Showing 6 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
 }
... ...
@@ -128,7 +128,7 @@ typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _
128 128
 
129 129
 
130 130
 
131
-typedef struct db_func{
131
+typedef struct db_func {
132 132
 	db_use_table_f  use_table;   /* Specify table name */
133 133
 	db_init_f       init;        /* Initialize dabase connection */
134 134
 	db_close_f      close;       /* Close database connection */
... ...
@@ -161,7 +161,7 @@ extern db_func_t dbf;
161 161
 #define db_update     (dbf.update)
162 162
 
163 163
 
164
-int bind_dbmod(void);
164
+int bind_dbmod(char* mod);
165 165
  
166 166
 
167 167
 #endif /* DB_H */
... ...
@@ -49,7 +49,4 @@ typedef struct {
49 49
 #define CON_TAIL(cn)       ((cn)->tail)
50 50
 
51 51
 
52
-int use_table(db_con_t* _h, const char* _t);
53
-
54
-
55 52
 #endif /* DB_CON_H */
... ...
@@ -29,13 +29,10 @@
29 29
 #ifndef DB_RES_H
30 30
 #define DB_RES_H
31 31
 
32
+
32 33
 #include "db_row.h"
33 34
 #include "db_key.h"
34 35
 #include "db_val.h"
35
-#include "db_con.h"
36
-
37
-
38
-struct db_row;
39 36
 
40 37
 
41 38
 typedef struct db_res {
... ...
@@ -56,22 +53,4 @@ typedef struct db_res {
56 53
 #define RES_ROW_N(re) ((re)->n)
57 54
 
58 55
 
59
-/*
60
- * Create a new result structure 
61
- */
62
-db_res_t* new_result(void);
63
-
64
-
65
-/*
66
- * Fill the structure with data from database
67
- */
68
-int convert_result(db_con_t* _h, db_res_t* _r);
69
-
70
-
71
-/*
72
- * Free all memory allocated by the structure
73
- */
74
-int free_result(db_res_t* _r);
75
-
76
-
77 56
 #endif /* DB_RES_H */
... ...
@@ -30,12 +30,8 @@
30 30
 #define DB_ROW_H
31 31
 
32 32
 #include "db_val.h"
33
-#include "db_con.h"
34
-#include "db_res.h"
35 33
 
36 34
 
37
-struct db_res;
38
-
39 35
 /*
40 36
  * Structure holding result of query_table function (ie. table row)
41 37
  */
... ...
@@ -49,8 +45,4 @@ typedef struct db_row {
49 45
 #define ROW_N(rw)      ((rw)->n)
50 46
 
51 47
 
52
-int convert_row(db_con_t* _h, struct db_res* _res, db_row_t* _r);
53
-int free_row(db_row_t* _r);
54
-
55
-
56 48
 #endif /* DB_ROW_H */
... ...
@@ -34,16 +34,16 @@
34 34
 
35 35
 
36 36
 /*
37
- * Accepted column types
37
+ * Accepted value types
38 38
  */
39 39
 typedef enum {
40
-	DB_INT,
41
-        DB_DOUBLE,
42
-	DB_STRING,
43
-	DB_STR,
44
-	DB_DATETIME,
45
-	DB_BLOB,
46
-	DB_BITMAP
40
+	DB_INT,        /* 32-bit integer */
41
+        DB_DOUBLE,     /* double data type */
42
+	DB_STRING,     /* Zero-terminated string */
43
+	DB_STR,        /* str structure */
44
+	DB_DATETIME,   /* Date and time */
45
+	DB_BLOB,       /* Large binary object */
46
+	DB_BITMAP      /* Bitmap of flags */
47 47
 } db_type_t;
48 48
 
49 49
 
... ...
@@ -70,7 +70,6 @@ typedef struct {
70 70
 /*
71 71
  * Useful macros for accessing attributes of db_val structure
72 72
  */
73
-
74 73
 #define VAL_TYPE(dv)   ((dv)->type)
75 74
 #define VAL_NULL(dv)   ((dv)->nul)
76 75
 #define VAL_INT(dv)    ((dv)->val.int_val)
... ...
@@ -82,16 +81,4 @@ typedef struct {
82 81
 #define VAL_BITMAP(dv) ((dv)->val.bitmap_val)
83 82
 
84 83
 
85
-/*
86
- * Convert string to given type
87
- */
88
-int str2val(db_type_t _t, db_val_t* _v, const char* _s, int _l);
89
-
90
-
91
-/*
92
- * Convert given type to string
93
- */
94
-int val2str(db_val_t* _v, char* _s, int* _len);
95
-
96
-
97 84
 #endif /* DB_VAL_H */