Browse code

Tests for return value of db.use_table functions added

Jan Janak authored on 16/06/2004 14:20:12
Showing 16 changed files
... ...
@@ -534,11 +534,16 @@ int acc_db_request( struct sip_msg *rq, struct hdr_field *to,
534 534
 	VAL_NULL(vals+i)=0;
535 535
 	VAL_STRING(vals+i)=time_s;
536 536
 
537
-	acc_dbf.use_table(db_handle, table);
537
+	if (acc_dbf.use_table(db_handle, table) < 0) {
538
+		LOG(L_ERR, "ERROR: acc_request: "
539
+		           "Error in use_table\n");
540
+		return -1;
541
+	}
542
+	
538 543
 	if (acc_dbf.insert(db_handle, keys, vals, i+1) < 0) {
539 544
 		LOG(L_ERR, "ERROR: acc_request: "
540 545
 				"Error while inserting to database\n");
541
-		return -1;;
546
+		return -1;
542 547
 	}
543 548
 
544 549
 	return 1;
... ...
@@ -80,7 +80,11 @@ static inline int get_ha1(struct username* _username, str* _domain, char* _table
80 80
 
81 81
 	n = (use_domain ? 2 : 1);
82 82
 	nc = (use_rpid ? 2 : 1);
83
-	auth_dbf.use_table(db_handle, _table);
83
+	if (auth_dbf.use_table(db_handle, _table) < 0) {
84
+		LOG(L_ERR, "get_ha1(): Error in use_table\n");
85
+		return -1;
86
+	}
87
+
84 88
 	if (auth_dbf.query(db_handle, keys, 0, vals, col, n, nc, 0, &res) < 0) {
85 89
 		LOG(L_ERR, "get_ha1(): Error while querying database\n");
86 90
 		return -1;
... ...
@@ -178,7 +178,11 @@ int is_user_in(struct sip_msg* _msg, char* _hf, char* _grp)
178 178
 
179 179
 	VAL_STR(vals + 1) = *((str*)_grp);
180 180
 	
181
-	group_dbf.use_table(db_handle, table.s);
181
+	if (group_dbf.use_table(db_handle, table.s) < 0) {
182
+		LOG(L_ERR, "is_user_in(): Error in use_table\n");
183
+		return -5;
184
+	}
185
+
182 186
 	if (group_dbf.query(db_handle, keys, 0, vals, col, (use_domain) ? (3): (2),
183 187
 				1, 0, &res) < 0) {
184 188
 		LOG(L_ERR, "is_user_in(): Error while querying database\n");
... ...
@@ -261,7 +261,10 @@ static int mod_init(void)
261 261
 		}
262 262
 		else
263 263
 		{
264
-			jabber_dbf.use_table(db_con[i], db_table);
264
+			if (jabber_dbf.use_table(db_con[i], db_table) < 0) {
265
+				LOG(L_ERR, "XJAB:mod_init: Error in use_table\n");
266
+				return -1;
267
+			}
265 268
 			DBG("XJAB:mod_init: Database connection opened successfuly\n");
266 269
 		}
267 270
 	}
... ...
@@ -250,7 +250,11 @@ static int child_init(int rank)
250 250
 	}
251 251
 	else
252 252
 	{
253
-		msilo_dbf.use_table(db_con, db_table);
253
+		if (msilo_dbf.use_table(db_con, db_table) < 0) {
254
+			LOG(L_ERR, "MSILO: child %d: Error in use_table\n");
255
+			return -1;
256
+		}
257
+		
254 258
 		DBG("MSILO: child %d: Database connection opened successfully\n", rank);
255 259
 	}
256 260
 	return 0;
... ...
@@ -247,11 +247,15 @@ int pa_location_init(void)
247 247
 	  result_cols[room_col = n_result_cols++] = "room";
248 248
 	  result_cols[placeid_col = n_result_cols++] = "placeid";
249 249
 
250
-	  pa_dbf.use_table(pa_db, place_table);
250
+	  if (pa_dbf.use_table(pa_db, place_table) < 0) {
251
+		  LOG(L_ERR, "pa_location_init: Error in use_table\n");
252
+		  return -1;
253
+	  }
254
+
251 255
 	  if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
252 256
 			result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {
253
-	       LOG(L_ERR, "db_new_tuple(): Error while querying tuple\n");
254
-	       return -1;
257
+		  LOG(L_ERR, "pa_location_init: Error while querying tuple\n");
258
+		  return -1;
255 259
 	  }
256 260
 	  LOG(L_ERR, "pa_location_init: res=%p res->n=%d\n", res, res->n);
257 261
 	  if (res && res->n > 0) {
... ...
@@ -173,11 +173,15 @@ int new_presentity(struct pdomain *pdomain, str* _uri, presentity_t** _p)
173 173
 
174 174
 	  result_cols[presid_col = n_result_cols++] = "presid";
175 175
 
176
-	  pa_dbf.use_table(pa_db, presentity_table);
176
+	  if (pa_dbf.use_table(pa_db, presentity_table) < 0) {
177
+		  LOG(L_ERR, "new_presentity: Error in use_table\n");
178
+		  return -1;
179
+	  }
180
+
177 181
 	  while (!presid) {
178 182
 	       if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
179 183
 			     result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {
180
-		    LOG(L_ERR, "db_new_tuple(): Error while querying presentity\n");
184
+		    LOG(L_ERR, "new_presentity: Error while querying presentity\n");
181 185
 		    return -1;
182 186
 	       }
183 187
 	       if (res && res->n > 0) {
... ...
@@ -190,10 +194,10 @@ int new_presentity(struct pdomain *pdomain, str* _uri, presentity_t** _p)
190 194
 
191 195
 	       } else {
192 196
 		    /* insert new record into database */
193
-		    LOG(L_INFO, "new_tuple: inserting %d cols into table\n", n_query_cols);
197
+		    LOG(L_INFO, "new_presentity: inserting %d cols into table\n", n_query_cols);
194 198
 		    if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols)
195 199
 					< 0) {
196
-			 LOG(L_ERR, "db_new_tuple(): Error while inserting tuple\n");
200
+			 LOG(L_ERR, "new_presentity: Error while inserting tuple\n");
197 201
 			 return -1;
198 202
 		    }
199 203
 	       }
... ...
@@ -282,10 +286,13 @@ int db_update_presentity(presentity_t* _p)
282 286
 	       {
283 287
 		    int n_query_cols = 2;
284 288
 		    LOG(L_INFO, "db_update_presentity: cleaning contact from table\n");
285
-		    pa_dbf.use_table(pa_db, presentity_contact_table);
289
+		    if (pa_dbf.use_table(pa_db, presentity_contact_table) < 0) {
290
+			    LOG(L_ERR, "db_update_presentity: Error in use_table\n");
291
+			    return -1;
292
+		    }
286 293
 		    if (pa_dbf.delete(pa_db, query_cols, query_ops, query_vals,
287
-						n_query_cols) < 0) {
288
-			 LOG(L_ERR, "db_new_tuple(): Error while deleting tuple\n");
294
+				      n_query_cols) < 0) {
295
+			 LOG(L_ERR, "db_update_presentity: Error while deleting tuple\n");
289 296
 			 return -1;
290 297
 		    }
291 298
 		    if (tuple->state == PS_OFFLINE)
... ...
@@ -390,7 +397,11 @@ int db_update_presentity(presentity_t* _p)
390 397
 					"dbf.update=%p\n", 
391 398
 			n_selectors, n_updates, pa_dbf.update);
