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

Asterisk resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_asterisk.h"
Include dependency graph for res_ari_asterisk.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_asterisk_add_log_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 /asterisk/logging/{logChannelName}.
 
int ast_ari_asterisk_add_log_parse_body (struct ast_json *body, struct ast_ari_asterisk_add_log_args *args)
 Body parsing function for /asterisk/logging/{logChannelName}.
 
static void ast_ari_asterisk_delete_log_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 /asterisk/logging/{logChannelName}.
 
static void ast_ari_asterisk_delete_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
 
static void ast_ari_asterisk_get_global_var_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 /asterisk/variable.
 
int ast_ari_asterisk_get_global_var_parse_body (struct ast_json *body, struct ast_ari_asterisk_get_global_var_args *args)
 Body parsing function for /asterisk/variable.
 
static void ast_ari_asterisk_get_info_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 /asterisk/info.
 
int ast_ari_asterisk_get_info_parse_body (struct ast_json *body, struct ast_ari_asterisk_get_info_args *args)
 Body parsing function for /asterisk/info.
 
static void ast_ari_asterisk_get_module_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 /asterisk/modules/{moduleName}.
 
static void ast_ari_asterisk_get_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
 
static void ast_ari_asterisk_list_log_channels_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 /asterisk/logging.
 
static void ast_ari_asterisk_list_modules_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 /asterisk/modules.
 
static void ast_ari_asterisk_load_module_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 /asterisk/modules/{moduleName}.
 
static void ast_ari_asterisk_ping_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 /asterisk/ping.
 
static void ast_ari_asterisk_reload_module_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 /asterisk/modules/{moduleName}.
 
static void ast_ari_asterisk_rotate_log_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 /asterisk/logging/{logChannelName}/rotate.
 
static void ast_ari_asterisk_set_global_var_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 /asterisk/variable.
 
int ast_ari_asterisk_set_global_var_parse_body (struct ast_json *body, struct ast_ari_asterisk_set_global_var_args *args)
 Body parsing function for /asterisk/variable.
 
static void ast_ari_asterisk_unload_module_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 /asterisk/modules/{moduleName}.
 
static void ast_ari_asterisk_update_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
 
int ast_ari_asterisk_update_object_parse_body (struct ast_json *body, struct ast_ari_asterisk_update_object_args *args)
 Body parsing function for /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
 
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 - Asterisk 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", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers asterisk
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_config
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_config_dynamic
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_config_dynamic_configClass
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType_id
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_info
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_logging
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_logging_logChannelName
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_logging_logChannelName_rotate
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_modules
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_modules_moduleName
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_ping
 REST handler for /api-docs/asterisk.json.
 
static struct stasis_rest_handlers asterisk_variable
 REST handler for /api-docs/asterisk.json.
 

Detailed Description

Asterisk resources.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file res_ari_asterisk.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 51 of file res_ari_asterisk.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1330 of file res_ari_asterisk.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1330 of file res_ari_asterisk.c.

◆ ast_ari_asterisk_add_log_cb()

static void ast_ari_asterisk_add_log_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 /asterisk/logging/{logChannelName}.

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 827 of file res_ari_asterisk.c.

831{
833 struct ast_variable *i;
834#if defined(AST_DEVMODE)
835 int is_valid;
836 int code;
837#endif /* AST_DEVMODE */
838
839 for (i = get_params; i; i = i->next) {
840 if (strcmp(i->name, "configuration") == 0) {
841 args.configuration = (i->value);
842 } else
843 {}
844 }
845 for (i = path_vars; i; i = i->next) {
846 if (strcmp(i->name, "logChannelName") == 0) {
847 args.log_channel_name = (i->value);
848 } else
849 {}
850 }
853 goto fin;
854 }
855 ast_ari_asterisk_add_log(headers, &args, response);
856#if defined(AST_DEVMODE)
857 code = response->response_code;
858
859 switch (code) {
860 case 0: /* Implementation is still a stub, or the code wasn't set */
861 is_valid = response->message == NULL;
862 break;
863 case 500: /* Internal Server Error */
864 case 501: /* Not Implemented */
865 case 400: /* Bad request body */
866 case 409: /* Log channel could not be created. */
867 is_valid = 1;
868 break;
869 default:
870 if (200 <= code && code <= 299) {
871 is_valid = ast_ari_validate_void(
872 response->message);
873 } else {
874 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}\n", code);
875 is_valid = 0;
876 }
877 }
878
879 if (!is_valid) {
880 ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}\n");
881 ast_ari_response_error(response, 500,
882 "Internal Server Error", "Response validation failed");
883 }
884#endif /* AST_DEVMODE */
885
886fin: __attribute__((unused))
887 return;
888}
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
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_validate_void(struct ast_json *json)
Validator for native Swagger void.
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
int ast_ari_asterisk_add_log_parse_body(struct ast_json *body, struct ast_ari_asterisk_add_log_args *args)
Body parsing function for /asterisk/logging/{logChannelName}.
static struct @519 args
#define NULL
Definition resample.c:96
void ast_ari_asterisk_add_log(struct ast_variable *headers, struct ast_ari_asterisk_add_log_args *args, struct ast_ari_response *response)
Adds a log channel.
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_asterisk_add_log(), ast_ari_asterisk_add_log_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_asterisk_add_log_parse_body()

int ast_ari_asterisk_add_log_parse_body ( struct ast_json body,
struct ast_ari_asterisk_add_log_args args 
)

Body parsing function for /asterisk/logging/{logChannelName}.

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 805 of file res_ari_asterisk.c.

808{
809 struct ast_json *field;
810 /* Parse query parameters out of it */
811 field = ast_json_object_get(body, "configuration");
812 if (field) {
813 args->configuration = ast_json_string_get(field);
814 }
815 return 0;
816}
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_asterisk_add_log_cb().

