| 
									
										
										
										
											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> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 02:57:52 -04:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>core</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | #include "resource_events.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | #include "asterisk/astobj2.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-19 08:05:36 -07:00
										 |  |  | #include "asterisk/http_websocket.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | #include "asterisk/stasis_app.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | #include "asterisk/vector.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*! Number of buckets for the event session registry. Remember to keep it a prime number! */ | 
					
						
							|  |  |  | #define EVENT_SESSION_NUM_BUCKETS 23
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! Number of buckets for a websocket apps container. Remember to keep it a prime number! */ | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | #define APPS_NUM_BUCKETS 7
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*! Initial size of a message queue. */ | 
					
						
							|  |  |  | #define MESSAGES_INIT_SIZE 23
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief A wrapper for the /ref ast_ari_websocket_session. */ | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | struct event_session { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	struct ast_ari_websocket_session *ws_session;   /*!< Handle to the websocket session. */ | 
					
						
							|  |  |  | 	struct ao2_container *websocket_apps;           /*!< List of Stasis apps registered to
 | 
					
						
							|  |  |  | 	                                                     the websocket session. */ | 
					
						
							|  |  |  | 	AST_VECTOR(, struct ast_json *) message_queue;  /*!< Container for holding delayed messages. */ | 
					
						
							|  |  |  | 	char session_id[];                              /*!< The id for the websocket session. */ | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*! \brief \ref event_session error types. */ | 
					
						
							|  |  |  | enum event_session_error_type { | 
					
						
							|  |  |  | 	ERROR_TYPE_STASIS_REGISTRATION = 1,  /*!< Stasis failed to register the application. */ | 
					
						
							|  |  |  | 	ERROR_TYPE_OOM = 2,                  /*!< Insufficient memory to create the event
 | 
					
						
							|  |  |  | 	                                          session. */ | 
					
						
							|  |  |  | 	ERROR_TYPE_MISSING_APP_PARAM = 3,    /*!< HTTP request was missing an [app] parameter. */ | 
					
						
							|  |  |  | 	ERROR_TYPE_INVALID_APP_PARAM = 4,    /*!< HTTP request contained an invalid [app]
 | 
					
						
							|  |  |  | 	                                          parameter. */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief Local registry for created \ref event_session objects. */ | 
					
						
							|  |  |  | static struct ao2_container *event_session_registry; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  |  * \brief Callback handler for Stasis application messages. | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  |  * \internal | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  |  * \param data      Void pointer to the event session (\ref event_session). | 
					
						
							|  |  |  |  * \param app_name  Name of the Stasis application that dispatched the message. | 
					
						
							|  |  |  |  * \param message   The dispatched message. | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | static void stasis_app_message_handler( | 
					
						
							|  |  |  | 		void *data, const char *app_name, struct ast_json *message) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	struct event_session *session = data; | 
					
						
							|  |  |  | 	const char *msg_type, *msg_application; | 
					
						
							| 
									
										
										
										
											2019-11-06 04:47:17 -07:00
										 |  |  | 	int app_debug_enabled; | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ast_assert(session != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 04:47:17 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * We need to get the debug flag before lockinf session | 
					
						
							|  |  |  | 	 * to help prevent a deadlock with the apps_registry container. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	app_debug_enabled = stasis_app_get_debug_by_name(app_name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	ao2_lock(session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msg_type = S_OR(ast_json_string_get(ast_json_object_get(message, "type")), ""); | 
					
						
							|  |  |  | 	msg_application = S_OR( | 
					
						
							|  |  |  | 		ast_json_string_get(ast_json_object_get(message, "application")), ""); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* If we've been replaced, remove the application from our local
 | 
					
						
							|  |  |  | 	   websocket_apps container */ | 
					
						
							|  |  |  | 	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
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Now, we need to determine our state to see how we will handle the message */ | 
					
						
							|  |  |  | 	if (ast_json_object_set(message, "application", ast_json_string_create(app_name))) { | 
					
						
							|  |  |  | 		/* We failed to add an application element to our json message */ | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 		        "Failed to dispatch '%s' message from Stasis app '%s'; could not update message\n", | 
					
						
							|  |  |  | 		        msg_type, | 
					
						
							|  |  |  | 		        msg_application); | 
					
						
							|  |  |  | 	} else if (!session->ws_session) { | 
					
						
							| 
									
										
										
										
											2015-08-18 15:07:49 -05:00
										 |  |  | 		/* If the websocket is NULL, the message goes to the queue */ | 
					
						
							| 
									
										
										
										
											2017-11-06 18:11:08 -05:00
										 |  |  | 		if (!AST_VECTOR_APPEND(&session->message_queue, message)) { | 
					
						
							|  |  |  | 			ast_json_ref(message); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-08-18 15:07:49 -05:00
										 |  |  | 		ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 				"Queued '%s' message for Stasis app '%s'; websocket is not ready\n", | 
					
						
							|  |  |  | 				msg_type, | 
					
						
							|  |  |  | 				msg_application); | 
					
						
							| 
									
										
										
										
											2019-02-08 14:48:27 -06:00
										 |  |  | 	} else if (stasis_app_event_allowed(app_name, message)) { | 
					
						
							| 
									
										
										
										
											2019-11-06 04:47:17 -07:00
										 |  |  | 		if (app_debug_enabled) { | 
					
						
							| 
									
										
										
										
											2017-01-19 08:05:36 -07:00
										 |  |  | 			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); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 		/* We are ready to publish the message */ | 
					
						
							|  |  |  | 		ast_ari_websocket_session_write(session->ws_session, message); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ao2_unlock(session); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief AO2 comparison function for \ref event_session objects. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param obj    Void pointer to the \ref event_session container. | 
					
						
							|  |  |  |  * \param arg    Void pointer to the \ref event_session object. | 
					
						
							|  |  |  |  * \param flags  The \ref search_flags to use when creating the hash key. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval 0          The objects are not equal. | 
					
						
							|  |  |  |  * \retval CMP_MATCH  The objects are equal. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int event_session_compare(void *obj, void *arg, int flags) | 
					
						
							| 
									
										
										
										
											2013-04-22 14:58:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	const struct event_session *object_left = obj; | 
					
						
							|  |  |  | 	const struct event_session *object_right = arg; | 
					
						
							|  |  |  | 	const char *right_key = arg; | 
					
						
							|  |  |  | 	int cmp = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (flags & OBJ_SEARCH_MASK) { | 
					
						
							|  |  |  | 	case OBJ_SEARCH_OBJECT: | 
					
						
							|  |  |  | 		right_key = object_right->session_id; | 
					
						
							|  |  |  | 		/* Fall through */ | 
					
						
							|  |  |  | 	case OBJ_SEARCH_KEY: | 
					
						
							|  |  |  | 		cmp = strcmp(object_left->session_id, right_key); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OBJ_SEARCH_PARTIAL_KEY: | 
					
						
							|  |  |  | 		cmp = strncmp(object_left->session_id, right_key, strlen(right_key)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	return cmp ? 0 : CMP_MATCH; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief AO2 hash function for \ref event_session objects. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \details Computes hash value for the given \ref event_session, with respect to the | 
					
						
							|  |  |  |  *          provided search flags. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param obj    Void pointer to the \ref event_session object. | 
					
						
							|  |  |  |  * \param flags  The \ref search_flags to use when creating the hash key. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval > 0  on success | 
					
						
							|  |  |  |  * \retval   0  on failure | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int event_session_hash(const void *obj, const int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const struct event_session *session; | 
					
						
							|  |  |  | 	const char *key; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (flags & OBJ_SEARCH_MASK) { | 
					
						
							|  |  |  | 	case OBJ_SEARCH_KEY: | 
					
						
							|  |  |  | 		key = obj; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OBJ_SEARCH_OBJECT: | 
					
						
							|  |  |  | 		session = obj; | 
					
						
							|  |  |  | 		key = session->session_id; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		/* Hash can only work on something with a full key. */ | 
					
						
							|  |  |  | 		ast_assert(0); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ast_str_hash(key); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Explicitly shutdown a session. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \details An explicit shutdown is necessary, since the \ref 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param session  Event session object (\ref event_session). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void event_session_shutdown(struct event_session *session) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	struct ao2_iterator i; | 
					
						
							|  |  |  | 	char *app; | 
					
						
							|  |  |  | 	int j; | 
					
						
							|  |  |  | 	SCOPED_AO2LOCK(lock, session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clean up the websocket_apps container */ | 
					
						
							|  |  |  | 	if (session->websocket_apps) { | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clean up the message_queue container */ | 
					
						
							|  |  |  | 	for (j = 0; j < AST_VECTOR_SIZE(&session->message_queue); j++) { | 
					
						
							|  |  |  | 		struct ast_json *msg = AST_VECTOR_GET(&session->message_queue, j); | 
					
						
							|  |  |  | 		ast_json_unref(msg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	AST_VECTOR_FREE(&session->message_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Remove the handle to the underlying websocket session */ | 
					
						
							|  |  |  | 	session->ws_session = NULL; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Updates the websocket session for an \ref event_session. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \details The websocket for the given \ref event_session will be updated to the value | 
					
						
							|  |  |  |  *          of the \c ws_session argument. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *          If the value of the \c ws_session is not \c NULL and there are messages in the | 
					
						
							|  |  |  |  *          event session's \c message_queue, the messages are dispatched and removed from | 
					
						
							|  |  |  |  *          the queue. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param session     The event session object to update (\ref event_session). | 
					
						
							|  |  |  |  * \param ws_session  Handle to the underlying websocket session | 
					
						
							|  |  |  |  *                    (\ref ast_ari_websocket_session). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void event_session_update_websocket( | 
					
						
							|  |  |  | 		struct event_session *session, struct ast_ari_websocket_session *ws_session) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_assert(session != NULL); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	ao2_lock(session); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	session->ws_session = ws_session; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	for (i = 0; i < AST_VECTOR_SIZE(&session->message_queue); i++) { | 
					
						
							|  |  |  | 		struct ast_json *msg = AST_VECTOR_GET(&session->message_queue, i); | 
					
						
							|  |  |  | 		ast_ari_websocket_session_write(session->ws_session, msg); | 
					
						
							|  |  |  | 		ast_json_unref(msg); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	AST_VECTOR_RESET(&session->message_queue, AST_VECTOR_ELEM_CLEANUP_NOOP); | 
					
						
							|  |  |  | 	ao2_unlock(session); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  |  * \brief Processes cleanup actions for a \ref event_session object. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param session  The event session object to cleanup (\ref event_session). | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | static void event_session_cleanup(struct event_session *session) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 	if (!session) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	event_session_shutdown(session); | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	if (event_session_registry) { | 
					
						
							|  |  |  | 		ao2_unlink(event_session_registry, session); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Event session object destructor (\ref event_session). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param obj  Void pointer to the \ref event_session object. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void event_session_dtor(void *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #ifdef AST_DEVMODE /* Avoid unused variable warning */
 | 
					
						
							|  |  |  | 	struct event_session *session = obj; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* event_session_shutdown should have been called before now */ | 
					
						
							|  |  |  | 	ast_assert(session->ws_session == NULL); | 
					
						
							|  |  |  | 	ast_assert(session->websocket_apps == NULL); | 
					
						
							|  |  |  | 	ast_assert(AST_VECTOR_SIZE(&session->message_queue) == 0); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  |  * \brief Handles \ref event_session error processing. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param session  The \ref event_session object. | 
					
						
							|  |  |  |  * \param error    The \ref event_session_error_type to handle. | 
					
						
							|  |  |  |  * \param ser      HTTP TCP/TLS Server Session (\ref ast_tcptls_session_instance). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval  -1  Always returns -1. | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | static int event_session_allocation_error_handler( | 
					
						
							|  |  |  | 		struct event_session *session, enum event_session_error_type error, | 
					
						
							|  |  |  | 		struct ast_tcptls_session_instance *ser) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Notify the client */ | 
					
						
							|  |  |  | 	switch (error) { | 
					
						
							|  |  |  | 	case ERROR_TYPE_STASIS_REGISTRATION: | 
					
						
							|  |  |  | 		ast_http_error(ser, 500, "Internal Server Error", | 
					
						
							|  |  |  | 			"Stasis registration failed"); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	case ERROR_TYPE_OOM: | 
					
						
							|  |  |  | 		ast_http_error(ser, 500, "Internal Server Error", | 
					
						
							|  |  |  | 			"Allocation failed"); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	case ERROR_TYPE_MISSING_APP_PARAM: | 
					
						
							|  |  |  | 		ast_http_error(ser, 400, "Bad Request", | 
					
						
							|  |  |  | 			"HTTP request is missing param: [app]"); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	case ERROR_TYPE_INVALID_APP_PARAM: | 
					
						
							|  |  |  | 		ast_http_error(ser, 400, "Bad Request", | 
					
						
							|  |  |  | 			"Invalid application provided in param [app]."); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Cleanup the session */ | 
					
						
							|  |  |  | 	event_session_cleanup(session); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Creates an \ref event_session object and registers its apps with Stasis. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param ser         HTTP TCP/TLS Server Session (\ref ast_tcptls_session_instance). | 
					
						
							|  |  |  |  * \param args        The Stasis [app] parameters as parsed from the HTTP request | 
					
						
							|  |  |  |  *                    (\ref ast_ari_events_event_websocket_args). | 
					
						
							|  |  |  |  * \param session_id  The id for the websocket session that will be created for this | 
					
						
							|  |  |  |  *                    event session. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval  0  on success | 
					
						
							|  |  |  |  * \retval -1  on failure | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int event_session_alloc(struct ast_tcptls_session_instance *ser, | 
					
						
							|  |  |  | 		struct ast_ari_events_event_websocket_args *args, const char *session_id) | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	RAII_VAR(struct event_session *, session, NULL, ao2_cleanup); | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	int (* register_handler)(const char *, stasis_app_cb handler, void *data); | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	size_t size, i; | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* The request must have at least one [app] parameter */ | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 	if (args->app_count == 0) { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 		return event_session_allocation_error_handler( | 
					
						
							|  |  |  | 			session, ERROR_TYPE_MISSING_APP_PARAM, ser); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	size = sizeof(*session) + strlen(session_id) + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Instantiate the event session */ | 
					
						
							|  |  |  | 	session = ao2_alloc(size, event_session_dtor); | 
					
						
							|  |  |  | 	if (!session) { | 
					
						
							|  |  |  | 		return event_session_allocation_error_handler(session, ERROR_TYPE_OOM, ser); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	strncpy(session->session_id, session_id, size - sizeof(*session)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Instantiate the hash table for Stasis apps */ | 
					
						
							|  |  |  | 	session->websocket_apps = | 
					
						
							|  |  |  | 		ast_str_container_alloc(APPS_NUM_BUCKETS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!session->websocket_apps) { | 
					
						
							|  |  |  | 		return event_session_allocation_error_handler(session, ERROR_TYPE_OOM, ser); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Instantiate the message queue */ | 
					
						
							|  |  |  | 	if (AST_VECTOR_INIT(&session->message_queue, MESSAGES_INIT_SIZE)) { | 
					
						
							|  |  |  | 		return event_session_allocation_error_handler(session, ERROR_TYPE_OOM, ser); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Register the apps with Stasis */ | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 		const char *app = args->app[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ast_strlen_zero(app)) { | 
					
						
							|  |  |  | 			return event_session_allocation_error_handler( | 
					
						
							|  |  |  | 				session, ERROR_TYPE_INVALID_APP_PARAM, ser); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 		if (ast_str_container_add(session->websocket_apps, app)) { | 
					
						
							|  |  |  | 			return event_session_allocation_error_handler(session, ERROR_TYPE_OOM, ser); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 		if (register_handler(app, stasis_app_message_handler, session)) { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 			ast_log(LOG_WARNING, "Stasis registration failed for application: '%s'\n", app); | 
					
						
							|  |  |  | 			return event_session_allocation_error_handler( | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 				session, ERROR_TYPE_STASIS_REGISTRATION, ser); | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Add the event session to the local registry */ | 
					
						
							|  |  |  | 	if (!ao2_link(event_session_registry, session)) { | 
					
						
							|  |  |  | 		return event_session_allocation_error_handler(session, ERROR_TYPE_OOM, ser); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2015-05-17 20:36:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | static int event_session_shutdown_cb(void *session, void *arg, int flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	event_session_cleanup(session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 15:07:49 -05:00
										 |  |  | void ast_ari_websocket_events_event_websocket_dtor(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	ao2_callback(event_session_registry, OBJ_MULTIPLE | OBJ_NODATA, event_session_shutdown_cb, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 15:07:49 -05:00
										 |  |  | 	ao2_cleanup(event_session_registry); | 
					
						
							|  |  |  | 	event_session_registry = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | int ast_ari_websocket_events_event_websocket_init(void) | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Try to instantiate the registry */ | 
					
						
							| 
									
										
										
										
											2018-11-19 15:10:02 -05:00
										 |  |  | 	event_session_registry = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, | 
					
						
							|  |  |  | 		EVENT_SESSION_NUM_BUCKETS, event_session_hash, NULL, event_session_compare); | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	if (!event_session_registry) { | 
					
						
							|  |  |  | 		/* This is bad, bad. */ | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 			    "Failed to allocate the local registry for websocket applications\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -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, const char *session_id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ast_debug(3, "/events WebSocket attempted\n"); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	/* Create the event session */ | 
					
						
							|  |  |  | 	return event_session_alloc(ser, args, session_id); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-02 14:36:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 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) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 	struct event_session *session; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	struct ast_json *msg; | 
					
						
							|  |  |  | 	const char *session_id; | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	ast_debug(3, "/events WebSocket established\n"); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	ast_assert(ws_session != NULL); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 11:27:23 -05:00
										 |  |  | 	session_id = ast_ari_websocket_session_id(ws_session); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Find the event_session and update its websocket  */ | 
					
						
							|  |  |  | 	session = ao2_find(event_session_registry, session_id, OBJ_SEARCH_KEY); | 
					
						
							|  |  |  | 	if (session) { | 
					
						
							|  |  |  | 		ao2_unlink(event_session_registry, session); | 
					
						
							|  |  |  | 		event_session_update_websocket(session, ws_session); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 			"Failed to locate an event session for the provided websocket session\n"); | 
					
						
							| 
									
										
										
										
											2013-07-03 16:32:00 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 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); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-04 12:25:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	event_session_cleanup(session); | 
					
						
							|  |  |  | 	ao2_ref(session, -1); | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |