[svn-commits] qwell: branch group/ast_storage r79270 - in /team/group/ast_storage: include/...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 13 14:02:46 CDT 2007


Author: qwell
Date: Mon Aug 13 14:02:45 2007
New Revision: 79270

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79270
Log:
Commit a bunch of changes I've had sitting in a local copy for a while (yeah, I know..)

This changes the API quite a bit.

It probably doesn't work - at all.

Modified:
    team/group/ast_storage/include/asterisk/storage.h
    team/group/ast_storage/main/storage.c
    team/group/ast_storage/res/res_storage_file.c
    team/group/ast_storage/res/res_storage_odbc.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=79270&r1=79269&r2=79270
==============================================================================
--- team/group/ast_storage/include/asterisk/storage.h (original)
+++ team/group/ast_storage/include/asterisk/storage.h Mon Aug 13 14:02:45 2007
@@ -31,31 +31,10 @@
 extern "C" {
 #endif
 
-struct ast_storage_dirent;
-
-struct ast_storage_be {
-	const char *name;
-	struct ast_storage *(*create)(const char *uri);
-	int (*free)(struct ast_storage *st);
-	struct ast_storage_filelist *(*get)(struct ast_storage *st, const char *objectname, const char *fileformats, char *localfile, size_t localfilesize);
-	int (*put)(struct ast_storage *st, const char *objectname, const char *fileformats, const char *localfile);
-	int (*del)(struct ast_storage *st, const char *objectname, const char *fileformats);
-	void *(*opendir)(struct ast_storage *st, const char *objectpath);
-	int (*readdir)(struct ast_storage *st, void *dirptr, struct ast_storage_dirent *dirent);
-	int (*closedir)(struct ast_storage *st, void *dirptr);
-	int (*status)(struct ast_storage *st, int fd);
-	AST_RWLIST_ENTRY(ast_storage_be) list;
-	struct ast_module *module;
-};
-
-/* Most specific backends will have longer structures */
-struct ast_storage {
-	struct ast_storage_be *be;
-};
-
 struct ast_storage_dirent {
 	char name[256];
-	char format[10];
+	char ext[10];
+	int fd;
 };
 
 /* XXX How are we going to handle metadata about the file?
@@ -78,6 +57,34 @@
 	AST_RWLIST_HEAD(, ast_storage_fileinst) files;
 };
 
+struct ast_storage_be {
+	const char *name;
+	struct ast_storage_filelist *fl;
+	struct ast_storage *(*create)(const char *uri);
+	int (*free)(struct ast_storage *st);
+	int (*get)(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize);
+#if 0
+	/* We don't need no stinkin' put() function. */
+	int (*put)(struct ast_storage *st, const char *exts);
+#endif
+	int (*open)(struct ast_storage *st, struct ast_storage_fileinst *fi, int mode);
+	int (*close)(struct ast_storage *st, struct ast_storage_fileinst *fi);
+	void *(*read)(struct ast_storage *st, struct ast_storage_fileinst *fi, size_t chunksize);
+	int (*write)(struct ast_storage *st, struct ast_storage_fileinst *fi, void *data, size_t chunksize);
+	int (*del)(struct ast_storage *st, const char *exts);
+	void *(*opendir)(struct ast_storage *st, const char *objectpath);
+	int (*readdir)(struct ast_storage *st, void *dirptr, struct ast_storage_dirent *dirent);
+	int (*closedir)(struct ast_storage *st, void *dirptr);
+	int (*status)(struct ast_storage *st, int fd);
+	AST_RWLIST_ENTRY(ast_storage_be) list;
+	struct ast_module *module;
+};
+
+/* Most specific backends will have longer structures */
+struct ast_storage {
+	struct ast_storage_be *be;
+};
+
 int __ast_register_storage(const struct ast_storage_be *e, struct ast_module *mod);
 #define ast_register_storage(e) __ast_register_storage(e, ast_module_info->self)
 
