瀏覽代碼

Very simple module that implement very fast inserts. Each process opens
its own file (no locking, distinguished by the number of the ser child),
only inserts are supported, the data is stored in plaintext files.
The main purpose of the module is to implement very fast accounting without
relying on a backend database.

Jan Janak 21 年之前
當前提交
ecbabeb09b

+ 9 - 0
modules/db_flatstore/Makefile

@@ -0,0 +1,9 @@
+# $Id$
+#
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=flatstore.so
+
+include ../../Makefile.modules

+ 107 - 0
modules/db_flatstore/flat_con.c

@@ -0,0 +1,107 @@
+/* 
+ * $Id$
+ *
+ * Flastore module connection structure
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+
+#include <string.h>
+#include <linux/limits.h>
+#include <errno.h>
+#include "../../mem/mem.h"
+#include "../../dprint.h"
+#include "../../ut.h"
+#include "flatstore_mod.h"
+#include "flat_con.h"
+
+#define FILE_SUFFIX ".log"
+#define FILE_SUFFIX_LEN (sizeof(FILE_SUFFIX) - 1)
+
+struct flat_con* flat_new_connection(struct flat_id* id)
+{
+	char buf[PATH_MAX];
+	char* num, *ptr;
+	int num_len;
+
+	struct flat_con* res;
+
+	if (!id) {
+		LOG(L_ERR, "flat_new_connection: Invalid parameter value\n");
+		return 0;
+	}
+
+	res = (struct flat_con*)pkg_malloc(sizeof(struct flat_con));
+	if (!res) {
+		LOG(L_ERR, "flat_new_connection: No memory left\n");
+		return 0;
+	}
+
+	memset(res, 0, sizeof(struct flat_con));
+	res->ref = 1;
+	
+	res->id = id;
+	ptr = buf;
+
+	memcpy(ptr, id->dir.s, id->dir.len);
+	ptr += id->dir.len;
+	*ptr++ = '/';
+
+	memcpy(ptr, id->table.s, id->table.len);
+	ptr += id->table.len;
+
+	*ptr++ = '_';
+	
+	num = int2str(flat_pid, &num_len);
+	memcpy(ptr, num, num_len);
+	ptr += num_len;
+
+	memcpy(ptr, FILE_SUFFIX, FILE_SUFFIX_LEN);
+	ptr += FILE_SUFFIX_LEN;
+
+	*ptr = '\0';
+
+	res->file = fopen(buf, "w");
+	if (!res->file) {
+		LOG(L_ERR, "flat_new_connection: %s\n", strerror(errno));
+		pkg_free(res);
+		return 0;
+	}
+	
+	return res;
+}
+
+
+/*
+ * Close the connection and release memory
+ */
+void flat_free_connection(struct flat_con* con)
+{
+	if (!con) return;
+	if (con->id) free_flat_id(con->id);
+	if (con->file) {
+		fclose(con->file);
+	}
+	pkg_free(con);
+}

+ 64 - 0
modules/db_flatstore/flat_con.h

@@ -0,0 +1,64 @@
+/* 
+ * $Id$
+ *
+ * Flatstore module connection structure
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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_CON_H
+#define _FLAT_CON_H
+
+#include <stdio.h>
+#include <time.h>
+#include "flat_id.h"
+
+struct flat_con {
+	struct flat_id* id;    /* Connection identifier */
+	int ref;               /* Reference count */
+	FILE* file;            /* File descriptor structure */
+	struct flat_con* next; /* Next connection in the pool */
+};
+
+
+/*
+ * Some convenience wrappers
+ */
+#define CON_FILE(db_con) (((struct flat_con*)((db_con)->tail))->file)
+
+
+/*
+ * Create a new connection structure,
+ * open the MySQL connection and set reference count to 1
+ */
+struct flat_con* flat_new_connection(struct flat_id* id);
+
+
+/*
+ * Close the connection and release memory
+ */
+void flat_free_connection(struct flat_con* con);
+
+
+#endif /* _FLAT_CON_H */

+ 87 - 0
modules/db_flatstore/flat_id.c

