Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions
resource_sounds.h File Reference

Generated file - declares stubs to be implemented in res/ari/resource_sounds.c. More...

#include "asterisk/ari.h"
Include dependency graph for resource_sounds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_sounds_get_args
 
struct  ast_ari_sounds_list_args
 

Functions

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. More...
 
void ast_ari_sounds_list (struct ast_variable *headers, struct ast_ari_sounds_list_args *args, struct ast_ari_response *response)
 List all sounds. More...
 
int ast_ari_sounds_list_parse_body (struct ast_json *body, struct ast_ari_sounds_list_args *args)
 Body parsing function for /sounds. More...
 

Detailed Description

Generated file - declares stubs to be implemented in res/ari/resource_sounds.c.

Sound resources

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

Definition in file resource_sounds.h.

Function Documentation

◆ ast_ari_sounds_get()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 220 of file resource_sounds.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_ok(), ast_sounds_get_index_for_file(), create_sound_blob(), NULL, and ast_ari_sounds_get_args::sound_id.

Referenced by ast_ari_sounds_get_cb().

223 {
224  struct ast_json *sound_blob;
225  struct ast_media_index *sounds_index = ast_sounds_get_index_for_file(args->sound_id);
226 
227  sound_blob = create_sound_blob(args->sound_id, NULL, sounds_index);
228  ao2_cleanup(sounds_index);
229  if (!sound_blob) {
230  ast_ari_response_error(response, 404, "Not Found", "Sound not found");
231  return;
232  }
233 
234  ast_ari_response_ok(response, sound_blob);
235 }
#define NULL
Definition: resample.c:96
static struct ast_json * create_sound_blob(const char *filename, struct ast_ari_sounds_list_args *args, struct ast_media_index *sounds_index)
Generate a Sound structure as documented in sounds.json for the specified filename.
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
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:259
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).
struct ast_media_index * ast_sounds_get_index_for_file(const char *filename)
Get the index for a specific sound file.
Definition: sounds.c:313

◆ ast_ari_sounds_list()

void ast_ari_sounds_list ( struct ast_variable headers,
struct ast_ari_sounds_list_args args,
struct ast_ari_response response 
)

List all sounds.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 180 of file resource_sounds.c.

References ao2_callback_data, ao2_cleanup, append_sound_cb(), args, sounds_cb_data::args, ast_ari_response_error(), ast_ari_response_ok(), ast_json_array_create(), ast_json_array_size(), ast_json_unref(), ast_media_get_media(), ast_sounds_get_index(), NULL, OBJ_NODATA, and RAII_VAR.

Referenced by ast_ari_sounds_list_cb().

183 {
184  RAII_VAR(struct ao2_container *, sound_files, NULL, ao2_cleanup);
185  struct ast_json *sounds_blob;
186  RAII_VAR(struct ast_media_index *, sounds_index, ast_sounds_get_index(), ao2_cleanup);
187  struct sounds_cb_data cb_data = {
188  .args = args,
189  .index = sounds_index,
190  };
191 
192  if (!sounds_index) {
193  ast_ari_response_error(response, 500, "Internal Error", "Sounds index not available");
194  return;
195  }
196 
197  sound_files = ast_media_get_media(sounds_index);
198  if (!sound_files) {
199  ast_ari_response_error(response, 500, "Internal Error", "Allocation Error");
200  return;
201  }
202 
203  sounds_blob = ast_json_array_create();
204  if (!sounds_blob) {
205  ast_ari_response_error(response, 500, "Internal Error", "Allocation Error");
206  return;
207  }
208 
209  ao2_callback_data(sound_files, OBJ_NODATA, append_sound_cb, sounds_blob, &cb_data);
210 
211  if (!ast_json_array_size(sounds_blob)) {
212  ast_ari_response_error(response, 404, "Not Found", "No sounds found that matched the query");
213  ast_json_unref(sounds_blob);
214  return;
215  }
216 
217  ast_ari_response_ok(response, sounds_blob);
218 }
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ao2_container * ast_media_get_media(struct ast_media_index *index)
Get the a container of all media available on the system.
Definition: media_index.c:307
const char * args
#define NULL
Definition: resample.c:96
struct ast_media_index * ast_sounds_get_index(void)
Get the sounds index.
Definition: sounds.c:308
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1743
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:259
struct ast_ari_sounds_list_args * args
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
Abstract JSON element (object, array, string, int, ...).
static int append_sound_cb(void *obj, void *arg, void *data, int flags)
Generate a Sound structure and append it to the output blob.
Generic container type.

◆ 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.

References ast_json_object_get(), ast_json_string_get(), ast_ari_sounds_list_args::format, and ast_ari_sounds_list_args::lang.

Referenced by ast_ari_sounds_list_cb().

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:273
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
Abstract JSON element (object, array, string, int, ...).