Browse code

modules_s/cpl-c: moved to obsolete list

- use the other cpl-c module

Daniel-Constantin Mierla authored on 21/12/2012 12:28:44
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,206 +0,0 @@
1
-/*
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
26
- */
27
- /*
28
-  * History:
29
-  * --------
30
-  *  2004-06-06  updated to the new DB api (andrei)
31
-  */
32
-
33
-#include "../../mem/shm_mem.h"
34
-#include "../../lib/srdb2/db.h"
35
-#include "../../dprint.h"
36
-#include "cpl_db.h"
37
-
38
-static db_ctx_t* ctx = NULL;
39
-static db_cmd_t* get_script;
40
-static db_cmd_t* write_script;
41
-static db_cmd_t* delete_user;
42
-
43
-
44
-void cpl_db_close()
45
-{
46
-	if (delete_user) db_cmd_free(delete_user);
47
-	delete_user = NULL;
48
-
49
-	if (write_script) db_cmd_free(write_script);
50
-	write_script = NULL;
51
-
52
-	if (get_script) db_cmd_free(get_script);
53
-	get_script = NULL;
54
-
55
-	if (ctx) {
56
-		db_disconnect(ctx);
57
-		db_ctx_free(ctx);
58
-		ctx = NULL;
59
-	}
60
-}
61
-
62
-
63
-int cpl_db_init(char* db_url, char* db_table)
64
-{
65
-	db_fld_t cols[] = {
66
-		{.name = "cpl_bin", .type = DB_BLOB},
67
-		{.name = "cpl_xml", .type = DB_STR},
68
-		{.name = 0}
69
-	};
70
-
71
-	db_fld_t match[] = {
72
-		{.name = "uid", .type = DB_CSTR},
73
-		{.name = 0}
74
-	};
75
-
76
-	db_fld_t vals[] = {
77
-		{.name = "uid",     .type = DB_CSTR},
78
-		{.name = "cpl_bin", .type = DB_BLOB},
79
-		{.name = "cpl_xml", .type = DB_STR },
80
-		{.name = 0}
81
-	};
82
-
83
-	ctx = db_ctx("cpl-c");
84
-	if (ctx == NULL) goto error;
85
-
86
-	if (db_add_db(ctx, db_url) < 0) goto error;
87
-	if (db_connect(ctx) < 0) goto error;
88
-
89
-	get_script = db_cmd(DB_GET, ctx, db_table, cols, match, NULL);
90
-	if (!get_script) goto error;
91
-
92
-	write_script = db_cmd(DB_PUT, ctx, db_table, NULL, NULL, vals);
93
-	if (!write_script) goto error;
94
-
95
-	delete_user = db_cmd(DB_DEL, ctx, db_table, NULL, match, NULL);
96
-	if (!delete_user) goto error;
97
-
98
-	return 0;
99
-error:
100
-	ERR("cpl-c: Error while initializing db layer\n");
101
-	cpl_db_close();
102
-	return -1;
103
-}
104
-
105
-
106
-/* gets from database the cpl script in binary format; the returned script is
107
- * allocated in shared memory
108
- * Returns:  1 - success
109
- *          -1 - error
110
- */
111
-int get_user_script(str *user, str *script, int bin)
112
-{
113
-	db_res_t* res = 0;
114
-	db_rec_t* rec;
115
-	int i;
116
-
117
-	if (bin) i = 0;
118
-	else i = 1;
119
-
120
-	get_script->match[0].v.cstr = user->s;
121
-
122
-	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
123
-	if (db_exec(&res, get_script) < 0) {
124
-		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
125
-		goto error;
126
-	}
127
-
128
-	if (!res || !(rec = db_first(res))) {
129
-		DBG("DEBUG:get_user_script: user <%.*s> not found in db -> probably "
130
-			"he has no script\n",user->len, user->s);
131
-		script->s = 0;
132
-		script->len = 0;
133
-	} else {
134
-		if (rec->fld[i].flags & DB_NULL) {
135
-			DBG("DEBUG:get_user_script: user <%.*s> has a NULL script\n",
136
-				user->len, user->s);
137
-			script->s = 0;
138
-			script->len = 0;
139
-		} else {
140
-			DBG("DEBUG:get_user_script: we got the script len=%d\n",
141
-				rec->fld[i].v.blob.len);
142
-			script->len = rec->fld[i].v.blob.len;
143
-			script->s = shm_malloc( script->len );
144
-			if (!script->s) {
145
-				LOG(L_ERR,"ERROR:cpl-c:get_user_script: no free sh_mem\n");
146
-				goto error;
147
-			}
148
-			memcpy( script->s, rec->fld[i].v.blob.s,
149
-				script->len);
150
-		}
151
-	}
152
-
153
-	if (res) db_res_free(res);
154
-	return 1;
155
-error:
156
-	if (res)
157
-		db_res_free(res);
158
-	script->s = 0;
159
-	script->len = 0;
160
-	return -1;
161
-}
162
-
163
-
164
-
165
-/* inserts into database a cpl script in XML format(xml) along with its binary
166
- * format (bin)
167
- * Returns:  1 - success
168
- *          -1 - error
169
- */
170
-int write_to_db(char *usr, str *xml, str *bin)
171
-{
172
-	write_script->vals[0].v.cstr = usr;
173
-	write_script->vals[1].v.blob = *bin;
174
-	write_script->vals[2].v.lstr = *xml;
175
-
176
-	/* No need to do update/insert here, the db layer does that
177
-	 * automatically without the need to query the db
178
-	 */
179
-	if (db_exec(NULL, write_script) < 0) {
180
-		ERR("cpl-c: Error while writing script into database\n");
181
-		return -1;
182
-	}
183
-	return 0;
184
-}
185
-
186
-
187
-
188
-/* delete from database the entity record for a given user - if a user has no
189
- * script, he will be removed completely from db; users without script are not
190
- * allowed into db ;-)
191
- * Returns:  1 - success
192
- *          -1 - error
193
- */
194
-int rmv_from_db(char *usr)
195
-{
196
-	delete_user->match[0].v.cstr = usr;
197
-	
198
-	if (db_exec(NULL, delete_user) < 0) {
199
-		LOG(L_ERR,"ERROR:cpl-c:rmv_from_db: error when deleting script for "
200
-			"user \"%s\"\n",usr);
201
-		return -1;
202
-	}
203
-
204
-	return 1;
205
-}
206
-
Browse code

