2
0
Эх сурвалжийг харах

Merge commit 'kam/trunk'

* commit 'kam/trunk': (219 commits)
  - add one debug probe for SQL NULL values, like for the other datatypes
  * Hostname of gateway should default to NULL.
  - new column to dispatcher table to hold priority
  * Introduced optional aliveness checking of gateways.  Contributed by
  - partial revert of commit rev5359 for db_mysql module
  - remove obselete DB example directory, the Makefile don't work and the source
  - prevent problems when a DB modules (like db_postgres) first calls
  - small indention fix
  - revert commit rev5415
  - move one DBG probe to the beginning of the free, to catch later problems
  - add group functionality to read content from specified sections
  - port from opensips, commit 4977, 4988, credits to Dan Pascu
  - port from opensips, commit 4889
  - port from opensips, commit 4990, credits to Dan Pascu
  - unify common rows and row allocation functionality in the DB API core
  - change behaviour of db_str2val, this now copy strings
  - avoid potential read overflow on non NULL terminated string
  - move db_mysql and db_unixodbc str2val implementation to the DB core,
  - fix a bunch of doxygen errors (mostly in modules, some in the core)
  - finish refactoring of carrierroute module
  ...
Jan Janak 16 жил өмнө
parent
commit
f3bcff01b2
93 өөрчлөгдсөн 8162 нэмэгдсэн , 0 устгасан
  1. 7 0
      lib/srdb1/README
  2. 428 0
      lib/srdb1/db.c
  3. 402 0
      lib/srdb1/db.h
  4. 69 0
      lib/srdb1/db_cap.h
  5. 52 0
      lib/srdb1/db_con.h
  6. 295 0
      lib/srdb1/db_id.c
  7. 70 0
      lib/srdb1/db_id.h
  8. 43 0
      lib/srdb1/db_key.h
  9. 53 0
      lib/srdb1/db_op.h
  10. 122 0
      lib/srdb1/db_pool.c
  11. 83 0
      lib/srdb1/db_pool.h
  12. 322 0
      lib/srdb1/db_query.c
  13. 187 0
      lib/srdb1/db_query.h
  14. 186 0
      lib/srdb1/db_res.c
  15. 131 0
      lib/srdb1/db_res.h
  16. 126 0
      lib/srdb1/db_row.c
  17. 76 0
      lib/srdb1/db_row.h
  18. 374 0
      lib/srdb1/db_ut.c
  19. 209 0
      lib/srdb1/db_ut.h
  20. 267 0
      lib/srdb1/db_val.c
  21. 198 0
      lib/srdb1/db_val.h
  22. 221 0
      lib/srdb1/schema/Makefile
  23. 88 0
      lib/srdb1/schema/acc.xml
  24. 59 0
      lib/srdb1/schema/address.xml
  25. 163 0
      lib/srdb1/schema/aliases.xml
  26. 39 0
      lib/srdb1/schema/carrier_name.xml
  27. 112 0
      lib/srdb1/schema/carrierfailureroute.xml
  28. 144 0
      lib/srdb1/schema/carrierroute.xml
  29. 62 0
      lib/srdb1/schema/cpl.xml
  30. 75 0
      lib/srdb1/schema/dbaliases.xml
  31. 174 0
      lib/srdb1/schema/dialog.xml
  32. 85 0
      lib/srdb1/schema/dialplan.xml
  33. 69 0
      lib/srdb1/schema/dispatcher.xml
  34. 51 0
      lib/srdb1/schema/domain.xml
  35. 39 0
      lib/srdb1/schema/domain_name.xml
  36. 80 0
      lib/srdb1/schema/domainpolicy.xml
  37. 28 0
      lib/srdb1/schema/entities.xml
  38. 58 0
      lib/srdb1/schema/globalblacklist.xml
  39. 72 0
      lib/srdb1/schema/grp.xml
  40. 128 0
      lib/srdb1/schema/gw.xml
  41. 59 0
      lib/srdb1/schema/htable.xml
  42. 67 0
      lib/srdb1/schema/imc_members.xml
  43. 58 0
      lib/srdb1/schema/imc_rooms.xml
  44. 14 0
      lib/srdb1/schema/kamailio-acc.xml
  45. 12 0
      lib/srdb1/schema/kamailio-alias_db.xml
  46. 12 0
      lib/srdb1/schema/kamailio-auth_db.xml
  47. 12 0
      lib/srdb1/schema/kamailio-avpops.xml
  48. 16 0
      lib/srdb1/schema/kamailio-carrierroute.xml
  49. 12 0
      lib/srdb1/schema/kamailio-cpl.xml
  50. 12 0
      lib/srdb1/schema/kamailio-dialog.xml
  51. 13 0
      lib/srdb1/schema/kamailio-dialplan.xml
  52. 12 0
      lib/srdb1/schema/kamailio-dispatcher.xml
  53. 12 0
      lib/srdb1/schema/kamailio-domain.xml
  54. 12 0
      lib/srdb1/schema/kamailio-domainpolicy.xml
  55. 21 0
      lib/srdb1/schema/kamailio-extensions.xml
  56. 13 0
      lib/srdb1/schema/kamailio-group.xml
  57. 12 0
      lib/srdb1/schema/kamailio-htable.xml
  58. 13 0
      lib/srdb1/schema/kamailio-imc.xml
  59. 14 0
      lib/srdb1/schema/kamailio-lcr.xml
  60. 12 0
      lib/srdb1/schema/kamailio-msilo.xml
  61. 13 0
      lib/srdb1/schema/kamailio-pdt.xml
  62. 13 0
      lib/srdb1/schema/kamailio-permissions.xml
  63. 17 0
      lib/srdb1/schema/kamailio-presence.xml
  64. 12 0
      lib/srdb1/schema/kamailio-registrar.xml
  65. 15 0
      lib/srdb1/schema/kamailio-rls.xml
  66. 12 0
      lib/srdb1/schema/kamailio-siptrace.xml
  67. 12 0
      lib/srdb1/schema/kamailio-speeddial.xml
  68. 14 0
      lib/srdb1/schema/kamailio-standard.xml
  69. 12 0
      lib/srdb1/schema/kamailio-uri_db.xml
  70. 14 0
      lib/srdb1/schema/kamailio-userblacklist.xml
  71. 12 0
      lib/srdb1/schema/kamailio-usrloc.xml
  72. 74 0
      lib/srdb1/schema/lcr.xml
  73. 163 0
      lib/srdb1/schema/location.xml
  74. 87 0
      lib/srdb1/schema/missed_calls.xml
  75. 58 0
      lib/srdb1/schema/pdt.xml
  76. 184 0
      lib/srdb1/schema/pr_active_watchers.xml
  77. 95 0
      lib/srdb1/schema/pr_presentity.xml
  78. 154 0
      lib/srdb1/schema/pr_pua.xml
  79. 90 0
      lib/srdb1/schema/pr_watchers.xml
  80. 100 0
      lib/srdb1/schema/pr_xcap.xml
  81. 51 0
      lib/srdb1/schema/re_grp.xml
  82. 96 0
      lib/srdb1/schema/rls_presentity.xml
  83. 185 0
      lib/srdb1/schema/rls_watchers.xml
  84. 105 0
      lib/srdb1/schema/silo.xml
  85. 128 0
      lib/srdb1/schema/sip_trace.xml
  86. 103 0
      lib/srdb1/schema/speed_dial.xml
  87. 100 0
      lib/srdb1/schema/subscriber.xml
  88. 59 0
      lib/srdb1/schema/template.xml
  89. 66 0
      lib/srdb1/schema/trusted.xml
  90. 72 0
      lib/srdb1/schema/uri.xml
  91. 67 0
      lib/srdb1/schema/userblacklist.xml
  92. 100 0
      lib/srdb1/schema/usr_preferences.xml
  93. 24 0
      lib/srdb1/schema/version.xml

+ 7 - 0
lib/srdb1/README

@@ -0,0 +1,7 @@
+$Id$
+
+This directory contains generic database support interface. The interface 
+should be used by all modules willing to communicate with a database. Kamailio
+can then switch from one database to another simply by loading a different 
+database support module. Directory example contains a very simple example 
+how to use the interface. Directory doc contains the API documentation.

+ 428 - 0
lib/srdb1/db.c

@@ -0,0 +1,428 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ * 
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+ /*
+  * History:
+  * --------
+  *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
+  *  2006-10-10  Added support for retrieving the last inserted ID (Carsten Bock, BASIS AudioNet GmbH)
+  */
+
+/**
+ * \file db/db.c
+ * \ingroup db
+ * \brief Generic Database Interface
+ *
+ */
+/*! \defgroup db DB: The Kamailio generic database interface
+ * This is a generic database interface for modules that need to utilize a
+ * database. The interface should be used by all modules that access database.
+ * The interface will be independent of the underlying database server.
+ * Notes:
+ * If possible, use the predefined macros if you need to access any structure
+ * attributes.
+ * For additional description, see the comments in the sources of mysql module.
+ *
+ * If you want to see more complicated examples of how the API could be used,
+ * take a look at the sources of the usrloc or auth modules.
+ * - \ref usrloc
+ * - \ref auth
+ *
+ * Implemented modules
+ * - \ref ../modules/db_berkeley
+ * - \ref ../modules/db_flatstore
+ * - \ref ../modules/db_text
+ * - \ref ../modules/db_mysql
+ * - \ref ../modules/db_oracle
+ * - \ref ../modules/db_postgres
+ * - \ref ../modules/db_unixodbc
+ */
+
+#include "../dprint.h"
+#include "../sr_module.h"
+#include "../mem/mem.h"
+#include "../ut.h"
+#include "db_cap.h"
+#include "db_id.h"
+#include "db_pool.h"
+#include "db.h"
+
+static unsigned int MAX_URL_LENGTH = 255;	/*!< maximum length of a SQL URL */
+
+
+int db_check_api(db_func_t* dbf, char *mname)
+{
+	if(dbf==NULL)
+		return -1;
+
+	/* All modules must export db_use_table */
+	if (dbf->use_table == 0) {
+		LM_ERR("module %s does not export db_use_table function\n", mname);
+		goto error;
+	}
+
+	/* All modules must export db_init */
+	if (dbf->init == 0) {
+		LM_ERR("module %s does not export db_init function\n", mname);
+		goto error;
+	}
+
+	/* All modules must export db_close */
+	if (dbf->close == 0) {
+		LM_ERR("module %s does not export db_close function\n", mname);
+		goto error;
+	}
+
+	if (dbf->query) {
+		dbf->cap |= DB_CAP_QUERY;
+	}
+
+	if (dbf->fetch_result) {
+		dbf->cap |= DB_CAP_FETCH;
+	}
+
+	if (dbf->raw_query) {
+		dbf->cap |= DB_CAP_RAW_QUERY;
+	}
+
+	/* Free result must be exported if DB_CAP_QUERY or
+	 * DB_CAP_RAW_QUERY is set */
+	if ((dbf->cap & (DB_CAP_QUERY|DB_CAP_RAW_QUERY)) && (dbf->free_result==0)) {
+		LM_ERR("module %s supports queries but does not export free_result\n",
+				mname);
+		goto error;
+	}
+
+	if (dbf->insert) {
+		dbf->cap |= DB_CAP_INSERT;
+	}
+
+	if (dbf->delete) {
+		dbf->cap |= DB_CAP_DELETE;
+	}
+
+	if (dbf->update) {
+		dbf->cap |= DB_CAP_UPDATE;
+	}
+
+	if (dbf->replace) {
+		dbf->cap |= DB_CAP_REPLACE;
+	}
+
+	if (dbf->last_inserted_id) {
+		dbf->cap |= DB_CAP_LAST_INSERTED_ID;
+	}
+
+	if (dbf->insert_update) {
+		dbf->cap |= DB_CAP_INSERT_UPDATE;
+	}
+	return 0;
+error:
+	return -1;
+}
+
+/*! \brief fills mydbf with the corresponding db module callbacks
+ * \param mod
+ * \param mydbf
+ * \return returns 0 on success, -1 on error
+ * \note on error mydbf will contain only 0s */
+int db_bind_mod(const str* mod, db_func_t* mydbf)
+{
+	char *name, *tmp, *p;
+	int len;
+	db_func_t dbf;
+	db_bind_api_f dbind;
+
+	if (!mod || !mod->s) {
+		LM_CRIT("null database module name\n");
+		return -1;
+	}
+	if (mydbf==0) {
+		LM_CRIT("null dbf parameter\n");
+		return -1;
+	}
+	if (mod->len > MAX_URL_LENGTH)
+	{
+		LM_ERR("SQL URL too long\n");
+		return 0;
+	}
+	// add the prefix
+	name = pkg_malloc(mod->len + 4);
+	if (!name) {
+		LM_ERR("no private memory left\n");
+		return -1;
+	}
+	memcpy(name, "db_", 3);
+	memcpy(name+3, mod->s, mod->len);
+	name[mod->len+3] = 0;
+
+	/* for safety we initialize mydbf with 0 (this will cause
+	 *  a segfault immediately if someone tries to call a function
+	 *  from it without checking the return code from bind_dbmod */
+	memset((void*)mydbf, 0, sizeof(db_func_t));
+
+	p = strchr(name, ':');
+	if (p) {
+		len = p - name;
+		tmp = (char*)pkg_malloc(len + 4);
+		if (!tmp) {
+			LM_ERR("no private memory left\n");
+			pkg_free(name);
+			return -1;
+		}
+		memcpy(tmp, name, len);
+		tmp[len] = '\0';
+		pkg_free(name);
+	} else {
+		tmp = name;
+	}
+
+	dbind = (db_bind_api_f)find_mod_export(tmp, "db_bind_api", 0, 0);
+	if(dbind != NULL)
+	{
+		LM_DBG("using db bind api for %s\n", tmp);
+		if(dbind(&dbf)<0)
+		{
+			LM_ERR("db_bind_api returned error for module %s\n", tmp);
+			goto error;
+		}
+	} else {
+		memset(&dbf, 0, sizeof(db_func_t));
+		LM_DBG("using export interface to bind %s\n", tmp);
+		dbf.use_table = (db_use_table_f)find_mod_export(tmp,
+			"db_use_table", 2, 0);
+		dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
+		dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
+		dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
+		dbf.fetch_result = (db_fetch_result_f)find_mod_export(tmp,
+			"db_fetch_result", 2, 0);
+		dbf.raw_query = (db_raw_query_f)find_mod_export(tmp,
+			"db_raw_query", 2, 0);
+		dbf.free_result = (db_free_result_f)find_mod_export(tmp,
+			"db_free_result", 2, 0);
+		dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
+		dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
+		dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
+		dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
+		dbf.last_inserted_id= (db_last_inserted_id_f)find_mod_export(tmp,
+			"db_last_inserted_id", 1, 0);
+		dbf.insert_update = (db_insert_update_f)find_mod_export(tmp,
+			"db_insert_update", 2, 0);
+	}
+	if(db_check_api(&dbf, tmp)!=0)
+		goto error;
+
+	*mydbf=dbf; /* copy */
+	pkg_free(tmp);
+	return 0;
+
+error:
+	pkg_free(tmp);
+	return -1;
+}
+
+
+/*! \brief
+ * Initialize database module
+ * \note No function should be called before this
+ */
+db_con_t* db_do_init(const str* url, void* (*new_connection)())
+{
+	struct db_id* id;
+	void* con;
+	db_con_t* res;
+
+	int con_size = sizeof(db_con_t) + sizeof(void *);
+	id = 0;
+	res = 0;
+
+	if (!url || !url->s || !new_connection) {
+		LM_ERR("invalid parameter value\n");
+		return 0;
+	}
+	if (url->len > MAX_URL_LENGTH)
+	{
+		LM_ERR("The configured db_url is too long\n");
+		return 0;
+	}
+	
+	/* this is the root memory for this database connection. */
+	res = (db_con_t*)pkg_malloc(con_size);
+	if (!res) {
+		LM_ERR("no private memory left\n");
+		return 0;
+	}
+	memset(res, 0, con_size);
+
+	id = new_db_id(url);
+	if (!id) {
+		LM_ERR("cannot parse URL '%.*s'\n", url->len, url->s);
+		goto err;
+	}
+
+	/* Find the connection in the pool */
+	con = pool_get(id);
+	if (!con) {
+		LM_DBG("connection %p not found in pool\n", id);
+		/* Not in the pool yet */
+		con = new_connection(id);
+		if (!con) {
+			LM_ERR("could not add connection to the pool");
+			goto err;
+		}
+		pool_insert((struct pool_con*)con);
+	} else {
+		LM_DBG("connection %p found in pool\n", id);
+	}
+
+	res->tail = (unsigned long)con;
+	return res;
+
+ err:
+	if (id) free_db_id(id);
+	if (res) pkg_free(res);
+	return 0;
+}
+
+
+/*! \brief
+ * Shut down database module
+ * \note No function should be called after this
+ */
+void db_do_close(db_con_t* _h, void (*free_connection)())
+{
+	struct pool_con* con;
+
+	if (!_h || !_h->tail) {
+		LM_ERR("invalid parameter value\n");
+		return;
+	}
+
+	con = (struct pool_con*)_h->tail;
+	if (pool_remove(con) == 1) {
+		free_connection(con);
+	}
+
+	pkg_free(_h);
+}
+
+
+
+/*! \brief
+ * Get version of a table
+ * \param dbf
+ * \param connection
+ * \param table
+ * \return If there is no row for the given table, return version 0
+ */
+int db_table_version(const db_func_t* dbf, db_con_t* connection, const str* table)
+{
+	db_key_t key[1], col[1];
+	db_val_t val[1];
+	db_res_t* res = NULL;
+	db_val_t* ver = 0;
+
+	if (!dbf||!connection || !table || !table->s) {
+		LM_CRIT("invalid parameter value\n");
+		return -1;
+	}
+
+	str version = str_init(VERSION_TABLE);
+	int ret;
+
+	if (dbf->use_table(connection, &version) < 0) {
+		LM_ERR("error while changing table\n");
+		return -1;
+	}
+	str tmp1 = str_init(TABLENAME_COLUMN);
+	key[0] = &tmp1;
+
+	VAL_TYPE(val) = DB_STR;
+	VAL_NULL(val) = 0;
+	VAL_STR(val) = *table;
+	
+	str tmp2 = str_init(VERSION_COLUMN);
+	col[0] = &tmp2;
+	
+	if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
+		LM_ERR("error in db_query\n");
+		return -1;
+	}
+
+	if (RES_ROW_N(res) == 0) {
+		LM_DBG("no row for table %.*s found\n",
+			table->len, ZSW(table->s));
+		return 0;
+	}
+
+	if (RES_ROW_N(res) != 1) {
+		LM_ERR("invalid number of rows received:"
+			" %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
+		dbf->free_result(connection, res);
+		return -1;
+	}
+
+	ver = ROW_VALUES(RES_ROWS(res));
+	if ( VAL_TYPE(ver)!=DB_INT || VAL_NULL(ver) ) {
+		LM_ERR("invalid type (%d) or nul (%d) version "
+			"columns for %.*s\n", VAL_TYPE(ver), VAL_NULL(ver),
+			table->len, ZSW(table->s));
+		dbf->free_result(connection, res);
+		return -1;
+	}
+
+	ret = VAL_INT(ver);
+	dbf->free_result(connection, res);
+	return ret;
+}
+
+/*! \brief
+ * 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, expected %d (check table structure and table \"version\")\n", ver, table->len, table->s, version);
+		return -1;
+	}
+	return 0;
+}
+
+/*! \brief
+ * Store name of table that will be used by
+ * subsequent database functions
+ */
+int db_use_table(db_con_t* _h, const str* _t)
+{
+	if (!_h || !_t || !_t->s) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	CON_TABLE(_h) = _t;
+	return 0;
+}

+ 402 - 0
lib/srdb1/db.h

@@ -0,0 +1,402 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db.h
+ * \ingroup db
+ * \ref db.c
+ * \brief Generic Database Interface
+ *
+ * This is a generic database interface for modules that need to utilize a
+ * database. The interface should be used by all modules that access database.
+ * The interface will be independent of the underlying database server.
+ * Notes:
+ * If possible, use the predefined macros if you need to access any structure
+ * attributes.
+ * For additional description, see the comments in the sources of mysql module.
+ *
+ * If you want to see more complicated examples of how the API could be used,
+ * take a look at the sources of the usrloc or auth modules.
+ */
+
+#ifndef DB_H
+#define DB_H
+
+#include "db_key.h"
+#include "db_op.h"
+#include "db_val.h"
+#include "db_con.h"
+#include "db_res.h"
+#include "db_cap.h"
+#include "db_con.h"
+#include "db_row.h"
+
+
+/**
+ * \brief Specify table name that will be used for subsequent operations.
+ * 
+ * The function db_use_table takes a table name and stores it db_con_t structure.
+ * All subsequent operations (insert, delete, update, query) are performed on
+ * that table.
+ * \param _h database connection handle
+ * \param _t table name
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_use_table_f)(db_con_t* _h, const str * _t);
+
+/**
+ * \brief Initialize database connection and obtain the connection handle.
+ *
+ * This function initialize the database API and open a new database
+ * connection. This function must be called after bind_dbmod but before any
+ * other database API function is called.
+ * 
+ * The function takes one parameter, the parameter must contain the database
+ * connection URL. The URL is of the form 
+ * mysql://username:password\@host:port/database where:
+ * 
+ * username: Username to use when logging into database (optional).
+ * password: password if it was set (optional)
+ * host:     Hosname or IP address of the host where database server lives (mandatory)
+ * port:     Port number of the server if the port differs from default value (optional)
+ * database: If the database server supports multiple databases, you must specify the
+ * name of the database (optional).
+ * \see bind_dbmod
+ * \param _sqlurl database connection URL
+ * \return returns a pointer to the db_con_t representing the connection if it was
+ * successful, otherwise 0 is returned
+ */
+typedef db_con_t* (*db_init_f) (const str* _sqlurl);
+
+/**
+ * \brief Close a database connection and free all memory used.
+ *
+ * The function closes previously open connection and frees all previously 
+ * allocated memory. The function db_close must be the very last function called.
+ * \param _h db_con_t structure representing the database connection
+ */
+typedef void (*db_close_f) (db_con_t* _h); 
+
+
+/**
+ * \brief Query table for specified rows.
+ *
+ * This function implements the SELECT SQL directive.
+ * If _k and _v parameters are NULL and _n is zero, you will get the whole table.
+ *
+ * if _c is NULL and _nc is zero, you will get all table columns in the result.
+ * _r will point to a dynamically allocated structure, it is neccessary to call
+ * db_free_result function once you are finished with the result.
+ *
+ * If _op is 0, equal (=) will be used for all key-value pairs comparisons.
+ *
+ * Strings in the result are not duplicated, they will be discarded if you call
+ * db_free_result, make a copy yourself if you need to keep it after db_free_result.
+ *
+ * You must call db_free_result before you can call db_query again!
+ * \see db_free_result
+ *
+ * \param _h database connection handle
+ * \param _k array of column names that will be compared and their values must match
+ * \param _op array of operators to be used with key-value pairs
+ * \param _v array of values, columns specified in _k parameter must match these values
+ * \param _c array of column names that you are interested in
+ * \param _n number of key-value pairs to match in _k and _v parameters
+ * \param _nc number of columns in _c parameter
+ * \param _o order by statement for query
+ * \param _r address of variable where pointer to the result will be stored
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_query_f) (const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+				const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
+				const db_key_t _o, db_res_t** _r);
+
+/**
+ * \brief Gets a partial result set, fetch rows from a result
+ *
+ * Gets a partial result set, fetch a number of rows from a database result.
+ * This function initialize the given result structure on the first run, and
+ * fetches the nrows number of rows. On subsequenting runs, it uses the
+ * existing result and fetches more rows, until it reaches the end of the
+ * result set. Because of this the result needs to be null in the first
+ * invocation of the function. If the number of wanted rows is zero, the
+ * function returns anything with a result of zero.
+ * \param _h structure representing database connection
+ * \param _r structure for the result
+ * \param _n the number of rows that should be fetched
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_fetch_result_f) (const db_con_t* _h, db_res_t** _r, const int _n);
+
+
+/**
+ * \brief Raw SQL query.
+ *
+ * This function can be used to do database specific queries. Please
+ * use this function only if needed, as this creates portability issues
+ * for the different databases. Also keep in mind that you need to
+ * escape all external data sources that you use. You could use the
+ * escape_common and unescape_common functions in the core for this task.
+ * \see escape_common
+ * \see unescape_common
+ * \param _h structure representing database connection
+ * \param _s the SQL query
+ * \param _r structure for the result
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_raw_query_f) (const db_con_t* _h, const str* _s, db_res_t** _r);
+
+
+/**
+ * \brief Free a result allocated by db_query.
+ *
+ * This function frees all memory allocated previously in db_query. Its
+ * neccessary to call this function on a db_res_t structure if you don't need the
+ * structure anymore. You must call this function before you call db_query again!
+ * \param _h database connection handle
+ * \param _r pointer to db_res_t structure to destroy
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_free_result_f) (db_con_t* _h, db_res_t* _r);
+
+
+/**
+ * \brief Insert a row into the specified table.
+ * 
+ * This function implements INSERT SQL directive, you can insert one or more
+ * rows in a table using this function.
+ * \param _h database connection handle
+ * \param _k array of keys (column names) 
+ * \param _v array of values for keys specified in _k parameter
+ * \param _n number of keys-value pairs int _k and _v parameters
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_insert_f) (const db_con_t* _h, const db_key_t* _k,
+				const db_val_t* _v, const int _n);
+
+
+/**
+ * \brief Delete a row from the specified table.
+ *
+ * This function implements DELETE SQL directive, it is possible to delete one or
+ * more rows from a table.
+ * If _k is NULL and _v is NULL and _n is zero, all rows are deleted, the
+ * resulting table will be empty.
+ * If _o is NULL, the equal operator "=" will be used for the comparison.
+ * 
+ * \param _h database connection handle
+ * \param _k array of keys (column names) that will be matched
+ * \param _o array of operators to be used with key-value pairs
+ * \param _v array of values that the row must match to be deleted
+ * \param _n number of keys-value parameters in _k and _v parameters
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_delete_f) (const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+				const db_val_t* _v, const int _n);
+
+
+/**
+ * \brief Update some rows in the specified table.
+ *
+ * The function implements UPDATE SQL directive. It is possible to modify one
+ * or more rows in a table using this function.
+ * \param _h database connection handle
+ * \param _k array of keys (column names) that will be matched
+ * \param _o array of operators to be used with key-value pairs
+ * \param _v array of values that the row must match to be modified
+ * \param _uk array of keys (column names) that will be modified
+ * \param _uv new values for keys specified in _k parameter
+ * \param _n number of key-value pairs in _k and _v parameters
+ * \param _un number of key-value pairs in _uk and _uv parameters
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_update_f) (const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+				const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv,
+				const int _n, const int _un);
+
+
+/**
+ * \brief Insert a row and replace if one already exists.
+ *
+ * The function implements the REPLACE SQL directive. It is possible to insert
+ * a row and replace if one already exists. The old row will be deleted before
+ * the insertion of the new data.
+ * \param _h structure representing database connection
+ * \param _k key names
+ * \param _v values of the keys
+ * \param _n number of key=value pairs
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+*/
+typedef int (*db_replace_f) (const db_con_t* handle, const db_key_t* keys,
+				const db_val_t* vals, const int n);
+
+
+/**
+ * \brief Retrieve the last inserted ID in a table.
+ *
+ * The function returns the value generated for an AUTO_INCREMENT column by the
+ * previous INSERT or UPDATE  statement. Use this function after you have 
+ * performed an INSERT statement into a table that contains an AUTO_INCREMENT
+ * 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.
+ */
+typedef int (*db_last_inserted_id_f) (const db_con_t* _h);
+
+
+/**
+ * \brief Insert a row into specified table, update on duplicate key.
+ * 
+ * The function implements the INSERT ON DUPLICATE KEY UPDATE SQL directive.
+ * It is possible to insert a row and update if one already exists.
+ * The old row will not deleted before the insertion of the new data.
+ * \param _h structure representing database connection
+ * \param _k key names
+ * \param _v values of the keys
+ * \param _n number of key=value pairs
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_insert_update_f) (const db_con_t* _h, const db_key_t* _k,
+				const db_val_t* _v, const int _n);
+
+
+/**
+ * \brief Database module callbacks
+ * 
+ * This structure holds function pointer to all database functions. Before this
+ * structure can be used it must be initialized with bind_dbmod.
+ * \see bind_dbmod
+ */
+typedef struct db_func {
+	unsigned int      cap;           /* Capability vector of the database transport */
+	db_use_table_f    use_table;     /* Specify table name */
+	db_init_f         init;          /* Initialize database connection */
+	db_close_f        close;         /* Close database connection */
+	db_query_f        query;         /* query a table */
+	db_fetch_result_f fetch_result;  /* fetch result */
+	db_raw_query_f    raw_query;     /* Raw query - SQL */
+	db_free_result_f  free_result;   /* Free a query result */
+	db_insert_f       insert;        /* Insert into table */
+	db_delete_f       delete;        /* Delete from table */ 
+	db_update_f       update;        /* Update table */
+	db_replace_f      replace;       /* Replace row in a table */
+	db_last_inserted_id_f  last_inserted_id;  /* Retrieve the last inserted ID
+	                                            in a table */
+	db_insert_update_f insert_update; /* Insert into table, update on duplicate key */ 
+} db_func_t;
+
+
+/**
+ * \brief Bind database module functions
+ *
+ * This function is special, it's only purpose is to call find_export function in
+ * the core and find the addresses of all other database related functions. The 
+ * db_func_t callback given as parameter is updated with the found addresses.
+ *
+ * This function must be called before any other database API call!
+ *
+ * The database URL is of the form "mysql://username:password@host:port/database" or
+ * "mysql" (database module name).
+ * In the case of a database connection URL, this function looks only at the first
+ * token (the database protocol). In the example above that would be "mysql":
+ * \see db_func_t
+ * \param mod database connection URL or a database module name
+ * \param dbf database module callbacks
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+int db_bind_mod(const str* mod, db_func_t* dbf);
+
+
+/**
+ * \brief Helper for db_init function.
+ *
+ * This helper method do the actual work for the database specific db_init
+ * functions.
+ * \param url database connection URL
+ * \param (*new_connection)() Pointer to the db specific connection creation method
+ * \return returns a pointer to the db_con_t representing the connection if it was
+   successful, otherwise 0 is returned.
+ */
+db_con_t* db_do_init(const str* url, void* (*new_connection)());
+
+
+/**
+ * \brief Helper for db_close function.
+ *
+ * This helper method does some work for the closing of a database 
+ * connection. No function should be called after this
+ * \param _h database connection handle
+ * \param (*free_connection) Pointer to the db specifc free_connection method
+ */
+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
+ * \return the version number if present, 0 if no version data available, < 0 on error
+ */
+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 dbh 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.
+ *
+ * Stores the name of the table that will be used by subsequent database
+ * functions calls in a db_con_t structure.
+ * \param _h database connection handle
+ * \param _t stored name
+ * \return 0 if everything is ok, otherwise returns value < 0
+ */
+int db_use_table(db_con_t* _h, const str* _t);
+
+/**
+ * \brief Bind the DB API exported by a module.
+ *
+ * The function links the functions implemented by the module to the members
+ * of db_func_t structure
+ * \param dbb db_func_t structure representing the variable where to bind
+ * \return 0 if everything is ok, otherwise returns -1
+ */
+
+typedef int (*db_bind_api_f)(db_func_t *dbb);
+
+
+#endif /* DB_H */

+ 69 - 0
lib/srdb1/db_cap.h

@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2004 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file db_cap.h
+ * \ingroup db
+ * \brief Data structures that represents capabilities in the database.
+ *
+ * This file defines data structures that represents certain database
+ * capabilities. It also provides some macros for convenient access to this
+ * values.
+ */
+
+#ifndef DB_CAP_H
+#define DB_CAP_H
+
+
+/*! \brief
+ * Represents the capabilities that a database driver supports.
+ */
+typedef enum db_cap {
+	DB_CAP_QUERY =     1 << 0,  /*!< driver can perform queries                                     */
+	DB_CAP_RAW_QUERY = 1 << 1,  /*!< driver can perform raw queries                                 */
+	DB_CAP_INSERT =    1 << 2,  /*!< driver can insert data                                         */
+	DB_CAP_DELETE =    1 << 3,  /*!< driver can delete data                                         */
+	DB_CAP_UPDATE =    1 << 4,  /*!< driver can update data                                         */
+	DB_CAP_REPLACE =   1 << 5,  /*!< driver can replace (also known as INSERT OR UPDATE) data       */
+	DB_CAP_FETCH   =   1 << 6,  /*!< driver supports fetch result queries                           */
+	DB_CAP_LAST_INSERTED_ID = 1 << 7,  /*!< driver can return the ID of the last insert operation   */
+ 	DB_CAP_INSERT_UPDATE = 1 << 8 /*!< driver can insert data into database and update on duplicate */
+
+} db_cap_t;
+
+
+/*! \brief
+ * All database capabilities except raw_query, replace, insert_update and 
+ * last_inserted_id which should be checked separately when needed
+ */
+#define DB_CAP_ALL (DB_CAP_QUERY | DB_CAP_INSERT | DB_CAP_DELETE | DB_CAP_UPDATE)
+
+
+/*! \brief
+ * Returns true if all the capabilities in cpv are supported by module
+ * represented by dbf, false otherwise
+ */
+#define DB_CAPABILITY(dbf, cpv) (((dbf).cap & (cpv)) == (cpv))
+
+
+#endif /* DB_CAP_H */

+ 52 - 0
lib/srdb1/db_con.h

@@ -0,0 +1,52 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file db/db_con.h
+ * \ingroup db
+ * \brief Type that represents a database connection
+ */
+
+#ifndef DB_CON_H
+#define DB_CON_H
+
+#include "../str.h"
+
+
+/*! \brief
+ * This structure represents a database connection, pointer to this structure
+ * are used as a connection handle from modules uses the db API.
+ */
+typedef struct {
+	const str* table;      /*!< Default table that should be used              */
+	unsigned long tail;    /*!< Variable length tail, database module specific */
+} db_con_t;
+
+
+/** Return the table of the connection handle */
+#define CON_TABLE(cn)      ((cn)->table)
+/** Return the tail of the connection handle */
+#define CON_TAIL(cn)       ((cn)->tail)
+
+
+#endif /* DB_CON_H */

+ 295 - 0
lib/srdb1/db_id.c

@@ -0,0 +1,295 @@
+/* 
+ * $Id$
+ *
+ * Copyright (C) 2001-2005 iptel.org
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_id.c
+ * \ingroup db
+ * \brief Functions for parsing a database URL and work with db identifier.
+ */
+
+#include "db_id.h"
+#include "../dprint.h"
+#include "../mem/mem.h"
+#include "../ut.h"
+#include <stdlib.h>
+#include <string.h>
+
+
+/**
+ * Duplicate a string
+ * \param dst destination
+ * \param begin start of the string
+ * \param end end of the string
+ */
+static int dupl_string(char** dst, const char* begin, const char* end)
+{
+	if (*dst) pkg_free(*dst);
+
+	*dst = pkg_malloc(end - begin + 1);
+	if ((*dst) == NULL) {
+		return -1;
+	}
+
+	memcpy(*dst, begin, end - begin);
+	(*dst)[end - begin] = '\0';
+	return 0;
+}
+
+
+/**
+ * Parse a database URL of form 
+ * scheme://[username[:password]@]hostname[:port]/database
+ *
+ * \param id filled id struct
+ * \param url parsed URL
+ * \return 0 if parsing was successful and -1 otherwise
+ */
+static int parse_db_url(struct db_id* id, const str* url)
+{
+#define SHORTEST_DB_URL "s://a/b"
+#define SHORTEST_DB_URL_LEN (sizeof(SHORTEST_DB_URL) - 1)
+
+	enum state {
+		ST_SCHEME,     /* Scheme part */
+		ST_SLASH1,     /* First slash */
+		ST_SLASH2,     /* Second slash */
+		ST_USER_HOST,  /* Username or hostname */
+		ST_PASS_PORT,  /* Password or port part */
+		ST_HOST,       /* Hostname part */
+		ST_PORT,       /* Port part */
+		ST_DB          /* Database part */
+	};
+
+	enum state st;
+	unsigned int len, i;
+	const char* begin;
+	char* prev_token;
+
+	prev_token = 0;
+
+	if (!id || !url || !url->s) {
+		goto err;
+	}
+	
+	len = url->len;
+	if (len < SHORTEST_DB_URL_LEN) {
+		goto err;
+	}
+	
+	/* Initialize all attributes to 0 */
+	memset(id, 0, sizeof(struct db_id));
+	st = ST_SCHEME;
+	begin = url->s;
+
+	for(i = 0; i < len; i++) {
+		switch(st) {
+		case ST_SCHEME:
+			switch(url->s[i]) {
+			case ':':
+				st = ST_SLASH1;
+				if (dupl_string(&id->scheme, begin, url->s + i) < 0) goto err;
+				break;
+			}
+			break;
+
+		case ST_SLASH1:
+			switch(url->s[i]) {
+			case '/':
+				st = ST_SLASH2;
+				break;
+
+			default:
+				goto err;
+			}
+			break;
+
+		case ST_SLASH2:
+			switch(url->s[i]) {
+			case '/':
+				st = ST_USER_HOST;
+				begin = url->s + i + 1;
+				break;
+				
+			default:
+				goto err;
+			}
+			break;
+
+		case ST_USER_HOST:
+			switch(url->s[i]) {
+			case '@':
+				st = ST_HOST;
+				if (dupl_string(&id->username, begin, url->s + i) < 0) goto err;
+				begin = url->s + i + 1;
+				break;
+
+			case ':':
+				st = ST_PASS_PORT;
+				if (dupl_string(&prev_token, begin, url->s + i) < 0) goto err;
+				begin = url->s + i + 1;
+				break;
+
+			case '/':
+				if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
+				if (dupl_string(&id->database, url->s + i + 1, url->s + len) < 0) goto err;
+				return 0;
+			}
+			break;
+
+		case ST_PASS_PORT:
+			switch(url->s[i]) {
+			case '@':
+				st = ST_HOST;
+				id->username = prev_token;
+				if (dupl_string(&id->password, begin, url->s + i) < 0) goto err;
+				begin = url->s + i + 1;
+				break;
+
+			case '/':
+				id->host = prev_token;
+				id->port = str2s(begin, url->s + i - begin, 0);
+				if (dupl_string(&id->database, url->s + i + 1, url->s + len) < 0) goto err;
+				return 0;
+			}
+			break;
+
+		case ST_HOST:
+			switch(url->s[i]) {
+			case ':':
+				st = ST_PORT;
+				if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
+				begin = url->s + i + 1;
+				break;
+
+			case '/':
+				if (dupl_string(&id->host, begin, url->s + i) < 0) goto err;
+				if (dupl_string(&id->database, url->s + i + 1, url->s + len) < 0) goto err;
+				return 0;
+			}
+			break;
+
+		case ST_PORT:
+			switch(url->s[i]) {
+			case '/':
+				id->port = str2s(begin, url->s + i - begin, 0);
+				if (dupl_string(&id->database, url->s + i + 1, url->s + len) < 0) goto err;
+				return 0;
+			}
+			break;
+			
+		case ST_DB:
+			break;
+		}
+	}
+
+	if (st != ST_DB) goto err;
+	return 0;
+
+ err:
+	if (id->scheme) pkg_free(id->scheme);
+	if (id->username) pkg_free(id->username);
+	if (id->password) pkg_free(id->password);
+	if (id->host) pkg_free(id->host);
+	if (id->database) pkg_free(id->database);
+	if (prev_token) pkg_free(prev_token);
+	return -1;
+}
+
+
+/**
+ * Create a new connection identifier
+ * \param url database URL
+ * \return connection identifier, or zero on error
+ */
+struct db_id* new_db_id(const str* url)
+{
+	struct db_id* ptr;
+
+	if (!url || !url->s) {
+		LM_ERR("invalid parameter\n");
+		return 0;
+	}
+
+	ptr = (struct db_id*)pkg_malloc(sizeof(struct db_id));
+	if (!ptr) {
+		LM_ERR("no private memory left\n");
+		goto err;
+	}
+	memset(ptr, 0, sizeof(struct db_id));
+
+	if (parse_db_url(ptr, url) < 0) {
+		LM_ERR("error while parsing database URL: '%.*s' \n", url->len, url->s);
+		goto err;
+	}
+
+	return ptr;
+
+ err:
+	if (ptr) pkg_free(ptr);
+	return 0;
+}
+
+
+/**
+ * Compare two connection identifiers
+ * \param id1 first identifier
+ * \param id2 second identifier
+ * \return one if both are equal, zero otherwise
+ */
+unsigned char cmp_db_id(const struct db_id* id1, const struct db_id* id2)
+{
+	if (!id1 || !id2) return 0;
+	if (id1->port != id2->port) return 0;
+
+	if (strcmp(id1->scheme, id2->scheme)) return 0;
+	if (id1->username!=0 && id2->username!=0) {
+		if (strcmp(id1->username, id2->username)) return 0;
+	} else {
+		if (id1->username!=0 || id2->username!=0) return 0;
+	}
+	if (id1->password!=0 && id2->password!=0) {
+		if(strcmp(id1->password, id2->password)) return 0;
+	} else {
+		if (id1->password!=0 || id2->password!=0) return 0;
+	}
+	if (strcasecmp(id1->host, id2->host)) return 0;
+	if (strcmp(id1->database, id2->database)) return 0;
+	return 1;
+}
+
+
+/**
+ * Free a connection identifier
+ * \param id identifier
+ */
+void free_db_id(struct db_id* id)
+{
+	if (!id) return;
+
+	if (id->scheme) pkg_free(id->scheme);
+	if (id->username) pkg_free(id->username);
+	if (id->password) pkg_free(id->password);
+	if (id->host) pkg_free(id->host);
+	if (id->database) pkg_free(id->database);
+	pkg_free(id);
+}

+ 70 - 0
lib/srdb1/db_id.h

@@ -0,0 +1,70 @@
+/* 
+ * $Id$
+ *
+ * Copyright (C) 2001-2005 iptel.org
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ * 
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file db/db_id.h
+ * \ingroup db
+ * \brief Functions for parsing a database URL and works with db identifier.
+ */
+
+#ifndef _DB_ID_H
+#define _DB_ID_H
+
+#include "../str.h"
+
+/** Structure representing a database ID */
+struct db_id {
+	char* scheme;        /**< URL scheme */
+	char* username;      /**< Username, case sensitive */
+	char* password;      /**< Password, case sensitive */
+	char* host;          /**< Host or IP, case insensitive */
+	unsigned short port; /**< Port number */
+	char* database;      /**< Database, case sensitive */
+};
+
+
+/**
+ * Create a new connection identifier
+ * \param url database URL
+ * \return new allocated db_id structure, NULL on failure
+ */
+struct db_id* new_db_id(const str* url);
+
+
+/**
+ * Compare two connection identifiers
+ * \param id1 first identifier
+ * \param id2 second identifier
+ * \return 1 if both identifier are equal, 0 if there not equal
+ */
+unsigned char cmp_db_id(const struct db_id* id1, const struct db_id* id2);
+
+
+/**
+ * Free a connection identifier
+ * \param id the identifier that should released
+ */
+void free_db_id(struct db_id* id);
+
+
+#endif /* _DB_ID_H */

+ 43 - 0
lib/srdb1/db_key.h

@@ -0,0 +1,43 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_key.h
+ * \ingroup db
+ * \brief Type that represents a database key.
+ */
+
+#ifndef DB_KEY_H
+#define DB_KEY_H
+
+#include "../ut.h"
+
+
+/**
+ * This type represents a database key (column).
+ * Every time you need to specify a key value, this type should be used.
+ */
+typedef str* db_key_t;
+
+
+#endif /* DB_KEY_H */

+ 53 - 0
lib/srdb1/db_op.h

@@ -0,0 +1,53 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_op.h
+ * \brief Type that represents a expression operator.
+ * \ingroup db
+ */
+
+#ifndef DB_OP_H
+#define DB_OP_H
+
+/** operator less than */
+#define OP_LT  "<"
+/** operator greater than */
+#define OP_GT  ">"
+/** operator equal */
+#define OP_EQ  "="
+/** operator less than equal */
+#define OP_LEQ "<="
+/** operator greater than equal */
+#define OP_GEQ ">="
+/** operator negation */
+#define OP_NEQ "!="
+
+
+/**
+ * This type represents an expression operator uses for SQL queries.
+ */
+typedef const char* db_op_t;
+
+
+#endif /* DB_OP_H */

+ 122 - 0
lib/srdb1/db_pool.c

