[asterisk-commits] mjordan: branch mjordan/voicemail_refactor_11_10_19 r342768 - in /team/mjorda...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 31 10:37:34 CDT 2011


Author: mjordan
Date: Mon Oct 31 10:37:28 2011
New Revision: 342768

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342768
Log:
Merged new resource modules in

Added:
    team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h   (with props)
    team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c   (with props)
    team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c   (with props)
    team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c   (with props)
Modified:
    team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h
    team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c

Modified: team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h?view=diff&rev=342768&r1=342767&r2=342768
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h (original)
+++ team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h Mon Oct 31 10:37:28 2011
@@ -241,6 +241,8 @@
  */
 int vm_load_config(int reload);
 
+void vm_initialize(void);
+
 struct ast_vm_user *vm_get_user(const char *context, const char *mailbox);
 
 struct vm_timezone *vm_get_timezone(const char *timezone);

Modified: team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c?view=diff&rev=342768&r1=342767&r2=342768
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c (original)
+++ team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c Mon Oct 31 10:37:28 2011
@@ -1954,7 +1954,6 @@
 	return result;
 }
 
-
 void vm_register_config_tests(void)
 {
 	AST_TEST_REGISTER(test_vm_default_config);

Added: team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h?view=auto&rev=342768
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h (added)
+++ team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h Mon Oct 31 10:37:28 2011
@@ -1,0 +1,27 @@
+/*
+ * message_storage.h
+ *
+ *  Created on: Oct 30, 2011
+ *      Author: mjordan
+ */
+
+#ifndef MESSAGE_STORAGE_H_
+#define MESSAGE_STORAGE_H_
+
+struct ast_msg_storage_tech {
+	const char * const name;
+
+	int (* const load_config)(struct ast_config *cfg, int reload);
+
+	/* store message */
+
+	/* delete message */
+
+	/* retrieve message */
+};
+
+void ast_register_message_storage_tech(struct ast_msg_storage_tech *ms_tech);
+
+struct ast_msg_storage_tech *ast_get_message_storage_tech(const char * const name);
+
+#endif /* MESSAGE_STORAGE_H_ */

Propchange: team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c?view=auto&rev=342768
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c (added)
+++ team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c Mon Oct 31 10:37:28 2011
@@ -1,0 +1,133 @@
+
+#include "asterisk.h"
+#include "asterisk/module.h"
+#include "asterisk/message_storage.h"
+
+#define VOICEMAIL_CONFIG "voicemail.conf"
+#define USERS_CONFIG "users.conf"
+
+struct imap_config {
+	int expunge_on_hangup:1;
+	int imap_greetings:1;
+	char delimiter;
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(server);
+		AST_STRING_FIELD(port);
+		AST_STRING_FIELD(flags);
+		AST_STRING_FIELD(folder);
+		AST_STRING_FIELD(parent_folder);
+		AST_STRING_FIELD(greeting_folder);
+		AST_STRING_FIELD(auth_user);
+		AST_STRING_FIELD(auth_password);
+	);
+};
+
+struct imap_user {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(user);               /*!< IMAP server login */
+		AST_STRING_FIELD(password);           /*!< IMAP server password if authpassword not defined */
+		AST_STRING_FIELD(default_folder);     /*!< IMAP voicemail folder */
+		AST_STRING_FIELD(shared_id);          /*!< Shared mailbox ID to use rather than the dialed one */
+	);
+};
+
+static const char default_delimiter = '\0';
+
+static struct imap_config *config;
+
+static struct ao2_container *imap_users;
+
+static struct ast_msg_storage_tech imap_message_storage_tech = {
+		.name = "IMAP",
+		.load_config = imap_load_config,
+};
+
+static int imap_load_config(struct ast_config *cfg, int reload)
+{
+
+	/* lock something */
+	return 0;
+}
+
+static int imap_load_users(struct ast_config *ucfg, int reload)
+{
+	return 0;
+}
+
+static int load_configs(int reload)
+{
+	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+	struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+	struct ast_config *ucfg = ast_config_load(USERS_CONFIG, config_flags);
+
+	/* If both configs are unchanged exit; otherwise load both */
+	if (cfg == CONFIG_STATUS_FILEUNCHANGED && ucfg == CONFIG_STATUS_FILEUNCHANGED) {
+		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED && ucfg != CONFIG_STATUS_FILEUNCHANGED) {
+		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
+		cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+	} else if (cfg != CONFIG_STATUS_FILEUNCHANGED && ucfg == CONFIG_STATUS_FILEUNCHANGED) {
+		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
+		ucfg = ast_config_load(USER_CONFIG, config_flags);
+	}
+
+	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
+		if (ucfg && ucfg != CONFIG_STATUS_FILEINVALID) {
+			ast_config_destroy(ucfg);
+		}
+		ast_log(AST_LOG_ERROR, "Config file " VOICEMAIL_CONFIG " is in an invalid format.  Aborting.\n");
+		return 1;
+	}
+
+	if (ucfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(AST_LOG_WARNING, "Config file " USER_CONFIG " is in an invalid format.  Avoiding.\n");
+		ucfg = NULL;
+	}
+
+	imap_load_config(cfg, reload);
+
+	imap_load_users(cfg, reload);
+	if (ucfg) {
+		imap_load_users(ucfg, reload);
+	}
+}
+
+static int reload(void)
+{
+	int res = 0;
+
+	res |= load_configs(1);
+
+	return res;
+}
+
+/* If I were to allow unloading it would look something like this */
+static int unload_module(void)
+{
+	return 0;
+}
+
+static int load_module(void)
+{
+	if (!(imap_users = ao2_container_alloc())) {
+		ast_log(LOG_ERROR, "Unable to allocate IMAP users container\n");
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (load_configs(0)) {
+		ao2_ref(imap_users, -1);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	ast_register_message_storage_tech(&imap_message_storage_tech);
+
+	return res;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Asterisk Message Storage for IMAP",
+	.load = load_module,
+	.unload = unload_module,
+	.reload = reload,
+	.load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
+);
+

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c?view=auto&rev=342768
==============================================================================
    (empty)

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_odbc.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c?view=auto&rev=342768
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c (added)
+++ team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c Mon Oct 31 10:37:28 2011
@@ -1,0 +1,99 @@
+/*
+ * res_message_storage.c
+ *
+ *  Created on: Oct 30, 2011
+ *      Author: mjordan
+ */
+
+#include "asterisk.h"
+#include "asterisk/module.h"
+#include "asterisk/message_storage.h"
+
+static struct ao2_container *msg_storage_techs;
+
+#define MSG_STORAGE_TECH_BUCKETS 19
+
+void ast_register_message_storage_tech(struct ast_msg_storage_tech *ms_tech)
+{
+	struct ao2_iterator it_techs;
+	struct ast_msg_storage_tech *tech_current = NULL;
+
+	if (!ms_tech) {
+		return;
+	}
+
+	/* Don't add the tech if its already been added */
+	ao2_lock(msg_storage_techs);
+	it_techs = ao2_iterator_init(msg_storage_techs, 0);
+	while ((tech_current = ao2_iterator_next(&it_techs))) {
+		if (!strncmp(ms_tech->name, tech_current->name, sizeof(ms_tech->name))) {
+			ao2_ref(tech_current, -1);
+			ao2_iterator_destroy(&it_techs);
+			ao2_unlock(msg_storage_techs);
+			return;
+		}
+		ao2_ref(tech_current, -1);
+	}
+	ao2_iterator_destroy(&it_techs);
+	ao2_unlock(msg_storage_techs);
+
+	ao2_link(msg_storage_techs, ms_tech);
+}
+
+struct ast_msg_storage_tech *ast_get_message_storage_tech(const char * const name)
+{
+	struct ast_msg_storage_tech tech_temp = { .name = name, };
+	struct ast_msg_storage_tech *ms_tech;
+
+	ms_tech = ao2_find(msg_storage_techs, tech_temp, OBJ_POINTER);
+
+	return ms_tech;
+}
+
+static int message_storage_hash_fn(const void *obj, const int flags)
+{
+	const struct ast_message_storage_tech *ms_tech = obj;
+	return ast_str_case_hash(ms_tech->name);
+}
+
+static int message_storage_cmp_fn(void *obj, void *arg, int flags)
+{
+	const struct ast_message_storage_tech *ms_tech_left = obj;
+	const struct ast_message_storage_tech *ms_tech_right = arg;
+	return !strcasecmp(ms_tech_left->name, ms_tech_right->name) ? CMP_MATCH | CMP_STOP: 0;
+}
+
+static int reload(void)
+{
+	/* Not sure about this yet */
+	return 0;
+}
+
+/* If I were to allow unloading it would look something like this */
+static int unload_module(void)
+{
+	ao2_ref(msg_storage_techs, -1);
+	return 0;
+}
+
+static int load_module(void)
+{
+	if (!(msg_storage_techs = ao2_container_alloc(MSG_STORAGE_TECH_BUCKETS, message_storage_hash_fn, message_storage_cmp_fn))) {
+		ast_log(LOG_ERROR, "Unable to allocate message storage technology container\n");
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	/* Since other modules depend on this, disable unloading */
+	/* TODO: not sure about this either, since it is sort of a memory leak */
+	ast_module_ref(ast_module_info->self);
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Asterisk Message Storage API",
+	.load = load_module,
+	.unload = unload_module,
+	.reload = reload,
+	.load_pri = AST_MODPRI_APP_DEPEND,
+);
+

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/voicemail_refactor_11_10_19/res/res_message_storage.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list