ser modules ported to sip-router

- added -DSER_MOD_INTERFACE to each module Makefile
- db:
- linked with srdb2 when needed
- fixed db includes path (../../lib/srdb2/*.h)
- fixed db constants
- fixed tm include path (../../modules/tm/*.h)

Andrei Pelinescu-Onciul authored on 15/04/2009 17:16:10
Showing 1 changed files
... ...
@@ -31,7 +31,7 @@
31 31
   */
32 32
 
33 33
 #include "../../mem/shm_mem.h"
34
-#include "../../db/db.h"
34
+#include "../../lib/srdb2/db.h"
35 35
 #include "../../dprint.h"
36 36
 #include "cpl_db.h"
37 37
 
Browse code

- updated to the latest db api

Jan Janak authored on 28/05/2008 16:51:35
Showing 1 changed files
... ...
@@ -35,119 +35,126 @@
35 35
 #include "../../dprint.h"
36 36
 #include "cpl_db.h"
37 37
 
38
-static db_con_t* db_hdl=0;
39
-static db_func_t cpl_dbf;
38
+static db_ctx_t* ctx = NULL;
39
+static db_cmd_t* get_script;
40
+static db_cmd_t* write_script;
41
+static db_cmd_t* delete_user;
40 42
 
41 43
 
42
-
43
-int cpl_db_bind(char* db_url)
44
+void cpl_db_close()
44 45
 {
45
-	if (bind_dbmod(db_url, &cpl_dbf )) {
46
-		LOG(L_CRIT, "ERROR:cpl_db_bind: cannot bind to database module! "
47
-		    "Did you forget to load a database module ?\n");
48
-		return -1;
49
-	}
50
-	
51
-	     /* CPL module uses all database functions */
52
-	if (!DB_CAPABILITY(cpl_dbf, DB_CAP_ALL)) {
53
-		LOG(L_CRIT, "ERROR:cpl_db_bind: Database modules does not "
54
-		    "provide all functions needed by cpl-c module\n");
55
-		return -1;
56
-	}
46
+	if (delete_user) db_cmd_free(delete_user);
47
+	delete_user = NULL;
57 48
 
58
-	return 0;
59
-}
49
+	if (write_script) db_cmd_free(write_script);
50
+	write_script = NULL;
51
+
52
+	if (get_script) db_cmd_free(get_script);
53
+	get_script = NULL;
60 54
 
55
+	if (ctx) {
56
+		db_disconnect(ctx);
57
+		db_ctx_free(ctx);
58
+		ctx = NULL;
59
+	}
60
+}
61 61
 
62 62
 
63 63
 int cpl_db_init(char* db_url, char* db_table)