@@ -98,26 +105,32 @@
 /*! \brief Retrieves a file from the storage medium
  * \param st Storage instance
  * \param objectname Logical name of the file
- * \param fileformats Formats to retrieve
+ * \param exts File extensions to retrieve
  * \param localfile Buffer in which to place the name of the resulting temporary file.
  * \param localfilesize Length of the above buffer
  */
-struct ast_storage_filelist *ast_storage_get(struct ast_storage *st, const char *objectname, const char *fileformats, char *localfile, size_t localfilesize);
+int ast_storage_get(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize);
 
+#if 0
 /*! \brief Stores a file into the storage medium
  * \param st Storage instance
- * \param objectname Logical name of the file
- * \param fileformats Formats to store
- * \param localfile Location of the file to store
+ * \param exts File extensions to store
  */
-int ast_storage_put(struct ast_storage *st, const char *objectname, const char *fileformats, const char *localfile);
+int ast_storage_put(struct ast_storage *st, const char *exts);
+#endif
+
+int ast_storage_open(struct ast_storage *st, struct ast_storage_fileinst *fi, int mode);
+int ast_storage_close(struct ast_storage *st, struct ast_storage_fileinst *fi);
+void *ast_storage_read(struct ast_storage *st, struct ast_storage_fileinst *fi, size_t chunksize);
+int ast_storage_write(struct ast_storage *st, struct ast_storage_fileinst *fi, void *data, size_t chunksize);
 
 /*! \brief Removes a file from the storage medium
  * \param st Storage instance
- * \param objectname Logical name of the file
- * \param fileformats Formats to delete
+ * \param exts File extensions to delete
  */
