فهرست منبع

- 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 17 سال پیش
والد
کامیت
d162a81c32
2فایلهای تغییر یافته به همراه29 افزوده شده و 1 حذف شده
  1. 16 0
      lib/srdb1/db.c
  2. 13 1
      lib/srdb1/db.h

+ 16 - 0
lib/srdb1/db.c

@@ -373,6 +373,22 @@ int db_table_version(const db_func_t* dbf, db_con_t* connection, const str* tabl
 	return ret;
 }
 
+/*
+ * Check the table version
+ * 0 means ok, -1 means an error occured
+ */
+int db_check_table_version(db_func_t* dbf, db_con_t* dbh, const str* table, const unsigned int version)
+{
+	int ver = db_table_version(dbf, dbh, table);
+	if (ver < 0) {
+		LM_ERR("querying version for table %.*s\n", table->len, table->s);
+		return -1;
+	} else if (ver != version) {
+		LM_ERR("invalid version %d for table %.*s found, espected %d\n", ver, table->len, table->s, version);
+		return -1;
+	}
+	return 0;
+}
 
 /*
  * Store name of table that will be used by

+ 13 - 1
lib/srdb1/db.h

@@ -253,7 +253,7 @@ typedef int (*db_replace_f) (const db_con_t* handle, const db_key_t* keys,
  * field.
  * \param _h structure representing database connection
  * \return returns the ID as integer or returns 0 if the previous statement
-   does not use an AUTO_INCREMENT value.
+ * does not use an AUTO_INCREMENT value.
  */
 typedef int (*db_last_inserted_id_f) (const db_con_t* _h);
 
@@ -349,6 +349,7 @@ void db_do_close(db_con_t* _h, void (*free_connection)());
  * \brief Get the version of a table.
  *
  * Returns the version number of a given table from the version table.
+ * Instead of this function you could also use db_check_table_version
  * \param dbf database module callbacks
  * \param con database connection handle
  * \param table checked table
@@ -356,6 +357,17 @@ void db_do_close(db_con_t* _h, void (*free_connection)());
  */
 int db_table_version(const db_func_t* dbf, db_con_t* con, const str* table);
 
+/**
+ * \brief Check the table version
+ *
+ * Small helper function to check the table version.
+ * \param dbf database module callbacks
+ * \param con database connection handle
+ * \param table checked table
+ * \param \version checked version
+ * \return 0 means ok, -1 means an error occured
+ */
+int db_check_table_version(db_func_t* dbf, db_con_t* dbh, const str* table, const unsigned int version);
 
 /**
  * \brief Stores the name of a table.