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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 11 15:17:22 CDT 2010


Author: ivaxer
Date: Wed Aug 11 15:17:17 2010
New Revision: 281868

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281868
Log:
fixes due the review #773 (r5)
- fixed missed braces
- start work on documentation
- ast_storage_engine_init moved to _private.h
- removed old code
- fixed copyrights
- fixed file descriptor leak in open_fileinst() of odbc
- code guidelines fixes.

Modified:
    team/ivaxer/ast_storage/include/asterisk/_private.h
    team/ivaxer/ast_storage/include/asterisk/storage.h
    team/ivaxer/ast_storage/main/file.c
    team/ivaxer/ast_storage/main/storage.c
    team/ivaxer/ast_storage/res/res_storage_odbc.c

Modified: team/ivaxer/ast_storage/include/asterisk/_private.h
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/include/asterisk/_private.h?view=diff&rev=281868&r1=281867&r2=281868
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/_private.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/_private.h Wed Aug 11 15:17:17 2010
@@ -47,6 +47,7 @@
 int ast_cel_engine_reload(void);	/*!< Provided by cel.c */
 int ast_ssl_init(void);                 /*!< Provided by ssl.c */
 int ast_test_init(void);            /*!< Provided by test.c */
+int ast_storage_engine_init(void);	/*!< Provided by storage.c */
 
 /*!
  * \brief Reload asterisk modules.

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=281868&r1=281867&r2=281868
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/storage.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/storage.h Wed Aug 11 15:17:17 2010
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2010, Digium, Inc.
  *
- * Jason Parker <jparker at digium.com>
+ * John Khvatov <ivaxer at gmail.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -19,7 +19,6 @@
 /*! \file
  * \brief Generic File Storage Engine Support.
  *
- * \author Jason Parker <jparker at digium.com>
  * \author John Khvatov <ivaxer at gmail.com>
  */
 
@@ -73,34 +72,48 @@
 	void *storage_pvt; /* Backend specific structure */
 };
 
+/*! \brief Register a storage backenda
+ * \retval Returns 1 on success or 0 on failure
+ */
 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)
 
+/*! \brief Unregister a storage backend
+ * \param name Storage backend name
+ * \retval Returns 1 on success or 0 on failure
+ */
 int ast_unregister_storage(const char *name);
 
-int ast_storage_engine_init(void);
-
-/*! \brief Retrieves an instance of a storage method
+/*! \brief Retrieves an instance of a storage engine
  * \param uri Backend specific URI to the resource
+ * \retval NULL on faulure
+ * \retval non-NULL successfully created storage instance
  */
 struct ast_storage *ast_storage_request(const char *uri);
 
 /*! \brief Releases a storage instance created with ast_storage_request
+ * \param st Storage instance
+ * \retval Returns 1 on success or 0 on failure
  */
 int ast_storage_release(struct ast_storage *st);
 
 /*! \brief Retrieves a file from the storage medium
  * \param st Storage instance
  * \param objectname Logical name of the file
- * \param exts File extensions to retrieve
+ * \param exts File extensions to retrieve (separated by | character)
+ * \retval NULL on faulure
+ * \retval non-NULL successfully retrieved fileobject
  */
 struct ast_storage_fileobject *ast_storage_get(struct ast_storage *st, const char *objectname, const char *exts);
 
 /*! \brief Stores a file into the storage medium
  * \param st Storage instance
  * \param fo File object to store
+ * \param exts File extensions to store (separated by '|' character)
+ * \retval Returns 1 on success or 0 on failure
  */
 int ast_storage_put(struct ast_storage *st, struct ast_storage_fileobject *fo, const char *exts);
+
 
 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);
@@ -108,6 +121,7 @@
 /*! \brief Removes a file from the storage medium
  * \param st Storage instance
  * \param fileobject Logical name of the file to delete
+ * \retval Returns 1 on success or 0 on failure
  */
 int ast_storage_del(struct ast_storage *st, const char *fileobject);
 
@@ -116,6 +130,8 @@
 /*! \brief Starts retrieval of objects in a resource path
  * \param st Storage instance
  * \param pathname Logical name of the path
+ * \retval NULL on failure
+ * \retval non-NULL pointer to head of fileobjects list
  */
 struct ast_storage_fileobjects *ast_storage_listdir(struct ast_storage *st, const char *pathname);
 