◆ ast_ari_asterisk_delete_log_cb()

static void ast_ari_asterisk_delete_log_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 /asterisk/logging/{logChannelName}.

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 898 of file res_ari_asterisk.c.

902{
904 struct ast_variable *i;
905#if defined(AST_DEVMODE)
906 int is_valid;
907 int code;
908#endif /* AST_DEVMODE */
909
910 for (i = path_vars; i; i = i->next) {
911 if (strcmp(i->name, "logChannelName") == 0) {
912 args.log_channel_name = (i->value);
913 } else
914 {}
915 }
916 ast_ari_asterisk_delete_log(headers, &args, response);
917#if defined(AST_DEVMODE)
918 code = response->response_code;
919
920 switch (code) {
921 case 0: /* Implementation is still a stub, or the code wasn't set */
922 is_valid = response->message == NULL;
923 break;
924 case 500: /* Internal Server Error */
925 case 501: /* Not Implemented */
926 case 404: /* Log channel does not exist. */
927 is_valid = 1;
928 break;
929 default:
930 if (200 <= code && code <= 299) {
931 is_valid = ast_ari_validate_void(
932 response->message);
933 } else {
934 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}\n", code);
935 is_valid = 0;
936 }
937 }
938
939 if (!is_valid) {
940 ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}\n");
941 ast_ari_response_error(response, 500,
942 "Internal Server Error", "Response validation failed");
943 }
944#endif /* AST_DEVMODE */
945
946fin: __attribute__((unused))
947 return;
948}
void ast_ari_asterisk_delete_log(struct ast_variable *headers, struct ast_ari_asterisk_delete_log_args *args, struct ast_ari_response *response)
Deletes a log channel.

References args, ast_ari_asterisk_delete_log(), 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_asterisk_delete_object_cb()

static void ast_ari_asterisk_delete_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.

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 205 of file res_ari_asterisk.c.

209{
211 struct ast_variable *i;
212#if defined(AST_DEVMODE)
213 int is_valid;
214 int code;
215#endif /* AST_DEVMODE */
216
217 for (i = path_vars; i; i = i->next) {
218 if (strcmp(i->name, "configClass") == 0) {
219 args.config_class = (i->value);
220 } else
221 if (strcmp(i->name, "objectType") == 0) {
222 args.object_type = (i->value);
223 } else
224 if (strcmp(i->name, "id") == 0) {
225 args.id = (i->value);
226 } else
227 {}
228 }
229 ast_ari_asterisk_delete_object(headers, &args, response);
230#if defined(AST_DEVMODE)
231 code = response->response_code;
232
233 switch (code) {
234 case 0: /* Implementation is still a stub, or the code wasn't set */
235 is_valid = response->message == NULL;
236 break;
237 case 500: /* Internal Server Error */
238 case 501: /* Not Implemented */
239 case 403: /* Could not delete object */
240 case 404: /* {configClass|objectType|id} not found */
241 is_valid = 1;
242 break;
243 default:
244 if (200 <= code && code <= 299) {
245 is_valid = ast_ari_validate_void(
246 response->message);
247 } else {
248 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
249 is_valid = 0;
250 }
251 }
252
253 if (!is_valid) {
254 ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
255 ast_ari_response_error(response, 500,
256 "Internal Server Error", "Response validation failed");
257 }
258#endif /* AST_DEVMODE */
259
260fin: __attribute__((unused))
261 return;
262}
void ast_ari_asterisk_delete_object(struct ast_variable *headers, struct ast_ari_asterisk_delete_object_args *args, struct ast_ari_response *response)
Delete a dynamic configuration object.

References args, ast_ari_asterisk_delete_object(), 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_asterisk_get_global_var_cb()

static void ast_ari_asterisk_get_global_var_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 /asterisk/variable.

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 1031 of file res_ari_asterisk.c.

1035{
1037 struct ast_variable *i;
1038#if defined(AST_DEVMODE)
1039 int is_valid;
1040 int code;
1041#endif /* AST_DEVMODE */
1042
1043 for (i = get_params; i; i = i->next) {
1044 if (strcmp(i->name, "variable") == 0) {
1045 args.variable = (i->value);
1046 } else
1047 {}
1048 }
1051 goto fin;
1052 }
1053 ast_ari_asterisk_get_global_var(headers, &args, response);
1054#if defined(AST_DEVMODE)
1055 code = response->response_code;
1056
1057 switch (code) {
1058 case 0: /* Implementation is still a stub, or the code wasn't set */
1059 is_valid = response->message == NULL;
1060 break;
1061 case 500: /* Internal Server Error */
1062 case 501: /* Not Implemented */
1063 case 400: /* Missing variable parameter. */
1064 is_valid = 1;
1065 break;
1066 default:
1067 if (200 <= code && code <= 299) {
1068 is_valid = ast_ari_validate_variable(
1069 response->message);
1070 } else {
1071 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
1072 is_valid = 0;
1073 }
1074 }
1075
1076 if (!is_valid) {
1077 ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
1078 ast_ari_response_error(response, 500,
1079 "Internal Server Error", "Response validation failed");
1080 }
1081#endif /* AST_DEVMODE */
1082
1083fin: __attribute__((unused))
1084 return;
1085}
int ast_ari_validate_variable(struct ast_json *json)
Validator for Variable.
int ast_ari_asterisk_get_global_var_parse_body(struct ast_json *body, struct ast_ari_asterisk_get_global_var_args *args)
Body parsing function for /asterisk/variable.
void ast_ari_asterisk_get_global_var(struct ast_variable *headers, struct ast_ari_asterisk_get_global_var_args *args, struct ast_ari_response *response)
Get the value of a global variable.

References args, ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_global_var_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_variable(), 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_asterisk_get_global_var_parse_body()

