[svn-commits] mjordan: branch mjordan/voicemail_refactor_11_10_19 r348463 - /team/mjordan/v...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 16 17:01:20 CST 2011


Author: mjordan
Date: Fri Dec 16 17:01:18 2011
New Revision: 348463

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=348463
Log:
Sync for the weekend... and go!

Modified:
    team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c

Modified: 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=diff&rev=348463&r1=348462&r2=348463
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c (original)
+++ team/mjordan/voicemail_refactor_11_10_19/res/res_message_imap.c Fri Dec 16 17:01:18 2011
@@ -30,7 +30,7 @@
 
 /*! \internal \brief The IMAP mailbox definition */
 struct imap_mailbox {
-	struct ast_msg_mailbox *msg_mailbox;			/*!< The inherited message mailbox information */
+	struct ast_msg_mailbox *msg_mailbox;		/*!< The inherited message mailbox information */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(user);					/*!< IMAP server login */
 		AST_STRING_FIELD(password);				/*!< IMAP server password if auth_password not defined */
@@ -87,6 +87,13 @@
 		.get_mailbox = ast_get_message_mailbox,
 };
 
+/*! \internal \brief Create a new IMAP mailbox
+ * \param context, the context the mailbox resides in
+ * \param mailbox, the mailbox name
+ * \note The base message storage technology must first have loaded a mailbox
+ * that matches the context/mailbox pair.  The combination of context/mailbox must be unique
+ * across all mailboxes.  The IMAP mailbox created is an ao2 ref counted object.
+ */
 static struct imap_mailbox *imap_mailbox_new(const char *context, const char *mailbox)
 {
 	struct imap_mailbox *imbox = NULL;
@@ -114,6 +121,7 @@
 	return imbox;
 }
 
+/*! \internal \brief Dispose of a mailbox */
 static void imap_mailbox_destroy(void *obj)
 {
 	struct imap_mailbox *imbox = obj;
@@ -126,6 +134,10 @@
 	ast_string_field_free_memory(imbox);
 }
 
+/*! \internal \brief Create a new IMAP configuration object
+ * \note The base message storage technology must first have loaded its configuration
+ * before calling this method.
+ */
 static struct imap_config *imap_config_new(void)
 {
 	struct imap_config *iconfig = NULL;
@@ -153,6 +165,7 @@
 	return iconfig;
 }
 
+/*! \internal \brief Dispose of an IMAP configuration object */
 static void imap_config_destroy(void *obj)
 {
 	struct imap_config *iconfig = obj;
@@ -165,6 +178,9 @@
 	ast_string_field_free_memory(iconfig);
 }
 
+/* \internal \brief Populate the default options in an IMAP config object
+ * \param iconfig, the IMAP configuration object to populate
+ */
 static void populate_default_config_options(struct imap_config *iconfig)
 {
 	iconfig->expunge_on_hangup = default_expunge_on_hangup;
@@ -180,7 +196,10 @@
 	ast_string_field_set(iconfig, folder, default_imap_folder);
 }
 
-static int imap_load_config(struct ast_config *cfg, int reload)
+/* \internal \brief Load an IMAP configuration object from an Asterisk configuration object
+ * \param cfg, the Asterisk configuration object containing the information
+ */
+static int imap_load_config(struct ast_config *cfg)
 {
 	struct ast_variable *var;
 	struct ast_category *cat = ast_category_get(cfg, default_settings_context);
@@ -255,7 +274,7 @@
 	}
 
 	ast_mutex_lock(&config_lock);
