Asterisk - The Open Source Telephony Project GIT-master-590b490
Loading...
Searching...
No Matches
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"
36
39 struct ast_ari_response *response)
40{
42 struct ast_json *json_variables = NULL;
43
44 if (args->variables) {
46 json_variables = ast_json_object_get(args->variables, "variables");
47 }
48
49 if (ast_strlen_zero(args->application)) {
50 ast_ari_response_error(response, 400, "Bad Request",
51 "Missing parameter application");
52 return;
53 }
54
55 res = stasis_app_user_event(args->application,
56 args->event_name,
57 args->source, args->source_count,
58 json_variables);
59
60 switch (res) {
63 break;
64
66 ast_ari_response_error(response, 404, "Not Found",
67 "Application not found");
68 break;
69
71 ast_ari_response_error(response, 422, "Unprocessable Entity",
72 "Event source was not found");
73 break;
74
76 ast_ari_response_error(response, 400, "Bad Request",
77 "Invalid event source URI scheme");
78 break;
79
81 ast_ari_response_error(response, 400, "Bad Request",
82 "Invalid userevent data");
83 break;
84
86 default:
87 ast_ari_response_error(response, 500, "Internal Server Error",
88 "Error processing request");
89 }
90}
91
94 struct ast_ari_response *response)
95{
96 int res;
97
98 if (ast_strlen_zero(args->channel_id)) {
99 ast_ari_response_error(response, 400, "Bad Request",
100 "channelId parameter is required");
101 return;
102 }
103
104 if (ast_strlen_zero(args->application)) {
105 ast_ari_response_error(response, 400, "Bad Request",
106 "application parameter is required");
107 return;
108 }
109
110 res = stasis_app_claim_channel(args->channel_id, args->application);
111
112 switch (res) {
113 case 0:
114 /* Success */
116 break;
117 case -1:
118 /* Channel not found */
119 ast_ari_response_error(response, 404, "Not Found",
120 "Channel not found or not in broadcast state");
121 break;
122 case -2:
123 /* Already claimed */
124 ast_ari_response_error(response, 409, "Conflict",
125 "Channel has already been claimed by another application");
126 break;
128 /* Module not loaded */
129 ast_ari_response_error(response, 501, "Not Implemented",
130 "Broadcast functionality not available (res_stasis_broadcast not loaded)");
131 break;
132 default:
133 ast_ari_response_error(response, 500, "Internal Server Error",
134 "Failed to claim channel");
135 break;
136 }
137}
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_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition res_ari.c:237
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 AST_OPTIONAL_API_UNAVAILABLE
A common value for optional API stub functions to return.
static struct @522 args
#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.
void ast_ari_events_claim_channel(struct ast_variable *headers, struct ast_ari_events_claim_channel_args *args, struct ast_ari_response *response)
Claim a broadcast channel for this application.
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)
Stasis Application Broadcast API.
int AST_OPTIONAL_API_NAME() stasis_app_claim_channel(const char *channel_id, const char *app_name)
Attempt to claim a broadcast channel.
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.