Jelajahi Sumber

db schema(k): add XSL files, as the ones from sr not work for us (extensions etc..)

Henning Westerholt 16 tahun lalu
induk
melakukan
9113fae618

+ 35 - 0
doc/stylesheets/dbschema_k/bookinfo.xml

@@ -0,0 +1,35 @@
+<book>
+<title>&kamailio; database tables</title>
+<bookinfo>
+	<productname class="trade">&kamailio;</productname>
+	<authorgroup>
+		<author>
+			<firstname>&kamailio;</firstname>
+			<surname>Development Team</surname>
+			<affiliation><orgname>&kamailiohomelink;</orgname></affiliation>
+			<address>&kamailiodevmail;</address>
+		</author>
+		<editor>
+			<firstname>Henning</firstname>
+			<surname>Westerholt</surname>
+			<affiliation><orgname>1und1 Internet AG</orgname></affiliation>
+			<address>
+				<email>[email protected]</email>
+			</address>
+		</editor>
+		<editor>
+			<firstname>Norman</firstname>
+			<surname>Brandinger</surname>
+		</editor>
+	</authorgroup>
+	<copyright>
+		<year>2007</year>
+		<holder>&kamailio; development Team</holder>
+	</copyright>
+	<revhistory>
+		<revision>
+			<revnumber>$Revision: 4594 $</revnumber>
+			<date>$Date: 2008-08-06 12:08:33 +0200 (Mi, 06 Aug 2008) $</date>
+		</revision>
+	</revhistory>
+</bookinfo>

+ 72 - 0
doc/stylesheets/dbschema_k/dtd/dbschema.dtd

