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

Sound resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_sounds.h"
Include dependency graph for res_ari_sounds.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_sounds_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 /sounds/{soundId}.
 
static void ast_ari_sounds_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 /sounds.
 
int ast_ari_sounds_list_parse_body (struct ast_json *body, struct ast_ari_sounds_list_args *args)
 Body parsing function for /sounds.
 
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 - Sound 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 sounds
 REST handler for /api-docs/sounds.json.
 
static struct stasis_rest_handlers sounds_soundId
 REST handler for /api-docs/sounds.json.
 

Detailed Description

Sound resources.

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

Definition in file res_ari_sounds.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 51 of file res_ari_sounds.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 241 of file res_ari_sounds.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 241 of file res_ari_sounds.c.

◆ ast_ari_sounds_get_cb()

static void ast_ari_sounds_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 /sounds/{soundId}.

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 145 of file res_ari_sounds.c.

149{
150 struct ast_ari_sounds_get_args args = {};
151 struct ast_variable *i;
152#if defined(AST_DEVMODE)
153 int is_valid;
154 int code;
155#endif /* AST_DEVMODE */
156
157 for (i = path_vars; i; i = i->next) {
158 if (strcmp(i->name, "soundId") == 0) {
159 args.sound_id = (i->value);
160 } else
161 {}
162 }
163 ast_ari_sounds_get(headers, &args, response);
164#if defined(AST_DEVMODE)
165 code = response->response_code;
166
167 switch (code) {
168 case 0: /* Implementation is still a stub, or the code wasn't set */
169 is_valid = response->message == NULL;
170 break;
171 case 500: /* Internal Server Error */
172 case 501: /* Not Implemented */
173 is_valid = 1;
174 break;
175 default:
176 if (200 <= code && code <= 299) {
177 is_valid = ast_ari_validate_sound(
178 response->message);
179 } else {
180 ast_log(LOG_ERROR, "Invalid error response %d for /sounds/{soundId}\n", code);
181 is_valid = 0;
182 }
183 }
184
185 if (!is_valid) {
186 ast_log(LOG_ERROR, "Response validation failed for /sounds/{soundId}\n");
187 ast_ari_response_error(response, 500,
188 "Internal Server Error", "Response validation failed");
189 }
190#endif /* AST_DEVMODE */
191
192fin: __attribute__((unused))
193 return;
194}
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_sound(struct ast_json *json)
Validator for Sound.
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
static struct @519 args
#define NULL
Definition resample.c:96
void ast_ari_sounds_get(struct ast_variable *headers, struct ast_ari_sounds_get_args *args, struct ast_ari_response *response)
Get a sound's details.
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_response_error(), ast_ari_sounds_get(), ast_ari_validate_sound(), 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_sounds_list_cb()

static void ast_ari_sounds_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 /sounds.

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 79 of file res_ari_sounds.c.

83{
85 struct ast_variable *i;
86#if defined(AST_DEVMODE)
87 int is_valid;
88 int code;
89#endif /* AST_DEVMODE */
90
91 for (i = get_params; i; i = i->next) {
92 if (strcmp(i->name, "lang") == 0) {
93 args.lang = (i->value);
94 } else
95 if (strcmp(i->name, "format") == 0) {
96 args.format = (i->value);
97 } else
98 {}
99 }
102 goto fin;
103 }
104 ast_ari_sounds_list(headers, &args, response);
105#if defined(AST_DEVMODE)
106 code = response->response_code;
107
108 switch (code) {
109 case 0: /* Implementation is still a stub, or the code wasn't set */
110 is_valid = response->message == NULL;
111 break;
112 case 500: /* Internal Server Error */
113 case 501: /* Not Implemented */
114 is_valid = 1;
115 break;
116 default:
117 if (200 <= code && code <= 299) {
118 is_valid = ast_ari_validate_list(response->message,
120 } else {
121 ast_log(LOG_ERROR, "Invalid error response %d for /sounds\n", code);
122 is_valid = 0;
123 }
124 }
125
126 if (!is_valid) {
127 ast_log(LOG_ERROR, "Response validation failed for /sounds\n");
128 ast_ari_response_error(response, 500,
129 "Internal Server Error", "Response validation failed");
130 }
131#endif /* AST_DEVMODE */
132
133fin: __attribute__((unused))
134 return;
135}
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
ari_validator ast_ari_validate_sound_fn(void)
Function pointer to ast_ari_validate_sound().
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
int ast_ari_sounds_list_parse_body(struct ast_json *body, struct ast_ari_sounds_list_args *args)
Body parsing function for /sounds.
void ast_ari_sounds_list(struct ast_variable *headers, struct ast_ari_sounds_list_args *args, struct ast_ari_response *response)
List all sounds.

References args, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_sounds_list(), ast_ari_sounds_list_parse_body(), ast_ari_validate_list(), ast_ari_validate_sound_fn(), 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_sounds_list_parse_body()

int ast_ari_sounds_list_parse_body ( struct ast_json body,
struct ast_ari_sounds_list_args args 
)

Body parsing function for /sounds.

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 53 of file res_ari_sounds.c.

56{
57 struct ast_json *field;
58 /* Parse query parameters out of it */
59 field = ast_json_object_get(body, "lang");
60 if (field) {
61 args->lang = ast_json_string_get(field);
62 }
63 field = ast_json_object_get(body, "format");
64 if (field) {
65 args->format = ast_json_string_get(field);
66 }
67 return 0;
68}
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_sounds_list_cb().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 241 of file res_ari_sounds.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 222 of file res_ari_sounds.c.

223{
224 int res = 0;
225
226
228 if (res) {
231 }
232
234}
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 sounds
REST handler for /api-docs/sounds.json.
static int unload_module(void)

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 216 of file res_ari_sounds.c.

217{
219 return 0;
220}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition res_ari.c:155

References ast_ari_remove_handler(), and sounds.

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 - Sound 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 241 of file res_ari_sounds.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 241 of file res_ari_sounds.c.

◆ sounds

struct stasis_rest_handlers sounds
static

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

Definition at line 207 of file res_ari_sounds.c.

207 {
208 .path_segment = "sounds",
209 .callbacks = {
211 },
212 .num_children = 1,
213 .children = { &sounds_soundId, }
214};
@ AST_HTTP_GET
Definition http.h:60
static struct stasis_rest_handlers sounds_soundId
REST handler for /api-docs/sounds.json.
static void ast_ari_sounds_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 /sounds.

Referenced by bridge_profile_sounds_alloc(), bridge_profile_sounds_destroy_cb(), bridge_template_handler(), load_module(), set_sound(), and unload_module().

◆ sounds_soundId

struct stasis_rest_handlers sounds_soundId
static

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

Definition at line 197 of file res_ari_sounds.c.

197 {
198 .path_segment = "soundId",
199 .is_wildcard = 1,
200 .callbacks = {
202 },
203 .num_children = 0,
204 .children = { }
205};
static void ast_ari_sounds_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 /sounds/{soundId}.