Debian Codegraph @

res/ari/resource_mailboxes.c

raw symbols SCIP
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"
31 #include "asterisk/stasis_app_mailbox.h"
32
33 #include "resource_mailboxes.h"
34
35 void ast_ari_mailboxes_list(struct ast_variable *headers,
36 struct ast_ari_mailboxes_list_args *args,
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,
50 struct ast_ari_mailboxes_get_args *args,
51 struct ast_ari_response *response)
52 {
53 struct ast_json *json;
54
55 switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
56 case STASIS_MAILBOX_MISSING:
57 ast_ari_response_error(response, 404,
58 "Not Found", "Mailbox is does not exist");
59 return;
60 case STASIS_MAILBOX_ERROR:
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 }
68 void ast_ari_mailboxes_update(struct ast_variable *headers,
69 struct ast_ari_mailboxes_update_args *args,
70 struct ast_ari_response *response)
71 {
72 if (stasis_app_mailbox_update(args->mailbox_name, args->old_messages, args->new_messages)) {
73 ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
74 return;
75 }
76
77 ast_ari_response_no_content(response);
78 }
79 void ast_ari_mailboxes_delete(struct ast_variable *headers,
80 struct ast_ari_mailboxes_delete_args *args,
81 struct ast_ari_response *response)
82 {
83 switch (stasis_app_mailbox_delete(args->mailbox_name)) {
84 case STASIS_MAILBOX_MISSING:
85 ast_ari_response_error(response, 404,
86 "Not Found", "Mailbox does not exist");
87 return;
88 case STASIS_MAILBOX_ERROR:
89 ast_ari_response_error(response, 500,
90 "INternal Server Error", "Failed to delete the mailbox");
91 return;
92 case STASIS_MAILBOX_OK:
93 ast_ari_response_no_content(response);
94 }
95 }