Module: sip-router
Branch: janakj/flatstore
Commit: c4bddb54e21e2a78adf2910951e03ab359f71aa0
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c4bddb5…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Jun 23 17:29:11 2008 +0000
- missing READMEs added
---
modules/db_flatstore/README | 95 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 95 insertions(+), 0 deletions(-)
diff --git a/modules/db_flatstore/README b/modules/db_flatstore/README
new file mode 100644
index 0000000..715c2c3
--- /dev/null
+++ b/modules/db_flatstore/README
@@ -0,0 +1,95 @@
+1. Flatstore Module
+
+Jan Janak
+
+ FhG FOKUS
+ <jan(a)iptel.org>
+
+ Copyright � 2004, 2005 FhG FOKUS
+ Revision History
+ Revision $Revision$ $Date$
+ __________________________________________________________________
+
+ 1.1. Overview
+
+ 1.1.1. Rotating Log Files
+
+ 1.2. Parameters
+
+ 1.2.1. flush (integer)
+
+1.1. Overview
+
+ 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.
+
+ 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.
+
+ 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.
+
+ The acc module can be configured to use flatstore module as database
+ backend using the db_url_parameter:
+modparam("acc", "db_url", "flatstore:/var/log/acc")
+
+ 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.
+
+ Name of files in that directory will follow the following pattern:
+<table_name>_<process_name>.log
+
+ 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.
+
+1.1.1. Rotating Log Files
+
+ 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:
+ * Rename the files that you want to rotate:
+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
+...
+ Note that at this point SER will still be writing all data into the
+ renamed files.
+ * Send SER the fifo command to close and reopen the renamed files:
+serctl fifo flat_rotate
+ This will force SER to close the renamed files and open new ones
+ with original names, such as acc_1.log. 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.
+ * Move the renamed files somewhere else and process them.
+
+1.2. Parameters
+
+ Revision History
+ Revision $Revision$ $Date$
+
+1.2.1. flush (integer)
+
+ Enable or disable flushing after each write.
+
+ Default value is 1.
Module: sip-router
Branch: janakj/flatstore
Commit: 6fe11123ef7ae7f95a62bc0ef20969ba03483d3d
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6fe1112…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Jun 1 10:00:59 2008 +0000
- support for flatstore uris with relative pathnames (they are
converted to absolute with respect to the main ser config file)
- todo list added
---
modules/db_flatstore/flat_con.c | 5 ++-
modules/db_flatstore/flat_uri.c | 80 ++++++++++++++++++++++++++++++++++
modules/db_flatstore/flat_uri.h | 62 ++++++++++++++++++++++++++
modules/db_flatstore/flatstore_mod.c | 8 ++-
modules/db_flatstore/todo.txt | 2 +
5 files changed, 153 insertions(+), 4 deletions(-)
diff --git a/modules/db_flatstore/flat_con.c b/modules/db_flatstore/flat_con.c
index 3697cfd..0b20131 100644
--- a/modules/db_flatstore/flat_con.c
+++ b/modules/db_flatstore/flat_con.c
@@ -32,6 +32,7 @@
#include "flat_con.h"
#include "flatstore_mod.h"
+#include "flat_uri.h"
#include "../../mem/mem.h"
#include "../../dprint.h"
@@ -229,6 +230,7 @@ static char* get_filename(str* dir, str* name)
int flat_open_table(int* idx, db_con_t* con, str* name)
{
+ struct flat_uri* furi;
struct flat_con* fcon;
struct flat_file* new;
int i;
@@ -238,6 +240,7 @@ int flat_open_table(int* idx, db_con_t* con, str* name)
filename = NULL;
table = NULL;
fcon = DB_GET_PAYLOAD(con);
+ furi = DB_GET_PAYLOAD(con->uri);
for(i = 0; i < fcon->n; i++) {
if (name->len == fcon->file[i].table.len &&
@@ -249,7 +252,7 @@ int flat_open_table(int* idx, db_con_t* con, str* name)
* fcon->file, so that we can fail gracefully if one of the
* operations fail.
*/
- if ((filename = get_filename(&con->uri->body, name)) == NULL)
+ if ((filename = get_filename(&furi->path, name)) == NULL)
goto no_mem;
if ((table = pkg_malloc(name->len)) == NULL) goto no_mem;
diff --git a/modules/db_flatstore/flat_uri.c b/modules/db_flatstore/flat_uri.c
new file mode 100644
index 0000000..05005f3
--- /dev/null
+++ b/modules/db_flatstore/flat_uri.c
@@ -0,0 +1,80 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ * Written by Jan Janak <jan(a)iptel.org>
+ *
+ * This file is part of SER, a free SIP server.
+ *
+ * SER 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.
+ *
+ * SER 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
+ */
+
+/** \addtogroup flatstore
+ * @{
+ */
+
+/** \file
+ * The implementation of parser parsing flatstore:.. URIs.
+ */
+
+#include "flat_uri.h"
+
+#include "../../mem/mem.h"
+#include "../../ut.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+
+static void flat_uri_free(db_uri_t* uri, struct flat_uri* payload)
+{
+ if (payload == NULL) return;
+ if (payload->path.s) free(payload->path.s);
+ db_drv_free(&payload->drv);
+ pkg_free(payload);
+}
+
+
+int flat_uri(db_uri_t* uri)
+{
+ struct flat_uri* furi;
+
+ if ((furi = (struct flat_uri*)pkg_malloc(sizeof(*furi))) == NULL) {
+ ERR("flatstore: No memory left\n");
+ return -1;
+ }
+ memset(furi, '\0', sizeof(*furi));
+ if (db_drv_init(&furi->drv, flat_uri_free) < 0) goto error;
+
+ if ((furi->path.s = get_abs_pathname(NULL, &uri->body)) == NULL) {
+ ERR("flatstore: Error while obtaining absolute pathname for '%.*s'\n",
+ STR_FMT(&uri->body));
+ goto error;
+ }
+ furi->path.len = strlen(furi->path.s);
+
+ DB_SET_PAYLOAD(uri, furi);
+ return 0;
+
+ error:
+ if (furi) {
+ if (furi->path.s) free(furi->path.s);
+ db_drv_free(&furi->drv);
+ pkg_free(furi);
+ }
+ return -1;
+}
+
+/** @} */
diff --git a/modules/db_flatstore/flat_uri.h b/modules/db_flatstore/flat_uri.h
new file mode 100644
index 0000000..2cb251a
--- /dev/null
+++ b/modules/db_flatstore/flat_uri.h
@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ * Written by Jan Janak <jan(a)iptel.org>
+ *
+ * This file is part of SER, a free SIP server.
+ *
+ * SER 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.
+ *
+ * SER 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
+ */
+
+#ifndef _FLAT_URI_H
+#define _FLAT_URI_H
+
+/** \addtogroup flatstore
+ * @{
+ */
+
+/** \file
+ * The functions parsing and interpreting flatstore: URIs.
+ */
+
+#include "../../db/db_uri.h"
+#include "../../db/db_drv.h"
+
+/** Flatstore driver specific payload to attach to db_uri structures.
+ * This is the flatstore specific structure that will be attached to generic
+ * db_uri structures in the database API in SER. The structure is used to
+ * convert relative pathnames in flatstore URIs to absolute.
+ */
+struct flat_uri {
+ db_drv_t drv;
+ /** Absolute pathname to the database directory, zero terminated */
+ str path;
+};
+
+
+/** Create a new flat_uri structure and convert the path in parameter.
+ * This function builds a new flat_uri structure from the body of
+ * the generic URI given to it in parameter.
+ * @param uri A generic db_uri structure.
+ * @retval 0 on success
+ * @retval A negative number on error.
+ */
+int flat_uri(db_uri_t* uri);
+
+
+/** @} */
+
+#endif /* _FLAT_URI_H */
diff --git a/modules/db_flatstore/flatstore_mod.c b/modules/db_flatstore/flatstore_mod.c
index 8a27740..a64dc73 100644
--- a/modules/db_flatstore/flatstore_mod.c
+++ b/modules/db_flatstore/flatstore_mod.c
@@ -34,6 +34,7 @@
#include "flat_con.h"
#include "flat_cmd.h"
#include "flat_rpc.h"
+#include "flat_uri.h"
#include "../../sr_module.h"
#include "../../mem/shm_mem.h"
@@ -105,9 +106,10 @@ time_t flat_local_timestamp;
/* Flatstore database module interface */
static cmd_export_t cmds[] = {
- {"db_con", (cmd_function)flat_con, 0, 0, 0},
- {"db_cmd", (cmd_function)flat_cmd, 0, 0, 0},
- {"db_put", (cmd_function)flat_put, 0, 0, 0},
+ {"db_uri", (cmd_function)flat_uri, 0, 0, 0},
+ {"db_con", (cmd_function)flat_con, 0, 0, 0},
+ {"db_cmd", (cmd_function)flat_cmd, 0, 0, 0},
+ {"db_put", (cmd_function)flat_put, 0, 0, 0},
{0, 0, 0, 0, 0}
};
diff --git a/modules/db_flatstore/todo.txt b/modules/db_flatstore/todo.txt
new file mode 100644
index 0000000..aff00cc
--- /dev/null
+++ b/modules/db_flatstore/todo.txt
@@ -0,0 +1,2 @@
+* Create the directory if it does not exist and check permissions
+