[asterisk-commits] kmoore: trunk r420124 - in /trunk: apps/ configs/samples/ funcs/ include/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 6 07:55:53 CDT 2014


Author: kmoore
Date: Wed Aug  6 07:55:28 2014
New Revision: 420124

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=420124
Log:
Stasis: Allow message types to be blocked

This introduces stasis.conf and a mechanism to prevent certain message
types from being published. Internally, this works by preventing the
chosen message types from being created which ensures that those
message types can never be published. This patch also adjusts message
publishers such that message payloads are not created if the related
message type is not available.

Review: https://reviewboard.asterisk.org/r/3823/

Added:
    trunk/configs/samples/stasis.conf.sample   (with props)
Modified:
    trunk/apps/app_chanspy.c
    trunk/apps/app_forkcdr.c
    trunk/apps/app_queue.c
    trunk/funcs/func_cdr.c
    trunk/include/asterisk/stasis.h
    trunk/main/app.c
    trunk/main/bridge.c
    trunk/main/ccss.c
    trunk/main/cdr.c
    trunk/main/channel.c
    trunk/main/core_local.c
    trunk/main/devicestate.c
    trunk/main/endpoints.c
    trunk/main/file.c
    trunk/main/loader.c
    trunk/main/manager.c
    trunk/main/named_acl.c
    trunk/main/pickup.c
    trunk/main/presencestate.c
    trunk/main/rtp_engine.c
    trunk/main/security_events.c
    trunk/main/stasis.c
    trunk/main/stasis_bridges.c
    trunk/main/stasis_cache.c
    trunk/main/stasis_channels.c
    trunk/main/stasis_endpoints.c
    trunk/main/stasis_message.c
    trunk/main/stasis_system.c
    trunk/main/test.c
    trunk/pbx/pbx_realtime.c
    trunk/res/parking/parking_manager.c
    trunk/res/res_corosync.c
    trunk/res/res_stasis.c
    trunk/res/res_stasis_snoop.c
    trunk/res/res_stasis_test.c
    trunk/res/res_stun_monitor.c
    trunk/tests/test_stasis.c
    trunk/tests/test_stasis_channels.c

Modified: trunk/apps/app_chanspy.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_chanspy.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/apps/app_chanspy.c (original)
+++ trunk/apps/app_chanspy.c Wed Aug  6 07:55:28 2014
@@ -557,13 +557,14 @@
 	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+	struct stasis_message_type *type = start ? ast_channel_chanspy_start_type(): ast_channel_chanspy_stop_type();
 
 	if (!spyer) {
 		ast_log(AST_LOG_WARNING, "Attempt to publish ChanSpy message for NULL spyer channel\n");
 		return;
 	}
 	blob = ast_json_null();
-	if (!blob) {
+	if (!blob || !type) {
 		return;
 	}
 
@@ -582,9 +583,7 @@
 		}
 	}
 
-	message = stasis_message_create(
-			start ? ast_channel_chanspy_start_type(): ast_channel_chanspy_stop_type(),
-					payload);
+	message = stasis_message_create(type, payload);
 	if (!message) {
 		return;
 	}

Modified: trunk/apps/app_forkcdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_forkcdr.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/apps/app_forkcdr.c (original)
+++ trunk/apps/app_forkcdr.c Wed Aug  6 07:55:28 2014
@@ -136,7 +136,7 @@
 static int forkcdr_exec(struct ast_channel *chan, const char *data)
 {
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct fork_cdr_message_payload *, payload, ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
+	RAII_VAR(struct fork_cdr_message_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
 
 	char *parse;
@@ -153,6 +153,13 @@
 		ast_app_parse_options(forkcdr_exec_options, &flags, NULL, args.options);
 	}
 
+	if (!forkcdr_message_type()) {
+		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message type\n",
+			ast_channel_name(chan));
+		return -1;
+	}
+
+	payload = ao2_alloc(sizeof(*payload), NULL);
 	if (!payload) {
 		return -1;
 	}

Modified: trunk/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_queue.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Wed Aug  6 07:55:28 2014
@@ -2066,6 +2066,10 @@
 	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
