[asterisk-commits] qwell: branch group/ast_storage r90988 - in /team/group/ast_storage: include/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 4 14:58:24 CST 2007


Author: qwell
Date: Tue Dec  4 14:58:24 2007
New Revision: 90988

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90988
Log:
Allow this branch to build again.
Also add some general cleanup, and make the API a little more sane.

Part of this closes issue #11466, which had a patch by snuffy.

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

Modified: team/group/ast_storage/include/asterisk/storage.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/include/asterisk/storage.h?view=diff&rev=90988&r1=90987&r2=90988
==============================================================================
--- team/group/ast_storage/include/asterisk/storage.h (original)
+++ team/group/ast_storage/include/asterisk/storage.h Tue Dec  4 14:58:24 2007
@@ -97,7 +97,7 @@
  * \param storage_type Name of the backend
  * \param uri Backend specific URI to the resource
  */
-struct ast_storage *ast_storage_request(const char *storage_type, const char *uri);
+struct ast_storage *ast_storage_request(const char *uri);
 
 /*! \brief Releases a storage instance created with ast_storage_request
  */

Modified: team/group/ast_storage/main/storage.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/main/storage.c?view=diff&rev=90988&r1=90987&r2=90988
==============================================================================
--- team/group/ast_storage/main/storage.c (original)
+++ team/group/ast_storage/main/storage.c Tue Dec  4 14:58:24 2007
@@ -57,7 +57,7 @@
 
 static int se_free_null(struct ast_storage *st)
 {
-	free(st);
+	ast_free(st);
 	return 0;
 }
 
@@ -104,8 +104,8 @@
 	}
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&storage_engines, tmp, list) {
 		if (!strcasecmp(name, tmp->name)) {
-			AST_RWLIST_REMOVE_CURRENT(&storage_engines, list);
-			free(tmp);
+			AST_RWLIST_REMOVE_CURRENT(list);
+			ast_free(tmp);
 			res = 0;
 		}
 	}
@@ -113,8 +113,7 @@
 	AST_RWLIST_UNLOCK(&storage_engines);
 
 	if (!res) {
-		if (option_verbose > 1)
-			ast_verbose(VERBOSE_PREFIX_2 "Unregistered storage engine '%s'\n", name);
+		ast_verb(2, "Unregistered storage engine '%s'\n", name);
 	} else
 		ast_log(LOG_WARNING, "Tried to unregister storage engine '%s', already unregistered\n", name);
 
@@ -130,9 +129,9 @@
 
 	AST_RWLIST_WRLOCK(&fl->files);
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&fl->files, fi, list) {
-		AST_RWLIST_REMOVE_CURRENT(&fl->files, list);
-		free(fi->ent);
-		free(fi);
+		AST_RWLIST_REMOVE_CURRENT(list);
+		ast_free(fi->ent);
+		ast_free(fi);
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END
 	AST_RWLIST_UNLOCK(&fl->files);
@@ -155,14 +154,28 @@
 	return be;
 }
 
