فهرست منبع

- initial version of infrastructure for autogenerating DB functions
and definitions - use 'make dbschema' to generate
- will be refined in the next weeks
- change only auth_db module to use this functions for now
- add autogenerated header to repository
- add new directory to doxygen, fix some small bug in schema makefile


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4687 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 سال پیش
والد
کامیت
53b1496ec6
2فایلهای تغییر یافته به همراه155 افزوده شده و 3 حذف شده
  1. 136 0
      lib/srdb1/module/db_uri_db.h
  2. 19 3
      lib/srdb1/schema/Makefile

+ 136 - 0
lib/srdb1/module/db_uri_db.h

@@ -0,0 +1,136 @@
+
+/*!
+ * \file
+ * \ingroup db
+ * \brief Database support for modules.
+ *
+ * Database support functions for modules.
+ *
+ * @cond
+ * WARNING:
+ * This file was autogenerated from the XML source file
+ * ../../db/module/kamailio-uri_db.xml.
+ * It can be regenerated by running 'make dbschema' in the top level
+ * directory of the source code. You need to have xsltproc and
+ * docbook-xsl stylesheets installed.
+ * ALL CHANGES DONE HERE WILL BE LOST IF THE FILE IS REGENERATED
+ * @endcond
+ */
+#ifndef db_uri_db_h
+#define db_uri_db_h
+
+
+/* necessary includes */
+#include "../../db/db.h"
+#include "../../str.h"
+
+#include <string.h>
+
+
+/* database variables */
+
+/* assign the read-only or read-write URL in mod_init */
+extern str uri_db_db_url;
+db_con_t * uri_db_dbh;
+db_func_t uri_db_dbf;
+
+str uri_table;
+
+/* column names */
+str uri_id_col;
+str uri_username_col;
+str uri_domain_col;
+str uri_uri_user_col;
+str uri_last_modified_col;
+
+/* table version */
+static const unsigned int uri_version = 1;
+
+
+/*
+ * Closes the DB connection.
+ */
+static void uri_db_db_close(void) {
+	if (uri_db_dbh) {
+		uri_db_dbf.close(uri_db_dbh);
+		uri_db_dbh = NULL;
+	}
+}
+
+
+/*!
+ * Initialises the DB API, check the table version and closes the connection.
+ * This should be called from the mod_init function.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+static int uri_db_db_init(void) {
+	if (!uri_db_db_url.s || !uri_db_db_url.len) {
+		LM_ERR("you have to set the db_url module parameter.\n");
+		return -1;
+	}
+	if (db_bind_mod(&uri_db_db_url, &uri_db_dbf) < 0) {
+		LM_ERR("can't bind database module.\n");
+		return -1;
+	}
+	if ((uri_db_dbh = uri_db_dbf.init(&uri_db_db_url)) == NULL) {
+		LM_ERR("can't connect to database.\n");
+		return -1;
+	}
+	if (
+	(db_check_table_version(&uri_db_dbf, uri_db_dbh, &uri_table, uri_version) < 0)
+	) {
+		LM_ERR("during table version check.\n");
+		uri_db_db_close();
+		return -1;
+	}
+	uri_db_db_close();
+	return 0;
+}
+
+
+/*!
+ * Initialize the DB connection without checking the table version and DB URL.
+ * This should be called from child_init. An already existing database
+ * connection will be closed, and a new one created.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+static int uri_db_db_open(void) {
+	if (uri_db_dbh) {
+		uri_db_dbf.close(uri_db_dbh);
+	}
+	if ((uri_db_dbh = uri_db_dbf.init(&uri_db_db_url)) == NULL) {
+		LM_ERR("can't connect to database.\n");
+		return -1;
+	}
+	return 0;
+}
+
+
+/*!
+ * Update the variable length after eventual assignments from the config script.
+ * This is necessary because we're using the 'str' type.
+ */
+static void uri_db_db_vars(void) {
+	if (! uri_table.s)
+		uri_table.s = "uri";
+	uri_table.len = strlen(uri_table.s);
+	if (! uri_id_col.s)
+		uri_id_col.s = "id";
+	uri_id_col.len = strlen(uri_id_col.s);
+	if (! uri_username_col.s)
+		uri_username_col.s = "username";
+	uri_username_col.len = strlen(uri_username_col.s);
+	if (! uri_domain_col.s)
+		uri_domain_col.s = "domain";
+	uri_domain_col.len = strlen(uri_domain_col.s);
+	if (! uri_uri_user_col.s)
+		uri_uri_user_col.s = "uri_user";
+	uri_uri_user_col.len = strlen(uri_uri_user_col.s);
+	if (! uri_last_modified_col.s)
+		uri_last_modified_col.s = "last_modified";
+	uri_last_modified_col.len = strlen(uri_last_modified_col.s);
+}
+
+#endif

+ 19 - 3
lib/srdb1/schema/Makefile

@@ -26,6 +26,9 @@ ORACLE_XSL = $(STYLESHEETS)/oracle.xsl
 # Stylesheet used to generate docbook documentation
 DOCBOOK_XSL = $(STYLESHEETS)/docbook.xsl
 
+# Stylesheet used to generate modules templates
+MODULES_XSL = $(STYLESHEETS)/modules.xsl
+
 # Enable/disable DTD validation
 VALIDATE = 0
 
@@ -46,7 +49,7 @@ ifeq ($(VERBOSE), 1)
 	override XSLTPROC := $(XSLTPROC) --verbose
 endif
 
-all: mysql postgres dbtext db_berkeley docbook oracle
+all: mysql postgres dbtext db_berkeley docbook oracle modules
 
 .PHONY: mysql mysql_clean
 mysql:
@@ -85,7 +88,7 @@ oracle:
 	done
 
 oracle_clean:
-	-@rm -f $(ROOT)/scripts/oracle/*
+	-@rm -f $(ROOT)/scripts/oracle/*.sql
 
 .PHONY: dbtext dbtext_clean
 dbtext:
@@ -170,6 +173,19 @@ docbook_clean:
 	-@rm -f $(ROOT)/doc/database/*.xml
 	-@rm -f $(ROOT)/doc/database/tables.sgml
 
+.PHONY: modules modules_clean
+modules:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/db/module/" \
+		--stringparam prefix "$$FILE" \
+		--stringparam db "modules" \
+		$(MODULES_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+modules_clean:
+	-@rm -f $(ROOT)/db/module/*
+
 
 .PHONY: clean
-clean: mysql_clean postgres_clean oracle_clean dbtext_clean db_berkeley_clean docbook_clean
+clean: mysql_clean postgres_clean oracle_clean dbtext_clean db_berkeley_clean docbook_clean modules_clean