Sfoglia il codice sorgente

uri_db: convert module to use DB_TABLE_VERSION_ERROR helper

        - convert module to use DB_TABLE_VERSION_ERROR helper
        - unify error handling (properly close database on errors, null db handle)
        - use abstract db_table_version_error function
Henning Westerholt 6 anni fa
parent
commit
8d9258aba6

+ 16 - 3
src/modules/uri_db/checks.c

@@ -376,11 +376,17 @@ void uridb_db_close(void)
 }
 
 
-int uridb_db_ver(const str* db_url, str* name)
+int uridb_db_ver(const str* db_url)
 {
 	db1_con_t* dbh;
 	int ver;
 
+	if (use_uri_table) {
+		ver = URI_TABLE_VERSION;
+	} else {
+		ver = SUBSCRIBER_TABLE_VERSION;
+	}
+
 	if (uridb_dbf.init==0){
 		LM_BUG("unbound database\n");
 		return -1;
@@ -391,7 +397,14 @@ int uridb_db_ver(const str* db_url, str* name)
 		LM_ERR("unable to open database connection\n");
 		return -1;
 	}
-	ver=db_table_version(&uridb_dbf, dbh, name);
+	if (db_check_table_version(&uridb_dbf, dbh, &db_table, ver) < 0) {
+		DB_TABLE_VERSION_ERROR(db_table);
+		uridb_dbf.close(dbh);
+		dbh=0;
+		return -1;
+	}
 	uridb_dbf.close(dbh);
-	return ver;
+	dbh=0;
+
+	return 0;
 }

+ 1 - 1
src/modules/uri_db/checks.h

@@ -58,7 +58,7 @@ int does_uri_exist(struct sip_msg* _msg, char* _table, char* _s2);
 int uridb_db_init(const str* db_url);
 int uridb_db_bind(const str* db_url);
 void uridb_db_close(void);
-int uridb_db_ver(const str* db_url, str* name);
+int uridb_db_ver(const str* db_url);
 
 int ki_check_to(struct sip_msg* _m);
 int ki_check_from(struct sip_msg* _m);

+ 2 - 25
src/modules/uri_db/uri_db.c

@@ -37,14 +37,6 @@
 
 MODULE_VERSION
 
-/*
- * Version of domain table required by the module,
- * increment this value if you change the table in
- * an backwards incompatible way. The subscriber
- * table version needs to be the same as auth_db use.
- */
-#define URI_TABLE_VERSION 1
-#define SUBSCRIBER_TABLE_VERSION 7	/* From auth_db */
 
 static void destroy(void);       /* Module destroy function */
 static int child_init(int rank); /* Per-child initialization function */
@@ -144,8 +136,6 @@ static int child_init(int rank)
  */
 static int mod_init(void)
 {
-	int ver;
-
 	if (db_url.len == 0) {
 		if (use_uri_table) {
 			LM_ERR("configuration error - no database URL, "
@@ -161,22 +151,9 @@ static int mod_init(void)
 	}
 
 	/* Check table version */
-	ver = uridb_db_ver(&db_url, &db_table);
-	if (ver < 0) {
-		LM_ERR("Error while querying table version\n");
+	if (uridb_db_ver(&db_url) < 0) {
+		LM_ERR("Error during database table version check");
 		return -1;
-	} else {
-		if (use_uri_table) {
-			if (ver != URI_TABLE_VERSION) {
-				LM_ERR("Invalid table version of the uri table. Expected %d, database is %d\n", URI_TABLE_VERSION, ver);
-				return -1;
-			}
-		} else {
-			if (ver != SUBSCRIBER_TABLE_VERSION) {
-				LM_ERR("Invalid table version of the subscriber table. Expected %d, database is %d\n", SUBSCRIBER_TABLE_VERSION, ver);
-				return -1;
-			}
-		}
 	}
 	return 0;
 }

+ 10 - 0
src/modules/uri_db/uri_db.h

@@ -28,6 +28,16 @@
 #include "../../lib/srdb1/db.h"
 #include "../../core/str.h"
 
+/*
+ * Version of domain table required by the module,
+ * increment this value if you change the table in
+ * an backwards incompatible way. The subscriber
+ * table version needs to be the same as auth_db use.
+ */
+#define URI_TABLE_VERSION 1
+#define SUBSCRIBER_TABLE_VERSION 7	/* From auth_db */
+
+
 /*
  * Module parameters variables
  */