Browse Source

- support for flatstore uris with relative pathnames (they are
converted to absolute with respect to the main ser config file)
- todo list added

Jan Janak 17 years ago
parent
commit
6fe11123ef

+ 4 - 1
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;

+ 80 - 0
modules/db_flatstore/flat_uri.c

@@ -0,0 +1,80 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ * Written by Jan Janak <[email protected]>
+ *
+ * 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;	
+}
+
+/** @} */

+ 62 - 0
modules/db_flatstore/flat_uri.h

@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ * Written by Jan Janak <[email protected]>
+ *
+ * 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 */

+ 5 - 3
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}
 };
 

+ 2 - 0
modules/db_flatstore/todo.txt

@@ -0,0 +1,2 @@
+* Create the directory if it does not exist and check permissions
+