@@ -0,0 +1,87 @@
+/* 
+ * $Id$
+ *
+ * Flatstore module connection identifier
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+
+#include <string.h>
+#include "../../dprint.h"
+#include "../../mem/mem.h"
+#include "flat_id.h"
+
+
+
+/*
+ * Create a new connection identifier
+ */
+struct flat_id* new_flat_id(char* dir, char* table)
+{
+	struct flat_id* ptr;
+
+	if (!dir || !table) {
+		LOG(L_ERR, "new_flat_id: Invalid parameter(s)\n");
+		return 0;
+	}
+
+	ptr = (struct flat_id*)pkg_malloc(sizeof(struct flat_id));
+	if (!ptr) {
+		LOG(L_ERR, "new_flat_id: No memory left\n");
+		return 0;
+	}
+	memset(ptr, 0, sizeof(struct flat_id));
+
+	ptr->dir.s = dir;
+	ptr->dir.len = strlen(dir);
+	ptr->table.s = table;
+	ptr->table.len = strlen(table);
+
+	return ptr;
+}
+
+
+/*
+ * Compare two connection identifiers
+ */
+unsigned char cmp_flat_id(struct flat_id* id1, struct flat_id* id2)
+{
+	if (!id1 || !id2) return 0;
+	if (id1->dir.len != id2->dir.len) return 0;
+	if (id1->table.len != id2->table.len) return 0;
+
+	if (memcmp(id1->dir.s, id2->dir.s, id1->dir.len)) return 0;
+	if (memcmp(id1->table.s, id2->table.s, id1->table.len)) return 0;
+	return 1;
+}
+
+
+/*
+ * Free a connection identifier
+ */
+void free_flat_id(struct flat_id* id)
+{
+	if (!id) return;
+	pkg_free(id);
+}

+ 60 - 0
modules/db_flatstore/flat_id.h

@@ -0,0 +1,60 @@
+/* 
+ * $Id$
+ *
+ * Flatstore connection identifier
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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_ID_H
+#define _FLAT_ID_H
+
+#include "../../str.h"
+
+
+struct flat_id {
+	str dir;   /* Database directory */ 
+	str table; /* Name of table */
+};
+
+
+/*
+ * Create a new connection identifier
+ */
+struct flat_id* new_flat_id(char* dir, char* table);
+
+
+/*
+ * Compare two connection identifiers
+ */
+unsigned char cmp_flat_id(struct flat_id* id1, struct flat_id* id2);
+
+
+/*
+ * Free a connection identifier
+ */
+void free_flat_id(struct flat_id* id);
+
+
+#endif /* _FLAT_ID_H */

+ 136 - 0
modules/db_flatstore/flat_pool.c

@@ -0,0 +1,136 @@
+/* 
+ * $Id$
+ *
+ * Flatstore module connection pool
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+
+#include <unistd.h>
+#include "../../dprint.h"
+#include "flat_pool.h"
+#include "flat_id.h"
+
+
+/* The head of the pool */
+static struct flat_con* pool = 0;
+
+/*
+ * Pid of the process that added the last
+ * connection to the pool. This is used to
+ * check for inherited database connections.
+ */
+static int pool_pid;
+
+
+/*
+ * Get a connection from the pool, reuse existing
+ * if possible, otherwise create a new one
+ */
+struct flat_con* flat_get_connection(char* dir, char* table)
+{
+	struct flat_id* id;
+	struct flat_con* ptr;
+	int pid;
+
+	if (!dir || !table) {
+		LOG(L_ERR, "flat_get_connection: Invalid parameter value\n");
+		return 0;
+	}
+
+	pid = getpid();
+	if (pool && (pool_pid != pid)) {
+		LOG(L_ERR, "flat_get_connection: Inherited open database connections, this is not a good idea\n");
+		return 0;
+	}
+
+	pool_pid = pid;
+
+	id = new_flat_id(dir, table);
+	if (!id) return 0;
+
+	ptr = pool;
+	while (ptr) {
+		if (cmp_flat_id(id, ptr->id)) {
+			DBG("flat_get_connection: Connection found in the pool\n");
+			ptr->ref++;
+			free_flat_id(id);
+			return ptr;
+		}
+		ptr = ptr->next;
+	}
+
+	DBG("flat_get_connection: Connection not found in the pool\n");
+	ptr = flat_new_connection(id);
+	if (!ptr) {
+		free_flat_id(id);
+		return 0;
+	}
+
+	ptr->next = pool;
+	pool = ptr;
+	return ptr;
+}
+
+
+/*
+ * Release a connection, the connection will be left
+ * in the pool if ref count != 0, otherwise it
+ * will be delete completely
+ */
+void flat_release_connection(struct flat_con* con)
+{
+	struct flat_con* ptr;
+
+	if (!con) return;
+
+	if (con->ref > 1) {
+		     /* There are still other users, just
+		      * decrease the reference count and return
+		      */
+		DBG("flat_release_connection: Connection still kept in the pool\n");
+		con->ref--;
+		return;
+	}
+
+	DBG("flat_release_connection: Removing connection from the pool\n");
+
+	if (pool == con) {
+		pool = pool->next;
+	} else {
+		ptr = pool;
+		while(ptr) {
+			if (ptr->next == con) break;
+			ptr = ptr->next;
+		}
+		if (!ptr) {
+			LOG(L_ERR, "flat_release_connection: Weird, connection not found in the pool\n");
+		} else {
+			     /* Remove the connection from the pool */
+			ptr->next = con->next;
+		}
+	}
+
+	flat_free_connection(con);
+}