-int ast_storage_del(struct ast_storage *st, const char *objectname, const char *fileformats);
+int ast_storage_del(struct ast_storage *st, const char *exts);
+
+int ast_storage_copy(struct ast_storage *st, struct ast_storage_fileinst *from, struct ast_storage_fileinst *to);
 
 /*! \brief Starts retrieval of objects in a resource path
  * \param st Storage instance

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=79270&r1=79269&r2=79270
==============================================================================
--- team/group/ast_storage/main/storage.c (original)
+++ team/group/ast_storage/main/storage.c Mon Aug 13 14:02:45 2007
@@ -43,7 +43,7 @@
 	const struct ast_storage_be *be;
 };
 
-const struct ast_storage_be null_se;
+static const struct ast_storage_be null_se;
 
 static struct ast_storage *se_create_null(const char *uri)
 {
@@ -118,77 +118,12 @@
 	return res;
 }
 
-struct ast_storage *ast_storage_request(const char *storage_type, const char *uri)
-{
-	struct ast_storage_be *e;
-
-	AST_RWLIST_TRAVERSE(&storage_engines, e, list) {
-		if (!strcasecmp(e->name, storage_type))
-			return e->create(S_OR(uri, ""));
-	}
-	return NULL;
-}
-
-int ast_storage_release(struct ast_storage *st)
-{
-	return st && st->be->free ? st->be->free(st) : -1;
-}
-
-struct ast_storage_filelist *ast_storage_get(struct ast_storage *st, const char *objectname, const char *fileformats, char *localfile, size_t localfilesize)
-{
-	return st->be->get ? st->be->get(st, objectname, fileformats, localfile, localfilesize) : NULL;
-}
-
-int ast_storage_put(struct ast_storage *st, const char *objectname, const char *fileformats, const char *localfile)
-{
-	return st->be->put ? st->be->put(st, objectname, fileformats, localfile) : -1;
-}
-
-int ast_storage_del(struct ast_storage *st, const char *objectname, const char *fileformats)
-{
-	return st->be->del ? st->be->del(st, objectname, fileformats) : -1;
-}
-
-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) {
-		if (strcmp(dirent.format, "txt") == 0)
-			count++;
-	}
-
-	st->be->closedir(st, dirptr);
-	return count;
-}
-
-static void destroy_filelist(struct ast_storage_filelist *fl)
+static int destroy_filelist(struct ast_storage_filelist *fl)
 {
 	struct ast_storage_fileinst *fi;
+
+	if (!fl)
+		return 0;
 
 	AST_RWLIST_WRLOCK(&fl->files);
 	AST_RWLIST_TRAVERSE(&fl->files, fi, list) {
@@ -197,6 +132,7 @@
 	}
 	AST_RWLIST_UNLOCK(&fl->files);
 	free(fl);
+	return 0;
 }
 
 struct ast_storage_be *ast_storage_getbyname(const char *name)
@@ -215,10 +151,117 @@
 	return e;
 }
 
+struct ast_storage *ast_storage_request(const char *storage_type, const char *uri)
+{
+	struct ast_storage_be *e;
+
+	AST_RWLIST_TRAVERSE(&storage_engines, e, list) {
+		if (!strcasecmp(e->name, storage_type))
+			return e->create(S_OR(uri, ""));
+	}
+	return NULL;
+}
+
+int ast_storage_release(struct ast_storage *st)
+{
+	destroy_filelist(st->be->fl);
+	return st && st->be->free ? st->be->free(st) : -1;
+}
+
+int ast_storage_get(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize)
+{
+	return st->be->get ? st->be->get(st, objectname, exts, localfile, localfilesize) : -1;
+}
+
+#if 0
+int ast_storage_put(struct ast_storage *st, struct ast_storage_filelist *fl, const char *exts)
+{
+	return st->be->put ? st->be->put(st, fl, exts) : -1;
+}
+#endif
+
+int ast_storage_open(struct ast_storage *st, struct ast_storage_fileinst *fi, int mode)
+{
+	return 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->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->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->be->write ? st->be->write(st, fi, data, chunksize) : -1;
+}
+
+int ast_storage_del(struct ast_storage *st, const char *exts)
+{
+	return 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, from, 0) == 0) {
+			while ((data = ast_storage_read(st, from, 0))) {
+				ast_storage_write(st, to, data, 0);
+			}
+			res = 0;
+			ast_storage_close(st, from);
+		}
+		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) {
+		if (strcmp(dirent.ext, "txt") == 0)
+			count++;
+	}
+
+	st->be->closedir(st, dirptr);
+	return count;
+}
+
 static int storage_show_file(int fd, int argc, char *argv[])
 {
 	struct ast_storage *e;
-	struct ast_storage_filelist *fl;
 	struct ast_storage_fileinst *fi;
 	char tmp[256];
 	char *stringp = tmp;
@@ -232,24 +275,30 @@
 	stringp = ast_strdupa(argv[3]);
 	sename = strsep(&stringp, ":");
 
-	if ((e = ast_storage_request(sename, NULL))) {
+	if (!(ast_storage_getbyname(sename))) {
+		ast_cli(fd, "No storage engine named '%s' found.\n", sename);
+		return RESULT_SUCCESS;
+	}
+
+	if (!(e = ast_storage_request(sename, NULL)))
+		ast_cli(fd, "Could not create storage engine named '%s'.\n", sename);
+	else {
 		ast_cli(fd, "File information\n");
-		/* We don't care about format here, so just send NULL */
-		if ((fl = ast_storage_get(e, stringp, NULL, blah, sizeof(blah)))) {
-			AST_RWLIST_TRAVERSE(&fl->files, fi, list) {
+		/* We don't care about format/extension here, so just send NULL */
+		if (!(ast_storage_get(e, stringp, NULL, blah, sizeof(blah)))) {
+			AST_RWLIST_TRAVERSE(&e->be->fl->files, fi, list) {
 				count_files++;
-				ast_cli(fd, "Format: %s\n", ast_getformatname(ast_getformatbyextension(fi->ent->format)));
+				ast_cli(fd, "Name  : '%s'\n", fi->ent->name);
+				ast_cli(fd, "Format: '%s'\n", ast_getformatname(ast_getformatbyextension(fi->ent->ext)));
 			}
-			destroy_filelist(fl);
 		}
 		ast_cli(fd, "\n");
 		ast_cli(fd, "Found %d matching file(s).\n", count_files);
-	} else
-		ast_cli(fd, "No storage engine named '%s' found.\n", sename);
+	}
 	return RESULT_SUCCESS;
 }
 
