|
@@ -0,0 +1,148 @@
|
|
|
+
|
|
|
+/*!
|
|
|
+ * \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-auth_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_auth_db_h
|
|
|
+#define db_auth_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 auth_db_db_url;
|
|
|
+db_con_t * auth_db_dbh;
|
|
|
+db_func_t auth_db_dbf;
|
|
|
+
|
|
|
+str subscriber_table;
|
|
|
+
|
|
|
+/* column names */
|
|
|
+str subscriber_id_col;
|
|
|
+str subscriber_username_col;
|
|
|
+str subscriber_domain_col;
|
|
|
+str subscriber_password_col;
|
|
|
+str subscriber_email_address_col;
|
|
|
+str subscriber_ha1_col;
|
|
|
+str subscriber_ha1b_col;
|
|
|
+str subscriber_rpid_col;
|
|
|
+
|
|
|
+/* table version */
|
|
|
+static const unsigned int subscriber_version = 6;
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ * Closes the DB connection.
|
|
|
+ */
|
|
|
+static void auth_db_db_close(void) {
|
|
|
+ if (auth_db_dbh) {
|
|
|
+ auth_db_dbf.close(auth_db_dbh);
|
|
|
+ auth_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 auth_db_db_init(void) {
|
|
|
+ if (!auth_db_db_url.s || !auth_db_db_url.len) {
|
|
|
+ LM_ERR("you have to set the db_url module parameter.\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (db_bind_mod(&auth_db_db_url, &auth_db_dbf) < 0) {
|
|
|
+ LM_ERR("can't bind database module.\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if ((auth_db_dbh = auth_db_dbf.init(&auth_db_db_url)) == NULL) {
|
|
|
+ LM_ERR("can't connect to database.\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (
|
|
|
+ (db_check_table_version(&auth_db_dbf, auth_db_dbh, &subscriber_table, subscriber_version) < 0)
|
|
|
+ ) {
|
|
|
+ LM_ERR("during table version check.\n");
|
|
|
+ auth_db_db_close();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ auth_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 auth_db_db_open(void) {
|
|
|
+ if (auth_db_dbh) {
|
|
|
+ auth_db_dbf.close(auth_db_dbh);
|
|
|
+ }
|
|
|
+ if ((auth_db_dbh = auth_db_dbf.init(&auth_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 auth_db_db_vars(void) {
|
|
|
+ if (! subscriber_table.s)
|
|
|
+ subscriber_table.s = "subscriber";
|
|
|
+ subscriber_table.len = strlen(subscriber_table.s);
|
|
|
+ if (! subscriber_id_col.s)
|
|
|
+ subscriber_id_col.s = "id";
|
|
|
+ subscriber_id_col.len = strlen(subscriber_id_col.s);
|
|
|
+ if (! subscriber_username_col.s)
|
|
|
+ subscriber_username_col.s = "username";
|
|
|
+ subscriber_username_col.len = strlen(subscriber_username_col.s);
|
|
|
+ if (! subscriber_domain_col.s)
|
|
|
+ subscriber_domain_col.s = "domain";
|
|
|
+ subscriber_domain_col.len = strlen(subscriber_domain_col.s);
|
|
|
+ if (! subscriber_password_col.s)
|
|
|
+ subscriber_password_col.s = "password";
|
|
|
+ subscriber_password_col.len = strlen(subscriber_password_col.s);
|
|
|
+ if (! subscriber_email_address_col.s)
|
|
|
+ subscriber_email_address_col.s = "email_address";
|
|
|
+ subscriber_email_address_col.len = strlen(subscriber_email_address_col.s);
|
|
|
+ if (! subscriber_ha1_col.s)
|
|
|
+ subscriber_ha1_col.s = "ha1";
|
|
|
+ subscriber_ha1_col.len = strlen(subscriber_ha1_col.s);
|
|
|
+ if (! subscriber_ha1b_col.s)
|
|
|
+ subscriber_ha1b_col.s = "ha1b";
|
|
|
+ subscriber_ha1b_col.len = strlen(subscriber_ha1b_col.s);
|
|
|
+ if (! subscriber_rpid_col.s)
|
|
|
+ subscriber_rpid_col.s = "rpid";
|
|
|
+ subscriber_rpid_col.len = strlen(subscriber_rpid_col.s);
|
|
|
+}
|
|
|
+
|
|
|
+#endif
|