[asterisk-commits] ivaxer: branch ivaxer/ast_storage r279386 - in /team/ivaxer/ast_storage: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 25 09:30:38 CDT 2010


Author: ivaxer
Date: Sun Jul 25 09:30:34 2010
New Revision: 279386

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=279386
Log:
implemented ast_storage_copy() function
- added 'test_copy' unit-test
- fixed the copy function prototype

Modified:
    team/ivaxer/ast_storage/include/asterisk/storage.h
    team/ivaxer/ast_storage/main/storage.c

Modified: team/ivaxer/ast_storage/include/asterisk/storage.h
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/include/asterisk/storage.h?view=diff&rev=279386&r1=279385&r2=279386
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/storage.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/storage.h Sun Jul 25 09:30:34 2010
@@ -63,7 +63,7 @@
 	struct ast_storage_dirobject *(*listdir)(struct ast_storage *st, const char *objectpath);
 	off_t (*tell)(struct ast_storage *st, struct ast_storage_fileinst *fi);
 	off_t (*seek)(struct ast_storage *st, struct ast_storage_fileinst *fi, off_t offset, int whence);
-	int (*copy)(struct ast_storage *st, struct ast_storage_fileobject *from, struct ast_storage_fileobject *to);
+	int (*copy)(struct ast_storage *st, const char *from, const char *to);
 	AST_RWLIST_ENTRY(ast_storage_be) list;
 	struct ast_module *module;
 };
@@ -112,7 +112,7 @@
  */
 int ast_storage_del(struct ast_storage *st, struct ast_storage_fileobject *fo);
 
-int ast_storage_copy(struct ast_storage *st, struct ast_storage_fileobject *from, struct ast_storage_fileobject *to);
+int ast_storage_copy(struct ast_storage *st, const char *from, const char *to);
 
 /*! \brief Starts retrieval of objects in a resource path
  * \param st Storage instance

Modified: team/ivaxer/ast_storage/main/storage.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/main/storage.c?view=diff&rev=279386&r1=279385&r2=279386
==============================================================================
--- team/ivaxer/ast_storage/main/storage.c (original)
+++ team/ivaxer/ast_storage/main/storage.c Sun Jul 25 09:30:34 2010
@@ -34,6 +34,7 @@
 #include "asterisk/options.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/module.h"
+#include "asterisk/test.h"
 
 static AST_RWLIST_HEAD_STATIC(storage_engines, ast_storage_be);
 
@@ -193,13 +194,30 @@
 	return st && st->be->del ? st->be->del(st, fo) : -1;
 }
 
-int ast_storage_copy(struct ast_storage *st, struct ast_storage_fileobject *from, struct ast_storage_fileobject *to)
-{
+int ast_storage_copy(struct ast_storage *st, const char *from, const char *to)
+{
+	struct ast_storage_fileobject *fo;
+
 	if (st && st->be->copy) {
 		return st->be->copy(st, from, to);
 	}
-	/* TODO: implement using the get and put functions */
-	return -1;
+
+	fo = ast_storage_get(st, from, NULL);
+	if (!fo) {
+		ast_log(LOG_WARNING, "Unable to copy '%s' to '%s': get() failed\n", from, to);
+		return -1;
+	}
+
+	ast_copy_string(fo->objectname, to, sizeof(fo->objectname));
+	
+	if (ast_storage_put(st, fo, NULL)) {
+		ast_log(LOG_WARNING, "Unable to copy '%s' to '%s': put() failed\n", from, to);
+		ast_storage_fileobject_release(fo);
+		return -1;
+	}
+
+	ast_storage_fileobject_release(fo);
+	return 0;
 }
 
 struct ast_storage_dirobject *ast_storage_listdir(struct ast_storage *st, const char *pathname)
@@ -415,8 +433,50 @@
 	AST_CLI_DEFINE(handle_storage_show_file,"Show a file within a storage engine"), */
 };
 
+#ifdef TEST_FRAMEWORK
+
+AST_TEST_DEFINE(copy_test)
+{
+	struct ast_storage *st;
+	int ret;
+	char uri[] = "odbc://asterisk-storage-test/storage/testpath";
+
+        switch (cmd) {
+        case TEST_INIT:
+                info->name = "copy_test";
+                info->category = "main/storage/generic";
+                info->summary = "copy test";
+                info->description =
+                        "Tests the ast_storage_copy function";
+                return AST_TEST_NOT_RUN;
+        case TEST_EXECUTE:
+                break;
+        }
+
+	st = ast_storage_request(uri);
+	if(!st) {
+		return AST_TEST_FAIL;
+	}
+
+	ret = ast_storage_copy(st, "test", "huest");
+	if(ret) {
+		return AST_TEST_FAIL;
+	}
+
+	ret = ast_storage_release(st);
+	if(ret) {
+		return AST_TEST_FAIL;
+	}
+
+        return AST_TEST_PASS;
+}
+#endif
+
 int ast_storage_engine_init(void)
 {
+#ifdef TEST_FRAMEWORK
+	AST_TEST_REGISTER(copy_test);
+#endif
 	ast_cli_register_multiple(cli_storage, ARRAY_LEN(cli_storage));
 	return 0;
 }




More information about the asterisk-commits mailing list