@@ -0,0 +1,122 @@
+/* 
+ * $Id$
+ *
+ * Copyright (C) 2001-2005 iptel.org
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_pool.c
+ * \brief Functions for managing a pool of database connections.
+ * \ingroup db
+ */
+
+#include "../dprint.h"
+#include "db_pool.h"
+
+
+/* The head of the pool */
+static struct pool_con* db_pool = 0;
+
+
+/*
+ * Search the pool for a connection with
+ * the identifier equal to id, NULL is returned
+ * when no connection is found
+ */
+struct pool_con* pool_get(const struct db_id* id)
+{
+	struct pool_con* ptr;
+
+	if (!id) {
+		LM_ERR("invalid parameter value\n");
+		return 0;
+	}
+
+	ptr = db_pool;
+	while (ptr) {
+		if (cmp_db_id(id, ptr->id)) {
+			ptr->ref++;
+			return ptr;
+		}
+		ptr = ptr->next;
+	}
+
+	return 0;
+}
+
+
+/*
+ * Insert a new connection into the pool
+ */
+void pool_insert(struct pool_con* con)
+{
+	if (!con) return;
+
+	con->next = db_pool;
+	db_pool = con;
+}
+
+
+/*
+ * Release connection from the pool, the function
+ * would return 1 when if the connection is not
+ * referenced anymore and thus can be closed and
+ * deleted by the backend. The function returns
+ * 0 if the connection should still be kept open
+ * because some other module is still using it.
+ * The function returns -1 if the connection is
+ * not in the pool.
+ */
+int pool_remove(struct pool_con* con)
+{
+	struct pool_con* ptr;
+
+	if (!con) return -2;
+
+	if (con->ref > 1) {
+		     /* There are still other users, just
+		      * decrease the reference count and return
+		      */
+		LM_DBG("connection still kept in the pool\n");
+		con->ref--;
+		return 0;
+	}
+
+	LM_DBG("removing connection from the pool\n");
+
+	if (db_pool == con) {
+		db_pool = db_pool->next;
+	} else {
+		ptr = db_pool;
+		while(ptr) {
+			if (ptr->next == con) break;
+			ptr = ptr->next;
+		}
+		if (!ptr) {
+			LM_ERR("weird, connection not found in the pool\n");
+			return -1;
+		} else {
+			     /* Remove the connection from the pool */
+			ptr->next = con->next;
+		}
+	}
+
+	return 1;
+}

+ 83 - 0
lib/srdb1/db_pool.h

@@ -0,0 +1,83 @@
+/* 
+ * $Id$
+ *
+ * Copyright (C) 2001-2005 iptel.org
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_pool.h
+ * \brief Functions for managing a pool of database connections.
+ * \ingroup db
+ */
+
+#ifndef _DB_POOL_H
+#define _DB_POOL_H
+
+#include "db_id.h"
+#include "db_con.h"
+
+
+/**
+ * This is a stub that contains all attributes
+ * that pool members must have, it is not really
+ * used, real connection structures are created
+ * by database backends. All such structures (
+ * created by the backends) must have these
+ * attributes.
+ */
+struct pool_con {
+	struct db_id* id;        /**< Connection identifier */
+	unsigned int ref;        /**< Reference count */
+	struct pool_con* next;   /**< Next element in the pool */
+};
+
+
+/**
+ * Search the pool for a connection with the identifier equal to
+ * the id.
+ * \param id searched id
+ * \return the connection if it could be found, NULL otherwise
+ */
+struct pool_con* pool_get(const struct db_id* id);
+
+
+/**
+ * Insert a new connection into the pool.
+ * \param con the inserted connection 
+ */
+void pool_insert(struct pool_con* con);
+
+
+/**
+ * Release a connection from the pool, the function
+ * would return 1 when if the connection is not
+ * referenced anymore and thus can be closed and
+ * deleted by the backend. The function returns
+ * 0 if the connection should still be kept open
+ * because some other module is still using it.
+ * The function returns -1 if the connection is
+ * not in the pool.
+ * \param con connection that should be removed
+ * \return 1 if the connection can be freed, 0 if it can't be freed, -1 if not found
+ */
+int pool_remove(struct pool_con* con);
+
+
+#endif /* _POOL_H */

+ 322 - 0
lib/srdb1/db_query.c

@@ -0,0 +1,322 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+/**
+ * \file db/db_query.c
+ * \brief Query helper for database drivers
+ * \ingroup db
+ *
+ * This helper methods for database queries are used from the database
+ * SQL driver to do the actual work. Each function uses some functions from
+ * the actual driver with function pointers to the concrete, specific
+ * implementation.
+*/
+
+#include <stdio.h>
+#include "../dprint.h"
+#include "db_ut.h"
+#include "db_query.h"
+
+static str  sql_str;
+static char sql_buf[SQL_BUF_LEN];
+
+int db_do_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+	const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
+	const db_key_t _o, db_res_t** _r, int (*val2str) (const db_con_t*,
+	const db_val_t*, char*, int* _len), int (*submit_query)(const db_con_t*,
+	const str*), int (*store_result)(const db_con_t* _h, db_res_t** _r))
+{
+	int off, ret;
+
+	if (!_h || !val2str || !submit_query || !store_result) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	if (!_c) {
+		ret = snprintf(sql_buf, SQL_BUF_LEN, "select * from %.*s ", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+		if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+		off = ret;
+	} else {
+		ret = snprintf(sql_buf, SQL_BUF_LEN, "select ");
+		if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+		off = ret;
+
+		ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _c, _nc);
+		if (ret < 0) return -1;
+		off += ret;
+
+		ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, "from %.*s ", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+		if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+		off += ret;
+	}
+	if (_n) {
+		ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, "where ");
+		if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+		off += ret;
+
+		ret = db_print_where(_h, sql_buf + off,
+				SQL_BUF_LEN - off, _k, _op, _v, _n, val2str);
+		if (ret < 0) return -1;;
+		off += ret;
+	}
+	if (_o) {
+		ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " order by %.*s", _o->len, _o->s);
+		if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+		off += ret;
+	}
+	/*
+	 * Null-terminate the string for the postgres driver. Its query function
+	 * don't support a length parameter, so they need this for the correct
+	 * function of strlen. This zero is not included in the 'str' length.
+	 * We need to check the length here, otherwise we could overwrite the buffer
+	 * boundaries if off is equal to SQL_BUF_LEN.
+	 */
+	if (off + 1 >= SQL_BUF_LEN) goto error;
+	sql_buf[off + 1] = '\0';
+	sql_str.s = sql_buf;
+	sql_str.len = off;
+
+	if (submit_query(_h, &sql_str) < 0) {
+		LM_ERR("error while submitting query\n");
+		return -2;
+	}
+
+	if(_r) {
+		int tmp = store_result(_h, _r);
+		if (tmp < 0) {
+			LM_ERR("error while storing result");
+			return tmp;
+		}
+	}
+	return 0;
+
+error:
+	LM_ERR("error while preparing query\n");
+	return -1;
+}
+
+
+int db_do_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r,
+	int (*submit_query)(const db_con_t* _h, const str* _c),
+	int (*store_result)(const db_con_t* _h, db_res_t** _r))
+{
+	if (!_h || !_s || !submit_query || !store_result) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	if (submit_query(_h, _s) < 0) {
+		LM_ERR("error while submitting query\n");
+		return -2;
+	}
+
+	if(_r) {
+		int tmp = store_result(_h, _r);
+		if (tmp < 0) {
+			LM_ERR("error while storing result");
+			return tmp;
+		}
+	}
+	return 0;
+}
+
+
+int db_do_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+	const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*),
+	int (*submit_query)(const db_con_t* _h, const str* _c))
+{
+	int off, ret;
+
+	if (!_h || !_k || !_v || !_n || !val2str || !submit_query) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(sql_buf, SQL_BUF_LEN, "insert into %.*s (", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+	if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+	off = ret;
+
+	ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _k, _n);
+	if (ret < 0) return -1;
+	off += ret;
+
+	ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, ") values (");
+	if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+	off += ret;
+
+	ret = db_print_values(_h, sql_buf + off, SQL_BUF_LEN - off, _v, _n, val2str);
+	if (ret < 0) return -1;
+	off += ret;
+
+	if (off + 2 > SQL_BUF_LEN) goto error;
+	sql_buf[off++] = ')';
+	sql_buf[off] = '\0';
+	sql_str.s = sql_buf;
+	sql_str.len = off;
+
+	if (submit_query(_h, &sql_str) < 0) {
+	        LM_ERR("error while submitting query\n");
+		return -2;
+	}
+	return 0;
+
+error:
+	LM_ERR("error while preparing insert operation\n");
+	return -1;
+}
+
+
+int db_do_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+	const db_val_t* _v, const int _n, int (*val2str) (const db_con_t*,
+	const db_val_t*, char*, int*), int (*submit_query)(const db_con_t* _h,
+	const str* _c))
+{
+	int off, ret;
+
+	if (!_h || !val2str || !submit_query) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(sql_buf, SQL_BUF_LEN, "delete from %.*s", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+	if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+	off = ret;
+
+	if (_n) {
+		ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
+		if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+		off += ret;
+
+		ret = db_print_where(_h, sql_buf + off,
+				SQL_BUF_LEN - off, _k, _o, _v, _n, val2str);
+		if (ret < 0) return -1;
+		off += ret;
+	}
+	if (off + 1 > SQL_BUF_LEN) goto error;
+	sql_buf[off] = '\0';
+	sql_str.s = sql_buf;
+	sql_str.len = off;
+
+	if (submit_query(_h, &sql_str) < 0) {
+		LM_ERR("error while submitting query\n");
+		return -2;
+	}
+	return 0;
+
+error:
+	LM_ERR("error while preparing delete operation\n");
+	return -1;
+}
+
+
+int db_do_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+	const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
+	const int _un, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*),
+	int (*submit_query)(const db_con_t* _h, const str* _c))
+{
+	int off, ret;
+
+	if (!_h || !_uk || !_uv || !_un || !val2str || !submit_query) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(sql_buf, SQL_BUF_LEN, "update %.*s set ", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+	if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+	off = ret;
+
+	ret = db_print_set(_h, sql_buf + off, SQL_BUF_LEN - off, _uk, _uv, _un, val2str);
+	if (ret < 0) return -1;
+	off += ret;
+
+	if (_n) {
+		ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
+		if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+		off += ret;
+
+		ret = db_print_where(_h, sql_buf + off, SQL_BUF_LEN - off, _k, _o, _v, _n, val2str);
+		if (ret < 0) return -1;
+		off += ret;
+	}
+	if (off + 1 > SQL_BUF_LEN) goto error;
+	sql_buf[off] = '\0';
+	sql_str.s = sql_buf;
+	sql_str.len = off;
+
+	if (submit_query(_h, &sql_str) < 0) {
+		LM_ERR("error while submitting query\n");
+		return -2;
+	}
+	return 0;
+
+error:
+	LM_ERR("error while preparing update operation\n");
+	return -1;
+}
+
+
+int db_do_replace(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+	const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*,
+	int*), int (*submit_query)(const db_con_t* _h, const str* _c))
+{
+	int off, ret;
+
+	if (!_h || !_k || !_v || !val2str|| !submit_query) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(sql_buf, SQL_BUF_LEN, "replace %.*s (", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+	if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
+	off = ret;
+
+	ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _k, _n);
+	if (ret < 0) return -1;
+	off += ret;
+
+	ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, ") values (");
+	if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
+	off += ret;
+
+	ret = db_print_values(_h, sql_buf + off, SQL_BUF_LEN - off, _v, _n,
+	val2str);
+	if (ret < 0) return -1;
+	off += ret;
+
+	if (off + 2 > SQL_BUF_LEN) goto error;
+	sql_buf[off++] = ')';
+	sql_buf[off] = '\0';
+	sql_str.s = sql_buf;
+	sql_str.len = off;
+
+	if (submit_query(_h, &sql_str) < 0) {
+	        LM_ERR("error while submitting query\n");
+		return -2;
+	}
+	return 0;
+
+ error:
+	LM_ERR("error while preparing replace operation\n");
+	return -1;
+}

+ 187 - 0
lib/srdb1/db_query.h

@@ -0,0 +1,187 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+/**
+ * \file db/db_query.h
+ * \brief Query helper for database drivers
+ * \ingroup db
+ *
+ * This helper methods for database queries are used from the database
+ * SQL driver to do the actual work. Each function uses some functions from
+ * the actual driver with function pointers to the concrete, specific
+ * implementation.
+*/
+
+#ifndef DB_QUERY_H
+#define DB_QUERY_H
+
+#include "db_key.h"
+#include "db_op.h"
+#include "db_val.h"
+#include "db_con.h"
+#include "db_row.h"
+#include "db_res.h"
+#include "db_cap.h"
+
+
+/**
+ * \brief Helper function for db queries
+ *
+ * This method evaluates the actual arguments for the database query and
+ * setups the string that is used for the query in the db module.
+ * Then its submit the query and stores the result if necessary. It uses for
+ * its work the implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _k key names, if not present the whole table will be returned
+ * \param _op operators
+ * \param _v values of the keys that must match
+ * \param _c column names that should be returned
+ * \param _n number of key/value pairs that are compared, if zero then no comparison is done
+ * \param _nc number of colums that should be returned
+ * \param _o order by the specificied column, optional
+ * \param _r the result that is returned, set to NULL if you want to use fetch_result later
+ * \param (*val2str) function pointer to the db specific val conversion function
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \param (*store_result) function pointer to the db specific store result function
+ * \return zero on success, negative on errors
+ */
+int db_do_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+	const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
+	const db_key_t _o, db_res_t** _r, int (*val2str) (const db_con_t*,
+	const db_val_t*, char*, int*), int (*submit_query)(const db_con_t* _h,
+	const str* _c), int (*store_result)(const db_con_t* _h, db_res_t** _r));
+
+
+/**
+ * \brief Helper function for raw db queries
+ *
+ * This method evaluates the actual arguments for the database raw query
+ * and setups the string that is used for the query in the db module.
+ * Then its submit the query and stores the result if necessary.
+ * It uses for its work the implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _s char holding the raw query
+ * \param _r the result that is returned
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \param (*store_result) function pointer to the db specific store result function
+ * \return zero on success, negative on errors
+ */
+int db_do_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r,
+	int (*submit_query)(const db_con_t* _h, const str* _c),
+	int (*store_result)(const db_con_t* _h, db_res_t** _r));
+
+
+/**
+ * \brief Helper function for db insert operations
+ *
+ * This method evaluates the actual arguments for the database operation
+ * and setups the string that is used for the insert operation in the db
+ * module. Then its submit the query for the operation. It uses for its work
+ * the implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _k key names
+ * \param _v values of the keys
+ * \param _n number of key/value pairs 
+ * \param (*val2str) function pointer to the db specific val conversion function
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \return zero on success, negative on errors
+ */
+int db_do_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+	const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*),
+	int (*submit_query)(const db_con_t* _h, const str* _c));
+
+
+/**
+ * \brief Helper function for db delete operations
+ *
+ * This method evaluates the actual arguments for the database operation
+ * and setups the string that is used for the delete operation in the db
+ * module. Then its submit the query for the operation. It uses for its work
+ * the implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _k key names
+ * \param _o operators
+ * \param _v values of the keys that must match
+ * \param _n number of key/value pairs that are compared, if zero then the whole table is deleted
+ * \param (*val2str) function pointer to the db specific val conversion function
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \return zero on success, negative on errors
+ */
+int db_do_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+	const db_val_t* _v, const int _n, int (*val2str) (const db_con_t*,
+	const db_val_t*, char*, int*), int (*submit_query)(const db_con_t* _h,
+	const str* _c));
+
+
+/**
+ * \brief Helper function for db update operations
+ *
+ * This method evaluates the actual arguments for the database operation
+ * and setups the string that is used for the update operation in the db
+ * module. Then its submit the query for the operation. It uses for its work
+ * the implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _k key names, if not present the whole table will be returned
+ * \param _o operators
+ * \param _v values of the keys that must match
+ * \param _uk: updated columns
+ * \param _uv: updated values of the columns
+ * \param _n number of key/value pairs that are compared, if zero then no comparison is done
+ * \param _un: number of columns that should be updated
+ * \param (*val2str) function pointer to the db specific val conversion function
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \return zero on success, negative on errors
+ */
+int db_do_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+	const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
+	const int _un, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*),
+	int (*submit_query)(const db_con_t* _h, const str* _c));
+
+
+/**
+ * \brief Helper function for db delete operations
+ *
+ * This helper method evaluates the actual arguments for the database operation
+ * and setups the string that is used for the replace operation in the db
+ * module. Then its submit the query for the operation. It uses for its work the
+ * implementation in the concrete database module.
+ *
+ * \param _h structure representing database connection
+ * \param _k key names, if not present the whole table will be returned
+ * \param _v values of the keys that must match
+ * \param _n number of key/value pairs that are compared, if zero then no comparison is done
+ * \param (*val2str) function pointer to the db specific val conversion function
+ * \param (*submit_query) function pointer to the db specific query submit function
+ * \return zero on success, negative on errors
+ */
+int db_do_replace(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+	const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*,
+	int*), int (*submit_query)(const db_con_t* _h, const str* _c));
+
+
+#endif

+ 186 - 0
lib/srdb1/db_res.c

@@ -0,0 +1,186 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_res.c
+ * \brief Functions to manage result structures
+ * \ingroup db
+ *
+ * Provides some convenience macros and some memory management
+ * functions for result structures.
+ */
+
+#include "db_res.h"
+
+#include "db_row.h"
+#include "../dprint.h"
+#include "../mem/mem.h"
+
+#include <string.h>
+
+/*
+ * Release memory used by rows
+ */
+inline int db_free_rows(db_res_t* _r)
+{
+	int i;
+
+	if (!_r) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+	LM_DBG("freeing %d rows\n", RES_ROW_N(_r));
+
+	for(i = 0; i < RES_ROW_N(_r); i++) {
+		db_free_row(&(RES_ROWS(_r)[i]));
+	}
+	RES_ROW_N(_r) = 0;
+
+	if (RES_ROWS(_r)) {
+		LM_DBG("freeing rows at %p\n", RES_ROWS(_r));
+		pkg_free(RES_ROWS(_r));
+		RES_ROWS(_r) = NULL;
+	}
+	return 0;
+}
+
+
+/*
+ * Release memory used by columns
+ */
+inline int db_free_columns(db_res_t* _r)
+{
+	int col;
+
+	if (!_r) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+	LM_DBG("freeing %d columns\n", RES_COL_N(_r));
+	/* free memory previously allocated to save column names */
+	for(col = 0; col < RES_COL_N(_r); col++) {
+		if (RES_NAMES(_r)[col]!=NULL) {
+			LM_DBG("freeing RES_NAMES[%d] at %p\n", col, RES_NAMES(_r)[col]);
+			pkg_free((str *)RES_NAMES(_r)[col]);
+			RES_NAMES(_r)[col] = NULL;
+		}
+	}
+	RES_COL_N(_r) = 0;
+
+	/* free names and types */
+	if (RES_NAMES(_r)) {
+		LM_DBG("freeing result names at %p\n", RES_NAMES(_r));
+		pkg_free(RES_NAMES(_r));
+		RES_NAMES(_r) = NULL;
+	}
+	if (RES_TYPES(_r)) {
+		LM_DBG("freeing result types at %p\n", RES_TYPES(_r));
+		pkg_free(RES_TYPES(_r));
+		RES_TYPES(_r) = NULL;
+	}
+	return 0;
+}
+
+/*
+ * Create a new result structure and initialize it
+ */
+inline db_res_t* db_new_result(void)
+{
+	db_res_t* r = NULL;
+	r = (db_res_t*)pkg_malloc(sizeof(db_res_t));
+	if (!r) {
+		LM_ERR("no private memory left\n");
+		return 0;
+	}
+	LM_DBG("allocate %d bytes for result set at %p\n",
+		(int)sizeof(db_res_t), r);
+	memset(r, 0, sizeof(db_res_t));
+	return r;
+}
+
+/*
+ * Release memory used by a result structure
+ */
+inline int db_free_result(db_res_t* _r)
+{
+	if (!_r)
+	{
+		LM_ERR("invalid parameter\n");
+		return -1;
+	}
+
+	db_free_columns(_r);
+	db_free_rows(_r);
+	LM_DBG("freeing result set at %p\n", _r);
+	pkg_free(_r);
+	_r = NULL;
+	return 0;
+}
+
+/*
+ * Allocate storage for column names and type in existing
+ * result structure.
+ */
+inline int db_allocate_columns(db_res_t* _r, const unsigned int cols)
+{
+	RES_NAMES(_r) = (db_key_t*)pkg_malloc(sizeof(db_key_t) * cols);
+	if (!RES_NAMES(_r)) {
+		LM_ERR("no private memory left\n");
+		return -1;
+	}
+	LM_DBG("allocate %d bytes for result names at %p\n",
+		(int)(sizeof(db_key_t) * cols),
+		RES_NAMES(_r));
+
+	RES_TYPES(_r) = (db_type_t*)pkg_malloc(sizeof(db_type_t) * cols);
+	if (!RES_TYPES(_r)) {
+		LM_ERR("no private memory left\n");
+		pkg_free(RES_NAMES(_r));
+		return -1;
+	}
+	LM_DBG("allocate %d bytes for result types at %p\n",
+		(int)(sizeof(db_type_t) * cols),
+		RES_TYPES(_r));
+
+	return 0;
+}
+
+
+/**
+ * Allocate memory for rows.
+ * \param _res result set
+ * \return zero on success, negative on errors
+ */
+inline int db_allocate_rows(db_res_t* _res)
+{
+	int len = sizeof(db_row_t) * RES_ROW_N(_res);
+	RES_ROWS(_res) = (struct db_row*)pkg_malloc(len);
+	if (!RES_ROWS(_res)) {
+		LM_ERR("no private memory left\n");
+		return -1;
+	}
+	LM_DBG("allocate %d bytes for rows at %p\n", len, RES_ROWS(_res));
+	memset(RES_ROWS(_res), 0, len);
+	
+	return 0;
+}

+ 131 - 0
lib/srdb1/db_res.h

