Asterisk - The Open Source Telephony Project  18.5.0
resource_mailboxes.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Jonathan Rose <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief /api-docs/mailboxes.{format} implementation- Mailboxes resources
22  *
23  * \author Jonathan Rose <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
32 
33 #include "resource_mailboxes.h"
34 
35 void ast_ari_mailboxes_list(struct ast_variable *headers,
37  struct ast_ari_response *response)
38 {
39  struct ast_json *json;
40 
41  if (!(json = stasis_app_mailboxes_to_json())) {
42  ast_ari_response_error(response, 500,
43  "Internal Server Error", "Error building response");
44  return;
45  }
46 
47  ast_ari_response_ok(response, json);
48 }
49 void ast_ari_mailboxes_get(struct ast_variable *headers,
51  struct ast_ari_response *response)
52 {
53  struct ast_json *json;
54 
55  switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
57  ast_ari_response_error(response, 404,
58  "Not Found", "Mailbox is does not exist");
59  return;
61  ast_ari_response_error(response, 500,
62  "Internal Server Error", "Error building response");
63  return;
64  case STASIS_MAILBOX_OK:
65  ast_ari_response_ok(response, json);
66  }
67 }
70  struct ast_ari_response *response)
71 {
73  ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
74  return;
75  }
76 
78 }
81  struct ast_ari_response *response)
82 {
83  switch (stasis_app_mailbox_delete(args->mailbox_name)) {
85  ast_ari_response_error(response, 404,
86  "Not Found", "Mailbox does not exist");
87  return;
89  ast_ari_response_error(response, 500,
90  "INternal Server Error", "Failed to delete the mailbox");
91  return;
92  case STASIS_MAILBOX_OK:
94  }
95 }
void ast_ari_mailboxes_update(struct ast_variable *headers, struct ast_ari_mailboxes_update_args *args, struct ast_ari_response *response)
Change the state of a mailbox. (Note - implicitly creates the mailbox).
enum stasis_mailbox_result stasis_app_mailbox_to_json(const char *name, struct ast_json **json)
Convert mailbox to JSON.
Asterisk main include file. File version handling, generic pbx functions.
void ast_ari_mailboxes_delete(struct ast_variable *headers, struct ast_ari_mailboxes_delete_args *args, struct ast_ari_response *response)
Destroy a mailbox.
Structure for variables, used for configurations and for channel variables.
const char * args
enum stasis_mailbox_result stasis_app_mailbox_delete(const char *name)
Delete a mailbox controlled by ARI.
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
struct ast_json * stasis_app_mailboxes_to_json(void)
Generated file - declares stubs to be implemented in res/ari/resource_mailboxes.c.
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition: res_ari.c:259
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
Abstract JSON element (object, array, string, int, ...).
Stasis Application Mailbox API. See StasisApplication API" for detailed documentation.
void ast_ari_mailboxes_get(struct ast_variable *headers, struct ast_ari_mailboxes_get_args *args, struct ast_ari_response *response)
Retrieve the current state of a mailbox.
int stasis_app_mailbox_update(const char *name, int old_messages, int new_messages)
Changes the state of a mailbox.
void ast_ari_mailboxes_list(struct ast_variable *headers, struct ast_ari_mailboxes_list_args *args, struct ast_ari_response *response)
List all mailboxes.