48 #if defined(AST_DEVMODE)
65 ast_log(LOG_ERROR,
"Failed to create response.\n");
69 for (i = get_params; i; i = i->
next) {
70 if (strcmp(i->
name,
"app") == 0) {
99 "Too many values for app");
110 args.
app[j] = (vals[j]);
113 if (strcmp(i->
name,
"subscribeAll") == 0) {
121 fin: __attribute__((unused))
123 ast_http_error(ser, 500,
"Server Error",
"Memory allocation error");
125 }
else if (response->response_code != 0) {
128 if (response->message) {
131 ast_log(LOG_ERROR,
"Missing response message\n");
135 ast_http_error(ser, response->response_code, response->response_text, msg);
144 static void ast_ari_events_event_websocket_ws_established_cb(
struct ast_websocket *ws_session,
157 ast_log(LOG_ERROR,
"Failed to create response.\n");
161 #if defined(AST_DEVMODE)
168 ast_log(LOG_ERROR,
"Failed to create ARI session\n");
172 for (i = get_params; i; i = i->
next) {
173 if (strcmp(i->
name,
"app") == 0) {
175 char *vals[MAX_VALS];
202 "Too many values for app");
213 args.
app[j] = (vals[j]);
216 if (strcmp(i->
name,
"subscribeAll") == 0) {
224 fin: __attribute__((unused))
225 if (response && response->response_code != 0) {
228 if (response->message) {
231 ast_log(LOG_ERROR,
"Missing response message\n");
299 #if defined(AST_DEVMODE)
304 for (i = get_params; i; i = i->
next) {
305 if (strcmp(i->
name,
"application") == 0) {
308 if (strcmp(i->
name,
"source") == 0) {
310 char *vals[MAX_VALS];
337 "Too many values for source");
348 args.
source[j] = (vals[j]);
353 for (i = path_vars; i; i = i->
next) {
354 if (strcmp(i->
name,
"eventName") == 0) {
361 #if defined(AST_DEVMODE)
366 is_valid = response->
message == NULL;
376 if (200 <= code && code <= 299) {
380 ast_log(LOG_ERROR,
"Invalid error response %d for /events/user/{eventName}\n", code);
386 ast_log(LOG_ERROR,
"Response validation failed for /events/user/{eventName}\n");
388 "Internal Server Error",
"Response validation failed");
392 fin: __attribute__((unused))
425 static int unload_module(
void)
434 static int load_module(
void)
444 events.
ws_server = ast_websocket_server_create();
450 protocol = ast_websocket_sub_protocol_alloc(
"ari");
459 res |= ast_websocket_server_add_protocol2(events.
ws_server, protocol);
470 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"RESTful API module - WebSocket resource",
471 .support_level = AST_MODULE_SUPPORT_CORE,
473 .unload = unload_module,
474 .requires =
"res_ari,res_ari_model,res_stasis,res_http_websocket",
struct ast_variable * next
Asterisk main include file. File version handling, generic pbx functions.
void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text)
Send HTTP error message and close socket.
A websocket protocol implementation.
Generated file - declares stubs to be implemented in res/ari/resource_events.c.
ast_websocket_pre_callback session_attempted
Callback called when a new session is attempted. Optional.
int ast_ari_websocket_events_event_websocket_attempted(struct ast_tcptls_session_instance *ser, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args, const char *session_id)
WebSocket connection for events.
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Structure for variables, used for configurations and for channel variables.
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
int ast_ari_events_user_event_parse_body(struct ast_json *body, struct ast_ari_events_user_event_args *args)
Body parsing function for /events/user/{eventName}.
Generated file - Build validators for ARI model objects.
#define ast_strdup(str)
A wrapper for strdup()
static void ast_ari_events_user_event_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 /events/user/{eventName}.
struct ast_ari_websocket_session * ast_ari_websocket_session_create(struct ast_websocket *ws_session, int(*validator)(struct ast_json *))
Create an ARI WebSocket session.
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
static struct stasis_rest_handlers events
REST handler for /api-docs/events.json.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
#define ast_malloc(len)
A wrapper for malloc()
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
describes a server instance
static struct stasis_rest_handlers events_user_eventName
REST handler for /api-docs/events.json.
struct ast_websocket_server * ws_server
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
int AST_OPTIONAL_API_NAME() ast_websocket_write(struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size)
Write function for websocket traffic.
Structure definition for session.
#define ast_calloc(num, len)
A wrapper for calloc()
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.
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Module has failed to load, may be in an inconsistent state.
static struct stasis_rest_handlers events_user
REST handler for /api-docs/events.json.
#define SCOPED_MODULE_USE(module)
int ast_ari_websocket_events_event_websocket_init(void)
WebSocket connection for events.
struct ast_json * message
struct ast_json * variables
void ast_ari_events_user_event(struct ast_variable *headers, struct ast_ari_events_user_event_args *args, struct ast_ari_response *response)
Generate a user event.
const char * path_segment
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
void ast_ari_websocket_events_event_websocket_dtor(void)
WebSocket connection for events.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Abstract JSON element (object, array, string, int, ...).
ari_validator ast_ari_validate_message_fn(void)
Function pointer to ast_ari_validate_message().
Stasis Application API. See Stasis Application API for detailed documentation.
ast_websocket_callback session_established
Callback called when a new session is established. Mandatory.
void ast_ari_websocket_events_event_websocket_established(struct ast_ari_websocket_session *ws_session, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args)
WebSocket connection for events.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
Handler for a single RESTful path segment.