+	if (!type) {
+		return;
+	}
+
 	payload = ast_multi_channel_blob_create(blob);
 	if (!payload) {
 		return;
@@ -2122,7 +2126,7 @@
 	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
-	if (!blob) {
+	if (!blob || !type) {
 		return;
 	}
 

Added: trunk/configs/samples/stasis.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/samples/stasis.conf.sample?view=auto&rev=420124
==============================================================================
--- trunk/configs/samples/stasis.conf.sample (added)
+++ trunk/configs/samples/stasis.conf.sample Wed Aug  6 07:55:28 2014
@@ -1,0 +1,122 @@
+[declined_message_types]
+; This config section contains the names of message types that should be prevented
+; from being created. By default, all message types are allowed to be created.
+;
+; Using this functionality requires knowledge of the names of internal stasis
+; message types which is generally the same as the name of the accessor function.
+;
+; Use of this functionality may break more complex functionality in Asterisk
+; such as CEL, CDR, transfers, etc. and will likely cause related messages in ARI
+; and AMI to go missing.
+; decline=stasis_app_recording_snapshot_type
+; decline=stasis_app_playback_snapshot_type
+; decline=stasis_test_message_type
+; decline=confbridge_start_type
+; decline=confbridge_end_type
+; decline=confbridge_join_type
+; decline=confbridge_leave_type
+; decline=confbridge_start_record_type
+; decline=confbridge_stop_record_type
+; decline=confbridge_mute_type
+; decline=confbridge_unmute_type
+; decline=confbridge_talking_type
+; decline=cel_generic_type
+; decline=ast_bridge_snapshot_type
+; decline=ast_bridge_merge_message_type
+; decline=ast_channel_entered_bridge_type
+; decline=ast_channel_left_bridge_type
+; decline=ast_blind_transfer_type
+; decline=ast_attended_transfer_type
+; decline=ast_endpoint_snapshot_type
+; decline=ast_endpoint_state_type
+; decline=ast_device_state_message_type
+; decline=ast_test_suite_message_type
+; decline=ast_mwi_state_type
+; decline=ast_mwi_vm_app_type
+; decline=ast_format_register_type
+; decline=ast_format_unregister_type
+; decline=ast_manager_get_generic_type
+; decline=ast_parked_call_type
+; decline=ast_channel_snapshot_type
+; decline=ast_channel_dial_type
+; decline=ast_channel_varset_type
+; decline=ast_channel_hangup_request_type
+; decline=ast_channel_dtmf_begin_type
+; decline=ast_channel_dtmf_end_type
+; decline=ast_channel_hold_type
+; decline=ast_channel_unhold_type
+; decline=ast_channel_chanspy_start_type
+; decline=ast_channel_chanspy_stop_type
+; decline=ast_channel_fax_type
+; decline=ast_channel_hangup_handler_type
+; decline=ast_channel_moh_start_type
+; decline=ast_channel_moh_stop_type
+; decline=ast_channel_monitor_start_type
+; decline=ast_channel_monitor_stop_type
+; decline=ast_channel_agent_login_type
+; decline=ast_channel_agent_logoff_type
+; decline=ast_channel_talking_start
+; decline=ast_channel_talking_stop
+; decline=ast_security_event_type
+; decline=ast_named_acl_change_type
+; decline=ast_local_bridge_type
+; decline=ast_local_optimization_begin_type
+; decline=ast_local_optimization_end_type
+; decline=stasis_subscription_change_type
+; decline=ast_multi_user_event_type
+; decline=stasis_cache_clear_type
+; decline=stasis_cache_update_type
+; decline=ast_network_change_type
+; decline=ast_system_registry_type
+; decline=ast_cc_available_type
+; decline=ast_cc_offertimerstart_type
+; decline=ast_cc_requested_type
+; decline=ast_cc_requestacknowledged_type
+; decline=ast_cc_callerstopmonitoring_type
+; decline=ast_cc_callerstartmonitoring_type
+; decline=ast_cc_callerrecalling_type
+; decline=ast_cc_recallcomplete_type
+; decline=ast_cc_failure_type
+; decline=ast_cc_monitorfailed_type
+; decline=ast_presence_state_message_type
+; decline=ast_rtp_rtcp_sent_type
+; decline=ast_rtp_rtcp_received_type
+; decline=ast_call_pickup_type
+; decline=aoc_s_type
+; decline=aoc_d_type
+; decline=aoc_e_type
+; decline=dahdichannel_type
+; decline=mcid_type
+; decline=session_timeout_type
+; decline=cdr_read_message_type
+; decline=cdr_write_message_type
+; decline=cdr_prop_write_message_type
+; decline=corosync_ping_message_type
+; decline=agi_exec_start_type
+; decline=agi_exec_end_type
+; decline=agi_async_start_type
+; decline=agi_async_exec_type
+; decline=agi_async_end_type
+; decline=queue_caller_join_type
+; decline=queue_caller_leave_type
+; decline=queue_caller_abandon_type
+; decline=queue_member_status_type
+; decline=queue_member_added_type
+; decline=queue_member_removed_type
+; decline=queue_member_pause_type
+; decline=queue_member_penalty_type
+; decline=queue_member_ringinuse_type
+; decline=queue_agent_called_type
+; decline=queue_agent_connect_type
+; decline=queue_agent_complete_type
+; decline=queue_agent_dump_type
+; decline=queue_agent_ringnoanswer_type
+; decline=meetme_join_type
+; decline=meetme_leave_type
+; decline=meetme_end_type
+; decline=meetme_mute_type
+; decline=meetme_talking_type
+; decline=meetme_talk_request_type
+; decline=appcdr_message_type
+; decline=forkcdr_message_type
+; decline=cdr_sync_message_type

Propchange: trunk/configs/samples/stasis.conf.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/configs/samples/stasis.conf.sample
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/configs/samples/stasis.conf.sample
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/funcs/func_cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_cdr.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/funcs/func_cdr.c (original)
+++ trunk/funcs/func_cdr.c Wed Aug  6 07:55:28 2014
@@ -437,8 +437,7 @@
 		    char *buf, size_t len)
 {
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct cdr_func_payload *, payload,
-		ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
+	RAII_VAR(struct cdr_func_payload *, payload, NULL, ao2_cleanup);
 	struct cdr_func_data output = { 0, };
 
 	if (!chan) {
@@ -446,6 +445,13 @@
 		return -1;
 	}
 
+	if (!cdr_read_message_type()) {
+		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n",
+			ast_channel_name(chan));
+		return -1;
+	}
+
+	payload = ao2_alloc(sizeof(*payload), NULL);
 	if (!payload) {
 		return -1;
 	}
@@ -489,8 +495,7 @@
 		     const char *value)
 {
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct cdr_func_payload *, payload,
-		     ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
+	RAII_VAR(struct cdr_func_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message_router *, router,
 		     ast_cdr_message_router(), ao2_cleanup);
 
@@ -505,6 +510,13 @@
 		return -1;
 	}
 