@@ -136,15 +152,10 @@
 
 /*! \brief Get storage engine by name
  * \param name Name of storage engine
+ * \retval NULL on failure
+ * \retval non-NULL pointer to storage engine instance
  */
 struct ast_storage_be *ast_storage_getbyname(const char *name);
-
-/*! \brief Specify a backend specific parameter
- * \param st Storage instance
- * \param var Parameter name
- * \param value Parameter value
- */
-int ast_storage_parseoptions(struct ast_storage *st, const char *var, const char *value);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/ivaxer/ast_storage/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/main/file.c?view=diff&rev=281868&r1=281867&r2=281868
==============================================================================
--- team/ivaxer/ast_storage/main/file.c (original)
+++ team/ivaxer/ast_storage/main/file.c Wed Aug 11 15:17:17 2010
@@ -1009,8 +1009,9 @@
 
 	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		fs = NULL;
-		if (!ast_exts_compare(f->exts, type))
+		if (!ast_exts_compare(f->exts, type)) {
 			continue;
+		}
 		else {
 			format_found = 1;
 		}
@@ -1062,7 +1063,7 @@
 
 	/* set the O_TRUNC flag if and only if there is no O_APPEND specified */
 	/* We really can't use O_APPEND as it will break WAV header updates */
-	if (flags & O_APPEND) { 
+	if (flags & O_APPEND) {
 		flags &= ~O_APPEND;
 	} else {
 		myflags = O_TRUNC;
@@ -1075,13 +1076,16 @@
 	 */
 	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		char *fn, *orig_fn = NULL;
-		if (fs)
+		if (fs) {
 			break;
-
-		if (!ast_exts_compare(f->exts, type))
+		}
+
+		if (!ast_exts_compare(f->exts, type)) {
 			continue;
-		else
+		}
+		else {
 			format_found = 1;
+		}
 
 		fn = build_filename(filename, type);
 		fd = open(fn, flags | myflags, mode);

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=281868&r1=281867&r2=281868
==============================================================================
--- team/ivaxer/ast_storage/main/storage.c (original)
+++ team/ivaxer/ast_storage/main/storage.c Wed Aug 11 15:17:17 2010
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2010, Digium, Inc.
  *
- * Mark Spencer <markster at digium.com>
+ * John Khvatov <ivaxer at gmail.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -20,7 +20,6 @@
  *
  * \brief Generic File Storage Engine Support.
  *
- * \author Mark Spencer <markster at digium.com>uh
  * \author John Khvatov <ivaxer at gmail.com>
  */
 
@@ -28,6 +27,7 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include "asterisk/_private.h"
 #include "asterisk/storage.h"
 #include "asterisk/cli.h"
 #include "asterisk/file.h"
@@ -50,7 +50,7 @@
 	AST_RWLIST_TRAVERSE(&storage_engines, tmp, list) {
 		if (!strcasecmp(be->name, tmp->name)) {
 			AST_RWLIST_UNLOCK(&storage_engines);
-			ast_log(LOG_WARNING, "Tried to register storage engine '%s', already registered\n", be->name);
+			ast_log(LOG_WARNING, "Tried to register storage engine '%s', not found in list (was it already unregistered?)\n", be->name);
 			return -1;
 		}
 	}
@@ -60,8 +60,6 @@
 	}
 	*tmp = *be;
 	tmp->module = mod;
-
-	memset(&tmp->list, 0, sizeof(tmp->list));
 
 	AST_RWLIST_INSERT_TAIL(&storage_engines, tmp, list);
 	AST_RWLIST_UNLOCK(&storage_engines);
@@ -169,7 +167,7 @@
 {
 	int ret = -1;
 
-	if(!fi) {
+	if (!fi) {
 		return -1;
 	}
 
@@ -249,11 +247,9 @@
 		ast_storage_fileinst_release(fo->metadata);
 	}
 
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&fo->files, inst, list) {
-		AST_RWLIST_REMOVE_CURRENT(list);
+	while ((inst = AST_RWLIST_REMOVE_HEAD(&fo->files, list))) {
 		ast_storage_fileinst_release(inst);
 	}
-	AST_RWLIST_TRAVERSE_SAFE_END
 
 	ast_free(fo);
 }
@@ -261,7 +257,7 @@
 struct ast_storage_fileinst *ast_storage_fileinst_create(void)
 {
 	struct ast_storage_fileinst *fi = ast_calloc(1, sizeof(*fi));
-	if(!fi) {
+	if (!fi) {
 		return NULL;
 	}
 
@@ -279,7 +275,7 @@
 		ast_storage_close(fi);
 	}
 
-	if(fi->temporary && fi->localfile[0]) {
+	if (fi->temporary && fi->localfile[0]) {
 		unlink(fi->localfile);
 	}
 
@@ -289,7 +285,7 @@
 struct ast_storage_fileobjects *ast_storage_fileobjects_create(void)
 {
 	struct ast_storage_fileobjects *fobjs = ast_calloc(1, sizeof(*fobjs));
-	if(!fobjs) {
+	if (!fobjs) {
 		return NULL;
 	}
 

Modified: team/ivaxer/ast_storage/res/res_storage_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/res/res_storage_odbc.c?view=diff&rev=281868&r1=281867&r2=281868
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Wed Aug 11 15:17:17 2010
@@ -360,7 +360,7 @@
 		qdata.ext = NULL;
 	}
 
-	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_get_query, (void *) &qdata);
+	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_get_query, &qdata);
 	if (!stmt) {
 		ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
 		return NULL;
@@ -448,6 +448,7 @@
 	local_fdm = mmap(NULL, local_fdlen, PROT_READ, MAP_SHARED, local_fd, 0);
 	if (local_fdm == MAP_FAILED) {
 		ast_log(LOG_WARNING, "Unable to map file '%s': [%d]: %s\n", fi->localfile, errno, strerror(errno));
+		close(local_fd);
 		return -1;
 	}
 
@@ -528,7 +529,7 @@
 		qdata.metadata_len = qdata.metadata_ind = mfdlen;
 	}
 
-	stmt = ast_odbc_direct_execute(ost->conn, execute_put_query, (void *) &qdata);
+	stmt = ast_odbc_direct_execute(ost->conn, execute_put_query, &qdata);
 	if (!stmt) {
 		ast_log(LOG_WARNING, "SQL Execute failed!\n");
 		goto error;
@@ -539,7 +540,7 @@
 	if (stmt) {
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 	}
-	if(fdm) {
+	if (fdm) {
 		munmap(fdm, fdlen);
 		close(fd);
 	}
@@ -598,7 +599,7 @@
 	qdata.pathname = pathname;
 	qdata.objectname = objectname;
 
-	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_del_query, (void *) &qdata);
+	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_del_query, &qdata);
 	if (!stmt) {
 		ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
 		return -1;
@@ -713,7 +714,7 @@
 	qdata.sql = sql;
 	qdata.pathname = pathname;
 
-	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_listdir_query, (void *) &qdata);
+	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_listdir_query, &qdata);
 	if (!stmt) {
 		ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
 		return NULL;
@@ -747,7 +748,7 @@
 		return -1;
 	}
 
-	if(fi->fd == -1) {
+	if (fi->fd == -1) {
 		ast_log(LOG_WARNING, "read() failed: fileinst is closed");
 		return -1;
 	}
@@ -762,7 +763,7 @@
 		return -1;
 	}
 
-	if(fi->fd == -1) {
+	if (fi->fd == -1) {
 		ast_log(LOG_WARNING, "write() failed: fileinst is closed");
 		return -1;
 	}
@@ -776,7 +777,7 @@
 		return -1;
 	}
 
-	if(fi->fd == -1) {
+	if (fi->fd == -1) {
 		ast_log(LOG_WARNING, "write() failed: fileinst is closed");
 		return -1;
 	}
@@ -790,7 +791,7 @@
 		return -1;
 	}
 
-	if(fi->fd == -1) {
+	if (fi->fd == -1) {
 		ast_log(LOG_WARNING, "write() failed: fileinst is closed");
 		return -1;
 	}
@@ -845,7 +846,7 @@
 	qdata.from_objectname = from;
 	qdata.to_objectname = to;
 
-	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_copy_query, (void *) &qdata);
+	stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_copy_query, &qdata);
 	if (!stmt) {
 		ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
 		return -1;




More information about the asterisk-commits mailing list