-struct ast_storage *ast_storage_request(const char *storage_type, const char *uri)
+struct ast_storage *ast_storage_request(const char *uri)
 {
 	struct ast_storage_be *be;
 	struct ast_storage *st = NULL;
+	char tmp[PATH_MAX];
+	char *stringp = tmp;
+	char *sename;
+	char *dir;
+
+	stringp = ast_strdupa(uri);
+	if ((dir = strstr(stringp, "://"))) {
+		*dir = '\0';
+		dir += 3;
+	}
+	sename = stringp;
+
+	if (!(ast_storage_getbyname(sename)))
+		return NULL;
 
 	AST_RWLIST_TRAVERSE(&storage_engines, be, list) {
-		if (!strcasecmp(be->name, storage_type)) {
-			if ((st = be->create(S_OR(uri, ""))))
+		if (!strcasecmp(be->name, sename)) {
+			if ((st = be->create(S_OR(dir, ""))))
 				st->fl = ast_calloc(1, sizeof(*st->fl));
 			return st;
 		}
@@ -174,7 +187,7 @@
 {
 	if (st) {
 		empty_filelist(st->fl);
-		free(st->fl);
+		ast_free(st->fl);
 		return st->be->free ? st->be->free(st) : -1;
 	} else
 		return -1;
@@ -282,38 +295,41 @@
 	return count;
 }
 
-static int storage_show_file(int fd, int argc, char *argv[])
+static char *handle_storage_show_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_storage *st;
 	struct ast_storage_fileinst *fi;
-	char tmp[PATH_MAX];
-	char *stringp = tmp;
-	char *sename;
-	char *fn;
 	int count_files = 0;
 	/* XXX We want to remove the need to pass in a char array like this now.. */
 	char blah[PATH_MAX];
-	if (argc != 4)
-		return RESULT_SHOWUSAGE;
-
-	stringp = ast_strdupa(argv[3]);
-	if ((fn = strstr(stringp, "://"))) {
-		*fn = '\0';
-		fn += 3;
-	}
-	sename = stringp;
-
-	if (!(ast_storage_getbyname(sename))) {
-		ast_cli(fd, "No storage engine named '%s' found.\n", sename);
-		return RESULT_SUCCESS;
-	}
-
-	if (!(st = ast_storage_request(sename, fn)))
-		ast_cli(fd, "Could not create storage engine named '%s'.\n", sename);
-	else {
-		ast_cli(fd, "File information\n");
+	char *fn;
+	char *uri;
+
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "storage show file";
+		e->usage =
+			"Usage: storage show file <engine://filename>\n"
+			"       Displays information about a file via the storage engine\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	
+	if (a->argc != 4)
+		return CLI_SHOWUSAGE;
+
+	uri = ast_strdupa(a->argv[3]);
+	if ((fn = strrchr(uri, '/')))
+		*fn++ = '\0';
+	else
+		return CLI_SUCCESS;
+
+	if ((st = ast_storage_request(uri))) {
+		ast_cli(a->fd, "File information\n");
 		/* We don't care about format/extension here, so just send NULL */
-		if (!(ast_storage_get(st, st->path, NULL, blah, sizeof(blah)))) {
+		if (!(ast_storage_get(st, fn, NULL, blah, sizeof(blah)))) {
 			AST_RWLIST_TRAVERSE(&st->fl->files, fi, list) {
 				char *ext;
 
@@ -323,113 +339,117 @@
 				}
 
 				count_files++;
-				ast_cli(fd, "Name  : %s\n", fi->ent->name);
-				ast_cli(fd, "Format: %s\n", ast_getformatname(ast_getformatbyextension(ext)));
+				ast_cli(a->fd, "Name  : %s\n", fi->ent->name);
+				ast_cli(a->fd, "Format: %s\n", ast_getformatname(ast_getformatbyextension(ext)));
 			}
 		}
-		ast_cli(fd, "\n");
-		ast_cli(fd, "Found %d matching file(s).\n", count_files);
+		ast_cli(a->fd, "\n");
+		ast_cli(a->fd, "Found %d matching file(s).\n", count_files);
 	}
 	ast_storage_release(st);
-	return RESULT_SUCCESS;
-}
-
-static int storage_show_engines(int fd, int argc, char *argv[])
+	return CLI_SUCCESS;
+}
+
+static char *handle_storage_show_engines(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_storage_be *be;
 	int count_se = 0;
 
-	if (argc != 3)
-		return RESULT_SHOWUSAGE;
-	ast_cli(fd, "Storage Engine\n");
+	switch(cmd) {
+	case CLI_INIT:
+		e->command = "storage show engines";
+		e->usage =
+			"Usage: storage show engines\n"
+			"       Displays currently registered storage engines (if any)\n";
+		return NULL;
+	case CLI_GENERATE:
+			return NULL;
+	}
+
+	if(a->argc != 3)
+		return CLI_SHOWUSAGE;
+
+	ast_cli(a->fd, "Storage Engine\n");
 
 	if (AST_RWLIST_RDLOCK(&storage_engines)) {
 		ast_log(LOG_WARNING, "Unable to lock storage engine list\n");
-		return RESULT_FAILURE;
+		return CLI_FAILURE;
 	}
 
 	AST_RWLIST_TRAVERSE(&storage_engines, be, list) {
-		ast_cli(fd, "%s\n", be->name);
+		ast_cli(a->fd, "%s\n", be->name);
 		count_se++;
 	}
 	AST_RWLIST_UNLOCK(&storage_engines);
-	ast_cli(fd, "%d storage engine(s) registered.\n", count_se);
-	return RESULT_SUCCESS;
-}
-
-static int storage_show_engine(int fd, int argc, char *argv[])
+	ast_cli(a->fd, "%d storage engine(s) registered.\n", count_se);
+	return CLI_SUCCESS;
+}
+
+static char *complete_storage_show_engines(struct ast_cli_args *a)
 {
 	struct ast_storage_be *be;
-
-	if (argc != 4)
-		return RESULT_SHOWUSAGE;
-
-	if ((be = ast_storage_getbyname(argv[3]))) {
-		ast_cli(fd, "Storage Engine: %s\n", be->name);
-		ast_cli(fd, "Can get       : %s\n", be->get ? "yes" : "no");
+	char *ret = NULL;
+	int which = 0;
+	int wordlen = strlen(a->word);
+
+	AST_RWLIST_RDLOCK(&storage_engines);
+	AST_RWLIST_TRAVERSE(&storage_engines, be, list) {
+		if (!strncasecmp(a->word, be->name, wordlen) && ++which > a->n) {
+			ret = strdup(be->name);
+			break;
+		}
+	}
+	AST_RWLIST_UNLOCK(&storage_engines);
+
+	return ret;
+}
+static char *handle_storage_show_engine(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_storage_be *be;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "storage show engine";
+		e->usage =
+			"Usage: storage show engine <engine>\n"
+			"       Displays capabilities of requested storage engine\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_storage_show_engines(a);
+	}
+
+	if (a->argc != 4)
+		return CLI_SHOWUSAGE;
+
+	if ((be = ast_storage_getbyname(a->argv[3]))) {
+		ast_cli(a->fd, "Storage Engine: %s\n", be->name);
+		ast_cli(a->fd, "Can get       : %s\n", be->get ? "yes" : "no");
 #if 0
-		ast_cli(fd, "Can put       : %s\n", be->put ? "yes" : "no");
+		ast_cli(a->fd, "Can put       : %s\n", be->put ? "yes" : "no");
 #endif
-		ast_cli(fd, "Can del       : %s\n", be->del ? "yes" : "no");
-		ast_cli(fd, "Can opendir   : %s\n", be->opendir ? "yes" : "no");
-		ast_cli(fd, "Can readdir   : %s\n", be->readdir ? "yes" : "no");
-		ast_cli(fd, "Can closedir  : %s\n", be->closedir ? "yes" : "no");
+		ast_cli(a->fd, "Can del       : %s\n", be->del ? "yes" : "no");
+		ast_cli(a->fd, "Can opendir   : %s\n", be->opendir ? "yes" : "no");
+		ast_cli(a->fd, "Can readdir   : %s\n", be->readdir ? "yes" : "no");
+		ast_cli(a->fd, "Can closedir  : %s\n", be->closedir ? "yes" : "no");
 		if (be->status) {
-			ast_cli(fd, "\n");
-			ast_cli(fd, "Additional status\n");
+			ast_cli(a->fd, "\n");
+			ast_cli(a->fd, "Additional status\n");
 			/* XXX Need to rethink this.
 			 * This requires a struct ast_storage *, and we can't cast to it from ast_storage_be
 			be->status((struct ast_storage *)be, fd);
 			 */
 		}
 	} else
-		ast_cli(fd, "No storage engine named '%s' found.\n", argv[3]);
-	return RESULT_SUCCESS;
-}
-
-static char *complete_storage_show_engines(const char *line, const char *word, int pos, int state)
-{
-	struct ast_storage_be *be;
-	char *ret = NULL;
-	int which = 0;
-	int wordlen = strlen(word);
-
-	AST_RWLIST_RDLOCK(&storage_engines);
-	AST_RWLIST_TRAVERSE(&storage_engines, be, list) {
-		if (!strncasecmp(word, be->name, wordlen) && ++which > state) {
-			ret = strdup(be->name);
-			break;
-		}
-	}
-	AST_RWLIST_UNLOCK(&storage_engines);
-
-	return ret;
-}
-
-char storage_show_file_usage[] =
-"Usage: storage show file <engine://filename>\n"
-"       Displays information about a file via the storage engine\n";
-
-char storage_show_engines_usage[] = 
-"Usage: storage show engines\n"
-"       Displays currently registered storage engines (if any)\n";
-
-char storage_show_engine_usage[] =
-"Usage: storage show engine <engine>\n"
-"       Displays capabilities of requested storage engine\n";
+		ast_cli(a->fd, "No storage engine named '%s' found.\n", a->argv[3]);
+	return CLI_SUCCESS;
+}
+
+
 
 struct ast_cli_entry cli_storage[] = {
-	{ { "storage", "show", "file", NULL },
-	storage_show_file, "Displays information for a file",
-	storage_show_file_usage },
-
-	{ { "storage", "show", "engines" },
-	storage_show_engines, "Displays storage engines",
-	storage_show_engines_usage },
-
-	{ { "storage", "show", "engine", NULL },
-	storage_show_engine, "Displays storage engine capabilities",
-	storage_show_engine_usage, complete_storage_show_engines },
+	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"),
 };
 
 static const struct ast_storage_be null_se = {




More information about the asterisk-commits mailing list