@@ -0,0 +1,131 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_res.h
+ * \brief Data structure that represents a result from a query.
+ *
+ * Data structure that represents a result from a database query,
+ * it also provides some convenience macros and some memory management
+ * functions for result structures.
+ * \ingroup db
+ */
+
+#ifndef DB_RES_H
+#define DB_RES_H
+
+
+#include "db_key.h"
+#include "db_val.h"
+
+struct db_row;
+
+/**
+ * This type represents a result returned by db_query function (see below). The 
+ * result can consist of zero or more rows (see db_row_t description).
+ *
+ * Note: A variable of type db_res_t returned by db_query function uses dynamicaly
+ * allocated memory, don't forget to call db_free_result if you don't need the
+ * variable anymore. You will encounter memory leaks if you fail to do this!
+ *
+ * In addition to zero or more rows, each db_res_t object contains also an array
+ * of db_key_t objects. The objects represent keys (names of columns). *
+ */
+typedef struct db_res {
+	struct {
+		db_key_t* names;   /**< Column names                    */
+		db_type_t* types;  /**< Column types                    */
+		int n;             /**< Number of columns               */
+	} col;
+	struct db_row* rows;   /**< Rows                            */
+	int n;                 /**< Number of rows in current fetch */
+	int res_rows;          /**< Number of total rows in query   */
+	int last_row;          /**< Last row                        */
+} db_res_t;
+
+
+/** Return the column names */
+#define RES_NAMES(re) ((re)->col.names)
+/** Return the column types */
+#define RES_TYPES(re) ((re)->col.types)
+/** Return the number of columns */
+#define RES_COL_N(re) ((re)->col.n)
+/** Return the result rows */
+#define RES_ROWS(re)  ((re)->rows)
+/** Return the number of current result rows */
+#define RES_ROW_N(re) ((re)->n)
+/** Return the last row of the result */
+#define RES_LAST_ROW(re)  ((re)->last_row)
+/** Return the number of total result rows */
+#define RES_NUM_ROWS(re) ((re)->res_rows)
+
+
+/**
+ * Release memory used by rows in a result structure.
+ * \param _r the result that should be released
+ * \return zero on success, negative on errors
+ */
+inline int db_free_rows(db_res_t* _r);
+
+
+/**
+ * Release memory used by columns. This methods assumes that the string values
+ * holding the column names are in memory allocated from the database driver,
+ * and thus must be not freed here.
+ * \param _r the result that should be released
+ * \return zero on success, negative on errors
+ */
+inline int db_free_columns(db_res_t* _r);
+
+
+/**
+ * Create a new result structure and initialize it.
+ * \return a pointer to the new result on success, NULL on errors
+ */
+inline db_res_t* db_new_result(void);
+
+/**
+ * Release memory used by a result structure.
+ * \return zero on success, negative on errors
+ */
+inline int db_free_result(db_res_t* _r);
+
+/**
+ * Allocate storage for column names and type in existing result structure.
+ * If no more memory is available for the allocation of the types then the
+ * already allocated memory for the names is freed.
+ * \param _r filled result set
+ * \param cols number of columns
+ * \return zero on success, negative on errors
+ */
+inline int db_allocate_columns(db_res_t* _r, const unsigned int cols);
+
+
+/**
+ * Allocate memory for rows.
+ * \param _res result set
+ * \return zero on success, negative on errors
+ */
+inline int db_allocate_rows(db_res_t* _res);
+
+#endif /* DB_RES_H */

+ 126 - 0
lib/srdb1/db_row.c

@@ -0,0 +1,126 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_row.c
+ * \brief Type that represents a row in a database.
+ *
+ * This file holds a type that represents a row in a database, some convenience
+ * macros and a function for memory managements.
+ * \ingroup db
+ */
+
+#include "db_row.h"
+
+#include <string.h>
+#include "../dprint.h"
+#include "../mem/mem.h"
+
+/*
+ * Release memory used by row
+ */
+inline int db_free_row(db_row_t* _r)
+{
+	int col;
+	db_val_t* _val;
+
+	if (!_r) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	/*
+	 * Loop thru each columm, then check to determine if the storage pointed to
+	 * by db_val_t structure must be freed. This is required for all data types
+	 * which use a pointer to a buffer like DB_STRING, DB_STR and DB_BLOB and
+	 * the database module copied them during the assignment.
+	 * If this is not done, a memory leak will happen.
+	 * Don't try to free the static dummy string (as indicated from the NULL value),
+	 * as this is not valid.
+	 */
+	for (col = 0; col < ROW_N(_r); col++) {
+		_val = &(ROW_VALUES(_r)[col]);
+		switch (VAL_TYPE(_val)) {
+			case DB_STRING:
+				if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
+					LM_DBG("free VAL_STRING[%d] '%s' at %p\n", col,
+							(char *)VAL_STRING(_val),
+							(char *)VAL_STRING(_val));
+					pkg_free((char *)VAL_STRING(_val));
+					VAL_STRING(_val) = NULL;
+				}
+				break;
+			case DB_STR:
+				if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
+					LM_DBG("free VAL_STR[%d] '%.*s' at %p\n", col,
+							VAL_STR(_val).len,
+							VAL_STR(_val).s, VAL_STR(_val).s);
+					pkg_free(VAL_STR(_val).s);
+					VAL_STR(_val).s = NULL;
+				}
+				break;
+			case DB_BLOB:
+				if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
+					LM_DBG("free VAL_BLOB[%d] at %p\n", col, VAL_BLOB(_val).s);
+					pkg_free(VAL_BLOB(_val).s);
+					VAL_BLOB(_val).s = NULL;
+				}
+				break;
+			default:
+				break;
+		}
+	}
+	/* now as we freed all, set number of colums to zero again */
+	ROW_N(_r) = 0;
+
+	if (ROW_VALUES(_r)) {
+		LM_DBG("freeing row values at %p\n", ROW_VALUES(_r));
+		pkg_free(ROW_VALUES(_r));
+		ROW_VALUES(_r) = NULL;
+	}
+	return 0;
+}
+
+
+/**
+ * Allocate memory for row value.
+ * \param _res result set
+ * \param _row filled row
+ * \return zero on success, negative on errors
+ */
+inline int db_allocate_row(const db_res_t* _res, db_row_t* _row)
+{
+	int len = sizeof(db_val_t) * RES_COL_N(_res);
+	ROW_VALUES(_row) = (db_val_t*)pkg_malloc(len);
+	if (!ROW_VALUES(_row)) {
+		LM_ERR("no private memory left\n");
+		return -1;
+	}
+	LM_DBG("allocate %d bytes for row values at %p\n", len, ROW_VALUES(_row));
+
+	memset(ROW_VALUES(_row), 0, len);
+	/* Save the number of columns in the ROW structure */
+	ROW_N(_row) = RES_COL_N(_res);
+
+	return 0;
+}

+ 76 - 0
lib/srdb1/db_row.h

@@ -0,0 +1,76 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_row.h
+ * \brief Type that represents a row in a database.
+ *
+ * This file holds a type that represents a row in a database, some convenience
+ * macros and a function for memory managements.
+ * \ingroup db
+ */
+
+
+#ifndef DB_ROW_H
+#define DB_ROW_H
+
+#include "db_val.h"
+#include "db_res.h"
+
+
+/**
+ * Structure holding the result of a query table function.
+ * It represents one row in a database table. In other words, the row is an
+ * array of db_val_t variables, where each db_val_t variable represents exactly
+ * one cell in the table.
+ */
+typedef struct db_row {
+	db_val_t* values;  /**< Columns in the row */
+	int n;             /**< Number of columns in the row */
+} db_row_t;
+
+/** Return the columns in the row */
+#define ROW_VALUES(rw) ((rw)->values)
+/** Return the number of colums */
+#define ROW_N(rw)      ((rw)->n)
+
+/**
+ * Release memory used by a row. This method only frees values that are inside
+ * the row if the free flag of the specific value is set. Otherwise this
+ * storage must be released when the database specific result free function is
+ * called. Only string based values are freed if wanted, null values are skipped.
+ * \param _r row that should be released
+ * \return zero on success, negative on error
+ */
+inline int db_free_row(db_row_t* _r);
+
+
+/**
+ * Allocate memory for row value.
+ * \param _res result set
+ * \param _row filled row
+ * \return zero on success, negative on errors
+ */
+inline int db_allocate_row(const db_res_t* _res, db_row_t* _row);
+
+#endif /* DB_ROW_H */

+ 374 - 0
lib/srdb1/db_ut.c

@@ -0,0 +1,374 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_ut.c
+ * \brief Utility functions for database drivers.
+ *
+ * This utility methods are used from the database SQL driver to convert
+ * values and print SQL queries from the internal API representation.
+ * \ingroup db
+ */
+
+#include "db_ut.h"
+
+#include "../mem/mem.h"
+#include "../dprint.h"
+#include <limits.h>
+#include </usr/include/limits.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+inline int db_str2int(const char* _s, int* _v)
+{
+	long tmp;
+
+	if (!_s || !_v) {
+	       LM_ERR("Invalid parameter value\n");
+	       return -1;
+	}
+
+	tmp = strtoul(_s, 0, 10);
+	if ((tmp == ULONG_MAX && errno == ERANGE) || 
+	    (tmp < INT_MIN) || (tmp > UINT_MAX)) {
+		LM_ERR("Value out of range\n");
+		return -1;
+	}
+
+	*_v = (int)tmp;
+	return 0;
+}
+
+
+inline int db_str2longlong(const char* _s, long long * _v)
+{
+	long long tmp;
+
+	if (!_s || !_v) {
+	       LM_ERR("Invalid parameter value\n");
+	       return -1;
+	}
+
+	tmp = strtoll(_s, 0, 10);
+	if (errno == ERANGE) {
+		LM_ERR("Value out of range\n");
+		return -1;
+	}
+
+	*_v = tmp;
+	return 0;
+}
+
+
+/*
+ * Convert a string to double
+ */
+inline int db_str2double(const char* _s, double* _v)
+{
+	if ((!_s) || (!_v)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	*_v = atof(_s);
+	return 0;
+}
+
+
+
+/*
+ * Convert an integer to string
+ */
+inline int db_int2str(int _v, char* _s, int* _l)
+{
+	int ret;
+
+	if ((!_s) || (!_l) || (!*_l)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(_s, *_l, "%-d", _v);
+	if (ret < 0 || ret >= *_l) {
+		LM_ERR("Error in snprintf\n");
+		return -1;
+	}
+	*_l = ret;
+
+	return 0;
+}
+
+
+/*
+ * Convert an long long to string
+ */
+inline int db_longlong2str(long long _v, char* _s, int* _l)
+{
+	int ret;
+
+	if ((!_s) || (!_l) || (!*_l)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(_s, *_l, "%-lld", _v);
+	if (ret < 0 || ret >= *_l) {
+		LM_ERR("Error in snprintf\n");
+		return -1;
+	}
+	*_l = ret;
+
+	return 0;
+}
+
+
+/*
+ * Convert a double to string
+ */
+inline int db_double2str(double _v, char* _s, int* _l)
+{
+	int ret;
+
+	if ((!_s) || (!_l) || (!*_l)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(_s, *_l, "%-10.2f", _v);
+	if (ret < 0 || ret >= *_l) {
+		LM_ERR("Error in snprintf\n");
+		return -1;
+	}
+	*_l = ret;
+
+	return 0;
+}
+
+
+/* 
+ * Convert a string to time_t
+ */
+inline int db_str2time(const char* _s, time_t* _v)
+{
+	struct tm time;
+
+	if ((!_s) || (!_v)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	/* Convert database time representation to time_t structure
+	   It is necessary to zero tm structure first */
+	memset(&time, '\0', sizeof(struct tm));
+	if (strptime(_s, "%Y-%m-%d %H:%M:%S", &time) == NULL) {
+		LM_ERR("Error during time conversion\n");
+		return -1;
+	}
+
+	/* Daylight saving information got lost in the database
+	* so let mktime to guess it. This eliminates the bug when
+	* contacts reloaded from the database have different time
+	* of expiration by one hour when daylight saving is used
+	*/ 
+	time.tm_isdst = -1;
+	*_v = mktime(&time);
+
+	return 0;
+}
+
+
+inline int db_time2str(time_t _v, char* _s, int* _l)
+{
+	struct tm* t;
+	int l;
+
+	if ((!_s) || (!_l) || (*_l < 2)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	*_s++ = '\'';
+
+	/* Convert time_t structure to format accepted by the database */
+	t = localtime(&_v);
+	l = strftime(_s, *_l -1, "%Y-%m-%d %H:%M:%S", t);
+
+	if (l == 0) {
+		LM_ERR("Error during time conversion\n");
+		/* the value of _s is now unspecified */
+		_s = NULL;
+		_l = 0;
+		return -1;
+	}
+	*_l = l;
+
+	*(_s + l) = '\'';
+	*_l = l + 2;
+	return 0;
+}
+
+
+/*
+ * Print list of columns separated by comma
+ */
+inline int db_print_columns(char* _b, const int _l, const db_key_t* _c, const int _n)
+{
+	int i, ret, len = 0;
+
+	if ((!_c) || (!_n) || (!_b) || (!_l)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	for(i = 0; i < _n; i++)	{
+		if (i == (_n - 1)) {
+			ret = snprintf(_b + len, _l - len, "%.*s ", _c[i]->len, _c[i]->s);
+			if (ret < 0 || ret >= (_l - len)) goto error;
+			len += ret;
+		} else {
+			ret = snprintf(_b + len, _l - len, "%.*s,", _c[i]->len, _c[i]->s);
+			if (ret < 0 || ret >= (_l - len)) goto error;
+			len += ret;
+		}
+	}
+	return len;
+
+	error:
+	LM_ERR("Error in snprintf\n");
+	return -1;
+}
+
+
+/*
+ * Print values of SQL statement
+ */
+int db_print_values(const db_con_t* _c, char* _b, const int _l, const db_val_t* _v,
+	const int _n, int (*val2str)(const db_con_t*, const db_val_t*, char*, int*))
+{
+	int i, l, len = 0;
+
+	if (!_c || !_b || !_l || !_v || !_n) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	for(i = 0; i < _n; i++) {
+		l = _l - len;
+		if ( (*val2str)(_c, _v + i, _b + len, &l) < 0) {
+			LM_ERR("Error while converting value to string\n");
+			return -1;
+		}
+		len += l;
+		if (i != (_n - 1)) {
+			*(_b + len) = ',';
+			len++;
+		}
+	}
+	return len;
+}
+
+
+/*
+ * Print where clause of SQL statement
+ */
+int db_print_where(const db_con_t* _c, char* _b, const int _l, const db_key_t* _k,
+	const db_op_t* _o, const db_val_t* _v, const int _n, int (*val2str)
+	(const 	db_con_t*, const db_val_t*, char*, int*))
+{
+	int i, l, ret, len = 0;
+
+	if (!_c || !_b || !_l || !_k || !_v || !_n) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	for(i = 0; i < _n; i++) {
+		if (_o) {
+			ret = snprintf(_b + len, _l - len, "%.*s%s", _k[i]->len, _k[i]->s, _o[i]);
+			if (ret < 0 || ret >= (_l - len)) goto error;
+			len += ret;
+		} else {
+			ret = snprintf(_b + len, _l - len, "%.*s=", _k[i]->len, _k[i]->s);
+			if (ret < 0 || ret >= (_l - len)) goto error;
+			len += ret;
+		}
+		l = _l - len;
+		if ( (*val2str)(_c, &(_v[i]), _b + len, &l) < 0) {
+			LM_ERR("Error while converting value to string\n");
+			return -1;
+		}
+		len += l;
+		if (i != (_n - 1)) {
+			ret = snprintf(_b + len, _l - len, " AND ");
+			if (ret < 0 || ret >= (_l - len)) goto error;
+			len += ret;
+		}
+	}
+	return len;
+
+ error:
+	LM_ERR("Error in snprintf\n");
+	return -1;
+}
+
+
+/*
+ * Print set clause of update SQL statement
+ */
+int db_print_set(const db_con_t* _c, char* _b, const int _l, const db_key_t* _k,
+	const db_val_t* _v, const int _n, int (*val2str)(const db_con_t*,
+	const db_val_t*,char*, int*))
+{
+	int i, l, ret, len = 0;
+
+	if (!_c || !_b || !_l || !_k || !_v || !_n) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	for(i = 0; i < _n; i++) {
+		ret = snprintf(_b + len, _l - len, "%.*s=", _k[i]->len, _k[i]->s);
+		if (ret < 0 || ret >= (_l - len)) goto error;
+		len += ret;
+
+		l = _l - len;
+		if ( (*val2str)(_c, &(_v[i]), _b + len, &l) < 0) {
+			LM_ERR("Error while converting value to string\n");
+			return -1;
+		}
+		len += l;
+		if (i != (_n - 1)) {
+			if ((_l - len) >= 1) {
+				*(_b + len++) = ',';
+			}
+		}
+	}
+	return len;
+
+ error:
+	LM_ERR("Error in snprintf\n");
+	return -1;
+}

+ 209 - 0
lib/srdb1/db_ut.h

@@ -0,0 +1,209 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_ut.h
+ * \brief Utility functions for database drivers.
+ *
+ * This utility methods are used from the database SQL driver to convert
+ * values and print SQL queries from the internal API representation.
+ * \ingroup db
+*/
+
+#ifndef DB_UT_H
+#define DB_UT_H
+
+/**
+ * maximal SQL buffer length for database drivers
+ */
+#define SQL_BUF_LEN 65536
+
+/**
+ * make strptime available
+ * use 600 for 'Single UNIX Specification, Version 3'
+ * _XOPEN_SOURCE creates conflict in swab definition in Solaris
+ */
+#ifndef __OS_solaris
+	#define _XOPEN_SOURCE 600          /* glibc2 on linux, bsd */
+#else
+	#define _XOPEN_SOURCE_EXTENDED 1   /* solaris */
+#endif
+
+#include <time.h>
+
+#undef _XOPEN_SOURCE
+#undef _XOPEN_SOURCE_EXTENDED
+
+#include "db_key.h"
+#include "db.h"
+
+
+/**
+ * Converts a char into an integer value.
+ *
+ * \param _s source value
+ * \param _v target value
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_str2int(const char* _s, int* _v);
+
+
+/**
+ * Converts a char into an long long value.
+ *
+ * \param _s source value
+ * \param _v target value
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_str2longlong(const char* _s, long long* _v);
+
+
+/**
+ * Converts a char into a double value.
+ *
+ * \param _s source value
+ * \param _v target value
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_str2double(const char* _s, double* _v);
+
+
+/**
+ * Converts a integer value in a char pointer.
+ *
+ * \param _v source value
+ * \param _s target value
+ * \param _l available length and target length
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_int2str(int _v, char* _s, int* _l);
+
+
+/**
+ * Converts a long long value in a char pointer.
+ *
+ * \param _v source value
+ * \param _s target value
+ * \param _l available length and target length
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_longlong2str(long long _v, char* _s, int* _l);
+
+
+/**
+ * Converts a double value into a char pointer.
+ *
+ * \param _v source value
+ * \param _s target value
+ * \param _l available length and target length
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_double2str(double _v, char* _s, int* _l);
+
+
+/**
+ * Convert a time_t value to string.
+ *
+ * \param _v source value
+ * \param _s target value
+ * \param _l available length and target length
+ * \return zero on sucess, negative on conversion errors
+ * \todo This functions add quotes to the time value. This
+ * should be done in the val2str function, as some databases
+ * like db_berkeley don't need or like this at all.
+ */
+int db_time2str(time_t _v, char* _s, int* _l);
+
+
+/**
+ * Converts a char into a time_t value.
+ *
+ * \param _s source value
+ * \param _v target value
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_str2time(const char* _s, time_t* _v);
+
+
+/**
+ * Print columns for a SQL statement, separated by commas.
+ *
+ * \param _b target char
+ * \param _l length of the target
+ * \param _c keys that should be printed
+ * \param _n number of keys
+ * \return the length of the printed result on success, negative on errors
+ */
+int db_print_columns(char* _b, const int _l, const db_key_t* _c, const int _n);
+
+
+/**
+ * Print values for a SQL statement.
+ *
+ * \param _c structure representing database connection
+ * \param _b target char
+ * \param _l length of the target
+ * \param _v values that should be printed
+ * \param _n number of values
+ * \param  (*val2str) function pointer to a db specific conversion function
+ * \return the length of the printed result on success, negative on errors
+ */
+int db_print_values(const db_con_t* _c, char* _b, const int _l, const db_val_t* _v,
+	const int _n, int (*val2str)(const db_con_t*, const db_val_t*, char*, int*));
+
+
+/**
+ * Print where clause for a SQL statement.
+ *
+ * \param _c structure representing database connection
+ * \param _b target char
+ * \param _l length of the target
+ * \param _k keys that should be printed
+ * \param _o optional operators
+ * \param _v values that should be printed
+ * \param _n number of key/value pairs
+ * \param  (*val2str) function pointer to a db specific conversion function
+ * \return the length of the printed result on success, negative on errors
+ */
+int db_print_where(const db_con_t* _c, char* _b, const int _l, const db_key_t* _k,
+	const db_op_t* _o, const db_val_t* _v, const int _n, int (*val2str)
+	(const 	db_con_t*, const db_val_t*, char*, int*));
+
+
+/**
+ * Print set clause for a SQL statement.
+ *
+ * \param _c structure representing database connection
+ * \param _b target char
+ * \param _l length of the target
+ * \param _k keys that should be printed
+ * \param _v vals that should be printed
+ * \param _n number of key/value pairs
+ * \param  (*val2str) function pointer to a db specific conversion function
+ * \return the length of the printed result on success, negative on errors
+ */
+int db_print_set(const db_con_t* _c, char* _b, const int _l,
+	const db_key_t* _k, const db_val_t* _v, const int _n, int (*val2str)
+	(const db_con_t*, const db_val_t*, char*, int*));
+
+#endif

+ 267 - 0
lib/srdb1/db_val.c

@@ -0,0 +1,267 @@
+/*
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2008-2009 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "db_ut.h"
+
+#include <stdio.h>
+#include <time.h>
+
+/*!
+ * \brief Convert a str to a db value
+ *
+ * Convert a str to a db value, copy strings if _cpy is not zero.
+ * Copying is not necessary if the result from the database client library
+ * is freed after the result inside the server is processed. If the result
+ * is freed earlier, e.g. because its saved inside some temporary storage,
+ * then it must be copied in order to be use it reliable.
+ *
+ * \param _t destination value type
+ * \param _v destination value
+ * \param _s source string
+ * \param _l string length
+ * \param _cpy when set to zero does not copy strings, otherwise copy strings
+ * \return 0 on success, negative on error
+ */
+int db_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l,
+		const unsigned int _cpy)
+{
+	static str dummy_string = {"", 0};
+	
+	if (!_v) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+	/* A NULL string is a SQL NULL value, otherwise its an empty value */
+	if (!_s) {
+		LM_DBG("converting NULL value");
+		memset(_v, 0, sizeof(db_val_t));
+			/* Initialize the string pointers to a dummy empty
+			 * string so that we do not crash when the NULL flag
+			 * is set but the module does not check it properly
+			 */
+		VAL_STRING(_v) = dummy_string.s;
+		VAL_STR(_v) = dummy_string;
+		VAL_BLOB(_v) = dummy_string;
+		VAL_TYPE(_v) = _t;
+		VAL_NULL(_v) = 1;
+		return 0;
+	}
+	VAL_NULL(_v) = 0;
+
+	switch(_t) {
+	case DB_INT:
+		LM_DBG("converting INT [%s]\n", _s);
+		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
+			LM_ERR("error while converting integer value from string\n");
+			return -2;
+		} else {
+			VAL_TYPE(_v) = DB_INT;
+			return 0;
+		}
+		break;
+
+	case DB_BIGINT:
+		LM_DBG("converting BIGINT [%s]\n", _s);
+		if (db_str2longlong(_s, &VAL_BIGINT(_v)) < 0) {
+			LM_ERR("error while converting big integer value from string\n");
+			return -3;
+		} else {
+			VAL_TYPE(_v) = DB_BIGINT;
+			return 0;
+		}
+		break;
+
+	case DB_BITMAP:
+		LM_DBG("converting BITMAP [%s]\n", _s);
+		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
+			LM_ERR("error while converting bitmap value from string\n");
+			return -4;
+		} else {
+			VAL_TYPE(_v) = DB_BITMAP;
+			return 0;
+		}
+		break;
+	
+	case DB_DOUBLE:
+		LM_DBG("converting DOUBLE [%s]\n", _s);
+		if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) {
+			LM_ERR("error while converting double value from string\n");
+			return -5;
+		} else {
+			VAL_TYPE(_v) = DB_DOUBLE;
+			return 0;
+		}
+		break;
+
+	case DB_STRING:
+		LM_DBG("converting STRING [%s]\n", _s);
+
+		if (_cpy == 0) {
+			VAL_STRING(_v) = _s;
+		} else {
+			VAL_STRING(_v) = pkg_malloc(_l + 1);
+			if (VAL_STRING(_v) == NULL) {
+				LM_ERR("no private memory left\n");
+				return -6;
+			}
+			LM_DBG("allocate %d bytes memory for STRING at %p", _l + 1, VAL_STRING(_v));
+			strncpy((char*)VAL_STRING(_v), _s, _l);
+			((char*)VAL_STRING(_v))[_l] = '\0';
+			VAL_FREE(_v) = 1;
+		}
+
+		VAL_TYPE(_v) = DB_STRING;
+		return 0;
+
+	case DB_STR:
+		LM_DBG("converting STR [%.*s]\n", _l, _s);
+
+		if (_cpy == 0) {
+			VAL_STR(_v).s = (char*) _s;
+		} else {
+			VAL_STR(_v).s = pkg_malloc(_l);
+			if (VAL_STR(_v).s == NULL) {
+				LM_ERR("no private memory left\n");
+				return -7;
+			}
+			LM_DBG("allocate %d bytes memory for STR at %p", _l, VAL_STR(_v).s);
+			strncpy(VAL_STR(_v).s, _s, _l);
+			VAL_FREE(_v) = 1;
+		}
+
+		VAL_STR(_v).len = _l;
+		VAL_TYPE(_v) = DB_STR;
+		return 0;
+
+	case DB_DATETIME:
+		LM_DBG("converting DATETIME [%s]\n", _s);
+		if (db_str2time(_s, &VAL_TIME(_v)) < 0) {
+			LM_ERR("error while converting datetime value from string\n");
+			return -8;
+		} else {
+			VAL_TYPE(_v) = DB_DATETIME;
+			return 0;
+		}
+		break;
+
+	case DB_BLOB:
+		LM_DBG("converting BLOB [%.*s]\n", _l, _s);
+
+		if (_cpy == 0) {
+			VAL_BLOB(_v).s = (char*) _s;
+		} else {
+			VAL_BLOB(_v).s = pkg_malloc(_l);
+			if (VAL_BLOB(_v).s == NULL) {
+				LM_ERR("no private memory left\n");
+				return -9;
+			}
+			LM_DBG("allocate %d bytes memory for BLOB at %p", _l, VAL_BLOB(_v).s);
+			strncpy(VAL_BLOB(_v).s, _s, _l);
+			VAL_FREE(_v) = 1;
+		}
+
+		VAL_BLOB(_v).len = _l;
+		VAL_TYPE(_v) = DB_BLOB;
+		return 0;
+	}
+	return -10;
+}
+
+
+/*!
+ * \brief Convert a numerical value to a string
+ *
+ * Convert a numerical value to a string, used when converting result from a query.
+ * Implement common functionality needed from the databases, does parameter checking.
+ * \param _c database connection
+ * \param _v source value
+ * \param _s target string
+ * \param _len target string length
+ * \return 0 on success, negative on error, 1 if value must be converted by other means
+ */
+int db_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
+{
+	if (!_c || !_v || !_s || !_len || !*_len) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
+	if (VAL_NULL(_v)) {
+		if (*_len < sizeof("NULL")) {
+			LM_ERR("buffer too small\n");
+			return -1;
+		}
+		*_len = snprintf(_s, *_len, "NULL");
+		return 0;
+	}
+	
+	switch(VAL_TYPE(_v)) {
+	case DB_INT:
+		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
+			LM_ERR("error while converting string to int\n");
+			return -2;
+		} else {
+			return 0;
+		}
+		break;
+
+	case DB_BIGINT:
+		if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) {
+			LM_ERR("error while converting string to big int\n");
+			return -3;
+		} else {
+			return 0;
+		}
+		break;
+
+	case DB_BITMAP:
+		if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
+			LM_ERR("error while converting string to int\n");
+			return -4;
+		} else {
+			return 0;
+		}
+		break;
+
+	case DB_DOUBLE:
+		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
+			LM_ERR("error while converting string to double\n");
+			return -5;
+		} else {
+			return 0;
+		}
+		break;
+
+	case DB_DATETIME:
+		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
+			LM_ERR("failed to convert string to time_t\n");
+			return -8;
+		} else {
+			return 0;
+		}
+		break;
+
+	default:
+		return 1;
+	}
+}

