[asterisk-commits] rmudgett: branch rmudgett/external_mwi r403432 - in /team/rmudgett/external_m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 6 17:44:15 CST 2013
Author: rmudgett
Date: Fri Dec 6 17:44:13 2013
New Revision: 403432
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403432
Log:
Switch key from context/user to user at context. The previous organization was beneficial only in sorting if the sorcery backend was astdb.
Modified:
team/rmudgett/external_mwi/include/asterisk/res_mwi_external.h
team/rmudgett/external_mwi/res/res_mwi_external.c
team/rmudgett/external_mwi/res/res_mwi_external_ami.c
Modified: team/rmudgett/external_mwi/include/asterisk/res_mwi_external.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/include/asterisk/res_mwi_external.h?view=diff&rev=403432&r1=403431&r2=403432
==============================================================================
--- team/rmudgett/external_mwi/include/asterisk/res_mwi_external.h (original)
+++ team/rmudgett/external_mwi/include/asterisk/res_mwi_external.h Fri Dec 6 17:44:13 2013
@@ -70,6 +70,18 @@
struct ast_mwi_mailbox_object *ast_mwi_mailbox_alloc(const char *user, const char *context);
/*!
+ * \brief Get mailbox id (user at context).
+ * \since 13.0.0
+ *
+ * \param mailbox Object to get id.
+ *
+ * \return mailbox_id (user at context) of the object.
+ *
+ * \note This should never return NULL unless there is a bug in sorcery.
+ */
+const char *ast_mwi_mailbox_get_id(const struct ast_mwi_mailbox_object *mailbox);
+
+/*!
* \brief Get user part of user at context.
* \since 13.0.0
*
Modified: team/rmudgett/external_mwi/res/res_mwi_external.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/res/res_mwi_external.c?view=diff&rev=403432&r1=403431&r2=403432
==============================================================================
--- team/rmudgett/external_mwi/res/res_mwi_external.c (original)
+++ team/rmudgett/external_mwi/res/res_mwi_external.c Fri Dec 6 17:44:13 2013
@@ -101,9 +101,9 @@
char *user;
char *context;
- /* Separate context/user */
+ /* Separate user at context */
context = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- user = strsep(&context, "/");
+ user = strsep(&context, "@");
ast_publish_mwi_state(user, context, mailbox->msgs_new, mailbox->msgs_old);
}
@@ -131,9 +131,9 @@
return;
}
- /* Separate context/user */
- user = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- context = strsep(&user, "/");
+ /* Separate user at context */
+ context = ast_strdupa(ast_sorcery_object_get_id(mailbox));
+ user = strsep(&context, "@");
/* Post a count clearing event. */
ast_publish_mwi_state(user, context, 0, 0);
@@ -208,14 +208,8 @@
context = MWI_MAILBOX_CONTEXT_DEFAULT;
}
-#if 1
- regex = ast_alloca(3 + strlen(context));
- sprintf(regex, "^%s/", context);/* Safe */
-#else
-/* BUGBUG experiment to search by user instead in preparation to changing to storing as user at context */
regex = ast_alloca(5 + strlen(context));
- sprintf(regex, ".*/%s$", context);/* Safe */
-#endif
+ sprintf(regex, ".*@%s$", context);/* Safe */
return ast_sorcery_retrieve_by_regex(mwi_sorcery, MWI_MAILBOX_TYPE, regex);
}
@@ -232,7 +226,7 @@
}
mailbox_id = ast_alloca(2 + strlen(context) + strlen(user));
- sprintf(mailbox_id, "%s/%s", context, user);/* Safe */
+ sprintf(mailbox_id, "%s@%s", user, context);/* Safe */
return ast_sorcery_retrieve_by_id(mwi_sorcery, MWI_MAILBOX_TYPE, mailbox_id);
}
@@ -249,7 +243,7 @@
}
mailbox_id = ast_alloca(2 + strlen(context) + strlen(user));
- sprintf(mailbox_id, "%s/%s", context, user);/* Safe */
+ sprintf(mailbox_id, "%s@%s", user, context);/* Safe */
return ast_sorcery_alloc(mwi_sorcery, MWI_MAILBOX_TYPE, mailbox_id);
}
@@ -259,24 +253,29 @@
return ast_sorcery_copy(mwi_sorcery, mailbox);
}
+const char *ast_mwi_mailbox_get_id(const struct ast_mwi_mailbox_object *mailbox)
+{
+ return ast_sorcery_object_get_id(mailbox);
+}
+
char *ast_mwi_mailbox_get_user(const struct ast_mwi_mailbox_object *mailbox)
-{
- char *user;
-
- /* Separate context/user. The separator will always be present. */
- user = strchr(ast_sorcery_object_get_id(mailbox), '/') + 1;
-
- return ast_strdup(user);
-}
-
-char *ast_mwi_mailbox_get_context(const struct ast_mwi_mailbox_object *mailbox)
{
char *user;
char *context;
- /* Separate context/user. The separator will always be present. */
- user = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- context = strsep(&user, "/");
+ /* Separate user at context */
+ context = ast_strdupa(ast_sorcery_object_get_id(mailbox));
+ user = strsep(&context, "@");
+
+ return ast_strdup(user);
+}
+
+char *ast_mwi_mailbox_get_context(const struct ast_mwi_mailbox_object *mailbox)
+{
+ char *context;
+
+ /* Separate user at context. The separator will always be present. */
+ context = strchr(ast_sorcery_object_get_id(mailbox), '@') + 1;
return ast_strdup(context);
}
@@ -723,18 +722,8 @@
*/
static void mwi_cli_print_mailbox(int cli_fd, const struct ast_mwi_mailbox_object *mailbox)
{
- char *user;
- char *context;
- char *mailbox_id;
-
- /* Separate context/user */
- user = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- context = strsep(&user, "/");
-
- mailbox_id = ast_alloca(2 + strlen(user) + strlen(context));
- sprintf(mailbox_id, "%s@%s", user, context);/* Safe */
-
- ast_cli(cli_fd, FORMAT_MAILBOX_ROW, mailbox->msgs_new, mailbox->msgs_old, mailbox_id);
+ ast_cli(cli_fd, FORMAT_MAILBOX_ROW, mailbox->msgs_new, mailbox->msgs_old,
+ ast_sorcery_object_get_id(mailbox));
}
/*!
@@ -750,7 +739,7 @@
static void mwi_cli_list_mailboxes(int cli_fd, struct ao2_container *mailboxes)
{
struct ao2_iterator iter;
- struct ast_mwi_mailbox_object *mailbox;
+ const struct ast_mwi_mailbox_object *mailbox;
ast_cli(cli_fd, FORMAT_MAILBOX_HDR, "New", "Old", "Mailbox");
@@ -856,15 +845,11 @@
mailbox = ast_mwi_mailbox_get(user, context);
if (mailbox) {
- /* Separate context/user */
- user = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- context = strsep(&user, "/");
-
ast_cli(a->fd,
- "Mailbox: %s@%s\n"
+ "Mailbox: %s\n"
"NewMessages: %u\n"
"OldMessages: %u\n",
- user, context,
+ ast_sorcery_object_get_id(mailbox),
mailbox->msgs_new,
mailbox->msgs_old);
@@ -935,16 +920,13 @@
mailbox = ast_mwi_mailbox_alloc(user, context);
if (mailbox) {
- /* Separate context/user */
- user = ast_strdupa(ast_sorcery_object_get_id(mailbox));
- context = strsep(&user, "/");
-
ast_mwi_mailbox_set_msgs_new(mailbox, num_new);
ast_mwi_mailbox_set_msgs_old(mailbox, num_old);
if (ast_mwi_mailbox_update(mailbox)) {
- ast_cli(a->fd, "Could not update mailbox %s@%s\n", user, context);
+ ast_cli(a->fd, "Could not update mailbox %s.\n",
+ ast_sorcery_object_get_id(mailbox));
} else {
- ast_cli(a->fd, "Updated mailbox %s@%s\n", user, context);
+ ast_cli(a->fd, "Updated mailbox %s.\n", ast_sorcery_object_get_id(mailbox));
}
ast_mwi_mailbox_unref(mailbox);
Modified: team/rmudgett/external_mwi/res/res_mwi_external_ami.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/res/res_mwi_external_ami.c?view=diff&rev=403432&r1=403431&r2=403432
==============================================================================
--- team/rmudgett/external_mwi/res/res_mwi_external_ami.c (original)
+++ team/rmudgett/external_mwi/res/res_mwi_external_ami.c Fri Dec 6 17:44:13 2013
@@ -205,26 +205,18 @@
count = 0;
iter = ao2_iterator_init(mailboxes, AO2_ITERATOR_UNLINK);
for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
- user = ast_mwi_mailbox_get_user(mailbox);
- context = ast_mwi_mailbox_get_context(mailbox);
- if (user && context) {
- ++count;
- astman_append(s,
- "Event: MWIExternalGet\r\n"
- "Mailbox: %s@%s\r\n"
- "OldMessages: %u\r\n"
- "NewMessages: %u\r\n"
- "%s"
- "\r\n",
- user, context,
- ast_mwi_mailbox_get_msgs_old(mailbox),
- ast_mwi_mailbox_get_msgs_new(mailbox),
- id_text);
- } else {
- ast_debug(1, "User or context could not be gotten.\n");
- }
- ast_free(user);
- ast_free(context);
+ ++count;
+ astman_append(s,
+ "Event: MWIExternalGet\r\n"
+ "Mailbox: %s\r\n"
+ "OldMessages: %u\r\n"
+ "NewMessages: %u\r\n"
+ "%s"
+ "\r\n",
+ ast_mwi_mailbox_get_id(mailbox),
+ ast_mwi_mailbox_get_msgs_old(mailbox),
+ ast_mwi_mailbox_get_msgs_new(mailbox),
+ id_text);
}
ao2_iterator_destroy(&iter);
ao2_ref(mailboxes, -1);
More information about the asterisk-commits
mailing list