+ 50 - 0
modules/db_flatstore/flat_pool.h

@@ -0,0 +1,50 @@
+/* 
+ * $Id$
+ *
+ * Flatstore module connection pool
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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_POOL_H
+#define _FLAT_POOL_H
+
+#include "flat_con.h"
+
+/*
+ * Get a connection from the pool, reuse existing
+ * if possible, otherwise create a new one
+ */
+struct flat_con* flat_get_connection(char* dir, char* table);
+
+
+/*
+ * Release a connection, the connection will be left
+ * in the pool if ref count != 0, otherwise it
+ * will be delete completely
+ */
+void flat_release_connection(struct flat_con* con);
+
+
+#endif /* _FLAT_POOL_H */

+ 208 - 0
modules/db_flatstore/flatstore.c

@@ -0,0 +1,208 @@
+/* 
+ * $Id$ 
+ *
+ * Flatstore module interface
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-11  updated to the new module exports interface (andrei)
+ *  2003-03-16  flags export parameter added (janakj)
+ */
+
+#include <string.h>
+#include "../../mem/mem.h"
+#include "../../dprint.h"
+#include "flat_pool.h"
+#include "flat_con.h"
+#include "flatstore_mod.h"
+#include "flatstore.h"
+
+
+static int parse_flat_url(const char* url, const char** path)
+{
+	int len;
+
+	if (!url || !path) {
+		LOG(L_ERR, "parse_flat_url: Invalid parameter value\n");
+		return -1;
+	}
+
+	len = strlen(url);
+	
+	*path = strchr(url, ':') + 1;
+	return 0;
+}
+
+
+
+/*
+ * Initialize database module
+ * No function should be called before this
+ */
+db_con_t* flat_db_init(const char* url)
+{
+	db_con_t* res;
+
+	if (!url) {
+		LOG(L_ERR, "flat_db_init: Invalid parameter value\n");
+		return 0;
+	}
+
+	     /* We do not know the name of the table (and the name of the corresponding file)
+	      * at this point, we will simply store the path taken from url parameter in the
+	      * table variable, flat_use_table will then pick that value and open file
+	      */
+	res = pkg_malloc(sizeof(db_con_t) + sizeof(struct flat_con*));
+	if (!res) {
+		LOG(L_ERR, "flat_db_init: No memory left\n");
+		return 0;
+	}
+	memset(res, 0, sizeof(db_con_t) + sizeof(struct flat_con*));
+
+	if (parse_flat_url(url, &res->table) < 0) {
+		pkg_free(res);
+		return 0;
+	}
+
+	return res;
+}
+
+
+/*
+ * Store name of table that will be used by
+ * subsequent database functions
+ */
+int flat_use_table(db_con_t* h, const char* t)
+{
+	struct flat_con* con;
+
+	if (!h || !t) {
+		LOG(L_ERR, "flat_use_table: Invalid parameter value\n");
+		return -1;
+	}
+
+	if (CON_TABLE(h) != t) {
+		if (CON_TAIL(h)) {
+			     /* Decrement the reference count
+			      * of the connection but do not remove
+			      * it from the connection pool
+			      */
+			con = (struct flat_con*)CON_TAIL(h);
+			con->ref--;
+
+		}
+
+		CON_TAIL(h) = (unsigned long)flat_get_connection((char*)CON_TABLE(h), (char*)t);
+		if (!CON_TAIL(h)) {
+			return -1;
+		}
+	}
+	
+	return 0;
+}
+
+
+void flat_db_close(db_con_t* h)
+{
+	struct flat_con* con;
+
+	if (!h) {
+		LOG(L_ERR, "db_close: Invalid parameter value\n");
+		return;
+	}
+
+	con = (struct flat_con*)CON_TAIL(h);
+
+	if (con) {
+		flat_release_connection(con);
+	}
+	pkg_free(h);
+}
+
+
+/*
+ * Insert a row into specified table
+ * h: structure representing database connection
+ * k: key names
+ * v: values of the keys
+ * n: number of key=value pairs
+ */
+int flat_db_insert(db_con_t* h, db_key_t* k, db_val_t* v, int n)
+{
+	FILE* f;
+	int i;
+
+	f = CON_FILE(h);
+	if (!f) {
+		LOG(L_CRIT, "BUG: flat_db_insert: Uninitialized connection\n");
+		return -1;
+	}
+
+	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 (i < (n - 1)) {
+			fprintf(f, "%c", *flat_delimiter);
+		}
+	}
+
+	fprintf(f, "\n");
+
+	if (flat_flush) {
+		fflush(f);
+	}
+
+	return 0;
+}