+	if (!cdr_write_message_type()) {
+		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n",
+			ast_channel_name(chan));
+		return -1;
+	}
+
+	payload = ao2_alloc(sizeof(*payload), NULL);
 	if (!payload) {
 		return -1;
 	}
@@ -543,6 +555,13 @@
 		return -1;
 	}
 
+	if (!cdr_write_message_type()) {
+		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n",
+			ast_channel_name(chan));
+		return -1;
+	}
+
+	payload = ao2_alloc(sizeof(*payload), NULL);
 	if (!payload) {
 		return -1;
 	}

Modified: trunk/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis.h?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/include/asterisk/stasis.h (original)
+++ trunk/include/asterisk/stasis.h Wed Aug  6 07:55:28 2014
@@ -274,6 +274,15 @@
 };
 
 /*!
+ * \brief Return code for Stasis message type creation attempts
+ */
+enum stasis_message_type_result {
+	STASIS_MESSAGE_TYPE_ERROR = -1,	/*!< Message type was not created due to allocation failure */
+	STASIS_MESSAGE_TYPE_SUCCESS,	/*!< Message type was created successfully */
+	STASIS_MESSAGE_TYPE_DECLINED,	/*!< Message type was not created due to configuration */
+};
+
+/*!
  * \brief Create a new message type.
  *
  * \ref stasis_message_type is an AO2 object, so ao2_cleanup() when you're done
@@ -281,12 +290,15 @@
  *
  * \param name Name of the new type.
  * \param vtable Virtual table of message methods. May be \c NULL.
- * \return Pointer to the new type.
- * \return \c NULL on error.
- * \since 12
- */
-struct stasis_message_type *stasis_message_type_create(const char *name,
-	struct stasis_message_vtable *vtable);
+ * \param[out] result The location where the new message type will be placed
+ *
+ * \note Stasis message type creation may be declined if the message type is disabled
+ *
+ * \returns A stasis_message_type_result enum
+ * \since 12
+ */
+enum stasis_message_type_result stasis_message_type_create(const char *name,
+	struct stasis_message_vtable *vtable, struct stasis_message_type **result);
 
 /*!
  * \brief Gets the name of a given message type
@@ -296,6 +308,16 @@
  * \since 12
  */
 const char *stasis_message_type_name(const struct stasis_message_type *type);