392 399
 
393
-	       pa_dbf.use_table(pa_db, presentity_contact_table);
400
+	       if (pa_dbf.use_table(pa_db, presentity_contact_table) < 0) {
401
+		       LOG(L_ERR, "db_update_presentity: Error in use_table\n");
402
+		       return -1;
403
+	       }
404
+
394 405
 	       if (pa_dbf.insert(pa_db, query_cols, query_vals, n_updates) < 0) {
395 406
 		    LOG(L_ERR, "db_update_presentity: Error while updating database\n");
396 407
 		    return -1;
... ...
@@ -902,10 +913,14 @@ int pdomain_load_presentities(pdomain_t *pdomain)
902 913
 	  result_cols[uri_col = n_result_cols++] = "uri";
903 914
 	  result_cols[presid_col = n_result_cols++] = "presid";
904 915
 
905
-	  pa_dbf.use_table(pa_db, presentity_table);
916
+	  if (pa_dbf.use_table(pa_db, presentity_table) < 0) {
917
+		  LOG(L_ERR, "pdomain_load_presentities: Error in use_table\n");
918
+		  return -1;
919
+	  }
920
+
906 921
 	  if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
907 922
 			result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {
908
-	       LOG(L_ERR, "db_new_tuple(): Error while querying presentity\n");
923
+	       LOG(L_ERR, "pdomain_load_presentities: Error while querying presentity\n");
909 924
 	       return -1;
910 925
 	  }
911 926
 	  if (res) {
... ...
@@ -244,7 +244,7 @@ int new_watcher(presentity_t *_p, str* _uri, time_t _e, int event_package, docty
244 244
 	  int s_id_col, status_col, display_name_col, event_col;
245 245
 	  char *package = event_package_name[watcher->event_package];
246 246
 
247
-	  LOG(L_ERR, "db_new_watcher starting\n");
247
+	  LOG(L_ERR, "new_watcher starting\n");
248 248
 	  query_cols[n_query_cols] = "r_uri";
249 249
 	  query_ops[n_query_cols] = OP_EQ;
250 250
 	  query_vals[n_query_cols].type = DB_STR;
... ...
@@ -252,7 +252,7 @@ int new_watcher(presentity_t *_p, str* _uri, time_t _e, int event_package, docty
252 252
 	  query_vals[n_query_cols].val.str_val.s = _p->uri.s;
253 253
 	  query_vals[n_query_cols].val.str_val.len = _p->uri.len;
254 254
 	  n_query_cols++;
255
-	  LOG(L_ERR, "db_new_watcher:  _p->uri=%.*s\n", _p->uri.len, _p->uri.s);
255
+	  LOG(L_ERR, "new_watcher:  _p->uri=%.*s\n", _p->uri.len, _p->uri.s);
256 256
 
257 257
 	  query_cols[n_query_cols] = "w_uri";
258 258
 	  query_ops[n_query_cols] = OP_EQ;
... ...
@@ -271,18 +271,22 @@ int new_watcher(presentity_t *_p, str* _uri, time_t _e, int event_package, docty
271 271
 	  query_vals[n_query_cols].val.str_val.s = package;
272 272
 	  query_vals[n_query_cols].val.str_val.len = strlen(package);
273 273
 	  n_query_cols++;
274
-	  LOG(L_ERR, "db_new_watcher:  watcher->package=%s\n", package);
274
+	  LOG(L_ERR, "new_watcher:  watcher->package=%s\n", package);
275 275
 
276 276
 	  result_cols[s_id_col = n_result_cols++] = "s_id";
277 277
 	  result_cols[status_col = n_result_cols++] = "status";
278 278
 	  result_cols[event_col = n_result_cols++] = "event";
279 279
 	  result_cols[display_name_col = n_result_cols++] = "display_name";
280 280
 		
281
-	  pa_dbf.use_table(pa_db, watcherinfo_table);
281
+	  if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {
282
+		  LOG(L_ERR, "new_watcher: Error in use_table\n");
283
+		  return -1;
284
+	  }
285
+	  
282 286
 	  if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
283 287
 			result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {
284
-	       LOG(L_ERR, "new_watcher(): Error while querying tuple\n");
285
-	       return -1;
288
+		  LOG(L_ERR, "new_watcher: Error while querying tuple\n");
289
+		  return -1;
286 290
 	  }
287 291
 	  LOG(L_INFO, "new_watcher: getting values: res=%p res->n=%d\n",
288 292
 	      res, (res ? res->n : 0));
... ...
@@ -368,10 +372,10 @@ int new_watcher(presentity_t *_p, str* _uri, time_t _e, int event_package, docty
368 372
 	       n_query_cols++;
369 373
 
370 374
 	       /* insert new record into database */
371
-	       LOG(L_INFO, "new_tuple: inserting %d cols into table\n", n_query_cols);
375
+	       LOG(L_INFO, "new_watcher: inserting %d cols into table\n", n_query_cols);
372 376
 	       if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols)
373 377
 				   < 0) {
374
-		    LOG(L_ERR, "db_new_tuple(): Error while inserting tuple\n");
378
+		    LOG(L_ERR, "new_watcher: Error while inserting tuple\n");
375 379
 		    return -1;
376 380
 	       }
377 381
 	  }
... ...
@@ -416,7 +420,11 @@ int db_read_watcherinfo(presentity_t *_p)
416 420
 	  result_cols[expires_col = n_result_cols++] = "expires";
417 421
 	  result_cols[watcher_event_col = n_result_cols++] = "event";
418 422
 		
419
-	  pa_dbf.use_table(pa_db, watcherinfo_table);
423
+	  if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {
424
+		  LOG(L_ERR, "db_read_watcherinfo: Error in use_table\n");
425
+		  return -1;
426
+	  }
427
+
420 428
 	  if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
421 429
 			result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {
422 430
 	       LOG(L_ERR, "db_read_watcherinfo(): Error while querying watcherinfo\n");
... ...
@@ -267,7 +267,10 @@ static int mod_init(void)
267 267
 	}
268 268
 	else
269 269
 	{
270
-		pdt_dbf.use_table(db_con, db_table);
270
+		if (pdt_dbf.use_table(db_con, db_table) < 0) {
271
+			LOG(L_ERR, "PDT: mod_init: Error in use_table\n");
272
+			goto error1;
273
+		}
271 274
 		DBG("PDT: mod_init: Database connection opened successfully\n");
272 275
 	}
273 276
 	
... ...
@@ -362,8 +365,11 @@ static int mod_child_init(int r)
362 365
 	}
363 366
 	else
364 367
 	{
365
-	  pdt_dbf.use_table(db_con, db_table);
366
-	  DBG("PDT:child %d: Database connection opened successfuly\n",r);
368
+		if (pdt_dbf.use_table(db_con, db_table) < 0) {
369
+			LOG(L_ERR, "PDT:child %d: Error in use_table\n", r);
370
+			return -1;
371
+		}
372
+		DBG("PDT:child %d: Database connection opened successfuly\n",r);
367 373
 	}
368 374
 	return 0;
369 375
 }
... ...
@@ -115,6 +115,7 @@ static inline int check_username(struct sip_msg* _m, str* _uri)
115 115
 		if (uridb_dbf.use_table(db_handle, uri_table.s) < 0) {
116 116
 			LOG(L_ERR, "ERROR: check_username(): "
117 117
 					"Error while trying to use uri table\n");
118
+			return -7;
118 119
 		}
119 120
 
120 121
 		keys[0] = uri_user_col.s;
... ...
@@ -133,7 +134,7 @@ static inline int check_username(struct sip_msg* _m, str* _uri)
133 134
 		{
134 135
 			LOG(L_ERR, "ERROR: check_username():"
135 136
 					" Error while querying database\n");
136
-			return -7;
137
+			return -8;
137 138
 		}
138 139
 
139 140
 		     /* If the previous function returns at least one row, it means
... ...
@@ -144,7 +145,7 @@ static inline int check_username(struct sip_msg* _m, str* _uri)
144 145
 			DBG("check_username(): From/To user '%.*s' is spoofed\n", 
145 146
 			    puri.user.len, ZSW(puri.user.s));
146 147
 			uridb_dbf.free_query(db_handle, res);
147
-			return -8;
148
+			return -9;
148 149
 		} else {
149 150
 			DBG("check_username(): From/To user '%.*s' and auth user match\n", 
150 151
 			    puri.user.len, ZSW(puri.user.s));
... ...
@@ -163,7 +164,7 @@ static inline int check_username(struct sip_msg* _m, str* _uri)
163 164
 		}
164 165
 	
165 166
 		DBG("check_username(): Digest username and URI username do NOT match\n");
166
-		return -9;
167
+		return -10;
167 168
 	}
168 169
 }
169 170
 
... ...
@@ -214,6 +215,7 @@ int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
214 215
 		if (uridb_dbf.use_table(db_handle, uri_table.s) < 0) {
215 216
 			LOG(L_ERR, "ERROR: does_uri_exist(): "
216 217
 					"Error while trying to use uri table\n");
218
+			return -2;
217 219
 		}
218 220
 		keys[0] = uri_uriuser_col.s;
219 221
 		keys[1] = uri_domain_col.s;
... ...
@@ -222,6 +224,7 @@ int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
222 224
 		if (uridb_dbf.use_table(db_handle, subscriber_table.s) < 0) {
223 225
 			LOG(L_ERR, "ERROR: does_uri_exist():"
224 226
 					" Error while trying to use subscriber table\n");
227
+			return -3;
225 228
 		}
226 229
 		keys[0] = subscriber_user_col.s;
227 230
 		keys[1] = subscriber_domain_col.s;
... ...
@@ -236,13 +239,13 @@ int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
236 239
 	if (uridb_dbf.query(db_handle, keys, 0, vals, cols, (use_domain ? 2 : 1),
237 240
 				1, 0, &res) < 0) {
238 241
 		LOG(L_ERR, "does_uri_exist(): Error while querying database\n");
239
-		return -2;
242
+		return -4;
240 243
 	}
241 244
 	
242 245
 	if (RES_ROW_N(res) == 0) {
243 246
 		DBG("does_uri_exit(): User in request uri does not exist\n");
244 247
 		uridb_dbf.free_query(db_handle, res);
245
-		return -3;
248
+		return -5;
246 249
 	} else {
247 250
 		DBG("does_uri_exit(): User in request uri does exist\n");
248 251
 		uridb_dbf.free_query(db_handle, res);
... ...
@@ -74,7 +74,10 @@ int process_del_list(str* _d)
74 74
 	     /* FIXME */
75 75
 		memcpy(b, _d->s, _d->len);
76 76
 		b[_d->len] = '\0';
77
-		ul_dbf.use_table(ul_dbh, b);
77
+		if (ul_dbf.use_table(ul_dbh, b) < 0) {
78
+			LOG(L_ERR, "process_del_list(): Error in use_table\n");
79
+			return -1;
80
+		}
78 81
 	
79 82
 		VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
80 83
 		VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
... ...
@@ -91,7 +91,10 @@ int process_ins_list(str* _d)
91 91
 	     /* FIXME */
92 92
 		memcpy(b, _d->s, _d->len);
93 93
 		b[_d->len] = '\0';
94
-		ul_dbf.use_table(ul_dbh, b);
94
+		if (ul_dbf.use_table(ul_dbh, b) < 0) {
95
+			LOG(L_ERR, "process_ins_list: Error in use_table\n");
96
+			return -1;
97
+		}
95 98
 	
96 99
 		VAL_TYPE(vals) = DB_STR;
97 100
 		VAL_TYPE(vals + 1) = DB_STR;
... ...
@@ -500,7 +500,10 @@ int db_insert_ucontact(ucontact_t* _c)
500 500
 	     /* FIXME */
501 501
 	memcpy(b, _c->domain->s, _c->domain->len);
502 502
 	b[_c->domain->len] = '\0';
503
-	ul_dbf.use_table(ul_dbh, b);
503
+	if (ul_dbf.use_table(ul_dbh, b) < 0) {
504
+		LOG(L_ERR, "db_insert_ucontact(): Error in use_table\n");
505
+		return -1;
506
+	}
504 507
 
505 508
 	if (ul_dbf.insert(ul_dbh, keys, vals, (use_domain) ? (10) : (9)) < 0) {
506 509
 		LOG(L_ERR, "db_insert_ucontact(): Error while inserting contact\n");
... ...
@@ -589,7 +592,10 @@ int db_update_ucontact(ucontact_t* _c)
589 592
 	     /* FIXME */
590 593
 	memcpy(b, _c->domain->s, _c->domain->len);
591 594
 	b[_c->domain->len] = '\0';
592
-	ul_dbf.use_table(ul_dbh, b);
595
+	if (ul_dbf.use_table(ul_dbh, b) < 0) {
596
+		LOG(L_ERR, "db_upd_ucontact(): Error in use_table\n");
597
+		return -1;
598
+	}
593 599
 
594 600
 	if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, (use_domain) ? (3) : (2), 7) < 0) {
595 601
 		LOG(L_ERR, "db_upd_ucontact(): Error while updating database\n");
... ...
@@ -635,7 +641,10 @@ int db_delete_ucontact(ucontact_t* _c)
635 641
 	     /* FIXME */
636 642
 	memcpy(b, _c->domain->s, _c->domain->len);
637 643
 	b[_c->domain->len] = '\0';
638
-	ul_dbf.use_table(ul_dbh, b);
644
+	if (ul_dbf.use_table(ul_dbh, b) < 0) {
645
+		LOG(L_ERR, "db_del_ucontact: Error in use_table\n");
646
+		return -1;
647
+	}
639 648
 
640 649
 	if (ul_dbf.delete(ul_dbh, keys, 0, vals, (use_domain) ? (3) : (2)) < 0) {
641 650
 		LOG(L_ERR, "db_del_ucontact(): Error while deleting from database\n");
... ...
@@ -232,7 +232,12 @@ int preload_udomain(db_con_t* _c, udomain_t* _d)
232 232
 	
233 233
 	memcpy(b, _d->name->s, _d->name->len);
234 234
 	b[_d->name->len] = '\0';
235
-	ul_dbf.use_table(_c, b);
235
+
236
+	if (ul_dbf.use_table(_c, b) < 0) {
237
+		LOG(L_ERR, "preload_udomain(): Error in use_table\n");
238
+		return -1;
239
+	}
240
+
236 241
 	if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain) ? (10) : (9), 0,
237 242
 				&res) < 0) {
238 243
 		LOG(L_ERR, "preload_udomain(): Error while doing db_query\n");
... ...
@@ -465,7 +465,11 @@ int db_delete_urecord(urecord_t* _r)
465 465
 	     /* FIXME */
466 466
 	memcpy(b, _r->domain->s, _r->domain->len);
467 467
 	b[_r->domain->len] = '\0';
468
-	ul_dbf.use_table(ul_dbh, b);
468
+	if (ul_dbf.use_table(ul_dbh, b) < 0) {
469
+		LOG(L_ERR, "ERROR: db_delete_urecord():"
470
+		                " Error in use_table\n");
471
+		return -1;
472
+	}
469 473
 
470 474
 	if (ul_dbf.delete(ul_dbh, keys, 0, vals, (use_domain) ? (2) : (1)) < 0) {
471 475
 		LOG(L_ERR, "ERROR: db_delete_urecord():"
... ...
@@ -314,7 +314,11 @@ static int vm_get_user_info( str* user,   /*[in]*/
314 314
 	VAL_NULL(&vals[1]) = 0;
315 315
 	VAL_STR(&vals[1])  = *host;
316 316
 
317
-	vm_dbf.use_table(db_handle, subscriber_table);
317
+	if (vm_dbf.use_table(db_handle, subscriber_table) < 0) {
318
+		LOG(L_ERR, "ERROR: vm: get_user_info: Error in use_table\n");
319
+		goto error;
320
+	}
321
+
318 322
 	if (vm_dbf.query(db_handle, keys, 0, vals, cols, (use_domain ? 2 : 1),
319 323
 				1, 0, &email_res))
320 324
 	{