+ 198 - 0
lib/srdb1/db_val.h

@@ -0,0 +1,198 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007-2008 1&1 Internet AG
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ * \file db/db_val.h
+ * \brief Data structures that represents values in the database.
+ *
+ * This file defines data structures that represents values in the database.
+ * Several datatypes are recognized and converted by the database API.
+ * Available types: DB_INT, DB_DOUBLE, DB_STRING, DB_STR, DB_DATETIME, DB_BLOB and DB_BITMAP
+ * It also provides some macros for convenient access to this values,
+ * and a function to convert a str to a value.
+ * \ingroup db
+ */
+
+
+#ifndef DB_VAL_H
+#define DB_VAL_H
+
+#include "db_con.h"
+#include <time.h>
+#include "../str.h"
+
+
+/**
+ * Each cell in a database table can be of a different type. To distinguish
+ * among these types, the db_type_t enumeration is used. Every value of the
+ * enumeration represents one datatype that is recognized by the database
+ * API.
+ */
+typedef enum {
+	DB_INT,        /**< represents an 32 bit integer number      */
+	DB_BIGINT,     /**< represents an 64 bit integer number      */
+	DB_DOUBLE,     /**< represents a floating point number       */
+	DB_STRING,     /**< represents a zero terminated const char* */
+	DB_STR,        /**< represents a string of 'str' type        */
+	DB_DATETIME,   /**< represents date and time                 */
+	DB_BLOB,       /**< represents a large binary object         */
+	DB_BITMAP      /**< an one-dimensional array of 32 flags     */
+} db_type_t;
+
+
+/**
+ * This structure represents a value in the database. Several datatypes are
+ * recognized and converted by the database API. These datatypes are automaticaly
+ * recognized, converted from internal database representation and stored in the
+ * variable of corresponding type.
+ *
+ * Module that want to use this values needs to copy them to another memory
+ * location, because after the call to free_result there are not more available.
+ *
+ * If the structure holds a pointer to a string value that needs to be freed
+ * because the module allocated new memory for it then the free flag must
+ * be set to a non-zero value. A free flag of zero means that the string
+ * data must be freed internally by the database driver.
+ */
+typedef struct {
+	db_type_t type; /**< Type of the value                              */
+	int nul;		/**< Means that the column in database has no value */
+	int free;		/**< Means that the value should be freed */
+	/** Column value structure that holds the actual data in a union.  */
+	union {
+		int           int_val;    /**< integer value              */
+		long long     ll_val;     /**< long long value            */
+		double        double_val; /**< double value               */
+		time_t        time_val;   /**< unix time_t value          */
+		const char*   string_val; /**< zero terminated string     */
+		str           str_val;    /**< str type string value      */
+		str           blob_val;   /**< binary object data         */
+		unsigned int  bitmap_val; /**< Bitmap data type           */
+	} val;
+} db_val_t;
+
+
+/**
+ * Useful macros for accessing attributes of db_val structure.
+ * All macros expect a reference to a db_val_t variable as parameter.
+ */
+
+/**
+ * Use this macro if you need to set/get the type of the value.
+ */
+#define VAL_TYPE(dv)   ((dv)->type)
+
+
+/**
+ * Use this macro if you need to set/get the null flag. A non-zero flag means that
+ * the corresponding cell in the database contains no data (a NULL value in MySQL
+ * terminology).
+ */
+#define VAL_NULL(dv)   ((dv)->nul)
+
+
+/**
+ * Use this macro if you need to set/ get the free flag. A non-zero flag means that
+ * the corresponding cell in the database contains data that must be freed from the
+ * DB API.
+ */
+#define VAL_FREE(dv)   ((dv)->free)
+
+
+/**
+ * Use this macro if you need to access the integer value in the db_val_t structure.
+ */
+#define VAL_INT(dv)    ((dv)->val.int_val)
+
+
+/**
+ * Use this macro if you need to access the long long value in the db_val_t structure.
+ */
+#define VAL_BIGINT(dv)    ((dv)->val.ll_val)
+
+
+/**
+ * Use this macro if you need to access the double value in the db_val_t structure.
+ */
+#define VAL_DOUBLE(dv) ((dv)->val.double_val)
+
+
+/**
+ * Use this macro if you need to access the time_t value in the db_val_t structure.
+ */
+#define VAL_TIME(dv)   ((dv)->val.time_val)
+
+
+/**
+ * Use this macro if you need to access the string value in the db_val_t structure.
+ */
+#define VAL_STRING(dv) ((dv)->val.string_val)
+
+
+/**
+ * Use this macro if you need to access the str structure in the db_val_t structure.
+ */
+#define VAL_STR(dv)    ((dv)->val.str_val)
+
+
+/**
+ * Use this macro if you need to access the blob value in the db_val_t structure.
+ */
+#define VAL_BLOB(dv)   ((dv)->val.blob_val)
+
+
+/**
+ * Use this macro if you need to access the bitmap value in the db_val_t structure.
+ */
+#define VAL_BITMAP(dv) ((dv)->val.bitmap_val)
+
+
+/*!
+ * \brief Convert a str to a db value
+ *
+ * Convert a str to a db value, does not copy strings if _cpy is zero
+ * \param _t destination value type
+ * \param _v destination value
+ * \param _s source string
+ * \param _l string length
+ * \param _cpy when set to zero does not copy strings, otherwise copy strings
+ * \return 0 on success, negative on error
+ */
+int db_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l,
+		const unsigned int _cpy);
+
+
+/*!
+ * \brief Convert a numerical value to a string
+ *
+ * Convert a numerical value to a string, used when converting result from a query.
+ * Implement common functionality needed from the databases, does parameter checking.
+ * \param _c database connection
+ * \param _v source value
+ * \param _s target string
+ * \param _len target string length
+ * \return 0 on success, negative on error, 1 if value must be converted by other means
+ */
+int db_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len);
+
+#endif /* DB_VAL_H */

+ 221 - 0
lib/srdb1/schema/Makefile

@@ -0,0 +1,221 @@
+#
+# $Id$
+#
+
+# Kamailio database descriptions for modules
+TABLES := $(patsubst kamailio-%.xml,%,$(wildcard kamailio-*.xml))
+
+ROOT=../..
+STYLESHEETS=$(ROOT)/doc/dbschema/xsl
+
+# Stylesheet used to generate MySQL database schema
+MYSQL_XSL = $(STYLESHEETS)/mysql.xsl
+
+# Stylesheet used to generate Postgres database schema
+POSTGRES_XSL = $(STYLESHEETS)/postgres.xsl
+
+# Stylesheet used to generate dbtext database schema
+DBTEXT_XSL = $(STYLESHEETS)/dbtext.xsl
+
+# Stylesheet used to generate berkeley database schema
+DB_BERKELEY_XSL = $(STYLESHEETS)/db_berkeley.xsl
+
+# Stylesheet used to generate oracle database schema
+ORACLE_XSL = $(STYLESHEETS)/oracle.xsl
+
+# Stylesheet used to generate docbook documentation
+DOCBOOK_XSL = $(STYLESHEETS)/docbook.xsl
+
+# Stylesheet used to generate modules templates header
+MODULES_H_XSL = $(STYLESHEETS)/modules_h.xsl
+
+# Stylesheet used to generate modules templates implementation
+MODULES_C_XSL = $(STYLESHEETS)/modules_c.xsl
+
+# Stylesheet used to generate modules documentation
+DBDOC_XSL = $(STYLESHEETS)/dbdoc.xsl
+
+# Enable/disable DTD validation
+VALIDATE = 0
+
+# Enable/disable verbose output (and DTD validation)
+VERBOSE = 0
+
+# XML Catalog used to resolve entities
+CATALOG = $(ROOT)/doc/dbschema/catalog.xml
+
+XSLTPROC = /usr/bin/xsltproc
+XSLTPROC_FLAGS = --xinclude
+
+ifeq ($(VALIDATE), 0)
+	override XSLTPROC := $(XSLTPROC) --novalid
+endif
+
+ifeq ($(VERBOSE), 1)
+	override XSLTPROC := $(XSLTPROC) --verbose
+endif
+
+all: mysql postgres dbtext db_berkeley docbook oracle #modules dbdoc
+
+.PHONY: mysql mysql_clean
+mysql:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/scripts/mysql" \
+		--stringparam prefix "$$FILE-" \
+		--stringparam db "mysql" \
+		$(MYSQL_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+mysql_clean:
+	-@rm -f $(ROOT)/scripts/mysql/*
+
+.PHONY: postgres postgres_clean
+postgres:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/scripts/postgres" \
+		--stringparam prefix "$$FILE-" \
+		--stringparam db "postgres" \
+		$(POSTGRES_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+postgres_clean:
+	-@rm -f $(ROOT)/scripts/postgres/*
+
+.PHONY: oracle oracle_clean
+oracle:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/scripts/oracle" \
+		--stringparam prefix "$$FILE-" \
+		--stringparam db "oracle" \
+		$(ORACLE_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+oracle_clean:
+	-@rm -f $(ROOT)/scripts/oracle/*.sql
+
+.PHONY: dbtext dbtext_clean
+dbtext:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/scripts/dbtext/kamailio" \
+		--stringparam prefix "" \
+		--stringparam db "dbtext" \
+		$(DBTEXT_XSL) kamailio-"$$FILE".xml ; \
+	done
+	TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+	# small hack to create the version table entries, this is here easier as with XSL
+	for FILE in  $(wildcard $(ROOT)/scripts/dbtext/kamailio/*) ; do \
+		if [ -f "$$FILE" ]; then \
+			if [  "$$FILE" != "$(ROOT)/scripts/dbtext/kamailio/version" ]; then \
+				tail -n 1 "$$FILE" >> "$(ROOT)/scripts/dbtext/kamailio/version" ; \
+ 				head -n 1 "$$FILE" > $TMPFILE ; \
+				cp $TMPFILE "$$FILE" ; \
+			fi ; \
+		fi ; \
+	done ; \
+	rm -f $TMPFILE
+
+dbtext_clean:
+	-@rm -f $(ROOT)/scripts/dbtext/kamailio/*
+
+.PHONY: db_berkeley db_berkeley_clean
+db_berkeley:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/scripts/db_berkeley/kamailio" \
+		--stringparam prefix "" \
+		--stringparam db "db_berkeley" \
+		$(DB_BERKELEY_XSL) kamailio-"$$FILE".xml ; \
+	done
+	TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+	# small hack to create the version table entries, this is here easier as with XSL
+	for FILE in  $(wildcard $(ROOT)/scripts/db_berkeley/kamailio/*) ; do \
+		if [ -f "$$FILE" ]; then \
+			if [  "$$FILE" != "$(ROOT)/scripts/db_berkeley/kamailio/version" ]; then \
+				tail -n 2 "$$FILE" >> "$(ROOT)/scripts/db_berkeley/kamailio/version" ; \
+ 				head -n 10 "$$FILE" > $TMPFILE ; \
+				cp $TMPFILE "$$FILE" ; \
+			fi ; \
+		fi ; \
+	done ; \
+	rm -f $TMPFILE
+
+db_berkeley_clean:
+	-@rm -f $(ROOT)/scripts/db_berkeley/kamailio/*
+
+
+.PHONY: docbook docbook_clean
+docbook:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/doc/database" \
+		--stringparam prefix "$$FILE-" \
+		$(DOCBOOK_XSL) kamailio-"$$FILE".xml ; \
+	done ; \
+
+	# link all documents to one file, to get nicer output
+	echo "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V4.4//EN\" \"http://www.oasis-open.org/docbook/sgml/4.4/docbook.dtd\"[" > "$(ROOT)/doc/database/tables.sgml"
+	
+	# create entities, as xi:include is not available in sgml docbook
+	# substitute '-' for '_', docbook smgl don't like this
+	for FILE in $(wildcard $(ROOT)/doc/database/*.xml); do \
+		echo "  <!ENTITY `basename "$$FILE" | sed -e 's#_#-#g'` SYSTEM \""$$FILE"\">" >> "$(ROOT)/doc/database/tables.sgml" ; \
+	done ; \
+	#Include general documentation entities
+	echo "  <!ENTITY % docentities SYSTEM \"../entities.xml\"> %docentities;" >> "$(ROOT)/doc/database/tables.sgml" ; \
+	echo "]>" >> "$(ROOT)/doc/database/tables.sgml"
+	# add bookinfo
+	cat "$(ROOT)/doc/dbschema/bookinfo.xml" >> "$(ROOT)/doc/database/tables.sgml"
+	# actually include the entities
+	for FILE in $(wildcard $(ROOT)/doc/database/*.xml); do \
+		echo "    &`basename "$$FILE" | sed -e 's#_#-#g'`" >> "$(ROOT)/doc/database/tables.sgml" ; \
+	done ; \
+	echo "</book>" >> "$(ROOT)/doc/database/tables.sgml"
+
+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)/modules/$$FILE/" \
+		--stringparam prefix "$$FILE" \
+		--stringparam db "modules" \
+		$(MODULES_H_XSL) kamailio-"$$FILE".xml ; \
+	done
+	
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/modules/$$FILE/" \
+		--stringparam prefix "$$FILE" \
+		--stringparam db "modules" \
+		$(MODULES_C_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+modules_clean:
+	for FILE in $(TABLES); do \
+		rm -f $(ROOT)/modules/$$FILE/db_*.c; \
+		rm -f $(ROOT)/modules/$$FILE/db_*.h; \
+	done
+
+dbdoc:
+	for FILE in $(TABLES); do \
+		XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
+		--stringparam dir "$(ROOT)/modules/$$FILE/doc/" \
+		--stringparam prefix "$$FILE" \
+		--stringparam db "modules" \
+		$(DBDOC_XSL) kamailio-"$$FILE".xml ; \
+	done
+
+dbdoc_clean:
+	for FILE in $(TABLES); do \
+		rm -f $(ROOT)/modules/$$FILE/doc/*_db.xml; \
+	done
+
+.PHONY: clean
+clean: mysql_clean postgres_clean oracle_clean dbtext_clean db_berkeley_clean docbook_clean # modules_clean dbdoc_clean

+ 88 - 0
lib/srdb1/schema/acc.xml

@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="acc" xmlns:db="http://docbook.org/ns/docbook">
+    <name>acc</name>
+    <version>4</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the ACC module to report on transactions - accounted calls. More information is available at: &KAMAILIO_MOD_DOC;acc.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column>
+        <name>method</name>
+        <type>string</type>
+        <size>&method_len;</size>
+        <description>A method is the primary function that a request is meant to invoke on a server.</description>
+        <default/>
+    </column>
+
+    <column>
+        <name>from_tag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The tag parameter serves as a general mechanism to identify a dialog, which is the combination of the Call-ID along with two tags, one from participant in the dialog.</description>
+    </column>
+
+    <column>
+        <name>to_tag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The tag parameter serves as a general mechanism to identify a dialog, which is the combination of the Call-ID along with two tags, one from participant in the dialog.</description>
+    </column>
+
+    <column id="callid">
+        <name>callid</name>
+        <type>string</type>
+        <natural/>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Call-ID header field uniquely identifies a particular invitation or all registrations of a particular client. </description>
+    </column>
+
+    <column>
+        <name>sip_code</name>
+        <type>string</type>
+        <size>&sip_code_len;</size>
+        <default/>
+        <description>SIP reply code</description>
+    </column>
+
+    <column>
+        <name>sip_reason</name>
+        <type>string</type>
+        <size>&sip_reason_len;</size>
+        <default/>
+        <description>SIP reply reason</description>
+    </column>
+
+    <column>
+        <name>time</name>
+        <type>datetime</type>
+        <description>Date and time when this record was written.</description>
+    </column>
+
+    <index>
+        <name>callid_idx</name>
+        <colref linkend="callid"/>
+    </index>
+</table>

+ 59 - 0
lib/srdb1/schema/address.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="address" xmlns:db="http://docbook.org/ns/docbook">
+    <name>address</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the permissions module. More information is available at: &KAMAILIO_MOD_DOC;permissions.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column>
+        <name>grp</name>
+        <type>unsigned short</type>
+        <size>5</size>
+        <default>0</default>
+        <description>Group</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>ip_addr</name>
+        <type>string</type>
+        <size>15</size>
+        <description>IP address</description>
+    </column>
+
+    <column>
+        <name>mask</name>
+        <type>char</type>
+        <default>32</default>
+        <description>Network mask</description>
+    </column>
+
+    <column>
+        <name>port</name>
+        <type>unsigned short</type>
+        <size>5</size>
+        <default>0</default>
+        <description>Port</description>
+    </column>
+</table>

+ 163 - 0
lib/srdb1/schema/aliases.xml

@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="aliases" xmlns:db="http://docbook.org/ns/docbook">
+    <name>aliases</name>
+    <version>1004</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table for the registrar module is similar to the "location" table, (the aliases index makes lookup of missed calls much faster). Thus, the function lookup("alias") can be used to map aliases to AORs. More information is available at: &KAMAILIO_MOD_DOC;registrar.html. Most people uses the dbaliases table with the alias_db module now.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <natural/>
+        <description>Alias Username / Phone Number </description>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+		<null/>
+		<default><null/></default>
+        <natural/>
+        <description>Domain name</description>
+    </column>
+
+    <column id="contact">
+        <name>contact</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default/>
+        <description>Contact header field value provides a URI whoses meaning depends on the type of request or response it is in.</description>
+    </column>
+
+    <column>
+        <name>received</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Received IP:PORT in the format SIP:IP:PORT</description>
+    </column>
+
+    <column>
+        <name>path</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Path Header(s) per RFC 3327</description>
+    </column>
+
+    <column>
+        <name>expires</name>
+        <type>datetime</type>
+        <default>&DEFAULT_ALIASES_EXPIRES;</default>
+        <default db="oracle">to_date('&DEFAULT_ALIASES_EXPIRES;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this entry expires.</description>
+    </column>
+
+    <column>
+        <name>q</name>
+        <type>float</type>
+        <size>10,2</size>
+        <default>&DEFAULT_Q;</default>
+        <description>Value used for preferential routing.</description>
+    </column>
+
+    <column>
+        <name>callid</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default>&DEFAULT_CALLID;</default>
+        <description>Call-ID header field uniquely identifies a particular invitation or all registrations of a particular client.</description>
+    </column>
+
+    <column>
+        <name>cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <default>&DEFAULT_CSEQ;</default>
+        <description>CSeq header field contains a single decimal sequence number and the request method.</description>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this entry was last modified.</description>
+    </column>
+
+    <column>
+        <name>flags</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <default>0</default>
+        <description>Flags</description>
+    </column>
+
+    <column>
+        <name>cflags</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <default>0</default>
+        <description>CFlags</description>
+    </column>
+
+    <column>
+        <name>user_agent</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default/>
+        <description>User-Agent header field contains information about the UAC originating the request.</description>
+    </column>
+
+    <column>
+        <name>socket</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Socket used to connect to Kamailio. For example: UDP:IP:PORT</description>
+    </column>
+
+    <column>
+        <name>methods</name>
+        <type>int</type>
+        <size>11</size>
+        <null/>
+        <default><null/></default>
+        <description>Flags that indicate the SIP Methods this contact will accept.</description>
+    </column>
+
+    <index>
+        <name>alias_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="contact"/>
+    </index>
+
+</table>

+ 39 - 0
lib/srdb1/schema/carrier_name.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+	  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+	  
+	  <!ENTITY % entities SYSTEM "entities.xml">
+	  %entities;
+	  
+	  ]>
+	  
+	  <table id="carrier_name" xmlns:db="http://docbook.org/ns/docbook">
+		  <name>carrier_name</name>
+		  <version>1</version>
+		  <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+		  <description>
+			  <db:para>This table is used by the carrierroute module to provides routing, balancing and blacklisting capabilities. It contains the existing carriers, consisting of the ids and corresponding names. More
+			  information is available at: &KAMAILIO_MOD_DOC;carrierroute.html
+			  </db:para>
+		  </description>
+		  
+		  <column id="id">
+			  <name>id</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <natural/>
+			  <autoincrement/>
+			  <primary/>
+			  <type db="dbtext">int,auto</type>
+			  <description>Name of the column containing the unique identifier of a carrier.</description>
+		  </column>
+		  
+		  <column>
+			  <name>carrier</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <null/>
+			  <default><null/></default>
+			  <description>This column contains the carrier name.</description>
+		  </column>
+	  </table>

+ 112 - 0
lib/srdb1/schema/carrierfailureroute.xml

@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+	  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+	  
+	  <!ENTITY % entities SYSTEM "entities.xml">
+	  %entities;
+	  
+	  ]>
+	  
+	  <table id="carrierfailureroute" xmlns:db="http://docbook.org/ns/docbook">
+		  <name>carrierfailureroute</name>
+		  <version>2</version>
+		  <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+		  <description>
+			  <db:para>This table is used by the carrierroute module to provide failure routing capabilities. It contains the 
+			  failureroute routing informations. More information is available at: http://www.kamailio.org/docs/modules/devel/carrierroute.html
+			  </db:para>
+		  </description>
+		  
+		  <column id="id">
+			  <name>id</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <autoincrement/>
+			  <primary/>
+			  <type db="dbtext">int,auto</type>
+			  <description>This column contains the unique identifier of a failure route.</description>
+		  </column>
+		  
+		  <column>
+			  <name>carrier</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <default>0</default>
+			  <natural/>
+			  <description>This column contains the carrier id.</description>
+		  </column>
+		  
+		  <column>
+			  <name>domain</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <default>0</default>
+			  <natural/>
+			  <description>This column contains the routing domain id. You can define several routing domains
+			  to have different routing rules. Maybe you use domain 0 for normal routing and domain 1 if
+			  domain 0 failed.</description>
+		  </column>
+		  
+		  <column>
+			  <name>scan_prefix</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <default/>
+			  <description>Name of column contains the the scan prefixes. Scan prexies define the matching
+			  portion of a phone number, e.g. we have the scan prefixes 49721 and 49, the called number is
+			  49721913740, it matches 49721, because the longest match is taken. If no prefix matches,
+			  the number is not failure routed. To prevent this, an empty prefix value of <quote></quote>
+			  could be added.</description>
+		  </column>
+		  
+		  <column>
+			  <name>host_name</name>
+			  <type>string</type>
+			  <size>&uri_len;</size>
+			  <default/>
+			  <description>Name of the column containing the host name of the last routing destination,
+			  using for rules matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>reply_code</name>
+			  <type>string</type>
+			  <size>3</size>
+			  <default/>
+			  <description>This column contains the reply code used for rule matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>flags</name>
+			  <type>unsigned int</type>
+			  <size>&flag_len;</size>
+			  <default>0</default>
+			  <description>This column contains the flags used for rule matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>mask</name>
+			  <type>unsigned int</type>
+			  <size>&flag_len;</size>
+			  <default>0</default>
+			  <description>This column contains the mask that is applied to the message flags before rule matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>next_domain</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <default>0</default>
+			  <natural/>
+			  <description>This column contains the route domain id that should be used for the next routing attempt.</description>
+		  </column>
+		  
+		  <column>
+			  <name>description</name>
+			  <type>string</type>
+			  <size>&description_len;</size>
+			  <null/>
+			  <default><null/></default>
+			  <description>A comment for the route entry, useful for larger routing tables.</description>
+		  </column>
+	  </table>

+ 144 - 0
lib/srdb1/schema/carrierroute.xml

@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+	  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+	  
+	  <!ENTITY % entities SYSTEM "entities.xml">
+	  %entities;
+	  
+	  ]>
+	  
+	  <table id="carrierroute" xmlns:db="http://docbook.org/ns/docbook">
+		  <name>carrierroute</name>
+		  <version>3</version>
+		  <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+		  <description>
+			  <db:para>This table is used by the carrierroute module to provides routing, balancing and blacklisting 
+			  capabilities. It contains the routing data. More information is available at: http://www.kamailio.org/docs/modules/devel/carrierroute.html
+			  </db:para>
+		  </description>
+		  
+		  <column id="id">
+			  <name>id</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <autoincrement/>
+			  <primary/>
+			  <type db="dbtext">int,auto</type>
+			  <description>Name of the column contains the unique identifier of a route.</description>
+		  </column>
+		  
+		  <column>
+			  <name>carrier</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <default>0</default>
+			  <natural/>
+			  <description>This column contains the carrier id.</description>
+		  </column>
+		  
+		  <column>
+			  <name>domain</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <default>0</default>
+			  <natural/>
+			  <description>This column contains the routing domain id. You can define several routing
+			  domains to have different routing rules. Maybe you use domain 0 for normal routing and
+			  domain 1 if domain 0 failed.</description>
+		  </column>
+		  
+		  <column>
+			  <name>scan_prefix</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <default/>
+			  <description>Name of column contains the scan prefixes. Scan prefixes define
+			  the matching portion of a phone number, e.g. when we have the scan prefixes 49721
+			  and 49, the called number is 49721913740, it matches 49721, because the longest
+			  match is taken. If no prefix matches, the number is not routed. To prevent this,
+			  an empty prefix value of <quote></quote> could be added.</description>
+		  </column>
+		  
+		  <column>
+			  <name>flags</name>
+			  <type>unsigned int</type>
+			  <size>&flag_len;</size>
+			  <default>0</default>
+			  <description>This column contains the flags used for rule matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>mask</name>
+			  <type>unsigned int</type>
+			  <size>&flag_len;</size>
+			  <default>0</default>
+			  <description>This column contains the mask that is applied to the message flags before rule 
+			  matching.</description>
+		  </column>
+		  
+		  <column>
+			  <name>prob</name>
+			  <type>float</type>
+			  <default>0</default>
+			  <description><para>
+			  Name of column contains the probability. The probability value is used to
+			  distribute the traffic between several gateways. Let's say 70 % of the
+			  traffic shall be routed to gateway A, the other 30 % shall be routed to
+			  gateway B, we define a rule for gateway A with a prob value of 0.7 and a
+			  rule for gateway B with a prob value of 0.3.
+			  </para>
+			  <para>
+			  If all probabilities for a given prefix, tree and domain don't add to 100%,
+			  the prefix values will be adjusted according the given prob values. E.g. if
+			  three hosts with prob values of 0.5, 0.5 and 0.4 are defined, the resulting
+			  probabilities are 35.714, 35.714 and 28.571%. But its better to choose meaningful
+			  values in the first place because of clarity.
+			  </para></description>
+		  </column>
+		  
+		  <column>
+			  <name>strip</name>
+			  <type>unsigned int</type>
+			  <size>&flag_len;</size>
+			  <default>0</default>
+			  <description>Name of the column contains the number of digits to be stripped of the userpart of an URI before prepending rewrite_prefix.</description>
+		  </column>
+		  
+		  <column>
+			  <name>rewrite_host</name>
+			  <type>string</type>
+			  <size>&uri_len;</size>
+			  <default/>
+			  <description>Name of column contains the rewrite prefixes. Here you can define a rewrite prefix
+			  for the localpart of the SIP URI. An empty field represents a blacklist entry, anything else
+			  is put as domain part into the Request URI of the SIP message.</description>
+		  </column>
+		  
+		  <column>
+			  <name>rewrite_prefix</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <default/>
+			  <description>Name of column contains the rewrite prefixes. Here you can define a rewrite
+			  prefix for the localpart of the SIP URI.</description>
+		  </column>
+		  
+		  <column>
+			  <name>rewrite_suffix</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <default/>
+			  <description>Name of column contains the rewrite suffixes. Here you can define a rewrite
+			  suffix for the localpart of the SIP URI.</description>
+		  </column>
+		  
+		  <column>
+			  <name>description</name>
+			  <type>string</type>
+			  <size>&description_len;</size>
+			  <null/>
+			  <default><null/></default>
+			  <description>A comment for the route entry, useful for larger routing tables.
+			  The comment is also displayed by the fifo cmd "cr_dump_routes".</description>
+		  </column>
+	  </table>

+ 62 - 0
lib/srdb1/schema/cpl.xml

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="cpl" xmlns:db="http://docbook.org/ns/docbook">
+    <name>cpl</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the call processing language "cpl" module. More information is available at: &KAMAILIO_MOD_DOC;cpl-c.html</db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>64</size>
+        <default/>
+        <natural/>
+    </column>
+
+    <column>
+        <name>cpl_xml</name>
+        <type>text</type>
+        <null/>
+    </column>
+
+    <column>
+        <name>cpl_bin</name>
+        <type>text</type>
+        <null/>
+    </column>
+
+    <index>
+        <name>account_idx</name>
+        <unique/>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+    </index>
+
+</table>

+ 75 - 0
lib/srdb1/schema/dbaliases.xml

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="dbaliases" xmlns:db="http://docbook.org/ns/docbook">
+    <name>dbaliases</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table us used by the alias_db module as an alternative for user aliases via userloc. More information about the alias_db module can be found at: &KAMAILIO_MOD_DOC;alias_db.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="alias_username">
+        <name>alias_username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Alias username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="alias_domain">
+        <name>alias_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Alias domain name</description>
+        <natural/>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+    </column>
+
+    <index>
+        <name>alias_idx</name>
+        <colref linkend="alias_username"/>
+        <colref linkend="alias_domain"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>target_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+    </index>
+</table>

+ 174 - 0
lib/srdb1/schema/dialog.xml

@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="dialog" xmlns:db="http://docbook.org/ns/docbook">
+	<name>dialog</name>
+	<version>2</version>
+	<type db="mysql">&MYSQL_TABLE_TYPE;</type>
+	<description>
+		<db:para>Persistent dialog information for the dialog module. More 
+		information can be found at: &KAMAILIO_MOD_DOC;dialog.html
+		</db:para>
+	</description>
+
+	<column id="id">
+		<name>id</name>
+		<type>unsigned int</type>
+		<size>&table_id_len;</size>
+		<autoincrement/>
+		<primary/>
+		<type db="dbtext">int,auto</type>
+		<description>unique ID</description>
+	</column>
+
+	<column id="hash_entry">
+		<name>hash_entry</name>
+		<type>unsigned int</type>
+		<size>10</size>
+		<description>Number of the hash entry in the dialog hash table
+		</description>
+		<natural/>
+	</column>
+
+	<column id="hash_id">
+		<name>hash_id</name>
+		<type>unsigned int</type>
+		<size>10</size>
+		<description>The ID on the hash entry</description>
+		<natural/>
+	</column>
+
+	<column>
+		<name>callid</name>
+		<type>string</type>
+		<size>&hf_len;</size>
+		<description>Call-ID of the dialog</description>
+		
+	</column>
+
+	<column>
+		<name>from_uri</name>
+		<type>string</type>
+		<size>&uri_len;</size>
+		<description>The URI of the FROM header (as per INVITE)</description>
+	</column>
+
+	<column>
+		<name>from_tag</name>
+		<type>string</type>
+		<size>&user_len;</size>
+		<description>The tag parameter serves as a general mechanism to 
+		identify a dialog, which is the combination of the Call-ID along 
+		with two tags, one from participant in the dialog.</description>
+	</column>
+
+	<column>
+		<name>to_uri</name>
+		<type>string</type>
+		<size>&uri_len;</size>
+		<description>The URI of the TO header (as per INVITE)</description>
+	</column>
+
+	<column>
+		<name>to_tag</name>
+		<type>string</type>
+		<size>&user_len;</size>
+		<description>The tag parameter serves as a general mechanism to 
+		identify a dialog, which is the combination of the Call-ID along 
+		with two tags, one from participant in the dialog.</description>
+	</column>
+
+	<column>
+		<name>caller_cseq</name>
+		<type>string</type>
+		<size>7</size>
+		<description>Last Cseq number on the caller side.</description>
+	</column>
+
+	<column>
+		<name>callee_cseq</name>
+		<type>string</type>
+		<size>7</size>
+		<description>Last Cseq number on the caller side.</description>
+	</column>
+
+	<column>
+		<name>caller_route_set</name>
+		<type>string</type>
+		<size>512</size>
+		<null/>
+		<description>Route set on the caller side.</description>
+	</column>
+
+	<column>
+		<name>callee_route_set</name>
+		<type>string</type>
+		<size>512</size>
+		<null/>
+		<description>Route set on on the caller side.</description>
+	</column>
+
+	<column>
+		<name>caller_contact</name>
+		<type>string</type>
+		<size>&uri_len;</size>
+		<description>Caller's contact uri.</description>
+	</column>
+
+	<column>
+		<name>callee_contact</name>
+		<type>string</type>
+		<size>&uri_len;</size>
+		<description>Callee's contact uri.</description>
+	</column>
+
+	<column>
+		<name>caller_sock</name>
+		<type>string</type>
+		<size>64</size>
+		<description>Local socket used to communicate with caller</description>
+	</column>
+
+	<column>
+		<name>callee_sock</name>
+		<type>string</type>
+		<size>64</size>
+		<description>Local socket used to communicate with callee</description>
+	</column>
+
+
+	<column>
+		<name>state</name>
+		<type>unsigned int</type>
+		<size>10</size>
+		<description>The state of the dialog.</description>
+	</column>
+
+	<column>
+		<name>start_time</name>
+		<type>unsigned int</type>
+		<size>10</size>
+		<description>The timestamp (unix time) when the dialog was confirmed.
+		</description>
+	</column>
+
+	<column>
+		<name>timeout</name>
+		<type>unsigned int</type>
+		<size>10</size>
+		<description>The timestamp (unix time) when the dialog will expire.
+		</description>
+	</column>
+
+	<index>
+		<name>hash_idx</name>
+		<colref linkend="hash_entry"/>
+		<colref linkend="hash_id"/>
+	</index>
+</table>

+ 85 - 0
lib/srdb1/schema/dialplan.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="dialplan" xmlns:db="http://docbook.org/ns/docbook">
+    <name>dialplan</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the dialplan module for the translation rules. More information is available at: &KAMAILIO_MOD_DOC;dialplan.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="dpid">
+        <name>dpid</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Dialplan ID.</description>
+    </column>
+
+    <column id="pr">
+        <name>pr</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Priority of rule.</description>
+    </column>
+
+    <column id="match_op">
+        <name>match_op</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Matching operator for rule (0-equal, 1-regexp).</description>
+    </column>
+
+     <column id="match_exp">
+        <name>match_exp</name>
+        <type>string</type>
+        <size>64</size>
+        <description>Matching expresion (regexp or string).</description>
+    </column>
+
+    <column id="match_len">
+        <name>match_len</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Length of the matching expresion (used only for equal operator).</description>
+    </column>
+
+     <column id="subst_exp">
+        <name>subst_exp</name>
+        <type>string</type>
+        <size>64</size>
+        <description>Substitution expresion.</description>
+    </column>
+    
+    <column id="repl_exp">
+        <name>repl_exp</name>
+        <type>string</type>
+        <size>32</size>
+        <description>Replacement expresion (sed like).</description>
+    </column>
+
+    <column id="attrs">
+        <name>attrs</name>
+        <type>string</type>
+        <size>32</size>
+        <description>General attributes string to be returned in case of rule matching.</description>
+    </column>
+ 
+</table>

+ 69 - 0
lib/srdb1/schema/dispatcher.xml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="dispatcher" xmlns:db="http://docbook.org/ns/docbook">
+    <name>dispatcher</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the dispatcher module. It contains the sets of destinations used for load balancing and dispatching. More information about the dispatcher module can be found at: &KAMAILIO_MOD_DOC;dispatcher.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="setid">
+        <name>setid</name>
+        <type>int</type>
+        <description>Destination set id</description>
+        <default>0</default>
+        <natural/>
+    </column>
+
+    <column id="dst">
+        <name>destination</name>
+        <type>string</type>
+        <size>192</size>
+        <description>Destination SIP address</description>
+        <default/>
+    </column>
+
+    <column id="flags">
+        <name>flags</name>
+        <type>int</type>
+        <description>Flags of destination SIP address</description>
+        <default>0</default>
+        <natural/>
+    </column>
+
+    <column id="priority">
+        <name>priority</name>
+        <type>int</type>
+        <description>Priority of destination SIP address</description>
+        <default>0</default>
+        <natural/>
+    </column>
+
+    <column>
+        <name>description</name>
+        <type>string</type>
+        <size>64</size>
+        <default/>
+        <description>Description for this destination</description>
+    </column>
+
+</table>

+ 51 - 0
lib/srdb1/schema/domain.xml

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="domain" xmlns:db="http://docbook.org/ns/docbook">
+    <name>domain</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the domain module to determine if a host part of a URI is "local" or not. More information about the domain module can be found at: &KAMAILIO_MOD_DOC;domain.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="dom">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Domain name</description>
+        <default/>
+        <natural/>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this record was last modified.</description>
+    </column>
+
+    <index>
+        <name>domain_idx</name>
+        <colref linkend="dom"/>
+        <unique/>
+    </index>
+</table>

+ 39 - 0
lib/srdb1/schema/domain_name.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+	  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+	  
+	  <!ENTITY % entities SYSTEM "entities.xml">
+	  %entities;
+	  
+	  ]>
+	  
+	  <table id="domain_name" xmlns:db="http://docbook.org/ns/docbook">
+		  <name>domain_name</name>
+		  <version>1</version>
+		  <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+		  <description>
+			  <db:para>This table is used by the carrierroute module to provides routing, balancing and blacklisting capabilities. It contains the existing domains, consisting of the ids and corresponding names. More
+			  information is available at: &KAMAILIO_MOD_DOC;carrierroute.html
+			  </db:para>
+		  </description>
+		  
+		  <column id="id">
+			  <name>id</name>
+			  <type>unsigned int</type>
+			  <size>&table_id_len;</size>
+			  <natural/>
+			  <autoincrement/>
+			  <primary/>
+			  <type db="dbtext">int,auto</type>
+			  <description>Name of the column containing the unique identifier of a domain.</description>
+		  </column>
+		  
+		  <column>
+			  <name>domain</name>
+			  <type>string</type>
+			  <size>&user_len;</size>
+			  <null/>
+			  <default><null/></default>
+			  <description>This column contains the domain name.</description>
+		  </column>
+	  </table>

+ 80 - 0
lib/srdb1/schema/domainpolicy.xml

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+
+]>
+
+<table id="domainpolicy" xmlns:db="http://docbook.org/ns/docbook">
+    <name>domainpolicy</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the domainpolicy module. More information at &KAMAILIO_MOD_DOC;domainpolicy.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="rule">
+        <name>rule</name>
+        <type>string</type>
+        <size>&rule_len;</size>
+        <description>Domain policy rule name which is equal to the URI as published in the domain policy NAPTRs.</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>type</name>
+        <type>string</type>
+        <size>&rule_len;</size>
+        <description> Domain policy rule type. In the case of federation names, this is "fed". For standard referrals according to draft-lendl-speermint-technical-policy-00, this is "std". For direct domain lookups, this is "dom". Default value is "type".</description>
+        <natural/>
+    </column>
+
+    <column id="att">
+        <name>att</name>
+        <type>string</type>
+        <size>&rule_len;</size>
+        <null/>
+        <description>It contains the AVP's name. If the rule stored in this row triggers, than dp_can_connect() will add an AVP with that name.</description>
+    </column>
+
+    <column id="val">
+        <name>val</name>
+        <type>string</type>
+        <size>&avp_val_len;</size>
+        <null/>
+        <description>It contains the values for AVPs created by dp_can_connect(). Default value is "val"</description>
+    </column>
+
+    <column>
+        <name>description</name>
+        <type>string</type>
+        <size>&rule_len;</size>
+        <description>Comment about the rule</description>
+    </column>
+
+    <index>
+        <name>rav_idx</name>
+        <colref linkend="rule"/>
+        <colref linkend="att"/>
+        <colref linkend="val"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>rule_idx</name>
+        <colref linkend="rule"/>
+    </index>
+</table>

+ 28 - 0
lib/srdb1/schema/entities.xml

@@ -0,0 +1,28 @@
+<!ENTITY user_len "64">
+<!ENTITY domain_len "64">
+<!ENTITY realm_len "64">
+<!ENTITY uri_len "128">
+<!ENTITY id_len "64">
+<!ENTITY table_id_len "10">
+<!ENTITY hf_len "255">
+<!ENTITY rule_len "255">
+<!ENTITY method_len "16">
+<!ENTITY avp_name_len "32">
+<!ENTITY avp_val_len "128">
+<!ENTITY ip_add_len "50">
+<!ENTITY sip_code_len "3">
+<!ENTITY sip_reason_len "32">
+<!ENTITY cseq_len "11">
+<!ENTITY expires_len "11">
+<!ENTITY flag_len "11">
+<!ENTITY description_len "255">
+<!ENTITY MYSQL_TABLE_TYPE "MyISAM">
+<!ENTITY USERCOL "username">
+<!ENTITY DEFAULT_ALIASES_EXPIRES "2020-05-28 21:32:15">
+<!ENTITY DEFAULT_LOCATION_EXPIRES "2020-05-28 21:32:15">
+<!ENTITY DEFAULT_Q  "1.0">
+<!ENTITY DEFAULT_CALLID "Default-Call-ID">
+<!ENTITY DEFAULT_CSEQ "13">
+<!ENTITY DEFAULT_DATETIME "1900-01-01 00:00:01"> <!-- postgresql doesn't like 0000-00-00 00:00:00 -->
+<!ENTITY DEFAULT_FLAGS "0">
+<!ENTITY KAMAILIO_MOD_DOC "http://www.kamailio.org/docs/modules/devel/">

+ 58 - 0
lib/srdb1/schema/globalblacklist.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="globalblacklist" xmlns:db="http://docbook.org/ns/docbook">
+    <name>globalblacklist</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the userblacklist module for the global blacklists. More information is available at: &KAMAILIO_MOD_DOC;userblacklist.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="prefix">
+        <name>prefix</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The prefix that is matched for the blacklist.</description>
+    </column>
+
+    <column>
+        <name>whitelist</name>
+        <type>char</type>
+        <size>1</size>
+        <default>0</default>
+        <description>Specify if this a blacklist (0) or a whitelist (1) entry.</description>
+    </column>
+
+     <column>
+        <name>description</name>
+        <type>string</type>
+        <size>&description_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>A comment for the entry.</description>
+    </column>
+
+    <index>
+        <name>globalblacklist_idx</name>
+        <colref linkend="prefix"/>
+    </index>
+</table>

+ 72 - 0
lib/srdb1/schema/grp.xml

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="grp" xmlns:db="http://docbook.org/ns/docbook">
+    <name>grp</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table us used by the group module as a means of group membership checking. Used primarily for Access Control Lists (ACL's). More information about the group module can be found at: &KAMAILIO_MOD_DOC;group.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column id="group">
+        <name>grp</name>
+        <type>string</type>
+        <size>&id_len;</size>
+        <default/>
+        <description>Group name</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this record was last modified.</description>
+    </column>
+
+    <index>
+        <name>account_group_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="group"/>
+        <unique/>
+    </index>
+
+</table>

+ 128 - 0
lib/srdb1/schema/gw.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+
+<table id="gw" xmlns:db="http://docbook.org/ns/docbook">
+    <name>gw</name>
+    <version>9</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table contains Least Cost Routing Gateway definitions for the LCR module.
+                 More information can be found at: &KAMAILIO_MOD_DOC;lcr.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+    </column>
+
+    <column id="gw_name">
+        <name>gw_name</name>
+        <type>string</type>
+        <size>128</size>
+        <description>Name of the gateway</description>
+        <natural/>
+    </column>
+
+    <column id="grp_id">
+        <name>grp_id</name>
+        <type>unsigned int</type>
+        <description>ID of gateway's group</description>
+    </column>
+
+    <column>
+        <name>ip_addr</name>
+        <type>string</type>
+        <size>15</size>
+        <description>IP Address of the gateway</description>
+    </column>
+
+    <column>
+        <name>hostname</name>
+        <type>string</type>
+        <size>64</size>
+        <null/>
+        <description>Hostname of the gateway</description>
+    </column>
+
+    <column>
+        <name>port</name>
+        <type>unsigned short</type>
+        <null/>
+        <description>Port of the gateway</description>
+    </column>
+
+    <column>
+        <name>uri_scheme</name>
+        <type>unsigned char</type>
+        <null/>
+        <description>URI scheme of gateway</description>
+    </column>
+
+    <column>
+        <name>transport</name>
+        <type>unsigned char</type>
+        <null/>
+        <description>Transport type to be used for the gateway</description>
+    </column>
+
+    <column>
+        <name>strip</name>
+        <type>unsigned char</type>
+        <null/>
+        <description>The number of digits to strip from Request URI user part before inserting tag</description>
+    </column>
+
+    <column>
+        <name>tag</name>
+        <type>string</type>
+        <size>16</size>
+        <null/>
+        <default><null/></default>
+        <description>Request URI user part tag</description>
+    </column>
+
+    <column>
+        <name>weight</name>
+        <type>unsigned int</type>
+        <null/>
+        <description>Weight of gateway within gw_grp.  Valid values are 1-254.</description>
+    </column>
+
+    <column>
+        <name>ping</name>
+        <type>unsigned char</type>
+        <default>0</default>
+        <description>Is gateway eligible for aliveness check (0 = no, 1 = yes)</description>
+    </column>
+
+    <column>
+        <name>flags</name>
+        <type>unsigned int</type>
+        <default>&DEFAULT_FLAGS;</default>
+        <description>Gateway specific flags</description>
+    </column>
+
+    <index>
+        <name>gw_name_idx</name>
+        <colref linkend="gw_name"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>grp_id_idx</name>
+        <colref linkend="grp_id"/>
+    </index>
+
+</table>

+ 59 - 0
lib/srdb1/schema/htable.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="htable" xmlns:db="http://docbook.org/ns/docbook">
+    <name>htable</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table us used by the htabke module to load values in the hash table at start up. More information about the avpops module can be found at: &KAMAILIO_MOD_DOC;htable.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="key_name">
+        <name>key_name</name>
+        <type>string</type>
+        <size>64</size>
+        <default/>
+        <description>Name of the hash key</description>
+    </column>
+
+    <column id="key_type">
+        <name>key_type</name>
+        <type>int</type>
+        <default>0</default>
+        <description>Type of the key (0 - single value; 1 - array)</description>
+    </column>
+
+    <column id="value_type">
+        <name>value_type</name>
+        <type>int</type>
+        <default>0</default>
+        <description>Type of the value (0 - string valuel 1 - integer value)</description>
+    </column>
+
+    <column id="attribute">
+        <name>key_value</name>
+        <type>string</type>
+        <size>128</size>
+        <default/>
+        <description>The value of the key</description>
+    </column>
+
+</table>

+ 67 - 0
lib/srdb1/schema/imc_members.xml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+
+]>
+
+<table id="imc_members" xmlns:db="http://docbook.org/ns/docbook">
+    <name>imc_members</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Member table for the IMC module. More information at &KAMAILIO_MOD_DOC;imc.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>username</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Username</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Domain</description>
+        <natural/>
+    </column>
+
+    <column id="room">
+        <name>room</name>
+        <type>string</type>
+        <size>&realm_len;</size>
+        <natural/>
+    </column>
+
+    <column>
+        <name>flag</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <description>Flags</description>
+    </column>
+
+    <index>
+        <name>account_room_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="room"/>
+        <unique/>
+    </index>
+</table>
+

+ 58 - 0
lib/srdb1/schema/imc_rooms.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+
+]>
+
+<table id="imc_rooms" xmlns:db="http://docbook.org/ns/docbook">
+    <name>imc_rooms</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Room table for the IMC module. More information at &KAMAILIO_MOD_DOC;imc.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="name">
+        <name>name</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Name of the room</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Domain of the room</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>flag</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <description>Flags</description>
+    </column>
+
+    <index>
+        <name>name_domain_idx</name>
+        <colref linkend="name"/>
+        <colref linkend="domain"/>
+        <unique/>
+    </index>
+</table>

+ 14 - 0
lib/srdb1/schema/kamailio-acc.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Accounting</name>
+    <xi:include href="acc.xml"/>
+    <xi:include href="missed_calls.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-alias_db.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>alias db</name>
+    <xi:include href="dbaliases.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-auth_db.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Subscriber</name>
+    <xi:include href="subscriber.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-avpops.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>AVP Operations</name>
+    <xi:include href="usr_preferences.xml"/>
+</database>

+ 16 - 0
lib/srdb1/schema/kamailio-carrierroute.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>carrierroute</name>
+    <xi:include href="carrierroute.xml"/>
+    <xi:include href="carrierfailureroute.xml"/>
+    <xi:include href="carrier_name.xml"/>
+    <xi:include href="domain_name.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-cpl.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Call-processing language</name>
+    <xi:include href="cpl.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-dialog.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Dialog support</name>
+    <xi:include href="dialog.xml"/>
+</database>

+ 13 - 0
lib/srdb1/schema/kamailio-dialplan.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Matching and translation rules</name>
+    <xi:include href="dialplan.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-dispatcher.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Dispatcher</name>
+    <xi:include href="dispatcher.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-domain.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Domain</name>
+    <xi:include href="domain.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-domainpolicy.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Domainpolicy</name>
+    <xi:include href="domainpolicy.xml"/>
+</database>

+ 21 - 0
lib/srdb1/schema/kamailio-extensions.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<!-- Inclusion point for custom extensions for Kamailio -->
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Extensions</name>
+    <!-- Include extra definitions if found, it is not
+         an error if they are not present, although it
+         would produce a warning -->
+    <xi:include href="extra.xml">
+        <xi:fallback/>
+    </xi:include>
+    <!-- add more extensions here -->
+    <!-- <xi:include href="more-extras.xml"> -->
+</database>

+ 13 - 0
lib/srdb1/schema/kamailio-group.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Group checking</name>
+    <xi:include href="grp.xml"/>
+    <xi:include href="re_grp.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-htable.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>HashTable Values</name>
+    <xi:include href="htable.xml"/>
+</database>

+ 13 - 0
lib/srdb1/schema/kamailio-imc.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Instant Message Conference</name>
+    <xi:include href="imc_rooms.xml"/>
+    <xi:include href="imc_members.xml"/>
+</database>

+ 14 - 0
lib/srdb1/schema/kamailio-lcr.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Least-cost Routing</name>
+    <xi:include href="gw.xml"/>
+    <xi:include href="lcr.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-msilo.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Message Storage</name>
+    <xi:include href="silo.xml"/>
+</database>

+ 13 - 0
lib/srdb1/schema/kamailio-pdt.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Prefix-Domain Translation</name>
+    <xi:include href="pdt.xml"/>
+</database>

+ 13 - 0
lib/srdb1/schema/kamailio-permissions.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Permissions</name>
+    <xi:include href="trusted.xml"/>
+    <xi:include href="address.xml"/>
+</database>

+ 17 - 0
lib/srdb1/schema/kamailio-presence.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Presence</name>
+    <xi:include href="pr_presentity.xml"/>
+    <xi:include href="pr_active_watchers.xml"/>
+    <xi:include href="pr_watchers.xml"/>
+    <xi:include href="pr_xcap.xml"/>
+    <xi:include href="pr_pua.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-registrar.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Registrar</name>
+    <xi:include href="aliases.xml"/>
+</database>

+ 15 - 0
lib/srdb1/schema/kamailio-rls.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>RLS</name>
+    <xi:include href="rls_presentity.xml"/>
+    <xi:include href="rls_watchers.xml"/>
+    -->
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-siptrace.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>SIPtrace</name>
+    <xi:include href="sip_trace.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-speeddial.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Speed dial</name>
+    <xi:include href="speed_dial.xml"/>
+</database>

+ 14 - 0
lib/srdb1/schema/kamailio-standard.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<!-- Version table for Kamailio, and inclusion point for custom extensions -->
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>Version</name>
+    <xi:include href="version.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-uri_db.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>SIP URI checks</name>
+    <xi:include href="uri.xml"/>
+</database>

+ 14 - 0
lib/srdb1/schema/kamailio-userblacklist.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>User and global blacklists</name>
+    <xi:include href="userblacklist.xml"/>
+    <xi:include href="globalblacklist.xml"/>
+</database>

+ 12 - 0
lib/srdb1/schema/kamailio-usrloc.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE database PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+  <!ENTITY % entities SYSTEM "entities.xml">
+  %entities;
+]>
+
+<database xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>User location</name>
+    <xi:include href="location.xml"/>
+</database>

+ 74 - 0
lib/srdb1/schema/lcr.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="lcr" xmlns:db="http://docbook.org/ns/docbook">
+    <name>lcr</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the lcr (Least Cost Routing) rules.
+            More information can be found at: &KAMAILIO_MOD_DOC;lcr.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+    </column>
+
+    <column id="prefix">
+        <name>prefix</name>
+        <type>string</type>
+        <size>16</size>
+		<null/>
+        <default><null/></default>
+        <description>Prefix of Request URI user part</description>
+        <natural/>
+    </column>
+
+    <column id="from_uri">
+        <name>from_uri</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Pattern that is matched to caller's URI</description>
+    </column>
+
+    <column id="grp_id">
+        <name>grp_id</name>
+        <type>unsigned int</type>
+        <description>Group ID</description>
+    </column>
+
+    <column>
+        <name>priority</name>
+        <type>unsigned char</type>
+        <description>Priority</description>
+    </column>
+
+    <index>
+        <name>prefix_idx</name>
+        <colref linkend="prefix"/>
+    </index>
+
+    <index>
+        <name>from_uri_idx</name>
+        <colref linkend="from_uri"/>
+    </index>
+
+    <index>
+        <name>grp_id_idx</name>
+        <colref linkend="grp_id"/>
+    </index>
+</table>

+ 163 - 0
lib/srdb1/schema/location.xml

@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="location" xmlns:db="http://docbook.org/ns/docbook">
+    <name>location</name>
+    <version>1004</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Persistent user location information for the usrloc module. More information can be found at: &KAMAILIO_MOD_DOC;usrloc.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number </description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column id="contact">
+        <name>contact</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default/>
+        <description>Contact header field value provides a URI whoses meaning depends on the type of request or response it is in.</description>
+    </column>
+
+    <column>
+        <name>received</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Received IP:PORT in the format SIP:IP:PORT</description>
+    </column>
+
+    <column>
+        <name>path</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Path Header(s) per RFC 3327</description>
+    </column>
+
+    <column>
+        <name>expires</name>
+        <type>datetime</type>
+        <default>&DEFAULT_ALIASES_EXPIRES;</default>
+        <default db="oracle">to_date('&DEFAULT_ALIASES_EXPIRES;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this entry expires.</description>
+    </column>
+
+    <column>
+        <name>q</name>
+        <type>float</type>
+        <size>10,2</size>
+        <default>&DEFAULT_Q;</default>
+        <description>Value used for preferential routing.</description>
+    </column>
+
+    <column>
+        <name>callid</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default>&DEFAULT_CALLID;</default>
+        <description>Call-ID header field uniquely identifies a particular invitation or all registrations of a particular client.</description>
+    </column>
+
+    <column>
+        <name>cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <default>&DEFAULT_CSEQ;</default>
+        <description>CSeq header field contains a single decimal sequence number and the request method.</description>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this entry was last modified.</description>
+    </column>
+
+    <column>
+        <name>flags</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <default>0</default>
+        <description>Internal flags</description>
+    </column>
+
+    <column>
+        <name>cflags</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <default>0</default>
+        <description>Branch and contact flags</description>
+    </column>
+
+    <column>
+        <name>user_agent</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default/>
+        <description>User-Agent header field contains information about the UAC originating the request.</description>
+    </column>
+
+    <column>
+        <name>socket</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>Socket used to connect to Kamailio. For example: UDP:IP:PORT</description>
+    </column>
+
+    <column>
+        <name>methods</name>
+        <type>int</type>
+        <size>11</size>
+        <null/>
+        <default><null/></default>
+        <description>Flags that indicate the SIP Methods this contact will accept.</description>
+    </column>
+
+    <index>
+        <name>account_contact_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="contact"/>
+    </index>
+
+</table>

+ 87 - 0
lib/srdb1/schema/missed_calls.xml

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="missed_calls" xmlns:db="http://docbook.org/ns/docbook">
+    <name>missed_calls</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the ACC module for keeping track of missed calls. This table is similar to the 'acc' table. More information is available at: &KAMAILIO_MOD_DOC;acc.html</db:para>
+    </description>
+    
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+    
+    <column>
+        <name>method</name>
+        <type>string</type>
+        <size>&method_len;</size>
+        <description>A method is the primary function that a request is meant to invoke on a server.</description>
+        <default/>
+    </column>
+    
+    <column>
+        <name>from_tag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The tag parameter serves as a general mechanism to identify a dialog, which is the combination of the Call-ID along with two tags, one from participant in the dialog.</description>
+    </column>
+    
+    <column>
+        <name>to_tag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The tag parameter serves as a general mechanism to identify a dialog, which is the combination of the Call-ID along with two tags, one from participant in the dialog.</description>
+    </column>
+    
+    <column id="callid">
+        <name>callid</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Call-ID header field uniquely identifies a particular invitation or all registrations of a particular client. </description>
+        <natural/>
+    </column>
+    
+    <column>
+        <name>sip_code</name>
+        <type>string</type>
+        <size>&sip_code_len;</size>
+        <default/>
+        <description>SIP reply code</description>
+    </column>
+    
+    <column>
+        <name>sip_reason</name>
+        <type>string</type>
+        <size>&sip_reason_len;</size>
+        <default/>
+        <description>SIP reply reason</description>
+    </column>
+    
+    <column>
+        <name>time</name>
+        <type>datetime</type>
+        <description>Date and time when this record was written.</description>
+    </column>
+    
+    <index>
+        <name>callid_idx</name>
+        <colref linkend="callid"/>
+    </index>
+</table>

+ 58 - 0
lib/srdb1/schema/pdt.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="pdt" xmlns:db="http://docbook.org/ns/docbook">
+    <name>pdt</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Prefix-Domain Translation means to change the host and port in R-URI, based on the prefix found in R-URI and source           domain (that is domain in From-URI). More information can be found at: &KAMAILIO_MOD_DOC;pdt.html 
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="sdomain">
+        <name>sdomain</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Source domain</description>
+        <natural/>
+    </column>
+
+    <column id="prefix">
+        <name>prefix</name>
+        <type>string</type>
+        <size>32</size>
+        <description>Prefix found in the username part of R-URI.</description>
+    </column>
+
+    <column>
+        <name>domain</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>Domain corresponding to (sdomain, prefix) pair where the message must be sent.</description>
+    </column>
+
+    <index>
+        <name>sdomain_prefix_idx</name>
+        <colref linkend="sdomain"/>
+        <colref linkend="prefix"/>
+        <unique/>
+    </index>
+</table>

+ 184 - 0
lib/srdb1/schema/pr_active_watchers.xml

@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="active_watchers" xmlns:db="http://docbook.org/ns/docbook">
+    <name>active_watchers</name>
+    <version>9</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the presence module. More information can be found at: &KAMAILIO_MOD_DOC;presence.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="presentity_uri">
+        <name>presentity_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Presence URI</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>watcher_username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>From User</description>
+    </column>
+
+    <column>
+        <name>watcher_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>From Domain</description>
+    </column>
+
+    <column>
+        <name>to_user</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>To User</description>
+    </column>
+
+    <column>
+        <name>to_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>To Domain</description>
+    </column>
+
+    <column>
+        <name>event</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default>presence</default>
+        <description>Event description</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>event_id</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <null/>
+        <description>Event ID</description>
+    </column>
+
+    <column id="to_tag">
+        <name>to_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>TO tag</description>
+    </column>
+
+    <column id="from_tag">
+        <name>from_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>From tag</description>
+    </column>
+
+    <column id="callid">
+        <name>callid</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Call ID</description>
+    </column>
+
+    <column>
+        <name>local_cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <description>Local cseq</description>
+    </column>
+
+    <column>
+        <name>remote_cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <description>Remote cseq</description>
+    </column>
+
+    <column>
+        <name>contact</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Contact</description>
+    </column>
+
+    <column>
+        <name>record_route</name>
+        <type>text</type>
+        <null/>
+        <description>Record route</description>
+    </column>
+
+    <column>
+        <name>expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Expires</description>
+    </column>
+
+    <column>
+        <name>status</name>
+        <type>int</type>
+        <size>11</size>
+        <default>2</default>
+        <description>Status</description>
+    </column>
+
+    <column>
+        <name>reason</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>Reason</description>
+    </column>
+
+    <column>
+        <name>version</name>
+        <type>int</type>
+        <size>11</size>
+        <default>0</default>
+        <description>Version</description>
+    </column>
+
+    <column>
+        <name>socket_info</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Socket info</description>
+    </column>
+
+    <column>
+        <name>local_contact</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Local contact</description>
+    </column>
+
+    <index>
+        <name>active_watchers_idx</name>
+        <colref linkend="presentity_uri"/>
+        <colref linkend="callid"/>
+        <colref linkend="to_tag"/>
+        <colref linkend="from_tag"/>
+        <unique/>
+    </index>
+
+</table>

+ 95 - 0
lib/srdb1/schema/pr_presentity.xml

@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="presentity" xmlns:db="http://docbook.org/ns/docbook">
+    <name>presentity</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the presence module. More information can be found at: &KAMAILIO_MOD_DOC;presence.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>User name</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Domain</description>
+        <natural/>
+    </column>
+
+    <column id="event">
+        <name>event</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>Event</description>
+        <natural/>
+    </column>
+
+    <column id="etag">
+        <name>etag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>User name</description>
+    </column>
+
+    <column id="expires">
+        <name>expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Expires</description>
+    </column>
+
+    <column>
+        <name>received_time</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Reveived time</description>
+    </column>
+
+    <column>
+        <name>body</name>
+        <type>binary</type>
+    </column>
+  
+	<column id="sender">
+        <name>sender</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Sender contact</description>
+    </column>
+
+    <index>
+        <name>presentity_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="event"/>
+        <colref linkend="etag"/>
+        <unique/>
+    </index>
+
+</table>

+ 154 - 0
lib/srdb1/schema/pr_pua.xml

@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="pua" xmlns:db="http://docbook.org/ns/docbook">
+    <name>pua</name>
+    <version>6</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the presence related pua module. More information can be found at: &KAMAILIO_MOD_DOC;pua.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column>
+        <name>pres_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>URI</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>pres_id</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>ID</description>
+    </column>
+
+    <column>
+        <name>event</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Event</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Expires</description>
+    </column>
+
+    <column>
+        <name>desired_expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Desired Expires</description>
+    </column>
+
+    <column>
+        <name>flag</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <description>Flags</description>
+    </column>
+
+    <column>
+        <name>etag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Etag</description>
+    </column>
+
+    <column>
+        <name>tuple_id</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <description>Tuple ID</description>
+    </column>
+
+    <column>
+        <name>watcher_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Watcher URI</description>
+    </column>
+
+    <column>
+        <name>call_id</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Call ID</description>
+    </column>
+
+    <column>
+        <name>to_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>To tag</description>
+    </column>
+
+    <column>
+        <name>from_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>To tag</description>
+    </column>
+
+    <column>
+        <name>cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+    </column>
+
+    <column>
+        <name>record_route</name>
+        <type>text</type>
+        <null/>
+        <description>Record route</description>
+    </column>
+
+    <column>
+        <name>contact</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Contact</description>
+    </column>
+
+    <column>
+        <name>remote_contact</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Remote contact</description>
+    </column>
+
+    <column>
+        <name>version</name>
+        <type>int</type>
+        <size>11</size>
+        </column>
+        <column>
+        <name>extra_headers</name>
+        <type>text</type>
+        <description>Extra Headers</description>
+    </column>
+
+</table>

+ 90 - 0
lib/srdb1/schema/pr_watchers.xml

@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="watchers" xmlns:db="http://docbook.org/ns/docbook">
+    <name>watchers</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the presence module. More information can be found at: &KAMAILIO_MOD_DOC;presence.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="presentity_uri">
+        <name>presentity_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Presentity Uri</description>
+        <natural/>
+    </column>
+
+    <column id="watcher_username">
+        <name>watcher_username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>Watcher User</description>
+    </column>
+
+    <column id="watcher_domain">
+        <name>watcher_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Watcher Domain</description>
+    </column>
+
+    <column id="event">
+        <name>event</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default>presence</default>
+        <description>Event description</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>status</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Status</description>
+    </column>
+
+    <column>
+        <name>reason</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <null/>
+        <description>Reason</description>
+    </column>
+
+    <column>
+        <name>inserted_time</name>
+        <type>int</type>
+        <size>11</size>
+    </column>
+
+    <index>
+        <name>watcher_idx</name>
+        <colref linkend="presentity_uri"/>
+        <colref linkend="watcher_username"/>
+        <colref linkend="watcher_domain"/>
+        <colref linkend="event"/>
+        <unique/>
+    </index>
+
+</table>

+ 100 - 0
lib/srdb1/schema/pr_xcap.xml

@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="xcap" xmlns:db="http://docbook.org/ns/docbook">
+    <name>xcap</name>
+    <version>3</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the presence module. More information can be found at: &KAMAILIO_MOD_DOC;presence.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>User name</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Domain</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>doc</name>
+        <type>binary</type>
+        <description>doc</description>
+    </column>
+
+    <column id="doc_type">
+        <name>doc_type</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Document type</description>
+    </column>
+
+    <column id="etag">
+        <name>etag</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>Document Etag</description>
+    </column>
+
+    <column id="source">
+        <name>source</name>
+        <type>int</type>
+        <size>11</size>
+        <description>Entity inserting the record</description>
+    </column>
+
+    <column id="doc_uri">
+        <name>doc_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Document uri</description>
+    </column>
+
+    <column id="port">
+        <name>port</name>
+        <type>int</type>
+        <size>11</size>
+        <description>XCAP server port</description>
+    </column>
+
+    <index>
+        <name>account_doc_type_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="doc_type"/>
+        <colref linkend="doc_uri"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>source_idx</name>
+        <colref linkend="source"/>
+    </index>
+
+</table>

+ 51 - 0
lib/srdb1/schema/re_grp.xml

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="re_grp" xmlns:db="http://docbook.org/ns/docbook">
+    <name>re_grp</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para> This table is used by the group module to check membership based on regular expressions. More information about the group module can be found at: &KAMAILIO_MOD_DOC;group.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column>
+        <name>reg_exp</name>
+        <type>string</type>
+        <size>128</size>
+        <description>Regular expression</description>
+        <default/>
+    </column>
+
+    <column id="group_id">
+        <name>group_id</name>
+        <type>int</type>
+        <size>11</size>
+        <default>0</default>
+        <description>Group ID</description>
+        <natural/>
+    </column>
+
+    <index>
+        <name>group_idx</name>
+        <colref linkend="group_id"/>
+    </index>
+
+</table>

+ 96 - 0
lib/srdb1/schema/rls_presentity.xml

@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="rls_presentity" xmlns:db="http://docbook.org/ns/docbook">
+    <name>rls_presentity</name>
+    <version>0</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for the RLS module.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="rlsubs_did">
+        <name>rlsubs_did</name>
+        <type>string</type>
+        <size>255</size>
+        <description>Resource list subscribe dialog id</description>
+        <natural/>
+    </column>
+
+    <column id="resource_uri">
+        <name>resource_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>List Uri</description>
+    </column>
+
+    <column>
+        <name>content_type</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Event</description>
+    </column>
+
+    <column>
+        <name>presence_state</name>
+        <type>binary</type>
+    </column>
+
+    <column id="expires">
+        <name>expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Expires</description>
+    </column>
+
+    <column id="updated">
+        <name>updated</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Update flag</description>
+    </column>
+
+    <column>
+        <name>auth_state</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Watcher authorization state</description>
+    </column>
+
+    <column>
+        <name>reason</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>reason for watcher authorization state</description>
+    </column>
+
+    <index>
+        <name>rls_presentity_idx</name>
+        <colref linkend="rlsubs_did"/>
+        <colref linkend="resource_uri"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>updated_idx</name>
+        <colref linkend="updated"/>
+    </index>
+
+</table>

+ 185 - 0
lib/srdb1/schema/rls_watchers.xml

@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="rls_watchers" xmlns:db="http://docbook.org/ns/docbook">
+    <name>rls_watchers</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>Table for RLS module used for storing resource lists subscribe
+                 information.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="presentity_uri">
+        <name>presentity_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Presence URI</description>
+    </column>
+
+    <column>
+        <name>to_user</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>To user</description>
+    </column>
+
+    <column>
+        <name>to_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>To domain</description>
+    </column>
+
+    <column>
+        <name>watcher_username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>From user</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>watcher_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>From domain</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>event</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default>presence</default>
+        <description>Event description</description>
+    </column>
+
+    <column>
+        <name>event_id</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <null/>
+        <description>Event ID</description>
+    </column>
+
+    <column id="to_tag">
+        <name>to_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>To tag</description>
+    </column>
+
+    <column id="from_tag">
+        <name>from_tag</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>From tag</description>
+    </column>
+
+    <column id="callid">
+        <name>callid</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Call ID</description>
+    </column>
+
+    <column>
+        <name>local_cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <description>Local cseq</description>
+    </column>
+
+    <column>
+        <name>remote_cseq</name>
+        <type>int</type>
+        <size>&cseq_len;</size>
+        <description>Remote cseq</description>
+    </column>
+
+    <column>
+        <name>contact</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Contact</description>
+    </column>
+
+    <column>
+        <name>record_route</name>
+        <type>text</type>
+        <null/>
+        <description>Record route</description>
+    </column>
+
+    <column>
+        <name>expires</name>
+        <type>int</type>
+        <size>&expires_len;</size>
+        <description>Expires</description>
+    </column>
+
+    <column>
+        <name>status</name>
+        <type>int</type>
+        <size>11</size>
+        <default>2</default>
+        <description>Status</description>
+    </column>
+
+    <column>
+        <name>reason</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <description>Reason</description>
+    </column>
+
+    <column>
+        <name>version</name>
+        <type>int</type>
+        <size>11</size>
+        <default>0</default>
+        <description>Version</description>
+    </column>
+
+    <column>
+        <name>socket_info</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <description>Socket info</description>
+    </column>
+
+    <column>
+        <name>local_contact</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <description>Local contact</description>
+    </column>
+
+    <index>
+        <name>rls_watcher_idx</name>
+        <colref linkend="presentity_uri"/>
+        <colref linkend="callid"/>
+        <colref linkend="to_tag"/>
+        <colref linkend="from_tag"/>
+        <unique/>
+    </index>
+
+</table>

+ 105 - 0
lib/srdb1/schema/silo.xml

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="silo" xmlns:db="http://docbook.org/ns/docbook">
+    <name>silo</name>
+    <version>5</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para> This table us used by the msilo module to provide offline message storage More information about the msilo module can be found at: &KAMAILIO_MOD_DOC;msilo.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column>
+        <name>src_addr</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>Source address - From URI</description>
+    </column>
+
+    <column>
+        <name>dst_addr</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>Destination address - To URI</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>SIP domain of target user</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Username / phone number of target user</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>inc_time</name>
+        <type>int</type>
+        <default>0</default>
+        <description>Incoming time</description>
+    </column>
+
+    <column>
+        <name>exp_time</name>
+        <type>int</type>
+        <default>0</default>
+        <description>Expiration time</description>
+    </column>
+
+    <column>
+        <name>snd_time</name>
+        <type>int</type>
+        <default>0</default>
+        <description>Reminder send time</description>
+    </column>
+
+    <column>
+        <name>ctype</name>
+        <type>string</type>
+        <size>32</size>
+        <default>text/plain</default>
+        <description>Content type</description>
+    </column>
+
+    <column>
+        <name>body</name>
+        <type>binary</type>
+        <default/>
+        <description>Body of the message</description>
+    </column>
+
+    <index>
+        <name>account_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+    </index>
+
+</table>

+ 128 - 0
lib/srdb1/schema/sip_trace.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//pub/kamailio/.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="sip_trace" xmlns:db="http://docbook.org/ns/docbook">
+    <name>sip_trace</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used to store incoming/outgoing SIP messages in database. More informations can be found in the siptrace module documentation at: &KAMAILIO_MOD_DOC;siptrace.html.
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="time_stamp">
+        <name>time_stamp</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Recording date</description>
+    </column>
+
+    <column id="callid">
+        <name>callid</name>
+        <type>string</type>
+        <size>&hf_len;</size>
+        <default/>
+        <description>call ID from SIP message</description>
+        <natural/>
+    </column>
+
+    <column id="traced_user">
+        <name>traced_user</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>SIP URI of the user being traced</description>
+    </column>
+
+    <column>
+        <name>msg</name>
+        <type>text</type>
+        <description>Full SIP message</description>
+    </column>
+
+    <column>
+        <name>method</name>
+        <type>string</type>
+        <size>50</size>
+        <default/>
+        <description>SIP method name</description>
+    </column>
+
+    <column>
+        <name>status</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>SIP reply status</description>
+    </column>
+
+    <column id="fromip">
+        <name>fromip</name>
+        <type>string</type>
+        <size>&ip_add_len;</size>
+        <default/>
+        <description>Source IP address</description>
+    </column>
+
+    <column>
+        <name>toip</name>
+        <type>string</type>
+        <size>&ip_add_len;</size>
+        <default/>
+        <description>Destination IP address</description>
+    </column>
+
+    <column>
+        <name>fromtag</name>
+        <type>string</type>
+        <size>&id_len;</size>
+        <default/>
+        <description>From tag</description>
+    </column>
+
+    <column>
+        <name>direction</name>
+        <type>string</type>
+        <size>4</size>
+        <default/>
+        <description>Destination IP address</description>
+    </column>
+
+    <index>
+        <name>traced_user_idx</name>
+        <colref linkend="traced_user"/>
+    </index>
+
+    <index>
+        <name>date_idx</name>
+        <colref linkend="time_stamp"/>
+    </index>
+
+    <index>
+        <name>fromip_idx</name>
+        <colref linkend="fromip"/>
+    </index>
+
+    <index>
+        <name>callid_idx</name>
+        <colref linkend="callid"/>
+    </index>
+
+</table>

+ 103 - 0
lib/srdb1/schema/speed_dial.xml

@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="speed_dial" xmlns:db="http://docbook.org/ns/docbook">
+    <name>speed_dial</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the speeddial module to provide on-server speed dial facilities. More information about the speeddial module can be found at: &KAMAILIO_MOD_DOC;speeddial.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column id="sd_username">
+        <name>sd_username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Speed dial username</description>
+    </column>
+
+    <column id="sd_domain">
+        <name>sd_domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Speed dial domain</description>
+    </column>
+
+    <column>
+        <name>new_uri</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default/>
+        <description>New URI</description>
+    </column>
+
+    <column>
+        <name>fname</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>First name</description>
+    </column>
+
+    <column>
+        <name>lname</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Last name</description>
+    </column>
+
+    <column>
+        <name>description</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Description</description>
+    </column>
+
+    <index>
+        <name>speed_dial_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="sd_domain"/>
+        <colref linkend="sd_username"/>
+        <unique/>
+    </index>
+</table>

+ 100 - 0
lib/srdb1/schema/subscriber.xml

@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="subscriber" xmlns:db="http://docbook.org/ns/docbook">
+    <name>subscriber</name>
+    <version>6</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used to provide authentication information. More information about the auth_db module can be found at: &KAMAILIO_MOD_DOC;auth_db.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>password</name>
+        <type>string</type>
+        <size>25</size>
+        <default/>
+        <description>Password</description>
+    </column>
+
+    <column>
+        <name>email_address</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Email address</description>
+    </column>
+
+    <column>
+        <name>ha1</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>md5(username:realm:password)</description>
+    </column>
+
+    <column>
+        <name>ha1b</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>md5(username@domain:realm:password)</description>
+    </column>
+
+    <column>
+        <name>rpid</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <null/>
+        <default><null/></default>
+        <description>The SIP Remote-Party-ID header identifies the calling party and includes user, party, screen and privacy headers that specify how a call is presented and screened.</description>
+    </column>
+
+    <index>
+        <name>account_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <unique/>
+    </index>
+
+    <index>
+        <name>username_idx</name>
+        <colref linkend="username"/>
+    </index>
+
+</table>

+ 59 - 0
lib/srdb1/schema/template.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+<!-- set DTD for XML format, use values from entities.xml -->
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="table_name" xmlns:db="http://docbook.org/ns/docbook"> <!-- set id for colref links and namespace for "db:para" nodes -->
+    <name>table_name</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type><!-- specify the table type for mysql -->
+    <description>
+        <db:para>table documentation</db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>int</type><!-- look into the xsl files in doc/dbschema/xsl for a list of all possible datatypes -->
+        <size>&table_id_len;</size> <!-- use a value from entities.xml -->
+        <primary/><!-- primary key -->
+        <autoincrement/><!-- auto increment the id -->
+        <type db="dbtext">int,auto</type> <!-- this don't work for dbtext at the moment, so we specify the raw "SQL" code -->
+        <description>unique ID</description>
+    </column>
+
+    <column id="bla">
+        <name>foo</name>
+        <type>string</type>
+        <size>100</size>
+        <!--<default>bla</default> Default value for the column is 'bla' -->
+        <!--<default/>  Default value is '' -->
+        <!--<default><null/></default> Default value is NULL -->
+
+        <!--</null> This column can be NULL, if not specified it is NOT NULL -->
+        <description>column documentation</description>
+    </column>
+
+    <column id="another_id">
+        <name>test123</name>
+        <type>string</type>
+        <size>25</size>
+        <natural/><!-- This column is a natural key for non SQL databases, e.g. db_berkeley -->
+    </column>
+
+    <index>
+        <name>bar</name>
+        <!--<unique/> -> UNIQUE KEY -->
+        <colref linkend="bla"/> <!-- link to the node with these id -->
+    </index>
+
+    <index>
+        <name>blub</name>
+        <!--<primary/> -> PRIMARY KEY over more than one colums -->
+        <colref linkend="bla"/> <!-- link to the node with these id -->
+        <colref linkend="id"/>
+    </index>
+</table>

+ 66 - 0
lib/srdb1/schema/trusted.xml

@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="trusted" xmlns:db="http://docbook.org/ns/docbook">
+    <name>trusted</name>
+    <version>4</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the permissions module to determine if a call has the appropriate permission to be established. More information about the permissions module can be found at: &KAMAILIO_MOD_DOC;permissions.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="src_ip">
+        <name>src_ip</name>
+        <type>string</type>
+        <size>&ip_add_len;</size>
+        <description>Source address is equal to source address of request</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>proto</name>
+        <type>string</type>
+        <size>4</size>
+        <description>Transport protocol is either "any" or equal to transport protocol of request. Possible values that can be stored are "any", "udp", "tcp", "tls", and "sctp".</description>
+    </column>
+
+    <column>
+        <name>from_pattern</name>
+        <type>string</type>
+        <size>&id_len;</size>
+        <default><null/></default>
+        <null/>
+        <description>Regular expression matches From URI of request.</description>
+    </column>
+
+    <column>
+        <name>tag</name>
+        <type>string</type>
+        <size>32</size>
+        <null/>
+        <description>Tag</description>
+    </column>
+
+    <index>
+        <name>peer_idx</name>
+        <colref linkend="src_ip"/>
+    </index>
+
+</table>

+ 72 - 0
lib/srdb1/schema/uri.xml

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="uri" xmlns:db="http://docbook.org/ns/docbook">
+    <name>uri</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by uri_db module to implement various SIP URI checks.
+                 More information about the uri_db module can be found at: &KAMAILIO_MOD_DOC;uri_db.html 
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column id="uri_user">
+        <name>uri_user</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this record was last modified.</description>
+    </column>
+
+    <index>
+        <name>account_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="uri_user"/>
+        <unique/>
+    </index>
+
+</table>

+ 67 - 0
lib/srdb1/schema/userblacklist.xml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="userblacklist" xmlns:db="http://docbook.org/ns/docbook">
+    <name>userblacklist</name>
+    <version>1</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table is used by the userblacklist module for the user specific blacklists. More information is available at: &KAMAILIO_MOD_DOC;userblacklist.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>unique ID</description>
+    </column>
+
+    <column id="username">
+        <name>username</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The user that is used for the blacklist lookup.</description>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>The domain that is used for the blacklist lookup.</description>
+    </column>
+
+    <column id="prefix">
+        <name>prefix</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>The prefix that is matched for the blacklist.</description>
+    </column>
+
+    <column>
+        <name>whitelist</name>
+        <type>char</type>
+        <size>1</size>
+        <default>0</default>
+        <description>Specify if this a blacklist (0) or a whitelist (1) entry.</description>
+    </column>
+
+    <index>
+        <name>userblacklist_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="prefix"/>
+    </index>
+</table>

+ 100 - 0
lib/srdb1/schema/usr_preferences.xml

@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN" 
+  "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd" [
+
+<!ENTITY % entities SYSTEM "entities.xml">
+%entities;
+
+]>
+
+<table id="usr_preferences" xmlns:db="http://docbook.org/ns/docbook">
+    <name>usr_preferences</name>
+    <version>2</version>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+    <description>
+        <db:para>This table us used by the avpops module to implement Attribute Value Pairs (AVP's). More information about the avpops module can be found at: &KAMAILIO_MOD_DOC;avpops.html
+        </db:para>
+    </description>
+
+    <column id="id">
+        <name>id</name>
+        <type>unsigned int</type>
+        <size>&table_id_len;</size>
+        <autoincrement/>
+        <primary/>
+        <type db="dbtext">int,auto</type>
+        <description>Unique ID</description>
+    </column>
+
+    <column id="uuid">
+        <name>uuid</name>
+        <type>string</type>
+        <size>&user_len;</size>
+        <default/>
+        <description>Unique user ID</description>
+    </column>
+
+    <column id="username">
+        <name>&USERCOL;</name>
+        <type>string</type>
+        <size>&uri_len;</size>
+        <default>0</default>
+        <description>Username / phone number</description>
+        <natural/>
+    </column>
+
+    <column id="domain">
+        <name>domain</name>
+        <type>string</type>
+        <size>&domain_len;</size>
+        <default/>
+        <description>Domain name</description>
+        <natural/>
+    </column>
+
+    <column id="attribute">
+        <name>attribute</name>
+        <type>string</type>
+        <size>&avp_name_len;</size>
+        <default/>
+        <description>AVP attribute</description>
+    </column>
+
+    <column>
+        <name>type</name>
+        <type>int</type>
+        <size>&flag_len;</size>
+        <default>0</default>
+        <description>AVP type</description>
+    </column>
+
+    <column>
+        <name>value</name>
+        <type>string</type>
+        <size>&avp_val_len;</size>
+        <default/>
+        <description>AVP value</description>
+    </column>
+
+    <column>
+        <name>last_modified</name>
+        <type>datetime</type>
+        <default>&DEFAULT_DATETIME;</default>
+        <default db="oracle">to_date('&DEFAULT_DATETIME;','yyyy-mm-dd hh24:mi:ss')</default>
+        <description>Date and time when this record was last modified.</description>
+    </column>
+
+    <index>
+        <name>ua_idx</name>
+        <colref linkend="uuid"/>
+        <colref linkend="attribute"/>
+    </index>
+
+    <index>
+        <name>uda_idx</name>
+        <colref linkend="username"/>
+        <colref linkend="domain"/>
+        <colref linkend="attribute"/>
+    </index>
+
+</table>

+ 24 - 0
lib/srdb1/schema/version.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE table PUBLIC "-//kamailio.org//DTD DBSchema V1.1//EN"
+    "http://kamailio.org/pub/kamailio/dbschema/dtd/1.1/dbschema.dtd"[
+    <!ENTITY % entities SYSTEM "entities.xml">
+    %entities;
+
+]>
+
+<table id="version" xmlns:xi="http://www.w3.org/2001/XInclude">
+    <name>version</name>
+    <type db="mysql">&MYSQL_TABLE_TYPE;</type>
+
+    <column id="tn">
+        <name>table_name</name>
+        <type>string</type>
+        <size>32</size>
+        <natural/>
+    </column>
+    <column id="tv">
+        <name>table_version</name>
+        <type>unsigned int</type>
+        <default>0</default>
+    </column>
+</table>