@@ -0,0 +1,72 @@
+<!--
+ * $Id: dbschema.dtd 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for common definitions
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+<!ELEMENT database (name, description?, table*)>
+<!ATTLIST database
+    id ID #IMPLIED
+>
+
+<!ELEMENT name (#PCDATA) >
+
+<!ELEMENT description (#PCDATA) >
+
+<!ELEMENT table (name, description?, version?, column+, index*, row*) >
+<!ATTLIST table
+    id ID #IMPLIED
+>
+
+<!ELEMENT version (#PCDATA) >
+
+<!ELEMENT column (name, description?, type, size?, default?, null?, primary?, natural?, autoincrement?) >
+<!ATTLIST column
+    id ID #IMPLIED
+>
+
+<!ELEMENT index (name?, unique?, primary?, colref+) >
+<!ATTLIST index
+    id ID #IMPLIED
+>
+
+<!ELEMENT type (#PCDATA) >
+
+<!ELEMENT size (#PCDATA) >
+
+<!ELEMENT default (#PCDATA) >
+
+<!ELEMENT null EMPTY >
+
+<!ELEMENT unique EMPTY >
+
+<!ELEMENT primary EMPTY >
+
+<!ELEMENT natural EMPTY >
+
+<!ELEMENT autoincrement EMPTY >
+
+<!ELEMENT colref EMPTY>
+<!ATTLIST colref
+    linkend IDREF #REQUIRED
+>

+ 227 - 0
doc/stylesheets/dbschema_k/xsl/common.xsl

@@ -0,0 +1,227 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: common.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for common definitions
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	version='1.0'>
+
+    <xsl:key name="column_id" match="column" use="@id|xml:id"/>
+
+    <xsl:param name="prefix" select="_"/>
+    <xsl:param name="dir" select="mm"/>
+    <xsl:param name="db" select="_"/>
+
+    <xsl:variable name="sign-prefix">unsigned </xsl:variable>
+
+    <!-- Do not output text -->
+    <xsl:template match="text()|@*"/>
+    <xsl:template match="text()|@*" mode="drop"/>
+
+    <!-- Return the name of the context element, first look for a database
+         specific name, use the common name if no database-specific name
+         is found.
+    -->
+    <xsl:template name="get-name">
+	<xsl:param name="select" select="."/>
+	<xsl:choose>
+	    <!-- override test -->
+	    <xsl:when test="count($select/name[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/name[@db=$db])"/>
+	    </xsl:when>
+	    <!-- No override, use the standard name -->
+	    <xsl:otherwise>
+		<xsl:value-of select="normalize-space($select/name)"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="type-error">
+	<xsl:message terminate="yes">
+	    <xsl:text>ERROR: Table: </xsl:text>
+	    <xsl:value-of select="normalize-space(parent::table/name)"/>
+	    <xsl:text>, column: </xsl:text>
+	    <xsl:value-of select="normalize-space(name)"/>
+	    <xsl:text> - unsupported column type: </xsl:text>
+	    <xsl:value-of select="normalize-space(type)"/>
+	    <xsl:text>.</xsl:text>
+	</xsl:message>
+    </xsl:template>
+
+    <!-- Process the root database element -->
+    <xsl:template match="/">
+	<!-- Process only the first database element, this is supposed to be
+	     the root database element and having multiple database elements is
+	     a bug
+	-->
+	<xsl:apply-templates select="database[1]"/>
+    </xsl:template>
+
+    <!-- ################ DATABASE ################# -->
+
+    <xsl:template match="database">
+
+	<!-- Create all tables -->
+	<xsl:apply-templates select="table"/>
+	<xsl:apply-templates select="user"/>
+    </xsl:template>
+
+    <xsl:template match="database" mode="data">
+
+	<!-- Insert initial data -->
+	<xsl:apply-templates select="table" mode="data"/>
+    </xsl:template>
+
+    <!-- ################ /DATABASE ################# -->
+
+    <!-- ################ TABLE ################# -->
+
+    <xsl:template match="table">
+	<!-- Process all columns -->
+	<xsl:apply-templates select="column"/>
+
+	<!-- Process all indexes -->
+	<xsl:apply-templates select="index"/>
+
+    </xsl:template>
+
+    <!-- ################ /TABLE ################# -->
+
+    <!-- ################ COLUMN ################# -->
+
+    <xsl:template match="column"/>
+
+    <xsl:template name="get-type-string">
+	<xsl:param name="select" select="."/>
+	<xsl:choose>
+	    <xsl:when test="count($select/type[@db=$db])='1'">
+		<xsl:value-of select="translate(normalize-space($select/type[@db=$db]),
+		  'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="translate(normalize-space($select/type),
+		  'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="get-type">
+	<xsl:param name="select" select="."/>
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type-string">
+		<xsl:with-param name="select" select="$select"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	<xsl:choose>
+	    <xsl:when test="starts-with($type, $sign-prefix)">
+		<xsl:value-of select="substring-after($type, $sign-prefix)"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="$type"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="get-sign">
+	<xsl:param name="select" select="."/>
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type-string">
+		<xsl:with-param name="select" select="$select"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	<xsl:choose>
+	    <xsl:when test="starts-with($type, $sign-prefix)">0</xsl:when>
+	    <xsl:otherwise>1</xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="get-null">
+	<xsl:param name="select" select="."/>
+	<xsl:choose>
+	    <xsl:when test="count($select/null[@db=$db])='1'">1</xsl:when>
+	    <xsl:when test="count($select/null)='1'">1</xsl:when>
+	    <xsl:otherwise>0</xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="get-size">
+	<xsl:param name="select" select="."/>
+	<xsl:choose>
+	    <xsl:when test="count($select/size[@db=$db])='1'">
+		<xsl:value-of select="normalize-space($select/size[@db=$db])"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="normalize-space($select/size)"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+
+    <!-- column ID to column name -->
+    <xsl:template name="get-column-name">
+	<xsl:param name="select" select="."/>
+
+	<xsl:variable name="columns" select="key('column_id', $select)"/>
+	<xsl:variable name="column" select="$columns[1]"/>
+	<xsl:choose>
+	    <xsl:when test="count($column) = 0">
+		<xsl:message terminate="yes">
+		    <xsl:text>ERROR: Column with id '</xsl:text>
+		    <xsl:value-of select="$select"/>
+		    <xsl:text>' does not exist.</xsl:text>
+		</xsl:message>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="get-name">
+		    <xsl:with-param name="select" select="$column"/>
+		</xsl:call-template>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+
+    <xsl:template name="get-column">
+	<xsl:param name="id" select="/.."/>	
+	<xsl:variable name="columns" select="key('column_id', $id)"/>
+	<xsl:variable name="column" select="$columns[1]"/>
+
+	<xsl:choose>
+	    <xsl:when test="count($column) = 0">
+		<xsl:message terminate="yes">
+		    <xsl:text>ERROR: Column with id '</xsl:text>
+		    <xsl:value-of select="$id"/>
+		    <xsl:text>' does not exist.</xsl:text>
+		</xsl:message>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:copy-of select="$column"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <!-- ################ /COLUMN ################# -->
+
+</xsl:stylesheet>

+ 233 - 0
doc/stylesheets/dbschema_k/xsl/db_berkeley.xsl

@@ -0,0 +1,233 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: db_berkeley.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for db_berkeley
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude">
+
+    <xsl:import href="common.xsl"/>
+    <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
+
+    <!-- Create the file for the table in db_berkeley subdirectory -->
+    <xsl:template match="table">
+	<xsl:variable name="name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	
+	<xsl:variable name="path" select="concat($dir, concat('/', concat($prefix, $name)))"/>
+	<xsl:document href="{$path}" method="text" indent="no" omit-xml-declaration="yes">
+		<xsl:text>METADATA_COLUMNS&#x0A;</xsl:text>
+		<xsl:apply-imports/>
+
+		<!-- Process all indexes -->
+		<xsl:text>METADATA_KEY&#x0A;</xsl:text>
+		
+		<!-- natural indexes -->
+		<xsl:for-each select="column">
+			<xsl:if test="natural">
+				<xsl:value-of select="position() - 1"/>
+				<xsl:if test="not(position()=last())">
+			   	<xsl:text> </xsl:text>
+				</xsl:if>
+			</xsl:if>
+		</xsl:for-each>
+		<xsl:text>&#x0A;</xsl:text>
+
+	<!--
+		<xsl:for-each select="index">
+	        <xsl:call-template name="create_index"/>
+		</xsl:for-each>
+		<xsl:text>&#x0A;</xsl:text>
+	-->
+
+		<xsl:text>METADATA_READONLY&#x0A;</xsl:text>
+		<xsl:text>0&#x0A;</xsl:text>
+
+		<xsl:text>METADATA_LOGFLAGS&#x0A;</xsl:text>
+		<xsl:text>0&#x0A;</xsl:text>
+
+		<!-- default values -->
+		<xsl:text>METADATA_DEFAULTS&#x0A;</xsl:text>
+		<xsl:for-each select="column">
+		<xsl:choose>
+		    <xsl:when test="default[@db=$db]">
+			<xsl:choose>
+			    <xsl:when test="default[@db=$db]/null">
+				<xsl:text>NULL</xsl:text>
+		    	</xsl:when>
+		    	<xsl:otherwise>
+				<xsl:value-of select="default[@db=$db]"/>
+		    	</xsl:otherwise>
+			</xsl:choose>
+	    	</xsl:when>
+	    	<xsl:when test="default">
+			<xsl:choose>
+			    <xsl:when test="default/null">
+				<xsl:text>NULL</xsl:text>
+		    	</xsl:when>
+		    	<xsl:when test= "string(number(default))='NaN'"><!-- test for string value -->
+				<xsl:text>'</xsl:text>
+				<xsl:value-of select="default"/>
+				<xsl:text>'</xsl:text>
+		    	</xsl:when>
+		    	<xsl:otherwise>
+				<xsl:value-of select="default"/><!-- ommit the quotes for numbers -->
+		    	</xsl:otherwise>
+			</xsl:choose>
+	    	</xsl:when>
+			<xsl:otherwise>
+				<xsl:text>NIL</xsl:text><!-- no value specified -->
+			</xsl:otherwise>
+		</xsl:choose>
+		<xsl:if test="not(position()=last())">
+			<xsl:text>|</xsl:text>
+		</xsl:if>
+		</xsl:for-each>
+		<xsl:text>&#x0A;</xsl:text>
+
+		<!-- Insert version data -->
+		 <xsl:apply-templates select="version"/> 
+		<!-- this is not exactly what we want for db_berkeley, as the version data gets
+		     appended to the actual table file, and no to the 'version' table.
+		     But its not possible (at least with XSL 1.0, AFAIK) to append data to a
+		     file. So it's much more easier to do this in the Makefile -->
+	</xsl:document>
+    </xsl:template>
+
+	<!-- version data template -->
+	<xsl:template match="version">
+	<xsl:call-template name="get-name">
+	    <xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	<xsl:text>|&#x0A;</xsl:text>
+	<xsl:call-template name="get-name">
+	    <xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	<xsl:text>|</xsl:text>
+	<xsl:value-of select="text()"/>
+	<xsl:text>&#x0A;</xsl:text>
+	</xsl:template>
+
+    <!-- Create column definitions -->
+    <xsl:template match="column">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:variable name="null">
+	    <xsl:call-template name="get-null"/>
+	</xsl:variable>
+
+	<xsl:call-template name="get-name"/>
+
+	<xsl:text>(</xsl:text>
+	<xsl:choose>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
+	    </xsl:when>
+		<xsl:when test="$type='char' or 
+						$type='short' or 
+						$type='int' or
+						$type='unsigned int' or
+						$type='long'">
+		<xsl:text>int</xsl:text>
+		</xsl:when>
+		<xsl:when test="$type='datetime'">
+			<xsl:text>datetime</xsl:text>
+	    </xsl:when>
+	    <xsl:when test="$type='float' or 
+						$type='double'">
+		<xsl:text>double</xsl:text>
+	    </xsl:when>
+	    <xsl:when test="$type='string' or
+						$type='text' or
+						$type='binary'">
+		<xsl:text>str</xsl:text>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+
+<!-- Support berkeley db NULL values? -->
+<!--	<xsl:if test="$null=1">
+	    <xsl:text>,null</xsl:text>
+	</xsl:if>-->
+	<xsl:text>)</xsl:text>
+	<xsl:if test="not(position()=last())">
+	    <xsl:text> </xsl:text>
+	</xsl:if>
+	<xsl:if test="position()=last()">
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <!-- Escape all | occurrences -->
+    <xsl:template name="escape">
+	<xsl:param name="value"/>
+	<xsl:choose>
+	    <xsl:when test="contains($value, '|')">
+		<xsl:value-of select="concat(substring-before($value, '|'), '\|')"/>
+		<xsl:call-template name="escape">
+		    <xsl:with-param name="value" select="substring-after($value, '|')"/>
+		</xsl:call-template>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="$value"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+  <!-- create the non primary indexes -->
+	<xsl:template name="create_index">
+	<!-- save the parent table name -->
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+		</xsl:call-template>
+	</xsl:variable>
+	<!-- loop over all colrefs -->
+	<xsl:for-each select="colref">
+		<xsl:variable name="link">
+			<xsl:call-template name="get-column-name">
+			<xsl:with-param name="select" select="@linkend"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<!-- and search the right position of the link -->
+		<xsl:for-each select="//table[name = $table.name]/column">
+			<xsl:if test="@id = $link">
+			<!-- xsl count from 1 -->
+				<xsl:value-of select="position() - 1"/>
+				<xsl:text> </xsl:text>
+			</xsl:if>
+		</xsl:for-each>
+	</xsl:for-each>
+
+	</xsl:template>
+
+</xsl:stylesheet>

+ 116 - 0
doc/stylesheets/dbschema_k/xsl/dbdoc.xsl

@@ -0,0 +1,116 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: db_berkeley.xsl 3142 2007-11-15 14:09:15Z henningw $
+ *
+ * XSL converter script for generating module parameter documentation.
+ *
+ * Copyright (C) 2008 Henning Westerholt
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+
+	<xsl:import href="common.xsl"/>
+    <!-- Create the file for the tables in module subdirectory -->
+	<xsl:template match="/">
+		<xsl:variable name="createfile" select="concat($dir, concat('/', concat($prefix, '_db.xml')))"/>
+		<xsl:document href="{$createfile}" method="xml" indent="yes" omit-xml-declaration="yes">
+
+<xsl:comment xml:space="preserve">
+WARNING:
+This file was autogenerated from the XML source file
+<xsl:value-of select="concat($dir, 'kamailio-', $prefix, '.xml.')"/>
+It can be regenerated by running 'make dbdoc' in the db/schema
+directory of the source code. You need to have xsltproc and
+docbook-xsl stylesheets installed.
+ALL CHANGES DONE HERE WILL BE LOST IF THE FILE IS REGENERATED&#x0A;</xsl:comment>
+
+<xsl:text>&#x0A;</xsl:text>
+
+			<chapter>
+			<title>Module parameter for database access.</title>
+
+			<section>
+			<title><varname>db_url</varname> (String)</title>
+			<para>URL to the database containing the data.</para>
+			<para>
+				<!-- TODO use ro or rw URL depending on the module -->
+				<emphasis>Default value is <quote>mysql://openserro:openserro@localhost/openser</quote>.</emphasis>
+			</para>
+			<example>
+				<title>Set <varname>db_url</varname> parameter</title>
+				<programlisting format="linespecific">
+					<xsl:value-of select="concat('&#x0A;...&#x0A;modparam(&quot;', $prefix, '&quot;, &quot;db_url&quot;, &quot;dbdriver://username:password@dbhost/dbname&quot;)&#x0A;...&#x0A;')"/>
+				</programlisting>
+			</example>
+			</section>
+
+			<xsl:apply-templates select="/database[1]"/>
+			</chapter>
+		</xsl:document>
+
+	</xsl:template>
+
+
+	<!-- create table name parameter -->
+	<xsl:template match="table">
+	<xsl:variable name="name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<section>
+		<title><varname><xsl:value-of select="concat($name, '_table')"/></varname> (String)</title>
+		<para><xsl:value-of select="concat('Name of the ', $name, ' table for the ', $prefix, ' module.')"/></para>
+		<para>
+			<emphasis>Default value is <quote><xsl:value-of select="$name"/></quote>.</emphasis>
+		</para>
+		<example>
+			<title>Set <varname><xsl:value-of select="concat($name, '_table')"/></varname> parameter</title>
+			<programlisting format="linespecific">
+				<xsl:value-of select="concat('&#x0A;...&#x0A;modparam(&quot;', $prefix, '&quot;, &quot;', $name, '_table&quot;, &quot;', $name, '&quot;)&#x0A;...&#x0A;')"/>
+			</programlisting>
+		</example>
+	</section>
+	<xsl:apply-imports/>
+	</xsl:template>
+
+	<!-- Create column parameter -->
+	<xsl:template match="column">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+		</xsl:call-template>
+	</xsl:variable>
+	<xsl:variable name="column.name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<section>
+		<title><varname><xsl:value-of select="concat($table.name, '_', $column.name, '_col')"/></varname> (string)</title>
+		<para><xsl:value-of select="description"/></para>
+		<example>
+			<title>Set <varname><xsl:value-of select="concat($table.name, '_', $column.name, '_col')"/></varname> parameter</title>
+			<programlisting format="linespecific">
+				<xsl:value-of select="concat('&#x0A;...&#x0A;modparam(&quot;', $prefix, '&quot;, &quot;', $table.name, '_', $column.name, '_col&quot;, &quot;', $column.name, '&quot;)&#x0A;...&#x0A;')"/>
+			</programlisting>
+		</example>
+	</section>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 302 - 0
doc/stylesheets/dbschema_k/xsl/dbschema2docbook.xsl

@@ -0,0 +1,302 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+
+<!--
+ * $Id: dbschema2docbook.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * database schema to docbook convert xsl script
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<!-- Namespaces are NOT used in docbook < 5.0 - they SHOULD NOT be used in db schema description -->
+<!--
+<xsl:stylesheet version="1.0" xmlns="http://docbook.org/ns/docbook"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+>-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<!-- doctype-system, doctyp-public found in http://www.xml.com/pub/a/2002/09/04/xslt.html -->
+<!--<xsl:output method="xml" indent="yes" version="1.0"
+	doctype-system="http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" 
+	doctype-public="-//OASIS//DTD DocBook XML V4.2//EN"/>-->
+
+<xsl:template match="//database">
+<!--<section><title><xsl:value-of select="name"/> database tables</title>-->
+	<!-- generate table descriptions -->
+	<xsl:choose>
+	<xsl:when test="table">
+	<para><variablelist>
+		<xsl:for-each select="table">
+			<xsl:call-template name="table_proc_desc" mode="table_desc"/>
+		</xsl:for-each>
+	</variablelist></para>
+
+	<!-- generate table contents -->
+	<para>
+		<xsl:for-each select="table">
+			<xsl:call-template name="table_proc" mode="column_table"/>
+		</xsl:for-each>
+	</para>
+	</xsl:when>
+	<xsl:otherwise>
+	<para/><!-- no table present, insert some dummy content to make docbook happy -->
+	</xsl:otherwise>
+	</xsl:choose>
+<!--</section>-->
+</xsl:template>
+
+<!-- Needed for copying whole nodes from db schema description. We
+can not use xsl:copy because in such case are always included namespaces
+defined in compiled document (ser.xml for example uses 
+xmlns:xi="http://www.w3.org/2001/XInclude") but Docbook DTD (version less 
+than 5) doesn't allow "xmlns" attributes -->
+
+
+<xsl:template match="@*|node()" mode="copying">
+	<xsl:choose>	
+		<xsl:when test="local-name() and node()"> <!-- it is probably an element ;-) -->
+					<xsl:element name="{local-name()}">
+						<xsl:apply-templates select="@*|node()" mode="copying"/>
+					</xsl:element>
+		</xsl:when>
+		<xsl:otherwise> <!-- anything else - copy it -->
+			<xsl:copy>
+				<xsl:apply-templates select="@*|node()" mode="copying"/>
+			</xsl:copy>
+		</xsl:otherwise>
+	</xsl:choose>
+</xsl:template>
+
+<xsl:template name="copy_content_without_namespaces">
+	<xsl:apply-templates select="@*|node()" mode="copying"/>
+</xsl:template>
+
+<!-- Common processing <description> node within <table> and within <column>:
+       - text in <description> element is given at first (if not empty, it is nested in para)
+	   - all nested elements are included
+	   - if there are no nested elements the text is added even if empty
+-->
+<xsl:template name="process_description">
+	<xsl:choose>
+		<xsl:when test="description/*">
+			<xsl:choose>
+				<xsl:when test="description/para"> <!-- there are some para elements -->
+					<xsl:for-each select="description"><xsl:call-template
+					name="copy_content_without_namespaces"/></xsl:for-each>
+				</xsl:when>
+				
+				<xsl:when test="description/*[local-name()='para']"> <!-- there are some para elements -->
+<!--					<xsl:message>copying description X: '<xsl:value-of select="description/text()"/>'</xsl:message>-->
+					<xsl:for-each select="description"><xsl:call-template
+					name="copy_content_without_namespaces"/></xsl:for-each>
+				</xsl:when>
+				
+				<!-- if text of description is not empty add description
+				internals into a para element -->
+				<xsl:otherwise>
+<!--					<xsl:message>copying description into para: '<xsl:value-of select="description/text()"/>'</xsl:message>-->
+					<para><xsl:for-each select="description">
+					<xsl:call-template name="copy_content_without_namespaces"/></xsl:for-each></para>
+				</xsl:otherwise>
+
+			</xsl:choose>
+		</xsl:when>
+		<xsl:otherwise>
+			<!-- use text within description element (may be empty) -->
+			<para>
+			<xsl:choose>
+			<xsl:when test="description/text()">
+				<xsl:value-of select="description/text()"/>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:text> </xsl:text>
+			</xsl:otherwise>
+			</xsl:choose>
+			</para>
+		</xsl:otherwise>
+	</xsl:choose>
+</xsl:template>
+
+<xsl:template name="table_proc_desc" match="table" mode="table_desc">
+	<xsl:variable name="tmp" select="translate(name, '_', '-')"/> <!-- '_' is not allowed in docbook -->
+	<varlistentry>
+		<term><link linkend='gen-db-{$tmp}'><xsl:value-of select="name"/></link></term>
+		<listitem><xsl:call-template name="process_description"/></listitem>
+	</varlistentry>
+</xsl:template>
+
+<xsl:template name="table_proc" match="table" mode="column_table">
+
+	<!-- create table for columns --> 
+
+	<!--<section><title><xsl:value-of select="name"/></title>
+	<para><xsl:value-of select="description"/></para>-->
+
+	<xsl:variable name="tmp" select="translate(name, '_', '-')"/> <!-- '_' is not allowed in docbook -->
+	<table id='gen-db-{$tmp}' frame='all'><title>Table "<xsl:value-of select="name"/>"</title>
+	<tgroup cols='8' align='left' colsep='1' rowsep='1'>
+	<!--<colspec colname="c1"/><colspec colname="c2"/><colspec colname="c3"/><colspec colname="c4"/>-->
+	<thead>
+		<row>
+			<entry>name</entry>
+			<entry>type</entry>
+			<entry>size</entry>
+			<entry>default</entry>
+			<entry>null</entry>
+			<entry>key</entry>
+			<entry>extra attributes</entry>
+			<entry>description</entry>
+		</row>
+	</thead>
+	<tbody>
+	<xsl:for-each select="column">
+		<row>
+			<entry><varname><xsl:value-of select="name"/></varname></entry>
+			<entry><varname><xsl:value-of select="type"/></varname></entry>
+
+			<!-- some datatypes (e.g. time) don't have a size -->
+			<entry><constant>
+			<xsl:choose>
+			<xsl:when test="size">
+				<xsl:value-of select="size"/>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:text>not specified</xsl:text>
+			</xsl:otherwise>
+			</xsl:choose>
+			</constant></entry>
+			
+			<entry>
+			<xsl:choose>
+			<xsl:when test="default">
+				<xsl:choose>
+					<xsl:when test="default/null">
+						<xsl:text>NULL</xsl:text>
+					</xsl:when>
+				    <xsl:when test= "string(number(default))='NaN'"><!-- test for string value -->
+						<xsl:text>'</xsl:text>
+						<xsl:value-of select="default"/>
+						<xsl:text>'</xsl:text>
+		    		</xsl:when>
+		    		<xsl:otherwise>
+						<xsl:value-of select="default"/><!-- ommit the quotes for numbers -->
+		    		</xsl:otherwise>
+				</xsl:choose>
+			</xsl:when>
+
+			<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
+			</xsl:choose>
+			</entry>
+
+			<entry>
+			<xsl:choose>
+			<xsl:when test="null">
+				<xsl:text>yes</xsl:text>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:text>no</xsl:text>
+			</xsl:otherwise>
+			</xsl:choose>
+			</entry>
+
+			<entry>
+			<xsl:choose>
+			<xsl:when test="primary">
+				<xsl:text>primary</xsl:text>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:text> </xsl:text>
+			</xsl:otherwise>
+			</xsl:choose>
+			</entry>
+
+			<entry>
+			<xsl:choose>
+			<xsl:when test="autoincrement">
+				<xsl:text>autoincrement</xsl:text>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:text> </xsl:text>
+			</xsl:otherwise>
+			</xsl:choose>
+			</entry>
+
+			<entry><xsl:call-template name="process_description"/></entry>
+		</row>
+	</xsl:for-each>
+	</tbody></tgroup></table>
+	
+	<!-- create table for indexes -->
+	<xsl:if test="index">
+		<table id='gen-db-{$tmp}-index' frame='all'><title>Table "<xsl:value-of select="name"/>" indexes</title>
+		<tgroup cols='4' align='left' colsep='1' rowsep='1'>
+		<thead>
+			<row>
+				<entry>name</entry>
+				<entry>type</entry>
+				<entry>links</entry>
+				<entry>description</entry>
+			</row>
+		</thead>
+		<tbody>
+		<xsl:for-each select="index">
+			<row>
+				<entry><varname><xsl:value-of select="name"/></varname></entry>
+				<entry>
+				<xsl:choose>
+				<xsl:when test="unique">
+					<xsl:text>unique</xsl:text>
+				</xsl:when>
+				<xsl:when test="primary">
+					<xsl:text>primary</xsl:text>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:text>default</xsl:text>
+				</xsl:otherwise>
+				</xsl:choose>
+				</entry>
+				
+				<entry>
+				<xsl:choose>
+				<xsl:when test="colref">
+					<xsl:for-each select="colref">
+					<xsl:call-template name="get-column-name">
+						<xsl:with-param name="select" select="@linkend"/>
+					</xsl:call-template>
+					<xsl:if test="not(position()=last())">
+						<xsl:text>, </xsl:text>
+					</xsl:if>
+					</xsl:for-each>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:text> </xsl:text>
+				</xsl:otherwise>
+				</xsl:choose>
+				</entry>
+				<entry><xsl:call-template name="process_description"/></entry>
+			</row>
+		</xsl:for-each>
+		</tbody></tgroup></table>
+	</xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>

+ 126 - 0
doc/stylesheets/dbschema_k/xsl/dbtext.xsl

@@ -0,0 +1,126 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: dbtext.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for dbtext
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude">
+
+    <xsl:import href="common.xsl"/>
+    <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
+
+    <!-- Create the file for the table in dbtext subdirectory -->
+    <xsl:template match="table">
+	<xsl:variable name="name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+	
+	<xsl:variable name="path" select="concat($dir, concat('/', concat($prefix, $name)))"/>
+	<xsl:document href="{$path}" method="text" indent="no" omit-xml-declaration="yes">
+		<xsl:apply-imports/>
+		<!-- Insert version data -->
+		 <xsl:apply-templates select="version"/> 
+		<!-- this is not exactly what we want for dbtext, as the version data gets
+		     appended to the actual table file, and no to the 'version' table.
+		     But its not possible (at least with XSL 1.0, AFAIK) to append data to a
+		     file. So it's much more easier to do this in the Makefile -->
+	</xsl:document>
+    </xsl:template>
+
+    <!-- version data template -->
+    <xsl:template match="version">
+	<xsl:call-template name="get-name">
+	    <xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	<xsl:text>:</xsl:text>
+	<xsl:value-of select="text()"/>
+	<xsl:text>&#x0A;</xsl:text>
+    </xsl:template>
+
+    <!-- Create column definitions -->
+    <xsl:template match="column">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:variable name="null">
+	    <xsl:call-template name="get-null"/>
+	</xsl:variable>
+
+	<xsl:call-template name="get-name"/>
+	<xsl:text>(</xsl:text>
+	<xsl:choose>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
+	    </xsl:when>
+	    <xsl:when test="$type='char' or 
+						$type='short' or 
+						$type='int' or
+						$type='long' or 
+						$type='datetime'">
+		<xsl:text>int</xsl:text>
+	    </xsl:when>
+	    <xsl:when test="$type='float' or 
+						$type='double'">
+		<xsl:text>double</xsl:text>
+	    </xsl:when>
+	    <xsl:when test="$type='string' or
+						$type='text' or
+						$type='binary'">
+		<xsl:text>string</xsl:text>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+
+	<xsl:if test="$null=1">
+	    <xsl:text>,null</xsl:text>
+	</xsl:if>
+	<xsl:text>) </xsl:text>
+	<xsl:if test="position()=last()">
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <!-- Escape all : occurrences -->
+    <xsl:template name="escape">
+	<xsl:param name="value"/>
+	<xsl:choose>
+	    <xsl:when test="contains($value, ':')">
+		<xsl:value-of select="concat(substring-before($value, ':'), '\:')"/>
+		<xsl:call-template name="escape">
+		    <xsl:with-param name="value" select="substring-after($value, ':')"/>
+		</xsl:call-template>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:value-of select="$value"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+</xsl:stylesheet>

+ 54 - 0
doc/stylesheets/dbschema_k/xsl/docbook.xsl

@@ -0,0 +1,54 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: docbook.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for docbook
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
+    <xsl:import href="common.xsl"/>
+    <xsl:import href="dbschema2docbook.xsl"/>
+
+    <xsl:template match="/">
+	<xsl:variable name="path" select="concat($dir, concat('/', concat($prefix, 'dbschema.xml')))"/>
+	<xsl:document href="{$path}" method="xml" indent="yes" omit-xml-declaration="yes">
+	<!-- only needed for stand alone documents for each table -->
+	<!--doctype-system="http://www.oasis-open.org/docbook/sgml/4.4/docbook.dtd"
+	doctype-public="-//OASIS//DTD DocBook V4.4//EN">-->
+	<!--<xsl:element name="book">-->
+	<xsl:element name="chapter">
+	    <!--<xsl:element name="section">-->
+		<xsl:element name="title">
+		    <xsl:call-template name="get-name">
+			<xsl:with-param name="select" select="database[1]"/>
+		    </xsl:call-template>
+		</xsl:element>
+		<xsl:apply-templates select="/database[1]"/>
+	    <!--</xsl:element>-->
+	</xsl:element>
+        <!--</xsl:element>-->
+	</xsl:document>
+    </xsl:template>
+
+</xsl:stylesheet>

+ 240 - 0
doc/stylesheets/dbschema_k/xsl/modules_c.xsl

@@ -0,0 +1,240 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: db_berkeley.xsl 3142 2007-11-15 14:09:15Z henningw $
+ *
+ * XSL converter script for generating module parameter templates.
+ *
+ * Copyright (C) 2008 Henning Westerholt
+ *
+ * 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
+ *
+ */
+-->
+
+<!--
+ * Yes, this is probably not pretty, as XSL is not the perfect tool to generate
+ * C code. But we've now this infrastructure for the databases, and it works.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<xsl:import href="common.xsl"/>
+<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
+
+    <!-- Create the file for the tables in module subdirectory -->
+<xsl:template match="/">
+	<xsl:variable name="createfile" select="concat($dir, concat('/', concat('db_', $prefix, '.c')))"/>
+	<xsl:document href="{$createfile}" method="text" indent="no" omit-xml-declaration="yes">
+
+<!-- doxygen header -->
+<xsl:text>
+/*!
+ * \file
+ * \ingroup db
+ * \brief Database support for modules.
+ *
+ * Database support functions for modules.
+ *
+ * @cond
+ * WARNING:
+ * This file was autogenerated from the XML source file
+</xsl:text>
+<xsl:value-of select="concat(' * ', $dir, 'kamailio-', $prefix, '.xml.')"/>
+<xsl:text>
+ * It can be regenerated by running 'make modules' in the db/schema
+ * directory of the source code. You need to have xsltproc and
+ * docbook-xsl stylesheets installed.
+ * ALL CHANGES DONE HERE WILL BE LOST IF THE FILE IS REGENERATED
+ * @endcond
+ */
+
+</xsl:text>
+
+<xsl:value-of select="concat('#include &quot;', 'db_', $prefix, '.h&quot;&#x0A;&#x0A;')"/>
+
+<xsl:text>/* database variables */&#x0A;</xsl:text>
+<xsl:text>/* TODO assign read-write or read-only URI, introduce a parameter in XML */&#x0A;&#x0A;</xsl:text>
+<xsl:value-of select="concat('//extern str ', $prefix, '_db_url;&#x0A;')"/>
+<xsl:value-of select="concat('db_con_t * ', $prefix, '_dbh = NULL;&#x0A;')"/>
+<xsl:value-of select="concat('db_func_t ', $prefix, '_dbf;&#x0A;&#x0A;')"/>
+
+<xsl:apply-templates select="/database[1]"/>
+
+<xsl:text>
+/*
+ * Closes the DB connection.
+ */
+</xsl:text>
+<xsl:value-of select="concat('void ', $prefix, '_db_close(void) {&#x0A;')"/>
+<xsl:value-of select="concat('&#9;if (', $prefix, '_dbh) {&#x0A;')"/>
+<xsl:value-of select="concat('&#9;&#9;', $prefix, '_dbf.close(', $prefix, '_dbh);&#x0A;')"/>
+<xsl:value-of select="concat('&#9;&#9;', $prefix, '_dbh = NULL;&#x0A;&#9;}&#x0A;}&#x0A;&#x0A;')"/>
+
+<xsl:text>
+/*!
+ * Initialises the DB API, check the table version and closes the connection.
+ * This should be called from the mod_init function.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+</xsl:text>
+<xsl:value-of select="concat('int ', $prefix, '_db_init(void) {&#x0A;')"/>
+<xsl:value-of select="concat('&#9;if (!', $prefix, '_db_url.s || !', $prefix, '_db_url.len) {')"/>
+<xsl:text>
+		LM_ERR(&quot;you have to set the db_url module parameter.\n&quot;);
+		return -1;
+	}
+</xsl:text>
+<xsl:value-of select="concat('&#9;if (db_bind_mod(&amp;', $prefix, '_db_url, &amp;', $prefix, '_dbf) &lt; 0) {')"/>
+<xsl:text>
+		LM_ERR(&quot;can't bind database module.\n&quot;);
+		return -1;
+	}
+</xsl:text>
+<xsl:value-of select="concat('&#9;if ((', $prefix, '_dbh = ', $prefix, '_dbf.init(&amp;', $prefix, '_db_url)) == NULL) {')"/>
+<xsl:text>
+		LM_ERR(&quot;can't connect to database.\n&quot;);
+		return -1;
+	}
+</xsl:text>
+<xsl:text>	if (
+</xsl:text>
+
+<!-- create the table version check -->
+<xsl:for-each select="//database[1]/table">
+	<xsl:variable name="table">
+		<xsl:call-template name="get-name">
+		</xsl:call-template>
+	</xsl:variable>
+	<xsl:value-of select="concat('&#9;(db_check_table_version(&amp;', $prefix, '_dbf, ', $prefix, '_dbh, &amp;', $table, '_table, ', $table, '_version) &lt; 0)')"/>
+	<xsl:if test="not(position()=last())">
+		<xsl:text> ||&#x0A;</xsl:text>
+	</xsl:if>
+</xsl:for-each>
+<xsl:text>
+	) {
+		LM_ERR(&quot;during table version check.\n&quot;);
+</xsl:text>
+<xsl:value-of select="concat('&#9;&#9;', $prefix, '_db_close();')"/>
+<xsl:text>
+		return -1;
+	}
+</xsl:text>
+<xsl:value-of select="concat('&#9;', $prefix, '_db_close();')"/>
+<xsl:text>
+	return 0;
+}
+
+</xsl:text>
+
+<xsl:text>
+/*!
+ * Initialize the DB connection without checking the table version and DB URL.
+ * This should be called from child_init. An already existing database
+ * connection will be closed, and a new one created.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+</xsl:text>
+<xsl:value-of select="concat('int ', $prefix, '_db_open(void) {&#x0A;')"/>
+<xsl:value-of select="concat('&#9;if (', $prefix, '_dbh) {&#x0A;')"/>
+<xsl:value-of select="concat('&#9;&#9;', $prefix, '_dbf.close(', $prefix, '_dbh);&#x0A;&#9;}&#x0A;')"/>
+<xsl:value-of select="concat('&#9;if ((', $prefix, '_dbh = ', $prefix, '_dbf.init(&amp;', $prefix, '_db_url)) == NULL) {')"/>
+<xsl:text>
+		LM_ERR(&quot;can't connect to database.\n&quot;);
+		return -1;
+	}
+	return 0;
+}
+
+</xsl:text>
+
+<xsl:text>
+/*!
+ * Update the variable length after eventual assignments from the config script.
+ * This is necessary because we're using the 'str' type.
+ */
+</xsl:text>
+<xsl:value-of select="concat('void ', $prefix, '_db_vars(void) {&#x0A;')"/>
+<!-- TODO remove if case, if db_url is also set from this code -->
+<xsl:value-of select="concat('&#9;if (', $prefix, '_db_url.s) ', $prefix, '_db_url.len = strlen(', $prefix, '_db_url.s);&#x0A;')"/>
+
+<xsl:for-each select="//database[1]/table">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		</xsl:call-template>
+	</xsl:variable>
+	<xsl:value-of select="concat('&#9;', $table.name, '_table.len = strlen(', $table.name, '_table.s',');&#x0A;')"/>
+	<xsl:for-each select="column">
+		<xsl:variable name="column.name">
+			<xsl:call-template name="get-name"/>
+		</xsl:variable>
+		<xsl:value-of select="concat('&#9;', $table.name, '_', $column.name, '_col.len = strlen(', $table.name, '_', $column.name, '_col.s', ');&#x0A;')"/>
+	</xsl:for-each>
+</xsl:for-each>
+<xsl:text>}&#x0A;</xsl:text>
+		<xsl:text>&#x0A;</xsl:text>
+
+</xsl:document>
+</xsl:template>
+
+	<!-- create table name parameter -->
+	<xsl:template match="table">
+	<xsl:variable name="name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+
+	<xsl:value-of select="concat('str ', $name, '_table = str_init(&quot;', $name, '&quot;);&#x0A;')"/>
+	<xsl:text>&#x0A;</xsl:text>
+
+	<xsl:text>/* column names */&#x0A;</xsl:text>
+	<xsl:apply-imports/>
+
+	<xsl:text>&#x0A;</xsl:text>
+	<xsl:text>/* table version */&#x0A;</xsl:text>
+	<xsl:apply-templates select="version"/>
+	</xsl:template>
+
+	<!-- create version parameter -->
+	<xsl:template match="version">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	</xsl:variable>
+	<xsl:value-of select="concat('const unsigned int ', $table.name, '_version', ' = ')"/>
+	<xsl:value-of select="text()"/>
+	<xsl:text>;&#x0A;</xsl:text>
+	<xsl:text>&#x0A;</xsl:text>
+	</xsl:template>
+
+	<!-- Create column parameter -->
+	<xsl:template match="column">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+		</xsl:call-template>
+	</xsl:variable>
+	<xsl:variable name="column.name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:value-of select="concat('str ', $table.name, '_', $column.name, '_col = str_init(&quot;', $column.name, '&quot;);&#x0A;')"/>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 187 - 0
doc/stylesheets/dbschema_k/xsl/modules_h.xsl

@@ -0,0 +1,187 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: db_berkeley.xsl 3142 2007-11-15 14:09:15Z henningw $
+ *
+ * XSL converter script for generating module parameter templates.
+ *
+ * Copyright (C) 2008 Henning Westerholt
+ *
+ * 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
+ *
+ */
+-->
+
+<!--
+ * Yes, this is probably not pretty, as XSL is not the perfect tool to generate
+ * C code. But we've now this infrastructure for the databases, and it works.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<xsl:import href="common.xsl"/>
+<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
+
+    <!-- Create the file for the tables in module subdirectory -->
+<xsl:template match="/">
+	<xsl:variable name="createfile" select="concat($dir, concat('/', concat('db_', $prefix, '.h')))"/>
+	<xsl:document href="{$createfile}" method="text" indent="no" omit-xml-declaration="yes">
+
+<!-- doxygen header -->
+<xsl:text>
+/*!
+ * \file
+ * \ingroup db
+ * \brief Database support for modules.
+ *
+ * Database support functions for modules.
+ *
+ * @cond
+ * WARNING:
+ * This file was autogenerated from the XML source file
+</xsl:text>
+<xsl:value-of select="concat(' * ', $dir, 'kamailio-', $prefix, '.xml.')"/>
+<xsl:text>
+ * It can be regenerated by running 'make modules' in the db/schema
+ * directory of the source code. You need to have xsltproc and
+ * docbook-xsl stylesheets installed.
+ * ALL CHANGES DONE HERE WILL BE LOST IF THE FILE IS REGENERATED
+ * @endcond
+ */
+
+</xsl:text>
+
+<!-- include guard -->
+<xsl:value-of select="concat('#ifndef db_', $prefix, '_h&#x0A;')"/>
+<xsl:value-of select="concat('#define db_', $prefix, '_h&#x0A;')"/>
+<xsl:text>
+
+/* necessary includes */
+#include "../../db/db.h"
+#include "../../str.h"
+#include "../../ut.h"
+
+#include &lt;string.h&gt;
+
+
+</xsl:text>
+<xsl:text>/* database variables */&#x0A;&#x0A;</xsl:text>
+<xsl:value-of select="concat('extern str ', $prefix, '_db_url;&#x0A;')"/>
+<xsl:value-of select="concat('extern db_con_t * ', $prefix, '_dbh;&#x0A;')"/>
+<xsl:value-of select="concat('extern db_func_t ', $prefix, '_dbf;&#x0A;&#x0A;')"/>
+
+<!-- macro for module parameter -->
+<xsl:value-of select="concat('#define ', $prefix, '_DB_URL { &quot;db_url&quot;, STR_PARAM, &amp;', $prefix, '_db_url.s },&#x0A;&#x0A;')"/>
+
+<xsl:apply-templates select="/database[1]"/>
+
+<xsl:text>
+/*
+ * Closes the DB connection.
+ */
+</xsl:text>
+<xsl:value-of select="concat('void ', $prefix, '_db_close(void);&#x0A;')"/>
+
+<xsl:text>
+/*!
+ * Initialises the DB API, check the table version and closes the connection.
+ * This should be called from the mod_init function.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+</xsl:text>
+<xsl:value-of select="concat('int ', $prefix, '_db_init(void);&#x0A;')"/>
+
+<xsl:text>
+/*!
+ * Initialize the DB connection without checking the table version and DB URL.
+ * This should be called from child_init. An already existing database
+ * connection will be closed, and a new one created.
+ *
+ * \return 0 means ok, -1 means an error occured.
+ */
+</xsl:text>
+<xsl:value-of select="concat('int ', $prefix, '_db_open(void);&#x0A;')"/>
+
+<xsl:text>
+/*!
+ * Update the variable length after eventual assignments from the config script.
+ * This is necessary because we're using the 'str' type.
+ */
+</xsl:text>
+<xsl:value-of select="concat('void ', $prefix, '_db_vars(void);&#x0A;')"/>
+
+<!-- include guard end -->
+		<xsl:text>&#x0A;</xsl:text>
+		<xsl:text>#endif&#x0A;</xsl:text>
+
+</xsl:document>
+</xsl:template>
+
+	<!-- create table name parameter -->
+	<xsl:template match="table">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+
+	<!-- macro for db table -->
+	<xsl:value-of select="concat('#define ', $table.name, '_DB_TABLE { &quot;', $table.name, '_table&quot;, STR_PARAM, &amp;', $prefix, '_table.s },&#x0A;&#x0A;')"/>
+	<xsl:value-of select="concat('extern str ', $table.name, '_table;&#x0A;')"/>
+	<xsl:text>&#x0A;</xsl:text>
+
+	<xsl:text>/* column names */&#x0A;</xsl:text>
+	<xsl:apply-imports/>
+
+	<!-- macros for db columns -->
+	<xsl:value-of select="concat('#define ', $table.name, '_DB_COLS \&#x0A;')"/>
+	<xsl:for-each select="column">
+		<xsl:variable name="column.name">
+			<xsl:call-template name="get-name"/>
+		</xsl:variable>
+		<xsl:value-of select="concat('{ &quot;', $table.name, '_', $column.name, '_col&quot;, STR_PARAM, &amp;', $table.name, '_', $column.name, '_col.s }, \&#x0A;')"/>
+	</xsl:for-each>
+
+	<xsl:text>&#x0A;</xsl:text>
+	<xsl:text>/* table version */&#x0A;</xsl:text>
+	<xsl:apply-templates select="version"/>
+	</xsl:template>
+
+	<!-- create version parameter -->
+	<xsl:template match="version">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	</xsl:variable>
+	<xsl:value-of select="concat('extern const unsigned int ', $table.name, '_version;&#x0A;')"/>
+	<xsl:text>&#x0A;</xsl:text>
+	</xsl:template>
+	<!-- Create column parameter -->
+	<xsl:template match="column">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+		</xsl:call-template>
+	</xsl:variable>
+	<xsl:variable name="column.name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:value-of select="concat('extern str ', $table.name, '_', $column.name, '_col;&#x0A;')"/>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 140 - 0
doc/stylesheets/dbschema_k/xsl/mysql.xsl

@@ -0,0 +1,140 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: mysql.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for mysql databases
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude"
+>
+
+    <xsl:import href="sql.xsl"/>
+
+<!--
+    <xsl:template match="database" mode="drop">
+	<xsl:apply-templates mode="drop"/>
+    </xsl:template>
+-->
+
+<!-- specify the table type -->
+    <xsl:template name="table.close">
+	<xsl:text>)</xsl:text>
+	<xsl:if test="type[@db=$db]">
+	    <xsl:text> ENGINE=</xsl:text>
+	    <xsl:value-of select="normalize-space(type[@db=$db])"/>
+	</xsl:if>
+	<xsl:text>;&#x0A;&#x0A;</xsl:text>	
+    </xsl:template>
+
+    <xsl:template name="column.type">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:choose>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
+	    </xsl:when>
+	    <xsl:when test="$type='char'">
+		<xsl:text>TINYINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='short'">
+		<xsl:text>SMALLINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='int'">
+		<xsl:text>INT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='long'">
+		<xsl:text>BIGINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='datetime'">
+		<xsl:text>DATETIME</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='double'">
+		<xsl:text>DOUBLE</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='float'">
+		<xsl:text>FLOAT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='string'">
+		<xsl:text>VARCHAR</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='binary'">
+		<xsl:text>BLOB</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='text'">
+		<xsl:text>TEXT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="column.trailing">
+	<xsl:variable name="signed">
+	    <xsl:call-template name="get-sign"/>
+	</xsl:variable>	
+	<xsl:if test="$signed = 0">
+	    <xsl:text> UNSIGNED</xsl:text>
+	</xsl:if>
+	<xsl:if test="autoincrement">
+	    <xsl:text> AUTO_INCREMENT</xsl:text>
+	</xsl:if>
+	<!-- PRIMARY KEY column defintion -->
+	<xsl:if test="primary">
+	    <xsl:text> PRIMARY KEY</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+	<xsl:template name="get-index-name">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:value-of select="$index.name"/>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 221 - 0
doc/stylesheets/dbschema_k/xsl/oracle.xsl

@@ -0,0 +1,221 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: oracle.xsl 4535 2008-08-01 10:37:23Z henningw $
+ *
+ * XSL converter script for oracle databases
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:db="http://iptel.org/dbschema/oracle"
+>
+
+    <xsl:import href="sql.xsl"/>
+
+    <xsl:template match="database" mode="drop">
+	<xsl:apply-templates mode="drop"/>
+    </xsl:template>
+
+    <xsl:template name="table.close">
+	<xsl:variable name="table.name">
+		<xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:text>)</xsl:text>
+	<xsl:text>;&#x0A;&#x0A;</xsl:text>
+
+	<!-- small hack, as the version table don't have an id field -->
+	<xsl:if test="not($table.name='version')">
+		<!-- create the autoincrement trigger -->
+		<xsl:text>CREATE OR REPLACE TRIGGER </xsl:text>
+		<xsl:value-of select="concat($table.name, '_tr&#x0A;')"/>
+		<xsl:text>before insert on </xsl:text>
+		<xsl:value-of select="$table.name"/>
+		<xsl:text> FOR EACH ROW&#x0A;</xsl:text>
+		<xsl:text>BEGIN&#x0A;</xsl:text>
+		<xsl:text>  auto_id(:NEW.id);&#x0A;</xsl:text>
+		<xsl:text>END </xsl:text>
+		<xsl:value-of select="concat($table.name, '_tr;&#x0A;')"/>
+		<xsl:text>/&#x0A;</xsl:text>
+	</xsl:if>
+	<xsl:text>BEGIN map2users('</xsl:text>
+	<xsl:value-of select="$table.name"/>
+	<xsl:text>'); END;&#x0A;</xsl:text>
+	<xsl:text>/&#x0A;</xsl:text>
+    </xsl:template>
+
+    <xsl:template name="column.type">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:choose>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(db:type)"/>
+	    </xsl:when>
+	    <xsl:when test="$type='char'">
+		<xsl:text>NUMBER(5)</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='short'">
+		<xsl:text>NUMBER(5)</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='int'">
+		<xsl:text>NUMBER(10)</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='bitmap'">
+		<xsl:text>NUMBER(11)</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='long'">
+		<xsl:text>BIGINT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='datetime'">
+		<xsl:text>DATE</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='double'">
+		<xsl:text>NUMBER</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='float'">
+		<xsl:text>NUMBER</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='string'">
+		<xsl:text>VARCHAR2</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='binary'">
+		<xsl:text>BLOB</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='text'">
+		<xsl:text>CLOB</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="column.trailing">
+	<xsl:variable name="signed">
+	    <xsl:call-template name="get-sign"/>
+	</xsl:variable>
+	<!-- PRIMARY KEY column definition -->
+	<xsl:if test="primary">
+		<xsl:variable name="table.name">
+	    	<xsl:call-template name="get-name">
+				<xsl:with-param name="select" select="parent::table"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<xsl:text> PRIMARY KEY</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <!-- copied from sql.xsl, for oracle the empty string and NULL are equivalent -->
+    <xsl:template match="column">
+	<xsl:text>    </xsl:text>
+	<xsl:call-template name="get-name"/>
+	<xsl:text> </xsl:text>
+
+	<xsl:call-template name="column.type"/>
+
+	<xsl:choose>
+	    <xsl:when test="default[@db=$db]">
+		<xsl:text> DEFAULT </xsl:text>
+		<xsl:choose>
+		    <xsl:when test="default[@db=$db]/null">
+			<xsl:text>NULL</xsl:text>
+		    </xsl:when>
+		    <xsl:otherwise>
+			<xsl:value-of select="default[@db=$db]"/>
+		    </xsl:otherwise>
+		</xsl:choose>
+	    </xsl:when>
+	    <xsl:when test="default">
+		<xsl:text> DEFAULT </xsl:text>
+		<xsl:choose>
+		    <xsl:when test="default/null">
+			<xsl:text>NULL</xsl:text>
+		    </xsl:when>
+		    <xsl:when test="string(number(default))='NaN'"><!-- test for string value -->
+			<xsl:text>'</xsl:text>
+			<xsl:value-of select="default"/>
+			<xsl:text>'</xsl:text>
+		    </xsl:when>
+		    <xsl:otherwise>
+			<xsl:value-of select="default"/><!-- ommit the quotes for numbers -->
+		    </xsl:otherwise>
+		</xsl:choose>
+	    </xsl:when>
+	</xsl:choose>
+
+	<xsl:variable name="null">
+	    <xsl:call-template name="get-null"/>
+	</xsl:variable>
+	<xsl:if test="$null=0">
+		<xsl:if test="string(number(default))!='NaN'"><!-- test for string value -->
+	    	<xsl:text> NOT NULL</xsl:text>
+		</xsl:if>
+	</xsl:if>
+
+	<xsl:if test="not(position()=last())">
+	    <xsl:text>,</xsl:text>
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+	<xsl:template name="get-index-name">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:variable name="table.name">
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	<!-- because oracle don't allow index names longer than 30 -->
+	<xsl:choose>
+	<xsl:when test="not(string-length(concat($table.name, '_', $index.name)) > 30)">
+		<xsl:value-of select="concat($table.name, '_', $index.name, ' ')"/>
+	</xsl:when>
+	<xsl:otherwise>
+		<xsl:value-of select="concat('ORA_', $index.name, ' ')"/>
+	</xsl:otherwise>
+	</xsl:choose>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 135 - 0
doc/stylesheets/dbschema_k/xsl/postgres.xsl

@@ -0,0 +1,135 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: postgres.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for postgresql databases
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+                xmlns:xi="http://www.w3.org/2001/XInclude"
+>
+
+    <xsl:import href="sql.xsl"/>
+
+<!-- specify the table type -->
+    <xsl:template name="table.close">
+	<xsl:text>)</xsl:text>
+	<xsl:if test="type[@db=$db]">
+	    <xsl:text> Type=</xsl:text>
+	    <xsl:value-of select="normalize-space(type[@db=$db])"/>
+	</xsl:if>
+	<xsl:text>;&#x0A;&#x0A;</xsl:text>	
+    </xsl:template>
+
+    <xsl:template name="column.type">
+	<xsl:variable name="type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+
+	<xsl:choose>
+	    <xsl:when test="type[@db=$db]">
+		<xsl:value-of select="normalize-space(type[@db=$db])"/>
+	    </xsl:when>
+	    <xsl:when test="$type='char'">
+		<xsl:text>SMALLINT</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='short'">
+		<xsl:text>SMALLINT</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='int'">
+			<xsl:if test="not(autoincrement)">
+				<xsl:text>INTEGER</xsl:text>
+			</xsl:if>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='long'">
+		<xsl:text>BIGINT</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='datetime'">
+		<xsl:text>TIMESTAMP</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='double'">
+		<xsl:text>DOUBLE PRECISION</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='float'">
+		<xsl:text>REAL</xsl:text>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='string'">
+		<xsl:text>VARCHAR</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='binary'">
+		<xsl:text>BYTEA</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:when test="$type='text'">
+		<xsl:text>TEXT</xsl:text>
+		<xsl:call-template name="column.size"/>
+		<xsl:call-template name="column.trailing"/>
+	    </xsl:when>
+	    <xsl:otherwise>
+		<xsl:call-template name="type-error"/>
+	    </xsl:otherwise>
+	</xsl:choose>
+	</xsl:template>
+
+	<xsl:template name="column.trailing">
+	<xsl:variable name="column.type">
+	    <xsl:call-template name="get-type"/>
+	</xsl:variable>
+	<xsl:if test="$column.type='datetime'">
+	    <xsl:text> WITHOUT TIME ZONE</xsl:text>
+	</xsl:if>
+	<xsl:if test="autoincrement">
+		<xsl:text>SERIAL</xsl:text>
+	</xsl:if>
+	<!-- PRIMARY KEY column definition -->
+	<xsl:if test="primary">
+		<xsl:text> PRIMARY KEY</xsl:text>
+	</xsl:if>
+	</xsl:template>
+
+	<xsl:template name="get-index-name">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:variable name="table.name">
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	    </xsl:call-template>
+	</xsl:variable>
+	<!-- because postgres don't like identical index names, even on table level -->
+	<xsl:value-of select="concat($table.name, '_', $index.name)"/>
+	</xsl:template>
+
+</xsl:stylesheet>

+ 258 - 0
doc/stylesheets/dbschema_k/xsl/sql.xsl

@@ -0,0 +1,258 @@
+<?xml version='1.0'?>
+<!--
+ * $Id: sql.xsl 4518 2008-07-28 15:39:28Z henningw $
+ *
+ * XSL converter script for SQL
+ *
+ * Copyright (C) 2001-2007 FhG Fokus
+ *
+ * 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
+ *
+ */
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version='1.0'
+>
+
+    <xsl:import href="common.xsl"/>
+
+    <xsl:template match="/">
+	<xsl:variable name="createfile" select="concat($dir, concat('/', concat($prefix, 'create.sql')))"/>
+	<xsl:document href="{$createfile}" method="text" indent="no" omit-xml-declaration="yes">
+	    <xsl:apply-templates select="/database[1]"/>
+	</xsl:document>
+
+    </xsl:template>
+
+<!-- ################ DATABASE ################# -->
+
+<!-- ################ /DATABASE ################# -->
+
+
+<!-- ################ TABLE  ################# -->
+
+    <xsl:template match="table">
+	<xsl:variable name="table.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+
+	<!-- Create row in version table -->
+	<xsl:apply-templates select="version"/>
+
+	<xsl:text>CREATE TABLE </xsl:text>
+	<xsl:value-of select="$table.name"/>
+	<xsl:text> (&#x0A;</xsl:text>
+
+	<!-- Process all columns -->
+	<xsl:apply-templates select="column"/>
+
+	<!-- Process all unique indexes -->
+	<xsl:apply-templates select="index[child::unique]"/>
+
+	<!-- Process all primary indexes -->
+	<xsl:apply-templates select="index[child::primary]"/>
+
+	<xsl:text>&#x0A;</xsl:text>
+
+	<xsl:call-template name="table.close"/>
+
+	<xsl:for-each select="index[count(child::unique)=0]">
+	    <xsl:if test="not(child::primary)">
+	        <xsl:call-template name="create_index"/>
+	    </xsl:if>
+	</xsl:for-each>
+    </xsl:template>
+
+<!-- ################ /TABLE ################  -->
+
+
+<!-- ################ /VERSION ################  -->
+
+	<xsl:template match="version">
+	<xsl:text>INSERT INTO version (table_name, table_version) values ('</xsl:text>
+	<xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	</xsl:call-template>
+	<xsl:text>','</xsl:text>
+	<xsl:value-of select="text()"/>
+	<xsl:text>');&#x0A;</xsl:text>
+	</xsl:template>
+
+<!-- ################ /VERSION ################  -->
+
+
+<!-- ################ INDEX (constraint) ################  -->
+
+    <xsl:template match="index">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+
+	<xsl:if test="position()=1">
+	    <xsl:text>,&#x0A;</xsl:text>
+	</xsl:if>
+	<xsl:text>    </xsl:text>
+	<xsl:if test="not($index.name='')">
+		<xsl:text>CONSTRAINT </xsl:text>
+		<xsl:call-template name="get-index-name"/>
+	</xsl:if>
+	<xsl:if test="unique">
+		<xsl:text> UNIQUE (</xsl:text>
+		<xsl:apply-templates select="colref"/>
+		<xsl:text>)</xsl:text>
+	    <xsl:if test="not(position()=last())">
+		<xsl:text>,</xsl:text>
+		<xsl:text>&#x0A;</xsl:text>
+	    </xsl:if>
+	</xsl:if>
+	<!-- PRIMARY KEY standalone definition -->
+	<xsl:if test="primary">
+	    <xsl:text> PRIMARY KEY </xsl:text>
+	    <xsl:text> (</xsl:text>
+	    <xsl:apply-templates select="colref"/>
+	    <xsl:text>)</xsl:text>
+	    <xsl:if test="not(position()=last())">
+		<xsl:text>,</xsl:text>
+		<xsl:text>&#x0A;</xsl:text>
+	    </xsl:if>
+	</xsl:if>
+    </xsl:template>
+
+<!-- ################ /INDEX (constraint) ################  -->
+
+<!-- ################ INDEX (create) ################  -->
+
+    <xsl:template name="create_index">
+	<xsl:variable name="index.name">
+	    <xsl:call-template name="get-name"/>
+	</xsl:variable>
+	<xsl:variable name="table.name">
+	    <xsl:call-template name="get-name">
+		<xsl:with-param name="select" select="parent::table"/>
+	    </xsl:call-template>
+	</xsl:variable>
+
+	<xsl:text>CREATE </xsl:text>
+	<xsl:if test="unique">
+	    <xsl:text>UNIQUE </xsl:text>
+	</xsl:if>
+	<xsl:text>INDEX </xsl:text>
+	<xsl:if test="not($index.name='')">
+		<xsl:call-template name="get-index-name"/>
+	</xsl:if>
+	<xsl:text> ON </xsl:text>
+	<xsl:value-of select="$table.name"/>
+	<xsl:text> (</xsl:text>
+	<xsl:apply-templates select="colref"/>
+	<xsl:text>);&#x0A;</xsl:text>
+
+	<xsl:if test="position()=last()">
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+<!-- ################ /INDEX (create) ################  -->
+
+
+<!-- ################ COLUMN ################  -->
+
+    <xsl:template match="column">
+	<xsl:text>    </xsl:text>
+	<xsl:call-template name="get-name"/>
+	<xsl:text> </xsl:text>
+
+	<xsl:call-template name="column.type"/>
+
+	<xsl:choose>
+	    <xsl:when test="default[@db=$db]">
+		<xsl:text> DEFAULT </xsl:text>
+		<xsl:choose>
+		    <xsl:when test="default[@db=$db]/null">
+			<xsl:text>NULL</xsl:text>
+		    </xsl:when>
+		    <xsl:otherwise>
+			<xsl:value-of select="default[@db=$db]"/>
+		    </xsl:otherwise>
+		</xsl:choose>
+	    </xsl:when>
+	    <xsl:when test="default">
+		<xsl:text> DEFAULT </xsl:text>
+		<xsl:choose>
+		    <xsl:when test="default/null">
+			<xsl:text>NULL</xsl:text>
+		    </xsl:when>
+		    <xsl:when test="string(number(default))='NaN'"><!-- test for string value -->
+			<xsl:text>'</xsl:text>
+			<xsl:value-of select="default"/>
+			<xsl:text>'</xsl:text>
+		    </xsl:when>
+		    <xsl:otherwise>
+			<xsl:value-of select="default"/><!-- ommit the quotes for numbers -->
+		    </xsl:otherwise>
+		</xsl:choose>
+	    </xsl:when>
+	</xsl:choose>
+
+	<xsl:variable name="null">
+	    <xsl:call-template name="get-null"/>
+	</xsl:variable>
+	<xsl:if test="$null=0">
+	    <xsl:text> NOT NULL</xsl:text>
+	</xsl:if>
+
+	<xsl:if test="not(position()=last())">
+	    <xsl:text>,</xsl:text>
+	    <xsl:text>&#x0A;</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+    <xsl:template name="column.type">
+	<!-- FIXME -->
+	<xsl:call-template name="get-type"/>
+	<xsl:call-template name="column.size"/>
+    </xsl:template>
+
+    <xsl:template name="column.size">
+	<xsl:variable name="size">
+	    <xsl:call-template name="get-size"/>
+	</xsl:variable>
+
+	<xsl:if test="not($size='')">
+	    <xsl:text>(</xsl:text>
+	    <xsl:value-of select="$size"/>
+	    <xsl:text>)</xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+<!-- ################ /COLUMN ################  -->
+
+
+<!-- ################ COLREF ################  -->
+
+    <xsl:template match="colref">
+	<xsl:call-template name="get-column-name">
+	    <xsl:with-param name="select" select="@linkend"/>
+	</xsl:call-template>
+	<xsl:if test="not(position()=last())">
+	    <xsl:text>, </xsl:text>
+	</xsl:if>
+    </xsl:template>
+
+<!-- ################ /COLREF ################  -->
+
+</xsl:stylesheet>