| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
} |