64 64
 {
65
-	if (cpl_dbf.init==0){
66
-		LOG(L_CRIT, "BUG: cpl_db_init: unbound database module\n");
67
-		return -1;
68
-	}
69
-	db_hdl=cpl_dbf.init(db_url);
70
-	if (db_hdl==0){
71
-		LOG(L_CRIT,"ERROR:cpl_db_init: cannot initialize database "
72
-			"connection\n");
73
-		goto error;
74
-	}
75
-	if (cpl_dbf.use_table(db_hdl, db_table)<0) {
76
-		LOG(L_CRIT,"ERROR:cpl_db_init: cannot select table \"%s\"\n",db_table);
77
-		goto error;
78
-	}
65
+	db_fld_t cols[] = {
66
+		{.name = "cpl_bin", .type = DB_BLOB},
67
+		{.name = "cpl_xml", .type = DB_STR},
68
+		{.name = 0}
69
+	};
70
+
71
+	db_fld_t match[] = {
72
+		{.name = "uid", .type = DB_CSTR},
73
+		{.name = 0}
74
+	};
75
+
76
+	db_fld_t vals[] = {
77
+		{.name = "uid",     .type = DB_CSTR},
78
+		{.name = "cpl_bin", .type = DB_BLOB},
79
+		{.name = "cpl_xml", .type = DB_STR },
80
+		{.name = 0}
81
+	};
82
+
83
+	ctx = db_ctx("cpl-c");
84
+	if (ctx == NULL) goto error;
85
+
86
+	if (db_add_db(ctx, db_url) < 0) goto error;
87
+	if (db_connect(ctx) < 0) goto error;
88
+
89
+	get_script = db_cmd(DB_GET, ctx, db_table, cols, match, NULL);
90
+	if (!get_script) goto error;
91
+
92
+	write_script = db_cmd(DB_PUT, ctx, db_table, NULL, NULL, vals);
93
+	if (!write_script) goto error;
94
+
95
+	delete_user = db_cmd(DB_DEL, ctx, db_table, NULL, match, NULL);
96
+	if (!delete_user) goto error;
97
+
79 98
 	return 0;
80 99
 error:
81
-	if (db_hdl){
82
-		cpl_dbf.close(db_hdl);
83
-		db_hdl=0;
84
-	}
100
+	ERR("cpl-c: Error while initializing db layer\n");
101
+	cpl_db_close();
85 102
 	return -1;
86 103
 }
87 104
 
88
-void cpl_db_close()
89
-{
90
-	if (db_hdl && cpl_dbf.close){
91
-		cpl_dbf.close(db_hdl);
92
-		db_hdl=0;
93
-	}
94
-}
95
-
96 105
 
97 106
 /* gets from database the cpl script in binary format; the returned script is
98 107
  * allocated in shared memory
99 108
  * Returns:  1 - success
100 109
  *          -1 - error
101 110
  */
