Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
resource_events.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012 - 2013, Digium, Inc.
5 *
6 * David M. Lee, II <dlee@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief /api-docs/events.{format} implementation- WebSocket resource
22 *
23 * \author David M. Lee, II <dlee@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "resource_events.h"
33#include "internal.h"
34#include "asterisk/stasis_app.h"
35
38 struct ast_ari_response *response)
39{
41 struct ast_json *json_variables = NULL;
42
43 if (args->variables) {
45 json_variables = ast_json_object_get(args->variables, "variables");
46 }
47
48 if (ast_strlen_zero(args->application)) {
49 ast_ari_response_error(response, 400, "Bad Request",
50 "Missing parameter application");
51 return;
52 }
53
54 res = stasis_app_user_event(args->application,
55 args->event_name,
56 args->source, args->source_count,
57 json_variables);
58
59 switch (res) {
62 break;
63
65 ast_ari_response_error(response, 404, "Not Found",
66 "Application not found");
67 break;
68
70 ast_ari_response_error(response, 422, "Unprocessable Entity",
71 "Event source was not found");
72 break;
73
75 ast_ari_response_error(response, 400, "Bad Request",
76 "Invalid event source URI scheme");
77 break;
78
80 ast_ari_response_error(response, 400, "Bad Request",
81 "Invalid userevent data");
82 break;
83
85 default:
86 ast_ari_response_error(response, 500, "Internal Server Error",
87 "Error processing request");
88 }
89}
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:319
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:344
Asterisk main include file. File version handling, generic pbx functions.
Internal API's for res_ari.
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
#define NULL
Definition: resample.c:96
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.
Generated file - declares stubs to be implemented in res/ari/resource_events.c.
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}.
Stasis Application API. See Stasis Application API for detailed documentation.
stasis_app_user_event_res
Return code for stasis_app_user_event.
Definition: stasis_app.h:265
@ STASIS_APP_USER_APP_NOT_FOUND
Definition: stasis_app.h:267
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
Definition: stasis_app.h:268
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
Definition: stasis_app.h:269
@ STASIS_APP_USER_USEREVENT_INVALID
Definition: stasis_app.h:270
@ STASIS_APP_USER_OK
Definition: stasis_app.h:266
@ STASIS_APP_USER_INTERNAL_ERROR
Definition: stasis_app.h:271
enum stasis_app_user_event_res stasis_app_user_event(const char *app_name, const char *event_name, const char **source_uris, int sources_count, struct ast_json *json_variables)
Generate a Userevent for stasis app (echo to AMI)
Definition: res_stasis.c:2174
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Abstract JSON element (object, array, string, int, ...).
Structure for variables, used for configurations and for channel variables.
const char * args