-static int show_storage_engines(int fd, int argc, char *argv[])
+static int storage_show_engines(int fd, int argc, char *argv[])
 {
 	struct ast_storage_be *e;
 	int count_se = 0;
@@ -268,11 +317,11 @@
 		count_se++;
 	}
 	AST_RWLIST_UNLOCK(&storage_engines);
-	ast_cli(fd, "%d storage engine%s registered.\n", count_se, count_se == 1 ? "" : "s");
+	ast_cli(fd, "%d storage engine(s) registered.\n", count_se);
 	return RESULT_SUCCESS;
 }
 
-static int show_storage_engine(int fd, int argc, char *argv[])
+static int storage_show_engine(int fd, int argc, char *argv[])
 {
 	struct ast_storage_be *e;
 
@@ -282,7 +331,9 @@
 	if ((e = ast_storage_getbyname(argv[3]))) {
 		ast_cli(fd, "Storage Engine: %s\n", e->name);
 		ast_cli(fd, "Can get       : %s\n", e->get ? "yes" : "no");
+#if 0
 		ast_cli(fd, "Can put       : %s\n", e->put ? "yes" : "no");
+#endif
 		ast_cli(fd, "Can del       : %s\n", e->del ? "yes" : "no");
 		ast_cli(fd, "Can opendir   : %s\n", e->opendir ? "yes" : "no");
 		ast_cli(fd, "Can readdir   : %s\n", e->readdir ? "yes" : "no");
@@ -297,7 +348,7 @@
 	return RESULT_SUCCESS;
 }
 
-static char *complete_show_storage_engines(const char *line, const char *word, int pos, int state)
+static char *complete_storage_show_engines(const char *line, const char *word, int pos, int state)
 {
 	struct ast_storage_be *e;
 	char *ret = NULL;
@@ -320,12 +371,12 @@
 "Usage: storage show file <engine:filename>\n"
 "       Displays information about a file via the storage engine\n";
 
-char show_storage_engines_usage[] = 
-"Usage: core show storage engines\n"
+char storage_show_engines_usage[] = 
+"Usage: storage show engines\n"
 "       Displays currently registered storage engines (if any)\n";
 
-char show_storage_engine_usage[] =
-"Usage: core show storage engine <engine>\n"
+char storage_show_engine_usage[] =
+"Usage: storage show engine <engine>\n"
 "       Displays capabilities of requested storage engine\n";
 
 struct ast_cli_entry cli_storage[] = {
@@ -334,15 +385,15 @@
 	storage_show_file_usage },
 
 	{ { "storage", "show", "engines" },
-	show_storage_engines, "Displays storage engines",
-	show_storage_engines_usage },
+	storage_show_engines, "Displays storage engines",
+	storage_show_engines_usage },
 
 	{ { "storage", "show", "engine", NULL },
-	show_storage_engine, "Displays storage engine capabilities",
-	show_storage_engine_usage, complete_show_storage_engines },
+	storage_show_engine, "Displays storage engine capabilities",
+	storage_show_engine_usage, complete_storage_show_engines },
 };
 