int ast_ari_asterisk_get_global_var_parse_body ( struct ast_json body,
struct ast_ari_asterisk_get_global_var_args args 
)

Body parsing function for /asterisk/variable.

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 1009 of file res_ari_asterisk.c.

1012{
1013 struct ast_json *field;
1014 /* Parse query parameters out of it */
1015 field = ast_json_object_get(body, "variable");
1016 if (field) {
1017 args->variable = ast_json_string_get(field);
1018 }
1019 return 0;
1020}

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

Referenced by ast_ari_asterisk_get_global_var_cb().

◆ ast_ari_asterisk_get_info_cb()

static void ast_ari_asterisk_get_info_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 /asterisk/info.

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 310 of file res_ari_asterisk.c.

314{
316 struct ast_variable *i;
317#if defined(AST_DEVMODE)
318 int is_valid;
319 int code;
320#endif /* AST_DEVMODE */
321
322 for (i = get_params; i; i = i->next) {
323 if (strcmp(i->name, "only") == 0) {
324 /* Parse comma separated list */
325 char *vals[MAX_VALS];
326 size_t j;
327
328 args.only_parse = ast_strdup(i->value);
329 if (!args.only_parse) {
331 goto fin;
332 }
333
334 if (strlen(args.only_parse) == 0) {
335 /* ast_app_separate_args can't handle "" */
336 args.only_count = 1;
337 vals[0] = args.only_parse;
338 } else {
339 args.only_count = ast_app_separate_args(
340 args.only_parse, ',', vals,
341 ARRAY_LEN(vals));
342 }
343
344 if (args.only_count == 0) {
346 goto fin;
347 }
348
349 if (args.only_count >= MAX_VALS) {
350 ast_ari_response_error(response, 400,
351 "Bad Request",
352 "Too many values for only");
353 goto fin;
354 }
355
356 args.only = ast_malloc(sizeof(*args.only) * args.only_count);
357 if (!args.only) {
359 goto fin;
360 }
361
362 for (j = 0; j < args.only_count; ++j) {
363 args.only[j] = (vals[j]);
364 }
365 } else
366 {}
367 }
370 goto fin;
371 }
372 ast_ari_asterisk_get_info(headers, &args, response);
373#if defined(AST_DEVMODE)
374 code = response->response_code;
375
376 switch (code) {
377 case 0: /* Implementation is still a stub, or the code wasn't set */
378 is_valid = response->message == NULL;
379 break;
380 case 500: /* Internal Server Error */
381 case 501: /* Not Implemented */
382 is_valid = 1;
383 break;
384 default:
385 if (200 <= code && code <= 299) {
387 response->message);
388 } else {
389 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/info\n", code);
390 is_valid = 0;
391 }
392 }
393
394 if (!is_valid) {
395 ast_log(LOG_ERROR, "Response validation failed for /asterisk/info\n");
396 ast_ari_response_error(response, 500,
397 "Internal Server Error", "Response validation failed");
398 }
399#endif /* AST_DEVMODE */
400
401fin: __attribute__((unused))
402 ast_free(args.only_parse);
403 ast_free(args.only);
404 return;
405}
int ast_ari_validate_asterisk_info(struct ast_json *json)
Validator for AsteriskInfo.
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
#define ast_app_separate_args(a, b, c, d)
#define MAX_VALS
int ast_ari_asterisk_get_info_parse_body(struct ast_json *body, struct ast_ari_asterisk_get_info_args *args)
Body parsing function for /asterisk/info.
void ast_ari_asterisk_get_info(struct ast_variable *headers, struct ast_ari_asterisk_get_info_args *args, struct ast_ari_response *response)
Gets Asterisk system information.
#define ARRAY_LEN(a)
Definition utils.h:706

References args, ARRAY_LEN, ast_app_separate_args, ast_ari_asterisk_get_info(), ast_ari_asterisk_get_info_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_asterisk_info(), ast_free, ast_log, ast_malloc, ast_strdup, LOG_ERROR, MAX_VALS, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_asterisk_get_info_parse_body()

int ast_ari_asterisk_get_info_parse_body ( struct ast_json body,
struct ast_ari_asterisk_get_info_args args 
)

Body parsing function for /asterisk/info.

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 263 of file res_ari_asterisk.c.

266{
267 struct ast_json *field;
268 /* Parse query parameters out of it */
269 field = ast_json_object_get(body, "only");
270 if (field) {
271 /* If they were silly enough to both pass in a query param and a
272 * JSON body, free up the query value.
273 */
274 ast_free(args->only);
275 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
276 /* Multiple param passed as array */
277 size_t i;
278 args->only_count = ast_json_array_size(field);
279 args->only = ast_malloc(sizeof(*args->only) * args->only_count);
280
281 if (!args->only) {
282 return -1;
283 }
284
285 for (i = 0; i < args->only_count; ++i) {
286 args->only[i] = ast_json_string_get(ast_json_array_get(field, i));
287 }
288 } else {
289 /* Multiple param passed as single value */
290 args->only_count = 1;
291 args->only = ast_malloc(sizeof(*args->only) * args->only_count);
292 if (!args->only) {
293 return -1;
294 }
295 args->only[0] = ast_json_string_get(field);
296 }
297 }
298 return 0;
299}
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Definition json.c:78
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition json.c:370
@ AST_JSON_ARRAY
Definition json.h:165
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition json.c:366

References args, ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), and ast_malloc.

Referenced by ast_ari_asterisk_get_info_cb().

◆ ast_ari_asterisk_get_module_cb()

static void ast_ari_asterisk_get_module_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 /asterisk/modules/{moduleName}.

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 519 of file res_ari_asterisk.c.

