[asterisk-commits] qwell: branch qwell/astse r48036 - in
/team/qwell/astse: include/asterisk/ ma...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Nov 27 08:30:23 MST 2006
Author: qwell
Date: Mon Nov 27 09:30:23 2006
New Revision: 48036
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48036
Log:
Okay, I decided not to wait..
Here are the beginnings of what some people have envisioned as a generic storage engine..
The main reason for this, is to genericize (yes, I said genericize) voicemail,
but it would be useful in many other places as well.
Imagine if you will.. s,1,Playback(imap://tt-weasels)
Added:
team/qwell/astse/include/asterisk/storage.h (with props)
team/qwell/astse/main/storage.c (with props)
team/qwell/astse/res/res_storage_file.c (with props)
Modified:
team/qwell/astse/main/Makefile
team/qwell/astse/main/asterisk.c
Added: team/qwell/astse/include/asterisk/storage.h
URL: http://svn.digium.com/view/asterisk/team/qwell/astse/include/asterisk/storage.h?view=auto&rev=48036
==============================================================================
--- team/qwell/astse/include/asterisk/storage.h (added)
+++ team/qwell/astse/include/asterisk/storage.h Mon Nov 27 09:30:23 2006
@@ -1,0 +1,67 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2006, Digium, Inc.
+ *
+ * Jason Parker <jparker at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ * \brief Generic File Storage Engine Support.
+ *
+ * \author Jason Parker <jparker at digium.com>
+ */
+
+#ifndef _ASTERISK_STORAGE_H
+#define _ASTERISK_STORAGE_H
+
+#include "asterisk/linkedlists.h"
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+struct ast_storage {
+ const char *name;
+ int type;
+ int (*get)(int blah);
+ int (*put)(int blah);
+ int (*delete)(int blah);
+ int (*count)(int blah);
+ int (*parseoptions)(const char *var, const char *value);
+ AST_LIST_ENTRY(ast_storage) list;
+ struct ast_module *module;
+};
+
+#define AST_STORAGE_FILE (1 << 0)
+#define AST_STORAGE_ODBC (1 << 1)
+#define AST_STORAGE_IMAP (1 << 2)
+
+int __ast_register_storage(const struct ast_storage *e, struct ast_module *mod);
+#define ast_register_storage(e) __ast_register_storage(e, ast_module_info->self)
+
+int ast_unregister_storage(const char *name);
+
+int ast_storage_engine_init(void);
+
+int se_get(struct ast_storage *e);
+int se_put(struct ast_storage *e);
+int se_delete(struct ast_storage *e);
+int se_count(struct ast_storage *e);
+int se_parseoptions(struct ast_storage *e, const char *var, const char *value);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* _ASTERISK_STORAGE_H */
Propchange: team/qwell/astse/include/asterisk/storage.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/qwell/astse/include/asterisk/storage.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/qwell/astse/include/asterisk/storage.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/qwell/astse/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/qwell/astse/main/Makefile?view=diff&rev=48036&r1=48035&r2=48036
==============================================================================
--- team/qwell/astse/main/Makefile (original)
+++ team/qwell/astse/main/Makefile Mon Nov 27 09:30:23 2006
@@ -18,7 +18,7 @@
include $(ASTTOPDIR)/Makefile.moddir_rules
OBJS= io.o sched.o logger.o frame.o loader.o config.o channel.o \
- translate.o file.o pbx.o cli.o md5.o term.o \
+ translate.o file.o pbx.o cli.o md5.o term.o storage.o \
ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
Modified: team/qwell/astse/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/qwell/astse/main/asterisk.c?view=diff&rev=48036&r1=48035&r2=48036
==============================================================================
--- team/qwell/astse/main/asterisk.c (original)
+++ team/qwell/astse/main/asterisk.c Mon Nov 27 09:30:23 2006
@@ -114,6 +114,7 @@
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
+#include "asterisk/storage.h"
#include "asterisk/io.h"
#include "asterisk/lock.h"
#include "editline/histedit.h"
@@ -2726,6 +2727,11 @@
exit(1);
}
+ if (ast_storage_engine_init()) {
+ printf(term_quit());
+ exit(1);
+ }
+
if (load_pbx()) {
printf(term_quit());
exit(1);
Added: team/qwell/astse/main/storage.c
URL: http://svn.digium.com/view/asterisk/team/qwell/astse/main/storage.c?view=auto&rev=48036
==============================================================================
--- team/qwell/astse/main/storage.c (added)
+++ team/qwell/astse/main/storage.c Mon Nov 27 09:30:23 2006
@@ -1,0 +1,155 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2006, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Generic File Format Support.
+ *
+ * \author Mark Spencer <markster at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/storage.h"
+#include "asterisk/cli.h"
+#include "asterisk/options.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/module.h"
+
+static AST_LIST_HEAD_STATIC(storage_engines, ast_storage);
+
+int __ast_register_storage(const struct ast_storage *e, struct ast_module *mod)
+{
+ struct ast_storage *tmp;
+
+ if (AST_LIST_LOCK(&storage_engines)) {
+ ast_log(LOG_WARNING, "Unable to lock storage engine list\n");
+ return -1;
+ }
+ AST_LIST_TRAVERSE(&storage_engines, tmp, list) {
+ if (!strcasecmp(e->name, tmp->name)) {
+ AST_LIST_UNLOCK(&storage_engines);
+ ast_log(LOG_WARNING, "Tried to register storage engine '%s', already registered\n", e->name);
+ return -1;
+ }
+ }
+ if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
+ AST_LIST_UNLOCK(&storage_engines);
+ return -1;
+ }
+ *tmp = *e;
+ tmp->module = mod;
+
+ memset(&tmp->list, 0, sizeof(tmp->list));
+
+ AST_LIST_INSERT_HEAD(&storage_engines, tmp, list);
+ AST_LIST_UNLOCK(&storage_engines);
+ if (option_verbose > 1)
+ ast_verbose(VERBOSE_PREFIX_2 "Registered storage engine '%s'\n", e->name);
+
+ return 0;
+}
+
+int ast_unregister_storage(const char *name)
+{
+ struct ast_storage *tmp;
+ int res = -1;
+
+ if (AST_LIST_LOCK(&storage_engines)) {
+ ast_log(LOG_WARNING, "Unable to lock storage engine list\n");
+ return -1;
+ }
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&storage_engines, tmp, list) {
+ if (!strcasecmp(name, tmp->name)) {
+ AST_LIST_REMOVE_CURRENT(&storage_engines, list);
+ free(tmp);
+ res = 0;
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END
+ AST_LIST_UNLOCK(&storage_engines);
+
+ if (!res) {
+ if (option_verbose > 1)
+ ast_verbose(VERBOSE_PREFIX_2 "Unregistered storage engine '%s'\n", name);
+ } else
+ ast_log(LOG_WARNING, "Tried to unregister storage engine '%s', already unregistered\n", name);
+
+ return res;
+}
+
+int ast_se_get(struct ast_storage *e) {
+ return e->get(0);
+}
+
+int ast_se_put(struct ast_storage *e) {
+ return e->put(0);
+}
+
+int ast_se_delete(struct ast_storage *e) {
+ return e->delete(0);
+}
+
+int ast_se_count(struct ast_storage *e) {
+ return e->count(0);
+}
+
+int ast_se_parseoptions(struct ast_storage *e, const char *var, const char *value) {
+ return e->parseoptions(var, value);
+}
+
+static int show_storage_engines(int fd, int argc, char *argv[])
+{
+ struct ast_storage *e;
+ int count_se = 0;
+
+ if (argc != 4)
+ return RESULT_SHOWUSAGE;
+ ast_cli(fd, "Storage Engine\n");
+
+ if (AST_LIST_LOCK(&storage_engines)) {
+ ast_log(LOG_WARNING, "Unable to lock storage engine list\n");
+ return -1;
+ }
+
+ AST_LIST_TRAVERSE(&storage_engines, e, list) {
+ ast_cli(fd, "%s\n", e->name);
+ count_se++;
+ }
+ AST_LIST_UNLOCK(&storage_engines);
+ ast_cli(fd, "%d storage engines registered.\n", count_se);
+ return RESULT_SUCCESS;
+}
+
+char show_storage_engines_usage[] =
+"Usage: core show storage engines\n"
+" Displays currently registered storage engines (if any)\n";
+
+struct ast_cli_entry cli_storage[] = {
+ { { "core", "show", "storage", "engines" },
+ show_storage_engines, "Displays storage engines",
+ show_storage_engines_usage },
+};
+
+int ast_storage_engine_init(void)
+{
+ ast_cli_register_multiple(cli_storage, sizeof(cli_storage) / sizeof(struct ast_cli_entry));
+ return 0;
+}
Propchange: team/qwell/astse/main/storage.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/qwell/astse/main/storage.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/qwell/astse/main/storage.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/qwell/astse/res/res_storage_file.c
URL: http://svn.digium.com/view/asterisk/team/qwell/astse/res/res_storage_file.c?view=auto&rev=48036
==============================================================================
--- team/qwell/astse/res/res_storage_file.c (added)
+++ team/qwell/astse/res/res_storage_file.c Mon Nov 27 09:30:23 2006
@@ -1,0 +1,73 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2006, Digium, Inc.
+ *
+ * Jason Parker <jparker at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Files based storage engine
+ * \author Jason Parker <jparker at digium.com>
+ * \ingroup res
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/storage.h"
+#include "asterisk/module.h"
+
+static int se_get_file(int blah) {
+ return 0;
+}
+
+static int se_put_file(int blah) {
+ return 0;
+}
+
+static int se_delete_file(int blah) {
+ return 0;
+}
+
+static int se_count_file(int blah) {
+ return 0;
+}
+
+static int se_parseoptions_file(int blah) {
+ return 0;
+}
+
+static const struct ast_storage file_se = {
+ .name = "file",
+ .type = AST_STORAGE_FILE,
+ .get = se_get_file,
+ .put = se_put_file,
+ .delete = se_delete_file,
+ .count = se_count_file,
+ .parseoptions = se_parseoptions_file,
+};
+
+static int load_module(void)
+{
+ return ast_register_storage(&file_se);
+}
+
+static int unload_module(void)
+{
+ return ast_unregister_storage(file_se.name);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Files based storage engine");
Propchange: team/qwell/astse/res/res_storage_file.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/qwell/astse/res/res_storage_file.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/qwell/astse/res/res_storage_file.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list