-const struct ast_storage_be null_se = {
+static const struct ast_storage_be null_se = {
 	.name = "null",
 	.create = se_create_null,
 	.free = se_free_null,

Modified: team/group/ast_storage/res/res_storage_file.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/res/res_storage_file.c?view=diff&rev=79270&r1=79269&r2=79270
==============================================================================
--- team/group/ast_storage/res/res_storage_file.c (original)
+++ team/group/ast_storage/res/res_storage_file.c Mon Aug 13 14:02:45 2007
@@ -54,8 +54,10 @@
 static struct ast_storage *se_create_file(const char *uri)
 {
 	struct ast_storage_file *fst = ast_calloc(1, sizeof(struct ast_storage_file));
+	struct ast_storage_filelist *fl = ast_calloc(1, sizeof(struct ast_storage_filelist));
 	ast_copy_string(fst->rootpath, uri, sizeof(fst->rootpath));
 	fst->be = &file_se;
+	((struct ast_storage_be *)fst->be)->fl = fl;
 	return ((struct ast_storage *)fst);
 }
 
@@ -87,7 +89,7 @@
 {
 	struct dirent *f;
 	struct file_storage_dir *dir = dirptr;
-	char *fmt;
+	char *ext;
 
 	if (dirent == NULL)
 		return EINVAL;
@@ -96,10 +98,10 @@
 
 	if ((f = readdir(dir->dir))) {
 		ast_copy_string(dirent->name, f->d_name, sizeof(dirent->name));
-		/* Parse out the file format */
-		if ((fmt = strrchr(dirent->name, '.'))) {
-			*fmt++ = '\0';
-			ast_copy_string(dirent->format, fmt, sizeof(dirent->format));
+		/* Parse out the file extension */
+		if ((ext = strrchr(dirent->name, '.'))) {
+			*ext++ = '\0';
+			ast_copy_string(dirent->ext, ext, sizeof(dirent->ext));
 		}
 		return 0;
 	}
@@ -116,7 +118,31 @@
 	return 0;
 }
 
-static struct ast_storage_filelist *se_get_file(struct ast_storage *st, const char *objectname, const char *fileformats, char *localfile, size_t localfilesize)
+static void *se_read_file(struct ast_storage *st, struct ast_storage_fileinst *fi, size_t chunksize)
+{
+	void *data = NULL;
+	return data;
+}
+
+static int se_write_file(struct ast_storage *st, struct ast_storage_fileinst *fi, void *data, size_t chunksize)
+{
+	int len = 0;
+	return len;
+}
+
+static int se_open_file(struct ast_storage *st, struct ast_storage_fileinst *fi, int mode)
+{
+	fi->ent->fd = -1;
+	return fi->ent->fd;
+}
+
+static int se_close_file(struct ast_storage *st, struct ast_storage_fileinst *fi)
+{
+	fi->ent->fd = 0;
+	return 0;
+}
+
+static int se_get_file(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize)
 {
 	struct ast_storage_filelist *fl = NULL;
 	struct ast_storage_file *fst = (struct ast_storage_file *)st;
@@ -124,6 +150,9 @@
 	struct ast_storage_dirent *dirent;
 	char dirname[256], *dirnameptr;
 
+	if (ast_strlen_zero(objectname))
+		return -1;
+
 	if (objectname[0] == '/')
 		ast_copy_string(localfile, objectname, localfilesize);
 	else
@@ -134,7 +163,7 @@
 	if (dirnameptr)
 		*dirnameptr++ = '\0';
 	else
-		return NULL;
+		return -1;
 
 	fl = ast_calloc(1, sizeof(*fl));
 
@@ -142,15 +171,16 @@
 		dirent = ast_calloc(1, sizeof(*dirent));
 		while ((!se_readdir_file(st, dir, dirent))) {
 			int found = 0;
-			if (!ast_strlen_zero(dirent->format)) {
+
+			if (!ast_strlen_zero(dirent->ext)) {
 				char fullfn[256];
-				snprintf(fullfn, sizeof(fullfn), "%s.%s", dirent->name, dirent->format);
-				/* If it's going to be an exact match, we don't care about fileformats */
+				snprintf(fullfn, sizeof(fullfn), "%s.%s", dirent->name, dirent->ext);
+				/* If it's going to be an exact match, we don't care about exts */
 				if (!strcmp(fullfn, dirnameptr))
 					found = 1;
 			}
 			if (!found && !strcmp(dirent->name, dirnameptr)) {
-				if (ast_strlen_zero(dirent->format) || !fileformats || ast_exts_compare(fileformats, dirent->format))
+				if (ast_strlen_zero(dirent->ext) || !exts || ast_exts_compare(exts, dirent->ext))
 					found = 1;
 			}
 
@@ -159,7 +189,7 @@
 				fi = ast_calloc(1, sizeof(*fi));
 				fi->ent = ast_calloc(1, sizeof(struct ast_storage_dirent));
 				ast_copy_string(fi->ent->name, dirent->name, sizeof(fi->ent->name));
-				ast_copy_string(fi->ent->format, dirent->format, sizeof(fi->ent->format));
+				ast_copy_string(fi->ent->ext, dirent->ext, sizeof(fi->ent->ext));
 				AST_RWLIST_WRLOCK(&fl->files);
 				AST_RWLIST_INSERT_TAIL(&fl->files, fi, list);
 				AST_RWLIST_UNLOCK(&fl->files);
@@ -169,34 +199,39 @@
 		se_closedir_file(st, dir);
 	} else {
 		free(fl);
-		return NULL;
-	}
-
-	return fl;
-}
-
-static int se_put_file(struct ast_storage *st, const char *objectname, const char *fileformats, const char *localfile)
+		return -1;
+	}
+
+	st->be->fl = fl;
+	return 0;
+}
+
+#if 0
+static int se_put_file(struct ast_storage *st, struct ast_storage_filelist *fl, const char *exts)
 {
 	struct ast_storage_file *fst = (struct ast_storage_file *)st;
 	int ifd;
 	int ofd;
 	int res = 0;
-	int len;
+	int len = 0;
 	char dest[256];
 	char buf[4096];
 
-	snprintf(dest, sizeof(dest), "%s/%s", fst->rootpath, objectname);
-
+	snprintf(dest, sizeof(dest), "%s/%s", fst->rootpath, fl->name);
+
+/* XXX We aren't going to read() directly from the filesystem for put()s.
 	if ((ifd = open(localfile, O_RDONLY)) < 0) {
 		ast_log(LOG_WARNING, "Unable to open %s in read-only mode\n", localfile);
 		return -1;
 	}
+*/
 	if ((ofd = open(dest, O_WRONLY | O_TRUNC | O_CREAT, 0666)) < 0) {
 		ast_log(LOG_WARNING, "Unable to open %s in write-only mode\n", dest);
 		close(ifd);
 		return -1;
 	}
 	do {
+		/* XXX No direct read()ing
 		len = read(ifd, buf, sizeof(buf));
 		if (len < 0) {
 			ast_log(LOG_WARNING, "Read failed on %s: %s\n", localfile, strerror(errno));
@@ -204,6 +239,7 @@
 			close(ofd);
 			unlink(dest);
 		}
+		*/
 		if (len) {
 			res = write(ofd, buf, len);
 			if (errno == ENOMEM || errno == ENOSPC || res != len) {
@@ -218,16 +254,17 @@
 	close(ofd);
 	return res;
 }
-
-static int se_del_file(struct ast_storage *st, const char *objectname, const char *fileformats)
+#endif
+
+static int se_del_file(struct ast_storage *st, const char *exts)
 {
 	struct ast_storage_file *fst = (struct ast_storage_file *)st;
 	char dest[256];
 
-	if (objectname[0] == '/')
-		return unlink(objectname);
+	if (st->be->fl->name[0] == '/')
+		return unlink(st->be->fl->name);
 	else {
-		snprintf(dest, sizeof(dest), "%s/%s", fst->rootpath, objectname);
+		snprintf(dest, sizeof(dest), "%s/%s", fst->rootpath, st->be->fl->name);
 		return unlink(dest);
 	}
 }
@@ -237,7 +274,13 @@
 	.create = se_create_file,
 	.free = se_free_file,
 	.get = se_get_file,
+#if 0
 	.put = se_put_file,
+#endif
+	.open = se_open_file,
+	.close = se_close_file,
+	.read = se_read_file,
+	.write = se_write_file,
 	.del = se_del_file,
 	.opendir = se_opendir_file,
 	.readdir = se_readdir_file,

Modified: team/group/ast_storage/res/res_storage_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/res/res_storage_odbc.c?view=diff&rev=79270&r1=79269&r2=79270
==============================================================================
--- team/group/ast_storage/res/res_storage_odbc.c (original)
+++ team/group/ast_storage/res/res_storage_odbc.c Mon Aug 13 14:02:45 2007
@@ -223,29 +223,32 @@
 	ast_copy_string(filename, filename2, filenamesize);
 }
 
-static struct ast_storage_filelist *se_get_odbc(struct ast_storage *st, const char *objectname, const char *fileformats, char *localfile, size_t localfilesize)
+static int se_get_odbc(struct ast_storage *st, const char *objectname, const char *exts, char *localfile, size_t localfilesize)
 {
 	struct ast_storage_filelist *fl = NULL;
 	struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
 	int res = -1, tempfd, x, gotten = 0;
 	char sql[128];
 	char pathname[256], filename[256], reallocalfile[256];
-	char fileformat[10], rowdata[256], coltitle[128];
+	char ext[10], rowdata[256], coltitle[128];
 	SQLHSTMT stmt;
 	SQLSMALLINT colcount, collen, datatype;
 	FILE *txt;
 
+	if (ast_strlen_zero(objectname))
+		return -1;
+
 	ast_copy_string(localfile, "/var/tmp/XXXXXX", localfilesize);
 	tempfd = mkstemp(localfile);
 	if (tempfd == -1)
-		return NULL;
+		return -1;
 
 	snprintf(reallocalfile, sizeof(reallocalfile), "%s.txt", localfile);
 	txt = fopen(reallocalfile, "w");
 	if (!txt) {
 		close(tempfd);
 		unlink(localfile);
-		return NULL;
+		return -1;
 	}
 
 	fprintf(txt, "[info]\n");
@@ -260,7 +263,7 @@
 		fclose(txt);
 		close(tempfd);
 		unlink(localfile);
-		return NULL;
+		return -1;
 	}
 
 	res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
@@ -290,7 +293,7 @@
 			goto endget;
 		}
 
-		fileformat[0] = '\0';
+		ext[0] = '\0';
 		for (x = 0; x < colcount; x++) {
 			int fd = -1;
 			SQLULEN colsize;
@@ -312,9 +315,9 @@
 				void *fdm = NULL;
 				SQLLEN colsize2;
 
-				if (!ast_strlen_zero(fileformat)) {
-					/* We have a file format, just go ahead and create the destination */
-					snprintf(reallocalfile, sizeof(reallocalfile), "%s.%s", localfile, fileformat);
+				if (!ast_strlen_zero(ext)) {
+					/* We have an extension, just go ahead and create the destination */
+					snprintf(reallocalfile, sizeof(reallocalfile), "%s.%s", localfile, ext);
 					fd = open(reallocalfile, O_CREAT | O_WRONLY | O_EXCL);
 					if (fd == -1) {
 						ast_log(LOG_ERROR, "Unable to write recording: %s (%d)\n", strerror(errno), errno);
@@ -370,7 +373,7 @@
 					ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
 					goto endget;
 				}
-				if (!strcasecmp(coltitle, "fileformat")) {
+				if (!strcasecmp(coltitle, "extension")) {
 					/* Is there a recording waiting for us? */
 					if (lseek(tempfd, 0, SEEK_CUR) > 0) {
 						snprintf(reallocalfile, sizeof(reallocalfile), "%s.%s", localfile, rowdata);
@@ -378,7 +381,7 @@
 						lseek(tempfd, 0, SEEK_SET);
 						truncate(localfile, 0);
 					} else
-						ast_copy_string(fileformat, rowdata, sizeof(fileformat));
+						ast_copy_string(ext, rowdata, sizeof(ext));
 				} else if (strcasecmp(coltitle, "filename") && strcasecmp(coltitle, "pathname") && !ast_strlen_zero(rowdata) && !gotten)
 					fprintf(txt, "%s=%s\n", coltitle, rowdata);
 			}
@@ -395,10 +398,12 @@
 	/* This is just the temp marker */
 	unlink(localfile);
 
-	return res ? NULL : fl;
-}
-
-static int se_put_odbc(struct ast_storage *st, const char *objectname, const char *fileformats, const char *localfile)
+	st->be->fl = res ? NULL : fl;
+	return res;
+}
+
+#if 0
+static int se_put_odbc(struct ast_storage *st, struct ast_storage_filelist *fl, const char *exts)
 {
 	struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
 	int res = -1, x;
@@ -407,7 +412,7 @@
 	char sql[768], sqlfields[256] = ") VALUES (?,?,?,?";
 	char needlong[10] = "";
 	char pathname[256], *localfile2, reallocalfile[256];
-	char *fileformat;
+	char *ext;
 	SQLHSTMT stmt = NULL;
 	DIR *dir;
 	struct dirent *dirent;
@@ -417,7 +422,7 @@
 	cfg = ast_config_load(reallocalfile);
 	cfgvar = ast_variable_browse(cfg, "info");
 
-	snprintf(sql, sizeof(sql), "INSERT INTO %s (pathname,filename,recording,fileformat", ost->tablename);
+	snprintf(sql, sizeof(sql), "INSERT INTO %s (pathname,filename,recording,extension", ost->tablename);
 
 	for (var = cfgvar; var; var = var->next) {
 		strncat(sql, var->name, sizeof(sql) - 1);
@@ -459,9 +464,9 @@
 		if (strcmp(dirent->d_name, localfile2) != 0)
 			continue;
 
-		if (!(fileformat = strrchr(dirent->d_name, '.')))
+		if (!(ext = strrchr(dirent->d_name, '.')))
 			continue;
-		fileformat++;
+		ext++;
 
 		snprintf(reallocalfile, sizeof(reallocalfile), "%s.%s", pathname, dirent->d_name);
 		fd = open(reallocalfile, O_RDONLY);
@@ -492,7 +497,7 @@
 			SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, 0, 0, (SQLPOINTER)3, 0, &filesize);
 		} else
 			SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, 0, 0, (SQLPOINTER)3, 0, NULL);
-		SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(fileformat), 0, (void *)fileformat, 0, NULL);
+		SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ext), 0, (void *)ext, 0, NULL);
 		for (var = cfgvar, x = 5; var; var = var->next, x++) {
 			SQLBindParameter(stmt, x, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(var->value), 0, (void *)var->value, 0, NULL);
 		}