-	if (reload) {
+	if (!config) {
 		ao2_ref(config, -1);
 	}
 	config = iconfig;
@@ -265,7 +284,7 @@
 }
 
 /*! \internal \brief Safely access the global IMAP configuration object
- * \note IMAP methods should use this to safely get a reference to the global IMAP config object.  This
+ * \note in general, IMAP methods should use this to safely get a reference to the global IMAP config object.  This
  * method increases the object reference count on the configuration object to prevent it from being
  * prematurely deleted in the case of a reload - methods that obtain the object should decrement the
  * reference count when they are finished with it.
@@ -284,13 +303,24 @@
 	return 0;
 }
 
-static void create_mailbox_from_variable(const struct imap_config *iconfig, struct imap_user *imu, const char *cat_name, struct ast_variable *var)
+static void populate_default_mailbox_options(const struct imap_config *iconfig, struct imap_mailbox *imbox)
+{
+
+}
+
+static struct imap_mailbox *create_mailbox_from_variable(const struct imap_config *iconfig, const char *cat_name, struct ast_variable *var)
 {
 	char *values;
 	char *options;
 	char *option_key;
 	char *option_value;
 	char *value;
+	struct imap_mailbox *imbox;
+
+	if ((!imbox = imap_mailbox_new(cat_name, var->name))) {
+		ast_log(AST_LOG_ERROR, "Failed to create IMAP mailbox for %s/%s\n", cat_name, var->name);
+		return NULL;
+	}
 
 	ast_copy_string(vmu->mailbox, var->name, sizeof(vmu->mailbox));
 	ast_copy_string(vmu->context, context, sizeof(vmu->context));
@@ -331,7 +361,32 @@
 
 }
 
-static int imap_load_mailboxes(struct ast_config *mcfg, int reload, int by_variable)
+/*! \internal \brief Remove all of the mailboxes from a container
+ * \note This does *not* lock the container.  Thread synchronziation is left to the caller.
+ */
+static void imap_remove_mailboxes(struct ao2_container *container)
+{
+	struct imap_mailbox *imbox;
+	struct ao2_iterator it_container = ao2_iterator_init(container, AO2_ITERATOR_DONTLOCK | AO2_ITERATOR_UNLINK);
+	while ((imbox = ao2_iterator_next(&it_container))) {
+		ao2_ref(imbox, -1);
+	}
+}
+
+/*! \internal \brief Move all mailboxes from the source container to the destination container
+ * \note This does *not* lock the containers.  Thread synchronization is left to the caller.
+ */
+static void imap_move_mailboxes(struct ao2_container *src_container, struct ao2_container *dst_container)
+{
+	struct imap_mailbox *imbox;
+	struct ao2_iterator it_container = ao2_iterator_init(src_container, AO2_ITERATOR_DONTLOCK | AO2_ITERATOR_UNLINK);
+	while ((imbox = ao2_iterator_next(&it_container))) {
+		ao2_link(dst_container, imbox);
+		ao2_ref(imbox, -1);
+	}
+}
+
+static int imap_load_mailboxes(struct ast_config *mcfg, int by_variable)
 {
 	const char *cat_name;
 	int res = 0;
@@ -350,30 +405,35 @@
 	iconfig = imap_get_config();
 
 	for (cat_name = ast_category_browse(mcfg, NULL); cat_name; cat_name = ast_category_browse(mcfg, cat_name)) {
-		/* Anything not in the general context or timezone context is assumed to be user data */
+		/* Skip the general context or timezone context */
 		if (by_variable && (!strcasecmp(cat_name, default_settings_context) || !strcasecmp(cat_name, default_timezone_context))) {
 			continue;
 		}
 
 		if (!by_variable) {
 			for (var = ast_variable_browse(mcfg, cat_name); var; var = var->next) {
-				if (imbox = create_mailbox_from_variable(iconfig, imu, cat_name, var)) {
-					ao2_link(user_container, )
-				}
+				imbox = create_mailbox_from_variable(iconfig, cat_name, var);
 			}
 		} else {
 			/* TODO: this should probably be changed to hasmailbox or something along those lines */
 			if (ast_true(ast_config_option(mcfg, cat_name, "hasvoicemail"))) {
-				imbox = create_mailbox_from_category(iconfig, imu, ucfg, cat_name);
-			}
-		}
-
-		if (!validate_user(imu)) {
-			ao2_link(user_container, imu);
-		}
-		ao2_ref(imu, -1);
-	}
-
+				imbox = create_mailbox_from_category(iconfig, mcfg, cat_name);
+			}
+		}
+
+		if (!validate_user(imbox)) {
+			ao2_link(temp_container, imbox);
+		}
+		ao2_ref(imbox, -1);
+		imbox = NULL;
+	}
+
+	ao2_lock(imap_mailboxes);
+	imap_remove_mailboxes(imap_mailboxes);
+	imap_move_mailboxes(temp_container, imap_mailboxes);
+	ao2_unlock(imap_mailboxes);
+
+	ao2_ref(temp_container, -1);
 	ao2_ref(iconfig, -1);
 
 	return 0;
@@ -389,6 +449,10 @@
 	ast_unregister_message_storage_tech(imap_message_storage_tech.name);
 
 	ao2_ref(config, -1);
+	/* TODO: This may not be necessary */
+	ao2_lock(imap_mailboxes);
+	imap_remove_mailboxes(imap_mailboxes);
+	ao2_unlock(imap_mailboxes);
 	ao2_ref(imap_mailboxes, -1);
 
 	return 0;




More information about the svn-commits mailing list