Browse code

- db: fix cmp_db_id to work also with null strings

Andrei Pelinescu-Onciul authored on 10/11/2006 18:21:14
Showing 1 changed files
... ...
@@ -241,6 +241,12 @@ struct db_id* new_db_id(const char* url)
241 241
 }
242 242
 
243 243
 
244
+/* compare s1 & s2  with a function f (which should return 0 if ==);
245
+ * s1 & s2 can be null
246
+ * return 0 if match, 1 if not */
247
+#define cmpstr(s1, s2, f) \
248
+	((s1)!=(s2)) && ((s1)==0 || (s2)==0 || (f)((s1), (s2))!=0)
249
+
244 250
 /*
245 251
  * Compare two connection identifiers
246 252
  */
... ...
@@ -249,11 +255,11 @@ unsigned char cmp_db_id(struct db_id* id1, struct db_id* id2)
249 255
 	if (!id1 || !id2) return 0;
250 256
 	if (id1->port != id2->port) return 0;
251 257
 
252
-	if (strcmp(id1->scheme, id2->scheme)) return 0;
253
-	if (strcmp(id1->username, id2->username)) return 0;
254
-	if (strcmp(id1->password, id2->password)) return 0;
255
-	if (strcasecmp(id1->host, id2->host)) return 0;
256
-	if (strcmp(id1->database, id2->database)) return 0;
258
+	if (cmpstr(id1->scheme, id2->scheme, strcmp)) return 0;
259
+	if (cmpstr(id1->username, id2->username, strcmp)) return 0;
260
+	if (cmpstr(id1->password, id2->password, strcmp)) return 0;
261
+	if (cmpstr(id1->host, id2->host, strcasecmp)) return 0;
262
+	if (cmpstr(id1->database, id2->database, strcmp)) return 0;
257 263
 	return 1;
258 264
 }
259 265