@@ -529,15 +534,16 @@
 	ast_config_destroy(cfg);
 	return res ? -1 : 0;
 }
-
-static int se_del_odbc(struct ast_storage *st, const char *objectname, const char *fileformats)
+#endif
+
+static int se_del_odbc(struct ast_storage *st, const char *exts)
 {
 	char pathname[256], filename[256], sql[256];
 	struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
 	int res;
 	SQLHSTMT sth;
 
-	get_path_file(ost, objectname, pathname, sizeof(pathname), filename, sizeof(filename));
+	get_path_file(ost, st->be->fl->name, pathname, sizeof(pathname), filename, sizeof(filename));
 
 	snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE pathname=? AND filename=?", ost->tablename);
 
@@ -586,7 +592,7 @@
 static int se_status_odbc(struct ast_storage *st, int fd)
 {
 	struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
-	ast_cli(fd, "Connected: %s\n", (ost->conn && ost->conn->up) ? "yes" : "no");
+	ast_cli(fd, "Connected: %s\n", (ost && ost->conn && ost->conn->up) ? "yes" : "no");
 	return 0;
 }
 
@@ -595,7 +601,9 @@
 	.create = se_create_odbc,
 	.free = se_free_odbc,
 	.get = se_get_odbc,
+#if 0
 	.put = se_put_odbc,
+#endif
 	.del = se_del_odbc,
 	.opendir = se_opendir_odbc,
 	.readdir = se_readdir_odbc,




More information about the svn-commits mailing list