resource_mailboxes.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Jonathan Rose <jrose@digium.com>
  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. /*! \file
  19. *
  20. * \brief /api-docs/mailboxes.{format} implementation- Mailboxes resources
  21. *
  22. * \author Jonathan Rose <jrose@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <depend type="module">res_stasis_mailbox</depend>
  26. <support_level>core</support_level>
  27. ***/
  28. #include "asterisk.h"
  29. #include "asterisk/stasis_app_mailbox.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "resource_mailboxes.h"
  32. void ast_ari_mailboxes_list(struct ast_variable *headers,
  33. struct ast_ari_mailboxes_list_args *args,
  34. struct ast_ari_response *response)
  35. {
  36. struct ast_json *json;
  37. if (!(json = stasis_app_mailboxes_to_json())) {
  38. ast_ari_response_error(response, 500,
  39. "Internal Server Error", "Error building response");
  40. return;
  41. }
  42. ast_ari_response_ok(response, json);
  43. }
  44. void ast_ari_mailboxes_get(struct ast_variable *headers,
  45. struct ast_ari_mailboxes_get_args *args,
  46. struct ast_ari_response *response)
  47. {
  48. struct ast_json *json;
  49. switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
  50. case STASIS_MAILBOX_MISSING:
  51. ast_ari_response_error(response, 404,
  52. "Not Found", "Mailbox is does not exist");
  53. return;
  54. case STASIS_MAILBOX_ERROR:
  55. ast_ari_response_error(response, 500,
  56. "Internal Server Error", "Error building response");
  57. return;
  58. case STASIS_MAILBOX_OK:
  59. ast_ari_response_ok(response, json);
  60. }
  61. }
  62. void ast_ari_mailboxes_update(struct ast_variable *headers,
  63. struct ast_ari_mailboxes_update_args *args,
  64. struct ast_ari_response *response)
  65. {
  66. if (stasis_app_mailbox_update(args->mailbox_name, args->old_messages, args->new_messages)) {
  67. ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
  68. return;
  69. }
  70. ast_ari_response_no_content(response);
  71. }
  72. void ast_ari_mailboxes_delete(struct ast_variable *headers,
  73. struct ast_ari_mailboxes_delete_args *args,
  74. struct ast_ari_response *response)
  75. {
  76. switch (stasis_app_mailbox_delete(args->mailbox_name)) {
  77. case STASIS_MAILBOX_MISSING:
  78. ast_ari_response_error(response, 404,
  79. "Not Found", "Mailbox does not exist");
  80. return;
  81. case STASIS_MAILBOX_ERROR:
  82. ast_ari_response_error(response, 500,
  83. "INternal Server Error", "Failed to delete the mailbox");
  84. return;
  85. case STASIS_MAILBOX_OK:
  86. ast_ari_response_no_content(response);
  87. }
  88. }