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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 1 07:36:27 CDT 2010


Author: ivaxer
Date: Thu Jul  1 07:36:24 2010
New Revision: 273311

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=273311
Log:
implemented public API functions (excepting the copy function)

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=273311&r1=273310&r2=273311
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/storage.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/storage.h Thu Jul  1 07:36:24 2010
@@ -40,26 +40,21 @@
 struct ast_storage_fileobject {
 	char name[256];
 	AST_RWLIST_HEAD(, ast_storage_fileinst) files;
-};
-
-struct ast_storage_fileobjectlist {
-	struct ast_storage_fileobject fileobject;
-	AST_RWLIST_ENTRY(ast_storage_fileobjectlist) list;
+	AST_RWLIST_ENTRY(ast_storage_fileobject) list;
 };
 
 struct ast_storage_dirobject {
 	char objectpath[256];
-	AST_RWLIST_HEAD(, ast_storage_fileobjectlist) fileobjects;
+	AST_RWLIST_HEAD(, ast_storage_fileobject) fileobjects;
 };
 
 struct ast_storage_be {
+	const char *name;
 	struct ast_storage *(*create)(const char *uri);
 	int (*release)(struct ast_storage *st);
 	struct ast_storage_fileobject *(*get)(struct ast_storage *st, const char *objectname, const char *exts);
-	int (*put)(struct ast_storage *st, ast_storage_fileobject *fo);
-	int (*del)(struct ast_storage *st, ast_storage_fileobject *fo);
-	int (*open)(struct ast_storage *st, struct ast_storage_fileinst *fi, mode_t mode);
-	int (*close)(struct ast_storage *st, struct ast_storage_fileinst *fi);
+	int (*put)(struct ast_storage *st, struct ast_storage_fileobject *fo);
+	int (*del)(struct ast_storage *st, struct ast_storage_fileobject *fo);
 	size_t (*read)(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count);
 	size_t (*write)(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count);
 	struct ast_storage_dirobject *(*listdir)(struct ast_storage *st, const char *objectpath);
@@ -105,9 +100,6 @@
  */
 int ast_storage_put(struct ast_storage *st, struct ast_storage_fileobject *fo);
 
-int ast_storage_open(struct ast_storage *st, struct ast_storage_fileinst *fi, mode_t mode);
-int ast_storage_close(struct ast_storage *st, struct ast_storage_fileinst *fi);
-
 int ast_storage_read(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count);
 int ast_storage_write(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count);
 
@@ -128,6 +120,12 @@
 unsigned long ast_storage_tell(struct ast_storage *st, struct ast_storage_fileinst *fi);
 int ast_storage_seek(struct ast_storage *st, struct ast_storage_fileinst *fi);
 
+void ast_storage_fileobject_release(struct ast_storage_fileobject *fo);
+void ast_storage_dirobject_release(struct ast_storage_dirobject *dobj);
+
+int ast_storage_open(struct ast_storage_fileinst *fi, mode_t mode);
+int ast_storage_close(struct ast_storage_fileinst *fi);
+
 /*! \brief Get storage engine by name
  * \param name Name of storage engine
  */

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=273311&r1=273310&r2=273311
==============================================================================
--- team/ivaxer/ast_storage/main/storage.c (original)
+++ team/ivaxer/ast_storage/main/storage.c Thu Jul  1 07:36:24 2010
@@ -37,28 +37,6 @@
 
 static AST_RWLIST_HEAD_STATIC(storage_engines, ast_storage_be);
 
-struct ast_storage_null {
-	const struct ast_storage_be *be;
-};
-
-static const struct ast_storage_be null_se;
-
-static struct ast_storage *se_create_null(const char *uri)
-{
-	struct ast_storage *st = ast_calloc(1, sizeof(struct ast_storage));
-	struct ast_storage_null *nst = ast_calloc(1, sizeof(struct ast_storage_null));
-	st->xst = (void *)nst;
-	st->be = &null_se;
-	ast_copy_string(st->path, uri, sizeof(st->path));
-	return st;
-}
-
-static int se_free_null(struct ast_storage *st)
-{
-	ast_free(st);
-	return 0;
-}
-
 int __ast_register_storage(const struct ast_storage_be *be, struct ast_module *mod)
 {
 	struct ast_storage_be *tmp;
@@ -118,24 +96,6 @@
 	return res;
 }
 
-static int empty_filelist(struct ast_storage_filelist *fl)
-{
-	struct ast_storage_fileinst *fi;
-
-	if (!fl)
-		return 0;
-
-	AST_RWLIST_WRLOCK(&fl->files);
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&fl->files, fi, list) {
-		AST_RWLIST_REMOVE_CURRENT(list);
-		ast_free(fi->ent);
-		ast_free(fi);
-	}
-	AST_RWLIST_TRAVERSE_SAFE_END
-	AST_RWLIST_UNLOCK(&fl->files);
-	return 0;
-}
-
 struct ast_storage_be *ast_storage_getbyname(const char *name)
 {
 	struct ast_storage_be *be;
@@ -156,143 +116,121 @@
 {
 	struct ast_storage_be *be;
 	struct ast_storage *st = NULL;
-	char tmp[PATH_MAX];
-	char *stringp = tmp;
+	char *tmp;
 	char *sename;
 	char *dir;
 
-	stringp = ast_strdupa(uri);
-	if ((dir = strstr(stringp, "://"))) {
+	tmp = ast_strdupa(uri);
+	if ((dir = strstr(tmp, "://"))) {
 		*dir = '\0';
 		dir += 3;
 	}
-	sename = stringp;
-
-	if (!(ast_storage_getbyname(sename)))
-		return NULL;
-
-	AST_RWLIST_TRAVERSE(&storage_engines, be, list) {
-		if (!strcasecmp(be->name, sename)) {
-			if ((st = be->create(S_OR(dir, ""))))
-				st->fl = ast_calloc(1, sizeof(*st->fl));
-			return st;
-		}
-	}
-	return NULL;
+	sename = tmp;
+
+	if (!(be = ast_storage_getbyname(sename)))
+		return NULL;
+
+	st = be->create(S_OR(dir, ""));
+	return st;
 }
 
 int ast_storage_release(struct ast_storage *st)
 {
-	if (st) {
-		empty_filelist(st->fl);
-		ast_free(st->fl);
-		return st->be->free ? st->be->free(st) : -1;
-	} else
-		return -1;
-}
-
-int ast_storage_get(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize)
-{
-	if (st) {
-		/* Empty the file list first, just to be safe */
-		empty_filelist(st->fl);
-		return st->be->get ? st->be->get(st, objectname, exts, localfile, localfilesize) : -1;
-	} else
-		return -1;
+	return st && st->be->release ? st->be->release(st) : -1;
+}
+
+struct ast_storage_fileobject *ast_storage_get(struct ast_storage *st, const char *objectname, const char *exts)
+{
+	return st && st->be->get ? st->be->get(st, objectname, exts) : NULL;
+}
+
+int ast_storage_put(struct ast_storage *st, struct ast_storage_fileobject *fo)
+{
+	return st && st->be->put ? st->be->put(st, fo) : -1;
+}
+
+int ast_storage_open(struct ast_storage_fileinst *fi, mode_t mode)
+{
+	if (!fi)
+		return -1;
+
+	fi->fd = open(fi->localpath, mode);
+	return fi->fd;
+}
+
+int ast_storage_close(struct ast_storage_fileinst *fi)
+{
+	int ret = -1;
+
+	if(!fi)
+		return -1;
+
+	ret = close(fi->fd);
+	if (!ret)
+		fi->fd = -1;
+	return ret;
+}
+
+int ast_storage_read(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count)
+{
+	return st && st->be->read ? st->be->read(st, fi, buf, count) : -1;
+}
+
+int ast_storage_write(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count)
+{
+	return st && st->be->write ? st->be->write(st, fi, buf, count) : -1;
+}
+
+int ast_storage_del(struct ast_storage *st, struct ast_storage_fileobject *fo)
+{
+	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)
+{
+	if (st && st->be->copy)
+		return st->be->copy(st, from, to);
+	/* TODO: implement using the get and put functions */
+	return -1;
+}
+
+struct ast_storage_dirobject *ast_storage_listdir(struct ast_storage *st, const char *pathname)
+{
+	return st && st->be->listdir ? st->be->listdir(st, pathname) : NULL;
+}
+
+void ast_storage_fileobject_release(struct ast_storage_fileobject *fo) {
+	struct ast_storage_fileinst *inst;
+
+	if (!fo)
+		return;
+
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&fo->files, inst, list) {
+		AST_RWLIST_REMOVE_CURRENT(list);
+		ast_storage_close(inst);
+		ast_free(inst);
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END
+
+	ast_free(fo);
+}
+
+void ast_storage_dirobject_release(struct ast_storage_dirobject *dobj) {
+	struct ast_storage_fileobject *fo;
+
+	if (!dobj)
+		return;
+
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&dobj->fileobjects, fo, list) {
+		AST_RWLIST_REMOVE_CURRENT(list);
+		ast_storage_fileobject_release(fo);
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END
+
+	ast_free(dobj);
 }
 
 #if 0
-int ast_storage_put(struct ast_storage *st, struct ast_storage_filelist *fl, const char *exts)
-{
-	return st && st->be->put ? st->be->put(st, fl, exts) : -1;
-}
-#endif
-
-int ast_storage_open(struct ast_storage *st, struct ast_storage_fileinst *fi, mode_t mode)
-{
-	return st && st->be->open ? st->be->open(st, fi, mode) : -1;
-}
-
-int ast_storage_close(struct ast_storage *st, struct ast_storage_fileinst *fi)
-{
-	return st && st->be->close ? st->be->close(st, fi) : -1;
-}
-
-void *ast_storage_read(struct ast_storage *st, struct ast_storage_fileinst *fi, size_t chunksize)
-{
-	return st && st->be->read ? st->be->read(st, fi, chunksize) : NULL;
-}
-
-int ast_storage_write(struct ast_storage *st, struct ast_storage_fileinst *fi, void *data, size_t chunksize)
-{
-	return st && st->be->write ? st->be->write(st, fi, data, chunksize) : -1;
-}
-
-int ast_storage_del(struct ast_storage *st, const char *exts)
-{
-	return st && st->be->del ? st->be->del(st, exts) : -1;
-}
-
-int ast_storage_copy(struct ast_storage *st, struct ast_storage_fileinst *from, struct ast_storage_fileinst *to)
-{
-	int res = -1;
-	void *data;
-	if (ast_storage_open(st, from, 0) == 0) {
-		if (ast_storage_open(st, to, 0) == 0) {
-			while ((data = ast_storage_read(st, from, 0))) {
-				ast_storage_write(st, to, data, 0);
-			}
-			res = 0;
-			ast_storage_close(st, to);
-		}
-		ast_storage_close(st, from);
-	}
-	return res;
-}
-
-void *ast_storage_opendir(struct ast_storage *st, const char *objectpath)
-{
-	return st->be->opendir ? st->be->opendir(st, objectpath) : NULL;
-}
-
-int ast_storage_readdir(struct ast_storage *st, void *dirptr, struct ast_storage_dirent *dirent)
-{
-	return st->be->readdir ? st->be->readdir(st, dirptr, dirent) : -1;
-}
-
-int ast_storage_closedir(struct ast_storage *st, void *dirptr)
-{
-	return st->be->closedir ? st->be->closedir(st, dirptr) : -1;
-}
-
-int ast_storage_count(struct ast_storage *st, const char *objectpath)
-{
-	void *dirptr;
-	struct ast_storage_dirent dirent;
-	int count = 0;
-
-	if (!(st->be->opendir && st->be->readdir && st->be->closedir))
-		return -1;
-
-	dirptr = st->be->opendir(st, objectpath);
-	if (!dirptr)
-		return -1;
-
-	while (st->be->readdir(st, dirptr, &dirent) == 0) {
-		char *ext;
-
-		/* Parse out the file extension */
-		if ((ext = strrchr(dirent.name, '.'))) {
-			ext++;
-		}
-		if (strcmp(ext, "txt") == 0)
-			count++;
-	}
-
-	st->be->closedir(st, dirptr);
-	return count;
-}
-
 static char *handle_storage_show_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_storage *st;
@@ -441,24 +379,17 @@
 		ast_cli(a->fd, "No storage engine named '%s' found.\n", a->argv[3]);
 	return CLI_SUCCESS;
 }
-
+#endif
 
 
 struct ast_cli_entry cli_storage[] = {
-	AST_CLI_DEFINE(handle_storage_show_engines,"Show a storage engine"),
+/*	AST_CLI_DEFINE(handle_storage_show_engines,"Show a storage engine"),
 	AST_CLI_DEFINE(handle_storage_show_engine,"List of storage engines"),
-	AST_CLI_DEFINE(handle_storage_show_file,"Show a file within a storage engine"),
+	AST_CLI_DEFINE(handle_storage_show_file,"Show a file within a storage engine"), */
 };
 
-static const struct ast_storage_be null_se = {
-	.name = "null",
-	.create = se_create_null,
-	.free = se_free_null,
-};
-
 int ast_storage_engine_init(void)
 {
-	__ast_register_storage(&null_se, NULL);
 	ast_cli_register_multiple(cli_storage, ARRAY_LEN(cli_storage));
 	return 0;
 }




More information about the asterisk-commits mailing list