Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Macros | Functions | Variables
res_ari_device_states.c File Reference

Device state resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_device_states.h"
Include dependency graph for res_ari_device_states.c:

Go to the source code of this file.

Macros

#define MAX_VALS   128
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ast_ari_device_states_delete_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /deviceStates/{deviceName}.
 
static void ast_ari_device_states_get_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /deviceStates/{deviceName}.
 
static void ast_ari_device_states_list_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /deviceStates.
 
static void ast_ari_device_states_update_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /deviceStates/{deviceName}.
 
int ast_ari_device_states_update_parse_body (struct ast_json *body, struct ast_ari_device_states_update_args *args)
 Body parsing function for /deviceStates/{deviceName}.
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Device state resources" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis,res_stasis_device_state", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers deviceStates
 REST handler for /api-docs/deviceStates.json.
 
static struct stasis_rest_handlers deviceStates_deviceName
 REST handler for /api-docs/deviceStates.json.
 

Detailed Description

Device state resources.

Author
Kevin Harwell kharw.nosp@m.ell@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file res_ari_device_states.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 52 of file res_ari_device_states.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 358 of file res_ari_device_states.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 358 of file res_ari_device_states.c.

◆ ast_ari_device_states_delete_cb()

static void ast_ari_device_states_delete_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /deviceStates/{deviceName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 258 of file res_ari_device_states.c.

262{
264 struct ast_variable *i;
265#if defined(AST_DEVMODE)
266 int is_valid;
267 int code;
268#endif /* AST_DEVMODE */
269
270 for (i = path_vars; i; i = i->next) {
271 if (strcmp(i->name, "deviceName") == 0) {
272 args.device_name = (i->value);
273 } else
274 {}
275 }
276 ast_ari_device_states_delete(headers, &args, response);
277#if defined(AST_DEVMODE)
278 code = response->response_code;
279
280 switch (code) {
281 case 0: /* Implementation is still a stub, or the code wasn't set */
282 is_valid = response->message == NULL;
283 break;
284 case 500: /* Internal Server Error */
285 case 501: /* Not Implemented */
286 case 404: /* Device name is missing */
287 case 409: /* Uncontrolled device specified */
288 is_valid = 1;
289 break;
290 default:
291 if (200 <= code && code <= 299) {
292 is_valid = ast_ari_validate_void(
293 response->message);
294 } else {
295 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
296 is_valid = 0;
297 }
298 }
299
300 if (!is_valid) {
301 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
302 ast_ari_response_error(response, 500,
303 "Internal Server Error", "Response validation failed");
304 }
305#endif /* AST_DEVMODE */
306
307fin: __attribute__((unused))
308 return;
309}
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition res_ari.c:212
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
static struct @519 args
#define NULL
Definition resample.c:96
void ast_ari_device_states_delete(struct ast_variable *headers, struct ast_ari_device_states_delete_args *args, struct ast_ari_response *response)
Destroy a device-state controlled by ARI.
struct ast_json * message
Definition ari.h:103
int response_code
Definition ari.h:108
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References args, ast_ari_device_states_delete(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_device_states_get_cb()

static void ast_ari_device_states_get_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /deviceStates/{deviceName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 115 of file res_ari_device_states.c.

119{
121 struct ast_variable *i;
122#if defined(AST_DEVMODE)
123 int is_valid;
124 int code;
125#endif /* AST_DEVMODE */
126
127 for (i = path_vars; i; i = i->next) {
128 if (strcmp(i->name, "deviceName") == 0) {
129 args.device_name = (i->value);
130 } else
131 {}
132 }
133 ast_ari_device_states_get(headers, &args, response);
134#if defined(AST_DEVMODE)
135 code = response->response_code;
136
137 switch (code) {
138 case 0: /* Implementation is still a stub, or the code wasn't set */
139 is_valid = response->message == NULL;
140 break;
141 case 500: /* Internal Server Error */
142 case 501: /* Not Implemented */
143 is_valid = 1;
144 break;
145 default:
146 if (200 <= code && code <= 299) {
148 response->message);
149 } else {
150 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
151 is_valid = 0;
152 }
153 }
154
155 if (!is_valid) {
156 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
157 ast_ari_response_error(response, 500,
158 "Internal Server Error", "Response validation failed");
159 }
160#endif /* AST_DEVMODE */
161
162fin: __attribute__((unused))
163 return;
164}
int ast_ari_validate_device_state(struct ast_json *json)
Validator for DeviceState.
void ast_ari_device_states_get(struct ast_variable *headers, struct ast_ari_device_states_get_args *args, struct ast_ari_response *response)
Retrieve the current state of a device.

References args, ast_ari_device_states_get(), ast_ari_response_error(), ast_ari_validate_device_state(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_device_states_list_cb()

static void ast_ari_device_states_list_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /deviceStates.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 63 of file res_ari_device_states.c.

67{
69#if defined(AST_DEVMODE)
70 int is_valid;
71 int code;
72#endif /* AST_DEVMODE */
73
74 ast_ari_device_states_list(headers, &args, response);
75#if defined(AST_DEVMODE)
76 code = response->response_code;
77
78 switch (code) {
79 case 0: /* Implementation is still a stub, or the code wasn't set */
80 is_valid = response->message == NULL;
81 break;
82 case 500: /* Internal Server Error */
83 case 501: /* Not Implemented */
84 is_valid = 1;
85 break;
86 default:
87 if (200 <= code && code <= 299) {
88 is_valid = ast_ari_validate_list(response->message,
90 } else {
91 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates\n", code);
92 is_valid = 0;
93 }
94 }
95
96 if (!is_valid) {
97 ast_log(LOG_ERROR, "Response validation failed for /deviceStates\n");
98 ast_ari_response_error(response, 500,
99 "Internal Server Error", "Response validation failed");
100 }
101#endif /* AST_DEVMODE */
102
103fin: __attribute__((unused))
104 return;
105}
ari_validator ast_ari_validate_device_state_fn(void)
Function pointer to ast_ari_validate_device_state().
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
void ast_ari_device_states_list(struct ast_variable *headers, struct ast_ari_device_states_list_args *args, struct ast_ari_response *response)
List all ARI controlled device states.

References args, ast_ari_device_states_list(), ast_ari_response_error(), ast_ari_validate_device_state_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

◆ ast_ari_device_states_update_cb()

static void ast_ari_device_states_update_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /deviceStates/{deviceName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 187 of file res_ari_device_states.c.

191{
193 struct ast_variable *i;
194#if defined(AST_DEVMODE)
195 int is_valid;
196 int code;
197#endif /* AST_DEVMODE */
198
199 for (i = get_params; i; i = i->next) {
200 if (strcmp(i->name, "deviceState") == 0) {
201 args.device_state = (i->value);
202 } else
203 {}
204 }
205 for (i = path_vars; i; i = i->next) {
206 if (strcmp(i->name, "deviceName") == 0) {
207 args.device_name = (i->value);
208 } else
209 {}
210 }
213 goto fin;
214 }
215 ast_ari_device_states_update(headers, &args, response);
216#if defined(AST_DEVMODE)
217 code = response->response_code;
218
219 switch (code) {
220 case 0: /* Implementation is still a stub, or the code wasn't set */
221 is_valid = response->message == NULL;
222 break;
223 case 500: /* Internal Server Error */
224 case 501: /* Not Implemented */
225 case 404: /* Device name is missing */
226 case 409: /* Uncontrolled device specified */
227 is_valid = 1;
228 break;
229 default:
230 if (200 <= code && code <= 299) {
231 is_valid = ast_ari_validate_void(
232 response->message);
233 } else {
234 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
235 is_valid = 0;
236 }
237 }
238
239 if (!is_valid) {
240 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
241 ast_ari_response_error(response, 500,
242 "Internal Server Error", "Response validation failed");
243 }
244#endif /* AST_DEVMODE */
245
246fin: __attribute__((unused))
247 return;
248}
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition res_ari.c:251
int ast_ari_device_states_update_parse_body(struct ast_json *body, struct ast_ari_device_states_update_args *args)
Body parsing function for /deviceStates/{deviceName}.
void ast_ari_device_states_update(struct ast_variable *headers, struct ast_ari_device_states_update_args *args, struct ast_ari_response *response)
Change the state of a device controlled by ARI. (Note - implicitly creates the device state).

References args, ast_ari_device_states_update(), ast_ari_device_states_update_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_device_states_update_parse_body()

int ast_ari_device_states_update_parse_body ( struct ast_json body,
struct ast_ari_device_states_update_args args 
)

Body parsing function for /deviceStates/{deviceName}.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 165 of file res_ari_device_states.c.

168{
169 struct ast_json *field;
170 /* Parse query parameters out of it */
171 field = ast_json_object_get(body, "deviceState");
172 if (field) {
173 args->device_state = ast_json_string_get(field);
174 }
175 return 0;
176}
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
Abstract JSON element (object, array, string, int, ...).

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_device_states_update_cb().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 358 of file res_ari_device_states.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 339 of file res_ari_device_states.c.

340{
341 int res = 0;
342
343
345 if (res) {
348 }
349
351}
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:132
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
static struct stasis_rest_handlers deviceStates
REST handler for /api-docs/deviceStates.json.
static int unload_module(void)

References ast_ari_add_handler(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, deviceStates, and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 333 of file res_ari_device_states.c.

334{
336 return 0;
337}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:155

References ast_ari_remove_handler(), and deviceStates.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Device state resources" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis,res_stasis_device_state", }
static

Definition at line 358 of file res_ari_device_states.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 358 of file res_ari_device_states.c.

◆ deviceStates

struct stasis_rest_handlers deviceStates
static

REST handler for /api-docs/deviceStates.json.

Definition at line 324 of file res_ari_device_states.c.

324 {
325 .path_segment = "deviceStates",
326 .callbacks = {
328 },
329 .num_children = 1,
330 .children = { &deviceStates_deviceName, }
331};
@ AST_HTTP_GET
Definition http.h:60
static struct stasis_rest_handlers deviceStates_deviceName
REST handler for /api-docs/deviceStates.json.
static void ast_ari_device_states_list_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /deviceStates.

Referenced by load_module(), and unload_module().

◆ deviceStates_deviceName

struct stasis_rest_handlers deviceStates_deviceName
static

REST handler for /api-docs/deviceStates.json.

Definition at line 312 of file res_ari_device_states.c.

312 {
313 .path_segment = "deviceName",
314 .is_wildcard = 1,
315 .callbacks = {
319 },
320 .num_children = 0,
321 .children = { }
322};
@ AST_HTTP_PUT
Definition http.h:63
@ AST_HTTP_DELETE
Definition http.h:64
static void ast_ari_device_states_get_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /deviceStates/{deviceName}.
static void ast_ari_device_states_delete_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /deviceStates/{deviceName}.
static void ast_ari_device_states_update_cb(struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Parameter parsing callback for /deviceStates/{deviceName}.