| 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 |
|
| 32 |
#include "resource_events.h" |
| 33 |
#include "internal.h" |
| 34 |
#include "asterisk/stasis_app.h" |
| 35 |
#include "asterisk/stasis_app_broadcast.h" |
| 36 |
|
| 37 |
void ast_ari_events_user_event(struct ast_variable *headers, |
| 38 |
struct ast_ari_events_user_event_args *args, |
| 39 |
struct ast_ari_response *response) |
| 40 |
{ |
| 41 |
enum stasis_app_user_event_res res; |
| 42 |
struct ast_json *json_variables = NULL; |
| 43 |
|
| 44 |
if (args->variables) { |
| 45 |
ast_ari_events_user_event_parse_body(args->variables, args); |
| 46 |
json_variables = ast_json_object_get(args->variables, "variables"); |
| 47 |
} |
| 48 |
|
| 49 |
if (ast_strlen_zero(args->application)) { |
| 50 |
ast_ari_response_error(response, 400, "Bad Request", |
| 51 |
"Missing parameter application"); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
res = stasis_app_user_event(args->application, |
| 56 |
args->event_name, |
| 57 |
args->source, args->source_count, |
| 58 |
json_variables); |
| 59 |
|
| 60 |
switch (res) { |
| 61 |
case STASIS_APP_USER_OK: |
| 62 |
ast_ari_response_no_content(response); |
| 63 |
break; |
| 64 |
|
| 65 |
case STASIS_APP_USER_APP_NOT_FOUND: |
| 66 |
ast_ari_response_error(response, 404, "Not Found", |
| 67 |
"Application not found"); |
| 68 |
break; |
| 69 |
|
| 70 |
case STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND: |
| 71 |
ast_ari_response_error(response, 422, "Unprocessable Entity", |
| 72 |
"Event source was not found"); |
| 73 |
break; |
| 74 |
|
| 75 |
case STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME: |
| 76 |
ast_ari_response_error(response, 400, "Bad Request", |
| 77 |
"Invalid event source URI scheme"); |
| 78 |
break; |
| 79 |
|
| 80 |
case STASIS_APP_USER_USEREVENT_INVALID: |
| 81 |
ast_ari_response_error(response, 400, "Bad Request", |
| 82 |
"Invalid userevent data"); |
| 83 |
break; |
| 84 |
|
| 85 |
case STASIS_APP_USER_INTERNAL_ERROR: |
| 86 |
default: |
| 87 |
ast_ari_response_error(response, 500, "Internal Server Error", |
| 88 |
"Error processing request"); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void ast_ari_events_claim_channel(struct ast_variable *headers, |
| 93 |
struct ast_ari_events_claim_channel_args *args, |
| 94 |
struct ast_ari_response *response) |
| 95 |
{ |
| 96 |
int res; |
| 97 |
|
| 98 |
if (ast_strlen_zero(args->channel_id)) { |
| 99 |
ast_ari_response_error(response, 400, "Bad Request", |
| 100 |
"channelId parameter is required"); |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
if (ast_strlen_zero(args->application)) { |
| 105 |
ast_ari_response_error(response, 400, "Bad Request", |
| 106 |
"application parameter is required"); |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
res = stasis_app_claim_channel(args->channel_id, args->application); |
| 111 |
|
| 112 |
switch (res) { |
| 113 |
case 0: |
| 114 |
|
| 115 |
ast_ari_response_no_content(response); |
| 116 |
break; |
| 117 |
case -1: |
| 118 |
|
| 119 |
ast_ari_response_error(response, 404, "Not Found", |
| 120 |
"Channel not found or not in broadcast state"); |
| 121 |
break; |
| 122 |
case -2: |
| 123 |
|
| 124 |
ast_ari_response_error(response, 409, "Conflict", |
| 125 |
"Channel has already been claimed by another application"); |
| 126 |
break; |
| 127 |
case AST_OPTIONAL_API_UNAVAILABLE: |
| 128 |
|
| 129 |
ast_ari_response_error(response, 501, "Not Implemented", |
| 130 |
"Broadcast functionality not available (res_stasis_broadcast not loaded)"); |
| 131 |
break; |
| 132 |
default: |
| 133 |
ast_ari_response_error(response, 500, "Internal Server Error", |
| 134 |
"Failed to claim channel"); |
| 135 |
break; |
| 136 |
} |
| 137 |
} |