Browse code

- add db_check_table_version funtion to db API - this function includes error logging and also a error message on version mismatch, its require now a exact match of the version numbers - convert most of the modules to use this function, instead of implementing their own error handling again - new modules should use this function - increase trusted table version define for permissions module, it should be the same as the DB version entry - TODO: convert uri_db, domain, domainpolicy and dispatch too

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4232 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 21/05/2008 07:50:05
Showing 19 changed files
... ...
@@ -231,8 +231,7 @@ static void destroy(void)
231 231
  */
232 232
 static int auth_fixup(void** param, int param_no)
233 233
 {
234
-	db_con_t* dbh;
235
-	int ver;
234
+	db_con_t* dbh = NULL;
236 235
 	str name;
237 236
 
238 237
 	if (param_no == 1) {
... ...
@@ -246,16 +245,12 @@ static int auth_fixup(void** param, int param_no)
246 245
 			LM_ERR("unable to open database connection\n");
247 246
 			return -1;
248 247
 		}
249
-		ver = db_table_version(&auth_dbf, dbh, &name);
250
-		auth_dbf.close(dbh);
251
-		if (ver < 0) {
252
-			LM_ERR("failed to query table version\n");
253
-			return -1;
254
-		} else if (ver < TABLE_VERSION) {
255
-			LM_ERR("invalid table version (use openserdbctl reinit)\n");
248
+		if(db_check_table_version(&auth_dbf, dbh, &name, TABLE_VERSION) < 0) {
249
+			LM_ERR("error during table version check.\n");
250
+			auth_dbf.close(dbh);
256 251
 			return -1;
257 252
 		}
258 253
 	}
259
-
254
+	auth_dbf.close(dbh);
260 255
 	return 0;
261 256
 }
... ...
@@ -54,24 +54,6 @@ static char query[QUERY_LEN];
54 54
 db_func_t dbf;
55 55
 db_con_t * dbh = NULL;
56 56
 
57
-/**
58
- * Check the table version
59
- *
60
- * @return 0 means ok, -1 means an error occured
61
- */
62
-static int check_table_version(db_func_t* dbf, db_con_t* dbh, const str* table, const int version) {
63
-
64
-	int ver = db_table_version(dbf, dbh, table);
65
-	if (ver < 0) {
66
-		LM_ERR("Error while querying version for table %.*s\n", table->len, table->s);
67
-		return -1;
68
-	} else if (ver < version) {
69
-		LM_ERR("Invalid version for table %.*s found\n", table->len, table->s);
70
-		return -1;
71
-	}
72
-	return 0;
73
-}
74
-
75 57
 /**
76 58
  * Initialises the db API
77 59
  *
... ...
@@ -90,9 +72,9 @@ int db_init(void) {
90 72
 		LM_ERR("Can't connect to database.\n");
91 73
 		return -1;
92 74
 	}
93
-	if ( (check_table_version(&dbf, dbh, &db_table, ROUTE_TABLE_VER) < 0) ||
94
-		 (check_table_version(&dbf, dbh, &carrier_table, CARRIER_TABLE_VER) < 0) ||
95
-		 (check_table_version(&dbf, dbh, &db_failure_table, FAILURE_TABLE_VER) < 0) ) {
75
+	if ( (db_check_table_version(&dbf, dbh, &db_table, ROUTE_TABLE_VER) < 0) ||
76
+		 (db_check_table_version(&dbf, dbh, &carrier_table, CARRIER_TABLE_VER) < 0) ||
77
+		 (db_check_table_version(&dbf, dbh, &db_failure_table, FAILURE_TABLE_VER) < 0) ) {
96 78
 			LM_ERR("Error during table version check.\n");
97 79
 			return -1;
98 80
 	}
... ...
@@ -44,8 +44,6 @@ str cpl_bin_col  = str_init("cpl_bin");
44 44
 
45 45
 int cpl_db_bind(const str* db_url, const str *db_table)
46 46
 {
47
-	int ver;
48
-
49 47
 	if (db_bind_mod(db_url, &cpl_dbf )) {
50 48
 		LM_CRIT("cannot bind to database module! "
51 49
 		    "Did you forget to load a database module ?\n");
... ...
@@ -62,15 +60,8 @@ int cpl_db_bind(const str* db_url, const str *db_table)
62 60
 	if ( cpl_db_init( db_url, db_table) )
63 61
 		return -1;
64 62
 
65
-	ver = db_table_version(&cpl_dbf, db_hdl, db_table);
66
-	if (ver < 0) {
67
-		LM_CRIT("failed to query table version\n");
68
-		cpl_db_close();
69
-		return -1;
70
-	} else if (ver < TABLE_VERSION) {
71
-		LM_ERR("Invalid table version (%d, required %d)"
72
-			"(use openserdbctl reinit)\n",
73
-			ver, TABLE_VERSION);
63
+	if(db_check_table_version(&cpl_dbf, db_hdl, db_table, TABLE_VERSION) < 0) {
64
+		LM_ERR("error during table version check.\n");
74 65
 		cpl_db_close();
75 66
 		return -1;
76 67
 	}
... ...
@@ -118,8 +118,6 @@ int dlg_connect_db(const str *db_url)
118 118
 
119 119
 int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period)
120 120
 {
121
-	int ver;
122
-
123 121
 	/* Find a database module */
124 122
 	if (db_bind_mod(db_url, &dialog_dbf) < 0){
125 123
 		LM_ERR("Unable to bind to a database driver\n");
... ...
@@ -131,14 +129,8 @@ int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period)
131 129
 		return -1;
132 130
 	}
133 131
 
134
-	ver = db_table_version(&dialog_dbf, dialog_db_handle, &dialog_table_name);
135
-	if (ver < 0) {
136
-		LM_ERR("failed to query table version\n");
137
-		return -1;
138
-	} else if (ver != DLG_TABLE_VERSION) {
139
-		LM_ERR("Invalid table version (found %d , required %d)\n"
140
-			"(use openserdbctl reinit)\n",
141
-			ver, DLG_TABLE_VERSION );
132
+	if(db_check_table_version(&dialog_dbf, dialog_db_handle, &dialog_table_name, DLG_TABLE_VERSION) < 0) {
133
+		LM_ERR("error during table version check.\n");
142 134
 		return -1;
143 135
 	}
144 136
 
... ...
@@ -85,14 +85,11 @@ void domain_db_close(void)
85 85
 
86 86
 int domain_db_ver(str* name)
87 87
 {
88
-	int ver;
89
-
90 88
 	if (db_handle==0){
91 89
 		LM_ERR("Null database handler\n");
92 90
 		return -1;
93 91
 	}
94
-	ver=db_table_version(&domain_dbf, db_handle, name);
95
-	return ver;
92
+	return db_table_version(&domain_dbf, db_handle, name);
96 93
 }
97 94
 
98 95
 
... ...
@@ -214,8 +214,3 @@ void group_db_close(void)
214 214
 	}
215 215
 }
216 216
 
217
-
218
-int group_db_ver(str* name)
219
-{
220
-	return db_table_version( &group_dbf, group_dbh, name);
221
-}
... ...
@@ -59,6 +59,5 @@ int is_user_in(struct sip_msg* _msg, char* _hf, char* _grp);
59 59
 int group_db_init(const str* db_url);
60 60
 int group_db_bind(const str* db_url);
61 61
 void group_db_close();
62
-int group_db_ver(str* name);
63 62
 
64 63
 #endif /* GROUP_H */
... ...
@@ -176,8 +176,6 @@ static int child_init(int rank)
176 176
 
177 177
 static int mod_init(void)
178 178
 {
179
-	int ver;
180
-
181 179
 	LM_DBG("group module - initializing\n");
182 180
 
183 181
 	/* Calculate lengths */
... ...
@@ -202,28 +200,17 @@ static int mod_init(void)
202 200
 	}
203 201
 
204 202
 	/* check version for group table */
