resource_mailboxes.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "asterisk.h"
  25. #include "asterisk/stasis_app_mailbox.h"
  26. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  27. #include "resource_mailboxes.h"
  28. void ast_ari_mailboxes_list(struct ast_variable *headers,
  29. struct ast_ari_mailboxes_list_args *args,
  30. struct ast_ari_response *response)
  31. {
  32. struct ast_json *json;
  33. if (!(json = stasis_app_mailboxes_to_json())) {
  34. ast_ari_response_error(response, 500,
  35. "Internal Server Error", "Error building response");
  36. return;
  37. }
  38. ast_ari_response_ok(response, json);
  39. }
  40. void ast_ari_mailboxes_get(struct ast_variable *headers,
  41. struct ast_ari_mailboxes_get_args *args,
  42. struct ast_ari_response *response)
  43. {
  44. struct ast_json *json;
  45. switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
  46. case STASIS_MAILBOX_MISSING:
  47. ast_ari_response_error(response, 404,
  48. "Not Found", "Mailbox is does not exist");
  49. return;
  50. case STASIS_MAILBOX_ERROR:
  51. ast_ari_response_error(response, 500,
  52. "Internal Server Error", "Error building response");
  53. return;
  54. case STASIS_MAILBOX_OK:
  55. ast_ari_response_ok(response, json);
  56. }
  57. }
  58. void ast_ari_mailboxes_update(struct ast_variable *headers,
  59. struct ast_ari_mailboxes_update_args *args,
  60. struct ast_ari_response *response)
  61. {
  62. if (stasis_app_mailbox_update(args->mailbox_name, args->old_messages, args->new_messages)) {
  63. ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
  64. return;
  65. }
  66. ast_ari_response_no_content(response);
  67. }
  68. void ast_ari_mailboxes_delete(struct ast_variable *headers,
  69. struct ast_ari_mailboxes_delete_args *args,
  70. struct ast_ari_response *response)
  71. {
  72. switch (stasis_app_mailbox_delete(args->mailbox_name)) {
  73. case STASIS_MAILBOX_MISSING:
  74. ast_ari_response_error(response, 404,
  75. "Not Found", "Mailbox does not exist");
  76. return;
  77. case STASIS_MAILBOX_ERROR:
  78. ast_ari_response_error(response, 500,
  79. "INternal Server Error", "Failed to delete the mailbox");
  80. return;
  81. case STASIS_MAILBOX_OK:
  82. ast_ari_response_no_content(response);
  83. }
  84. }