Quellcode durchsuchen

domainpolicy: 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 vor 6 Jahren
Ursprung
Commit
f31dc9f008

+ 10 - 6
src/modules/domainpolicy/domainpolicy.c

@@ -252,12 +252,10 @@ void domainpolicy_db_close(void)
 /*!
  * \brief Check the database table version
  * \param db_url database URL
- * \param name table name
- * \return -1 on failure, positive database version on success
+ * \return -1 on failure, 0 on success
  */
-int domainpolicy_db_ver(const str* db_url, const str* name)
+int domainpolicy_db_ver(const str* db_url)
 {
-	int ver;
 	db1_con_t* dbh;
 
 	if (domainpolicy_dbf.init==0){
@@ -269,9 +267,15 @@ int domainpolicy_db_ver(const str* db_url, const str* name)
 		LM_CRIT("null database handler\n");
 		return -1;
 	}
-	ver=db_table_version(&domainpolicy_dbf, dbh, name);
+	if (db_check_table_version(&domainpolicy_dbf, dbh, &domainpolicy_table, DOMAINPOLICY_TABLE_VERSION) < 0) {
+		DB_TABLE_VERSION_ERROR(domainpolicy_table);
+		domainpolicy_dbf.close(dbh);
+		dbh=0;
+		return -1;
+	}
 	domainpolicy_dbf.close(dbh);
-	return ver;
+	dbh=0;
+	return 0;
 }
 
 /***************************/

+ 2 - 3
src/modules/domainpolicy/domainpolicy.h

@@ -100,10 +100,9 @@ void domainpolicy_db_close(void);
 /*!
  * \brief Check the database table version
  * \param db_url database URL
- * \param name table name
- * \return -1 on failure, positive database version on success
+ * \return -1 on failure, 0 on success
  */
-int domainpolicy_db_ver(const str* db_url, const str* name);
+int domainpolicy_db_ver(const str* db_url);
 
 
 #endif

+ 2 - 13
src/modules/domainpolicy/domainpolicy_mod.c

@@ -50,12 +50,6 @@ static int child_init(int rank);
 
 MODULE_VERSION
 
-/*!
- * Version of gw and lcr tables required by the module, increment this value
- * if you change the table in an backwards incompatible way
- */
-#define DOMAINPOLICY_TABLE_VERSION 2
-
 
 #define DOMAINPOLICY_TABLE "domainpolicy"
 #define DOMAINPOLICY_COL_RULE "rule"
@@ -151,7 +145,6 @@ struct module_exports exports = {
 static int mod_init(void)
 {
 	unsigned int par;
-	int ver;
 
 	LM_DBG("check for DB module\n");
 
@@ -163,12 +156,8 @@ static int mod_init(void)
 	}
 
 	/* Check table version */
-	ver = domainpolicy_db_ver(&db_url, &domainpolicy_table);
-	if (ver < 0) {
-		LM_ERR("failed to query table version\n");
-		return -1;
-	} else if (ver < DOMAINPOLICY_TABLE_VERSION) {
-		LM_ERR("invalid table version of domainpolicy table\n");
+	if (domainpolicy_db_ver(&db_url) < 0) {
+		LM_ERR("Error during database table version check");
 		return -1;
 	}
 

+ 7 - 0
src/modules/domainpolicy/domainpolicy_mod.h

@@ -36,6 +36,13 @@
 #include "../../core/usr_avp.h"
 
 
+/*!
+ * Version of gw and lcr tables required by the module, increment this value
+ * if you change the table in an backwards incompatible way
+ */
+#define DOMAINPOLICY_TABLE_VERSION 2
+
+
 /*
  * Module parameters variables
  */