102
-int get_user_script(str *user, str *script, const char* key)
111
+int get_user_script(str *user, str *script, int bin)
103 112
 {
104
-	db_key_t   keys_cmp[1];
105
-	db_key_t   keys_ret[1];
106
-	db_val_t   vals[1];
107
-	db_res_t   *res = 0 ;
113
+	db_res_t* res = 0;
114
+	db_rec_t* rec;
115
+	int i;
116
+
117
+	if (bin) i = 0;
118
+	else i = 1;
119
+
120
+	get_script->match[0].v.cstr = user->s;
108 121
 
109
-	keys_cmp[0]="user";
110
-	keys_ret[0]=key;
111 122
 	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
112
-	vals[0].type = DB_STRING;
113
-	vals[0].nul  = 0;
114
-	vals[0].val.string_val = user->s;
115
-	if (cpl_dbf.query(db_hdl, keys_cmp, 0, vals, keys_ret, 1, 1, NULL, &res)
116
-			< 0){
123
+	if (db_exec(&res, get_script) < 0) {
117 124
 		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
118 125
 		goto error;
119 126
 	}
120 127
 
121
-	if (res->n==0) {
128
+	if (!res || !(rec = db_first(res))) {
122 129
 		DBG("DEBUG:get_user_script: user <%.*s> not found in db -> probably "
123 130
 			"he has no script\n",user->len, user->s);
124 131
 		script->s = 0;
125 132
 		script->len = 0;
126 133
 	} else {
127
-		if (res->rows[0].values[0].nul) {
134
+		if (rec->fld[i].flags & DB_NULL) {
128 135
 			DBG("DEBUG:get_user_script: user <%.*s> has a NULL script\n",
129 136
 				user->len, user->s);
130 137
 			script->s = 0;
131 138
 			script->len = 0;
132 139
 		} else {
133 140
 			DBG("DEBUG:get_user_script: we got the script len=%d\n",
134
-				res->rows[0].values[0].val.blob_val.len);
135
-			script->len = res->rows[0].values[0].val.blob_val.len;
141
+				rec->fld[i].v.blob.len);
142
+			script->len = rec->fld[i].v.blob.len;
136 143
 			script->s = shm_malloc( script->len );
137 144
 			if (!script->s) {
138 145
 				LOG(L_ERR,"ERROR:cpl-c:get_user_script: no free sh_mem\n");
139 146
 				goto error;
140 147
 			}
141
-			memcpy( script->s, res->rows[0].values[0].val.blob_val.s,
148
+			memcpy( script->s, rec->fld[i].v.blob.s,
142 149
 				script->len);
143 150
 		}
144 151
 	}
145 152
 
146
-	cpl_dbf.free_result( db_hdl, res);
153
+	if (res) db_res_free(res);
147 154
 	return 1;
148 155
 error:
149 156
 	if (res)
150
-		cpl_dbf.free_result( db_hdl, res);
157
+		db_res_free(res);
151 158
 	script->s = 0;
152 159
 	script->len = 0;
153 160
 	return -1;
... ...
@@ -162,57 +169,18 @@ error:
162 169
  */
163 170
 int write_to_db(char *usr, str *xml, str *bin)
164 171
 {
165
-	db_key_t   keys[] = {"user","cpl_xml","cpl_bin"};
166
-	db_val_t   vals[3];
167
-	db_res_t   *res;
168
-
169
-	/* lets see if the user is already in database */
170
-	vals[0].type = DB_STRING;
171
-	vals[0].nul  = 0;
172
-	vals[0].val.string_val = usr;
173
-	if (cpl_dbf.query(db_hdl, keys, 0, vals, keys, 1, 1, NULL, &res) < 0) {
174
-		LOG(L_ERR,"ERROR:cpl:write_to_db: db_query failed\n");
175
-		goto error;
176
-	}
177
-	if (res->n>1) {
178
-		LOG(L_ERR,"ERROR:cpl:write_to_db: Inconsistent CPL database:"
179
-			" %d records for user %s\n",res->n,usr);
180
-		goto error;
181
-	}
182
-
183
-	/* username */
184
-	vals[0].type = DB_STRING;
185
-	vals[0].nul  = 0;
186
-	vals[0].val.string_val = usr;
187
-	/* cpl text */
188
-	vals[1].type = DB_BLOB;
189
-	vals[1].nul  = 0;
190
-	vals[1].val.blob_val.s = xml->s;
191
-	vals[1].val.blob_val.len = xml->len;
192
-	/* cpl bin */
193
-	vals[2].type = DB_BLOB;
194
-	vals[2].nul  = 0;
195
-	vals[2].val.blob_val.s = bin->s;
196
-	vals[2].val.blob_val.len = bin->len;
197
-	/* insert or update ? */
198
-	if (res->n==0) {
199
-		DBG("DEBUG:cpl:write_to_db:No user %s in CPL database->insert\n",usr);
200
-		if (cpl_dbf.insert(db_hdl, keys, vals, 3) < 0) {
201
-			LOG(L_ERR,"ERROR:cpl:write_to_db: insert failed !\n");
202
-			goto error;
203
-		}
204
-	} else {
205
-		DBG("DEBUG:cpl:write_to_db:User %s already in CPL database ->"
206
-			" update\n",usr);
207
-		if (cpl_dbf.update(db_hdl, keys, 0, vals, keys+1, vals+1, 1, 2) < 0) {
208
-			LOG(L_ERR,"ERROR:cpl:write_to_db: update failed !\n");
209
-			goto error;
210
-		}
172
+	write_script->vals[0].v.cstr = usr;
173
+	write_script->vals[1].v.blob = *bin;
174
+	write_script->vals[2].v.lstr = *xml;
175
+
176
+	/* No need to do update/insert here, the db layer does that
177
+	 * automatically without the need to query the db
178
+	 */
179
+	if (db_exec(NULL, write_script) < 0) {
180
+		ERR("cpl-c: Error while writing script into database\n");
181
+		return -1;
211 182
 	}
212
-
213
-	return 1;
214
-error:
215
-	return -1;
183
+	return 0;
216 184
 }
217 185
 
218 186
 
... ...
@@ -225,15 +193,9 @@ error:
225 193
  */
226 194
 int rmv_from_db(char *usr)
227 195
 {
228
-	db_key_t   keys[] = {"user"};
229
-	db_val_t   vals[1];
230
-
231
-	/* username */
232
-	vals[0].type = DB_STRING;
233
-	vals[0].nul  = 0;
234
-	vals[0].val.string_val = usr;
235
-
236
-	if (cpl_dbf.delete(db_hdl, keys, NULL, vals, 1) < 0) {
196
+	delete_user->match[0].v.cstr = usr;
197
+	
198
+	if (db_exec(NULL, delete_user) < 0) {
237 199
 		LOG(L_ERR,"ERROR:cpl-c:rmv_from_db: error when deleting script for "
238 200
 			"user \"%s\"\n",usr);
239 201
 		return -1;
Browse code

- merge 0.9.0 latest fixes/changes: radius modules makefiles and libradiusclient/radiusclient-ng selection and various minor compile fixes

Andrei Pelinescu-Onciul authored on 30/06/2005 21:29:31
Showing 1 changed files
... ...
@@ -101,11 +101,13 @@ void cpl_db_close()
101 101
  */
102 102
 int get_user_script(str *user, str *script, const char* key)
103 103
 {
104
-	db_key_t   keys_cmp[] = {"user"};
105
-	db_key_t   keys_ret[] = { key };
104
+	db_key_t   keys_cmp[1];
105
+	db_key_t   keys_ret[1];
106 106
 	db_val_t   vals[1];
107 107
 	db_res_t   *res = 0 ;
108 108
 
109
+	keys_cmp[0]="user";
110
+	keys_ret[0]=key;
109 111
 	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
110 112
 	vals[0].type = DB_STRING;
111 113
 	vals[0].nul  = 0;
Browse code

- database capability check

Jan Janak authored on 14/09/2004 12:25:40
Showing 1 changed files
... ...
@@ -44,9 +44,17 @@ int cpl_db_bind(char* db_url)
44 44
 {
45 45
 	if (bind_dbmod(db_url, &cpl_dbf )) {
46 46
 		LOG(L_CRIT, "ERROR:cpl_db_bind: cannot bind to database module! "
47
-		"Did you forget to load a database module ?\n");
47
+		    "Did you forget to load a database module ?\n");
48 48
 		return -1;
49 49
 	}
50
+	
51
+	     /* CPL module uses all database functions */
52
+	if (!DB_CAPABILITY(cpl_dbf, DB_CAP_ALL)) {
53
+		LOG(L_CRIT, "ERROR:cpl_db_bind: Database modules does not "
54
+		    "provide all functions needed by cpl-c module\n");
55
+		return -1;
56
+	}
57
+
50 58
 	return 0;
51 59
 }
52 60
 
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:58:23
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
  *
... ...
@@ -165,7 +165,7 @@ int write_to_db(char *usr, str *xml, str *bin)
165 165
 		goto error;
166 166
 	}
167 167
 	if (res->n>1) {
168
-		LOG(L_ERR,"ERROR:cpl:write_to_db: Incosistent CPL database:"
168
+		LOG(L_ERR,"ERROR:cpl:write_to_db: Inconsistent CPL database:"
169 169
 			" %d records for user %s\n",res->n,usr);
170 170
 		goto error;
171 171
 	}
... ...
@@ -186,7 +186,7 @@ int write_to_db(char *usr, str *xml, str *bin)
186 186
 	vals[2].val.blob_val.len = bin->len;
187 187
 	/* insert or update ? */
188 188
 	if (res->n==0) {
189
-		DBG("DEBUG:cpl:write_to_db:No user %s in CPL databse->insert\n",usr);
189
+		DBG("DEBUG:cpl:write_to_db:No user %s in CPL database->insert\n",usr);
190 190
 		if (cpl_dbf.insert(db_hdl, keys, vals, 3) < 0) {
191 191
 			LOG(L_ERR,"ERROR:cpl:write_to_db: insert failed !\n");
192 192
 			goto error;
... ...
@@ -195,7 +195,7 @@ int write_to_db(char *usr, str *xml, str *bin)
195 195
 		DBG("DEBUG:cpl:write_to_db:User %s already in CPL database ->"
196 196
 			" update\n",usr);
197 197
 		if (cpl_dbf.update(db_hdl, keys, 0, vals, keys+1, vals+1, 1, 2) < 0) {
198
-			LOG(L_ERR,"ERROR:cpl:write_to_db: updare failed !\n");
198
+			LOG(L_ERR,"ERROR:cpl:write_to_db: update failed !\n");
199 199
 			goto error;
200 200
 		}
201 201
 	}
... ...
@@ -207,8 +207,8 @@ error:
207 207
 
208 208
 
209 209
 
210
-/* delete from database the entiry record for a given user - if a user has no
211
- * script, he will be removed complitly from db; users without script are not
210
+/* delete from database the entity record for a given user - if a user has no
211
+ * script, he will be removed completely from db; users without script are not
212 212
  * allowed into db ;-)
213 213
  * Returns:  1 - success
214 214
  *          -1 - error
Browse code

free_query changed to more descriptive free_result

Jan Janak authored on 04/08/2004 14:25:06
Showing 1 changed files
... ...
@@ -133,11 +133,11 @@ int get_user_script(str *user, str *script, const char* key)
133 133
 		}
134 134
 	}
135 135
 
136
-	cpl_dbf.free_query( db_hdl, res);
136
+	cpl_dbf.free_result( db_hdl, res);
137 137
 	return 1;
138 138
 error:
139 139
 	if (res)
140
-		cpl_dbf.free_query( db_hdl, res);
140
+		cpl_dbf.free_result( db_hdl, res);
141 141
 	script->s = 0;
142 142
 	script->len = 0;
143 143
 	return -1;
Browse code

- flag CPL_IS_STATEFUL is set now imediatly after the transaction is created - all global variables merged into structs cpl_env and cpl_fct - append_branches param added to lookup node - case_sensitive and realm_prefix added for building AORs - suncc warnings fixed

Bogdan-Andrei Iancu authored on 14/06/2004 17:41:20
Showing 1 changed files
... ...
@@ -91,7 +91,7 @@ void cpl_db_close()
91 91
  * Returns:  1 - success
92 92
  *          -1 - error
93 93
  */
94
-int get_user_script(str *user, str *script, char* key)
94
+int get_user_script(str *user, str *script, const char* key)
95 95
 {
96 96
 	db_key_t   keys_cmp[] = {"user"};
97 97
 	db_key_t   keys_ret[] = { key };
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,21 +24,74 @@
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  updated to the new DB api (andrei)
31
+  */
27 32
 
28 33
 #include "../../mem/shm_mem.h"
29 34
 #include "../../db/db.h"
30 35
 #include "../../dprint.h"
31 36
 #include "cpl_db.h"
32 37
 
38
+static db_con_t* db_hdl=0;
39
+static db_func_t cpl_dbf;
33 40
 
34 41
 
35 42
 
43
+int cpl_db_bind(char* db_url)
44
+{
45
+	if (bind_dbmod(db_url, &cpl_dbf )) {
46
+		LOG(L_CRIT, "ERROR:cpl_db_bind: cannot bind to database module! "
47
+		"Did you forget to load a database module ?\n");
48
+		return -1;
49
+	}
50
+	return 0;
51
+}
52
+
53
+
54
+
55
+int cpl_db_init(char* db_url, char* db_table)
56
+{
57
+	if (cpl_dbf.init==0){
58
+		LOG(L_CRIT, "BUG: cpl_db_init: unbound database module\n");
59
+		return -1;
60
+	}
61
+	db_hdl=cpl_dbf.init(db_url);
62
+	if (db_hdl==0){
63
+		LOG(L_CRIT,"ERROR:cpl_db_init: cannot initialize database "
64
+			"connection\n");
65
+		goto error;
66
+	}
67
+	if (cpl_dbf.use_table(db_hdl, db_table)<0) {
68
+		LOG(L_CRIT,"ERROR:cpl_db_init: cannot select table \"%s\"\n",db_table);
69
+		goto error;
70
+	}
71
+	return 0;
72
+error:
73
+	if (db_hdl){
74
+		cpl_dbf.close(db_hdl);
75
+		db_hdl=0;
76
+	}
77
+	return -1;
78
+}
79
+
80
+void cpl_db_close()
81
+{
82
+	if (db_hdl && cpl_dbf.close){
83
+		cpl_dbf.close(db_hdl);
84
+		db_hdl=0;
85
+	}
86
+}
87
+
88
+
36 89
 /* gets from database the cpl script in binary format; the returned script is
37 90
  * allocated in shared memory
38 91
  * Returns:  1 - success
39 92
  *          -1 - error
40 93
  */
41
-int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
94
+int get_user_script(str *user, str *script, char* key)
42 95
 {
43 96
 	db_key_t   keys_cmp[] = {"user"};
44 97
 	db_key_t   keys_ret[] = { key };
... ...
@@ -49,7 +102,8 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
49 102
 	vals[0].type = DB_STRING;
50 103
 	vals[0].nul  = 0;
51 104
 	vals[0].val.string_val = user->s;
52
-	if (db_query(db_hdl, keys_cmp, 0, vals, keys_ret, 1, 1, NULL, &res) < 0) {
105
+	if (cpl_dbf.query(db_hdl, keys_cmp, 0, vals, keys_ret, 1, 1, NULL, &res)
106
+			< 0){
53 107
 		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
54 108
 		goto error;
55 109
 	}
... ...
@@ -79,11 +133,11 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
79 133
 		}
80 134
 	}
81 135
 
82
-	db_free_query( db_hdl, res);
136
+	cpl_dbf.free_query( db_hdl, res);
83 137
 	return 1;
84 138
 error:
85 139
 	if (res)
86
-		db_free_query( db_hdl, res);
140
+		cpl_dbf.free_query( db_hdl, res);
87 141
 	script->s = 0;
88 142
 	script->len = 0;
89 143
 	return -1;
... ...
@@ -96,7 +150,7 @@ error:
96 150
  * Returns:  1 - success
97 151
  *          -1 - error
98 152
  */
99
-int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin)
153
+int write_to_db(char *usr, str *xml, str *bin)
100 154
 {
101 155
 	db_key_t   keys[] = {"user","cpl_xml","cpl_bin"};
102 156
 	db_val_t   vals[3];
... ...
@@ -106,7 +160,7 @@ int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin)
106 160
 	vals[0].type = DB_STRING;
107 161
 	vals[0].nul  = 0;
108 162
 	vals[0].val.string_val = usr;
109
-	if (db_query(db_con, keys, 0, vals, keys, 1, 1, NULL, &res) < 0) {
163
+	if (cpl_dbf.query(db_hdl, keys, 0, vals, keys, 1, 1, NULL, &res) < 0) {
110 164
 		LOG(L_ERR,"ERROR:cpl:write_to_db: db_query failed\n");
111 165
 		goto error;
112 166
 	}
... ...
@@ -133,14 +187,14 @@ int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin)
133 187
 	/* insert or update ? */
134 188
 	if (res->n==0) {
135 189
 		DBG("DEBUG:cpl:write_to_db:No user %s in CPL databse->insert\n",usr);
136
-		if (db_insert(db_con, keys, vals, 3) < 0) {
190
+		if (cpl_dbf.insert(db_hdl, keys, vals, 3) < 0) {
137 191
 			LOG(L_ERR,"ERROR:cpl:write_to_db: insert failed !\n");
138 192
 			goto error;
139 193
 		}
140 194
 	} else {
141 195
 		DBG("DEBUG:cpl:write_to_db:User %s already in CPL database ->"
142 196
 			" update\n",usr);
143
-		if (db_update(db_con, keys, 0, vals, keys+1, vals+1, 1, 2) < 0) {
197
+		if (cpl_dbf.update(db_hdl, keys, 0, vals, keys+1, vals+1, 1, 2) < 0) {
144 198
 			LOG(L_ERR,"ERROR:cpl:write_to_db: updare failed !\n");
145 199
 			goto error;
146 200
 		}
... ...
@@ -159,7 +213,7 @@ error:
159 213
  * Returns:  1 - success
160 214
  *          -1 - error
161 215
  */
162
-int rmv_from_db(db_con_t *db_con, char *usr)
216
+int rmv_from_db(char *usr)
163 217
 {
164 218
 	db_key_t   keys[] = {"user"};
165 219
 	db_val_t   vals[1];
... ...
@@ -169,7 +223,7 @@ int rmv_from_db(db_con_t *db_con, char *usr)
169 223
 	vals[0].nul  = 0;
170 224
 	vals[0].val.string_val = usr;
171 225
 
172
-	if (db_delete(db_con, keys, NULL, vals, 1) < 0) {
226
+	if (cpl_dbf.delete(db_hdl, keys, NULL, vals, 1) < 0) {
173 227
 		LOG(L_ERR,"ERROR:cpl-c:rmv_from_db: error when deleting script for "
174 228
 			"user \"%s\"\n",usr);
175 229
 		return -1;
Browse code

-tm patch updated to latest changes -support for multidomain added

Bogdan-Andrei Iancu authored on 13/11/2003 20:08:07
Showing 1 changed files
... ...
@@ -44,14 +44,7 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
44 44
 	db_key_t   keys_ret[] = { key };
45 45
 	db_val_t   vals[1];
46 46
 	db_res_t   *res = 0 ;
47
-	char       tmp;
48
-
49
-	/* it shouldn't be aproblem overwriting a \0 at the end of user name; the
50
-	 * user name is part of the sip_msg struct received -  that is allocated in
51
-	 * process private mem - no sync problems; also there is all the time some
52
-	 * extra characters after the user name - at least the EOH */
53
-	tmp = user->s[user->len];
54
-	user->s[user->len] = 0;
47
+
55 48
 	DBG("DEBUG:get_user_script: fetching script for user <%s>\n",user->s);
56 49
 	vals[0].type = DB_STRING;
57 50
 	vals[0].nul  = 0;
... ...
@@ -60,7 +53,6 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
60 53
 		LOG(L_ERR,"ERROR:cpl-c:get_user_script: db_query failed\n");
61 54
 		goto error;
62 55
 	}
63
-	user->s[user->len] = tmp;
64 56
 
65 57
 	if (res->n==0) {
66 58
 		DBG("DEBUG:get_user_script: user <%.*s> not found in db -> probably "
Browse code

- GET_CPL FIFO command added - all FIFO commands return status + comments via reply file

Bogdan-Andrei Iancu authored on 20/10/2003 15:37:29
Showing 1 changed files
... ...
@@ -79,10 +79,11 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
79 79
 			script->len = res->rows[0].values[0].val.blob_val.len;
80 80
 			script->s = shm_malloc( script->len );
81 81
 			if (!script->s) {
82
-				LOG(L_ERR,"ERROR:cpl-c:get_user_script: no more free sh_mem\n");
82
+				LOG(L_ERR,"ERROR:cpl-c:get_user_script: no free sh_mem\n");
83 83
 				goto error;
84 84
 			}
85
-			memcpy(script->s,res->rows[0].values[0].val.blob_val.s,script->len);
85
+			memcpy( script->s, res->rows[0].values[0].val.blob_val.s,
86
+				script->len);
86 87
 		}
87 88
 	}
88 89
 
Browse code

- script download via Register added

Bogdan-Andrei Iancu authored on 12/09/2003 15:38:56
Showing 1 changed files
... ...
@@ -38,10 +38,10 @@
38 38
  * Returns:  1 - success
39 39
  *          -1 - error
40 40
  */
41
-int get_user_script( db_con_t *db_hdl, str *user, str *script)
41
+int get_user_script( db_con_t *db_hdl, str *user, str *script, char* key)
42 42
 {
43 43
 	db_key_t   keys_cmp[] = {"user"};
44
-	db_key_t   keys_ret[] = {"cpl_bin"};
44
+	db_key_t   keys_ret[] = { key };
45 45
 	db_val_t   vals[1];
46 46
 	db_res_t   *res = 0 ;
47 47
 	char       tmp;
Browse code

- for user not found in db, or found with an empty script, no error will be generated anymore, but ser script will be mormally resumed. - before starting script interpretation, 100 is send back.

Bogdan-Andrei Iancu authored on 21/08/2003 11:43:21
Showing 1 changed files
... ...
@@ -32,6 +32,12 @@
32 32
 
33 33
 
34 34
 
35
+
36
+/* gets from database the cpl script in binary format; the returned script is
37
+ * allocated in shared memory
38
+ * Returns:  1 - success
39
+ *          -1 - error
40
+ */
35 41
 int get_user_script( db_con_t *db_hdl, str *user, str *script)
36 42
 {
37 43
 	db_key_t   keys_cmp[] = {"user"};
... ...
@@ -40,7 +46,7 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script)
40 46
 	db_res_t   *res = 0 ;
41 47
 	char       tmp;
42 48
 
43
-	/* it shouldn't be aproblem verwriting a \0 at the end of user name; the
49
+	/* it shouldn't be aproblem overwriting a \0 at the end of user name; the
44 50
 	 * user name is part of the sip_msg struct received -  that is allocated in
45 51
 	 * process private mem - no sync problems; also there is all the time some
46 52
 	 * extra characters after the user name - at least the EOH */
... ...
@@ -57,26 +63,27 @@ int get_user_script( db_con_t *db_hdl, str *user, str *script)
57 63
 	user->s[user->len] = tmp;
58 64
 
59 65
 	if (res->n==0) {
60
-		LOG(L_ERR,"ERROR:get_user_script: user <%.*s> not found in databse\n",
61
-			user->len, user->s);
62
-		goto error;
63
-	}
64
-
65
-	if (res->rows[0].values[0].nul) {
66
-		DBG("DEBUG:get_user_script: user <%.*s> has a NULL script\n",
67
-			user->len, user->s);
66
+		DBG("DEBUG:get_user_script: user <%.*s> not found in db -> probably "
67
+			"he has no script\n",user->len, user->s);
68 68
 		script->s = 0;
69 69
 		script->len = 0;
70 70
 	} else {
71
-		DBG("DEBUG:get_user_script: we got the script len=%d\n",
72
-			res->rows[0].values[0].val.blob_val.len);
73
-		script->len = res->rows[0].values[0].val.blob_val.len;
74
-		script->s = shm_malloc( script->len );
75
-		if (!script->s) {
76
-			LOG(L_ERR,"ERROR:cpl-c:get_user_script: no more free memory\n");
77
-			goto error;
71
+		if (res->rows[0].values[0].nul) {
72
+			DBG("DEBUG:get_user_script: user <%.*s> has a NULL script\n",
73
+				user->len, user->s);
74
+			script->s = 0;
75
+			script->len = 0;
76
+		} else {
77
+			DBG("DEBUG:get_user_script: we got the script len=%d\n",
78
+				res->rows[0].values[0].val.blob_val.len);
79
+			script->len = res->rows[0].values[0].val.blob_val.len;
80
+			script->s = shm_malloc( script->len );
81
+			if (!script->s) {
82
+				LOG(L_ERR,"ERROR:cpl-c:get_user_script: no more free sh_mem\n");
83
+				goto error;
84
+			}
85
+			memcpy(script->s,res->rows[0].values[0].val.blob_val.s,script->len);
78 86
 		}
79
-		memcpy(script->s,res->rows[0].values[0].val.blob_val.s,script->len);
80 87
 	}
81 88
 
82 89
 	db_free_query( db_hdl, res);
... ...
@@ -152,6 +159,7 @@ error:
152 159
 }
153 160
 
154 161
 
162
+
155 163
 /* delete from database the entiry record for a given user - if a user has no
156 164
  * script, he will be removed complitly from db; users without script are not
157 165
  * allowed into db ;-)
... ...
@@ -176,3 +184,4 @@ int rmv_from_db(db_con_t *db_con, char *usr)
176 184
 
177 185
 	return 1;
178 186
 }
187
+
Browse code

-fifo command added for removing CPl scripts from database

Bogdan-Andrei Iancu authored on 21/08/2003 10:50:44
Showing 1 changed files
... ...
@@ -91,6 +91,11 @@ error:
91 91
 
92 92
 
93 93
 
94
+/* inserts into database a cpl script in XML format(xml) along with its binary
95
+ * format (bin)
96
+ * Returns:  1 - success
97
+ *          -1 - error
98
+ */
94 99
 int write_to_db(db_con_t *db_con, char *usr, str *xml, str *bin)
95 100
 {
96 101
 	db_key_t   keys[] = {"user","cpl_xml","cpl_bin"};
... ...
@@ -147,3 +152,27 @@ error:
147 152
 }
148 153
 
149 154
 
155
+/* delete from database the entiry record for a given user - if a user has no
156
+ * script, he will be removed complitly from db; users without script are not
157