+
+/*!
+ * \brief Check whether a message type is declined
+ *
+ * \param name The name of the message type to check
+ *
+ * \retval zero The message type is not declined
+ * \retval non-zero The message type is declined
+ */
+int stasis_message_type_declined(const char *name);
 
 /*!
  * \brief Create a new message.
@@ -1184,9 +1206,8 @@
 #define STASIS_MESSAGE_TYPE_INIT(name)					\
 	({								\
 		ast_assert(_priv_ ## name == NULL);			\
-		_priv_ ## name = stasis_message_type_create(#name,	\
-			&_priv_ ## name ## _v);				\
-		_priv_ ## name ? 0 : -1;				\
+		stasis_message_type_create(#name,	\
+			&_priv_ ## name ## _v, &_priv_ ## name) == STASIS_MESSAGE_TYPE_ERROR ? 1 : 0;	\
 	})
 
 /*!

Modified: trunk/main/app.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/app.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Wed Aug  6 07:55:28 2014
@@ -3104,6 +3104,10 @@
 	struct ast_mwi_state *mwi_state;
 	struct stasis_message *message;
 
+	if (!ast_mwi_state_type()) {
+		return NULL;
+	}
+
 	mwi_state = ast_mwi_create(mailbox, context);
 	if (!mwi_state) {
 		return NULL;
@@ -3247,6 +3251,10 @@
 
 	ast_assert(blob != NULL);
 
+	if (!message_type) {
+		return NULL;
+	}
+
 	obj = ao2_alloc(sizeof(*obj), mwi_blob_dtor);
 	if (!obj) {
 		return NULL;

Modified: trunk/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bridge.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/bridge.c (original)
+++ trunk/main/bridge.c Wed Aug  6 07:55:28 2014
@@ -615,6 +615,10 @@
 {
 	RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
 
+	if (!ast_bridge_snapshot_type()) {
+		return NULL;
+	}
+
 	ast_bridge_lock(bridge);
 	snapshot = ast_bridge_snapshot_create(bridge);
 	ast_bridge_unlock(bridge);

Modified: trunk/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/ccss.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/ccss.c (original)
+++ trunk/main/ccss.c Wed Aug  6 07:55:28 2014
@@ -1032,8 +1032,15 @@
 	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
+	if (!message_type) {
+		return -1;
+	}
+
 	blob = ast_json_pack("{s: i}",
 		"core_id", core_id);
+	if (!blob) {
+		return -1;
+	}
 
 	if (extras) {
 		ast_json_object_update(blob, extras);

Modified: trunk/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cdr.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Wed Aug  6 07:55:28 2014
@@ -4198,7 +4198,7 @@
 void ast_cdr_engine_term(void)
 {
 	RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
-	RAII_VAR(void *, payload, ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
+	RAII_VAR(void *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
 	/* Since this is called explicitly during process shutdown, we might not have ever
@@ -4208,16 +4208,19 @@
 		return;
 	}
 
-	/* Make sure we have the needed items */
-	if (!stasis_router || !payload) {
-		return;
-	}
-
-	ast_debug(1, "CDR Engine termination request received; waiting on messages...\n");
-
-	message = stasis_message_create(cdr_sync_message_type(), payload);
-	if (message) {
-		stasis_message_router_publish_sync(stasis_router, message);
+	if (cdr_sync_message_type()) {
+		/* Make sure we have the needed items */
+		payload = ao2_alloc(sizeof(*payload), NULL);
+		if (!stasis_router || !payload) {
+			return;
+		}
+
+		ast_debug(1, "CDR Engine termination request received; waiting on messages...\n");
+
+		message = stasis_message_create(cdr_sync_message_type(), payload);
+		if (message) {
+			stasis_message_router_publish_sync(stasis_router, message);
+		}
 	}
 
 	if (ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE)) {

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Wed Aug  6 07:55:28 2014
@@ -678,6 +678,11 @@
 static struct stasis_message *create_channel_snapshot_message(struct ast_channel *channel)
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+
+	if (!ast_channel_snapshot_type()) {
+		return NULL;
+	}
+
 	ast_channel_lock(channel);
 	snapshot = ast_channel_snapshot_create(channel);
 	ast_channel_unlock(channel);

Modified: trunk/main/core_local.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/core_local.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/core_local.c (original)
+++ trunk/main/core_local.c Wed Aug  6 07:55:28 2014
@@ -357,6 +357,10 @@
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct local_pvt *p = (struct local_pvt *)base;
 
+	if (!ast_local_optimization_begin_type()) {
+		return;
+	}
+
 	json_object = ast_json_pack("{s: i, s: i}",
 			"dest", dest, "id", id);
 
@@ -394,6 +398,10 @@
 	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct local_pvt *p = (struct local_pvt *)base;
+
+	if (!ast_local_optimization_end_type()) {
+		return;
+	}
 
 	json_object = ast_json_pack("{s: i, s: i}", "success", success, "id", id);
 
@@ -500,6 +508,10 @@
 	RAII_VAR(struct ast_channel_snapshot *, two_snapshot, NULL, ao2_cleanup);
 	struct ast_channel *owner;
 	struct ast_channel *chan;
+
+	if (!ast_local_bridge_type()) {
+		return;
+	}
 
 	ast_unreal_lock_all(&p->base, &chan, &owner);
 

Modified: trunk/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/devicestate.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Wed Aug  6 07:55:28 2014
@@ -721,6 +721,10 @@
 
 	ast_assert(!ast_strlen_zero(device));
 
+	if (!ast_device_state_message_type()) {
+		return -1;
+	}
+
 	device_state = device_state_alloc(device, state, cachable, eid);
 	if (!device_state) {
 		return -1;
@@ -806,6 +810,10 @@
 	const char *device = NULL;
 	struct ast_devstate_aggregate aggregate;
 	int idx;
+
+	if (!ast_device_state_message_type()) {
+		return NULL;
+	}
 
 	/* Determine the new aggregate device state. */
 	ast_devstate_aggregate_init(&aggregate);

Modified: trunk/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/endpoints.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/endpoints.c (original)
+++ trunk/main/endpoints.c Wed Aug  6 07:55:28 2014
@@ -174,6 +174,10 @@
 	ast_assert(endpoint != NULL);
 	ast_assert(endpoint->topics != NULL);
 
+	if (!ast_endpoint_snapshot_type()) {
+		return;
+	}
+
 	snapshot = ast_endpoint_snapshot_create(endpoint);
 	if (!snapshot) {
 		return;
@@ -349,6 +353,11 @@
 static struct stasis_message *create_endpoint_snapshot_message(struct ast_endpoint *endpoint)
 {
 	RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+
+	if (!ast_endpoint_snapshot_type()) {
+		return NULL;
+	}
+
 	snapshot = ast_endpoint_snapshot_create(endpoint);
 	if (!snapshot) {
 		return NULL;

Modified: trunk/main/file.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/file.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/file.c (original)
+++ trunk/main/file.c Wed Aug  6 07:55:28 2014
@@ -96,6 +96,10 @@
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+
+	if (!type) {
+		return -1;
+	}
 
 	json_object = ast_json_pack("{s: s, s: o}",
 		"format", f->name,

Modified: trunk/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/loader.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/loader.c (original)
+++ trunk/main/loader.c Wed Aug  6 07:55:28 2014
@@ -803,6 +803,10 @@
 	RAII_VAR(struct ast_json *, event_object, NULL, ast_json_unref);
 	char res_buffer[8];
 
+	if (!ast_manager_get_generic_type()) {
+		return;
+	}
+
 	snprintf(res_buffer, sizeof(res_buffer), "%u", result);
 	event_object = ast_json_pack("{s: s, s: s}",
 			"Module", S_OR(name, "All"),

Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Aug  6 07:55:28 2014
@@ -1519,7 +1519,7 @@
 	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
-	if (!obj) {
+	if (!obj || !ast_manager_get_generic_type()) {
 		return;
 	}
 

Modified: trunk/main/named_acl.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/named_acl.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/named_acl.c (original)
+++ trunk/main/named_acl.c Wed Aug  6 07:55:28 2014
@@ -380,7 +380,7 @@
 	RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_json *, json_object, ast_json_object_create(), ast_json_unref);
 
-	if (!json_object) {
+	if (!json_object || !ast_named_acl_change_type()) {
 		goto publish_failure;
 	}
 

Modified: trunk/main/pickup.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/pickup.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/pickup.c (original)
+++ trunk/main/pickup.c Wed Aug  6 07:55:28 2014
@@ -282,6 +282,10 @@
 	RAII_VAR(struct ast_multi_channel_blob *, pickup_payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
+	if (!ast_call_pickup_type()) {
+		return -1;
+	}
+
 	if (!(pickup_payload = ast_multi_channel_blob_create(ast_json_null()))) {
 		return -1;
 	}

Modified: trunk/main/presencestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/presencestate.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/presencestate.c (original)
+++ trunk/main/presencestate.c Wed Aug  6 07:55:28 2014
@@ -263,8 +263,13 @@
 		const char *message)
 {
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_presence_state_message *, presence_state, presence_state_alloc(provider, state, subtype, message), ao2_cleanup);
-
+	RAII_VAR(struct ast_presence_state_message *, presence_state, NULL, ao2_cleanup);
+
+	if (!ast_presence_state_message_type()) {
+		return;
+	}
+
+	presence_state = presence_state_alloc(provider, state, subtype, message);
 	if (!presence_state) {
 		return;
 	}

Modified: trunk/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/rtp_engine.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/rtp_engine.c (original)
+++ trunk/main/rtp_engine.c Wed Aug  6 07:55:28 2014
@@ -1996,6 +1996,10 @@
 	RAII_VAR(struct rtcp_message_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
+	if (!message_type) {
+		return;
+	}
+
 	payload = ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor);
 	if (!payload || !report) {
 		return;

Modified: trunk/main/security_events.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/security_events.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/security_events.c (original)
+++ trunk/main/security_events.c Wed Aug  6 07:55:28 2014
@@ -1127,8 +1127,11 @@
 	const struct ast_security_event_ie_type *ies;
 	unsigned int i;
 
+	if (!ast_security_event_type()) {
+		return -1;
+	}
+
 	json_object = alloc_security_event_json_object(sec);
-
 	if (!json_object) {
 		return -1;
 	}

Modified: trunk/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/stasis.c (original)
+++ trunk/main/stasis.c Wed Aug  6 07:55:28 2014
@@ -41,6 +41,7 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_bridges.h"
 #include "asterisk/stasis_endpoints.h"
+#include "asterisk/config_options.h"
 
 /*** DOCUMENTATION
 	<managerEvent language="en_US" name="UserEvent">
@@ -60,6 +61,135 @@
 			</see-also>
 		</managerEventInstance>
 	</managerEvent>
+	<configInfo name="stasis" language="en_US">
+		<configFile name="stasis.conf">
+			<configObject name="declined_message_types">
+				<synopsis>Stasis message types for which to decline creation.</synopsis>
+				<configOption name="decline">
+					<synopsis>The message type to decline.</synopsis>
+					<description>
+						<para>This configuration option defines the name of the Stasis
+						message type that Asterisk is forbidden from creating and can be
+						specified as many times as necessary to achieve the desired result.</para>
+						<enumlist>
+							<enum name="stasis_app_recording_snapshot_type" />
+							<enum name="stasis_app_playback_snapshot_type" />
+							<enum name="stasis_test_message_type" />
+							<enum name="confbridge_start_type" />
+							<enum name="confbridge_end_type" />
+							<enum name="confbridge_join_type" />
+							<enum name="confbridge_leave_type" />
+							<enum name="confbridge_start_record_type" />
+							<enum name="confbridge_stop_record_type" />
+							<enum name="confbridge_mute_type" />
+							<enum name="confbridge_unmute_type" />
+							<enum name="confbridge_talking_type" />
+							<enum name="cel_generic_type" />
+							<enum name="ast_bridge_snapshot_type" />
+							<enum name="ast_bridge_merge_message_type" />
+							<enum name="ast_channel_entered_bridge_type" />
+							<enum name="ast_channel_left_bridge_type" />
+							<enum name="ast_blind_transfer_type" />
+							<enum name="ast_attended_transfer_type" />
+							<enum name="ast_endpoint_snapshot_type" />
+							<enum name="ast_endpoint_state_type" />
+							<enum name="ast_device_state_message_type" />
+							<enum name="ast_test_suite_message_type" />
+							<enum name="ast_mwi_state_type" />
+							<enum name="ast_mwi_vm_app_type" />
+							<enum name="ast_format_register_type" />
+							<enum name="ast_format_unregister_type" />
+							<enum name="ast_manager_get_generic_type" />
+							<enum name="ast_parked_call_type" />
+							<enum name="ast_channel_snapshot_type" />
+							<enum name="ast_channel_dial_type" />
+							<enum name="ast_channel_varset_type" />
+							<enum name="ast_channel_hangup_request_type" />
+							<enum name="ast_channel_dtmf_begin_type" />
+							<enum name="ast_channel_dtmf_end_type" />
+							<enum name="ast_channel_hold_type" />
+							<enum name="ast_channel_unhold_type" />
+							<enum name="ast_channel_chanspy_start_type" />
+							<enum name="ast_channel_chanspy_stop_type" />
+							<enum name="ast_channel_fax_type" />
+							<enum name="ast_channel_hangup_handler_type" />
+							<enum name="ast_channel_moh_start_type" />
+							<enum name="ast_channel_moh_stop_type" />
+							<enum name="ast_channel_monitor_start_type" />
+							<enum name="ast_channel_monitor_stop_type" />
+							<enum name="ast_channel_agent_login_type" />
+							<enum name="ast_channel_agent_logoff_type" />
+							<enum name="ast_channel_talking_start" />
+							<enum name="ast_channel_talking_stop" />
+							<enum name="ast_security_event_type" />
+							<enum name="ast_named_acl_change_type" />
+							<enum name="ast_local_bridge_type" />
+							<enum name="ast_local_optimization_begin_type" />
+							<enum name="ast_local_optimization_end_type" />
+							<enum name="stasis_subscription_change_type" />
+							<enum name="ast_multi_user_event_type" />
+							<enum name="stasis_cache_clear_type" />
+							<enum name="stasis_cache_update_type" />
+							<enum name="ast_network_change_type" />
+							<enum name="ast_system_registry_type" />
+							<enum name="ast_cc_available_type" />
+							<enum name="ast_cc_offertimerstart_type" />
+							<enum name="ast_cc_requested_type" />
+							<enum name="ast_cc_requestacknowledged_type" />
+							<enum name="ast_cc_callerstopmonitoring_type" />
+							<enum name="ast_cc_callerstartmonitoring_type" />
+							<enum name="ast_cc_callerrecalling_type" />
+							<enum name="ast_cc_recallcomplete_type" />
+							<enum name="ast_cc_failure_type" />
+							<enum name="ast_cc_monitorfailed_type" />
+							<enum name="ast_presence_state_message_type" />
+							<enum name="ast_rtp_rtcp_sent_type" />
+							<enum name="ast_rtp_rtcp_received_type" />
+							<enum name="ast_call_pickup_type" />
+							<enum name="aoc_s_type" />
+							<enum name="aoc_d_type" />
+							<enum name="aoc_e_type" />
+							<enum name="dahdichannel_type" />
+							<enum name="mcid_type" />
+							<enum name="session_timeout_type" />
+							<enum name="cdr_read_message_type" />
+							<enum name="cdr_write_message_type" />
+							<enum name="cdr_prop_write_message_type" />
+							<enum name="corosync_ping_message_type" />
+							<enum name="agi_exec_start_type" />
+							<enum name="agi_exec_end_type" />
+							<enum name="agi_async_start_type" />
+							<enum name="agi_async_exec_type" />
+							<enum name="agi_async_end_type" />
+							<enum name="queue_caller_join_type" />
+							<enum name="queue_caller_leave_type" />
+							<enum name="queue_caller_abandon_type" />
+							<enum name="queue_member_status_type" />
+							<enum name="queue_member_added_type" />
+							<enum name="queue_member_removed_type" />
+							<enum name="queue_member_pause_type" />
+							<enum name="queue_member_penalty_type" />
+							<enum name="queue_member_ringinuse_type" />
+							<enum name="queue_agent_called_type" />
+							<enum name="queue_agent_connect_type" />
+							<enum name="queue_agent_complete_type" />
+							<enum name="queue_agent_dump_type" />
+							<enum name="queue_agent_ringnoanswer_type" />
+							<enum name="meetme_join_type" />
+							<enum name="meetme_leave_type" />
+							<enum name="meetme_end_type" />
+							<enum name="meetme_mute_type" />
+							<enum name="meetme_talking_type" />
+							<enum name="meetme_talk_request_type" />
+							<enum name="appcdr_message_type" />
+							<enum name="forkcdr_message_type" />
+							<enum name="cdr_sync_message_type" />
+						</enumlist>
+					</description>
+				</configOption>
+			</configObject>
+		</configFile>
+	</configInfo>
 ***/
 
 /*!
@@ -801,6 +931,10 @@
 	/* This assumes that we have already unsubscribed */
 	ast_assert(stasis_subscription_is_subscribed(sub));
 
+	if (!stasis_subscription_change_type()) {
+		return;
+	}
+
 	change = subscription_change_alloc(topic, sub->uniqueid, "Subscribe");
 	if (!change) {
 		return;
@@ -825,6 +959,10 @@
 
 	/* This assumes that we have already unsubscribed */
 	ast_assert(!stasis_subscription_is_subscribed(sub));
+
+	if (!stasis_subscription_change_type()) {
+		return;
+	}
 
 	change = subscription_change_alloc(topic, sub->uniqueid, "Unsubscribe");
 	if (!change) {
@@ -1066,6 +1204,10 @@
 	RAII_VAR(struct ast_channel_snapshot *, channel_snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_multi_object_blob *, multi, NULL, ao2_cleanup);
 
+	if (!type) {
+		return;
+	}
+
 	multi = ast_multi_object_blob_create(blob);
 	if (!multi) {
 		return;
@@ -1215,6 +1357,113 @@
 		ast_str_buffer(body));
 }
 
+/*! \brief A structure to hold global configuration-related options */
+struct stasis_declined_config {
+	/*! The list of message types to decline */
+	struct ao2_container *declined;
+};
+
+
+struct stasis_config {
+	struct stasis_declined_config *declined_message_types;
+};
+
+/*! \brief An aco_type structure to link the "declined_message_types" category to the stasis_declined_config type */
+static struct aco_type declined_option = {
+	.type = ACO_GLOBAL,
+	.name = "declined_message_types",
+	.item_offset = offsetof(struct stasis_config, declined_message_types),
+	.category_match = ACO_WHITELIST,
+	.category = "^declined_message_types$",
+};
+
+struct aco_type *declined_options[] = ACO_TYPES(&declined_option);
+
+struct aco_file stasis_conf = {
+        .filename = "stasis.conf",
+	.types = ACO_TYPES(&declined_option),
+};
+
+/*! \brief A global object container that will contain the stasis_config that gets swapped out on reloads */
+static AO2_GLOBAL_OBJ_STATIC(globals);
+
+static void *stasis_config_alloc(void);
+
+/*! \brief Register information about the configs being processed by this module */
+CONFIG_INFO_CORE("stasis", cfg_info, globals, stasis_config_alloc,
+        .files = ACO_FILES(&stasis_conf),
+);
+
+static void stasis_declined_config_destructor(void *obj)
+{
+	struct stasis_declined_config *declined = obj;
+	ao2_cleanup(declined->declined);
+}
+
+static void stasis_config_destructor(void *obj)
+{
+	struct stasis_config *cfg = obj;
+	ao2_cleanup(cfg->declined_message_types);
+}
+
+static void *stasis_config_alloc(void)
+{
+	struct stasis_config *cfg;
+
+	if (!(cfg = ao2_alloc(sizeof(*cfg), stasis_config_destructor))) {
+		return NULL;
+	}
+
+	/* Allocate/initialize memory */
+	cfg->declined_message_types = ao2_alloc(sizeof(*cfg->declined_message_types), stasis_declined_config_destructor);
+	if (!cfg->declined_message_types) {
+		goto error;
+	}
+
+	cfg->declined_message_types->declined = ast_str_container_alloc(13);
+	if (!cfg->declined_message_types->declined) {
+		goto error;
+	}
+
+	return cfg;
+error:
+	ao2_ref(cfg, -1);
+	return NULL;
+}
+
+int stasis_message_type_declined(const char *name)
+{
+	RAII_VAR(struct stasis_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
+	char *name_in_declined;
+	int res;
+
+	if (!cfg || !cfg->declined_message_types) {
+		return 0;
+	}
+
+	name_in_declined = ao2_find(cfg->declined_message_types->declined, name, OBJ_SEARCH_KEY);
+	res = name_in_declined ? 1 : 0;
+	ao2_cleanup(name_in_declined);
+	if (res) {
+		ast_log(LOG_NOTICE, "Declining to allocate Stasis message type '%s' due to configuration\n", name);
+	}
+	return res;
+}
+
+static int declined_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct stasis_declined_config *declined = obj;
+
+	if (ast_strlen_zero(var->value)) {
+		return 0;
+	}
+
+	if (ast_str_container_add(declined->declined, var->value)) {
+		return -1;
+	}
+
+	return 0;
+}
 
 /*!
  * @{ \brief Define multi user event message type(s).
@@ -1232,6 +1481,8 @@
 {
 	STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_multi_user_event_type);
+	aco_info_destroy(&cfg_info);
+	ao2_global_obj_release(globals);
 }
 
 int stasis_init(void)
@@ -1240,6 +1491,24 @@
 
 	/* Be sure the types are cleaned up after the message bus */
 	ast_register_cleanup(stasis_cleanup);
+
+	if (aco_info_init(&cfg_info)) {
+		return -1;
+	}
+
+	aco_option_register_custom(&cfg_info, "decline", ACO_EXACT, declined_options, "", declined_handler, 0);
+
+	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
+		RAII_VAR(struct stasis_config *, stasis_cfg, stasis_config_alloc(), ao2_cleanup);
+
+		if (aco_set_defaults(&declined_option, "declined_message_types", stasis_cfg->declined_message_types)) {
+			ast_log(LOG_ERROR, "Failed to load stasis.conf and failed to initialize defaults.\n");
+			return -1;
+		}
+
+		ast_log(LOG_NOTICE, "Could not load stasis config; using defaults\n");
+		ao2_global_obj_replace_unref(globals, stasis_cfg);
+	}
 
 	cache_init = stasis_cache_init();
 	if (cache_init != 0) {

Modified: trunk/main/stasis_bridges.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_bridges.c?view=diff&rev=420124&r1=420123&r2=420124
==============================================================================
--- trunk/main/stasis_bridges.c (original)
+++ trunk/main/stasis_bridges.c Wed Aug  6 07:55:28 2014
@@ -267,6 +267,10 @@
 	RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
+	if (!ast_bridge_snapshot_type()) {
+		return;
+	}
+
 	ast_assert(bridge != NULL);
 
 	snapshot = ast_bridge_snapshot_create(bridge);
@@ -357,6 +361,10 @@
 {
 	RAII_VAR(struct ast_bridge_merge_message *, merge_msg, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+	if (!ast_bridge_merge_message_type()) {
+		return;
+	}
 
 	ast_assert(to != NULL);
 	ast_assert(from != NULL);
@@ -393,6 +401,10 @@
 {
 	RAII_VAR(struct ast_bridge_blob *, obj, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+	if (!message_type) {
+		return NULL;
+	}
 
 	obj = ao2_alloc(sizeof(*obj), bridge_blob_dtor);
 	if (!obj) {
@@ -958,6 +970,10 @@
 	RAII_VAR(struct ast_attended_transfer_message *, transfer_msg, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
+	if (!ast_attended_transfer_type()) {
+		return;
+	}
+
 	transfer_msg = attended_transfer_message_create(is_external, result, transferee, target);
 	if (!transfer_msg) {
 		return;

[... 627 lines stripped ...]



More information about the asterisk-commits mailing list