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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 6 16:49:32 CST 2012


Author: mjordan
Date: Fri Jan  6 16:49:29 2012
New Revision: 349967

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=349967
Log:
Put some stuff in message_storage

Modified:
    team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h
    team/mjordan/voicemail_refactor_11_10_19/main/message_storage.c

Modified: 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=diff&rev=349967&r1=349966&r2=349967
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h (original)
+++ team/mjordan/voicemail_refactor_11_10_19/include/asterisk/message_storage.h Fri Jan  6 16:49:29 2012
@@ -8,10 +8,16 @@
 #ifndef MESSAGE_STORAGE_H_
 #define MESSAGE_STORAGE_H_
 
-struct mailbox_pvt;
+/*! \internal \brief Context that contains default settings */
+#define DEFAULT_MSG_SETTINGS_CONTEXT "general"
+
+/*! \internal \brief Context that contains timezone information; skipped for mailboxes */
+#define DEFAULT_MSG_TIMEZONE_CONTEXT "zonemessages"
 
 struct ast_msg_config {
 	char type_name[32];
+	const struct ast_msg_storage_tech * const msg_tech;
+	void *pvt;
 	unsigned int max_deleted_messages;
 	unsigned int max_messages;
 	char format[MAX_FORMAT_LENGTH];
@@ -25,18 +31,34 @@
 };
 
 struct ast_msg_mailbox {
-	const struct mailbox_pvt *pvt;
 	char type_name[32];
+	void *pvt;							/*!< Pointer to private data for specific mailbox types */
 	char context[AST_MAX_CONTEXT];		/*!< Mailbox context */
 	char mailbox[AST_MAX_EXTENSION];	/*!< Mailbox id, unique within a context */
-	char language[MAX_LANGUAGE];		/*!< Config: Language setting */
+	char language[MAX_LANGUAGE];		/*!< Default mailbox language setting */
 	int max_messages;					/*!< Maximum number of msgs per folder for this mailbox */
 	int max_deleted_messages;			/*!< Maximum number of deleted msgs saved for this mailbox */
 	int hash_key;
 	struct ast_flags flags;				/*!< general flags applicable to the mailbox */
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(fullname);					/*!< IMAP server login */
+		AST_STRING_FIELD(password);				/*!< IMAP server password if auth_password not defined */
+		AST_STRING_FIELD(email_address);		/*!< IMAP message folder */
+		AST_STRING_FIELD(pager_address);
+	);
 };
 
+int ast_msg_storage_add_mailbox(struct ast_msg_mailbox *mbox);
 
+int ast_msg_storage_add_mailboxes(struct ao2_iterator *it_mbox);
+
+struct ast_msg_mailbox *ast_msg_storage_get_mailbox(const char * const context, const char * const mailbox);
+
+struct ast_msg_mailbox *ast_msg_storage_create_mailbox_from_context(const char * const context, const char * const mailbox, struct ast_config *mcfg);
+
+struct ast_msg_mailbox *ast_msg_storage_create_mailbox_from_variable(const char * const context, const char * const mailbox, struct ast_variable *var);
+
+void ast_msg_storage_clear_mailboxes(void);
 
 struct ast_msg_storage_tech {
 
@@ -44,11 +66,10 @@
 
 	int (* const load_config)(struct ast_config *cfg, int reload);
 
-	int (* const load_mailboxes)(struct ast_config *mcfg, int reload, int by_variable);
+	int (* const load_mailbox)(struct ast_config *mcfg, int by_variable, struct ast_msg_mailbox *mbox);
 
 	struct ast_msg_config *(* const get_config)(void);
 
-	struct ast_msg_mailbox *(* const get_mailbox)(const char * const context, const char * const mailbox);
 
 	/* store message */
 	/* delete message */

Modified: team/mjordan/voicemail_refactor_11_10_19/main/message_storage.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/main/message_storage.c?view=diff&rev=349967&r1=349966&r2=349967
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/main/message_storage.c (original)
+++ team/mjordan/voicemail_refactor_11_10_19/main/message_storage.c Fri Jan  6 16:49:29 2012
@@ -10,7 +10,193 @@
 
 static struct ao2_container *msg_storage_techs;
 
+static struct ao2_container *mailboxes;
+
 #define MSG_STORAGE_TECH_BUCKETS 19
+
+#define MAILBOX_BUCKETS 19
+
+static int mailbox_hash_fn(const void *obj, const int flags)
+{
+	const struct ast_msg_mailbox *mbox = obj;
+	return mbox->hash_key;
+}
+
+static int mailbox_cmp_fn(void *obj, void *arg, int flags)
+{
+	const struct ast_msg_mailbox *left = obj;
+	const struct ast_msg_mailbox *right = arg;
+	return (left->hash_key == right->hash_key) ? CMP_MATCH | CMP_STOP: 0;
+}
+
+static ast_msg_mailbox *create_mailbox(const char * const context, const char * const mailbox)
+{
+	struct ast_msg_mailbox *mbox;
+	char unique_name[AST_MAX_CONTEXT + AST_MAX_EXTEN + 1];
+
+	if ((mbox = ao2_alloc(sizeof(*mbox), destroy_mailbox))) {
+		if (ast_string_field_init(mbox, 256)) {
+			ao2_ref(mbox, -1);
+			mbox = NULL;
+		}
+
+		strcpy(mbox->type_name, "UNKNOWN");
+		ast_copy_string(mbox->context, context, sizeof(mbox->context));
+		ast_copy_string(mbox->mailbox, mailbox, sizeof(mbox->mailbox));
+		strcpy(unique_name, mbox->context);
+		strcat(unique_name, mbox->mailbox);
+		mbox->hash_key = ast_str_case_hash(unique_name);
+	}
+
+	return mbox;
+}
+
+static void destroy_mailbox(void *obj)
+{
+	struct ast_msg_mailbox mbox = obj;
+
+	if (!mbox) {
+		return;
+	}
+
+	if (mbox->pvt) {
+		ao2_ref(mbox->pvt, -1);
+	}
+	ast_string_field_free_memory(mbox);
+}
+
+static void populate_default_mailbox_optons(const struct ast_msg_mailbox *mbox)
+{
+
+}
+
+struct ast_msg_mailbox *ast_msg_storage_create_mailbox_from_variable(const char * const context, const char * const mailbox, struct ast_variable *var)
+{
+	struct ast_msg_mailbox *mbox;
+	char *values;
+	char *options;
+	char *option_value;
+	char *option_key;
+
+	if (!(mbox = create_mailbox(context, mailbox))) {
+		return NULL;
+	}
+	populate_default_mailbox_optons(mbox);
+
+	values = ast_strdup(var->value);
+	if ((value = strsep(&values, ","))) {
+		ast_string_field_set(mbox, password, value);
+	}
+	if (values && (value = strsep(&values, ","))) {
+		ast_string_field_set(mbox, fullname, value);
+	}
+	if (values && (value = strsep(&values, ","))) {
+		ast_string_field_set(mbox, email_address, value);
+	}
+	if (values && (value = strsep(&values, ","))) {
+		ast_string_field_set(mbox, pager_address, value);
+	}
+	if (values && (value = strsep(&values, ","))) {
+		options = ast_strdup(value);
+		while ((option_value = strsep(&options, "|"))) {
+			if ((option_key = strsep(&option_value, "=")) && option_value) {
+				apply_mailbox_option(imbox, option_key, option_value);
+			}
+		}
+	}
+
+	return mbox;
+}
+
+struct ast_msg_mailbox *ast_msg_storage_create_mailbox_from_context(const char * const context, const char * const mailbox, struct ast_config *mcfg)
+{
+	struct ast_msg_mailbox *mbox;
+	struct ast_variable *var;
+
+	if (ast_strlen_zero(context)) {
+		/* Use the default context from the config options */
+	}
+
+	if (!(mbox = create_mailbox(context, mailbox))) {
+		return NULL;
+	}
+	populate_default_mailbox_optons(mbox);
+
+	for (var = ast_variable_browse(mcfg, cat); var; var = var->next) {
+		if (!strcasecmp(var->name, "vmsecret")) {
+			ast_string_field_set(mbox, password, var->value);
+		} else if (!strcasecmp(var->name, "secret") || !strcasecmp(var->name, "password")) {
+			/* don't overwrite vmsecret if it was already applied */
+			if (ast_strlen_zero(mbox->password)) {
+				ast_string_field_set(mbox, password, var->value);
+			}
+		} else if (!strcasecmp(var->name, "pager")) {
+			ast_string_field_set(mbox, pager_address, var->value);
+		} else if (!strcasecmp(var->name, "email")) {
+			ast_string_field_set(mbox, email_address, var->value);
+		} else if (!strcasecmp(var->name, "fullname")) {
+			ast_string_field_set(mbox, fullname, var->value);
+		} else {
+			apply_mailbox_option(mbox, var->name, var->value);
+		}
+	}
+
+	return mbox;
+}
+
+int ast_msg_storage_add_mailbox(struct ast_msg_mailbox *mbox)
+{
+	struct ast_msg_mailbox mbox_temp = { .hash_key = mbox->hash_key, };
+	struct ast_msg_mailbox *mbox_dup;
+
+	if ((mbox_dup = ao2_find(mailboxes, mbox_temp, OBJ_POINTER))) {
+		ast_log(AST_LOG_WARNING, "Attempted to add duplicate mailbox %s\%s\n", mbox->context, mbox->mailbox);
+		ao2_ref(mbox_dup, -1);
+		return 1;
+	}
+	ao2_link(mailboxes, mbox);
+}
+
+int ast_msg_storage_add_mailboxes(struct ao2_iterator *it_mbox)
+{
+	int res = 0;
+	struct ast_msg_mailbox *mbox_temp = NULL;
+
+	while ((mbox_temp = ao2_iterator_next(it_mbox))) {
+		res |= ast_msg_storage_add_mailbox(mbox_temp);
+		ao2_ref(mbox_temp, -1);
+	}
+	return res;
+}
+
+struct ast_msg_mailbox *ast_msg_storage_get_mailbox(const char * const context, const char * const mailbox)
+{
+	char unique_name[AST_MAX_CONTEXT + AST_MAX_EXTEN + 1];
+	struct ast_msg_mailbox mbox_temp = { .context = context, .mailbox = mailbox, };
+	struct ast_msg_mailbox *mbox;
+
+	strcpy(unique_name, mbox_temp.context);
+	strcat(unique_name, mbox_temp.mailbox);
+	mbox_temp.hash_key = ast_str_case_hash(unique_name);
+
+	mbox = ao2_find(mailboxes, mbox_temp, OBJ_POINTER);
+	return mbox;
+}
+
+void ast_msg_storage_clear_mailboxes(void)
+{
+	struct ao2_iterator it_mbox;
+	struct ast_msg_mailbox *mbox;
+
+	ao2_lock(mailboxes);
+	it_mbox = ao2_iterator_init(mailboxes, 0);
+	while ((mbox = ao2_iterator_next(&it_mbox))) {
+		ao2_unlink(mailboxes, mbox);
+		ao2_ref(mbox, -1);
+	}
+	ao2_iterator_destroy(&it_mbox);
+	ao2_unlock(mailboxes);
+}
 
 void ast_register_message_storage_tech(struct ast_msg_storage_tech *ms_tech)
 {
@@ -72,9 +258,15 @@
 int ast_message_storage_init(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");
+		ast_log(AST_LOG_ERROR, "Unable to allocate message storage technology container\n");
 		return 1;
 	}
 
+	if (!(mailboxes = ao2_container_alloc(MAILBOX_BUCKETS, mailbox_hash_fn, mailbox_storage_cmp_fn))) {
+		ast_log(AST_LOG_ERROR, "Unable to allocate mailbox container\n");
+		ao2_ref(msg_storage_techs, -1);
+		return 1;
+	}
+
 	return 0;
 }




More information about the asterisk-commits mailing list