205
-	ver = group_db_ver( &table );
206
-	if (ver < 0) {
207
-		LM_ERR("failed to query table version\n");
208
-		return -1;
209
-	} else if (ver < TABLE_VERSION) {
210
-		LM_ERR("invalid table version for %s "
211
-				"(use openserdbctl reinit)\n",table.s);
212
-		return -1;
203
+	if (db_check_table_version(&group_dbf, group_dbh, &table, TABLE_VERSION) < 0) {
204
+			LM_ERR("error during group table version check.\n");
205
+			return -1;
213 206
 	}
214 207
 
215 208
 	if (re_table.len) {
216
-		/* check version for re_group table */
217
-		ver = group_db_ver( &re_table );
218
-		if (ver < 0) {
219
-			LM_ERR("failed to query table version\n");
220
-			return -1;
221
-		} else if (ver < RE_TABLE_VERSION) {
222
-			LM_ERR("invalid table version for %s "
223
-					"(use openserdbctl reinit)\n",re_table.s);
209
+		/* check version for group re_group table */
210
+		if (db_check_table_version(&group_dbf, group_dbh, &re_table, RE_TABLE_VERSION) < 0) {
211
+			LM_ERR("error during re_group table version check.\n");
224 212
 			return -1;
225 213
 		}
226
-
227 214
 		if (load_re( &re_table )!=0 ) {
228 215
 			LM_ERR("failed to load <%s> table\n", re_table.s);
229 216
 			return -1;
... ...
@@ -400,26 +400,6 @@ static void lcr_db_close(void)
400 400
 }
401 401
 
402 402
 
403
-static int lcr_db_ver(const str* db_url, str* name)
404
-{
405
-	db_con_t* dbh;
406
-	int ver;
407
-
408
-	if (lcr_dbf.init==0){
409
-		LM_CRIT("Unbound database\n");
410
-		return -1;
411
-	}
412
-	dbh=lcr_dbf.init(db_url);
413
-	if (dbh==0){
414
-		LM_ERR("Unable to open database connection\n");
415
-		return -1;
416
-	}
417
-	ver=db_table_version(&lcr_dbf, dbh, name);
418
-	lcr_dbf.close(dbh);
419
-	return ver;
420
-}
421
-
422
-
423 403
 static int mi_child_init(void)
424 404
 {
425 405
 	return lcr_db_init(&db_url);
... ...
@@ -431,10 +411,9 @@ static int mi_child_init(void)
431 411
  */
432 412
 static int mod_init(void)
433 413
 {
434
-    int ver, i;
435
-
414
+	int i;
436 415
     pv_spec_t avp_spec;
437
-	str s;
416
+    str s;
438 417
     unsigned short avp_flags;
439 418
 
440 419
     LM_DBG("Initializing\n");
... ...
@@ -581,24 +560,23 @@ static int mod_init(void)
581 560
     }
582 561
 
583 562
     /* Check table version */
584
-    ver = lcr_db_ver(&db_url, &gw_table);
585
-    if (ver < 0) {
586
-	LM_ERR("Error while querying gw table version\n");
587
-	goto err;
588
-    } else if (ver < GW_TABLE_VERSION) {
589
-	LM_ERR("Invalid table version of gw table <%d>\n", ver);
590
-	goto err;
591
-    }		
592
-
593
-    /* Check table version */
594
-    ver = lcr_db_ver(&db_url, &lcr_table);
595
-    if (ver < 0) {
596
-	LM_ERR("Error while querying lcr table version\n");
597
-	goto err;
598
-    } else if (ver < LCR_TABLE_VERSION) {
599
-	LM_ERR("Invalid table version of lcr table <%d>\n", ver);
600
-	goto err;
601
-    }		
563
+	db_con_t* dbh;
564
+	if (lcr_dbf.init==0){
565
+		LM_CRIT("Unbound database\n");
566
+		return -1;
567
+	}
568
+	dbh=lcr_dbf.init(&db_url);
569
+	if (dbh==0){
570
+		LM_ERR("Unable to open database connection\n");
571
+		return -1;
572
+	}
573
+	if((db_check_table_version(&lcr_dbf, dbh, &gw_table, GW_TABLE_VERSION) < 0) ||
574
+		(db_check_table_version(&lcr_dbf, dbh, &lcr_table, LCR_TABLE_VERSION) < 0)) {
575
+			LM_ERR("error during table version check.\n");
576
+			lcr_dbf.close(dbh);
577
+			goto err;
578
+    }
579
+	lcr_dbf.close(dbh);
602 580
 
603 581
     /* Initializing gw tables and gw table pointer variable */
604 582
     gws_1 = (struct gw_info *)shm_malloc(sizeof(struct gw_info) *
... ...
@@ -255,7 +255,6 @@ struct module_exports exports= {
255 255
 static int mod_init(void)
256 256
 {
257 257
 	pv_spec_t avp_spec;
258
-	int ver = 0;
259 258
 
260 259
 	ms_db_url.len = strlen (ms_db_url.s);
261 260
 	ms_db_table.len = strlen (ms_db_table.s);
... ...
@@ -311,12 +310,8 @@ static int mod_init(void)
311 310
 		return -1;
312 311
 	}
313 312
 
314
-	ver = db_table_version(&msilo_dbf, db_con, &ms_db_table);
315
-	if(ver!=S_TABLE_VERSION)
316
-	{
317
-		LM_ERR("wrong version v%d for table <%.*s>,"
318
-				" need v%d\n", ver, ms_db_table.len, ms_db_table.s,
319
-				S_TABLE_VERSION);
313
+	if(db_check_table_version(&msilo_dbf, db_con, &ms_db_table, S_TABLE_VERSION) < 0) {
314
+		LM_ERR("error during table version check.\n");
320 315
 		return -1;
321 316
 	}
322 317
 	if(db_con)
... ...
@@ -173,8 +173,6 @@ int reload_address_table(void)
173 173
  */
174 174
 int init_addresses(void)
175 175
 {
176
-    int ver;
177
-
178 176
     if (!db_url.s) {
179 177
 	LM_INFO("db_url parameter of permissions module not set, "
180 178
 	    "disabling allow_addr\n");
... ...
@@ -200,28 +198,22 @@ int init_addresses(void)
200 198
 		return -1;
201 199
     }
202 200
 
203
-    ver = db_table_version(&perm_dbf, db_handle, &address_table);
204
-
205
-    if (ver < 0) {
206
-	LM_ERR("failed to query table version\n");
207
-	perm_dbf.close(db_handle);
208
-	return -1;
209
-    } else if (ver < TABLE_VERSION) {
210
-	    LM_ERR("invalid table version %d - expected %d\n", ver,TABLE_VERSION);
211
-	perm_dbf.close(db_handle);
212
-	return -1;
201
+    if(db_check_table_version(&perm_dbf, db_handle, &address_table, TABLE_VERSION) < 0) {
202
+		LM_ERR("error during table version check.\n");
203
+		perm_dbf.close(db_handle);
204
+		return -1;
213 205
     }
214 206
 
215 207
     addr_hash_table_1 = new_addr_hash_table();
216 208
     if (!addr_hash_table_1) return -1;
217
-		
209
+
218 210
     addr_hash_table_2  = new_addr_hash_table();
219 211
     if (!addr_hash_table_2) goto error;
220 212
 		
221 213
     addr_hash_table = (struct addr_list ***)shm_malloc
222 214
 	(sizeof(struct addr_list **));
223 215
     if (!addr_hash_table) goto error;
224
-    
216
+
225 217
     *addr_hash_table = addr_hash_table_1;
226 218
 
227 219
     subnet_table_1 = new_subnet_table();
... ...
@@ -40,7 +40,7 @@
40 40
 #include "../../parser/parse_from.h"
41 41
 #include "../../usr_avp.h"
42 42
 
43
-#define TABLE_VERSION 3
43
+#define TABLE_VERSION 4
44 44
 
45 45
 struct trusted_list ***hash_table;     /* Pointer to current hash table pointer */
46 46
 struct trusted_list **hash_table_1;   /* Pointer to hash table 1 */
... ...
@@ -147,9 +147,7 @@ int reload_trusted_table(void)
147 147
  */
148 148
 int init_trusted(void)
149 149
 {
150
-	int ver;
151 150
 	/* Check if hash table needs to be loaded from trusted table */
152
-
153 151
 	if (!db_url.s) {
154 152
 		LM_INFO("db_url parameter of permissions module not set, "
155 153
 			"disabling allow_trusted\n");
... ...
@@ -176,15 +174,8 @@ int init_trusted(void)
176 174
 			return -1;
177 175
 		}
178 176
 
179
-		ver = db_table_version(&perm_dbf, db_handle, &trusted_table);
180
-
181
-		if (ver < 0) {
182
-			LM_ERR("failed to query table version\n");
183
-			perm_dbf.close(db_handle);
184
-			return -1;
185
-		} else if (ver < TABLE_VERSION) {
186
-			LM_ERR("invalid table version %d - expected %d "
187
-					"(use openserdbctl reinit)\n", ver,TABLE_VERSION);
177
+		if(db_check_table_version(&perm_dbf, db_handle, &trusted_table, TABLE_VERSION) < 0) {
178
+			LM_ERR("error during table version check.\n");
188 179
 			perm_dbf.close(db_handle);
189 180
 			return -1;
190 181
 		}
... ...
@@ -235,8 +226,6 @@ error:
235 226
  */
236 227
 int init_child_trusted(int rank)
237 228
 {
238
-	int ver;
239
-
240 229
 	if (!db_url.s) {
241 230
 		return 0;
242 231
 	}
... ...
@@ -249,17 +238,11 @@ int init_child_trusted(int rank)
249 238
 			return -1;
250 239
 		}
251 240
 
252
-		ver = db_table_version(&perm_dbf, db_handle, &trusted_table);
253
-
254
-		if (ver < 0) {
255
-			LM_ERR("failed to query table version\n");
256
-			perm_dbf.close(db_handle);
257
-			return -1;
258
-		} else if (ver < TABLE_VERSION) {
259
-			LM_ERR("invalid table version (use openserdbctl reinit)\n");
241
+		if(db_check_table_version(&perm_dbf, db_handle, &trusted_table, TABLE_VERSION) < 0) {
242
+			LM_ERR("error during table version check.\n");
260 243
 			perm_dbf.close(db_handle);
261 244
 			return -1;
262
-		}		
245
+		}
263 246
 
264 247
 	}
265 248
 
... ...
@@ -170,7 +170,6 @@ static int mod_init(void)
170 170
 	presentity_table.len = strlen(presentity_table.s);
171 171
 	active_watchers_table.len = strlen(active_watchers_table.s);
172 172
 	watchers_table.len = strlen(watchers_table.s);
173
-	int ver = 0;
174 173
 
175 174
 	LM_NOTICE("initializing module ...\n");
176 175
 
... ...
@@ -241,31 +240,12 @@ static int mod_init(void)
241 240
 		return -1;
242 241
 	}
243 242
 	
244
-	/*verify table version */
245
-
246
-	ver = db_table_version(&pa_dbf, pa_db, &presentity_table);
247
-	if(ver!=P_TABLE_VERSION)
248
-	{
249
-		LM_ERR("Wrong version v%d for table <%.*s>, need v%d\n", 
250
-				ver, presentity_table.len, presentity_table.s , P_TABLE_VERSION);
251
-		return -1;
252
-	}
253
-	
254
-	ver = db_table_version(&pa_dbf, pa_db, &active_watchers_table);
255
-	if(ver!=ACTWATCH_TABLE_VERSION)
256
-	{
257
-		LM_ERR("Wrong version v%d for table <%.*s>, need v%d\n", 
258
-				ver, active_watchers_table.len, active_watchers_table.s,
259
-				ACTWATCH_TABLE_VERSION);
260
-		return -1;
261
-	}
262
-
263
-	ver = db_table_version(&pa_dbf, pa_db, &watchers_table);
264
-	if(ver!=S_TABLE_VERSION)
265
-	{
266
-		LM_ERR("Wrong version v%d for table <%.*s>, need v%d\n",
267
-				ver, watchers_table.len, watchers_table.s, S_TABLE_VERSION);
268
-		return -1;
243
+	/*verify table versions */
244
+	if((db_check_table_version(&pa_dbf, pa_db, &presentity_table, P_TABLE_VERSION) < 0) ||
245
+		(db_check_table_version(&pa_dbf, pa_db, &active_watchers_table, ACTWATCH_TABLE_VERSION) < 0) ||
246
+		(db_check_table_version(&pa_dbf, pa_db, &watchers_table, S_TABLE_VERSION) < 0)) {
247
+			LM_ERR("error during table version check.\n");
248
+			return -1;
269 249
 	}
270 250
 
271 251
 	EvList= init_evlist();
... ...
@@ -123,7 +123,6 @@ struct module_exports exports= {
123 123
  */
124 124
 static int mod_init(void)
125 125
 {
126
-	int ver = 0;
127 126
 	bind_presence_t bind_presence;
128 127
 	presence_api_t pres;
129 128
 		
... ...
@@ -151,11 +150,8 @@ static int mod_init(void)
151 150
 		return -1;
152 151
 	}
153 152
 
154
-	ver = db_table_version(&pxml_dbf, pxml_db, &xcap_table);
155
-	if(ver!=S_TABLE_VERSION)
156
-	{
157
-		LM_ERR("Wrong version v%d for table <%.*s>, need v%d\n",
158
-				 ver, xcap_table.len, xcap_table.s, S_TABLE_VERSION);
153
+	if(db_check_table_version(&pxml_dbf, pxml_db, &xcap_table, S_TABLE_VERSION) < 0) {
154
+		LM_ERR("error during table version check.\n");
159 155
 		return -1;
160 156
 	}
161 157
 	/* load SL API */
... ...
@@ -143,8 +143,6 @@ struct module_exports exports= {
143 143
  */
144 144
 static int mod_init(void)
145 145
 {
146
-	int ver = 0;
147
-	
148 146
 	load_tm_f  load_tm;
149 147
 
150 148
 	LM_DBG("...\n");
... ...
@@ -192,11 +190,8 @@ static int mod_init(void)
192 190
 		return -1;
193 191
 	}
194 192
 	/* verify table version  */
195
-	ver = db_table_version(&pua_dbf, pua_db, &db_table);
196
-	if(ver!=PUA_TABLE_VERSION)
197
-	{
198
-		LM_ERR("Wrong version v%d for table <%.*s>,"
199
-				" need v%d\n", ver, db_table.len, db_table.s, PUA_TABLE_VERSION);
193
+	if(db_check_table_version(&pua_dbf, pua_db, &db_table, PUA_TABLE_VERSION) < 0) {
194
+		LM_ERR("error during table version check.\n");
200 195
 		return -1;
201 196
 	}
202 197
 
... ...
@@ -206,7 +206,6 @@ struct module_exports exports= {
206 206
  */
207 207
 static int mod_init(void)
208 208
 {
209
-	int ver = 0;
210 209
 	bind_presence_t bind_presence;
211 210
 	presence_api_t pres;
212 211
 	bind_pua_t bind_pua;
... ...
@@ -331,22 +330,12 @@ static int mod_init(void)
331 330
 		return -1;
332 331
 	}
333 332
 	/* verify table version */
334
-	 ver = db_table_version(&rls_dbf, rls_db, &rlsubs_table);
335
-	if(ver!=W_TABLE_VERSION)
336
-	{
337
-		LM_ERR("Wrong version v%d for table <%.*s>,"
338
-				" need v%d\n", ver, rlsubs_table.len, rlsubs_table.s,
339
-				W_TABLE_VERSION);
340
-		return -1;
333
+	if((db_check_table_version(&rls_dbf, rls_db, &rlsubs_table, W_TABLE_VERSION) < 0) ||
334
+		(db_check_table_version(&rls_dbf, rls_db, &rlpres_table, P_TABLE_VERSION) < 0)) {
335
+			LM_ERR("error during table version check.\n");
336
+			return -1;
341 337
 	}
342 338
 	
343
-	ver = db_table_version(&rls_dbf, rls_db, &rlpres_table);
344
-	if(ver!=P_TABLE_VERSION)
345
-	{
346
-		LM_ERR("Wrong version v%d for table <%.*s>,"
347
-				" need v%d\n", ver, rlpres_table.len, rlpres_table.s, P_TABLE_VERSION);
348
-		return -1;
349
-	}
350 339
 	if(hash_size<=1)
351 340
 		hash_size= 512;
352 341
 	else
... ...
@@ -50,25 +50,6 @@ int db_bind(const str *url)
50 50
 }
51 51
 
52 52
 
53
-/**
54
- * Check the table version
55
- *
56
- * \return 0 means ok, -1 means an error occured
57
- */
58
-static int db_check_table_version(db_func_t* dbf, db_con_t* dbh, const str* table, const int version) {
59
-
60
-	int ver = db_table_version(dbf, dbh, table);
61
-	if (ver < 0) {
62
-		LM_ERR("Error while querying version for table %.*s\n", table->len, table->s);
63
-		return -1;
64
-	} else if (ver < version) {
65
-		LM_ERR("Invalid version for table %.*s found\n", table->len, table->s);
66
-		return -1;
67
-	}
68
-	return 0;
69
-}
70
-
71
-
72 53
 int db_init(const str *url, const str *table)
73 54
 {
74 55
 	dbc = dbf.init(url);
... ...
@@ -423,7 +423,6 @@ int register_udomain(const char* _n, udomain_t** _d)
423 423
 {
424 424
 	dlist_t* d;
425 425
 	str s;
426
-	int ver;
427 426
 	db_con_t* con;
428 427
 
429 428
 	s.s = (char*)_n;
... ...
@@ -449,13 +448,8 @@ int register_udomain(const char* _n, udomain_t** _d)
449 448
 			goto err;
450 449
 		}
451 450
 
452
-		ver = db_table_version(&ul_dbf, con, &s);
453
-
454
-		if (ver < 0) {
455
-			LM_ERR("querying table version failed\n");
456
-			goto err;
457
-		} else if (ver < UL_TABLE_VERSION) {
458
-			LM_ERR("Invalid table version (use openserdbctl reinit)\n");
451
+		if(db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION) < 0) {
452
+			LM_ERR("error during table version check.\n");
459 453
 			goto err;
460 454
 		}
461 455
 		/* test if DB really exists */
... ...
@@ -121,8 +121,6 @@ struct module_exports exports= {
121 121
  */
122 122
 static int mod_init(void)
123 123
 {
124
-	int ver;
125
-
126 124
 	xcap_db_url.len = xcap_db_url.s ? strlen(xcap_db_url.s) : 0;
127 125
 	xcap_db_table.len = xcap_db_table.s ? strlen(xcap_db_table.s) : 0;
128 126
 	
... ...
@@ -146,11 +144,8 @@ static int mod_init(void)
146 144
 		return -1;
147 145
 	}
148 146
 
149
-	ver = db_table_version(&xcap_dbf, xcap_db, &xcap_db_table);
150
-	if(ver!=XCAP_TABLE_VERSION)
151
-	{
152
-		LM_ERR("Wrong version v%d for table <%.*s>, need v%d\n",
153
-				 ver, xcap_db_table.len, xcap_db_table.s, XCAP_TABLE_VERSION);
147
+	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table, XCAP_TABLE_VERSION) < 0) {
148
+		LM_ERR("error during table version check.\n");
154 149
 		return -1;
155 150
 	}
156 151