| 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_device_states.h" |
| 33 |
#include "asterisk/stasis_app_device_state.h" |
| 34 |
|
| 35 |
void ast_ari_device_states_list( |
| 36 |
struct ast_variable *headers, |
| 37 |
struct ast_ari_device_states_list_args *args, |
| 38 |
struct ast_ari_response *response) |
| 39 |
{ |
| 40 |
struct ast_json *json; |
| 41 |
|
| 42 |
if (!(json = stasis_app_device_states_to_json())) { |
| 43 |
ast_ari_response_error(response, 500, |
| 44 |
"Internal Server Error", "Error building response"); |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
ast_ari_response_ok(response, json); |
| 49 |
} |
| 50 |
|
| 51 |
void ast_ari_device_states_get(struct ast_variable *headers, |
| 52 |
struct ast_ari_device_states_get_args *args, |
| 53 |
struct ast_ari_response *response) |
| 54 |
{ |
| 55 |
struct ast_json *json; |
| 56 |
|
| 57 |
if (!(json = stasis_app_device_state_to_json( |
| 58 |
args->device_name, ast_device_state(args->device_name)))) { |
| 59 |
ast_ari_response_error(response, 500, |
| 60 |
"Internal Server Error", "Error building response"); |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
ast_ari_response_ok(response, json); |
| 65 |
} |
| 66 |
|
| 67 |
void ast_ari_device_states_update(struct ast_variable *headers, |
| 68 |
struct ast_ari_device_states_update_args *args, |
| 69 |
struct ast_ari_response *response) |
| 70 |
{ |
| 71 |
switch (stasis_app_device_state_update( |
| 72 |
args->device_name, args->device_state)) { |
| 73 |
case STASIS_DEVICE_STATE_NOT_CONTROLLED: |
| 74 |
ast_ari_response_error(response, 409, |
| 75 |
"Conflict", "Uncontrolled device specified"); |
| 76 |
return; |
| 77 |
case STASIS_DEVICE_STATE_MISSING: |
| 78 |
ast_ari_response_error(response, 404, |
| 79 |
"Not Found", "Device name is missing"); |
| 80 |
return; |
| 81 |
case STASIS_DEVICE_STATE_UNKNOWN: |
| 82 |
ast_ari_response_error(response, 500, "Internal Server Error", |
| 83 |
"Unknown device"); |
| 84 |
return; |
| 85 |
case STASIS_DEVICE_STATE_OK: |
| 86 |
case STASIS_DEVICE_STATE_SUBSCRIBERS: |
| 87 |
ast_ari_response_no_content(response); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
void ast_ari_device_states_delete(struct ast_variable *headers, |
| 92 |
struct ast_ari_device_states_delete_args *args, |
| 93 |
struct ast_ari_response *response) |
| 94 |
{ |
| 95 |
switch (stasis_app_device_state_delete(args->device_name)) { |
| 96 |
case STASIS_DEVICE_STATE_NOT_CONTROLLED: |
| 97 |
ast_ari_response_error(response, 409, |
| 98 |
"Conflict", "Uncontrolled device specified"); |
| 99 |
return; |
| 100 |
case STASIS_DEVICE_STATE_MISSING: |
| 101 |
ast_ari_response_error(response, 404, |
| 102 |
"Not Found", "Device name is missing"); |
| 103 |
return; |
| 104 |
case STASIS_DEVICE_STATE_SUBSCRIBERS: |
| 105 |
ast_ari_response_error(response, 500, |
| 106 |
"Internal Server Error", |
| 107 |
"Cannot delete device with subscribers"); |
| 108 |
return; |
| 109 |
case STASIS_DEVICE_STATE_OK: |
| 110 |
case STASIS_DEVICE_STATE_UNKNOWN: |
| 111 |
ast_ari_response_no_content(response); |
| 112 |
} |
| 113 |
} |