[asterisk-commits] ivaxer: branch ivaxer/ast_storage r280775 - in /team/ivaxer/ast_storage: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 3 14:43:59 CDT 2010
Author: ivaxer
Date: Tue Aug 3 14:43:55 2010
New Revision: 280775
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=280775
Log:
implemented the del() function
Modified:
team/ivaxer/ast_storage/include/asterisk/storage.h
team/ivaxer/ast_storage/main/storage.c
team/ivaxer/ast_storage/res/res_storage_odbc.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=280775&r1=280774&r2=280775
==============================================================================
--- team/ivaxer/ast_storage/include/asterisk/storage.h (original)
+++ team/ivaxer/ast_storage/include/asterisk/storage.h Tue Aug 3 14:43:55 2010
@@ -59,7 +59,7 @@
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, struct ast_storage_fileobject *fo, const char *exts);
- int (*del)(struct ast_storage *st, struct ast_storage_fileobject *fo);
+ int (*del)(struct ast_storage *st, const char *fileobject);
ssize_t (*read)(struct ast_storage *st, struct ast_storage_fileinst *fi, void *buf, size_t count);
ssize_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);
@@ -110,9 +110,9 @@
/*! \brief Removes a file from the storage medium
* \param st Storage instance
- * \param fo File object to delete
+ * \param fileobject Logical name of the file to delete
*/
-int ast_storage_del(struct ast_storage *st, struct ast_storage_fileobject *fo);
+int ast_storage_del(struct ast_storage *st, const char *fileobject);
int ast_storage_copy(struct ast_storage *st, const char *from, const char *to);
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=280775&r1=280774&r2=280775
==============================================================================
--- team/ivaxer/ast_storage/main/storage.c (original)
+++ team/ivaxer/ast_storage/main/storage.c Tue Aug 3 14:43:55 2010
@@ -190,9 +190,9 @@
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_del(struct ast_storage *st, const char *fileobject)
+{
+ return st && st->be->del ? st->be->del(st, fileobject) : -1;
}
int ast_storage_copy(struct ast_storage *st, const char *from, const char *to)
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=280775&r1=280774&r2=280775
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Tue Aug 3 14:43:55 2010
@@ -86,6 +86,12 @@
SQLLEN metadata_ind;
};
+struct del_query_data {
+ const char *sql;
+ const char *pathname;
+ const char *objectname;
+};
+
static const struct ast_storage_be odbc_se;
static int se_release(struct ast_storage *st)
@@ -582,9 +588,60 @@
return putret;
}
-static int se_del(struct ast_storage *st, struct ast_storage_fileobject *fo)
-{
- return -1;
+static SQLHSTMT prepare_del_query(struct odbc_obj *obj, void *arg)
+{
+ SQLHSTMT stmt;
+ SQLRETURN ret;
+ struct del_query_data *qdata = (struct del_query_data *) arg;
+
+ ret = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
+ if (!SQL_SUCCEEDED(ret)) {
+ ast_log(LOG_WARNING, "SQL Alloc Handle failed!");
+ return NULL;
+ }
+
+ ret = SQLPrepare(stmt, (SQLCHAR *)qdata->sql, SQL_NTS);
+ if (!SQL_SUCCEEDED(ret)) {
+ ast_log(LOG_WARNING, "SQL Prepare failed!\n[%s]", qdata->sql);
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ return NULL;
+ }
+
+ SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
+ SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
+
+ return stmt;
+}
+
+static int se_del(struct ast_storage *st, const char *objectname)
+{
+ struct odbc_storage_pvt *ost = (struct odbc_storage_pvt*) st->storage_pvt;
+ struct del_query_data qdata;
+ char *pathname;
+ char sql[128];
+ SQLHSTMT stmt;
+
+ if (!objectname) {
+ ast_log(LOG_WARNING, "fileobject is null!\n");
+ return -1;
+ }
+
+ pathname = ost->pathname;
+
+ snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE pathname=? AND filename=?", ost->tablename);
+
+ qdata.sql = sql;
+ qdata.pathname = pathname;
+ qdata.objectname = objectname;
+
+ stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_del_query, (void *) &qdata);
+ if (!stmt) {
+ ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
+ return -1;
+ }
+
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ return 0;
}
static struct ast_storage_dirobject *se_listdir(struct ast_storage *st, const char *pathname)
@@ -809,6 +866,47 @@
return AST_TEST_PASS;
}
+
+AST_TEST_DEFINE(del_test)
+{
+ struct ast_storage *st;
+ int ret;
+ const char uri[] = "asterisk-storage-test/storage/testpath";
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "del_test";
+ info->category = "main/storage/odbc";
+ info->summary = "del test";
+ info->description =
+ "Tests the del functions";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ st = se_create(uri);
+ if (!st) {
+ return AST_TEST_FAIL;
+ }
+
+ ret = se_del(st, "del_test");
+
+ if (ret) {
+ ast_test_status_update(test, "put() failed\n");
+ return AST_TEST_FAIL;
+ }
+
+ /* TODO: add checks here */
+
+ ret = se_release(st);
+ if (ret) {
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
#endif
static int load_module(void)
@@ -817,6 +915,7 @@
AST_TEST_REGISTER(creation_test);
AST_TEST_REGISTER(get_test);
AST_TEST_REGISTER(put_test);
+ AST_TEST_REGISTER(del_test);
#endif
return ast_register_storage(&odbc_se);
}
@@ -827,6 +926,7 @@
AST_TEST_UNREGISTER(creation_test);
AST_TEST_UNREGISTER(get_test);
AST_TEST_UNREGISTER(put_test);
+ AST_TEST_UNREGISTER(del_test);
#endif
return ast_unregister_storage(odbc_se.name);
}
More information about the asterisk-commits
mailing list