+ 71 - 0
modules/db_flatstore/flatstore.h

@@ -0,0 +1,71 @@
+/* 
+ * $Id$ 
+ *
+ * Flatstore module interface
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-11  updated to the new module exports interface (andrei)
+ *  2003-03-16  flags export parameter added (janakj)
+ */
+
+#ifndef _FLATSTORE_H
+#define _FLATSTORE_H
+
+#include "../../db/db_val.h"
+#include "../../db/db_key.h"
+#include "../../db/db_con.h"
+
+
+/*
+ * Initialize database module
+ * No function should be called before this
+ */
+db_con_t* flat_db_init(const char* _url);
+
+
+/*
+ * Store name of table that will be used by
+ * subsequent database functions
+ */
+int flat_use_table(db_con_t* h, const char* t);
+
+
+void flat_db_close(db_con_t* h);
+
+
+/*
+ * Insert a row into specified table
+ * h: structure representing database connection
+ * k: key names
+ * v: values of the keys
+ * n: number of key=value pairs
+ */
+int flat_db_insert(db_con_t* h, db_key_t* k, db_val_t* v, int n);
+
+
+#endif /* _FLATSTORE_H */

+ 114 - 0
modules/db_flatstore/flatstore_mod.c

@@ -0,0 +1,114 @@
+/* 
+ * $Id$ 
+ *
+ * Flatstore module interface
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-11  updated to the new module exports interface (andrei)
+ *  2003-03-16  flags export parameter added (janakj)
+ */
+
+#include "../../sr_module.h"
+#include "flatstore.h"
+#include "flatstore_mod.h"
+
+MODULE_VERSION
+
+static int child_init(int rank);
+
+static int mod_init(void);
+
+/*
+ * Process number used in filenames
+ */
+int flat_pid;
+
+/*
+ * Should we flush after each write to the database ?
+ */
+int flat_flush = 1;
+
+
+/*
+ * Delimiter delimiting columns
+ */
+char* flat_delimiter = "|";
+
+
+/*
+ * Flatstore database module interface
+ */
+static cmd_export_t cmds[] = {
+	{"db_use_table",   (cmd_function)flat_use_table, 2, 0, 0},
+	{"db_init",        (cmd_function)flat_db_init,   1, 0, 0},
+	{"db_close",       (cmd_function)flat_db_close,  2, 0, 0},
+	{"db_insert",      (cmd_function)flat_db_insert, 2, 0, 0},
+	{0, 0, 0, 0, 0}
+};
+
+
+/*
+ * Exported parameters
+ */
+static param_export_t params[] = {
+	{"flush", INT_PARAM, &flat_flush},
+	{0, 0, 0}
+};
+
+
+struct module_exports exports = {	
+	"flatstore",
+	cmds,
+	params,    /*  module parameters */
+	mod_init,  /* module initialization function */
+	0,         /* response function*/
+	0,         /* destroy function */
+	0,         /* oncancel function */
+	child_init /* per-child init function */
+};
+
+
+static int mod_init(void)
+{
+	if (strlen(flat_delimiter) != 1) {
+		LOG(L_ERR, "flatstore:mod_init: Delimiter has to be exactly one character\n");
+		return -1;
+	}
+	return 0;
+}
+
+
+static int child_init(int rank)
+{
+	if (rank <= 0) {
+		flat_pid = - rank;
+	} else {
+		flat_pid = rank - PROC_UNIXSOCK;
+	}
+	return 0;
+}

+ 58 - 0
modules/db_flatstore/flatstore_mod.h

@@ -0,0 +1,58 @@
+/* 
+ * $Id$ 
+ *
+ * Flatstore module interface
+ *
+ * Copyright (C) 2004 FhG Fokus
+ *
+ * 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * 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
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-11  updated to the new module exports interface (andrei)
+ *  2003-03-16  flags export parameter added (janakj)
+ */
+
+#ifndef FLATSTORE_MOD_H
+#define FLATSTORE_MOD_H
+
+
+/*
+ * Process number used in filenames
+ */
+extern int flat_pid;
+
+
+/*
+ * Should we flush after each write to the database ?
+ */
+extern int flat_flush;
+
+
+/*
+ * Delmiter delimiting columns
+ */
+extern char* flat_delimiter;
+
+
+#endif /* FLATSTORE_MOD_H */