523{
525 struct ast_variable *i;
526#if defined(AST_DEVMODE)
527 int is_valid;
528 int code;
529#endif /* AST_DEVMODE */
530
531 for (i = path_vars; i; i = i->next) {
532 if (strcmp(i->name, "moduleName") == 0) {
533 args.module_name = (i->value);
534 } else
535 {}
536 }
537 ast_ari_asterisk_get_module(headers, &args, response);
538#if defined(AST_DEVMODE)
539 code = response->response_code;
540
541 switch (code) {
542 case 0: /* Implementation is still a stub, or the code wasn't set */
543 is_valid = response->message == NULL;
544 break;
545 case 500: /* Internal Server Error */
546 case 501: /* Not Implemented */
547 case 404: /* Module could not be found in running modules. */
548 case 409: /* Module information could not be retrieved. */
549 is_valid = 1;
550 break;
551 default:
552 if (200 <= code && code <= 299) {
553 is_valid = ast_ari_validate_module(
554 response->message);
555 } else {
556 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
557 is_valid = 0;
558 }
559 }
560
561 if (!is_valid) {
562 ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
563 ast_ari_response_error(response, 500,
564 "Internal Server Error", "Response validation failed");
565 }
566#endif /* AST_DEVMODE */
567
568fin: __attribute__((unused))
569 return;
570}
int ast_ari_validate_module(struct ast_json *json)
Validator for Module.
void ast_ari_asterisk_get_module(struct ast_variable *headers, struct ast_ari_asterisk_get_module_args *args, struct ast_ari_response *response)
Get Asterisk module information.

References args, ast_ari_asterisk_get_module(), ast_ari_response_error(), ast_ari_validate_module(), 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_asterisk_get_object_cb()

static void ast_ari_asterisk_get_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.

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 62 of file res_ari_asterisk.c.

