Module: sip-router
Branch: janakj/flatstore
Commit: fd142b4aa5797786db9261b60dea295c6576e7a0
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fd142b4…
Author: Tomas Mandys <tomas.mandys(a)iptel.org>
Committer: Tomas Mandys <tomas.mandys(a)iptel.org>
Date: Fri Jan 6 23:55:14 2006 +0000
- added record delimiter and escape char params
- escaping of delimiters in text
- zero delimiter supported via empty string delimiter param
---
modules/db_flatstore/flat_con.c | 14 ++--
modules/db_flatstore/flatstore.c | 106 ++++++++++++++++++++++------------
modules/db_flatstore/flatstore_mod.c | 39 ++++++++++---
modules/db_flatstore/flatstore_mod.h | 21 +++++--
4 files changed, 120 insertions(+), 60 deletions(-)
diff --git a/modules/db_flatstore/flat_con.c b/modules/db_flatstore/flat_con.c
index e148429..392b9c3 100644
--- a/modules/db_flatstore/flat_con.c
+++ b/modules/db_flatstore/flat_con.c
@@ -1,4 +1,4 @@
-/*
+/*
* $Id$
*
* Flastore module connection structure
@@ -22,8 +22,8 @@
* 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
+ * 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
*/
@@ -59,7 +59,7 @@ static char* get_name(struct flat_id* id)
total_len, buf_len);
return 0;
}
-
+
buf=pkg_malloc(buf_len);
if (buf==0){
LOG(L_ERR, "ERROR: get_name: memory allocation failure\n");
@@ -76,7 +76,7 @@ static char* get_name(struct flat_id* id)
ptr += id->table.len;
*ptr++ = '_';
-
+
num = int2str(flat_pid, &num_len);
if (buf_len<(total_len+num_len)){
LOG(L_ERR, "ERROR: get_name: the path is too long (%d and PATHMAX is"
@@ -114,7 +114,7 @@ struct flat_con* flat_new_connection(struct flat_id* id)
memset(res, 0, sizeof(struct flat_con));
res->ref = 1;
-
+
res->id = id;
fn = get_name(id);
@@ -130,7 +130,7 @@ struct flat_con* flat_new_connection(struct flat_id* id)
pkg_free(res);
return 0;
}
-
+
return res;
}
diff --git a/modules/db_flatstore/flatstore.c b/modules/db_flatstore/flatstore.c
index 8b7bfc2..a69c321 100644
--- a/modules/db_flatstore/flatstore.c
+++ b/modules/db_flatstore/flatstore.c
@@ -1,5 +1,5 @@
-/*
- * $Id$
+/*
+ * $Id$
*
* Flatstore module interface
*
@@ -22,8 +22,8 @@
* 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
+ * 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
*/
/*
@@ -52,7 +52,7 @@ static int parse_flat_url(const char* url, const char** path)
}
len = strlen(url);
-
+
*path = strchr(url, ':') + 1;
return 0;
}
@@ -121,7 +121,7 @@ int flat_use_table(db_con_t* h, const char* t)
return -1;
}
}
-
+
return 0;
}
@@ -155,6 +155,8 @@ int flat_db_insert(db_con_t* h, db_key_t* k, db_val_t* v, int n)
{
FILE* f;
int i;
+ char delims[4], *s;
+ size_t len;
f = CON_FILE(h);
if (!f) {
@@ -168,42 +170,72 @@ int flat_db_insert(db_con_t* h, db_key_t* k, db_val_t* v, int n)
}
for(i = 0; i < n; i++) {
- switch(VAL_TYPE(v + i)) {
- case DB_INT:
- fprintf(f, "%d", VAL_INT(v + i));
- break;
-
- case DB_DOUBLE:
- fprintf(f, "%f", VAL_DOUBLE(v + i));
- break;
-
- case DB_STRING:
- fprintf(f, "%s", VAL_STRING(v + i));
- break;
-
- case DB_STR:
- fprintf(f, "%.*s", VAL_STR(v + i).len, VAL_STR(v + i).s);
- break;
-
- case DB_DATETIME:
- fprintf(f, "%u", (unsigned int)VAL_TIME(v + i));
- break;
-
- case DB_BLOB:
- LOG(L_ERR, "flastore: Blobs not supported\n");
- break;
-
- case DB_BITMAP:
- fprintf(f, "%u", VAL_BITMAP(v + i));
- break;
- }
+ if (!VAL_NULL(v + i)) { // TODO: how to distinguish NULL from empty
+ switch(VAL_TYPE(v + i)) {
+ case DB_INT:
+ fprintf(f, "%d", VAL_INT(v + i));
+ break;
+
+ case DB_DOUBLE:
+ fprintf(f, "%f", VAL_DOUBLE(v + i));
+ break;
+
+ case DB_STRING: {
+ s = (char*) VAL_STRING(v + i);
+ delims[0] = flat_delimiter[0];
+ delims[1] = flat_record_delimiter[0];
+ delims[2] = flat_escape[0];
+ delims[3] = '\0';
+ while (*s) {
+ len = strcspn(s, delims);
+ fprintf(f, "%.*s", len, s);
+ s+= len;
+ if (*s) {
+ fprintf(f, "%c%c", flat_escape[0], *s);
+ s++;
+ }
+ }
+ break;
+ }
+ case DB_STR:
+ case DB_BLOB:
+ if (VAL_TYPE(v + i) == DB_STR) {
+ s = VAL_STR(v + i).s;
+ len = VAL_STR(v + i).len;
+ }
+ else {
+ s = VAL_BLOB(v + i).s;
+ len = VAL_BLOB(v + i).len;
+ }
+ while (len > 0) {
+ char *c;
+ for (c = s; len > 0 && *c != flat_delimiter[0] && *c != flat_record_delimiter[0] && *c != flat_escape[0]; c++, len--);
+ fprintf(f, "%.*s", c-s, s);
+ s = c;
+ if (len > 0) {
+ fprintf(f, "%c%c", flat_escape[0], *s);
+ s++;
+ len--;
+ }
+ }
+ break;
+
+ case DB_DATETIME:
+ fprintf(f, "%u", (unsigned int)VAL_TIME(v + i));
+ break;
+
+ case DB_BITMAP:
+ fprintf(f, "%u", VAL_BITMAP(v + i));
+ break;
+ }
+ }
if (i < (n - 1)) {
- fprintf(f, "%c", *flat_delimiter);
+ fprintf(f, "%c", flat_delimiter[0]);
}
}
- fprintf(f, "\n");
+ fprintf(f, "%c", flat_record_delimiter[0]);
if (flat_flush) {
fflush(f);
diff --git a/modules/db_flatstore/flatstore_mod.c b/modules/db_flatstore/flatstore_mod.c
index 4a2ca2b..54b280a 100644
--- a/modules/db_flatstore/flatstore_mod.c
+++ b/modules/db_flatstore/flatstore_mod.c
@@ -1,5 +1,5 @@
-/*
- * $Id$
+/*
+ * $Id$
*
* Flatstore module interface
*
@@ -22,8 +22,8 @@
* 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
+ * 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
*/
/*
@@ -58,18 +58,26 @@ int flat_pid;
*/
int flat_flush = 1;
+/*
+ * Delimiter delimiting rows
+ */
+char *flat_record_delimiter = "\n";
/*
* Delimiter delimiting columns
*/
-char* flat_delimiter = "|";
+char *flat_delimiter = "|";
+/*
+ * Escape char escaping delimiters
+ */
+char *flat_escape = "\\";
/*
* Timestamp of the last log rotation request from
* the FIFO interface
*/
-time_t* flat_rotate;
+time_t* flat_rotate;
time_t local_timestamp;
@@ -90,11 +98,14 @@ static cmd_export_t cmds[] = {
*/
static param_export_t params[] = {
{"flush", INT_PARAM, &flat_flush},
+ {"field_delimiter", STR_PARAM, &flat_delimiter},
+ {"record_delimiter", STR_PARAM, &flat_record_delimiter},
+ {"escape_char", STR_PARAM, &flat_escape},
{0, 0, 0}
};
-struct module_exports exports = {
+struct module_exports exports = {
"flatstore",
cmds,
flat_rpc, /* RPC methods */
@@ -109,8 +120,18 @@ struct module_exports exports = {
static int mod_init(void)
{
- if (strlen(flat_delimiter) != 1) {
- LOG(L_ERR, "flatstore:mod_init: Delimiter has to be exactly one character\n");
+ if (strlen(flat_delimiter) > 1) {
+ LOG(L_ERR, "flatstore:mod_init: Column delimiter has to be max. one character\n");
+ return -1;
+ }
+
+ if (strlen(flat_record_delimiter) > 1) {
+ LOG(L_ERR, "flatstore:mod_init: Record delimiter has to be max. one character\n");
+ return -1;
+ }
+
+ if (strlen(flat_escape) > 0) {
+ LOG(L_ERR, "flatstore:mod_init: Escape char has to be max. one character\n");
return -1;
}
diff --git a/modules/db_flatstore/flatstore_mod.h b/modules/db_flatstore/flatstore_mod.h
index 83bc593..3632ecb 100644
--- a/modules/db_flatstore/flatstore_mod.h
+++ b/modules/db_flatstore/flatstore_mod.h
@@ -1,5 +1,5 @@
-/*
- * $Id$
+/*
+ * $Id$
*
* Flatstore module interface
*
@@ -22,8 +22,8 @@
* 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
+ * 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
*/
/*
@@ -43,18 +43,25 @@
*/
extern int flat_pid;
-
/*
* Should we flush after each write to the database ?
*/
extern int flat_flush;
+/*
+ * Delimiter delimiting rows
+ */
+extern char *flat_record_delimiter;
/*
- * Delmiter delimiting columns
+ * Delimiter delimiting columns
*/
-extern char* flat_delimiter;
+extern char *flat_delimiter;
+/*
+ * Escape char escaning delimiters and itself
+ */
+extern char *flat_escape;
/*
* The timestamp of log rotation request from
Module: sip-router
Branch: janakj/flatstore
Commit: 5e3087888e64fc705a64b10aff378fc580a31cf7
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5e30878…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sat Jul 23 23:21:36 2005 +0000
- improved documentation system
- documentation makefiles
- proper documentation dependency tracking in makefiles
- XML-based dialect of docbook used with xi:include inclusions
---
modules/db_flatstore/doc/Makefile | 29 +++++++
modules/db_flatstore/doc/flatstore.xml | 134 ++++++++++++++++++++++++++++++++
modules/db_flatstore/doc/functions.xml | 17 ++++
modules/db_flatstore/doc/params.xml | 26 ++++++
4 files changed, 206 insertions(+), 0 deletions(-)
diff --git a/modules/db_flatstore/doc/Makefile b/modules/db_flatstore/doc/Makefile
new file mode 100644
index 0000000..28b668f
--- /dev/null
+++ b/modules/db_flatstore/doc/Makefile
@@ -0,0 +1,29 @@
+#
+# The list of documents to build (without extensions)
+#
+DOCUMENTS = flatstore
+
+#
+# The root directory containing Makefile.doc
+#
+ROOT_DIR=../../..
+
+#
+# Validate docbook documents before generating output
+# (may be slow)
+#
+#VALIDATE=1
+
+#
+# You can override the stylesheet used to generate
+# xhtml documents here
+#
+#XHTML_XSL=$(ROOT_DIR)/doc/stylesheets/xhtml.xsl
+
+#
+# You can override the stylesheet used to generate
+# plain text documents here
+#
+#TXT_XSL=$(XHTML_XSL)
+
+include $(ROOT_DIR)/Makefile.doc
diff --git a/modules/db_flatstore/doc/flatstore.xml b/modules/db_flatstore/doc/flatstore.xml
new file mode 100644
index 0000000..263f28a
--- /dev/null
+++ b/modules/db_flatstore/doc/flatstore.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4//EN"
+ "file:///usr/share/sgml/docbook/dtd/xml/4/docbookx.dtd">
+
+<section id="flatstore" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <sectioninfo>
+ <authorgroup>
+ <author>
+ <firstname>Jan</firstname>
+ <surname>Janak</surname>
+ <affiliation><orgname>FhG FOKUS</orgname></affiliation>
+ <email>jan(a)iptel.org</email>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2004</year>
+ <year>2005</year>
+ <holder>FhG FOKUS</holder>
+ </copyright>
+ <revhistory>
+ <revision>
+ <revnumber>$Revision$</revnumber>
+ <date>$Date$</date>
+ </revision>
+ </revhistory>
+ </sectioninfo>
+
+ <title>Flatstore Module</title>
+
+ <section id="overview">
+ <title>Overview</title>
+ <para>
+ Flatstore is one of so-called SER database modules. It does not
+ export any functions executable from the configuration scripts, but
+ it exports a subset of functions from the database API and thus
+ other module can use it instead of, for example, mysql module.
+ </para>
+ <para>
+ The module does not export all functions of the database API, it
+ supports only one function, insert. The module is limited but very
+ fast. It is especially suitable for storing accounting information
+ on sites with extremely high traffic. If MySQL is too slow or if
+ you get a huge amount of accounting data then you can consider
+ using this module. Note that the acc module is the only module that
+ was tested with flastore.
+ </para>
+ <para>
+ The format of the files produced by this module is plain text. Each
+ line consists of several fields, fields are separated by |
+ character. New information is always appended at the end of the
+ file, searching, deleting and updating of existing data is not
+ supported by the module.
+ </para>
+ <para>
+ The acc module can be configured to use flatstore module as
+ database backend using the db_url_parameter:
+ </para>
+ <programlisting>
+modparam("acc", "db_url", "flatstore:/var/log/acc")
+ </programlisting>
+ <para>
+ This configuration options tells acc module that it should use the
+ flatstore module and the flatstore module should create all files
+ in /var/log/acc directory. The directory must exist and SER
+ processes must have permissions to create files in that directory.
+ </para>
+ <para>
+ Name of files in that directory will follow the following pattern:
+ </para>
+ <programlisting>
+<table_name>_<process_name>.log
+ </programlisting>
+ <para>
+ For example, entries writen by SER process 8 into acc table would
+ be written in file acc_8.log. For each table there will be several
+ files, one file for every SER process that wrote some data into
+ that table. The main reason why there are several files for each
+ table is that it is much faster to have one file per process,
+ because it does not require any locking and thus SER processes will
+ not block each other. To get the complete data for a table you can
+ simply concatenate the contents of files with the same table name
+ but different process id.
+ </para>
+ <section id="rotating">
+ <title>Rotating Log Files</title>
+ <para>
+ There is a new SER FIFO interface command called flat_rotate.
+ When SER receives the command then it will close and reopen all
+ files used by flatstore module. The rotation itself has to be
+ done by another application (such as logrotate). Follow these
+ steps to rotate files generated by flatstore module:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Rename the files that you want to rotate:
+ <screen>
+cd /var/log/acc
+mv acc_1.log acc_1.log.20050605
+mv acc_2.log acc_2.log.20050605
+mv acc_4.log acc_3.log.20050605
+...
+ </screen>
+ Note that at this point SER will still be writing all
+ data into the renamed files.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Send SER the fifo command to close and reopen the
+ renamed files:
+ <screen>
+serctl fifo flat_rotate
+ </screen>
+ This will force SER to close the renamed files and open
+ new ones with original names, such as
+ <filename>acc_1.log</filename>. New files will be open
+ at the point when SER has some data to write. It is
+ normal that the files will be not created immediately
+ if there is no traffic on the proxy server.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Move the renamed files somewhere else and process them.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+ </section>
+
+ <xi:include href="params.xml"/>
+
+</section>
diff --git a/modules/db_flatstore/doc/functions.xml b/modules/db_flatstore/doc/functions.xml
new file mode 100644
index 0000000..29dea48
--- /dev/null
+++ b/modules/db_flatstore/doc/functions.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4//EN"
+ "file:///usr/share/sgml/docbook/dtd/xml/4/docbookx.dtd">
+
+<section id="flatstore.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <sectioninfo>
+ <revhistory>
+ <revision>
+ <revnumber>$Revision$</revnumber>
+ <date>$Date$</date>
+ </revision>
+ </revhistory>
+ </sectioninfo>
+
+ <title>Functions</title>
+
+</section>
diff --git a/modules/db_flatstore/doc/params.xml b/modules/db_flatstore/doc/params.xml
new file mode 100644
index 0000000..a6d838e
--- /dev/null
+++ b/modules/db_flatstore/doc/params.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4//EN"
+ "file:///usr/share/sgml/docbook/dtd/xml/4/docbookx.dtd">
+
+<section id="flatstore.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <sectioninfo>
+ <revhistory>
+ <revision>
+ <revnumber>$Revision$</revnumber>
+ <date>$Date$</date>
+ </revision>
+ </revhistory>
+ </sectioninfo>
+
+ <title>Parameters</title>
+
+ <section id="flush">
+ <title><varname>flush</varname> (integer)</title>
+ <para>
+ Enable or disable flushing after each write.
+ </para>
+ <para>
+ Default value is 1.
+ </para>
+ </section>
+</section>
Module: sip-router
Branch: janakj/postgres
Commit: dc24f971ded42f7315f389251120a6e39e364616
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dc24f97…
Author: Maxim Sobolev <sobomax(a)sippysoft.com>
Committer: Maxim Sobolev <sobomax(a)sippysoft.com>
Date: Wed May 21 04:16:30 2008 +0000
Put back functionality lost during DB API 2.0 conversion. Allo '/' to be
part of the "hostname" portion of the "URI". PostgreSQL allows using this
to specify location of the unix domain socket for communication with the
server. Example of such URL would be:
postgres://someuser@/var/run/sippy
Here the sippy is the database name, while /var/run is the location of the
socket. This change should be backward compatible since '/' is not
allowed in the database name.
---
modules/db_postgres/pg_uri.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/modules/db_postgres/pg_uri.c b/modules/db_postgres/pg_uri.c
index 3f876d1..02fa494 100644
--- a/modules/db_postgres/pg_uri.c
+++ b/modules/db_postgres/pg_uri.c
@@ -169,6 +169,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
break;
case '/':
+ if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+ break;
if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0)
goto err;
@@ -186,6 +188,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
break;
case '/':
+ if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+ break;
res->host = prev_token;
res->port = str2s(begin, uri->s + i - begin, 0);
if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0)
@@ -203,6 +207,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
break;
case '/':
+ if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+ break;
if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0)
goto err;