|
@@ -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
|