Skip to content

Commit

Permalink
Merge pull request #1432 from agranig/agranig/db_redis
Browse files Browse the repository at this point in the history
db_redis: Implement db_redis generic db driver
  • Loading branch information
agranig committed Feb 14, 2018
2 parents 136f0b6 + 56ad142 commit 94e2fe9
Show file tree
Hide file tree
Showing 86 changed files with 4,395 additions and 3 deletions.
126 changes: 126 additions & 0 deletions doc/stylesheets/dbschema_k/xsl/db_redis.xsl
@@ -0,0 +1,126 @@
<?xml version='1.0'?>
<!--
* $Id: $
*
* XSL converter script for db_redis
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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: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' or
$type='largetext' or
$type='largebinary'">
<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>&amp;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>
2 changes: 1 addition & 1 deletion src/Makefile.groups
Expand Up @@ -153,7 +153,7 @@ mod_list_jansson=jansson
mod_list_jansson_event=janssonrpcc

# - modules depending on redis library
mod_list_redis=ndb_redis topos_redis
mod_list_redis=db_redis ndb_redis topos_redis

# - modules depending on mono library
mod_list_mono=app_mono
Expand Down
19 changes: 17 additions & 2 deletions src/lib/srdb1/schema/Makefile
Expand Up @@ -37,6 +37,9 @@ ORACLE_XSL = $(STYLESHEETS)/oracle.xsl
# Stylesheet used to generate mongodb database schema
MONGODB_XSL = $(STYLESHEETS)/mongodb.xsl

# Stylesheet used to generate Redis database schema
DB_REDIS_XSL = $(STYLESHEETS)/db_redis.xsl

# Stylesheet used to generate docbook documentation
DOCBOOK_XSL = $(STYLESHEETS)/docbook.xsl

Expand Down Expand Up @@ -69,7 +72,7 @@ ifeq ($(VERBOSE), 1)
override XSLTPROC := $(XSLTPROC) --verbose
endif

all: mysql postgres dbtext db_berkeley db_sqlite oracle mongodb pi_framework
all: mysql postgres dbtext db_berkeley db_sqlite oracle mongodb db_redis pi_framework

.PHONY: pi_framework pi_framework_clean
pi_framework:
Expand Down Expand Up @@ -227,6 +230,18 @@ mongodb:
mongodb_clean:
-@rm -f $(SCHEME)/mongodb/kamailio/*

.PHONY: db_redis db_redis_clean
db_redis:
for FILE in $(TABLES); do \
XML_CATALOG_FILES=$(CATALOG) $(XSLTPROC) $(XSLTPROC_FLAGS) \
--stringparam dir "$(SCHEME)/db_redis/kamailio" \
--stringparam prefix "" \
--stringparam db "db_redis" \
$(DB_REDIS_XSL) kamailio-"$$FILE".xml ; \
done

db_redis_clean:
-@rm -f $(SCHEME)/db_redis/*

.PHONY: docbook-xml
docbook-xml:
Expand Down Expand Up @@ -350,4 +365,4 @@ dbdoc_clean:
done

.PHONY: clean
clean: mysql_clean postgres_clean oracle_clean dbtext_clean db_berkeley_clean db_sqlite_clean pi_framework_clean docbook_clean # modules_clean dbdoc_clean
clean: mysql_clean postgres_clean oracle_clean dbtext_clean db_berkeley_clean db_sqlite_clean mongodb_clean db_redis_clean pi_framework_clean docbook_clean # modules_clean dbdoc_clean
31 changes: 31 additions & 0 deletions src/modules/db_redis/Makefile
@@ -0,0 +1,31 @@
#
# WARNING: do not run this directly, it should be run by the master Makefile

include ../../Makefile.defs
auto_gen=
NAME=db_redis.so

ifeq ($(CROSS_COMPILE),)
HIREDIS_BUILDER = $(shell \
if pkg-config --exists hiredis; then \
echo 'pkg-config hiredis'; \
fi)
endif

ifeq ($(HIREDIS_BUILDER),)
HIREDISDEFS=-I$(LOCALBASE)/include
HIREDISLIBS=-L$(LOCALBASE)/lib -lhiredis
else
HIREDISDEFS = $(shell $(HIREDIS_BUILDER) --cflags)
HIREDISLIBS = $(shell $(HIREDIS_BUILDER) --libs)
endif

DEFS+=$(HIREDISDEFS)
LIBS=$(HIREDISLIBS)

DEFS+=-DKAMAILIO_MOD_INTERFACE

SERLIBPATH=../../lib
SER_LIBS=$(SERLIBPATH)/srdb2/srdb2 $(SERLIBPATH)/srdb1/srdb1

include ../../Makefile.modules

0 comments on commit 94e2fe9

Please sign in to comment.