66{
68 struct ast_variable *i;
69#if defined(AST_DEVMODE)
70 int is_valid;
71 int code;
72#endif /* AST_DEVMODE */
73
74 for (i = path_vars; i; i = i->next) {
75 if (strcmp(i->name, "configClass") == 0) {
76 args.config_class = (i->value);
77 } else
78 if (strcmp(i->name, "objectType") == 0) {
79 args.object_type = (i->value);
80 } else
81 if (strcmp(i->name, "id") == 0) {
82 args.id = (i->value);
83 } else
84 {}
85 }
86 ast_ari_asterisk_get_object(headers, &args, response);
87#if defined(AST_DEVMODE)
88 code = response->response_code;
89
90 switch (code) {
91 case 0: /* Implementation is still a stub, or the code wasn't set */
92 is_valid = response->message == NULL;
93 break;
94 case 500: /* Internal Server Error */
95 case 501: /* Not Implemented */
96 case 404: /* {configClass|objectType|id} not found */
97 is_valid = 1;
98 break;
99 default:
100 if (200 <= code && code <= 299) {
101 is_valid = ast_ari_validate_list(response->message,
103 } else {
104 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
105 is_valid = 0;
106 }
107 }
108
109 if (!is_valid) {
110 ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
111 ast_ari_response_error(response, 500,
112 "Internal Server Error", "Response validation failed");
113 }
114#endif /* AST_DEVMODE */
115
116fin: __attribute__((unused))
117 return;
118}
ari_validator ast_ari_validate_config_tuple_fn(void)
Function pointer to ast_ari_validate_config_tuple().
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
void ast_ari_asterisk_get_object(struct ast_variable *headers, struct ast_ari_asterisk_get_object_args *args, struct ast_ari_response *response)
Retrieve a dynamic configuration object.

References args, ast_ari_asterisk_get_object(), ast_ari_response_error(), ast_ari_validate_config_tuple_fn(), ast_ari_validate_list(), 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_asterisk_list_log_channels_cb()

static void ast_ari_asterisk_list_log_channels_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 /asterisk/logging.

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 762 of file res_ari_asterisk.c.

766{
768#if defined(AST_DEVMODE)
769 int is_valid;
770 int code;
771#endif /* AST_DEVMODE */
772
773 ast_ari_asterisk_list_log_channels(headers, &args, response);
774#if defined(AST_DEVMODE)
775 code = response->response_code;
776
777 switch (code) {
778 case 0: /* Implementation is still a stub, or the code wasn't set */
779 is_valid = response->message == NULL;
780 break;
781 case 500: /* Internal Server Error */
782 case 501: /* Not Implemented */
783 is_valid = 1;
784 break;
785 default:
786 if (200 <= code && code <= 299) {
787 is_valid = ast_ari_validate_list(response->message,
789 } else {
790 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging\n", code);
791 is_valid = 0;
792 }
793 }
794
795 if (!is_valid) {
796 ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging\n");
797 ast_ari_response_error(response, 500,
798 "Internal Server Error", "Response validation failed");
799 }
800#endif /* AST_DEVMODE */
801
802fin: __attribute__((unused))
803 return;
804}
ari_validator ast_ari_validate_log_channel_fn(void)
Function pointer to ast_ari_validate_log_channel().
void ast_ari_asterisk_list_log_channels(struct ast_variable *headers, struct ast_ari_asterisk_list_log_channels_args *args, struct ast_ari_response *response)
Gets Asterisk log channel information.

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

◆ ast_ari_asterisk_list_modules_cb()

static void ast_ari_asterisk_list_modules_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 /asterisk/modules.

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 467 of file res_ari_asterisk.c.

471{
473#if defined(AST_DEVMODE)
474 int is_valid;
475 int code;
476#endif /* AST_DEVMODE */
477
478 ast_ari_asterisk_list_modules(headers, &args, response);
479#if defined(AST_DEVMODE)
480 code = response->response_code;
481
482 switch (code) {
483 case 0: /* Implementation is still a stub, or the code wasn't set */
484 is_valid = response->message == NULL;
485 break;
486 case 500: /* Internal Server Error */
487 case 501: /* Not Implemented */
488 is_valid = 1;
489 break;
490 default:
491 if (200 <= code && code <= 299) {
492 is_valid = ast_ari_validate_list(response->message,
494 } else {
495 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules\n", code);
496 is_valid = 0;
497 }
498 }
499
500 if (!is_valid) {
501 ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules\n");
502 ast_ari_response_error(response, 500,
503 "Internal Server Error", "Response validation failed");
504 }
505#endif /* AST_DEVMODE */
506
507fin: __attribute__((unused))
508 return;
509}
ari_validator ast_ari_validate_module_fn(void)
Function pointer to ast_ari_validate_module().
void ast_ari_asterisk_list_modules(struct ast_variable *headers, struct ast_ari_asterisk_list_modules_args *args, struct ast_ari_response *response)
List Asterisk modules.

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

◆ ast_ari_asterisk_load_module_cb()

static void ast_ari_asterisk_load_module_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 /asterisk/modules/{moduleName}.

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 580 of file res_ari_asterisk.c.

584{
586 struct ast_variable *i;
587#if defined(AST_DEVMODE)
588 int is_valid;
589 int code;
590#endif /* AST_DEVMODE */
591
592 for (i = path_vars; i; i = i->next) {
593 if (strcmp(i->name, "moduleName") == 0) {
594 args.module_name = (i->value);
595 } else
596 {}
597 }
598 ast_ari_asterisk_load_module(headers, &args, response);
599#if defined(AST_DEVMODE)
600 code = response->response_code;
601
602 switch (code) {
603 case 0: /* Implementation is still a stub, or the code wasn't set */
604 is_valid = response->message == NULL;
605 break;
606 case 500: /* Internal Server Error */
607 case 501: /* Not Implemented */
608 case 409: /* Module could not be loaded. */
609 is_valid = 1;
610 break;
611 default:
612 if (200 <= code && code <= 299) {
613 is_valid = ast_ari_validate_void(
614 response->message);
615 } else {
616 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
617 is_valid = 0;
618 }
619 }
620
621 if (!is_valid) {
622 ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
623 ast_ari_response_error(response, 500,
624 "Internal Server Error", "Response validation failed");
625 }
626#endif /* AST_DEVMODE */
627
628fin: __attribute__((unused))
629 return;
630}
void ast_ari_asterisk_load_module(struct ast_variable *headers, struct ast_ari_asterisk_load_module_args *args, struct ast_ari_response *response)
Load an Asterisk module.

References args, ast_ari_asterisk_load_module(), 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_asterisk_ping_cb()

static void ast_ari_asterisk_ping_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 /asterisk/ping.

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 415 of file res_ari_asterisk.c.

419{
421#if defined(AST_DEVMODE)
422 int is_valid;
423 int code;
424#endif /* AST_DEVMODE */
425
426 ast_ari_asterisk_ping(headers, &args, response);
427#if defined(AST_DEVMODE)
428 code = response->response_code;
429
430 switch (code) {
431 case 0: /* Implementation is still a stub, or the code wasn't set */
432 is_valid = response->message == NULL;
433 break;
434 case 500: /* Internal Server Error */
435 case 501: /* Not Implemented */
436 is_valid = 1;
437 break;
438 default:
439 if (200 <= code && code <= 299) {
441 response->message);
442 } else {
443 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/ping\n", code);
444 is_valid = 0;
445 }
446 }
447
448 if (!is_valid) {
449 ast_log(LOG_ERROR, "Response validation failed for /asterisk/ping\n");
450 ast_ari_response_error(response, 500,
451 "Internal Server Error", "Response validation failed");
452 }
453#endif /* AST_DEVMODE */
454
455fin: __attribute__((unused))
456 return;
457}
int ast_ari_validate_asterisk_ping(struct ast_json *json)
Validator for AsteriskPing.
void ast_ari_asterisk_ping(struct ast_variable *headers, struct ast_ari_asterisk_ping_args *args, struct ast_ari_response *response)
Response pong message.

References args, ast_ari_asterisk_ping(), ast_ari_response_error(), ast_ari_validate_asterisk_ping(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

◆ ast_ari_asterisk_reload_module_cb()

static void ast_ari_asterisk_reload_module_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 /asterisk/modules/{moduleName}.

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 701 of file res_ari_asterisk.c.

705{
707 struct ast_variable *i;
708#if defined(AST_DEVMODE)
709 int is_valid;
710 int code;
711#endif /* AST_DEVMODE */
712
713 for (i = path_vars; i; i = i->next) {
714 if (strcmp(i->name, "moduleName") == 0) {
715 args.module_name = (i->value);
716 } else
717 {}
718 }
719 ast_ari_asterisk_reload_module(headers, &args, response);
720#if defined(AST_DEVMODE)
721 code = response->response_code;
722
723 switch (code) {
724 case 0: /* Implementation is still a stub, or the code wasn't set */
725 is_valid = response->message == NULL;
726 break;
727 case 500: /* Internal Server Error */
728 case 501: /* Not Implemented */
729 case 404: /* Module not found in running modules. */
730 case 409: /* Module could not be reloaded. */
731 is_valid = 1;
732 break;
733 default:
734 if (200 <= code && code <= 299) {
735 is_valid = ast_ari_validate_void(
736 response->message);
737 } else {
738 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
739 is_valid = 0;
740 }
741 }
742
743 if (!is_valid) {
744 ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
745 ast_ari_response_error(response, 500,
746 "Internal Server Error", "Response validation failed");
747 }
748#endif /* AST_DEVMODE */
749
750fin: __attribute__((unused))
751 return;
752}
void ast_ari_asterisk_reload_module(struct ast_variable *headers, struct ast_ari_asterisk_reload_module_args *args, struct ast_ari_response *response)
Reload an Asterisk module.

References args, ast_ari_asterisk_reload_module(), 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_asterisk_rotate_log_cb()

static void ast_ari_asterisk_rotate_log_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 /asterisk/logging/{logChannelName}/rotate.

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 958 of file res_ari_asterisk.c.

962{
964 struct ast_variable *i;
965#if defined(AST_DEVMODE)
966 int is_valid;
967 int code;
968#endif /* AST_DEVMODE */
969
970 for (i = path_vars; i; i = i->next) {
971 if (strcmp(i->name, "logChannelName") == 0) {
972 args.log_channel_name = (i->value);
973 } else
974 {}
975 }
976 ast_ari_asterisk_rotate_log(headers, &args, response);
977#if defined(AST_DEVMODE)
978 code = response->response_code;
979
980 switch (code) {
981 case 0: /* Implementation is still a stub, or the code wasn't set */
982 is_valid = response->message == NULL;
983 break;
984 case 500: /* Internal Server Error */
985 case 501: /* Not Implemented */
986 case 404: /* Log channel does not exist. */
987 is_valid = 1;
988 break;
989 default:
990 if (200 <= code && code <= 299) {
991 is_valid = ast_ari_validate_void(
992 response->message);
993 } else {
994 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/logging/{logChannelName}/rotate\n", code);
995 is_valid = 0;
996 }
997 }
998
999 if (!is_valid) {
1000 ast_log(LOG_ERROR, "Response validation failed for /asterisk/logging/{logChannelName}/rotate\n");
1001 ast_ari_response_error(response, 500,
1002 "Internal Server Error", "Response validation failed");
1003 }
1004#endif /* AST_DEVMODE */
1005
1006fin: __attribute__((unused))
1007 return;
1008}
void ast_ari_asterisk_rotate_log(struct ast_variable *headers, struct ast_ari_asterisk_rotate_log_args *args, struct ast_ari_response *response)
Rotates a log channel.

References args, ast_ari_asterisk_rotate_log(), 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_asterisk_set_global_var_cb()

static void ast_ari_asterisk_set_global_var_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 /asterisk/variable.

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 1112 of file res_ari_asterisk.c.

1116{
1118 struct ast_variable *i;
1119#if defined(AST_DEVMODE)
1120 int is_valid;
1121 int code;
1122#endif /* AST_DEVMODE */
1123
1124 for (i = get_params; i; i = i->next) {
1125 if (strcmp(i->name, "variable") == 0) {
1126 args.variable = (i->value);
1127 } else
1128 if (strcmp(i->name, "value") == 0) {
1129 args.value = (i->value);
1130 } else
1131 {}
1132 }
1135 goto fin;
1136 }
1137 ast_ari_asterisk_set_global_var(headers, &args, response);
1138#if defined(AST_DEVMODE)
1139 code = response->response_code;
1140
1141 switch (code) {
1142 case 0: /* Implementation is still a stub, or the code wasn't set */
1143 is_valid = response->message == NULL;
1144 break;
1145 case 500: /* Internal Server Error */
1146 case 501: /* Not Implemented */
1147 case 400: /* Missing variable parameter. */
1148 is_valid = 1;
1149 break;
1150 default:
1151 if (200 <= code && code <= 299) {
1152 is_valid = ast_ari_validate_void(
1153 response->message);
1154 } else {
1155 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
1156 is_valid = 0;
1157 }
1158 }
1159
1160 if (!is_valid) {
1161 ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
1162 ast_ari_response_error(response, 500,
1163 "Internal Server Error", "Response validation failed");
1164 }
1165#endif /* AST_DEVMODE */
1166
1167fin: __attribute__((unused))
1168 return;
1169}
int ast_ari_asterisk_set_global_var_parse_body(struct ast_json *body, struct ast_ari_asterisk_set_global_var_args *args)
Body parsing function for /asterisk/variable.
void ast_ari_asterisk_set_global_var(struct ast_variable *headers, struct ast_ari_asterisk_set_global_var_args *args, struct ast_ari_response *response)
Set the value of a global variable.

References args, ast_ari_asterisk_set_global_var(), ast_ari_asterisk_set_global_var_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_asterisk_set_global_var_parse_body()

int ast_ari_asterisk_set_global_var_parse_body ( struct ast_json body,
struct ast_ari_asterisk_set_global_var_args args 
)

Body parsing function for /asterisk/variable.

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 1086 of file res_ari_asterisk.c.

1089{
1090 struct ast_json *field;
1091 /* Parse query parameters out of it */
1092 field = ast_json_object_get(body, "variable");
1093 if (field) {
1094 args->variable = ast_json_string_get(field);
1095 }
1096 field = ast_json_object_get(body, "value");
1097 if (field) {
1098 args->value = ast_json_string_get(field);
1099 }
1100 return 0;
1101}

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

Referenced by ast_ari_asterisk_set_global_var_cb().

◆ ast_ari_asterisk_unload_module_cb()

static void ast_ari_asterisk_unload_module_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 /asterisk/modules/{moduleName}.

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 640 of file res_ari_asterisk.c.

644{
646 struct ast_variable *i;
647#if defined(AST_DEVMODE)
648 int is_valid;
649 int code;
650#endif /* AST_DEVMODE */
651
652 for (i = path_vars; i; i = i->next) {
653 if (strcmp(i->name, "moduleName") == 0) {
654 args.module_name = (i->value);
655 } else
656 {}
657 }
658 ast_ari_asterisk_unload_module(headers, &args, response);
659#if defined(AST_DEVMODE)
660 code = response->response_code;
661
662 switch (code) {
663 case 0: /* Implementation is still a stub, or the code wasn't set */
664 is_valid = response->message == NULL;
665 break;
666 case 500: /* Internal Server Error */
667 case 501: /* Not Implemented */
668 case 404: /* Module not found in running modules. */
669 case 409: /* Module could not be unloaded. */
670 is_valid = 1;
671 break;
672 default:
673 if (200 <= code && code <= 299) {
674 is_valid = ast_ari_validate_void(
675 response->message);
676 } else {
677 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/modules/{moduleName}\n", code);
678 is_valid = 0;
679 }
680 }
681
682 if (!is_valid) {
683 ast_log(LOG_ERROR, "Response validation failed for /asterisk/modules/{moduleName}\n");
684 ast_ari_response_error(response, 500,
685 "Internal Server Error", "Response validation failed");
686 }
687#endif /* AST_DEVMODE */
688
689fin: __attribute__((unused))
690 return;
691}
void ast_ari_asterisk_unload_module(struct ast_variable *headers, struct ast_ari_asterisk_unload_module_args *args, struct ast_ari_response *response)
Unload an Asterisk module.

References args, ast_ari_asterisk_unload_module(), 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_asterisk_update_object_cb()

static void ast_ari_asterisk_update_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.

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 136 of file res_ari_asterisk.c.

140{
142 struct ast_variable *i;
143#if defined(AST_DEVMODE)
144 int is_valid;
145 int code;
146#endif /* AST_DEVMODE */
147
148 for (i = path_vars; i; i = i->next) {
149 if (strcmp(i->name, "configClass") == 0) {
150 args.config_class = (i->value);
151 } else
152 if (strcmp(i->name, "objectType") == 0) {
153 args.object_type = (i->value);
154 } else
155 if (strcmp(i->name, "id") == 0) {
156 args.id = (i->value);
157 } else
158 {}
159 }
160 args.fields = body;
161 ast_ari_asterisk_update_object(headers, &args, response);
162#if defined(AST_DEVMODE)
163 code = response->response_code;
164
165 switch (code) {
166 case 0: /* Implementation is still a stub, or the code wasn't set */
167 is_valid = response->message == NULL;
168 break;
169 case 500: /* Internal Server Error */
170 case 501: /* Not Implemented */
171 case 400: /* Bad request body */
172 case 403: /* Could not create or update object */
173 case 404: /* {configClass|objectType} not found */
174 is_valid = 1;
175 break;
176 default:
177 if (200 <= code && code <= 299) {
178 is_valid = ast_ari_validate_list(response->message,
180 } else {
181 ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n", code);
182 is_valid = 0;
183 }
184 }
185
186 if (!is_valid) {
187 ast_log(LOG_ERROR, "Response validation failed for /asterisk/config/dynamic/{configClass}/{objectType}/{id}\n");
188 ast_ari_response_error(response, 500,
189 "Internal Server Error", "Response validation failed");
190 }
191#endif /* AST_DEVMODE */
192
193fin: __attribute__((unused))
194 return;
195}
void ast_ari_asterisk_update_object(struct ast_variable *headers, struct ast_ari_asterisk_update_object_args *args, struct ast_ari_response *response)
Create or update a dynamic configuration object.

References args, ast_ari_asterisk_update_object(), ast_ari_response_error(), ast_ari_validate_config_tuple_fn(), ast_ari_validate_list(), 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_asterisk_update_object_parse_body()

int ast_ari_asterisk_update_object_parse_body ( struct ast_json body,
struct ast_ari_asterisk_update_object_args args 
)

Body parsing function for /asterisk/config/dynamic/{configClass}/{objectType}/{id}.

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 119 of file res_ari_asterisk.c.

122{
123 /* Parse query parameters out of it */
124 return 0;
125}

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 1330 of file res_ari_asterisk.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 1311 of file res_ari_asterisk.c.

1312{
1313 int res = 0;
1314
1315
1317 if (res) {
1318 unload_module();
1320 }
1321
1323}
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 asterisk
REST handler for /api-docs/asterisk.json.
static int unload_module(void)

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1305 of file res_ari_asterisk.c.

1306{
1308 return 0;
1309}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:155

References ast_ari_remove_handler(), and asterisk.

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 - Asterisk 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", }
static

Definition at line 1330 of file res_ari_asterisk.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1330 of file res_ari_asterisk.c.

◆ asterisk

struct stasis_rest_handlers asterisk
static

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

Definition at line 1297 of file res_ari_asterisk.c.

1297 {
1298 .path_segment = "asterisk",
1299 .callbacks = {
1300 },
1301 .num_children = 6,
1303};
static struct stasis_rest_handlers asterisk_logging
REST handler for /api-docs/asterisk.json.
static struct stasis_rest_handlers asterisk_ping
REST handler for /api-docs/asterisk.json.
static struct stasis_rest_handlers asterisk_modules
REST handler for /api-docs/asterisk.json.
static struct stasis_rest_handlers asterisk_info
REST handler for /api-docs/asterisk.json.
static struct stasis_rest_handlers asterisk_variable
REST handler for /api-docs/asterisk.json.
static struct stasis_rest_handlers asterisk_config
REST handler for /api-docs/asterisk.json.

Referenced by load_module(), and unload_module().

◆ asterisk_config

struct stasis_rest_handlers asterisk_config
static

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

Definition at line 1210 of file res_ari_asterisk.c.

1210 {
1211 .path_segment = "config",
1212 .callbacks = {
1213 },
1214 .num_children = 1,
1215 .children = { &asterisk_config_dynamic, }
1216};
static struct stasis_rest_handlers asterisk_config_dynamic
REST handler for /api-docs/asterisk.json.

◆ asterisk_config_dynamic

struct stasis_rest_handlers asterisk_config_dynamic
static

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

Definition at line 1202 of file res_ari_asterisk.c.

1202 {
1203 .path_segment = "dynamic",
1204 .callbacks = {
1205 },
1206 .num_children = 1,
1207 .children = { &asterisk_config_dynamic_configClass, }
1208};
static struct stasis_rest_handlers asterisk_config_dynamic_configClass
REST handler for /api-docs/asterisk.json.

◆ asterisk_config_dynamic_configClass

struct stasis_rest_handlers asterisk_config_dynamic_configClass
static

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

Definition at line 1193 of file res_ari_asterisk.c.

1193 {
1194 .path_segment = "configClass",
1195 .is_wildcard = 1,
1196 .callbacks = {
1197 },
1198 .num_children = 1,
1200};
static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType
REST handler for /api-docs/asterisk.json.

◆ asterisk_config_dynamic_configClass_objectType

struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType
static

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

Definition at line 1184 of file res_ari_asterisk.c.

1184 {
1185 .path_segment = "objectType",
1186 .is_wildcard = 1,
1187 .callbacks = {
1188 },
1189 .num_children = 1,
1191};
static struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType_id
REST handler for /api-docs/asterisk.json.

◆ asterisk_config_dynamic_configClass_objectType_id

struct stasis_rest_handlers asterisk_config_dynamic_configClass_objectType_id
static

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

Definition at line 1172 of file res_ari_asterisk.c.

1172 {
1173 .path_segment = "id",
1174 .is_wildcard = 1,
1175 .callbacks = {
1179 },
1180 .num_children = 0,
1181 .children = { }
1182};
@ AST_HTTP_PUT
Definition http.h:63
@ AST_HTTP_DELETE
Definition http.h:64
@ AST_HTTP_GET
Definition http.h:60
static void ast_ari_asterisk_update_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
static void ast_ari_asterisk_delete_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.
static void ast_ari_asterisk_get_object_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 /asterisk/config/dynamic/{configClass}/{objectType}/{id}.

◆ asterisk_info

struct stasis_rest_handlers asterisk_info
static

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

Definition at line 1218 of file res_ari_asterisk.c.

1218 {
1219 .path_segment = "info",
1220 .callbacks = {
1222 },
1223 .num_children = 0,
1224 .children = { }
1225};
static void ast_ari_asterisk_get_info_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 /asterisk/info.

◆ asterisk_logging

struct stasis_rest_handlers asterisk_logging
static

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

Definition at line 1278 of file res_ari_asterisk.c.

1278 {
1279 .path_segment = "logging",
1280 .callbacks = {
1282 },
1283 .num_children = 1,
1284 .children = { &asterisk_logging_logChannelName, }
1285};
static void ast_ari_asterisk_list_log_channels_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 /asterisk/logging.
static struct stasis_rest_handlers asterisk_logging_logChannelName
REST handler for /api-docs/asterisk.json.

◆ asterisk_logging_logChannelName

struct stasis_rest_handlers asterisk_logging_logChannelName
static

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

Definition at line 1267 of file res_ari_asterisk.c.

1267 {
1268 .path_segment = "logChannelName",
1269 .is_wildcard = 1,
1270 .callbacks = {
1273 },
1274 .num_children = 1,
1276};
@ AST_HTTP_POST
Definition http.h:61
static struct stasis_rest_handlers asterisk_logging_logChannelName_rotate
REST handler for /api-docs/asterisk.json.
static void ast_ari_asterisk_delete_log_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 /asterisk/logging/{logChannelName}.
static void ast_ari_asterisk_add_log_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 /asterisk/logging/{logChannelName}.

◆ asterisk_logging_logChannelName_rotate

struct stasis_rest_handlers asterisk_logging_logChannelName_rotate
static

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

Definition at line 1258 of file res_ari_asterisk.c.

1258 {
1259 .path_segment = "rotate",
1260 .callbacks = {
1262 },
1263 .num_children = 0,
1264 .children = { }
1265};
static void ast_ari_asterisk_rotate_log_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 /asterisk/logging/{logChannelName}/rotate.

◆ asterisk_modules

struct stasis_rest_handlers asterisk_modules
static

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

Definition at line 1249 of file res_ari_asterisk.c.

1249 {
1250 .path_segment = "modules",
1251 .callbacks = {
1253 },
1254 .num_children = 1,
1255 .children = { &asterisk_modules_moduleName, }
1256};
static struct stasis_rest_handlers asterisk_modules_moduleName
REST handler for /api-docs/asterisk.json.
static void ast_ari_asterisk_list_modules_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 /asterisk/modules.

◆ asterisk_modules_moduleName

struct stasis_rest_handlers asterisk_modules_moduleName
static

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

Definition at line 1236 of file res_ari_asterisk.c.

1236 {
1237 .path_segment = "moduleName",
1238 .is_wildcard = 1,
1239 .callbacks = {
1244 },
1245 .num_children = 0,
1246 .children = { }
1247};
static void ast_ari_asterisk_reload_module_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 /asterisk/modules/{moduleName}.
static void ast_ari_asterisk_unload_module_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 /asterisk/modules/{moduleName}.
static void ast_ari_asterisk_get_module_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 /asterisk/modules/{moduleName}.
static void ast_ari_asterisk_load_module_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 /asterisk/modules/{moduleName}.

◆ asterisk_ping

struct stasis_rest_handlers asterisk_ping
static

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

Definition at line 1227 of file res_ari_asterisk.c.

1227 {
1228 .path_segment = "ping",
1229 .callbacks = {
1231 },
1232 .num_children = 0,
1233 .children = { }
1234};
static void ast_ari_asterisk_ping_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 /asterisk/ping.

◆ asterisk_variable

struct stasis_rest_handlers asterisk_variable
static

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

Definition at line 1287 of file res_ari_asterisk.c.

1287 {
1288 .path_segment = "variable",
1289 .callbacks = {
1292 },
1293 .num_children = 0,
1294 .children = { }
1295};
static void ast_ari_asterisk_get_global_var_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 /asterisk/variable.
static void ast_ari_asterisk_set_global_var_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 /asterisk/variable.