| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2012 - 2013, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * David M. Lee, II <dlee@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  * \brief /api-docs/events.{format} implementation- WebSocket resource | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author David M. Lee, II <dlee@digium.com> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | #include "asterisk/astobj2.h"
 | 
					
						
							|  |  |  | #include "asterisk/stasis_app.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | #include "resource_events.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | /*! Number of buckets for the Stasis application hash table. Remember to keep it
 | 
					
						
							|  |  |  |  *  a prime number! | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define APPS_NUM_BUCKETS 7
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief A connection to the event WebSocket */ | 
					
						
							|  |  |  | struct event_session { | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 	struct ast_ari_websocket_session *ws_session; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	struct ao2_container *websocket_apps; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Explicitly shutdown a session. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * An explicit shutdown is necessary, since stasis-app has a reference to this | 
					
						
							|  |  |  |  * session. We also need to be sure to null out the \c ws_session field, since | 
					
						
							|  |  |  |  * the websocket is about to go away. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param session Session info struct. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void session_shutdown(struct event_session *session) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |         struct ao2_iterator i; | 
					
						
							|  |  |  | 	char *app; | 
					
						
							|  |  |  | 	SCOPED_AO2LOCK(lock, session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	i = ao2_iterator_init(session->websocket_apps, 0); | 
					
						
							|  |  |  | 	while ((app = ao2_iterator_next(&i))) { | 
					
						
							|  |  |  | 		stasis_app_unregister(app); | 
					
						
							|  |  |  | 		ao2_cleanup(app); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ao2_iterator_destroy(&i); | 
					
						
							|  |  |  | 	ao2_cleanup(session->websocket_apps); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	session->websocket_apps = NULL; | 
					
						
							|  |  |  | 	session->ws_session = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void session_dtor(void *obj) | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | #ifdef AST_DEVMODE /* Avoid unused variable warning */
 | 
					
						
							|  |  |  | 	struct event_session *session = obj; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* session_shutdown should have been called before */ | 
					
						
							|  |  |  | 	ast_assert(session->ws_session == NULL); | 
					
						
							|  |  |  | 	ast_assert(session->websocket_apps == NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void session_cleanup(struct event_session *session) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	session_shutdown(session); | 
					
						
							|  |  |  | 	ao2_cleanup(session); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct event_session *session_create( | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 	struct ast_ari_websocket_session *ws_session) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	RAII_VAR(struct event_session *, session, NULL, ao2_cleanup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	session = ao2_alloc(sizeof(*session), session_dtor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	session->ws_session = ws_session; | 
					
						
							|  |  |  | 	session->websocket_apps = | 
					
						
							|  |  |  | 		ast_str_container_alloc(APPS_NUM_BUCKETS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!session->websocket_apps) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ao2_ref(session, +1); | 
					
						
							|  |  |  | 	return session; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Callback handler for Stasis application messages. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void app_handler(void *data, const char *app_name, | 
					
						
							|  |  |  | 			struct ast_json *message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct event_session *session = data; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2013-07-26 17:42:08 +00:00
										 |  |  | 	const char *msg_type = S_OR( | 
					
						
							|  |  |  | 		ast_json_string_get(ast_json_object_get(message, "type")), | 
					
						
							|  |  |  | 		""); | 
					
						
							|  |  |  | 	const char *msg_application = S_OR( | 
					
						
							|  |  |  | 		ast_json_string_get(ast_json_object_get(message, "application")), | 
					
						
							|  |  |  | 		""); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!session) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2013-07-26 17:42:08 +00:00
										 |  |  | 	/* Determine if we've been replaced */ | 
					
						
							|  |  |  | 	if (strcmp(msg_type, "ApplicationReplaced") == 0 && | 
					
						
							|  |  |  | 		strcmp(msg_application, app_name) == 0) { | 
					
						
							|  |  |  | 		ao2_find(session->websocket_apps, msg_application, | 
					
						
							|  |  |  | 			OBJ_UNLINK | OBJ_NODATA); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	res = ast_json_object_set(message, "application", | 
					
						
							|  |  |  | 				  ast_json_string_create(app_name)); | 
					
						
							|  |  |  | 	if(res != 0) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ao2_lock(session); | 
					
						
							|  |  |  | 	if (session->ws_session) { | 
					
						
							| 
									
										
										
										
											2017-01-19 08:05:36 -07:00
										 |  |  | 		if (stasis_app_get_debug_by_name(app_name)) { | 
					
						
							|  |  |  | 			char *str = ast_json_dump_string_format(message, ast_ari_json_format()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ast_verbose("<--- Sending ARI event to %s --->\n%s\n", | 
					
						
							|  |  |  | 				ast_sockaddr_stringify(ast_ari_websocket_session_get_remote_addr(session->ws_session)), | 
					
						
							|  |  |  | 				str); | 
					
						
							|  |  |  | 			ast_json_free(str); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 		ast_ari_websocket_session_write(session->ws_session, message); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ao2_unlock(session); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Register for all of the apps given. | 
					
						
							|  |  |  |  * \param session Session info struct. | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  |  * \param app_name Name of application to register. | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  |  * \param register_handler Pointer to the application registration handler | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | static int session_register_app(struct event_session *session, | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 				 const char *app_name, | 
					
						
							|  |  |  | 				 int (* register_handler)(const char *, stasis_app_cb handler, void *data)) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	SCOPED_AO2LOCK(lock, session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_assert(session->ws_session != NULL); | 
					
						
							|  |  |  | 	ast_assert(session->websocket_apps != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 	if (ast_strlen_zero(app_name)) { | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 	if (ast_str_container_add(session->websocket_apps, app_name)) { | 
					
						
							|  |  |  | 		ast_ari_websocket_session_write(session->ws_session, | 
					
						
							|  |  |  | 			ast_ari_oom_json()); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	register_handler(app_name, app_handler, session); | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 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) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							|  |  |  | 	size_t i, j; | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	int (* register_handler)(const char *, stasis_app_cb handler, void *data); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_debug(3, "/events WebSocket attempted\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (args->app_count == 0) { | 
					
						
							|  |  |  | 		ast_http_error(ser, 400, "Bad Request", "Missing param 'app'"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	if (args->subscribe_all) { | 
					
						
							|  |  |  | 		register_handler = &stasis_app_register_all; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		register_handler = &stasis_app_register; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 	for (i = 0; i < args->app_count; ++i) { | 
					
						
							|  |  |  | 		if (ast_strlen_zero(args->app[i])) { | 
					
						
							|  |  |  | 			res = -1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 		res |= register_handler(args->app[i], app_handler, NULL); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (res) { | 
					
						
							|  |  |  | 		for (j = 0; j < i; ++j) { | 
					
						
							|  |  |  | 			stasis_app_unregister(args->app[j]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ast_http_error(ser, 400, "Bad Request", "Invalid application provided in param 'app'."); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ast_ari_websocket_events_event_websocket_established(struct ast_ari_websocket_session *ws_session, | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	struct ast_variable *headers, | 
					
						
							| 
									
										
										
										
											2013-11-07 21:10:31 +00:00
										 |  |  | 	struct ast_ari_events_event_websocket_args *args) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	RAII_VAR(struct event_session *, session, NULL, session_cleanup); | 
					
						
							|  |  |  | 	struct ast_json *msg; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 	size_t i; | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	int (* register_handler)(const char *, stasis_app_cb handler, void *data); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_debug(3, "/events WebSocket connection\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	session = session_create(ws_session); | 
					
						
							|  |  |  | 	if (!session) { | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 		ast_ari_websocket_session_write(ws_session, ast_ari_oom_json()); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	if (args->subscribe_all) { | 
					
						
							|  |  |  | 		register_handler = &stasis_app_register_all; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		register_handler = &stasis_app_register; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 	res = 0; | 
					
						
							|  |  |  | 	for (i = 0; i < args->app_count; ++i) { | 
					
						
							|  |  |  | 		if (ast_strlen_zero(args->app[i])) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 		res |= session_register_app(session, args->app[i], register_handler); | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ao2_container_count(session->websocket_apps) == 0) { | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		msg = ast_json_pack("{s: s, s: [s]}", | 
					
						
							| 
									
										
										
										
											2013-07-05 19:15:27 +00:00
										 |  |  | 			"type", "MissingParams", | 
					
						
							|  |  |  | 			"params", "app"); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		if (!msg) { | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 			msg = ast_json_ref(ast_ari_oom_json()); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 		ast_ari_websocket_session_write(session->ws_session, msg); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (res != 0) { | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 		ast_ari_websocket_session_write(ws_session, ast_ari_oom_json()); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We don't process any input, but we'll consume it waiting for EOF */ | 
					
						
							| 
									
										
										
										
											2013-07-27 23:11:02 +00:00
										 |  |  | 	while ((msg = ast_ari_websocket_session_read(ws_session))) { | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 		ast_json_unref(msg); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-22 16:09:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ast_ari_events_user_event(struct ast_variable *headers, | 
					
						
							|  |  |  | 	struct ast_ari_events_user_event_args *args, | 
					
						
							|  |  |  | 	struct ast_ari_response *response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum stasis_app_user_event_res res; | 
					
						
							|  |  |  | 	struct ast_json *json_variables = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (args->variables) { | 
					
						
							|  |  |  | 		ast_ari_events_user_event_parse_body(args->variables, args); | 
					
						
							|  |  |  | 		json_variables = ast_json_object_get(args->variables, "variables"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(args->application)) { | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 400, "Bad Request", | 
					
						
							|  |  |  | 			"Missing parameter application"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res = stasis_app_user_event(args->application, | 
					
						
							|  |  |  | 		args->event_name, | 
					
						
							|  |  |  | 		args->source, args->source_count, | 
					
						
							|  |  |  | 		json_variables); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (res) { | 
					
						
							|  |  |  | 	case STASIS_APP_USER_OK: | 
					
						
							|  |  |  | 		ast_ari_response_no_content(response); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case STASIS_APP_USER_APP_NOT_FOUND: | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 404, "Not Found", | 
					
						
							|  |  |  | 			"Application not found"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND: | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 422, "Unprocessable Entity", | 
					
						
							|  |  |  | 			"Event source was not found"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME: | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 400, "Bad Request", | 
					
						
							|  |  |  | 			"Invalid event source URI scheme"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case STASIS_APP_USER_USEREVENT_INVALID: | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 400, "Bad Request", | 
					
						
							|  |  |  | 			"Invalid userevnet data"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case STASIS_APP_USER_INTERNAL_ERROR: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		ast_ari_response_error(response, 500, "Internal Server Error", | 
					
						
							|  |  |  | 			"Error processing request"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |