summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2014-01-14 23:44:57 +0000
committerJonathan Rose <jrose@digium.com>2014-01-14 23:44:57 +0000
commitaa9db707c56fa673560e25663f581954a66f3974 (patch)
treea539c9a84ad0679612606f15728bd5049ff2e441 /res/ari
parented0d083596bd22bf772433ac949f243dfc5fb28c (diff)
ARI: Add mailboxes resource for controlling and polling external MWI
Adds the following AMI commands: PUT mailboxes/mailboxName modifies mailbox state and implicitly creates new mailboxes GET mailboxes/mailboxName retrieves a JSON representation of a single mailbox if it exists GET mailboxes retrieves a JSON array of all mailboxes DELETE mailbox/mailboxName deletes a mailbox Note that res_mwi_external must be loaded for these functions to actually do anything. Review: https://reviewboard.asterisk.org/r/3117/ ........ Merged revisions 405553 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405554 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_model_validators.c70
-rw-r--r--res/ari/ari_model_validators.h22
-rw-r--r--res/ari/resource_mailboxes.c93
-rw-r--r--res/ari/resource_mailboxes.h97
4 files changed, 282 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index a04818045..b1482fa87 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -1419,6 +1419,76 @@ ari_validator ast_ari_validate_device_state_fn(void)
return ast_ari_validate_device_state;
}
+int ast_ari_validate_mailbox(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_name = 0;
+ int has_new_messages = 0;
+ int has_old_messages = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_name = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Mailbox field name failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("new_messages", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_new_messages = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Mailbox field new_messages failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("old_messages", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_old_messages = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Mailbox field old_messages failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Mailbox has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_name) {
+ ast_log(LOG_ERROR, "ARI Mailbox missing required field name\n");
+ res = 0;
+ }
+
+ if (!has_new_messages) {
+ ast_log(LOG_ERROR, "ARI Mailbox missing required field new_messages\n");
+ res = 0;
+ }
+
+ if (!has_old_messages) {
+ ast_log(LOG_ERROR, "ARI Mailbox missing required field old_messages\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_mailbox_fn(void)
+{
+ return ast_ari_validate_mailbox;
+}
+
int ast_ari_validate_application_replaced(struct ast_json *json)
{
int res = 1;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 326693950..ffe003903 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -499,6 +499,24 @@ int ast_ari_validate_device_state(struct ast_json *json);
ari_validator ast_ari_validate_device_state_fn(void);
/*!
+ * \brief Validator for Mailbox.
+ *
+ * Represents the state of a mailbox.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_mailbox(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_mailbox().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_mailbox_fn(void);
+
+/*!
* \brief Validator for ApplicationReplaced.
*
* Notification that another WebSocket has taken over for an application.
@@ -1111,6 +1129,10 @@ ari_validator ast_ari_validate_application_fn(void);
* DeviceState
* - name: string (required)
* - state: string (required)
+ * Mailbox
+ * - name: string (required)
+ * - new_messages: int (required)
+ * - old_messages: int (required)
* ApplicationReplaced
* - type: string (required)
* - application: string (required)
diff --git a/res/ari/resource_mailboxes.c b/res/ari/resource_mailboxes.c
new file mode 100644
index 000000000..0d9bac704
--- /dev/null
+++ b/res/ari/resource_mailboxes.c
@@ -0,0 +1,93 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jonathan Rose <jrose@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 /api-docs/mailboxes.{format} implementation- Mailboxes resources
+ *
+ * \author Jonathan Rose <jrose@digium.com>
+ */
+
+#include "asterisk.h"
+#include "asterisk/stasis_app_mailbox.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "resource_mailboxes.h"
+
+void ast_ari_mailboxes_list(struct ast_variable *headers,
+ struct ast_ari_mailboxes_list_args *args,
+ struct ast_ari_response *response)
+{
+ struct ast_json *json;
+
+ if (!(json = stasis_app_mailboxes_to_json())) {
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Error building response");
+ return;
+ }
+
+ ast_ari_response_ok(response, json);
+}
+void ast_ari_mailboxes_get(struct ast_variable *headers,
+ struct ast_ari_mailboxes_get_args *args,
+ struct ast_ari_response *response)
+{
+ struct ast_json *json;
+
+ switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
+ case STASIS_MAILBOX_MISSING:
+ ast_ari_response_error(response, 404,
+ "Not Found", "Mailbox is does not exist");
+ return;
+ case STASIS_MAILBOX_ERROR:
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Error building response");
+ return;
+ case STASIS_MAILBOX_OK:
+ ast_ari_response_ok(response, json);
+ }
+}
+void ast_ari_mailboxes_update(struct ast_variable *headers,
+ struct ast_ari_mailboxes_update_args *args,
+ struct ast_ari_response *response)
+{
+ if (stasis_app_mailbox_update(args->mailbox_name, args->old_messages, args->new_messages)) {
+ ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
+ return;
+ }
+
+ ast_ari_response_no_content(response);
+}
+void ast_ari_mailboxes_delete(struct ast_variable *headers,
+ struct ast_ari_mailboxes_delete_args *args,
+ struct ast_ari_response *response)
+{
+ switch (stasis_app_mailbox_delete(args->mailbox_name)) {
+ case STASIS_MAILBOX_MISSING:
+ ast_ari_response_error(response, 404,
+ "Not Found", "Mailbox does not exist");
+ return;
+ case STASIS_MAILBOX_ERROR:
+ ast_ari_response_error(response, 500,
+ "INternal Server Error", "Failed to delete the mailbox");
+ return;
+ case STASIS_MAILBOX_OK:
+ ast_ari_response_no_content(response);
+ }
+}
diff --git a/res/ari/resource_mailboxes.h b/res/ari/resource_mailboxes.h
new file mode 100644
index 000000000..33c69682d
--- /dev/null
+++ b/res/ari/resource_mailboxes.h
@@ -0,0 +1,97 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jonathan Rose <jrose@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 Generated file - declares stubs to be implemented in
+ * res/ari/resource_mailboxes.c
+ *
+ * Mailboxes resources
+ *
+ * \author Jonathan Rose <jrose@digium.com>
+ */
+
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * !!!!! DO NOT EDIT !!!!!
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * This file is generated by a mustache template. Please see the original
+ * template in rest-api-templates/ari_resource.h.mustache
+ */
+
+#ifndef _ASTERISK_RESOURCE_MAILBOXES_H
+#define _ASTERISK_RESOURCE_MAILBOXES_H
+
+#include "asterisk/ari.h"
+
+/*! \brief Argument struct for ast_ari_mailboxes_list() */
+struct ast_ari_mailboxes_list_args {
+};
+/*!
+ * \brief List all mailboxes.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_mailboxes_list(struct ast_variable *headers, struct ast_ari_mailboxes_list_args *args, struct ast_ari_response *response);
+/*! \brief Argument struct for ast_ari_mailboxes_get() */
+struct ast_ari_mailboxes_get_args {
+ /*! \brief Name of the mailbox */
+ const char *mailbox_name;
+};
+/*!
+ * \brief Retrieve the current state of a mailbox.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_mailboxes_get(struct ast_variable *headers, struct ast_ari_mailboxes_get_args *args, struct ast_ari_response *response);
+/*! \brief Argument struct for ast_ari_mailboxes_update() */
+struct ast_ari_mailboxes_update_args {
+ /*! \brief Name of the mailbox */
+ const char *mailbox_name;
+ /*! \brief Count of old messages in the mailbox */
+ int old_messages;
+ /*! \brief Count of new messages in the mailbox */
+ int new_messages;
+};
+/*!
+ * \brief Change the state of a mailbox. (Note - implicitly creates the mailbox).
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_mailboxes_update(struct ast_variable *headers, struct ast_ari_mailboxes_update_args *args, struct ast_ari_response *response);
+/*! \brief Argument struct for ast_ari_mailboxes_delete() */
+struct ast_ari_mailboxes_delete_args {
+ /*! \brief Name of the mailbox */
+ const char *mailbox_name;
+};
+/*!
+ * \brief Destroy a mailbox.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_mailboxes_delete(struct ast_variable *headers, struct ast_ari_mailboxes_delete_args *args, struct ast_ari_response *response);
+
+#endif /* _ASTERISK_RESOURCE_MAILBOXES_H */