[asterisk-commits] dlee: branch dlee/ari-url-shuffle r391765 - in /team/dlee/ari-url-shuffle: ./...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 13 22:09:19 CDT 2013


Author: dlee
Date: Thu Jun 13 22:09:17 2013
New Revision: 391765

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391765
Log:
Merged revisions 391596-391732 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    team/dlee/ari-url-shuffle/   (props changed)
    team/dlee/ari-url-shuffle/apps/app_confbridge.c
    team/dlee/ari-url-shuffle/apps/confbridge/conf_config_parser.c
    team/dlee/ari-url-shuffle/apps/confbridge/include/confbridge.h
    team/dlee/ari-url-shuffle/include/asterisk/_private.h
    team/dlee/ari-url-shuffle/include/asterisk/cel.h
    team/dlee/ari-url-shuffle/include/asterisk/channel.h
    team/dlee/ari-url-shuffle/include/asterisk/config_options.h
    team/dlee/ari-url-shuffle/include/asterisk/json.h
    team/dlee/ari-url-shuffle/include/asterisk/parking.h
    team/dlee/ari-url-shuffle/include/asterisk/stasis.h
    team/dlee/ari-url-shuffle/include/asterisk/stasis_bridging.h
    team/dlee/ari-url-shuffle/include/asterisk/stasis_channels.h
    team/dlee/ari-url-shuffle/include/asterisk/stasis_endpoints.h
    team/dlee/ari-url-shuffle/include/asterisk/strings.h
    team/dlee/ari-url-shuffle/main/asterisk.c
    team/dlee/ari-url-shuffle/main/cel.c
    team/dlee/ari-url-shuffle/main/channel.c
    team/dlee/ari-url-shuffle/main/channel_internal_api.c
    team/dlee/ari-url-shuffle/main/config_options.c
    team/dlee/ari-url-shuffle/main/endpoints.c
    team/dlee/ari-url-shuffle/main/features.c
    team/dlee/ari-url-shuffle/main/features_config.c
    team/dlee/ari-url-shuffle/main/json.c
    team/dlee/ari-url-shuffle/main/manager.c
    team/dlee/ari-url-shuffle/main/parking.c
    team/dlee/ari-url-shuffle/main/pbx.c
    team/dlee/ari-url-shuffle/main/stasis_bridging.c
    team/dlee/ari-url-shuffle/main/stasis_cache.c
    team/dlee/ari-url-shuffle/main/stasis_channels.c
    team/dlee/ari-url-shuffle/main/stasis_endpoints.c
    team/dlee/ari-url-shuffle/res/parking/parking_manager.c
    team/dlee/ari-url-shuffle/res/stasis_http/resource_endpoints.c
    team/dlee/ari-url-shuffle/utils/ael_main.c
    team/dlee/ari-url-shuffle/utils/check_expr.c
    team/dlee/ari-url-shuffle/utils/conf2ael.c
    team/dlee/ari-url-shuffle/utils/refcounter.c

Propchange: team/dlee/ari-url-shuffle/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/dlee/ari-url-shuffle/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jun 13 22:09:17 2013
@@ -1,1 +1,1 @@
-/trunk:1-391564
+/trunk:1-391764

Modified: team/dlee/ari-url-shuffle/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/apps/app_confbridge.c?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/apps/app_confbridge.c (original)
+++ team/dlee/ari-url-shuffle/apps/app_confbridge.c Thu Jun 13 22:09:17 2013
@@ -3142,7 +3142,7 @@
 {
 	int res = 0;
 
-	if (conf_load_config(0)) {
+	if (conf_load_config()) {
 		ast_log(LOG_ERROR, "Unable to load config. Not loading module.\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
@@ -3191,7 +3191,7 @@
 
 static int reload(void)
 {
-	return conf_load_config(1);
+	return conf_reload_config();
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Conference Bridge Application",

Modified: team/dlee/ari-url-shuffle/apps/confbridge/conf_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/apps/confbridge/conf_config_parser.c?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/apps/confbridge/conf_config_parser.c (original)
+++ team/dlee/ari-url-shuffle/apps/confbridge/conf_config_parser.c Thu Jun 13 22:09:17 2013
@@ -1889,12 +1889,10 @@
 	return 0;
 }
 
-int conf_load_config(int reload)
-{
-	if (!reload) {
-		if (aco_info_init(&cfg_info)) {
-			return -1;
-		}
+int conf_load_config(void)
+{
+	if (aco_info_init(&cfg_info)) {
+		return -1;
 	}
 
 	/* User options */
@@ -1944,21 +1942,27 @@
 	aco_option_register(&cfg_info, "type", ACO_EXACT, menu_types, NULL, OPT_NOOP_T, 0, 0);
 	aco_option_register_custom(&cfg_info, "^[0-9A-D*#]+$", ACO_REGEX, menu_types, NULL, menu_option_handler, 0);
 
-	if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {
+	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
 		goto error;
 	}
 
-	if (!reload && ast_cli_register_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser))) {
+	if (ast_cli_register_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser))) {
 		goto error;
 	}
 
 	return 0;
 error:
-	/* On a reload, just keep the config we already have in place. */
-	if (!reload) {
-		conf_destroy_config();
-	}
+	conf_destroy_config();
 	return -1;
+}
+
+int conf_reload_config(void)
+{
+	if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
+		/* On a reload, just keep the config we already have in place. */
+		return -1;
+	}
+	return 0;
 }
 
 static void conf_user_profile_copy(struct user_profile *dst, struct user_profile *src)

Modified: team/dlee/ari-url-shuffle/apps/confbridge/include/confbridge.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/apps/confbridge/include/confbridge.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/apps/confbridge/include/confbridge.h (original)
+++ team/dlee/ari-url-shuffle/apps/confbridge/include/confbridge.h Thu Jun 13 22:09:17 2013
@@ -247,7 +247,10 @@
 };
 
 /*! \brief load confbridge.conf file */
-int conf_load_config(int reload);
+int conf_load_config(void);
+
+/*! \brief reload confbridge.conf file */
+int conf_reload_config(void);
 
 /*! \brief destroy the information loaded from the confbridge.conf file*/
 void conf_destroy_config(void);

Modified: team/dlee/ari-url-shuffle/include/asterisk/_private.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/_private.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/_private.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/_private.h Thu Jun 13 22:09:17 2013
@@ -134,4 +134,10 @@
 
 /*! \brief initializes the rtp engine arrays */
 int ast_rtp_engine_init(void);
+
+/*!
+ * \brief initializes the rtp engine arrays
+ * \since 12.0.0
+ */
+int ast_parking_stasis_init(void);
 #endif /* _ASTERISK__PRIVATE_H */

Modified: team/dlee/ari-url-shuffle/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/cel.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/cel.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/cel.h Thu Jun 13 22:09:17 2013
@@ -103,6 +103,8 @@
 	AST_CEL_PICKUP = 24,
 	/*! \brief this call was forwarded somewhere else  */
 	AST_CEL_FORWARD = 25,
+	/*! \brief a bridge turned into a conference and will be treated as such until it is torn down */
+	AST_CEL_BRIDGE_TO_CONF = 26,
 };
 
 /*! 

Modified: team/dlee/ari-url-shuffle/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/channel.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/channel.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/channel.h Thu Jun 13 22:09:17 2013
@@ -152,6 +152,7 @@
 #include "asterisk/framehook.h"
 #include "asterisk/stasis.h"
 #include "asterisk/json.h"
+#include "asterisk/endpoints.h"
 
 #define DATASTORE_INHERIT_FOREVER	INT_MAX
 
@@ -4265,4 +4266,16 @@
  */
 int ast_channel_move(struct ast_channel *dest, struct ast_channel *source);
 
+/*!
+ * \since 12
+ * \brief Forward channel stasis messages to the given endpoint
+ *
+ * \param chan The channel to forward from
+ * \param endpoint The endpoint to forward to
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *endpoint);
+
 #endif /* _ASTERISK_CHANNEL_H */

Modified: team/dlee/ari-url-shuffle/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/config_options.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/config_options.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/config_options.h Thu Jun 13 22:09:17 2013
@@ -146,10 +146,11 @@
 
 /*! \brief The representation of a single configuration file to be processed */
 struct aco_file {
-	const char *filename; /*!< \brief The filename to be processed */
-	const char *alias;    /*!< \brief An alias filename to be tried if 'filename' cannot be found */
-	const char **preload; /*!< \brief A null-terminated oredered array of categories to be loaded first */
-	struct aco_type *types[]; /*!< The list of types for this config. Required. Use a sentinel! */
+	const char *filename;       /*!< The filename to be processed */
+	const char *alias;          /*!< An alias filename to be tried if 'filename' cannot be found */
+	const char **preload;       /*!< A null-terminated ordered array of categories to be loaded first */
+	const char *skip_category;  /*!< A regular expression of categories to skip in the file. Use when a file is processed by multiple modules */
+	struct aco_type *types[];   /*!< The list of types for this config. Required. Use a sentinel! */
 };
 
 struct aco_info {

Modified: team/dlee/ari-url-shuffle/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/json.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/json.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/json.h Thu Jun 13 22:09:17 2013
@@ -604,15 +604,6 @@
 const char *ast_json_object_iter_key(struct ast_json_iter *iter);
 
 /*!
- * \brief Retrieve the iterator object for a particular key
- * \since 12.0.0
- *
- * \param key Key of the field the \c ast_json_iter points to
- * \return \ref ast_json_iter object that points to \a key
- */
-struct ast_json_iter *ast_json_object_key_to_iter(const char *key);
-
-/*!
  * \brief Get the value from an iterator.
  * \since 12.0.0
  *
@@ -638,23 +629,6 @@
  * \return -1 on error.
  */
 int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter, struct ast_json *value);
-
-/*!
- * \brief Iterate over key/value pairs
- *
- * \note This is a reproduction of the jansson library's \ref json_object_foreach
- * using the equivalent ast_* wrapper functions. This creates a for loop using the various
- * iteration function calls.
- *
- * \param object The \ref ast_json object that contains key/value tuples to iterate over
- * \param key A \c const char pointer key for the key/value tuple
- * \param value A \ref ast_json object for the key/value tuple
- */
-#define ast_json_object_foreach(object, key, value) \
-	for (key = ast_json_object_iter_key(ast_json_object_iter(object)); \
-		key && (value = ast_json_object_iter_value(ast_json_object_key_to_iter(key))); \
-		key = ast_json_object_iter_key(ast_json_object_iter_next(object, ast_json_object_key_to_iter(key))))
-
 
 /*!@}*/
 

Modified: team/dlee/ari-url-shuffle/include/asterisk/parking.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/parking.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/parking.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/parking.h Thu Jun 13 22:09:17 2013
@@ -76,18 +76,6 @@
 		struct ast_channel_snapshot *parkee_snapshot, struct ast_channel_snapshot *parker_snapshot,
 		struct ast_channel_snapshot *retriever_snapshot, const char *parkinglot,
 		unsigned int parkingspace, unsigned long int timeout, unsigned long int duration);
-
-/*!
- * \brief initialize parking stasis types
- * \since 12
- */
-void ast_parking_stasis_init(void);
-
-/*!
- * \brief disable parking stasis types
- * \since 12
- */
-void ast_parking_stasis_disable(void);
 
 /*!
  * \brief accessor for the parking stasis topic

Modified: team/dlee/ari-url-shuffle/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/stasis.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/stasis.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/stasis.h Thu Jun 13 22:09:17 2013
@@ -670,9 +670,23 @@
  * \return \c NULL if message is not found.
  * \since 12
  */
-struct stasis_message *stasis_cache_get(struct stasis_caching_topic *caching_topic,
+#define stasis_cache_get(caching_topic, type, id) stasis_cache_get_extended(caching_topic, type, id, 0)
+
+/*!
+ * \brief Retrieve an item from the cache.
+ * \param caching_topic The topic returned from stasis_caching_topic_create().
+ * \param type Type of message to retrieve.
+ * \param id Identity of the snapshot to retrieve.
+ * \param guaranteed If set to 1 it is guaranteed that any pending messages have been processed.
+ * \return Message from the cache. The cache still owns the message, so
+ *         ao2_ref() if you want to keep it.
+ * \return \c NULL if message is not found.
+ * \since 12
+ */
+struct stasis_message *stasis_cache_get_extended(struct stasis_caching_topic *caching_topic,
 					struct stasis_message_type *type,
-					const char *id);
+					const char *id,
+					unsigned int guaranteed);
 
 /*!
  * \brief Dump cached items to a subscription

Modified: team/dlee/ari-url-shuffle/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/stasis_bridging.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/stasis_bridging.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/stasis_bridging.h Thu Jun 13 22:09:17 2013
@@ -45,6 +45,8 @@
 	struct ao2_container *channels;
 	/*! Bridge flags to tweak behavior */
 	struct ast_flags feature_flags;
+	/*! Bridge capabilities */
+	uint32_t capabilities;
 	/*! Number of channels participating in the bridge */
 	unsigned int num_channels;
 	/*! Number of active channels in the bridge. */

Modified: team/dlee/ari-url-shuffle/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/stasis_channels.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/stasis_channels.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/stasis_channels.h Thu Jun 13 22:09:17 2013
@@ -52,6 +52,9 @@
 		AST_STRING_FIELD(exten);		/*!< Dialplan: Current extension number */
 		AST_STRING_FIELD(caller_name);		/*!< Caller ID Name */
 		AST_STRING_FIELD(caller_number);	/*!< Caller ID Number */
+		AST_STRING_FIELD(caller_ani);		/*!< Caller ID ANI Number */
+		AST_STRING_FIELD(caller_rdnis);		/*!< Caller ID RDNIS Number */
+		AST_STRING_FIELD(caller_dnid);		/*!< Caller ID DNID Number */
 		AST_STRING_FIELD(connected_name);	/*!< Connected Line Name */
 		AST_STRING_FIELD(connected_number);	/*!< Connected Line Number */
 		AST_STRING_FIELD(language);		/*!< The default spoken language for the channel */

Modified: team/dlee/ari-url-shuffle/include/asterisk/stasis_endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/stasis_endpoints.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/stasis_endpoints.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/stasis_endpoints.h Thu Jun 13 22:09:17 2013
@@ -122,12 +122,14 @@
  *
  * \param tech Name of the endpoint's technology.
  * \param resource Resource name of the endpoint.
+ * \param guaranteed Whether to require all pending messages to have been processed or not.
  * \return Snapshot of the endpoint with the given name.
  * \return \c NULL if endpoint is not found, or on error.
  * \since 12
  */
 struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
-	const char *resource
+	const char *resource,
+	unsigned int guaranteed
 );
 
 /*! @} */

Modified: team/dlee/ari-url-shuffle/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/strings.h?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/strings.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/strings.h Thu Jun 13 22:09:17 2013
@@ -1067,4 +1067,46 @@
 	return abs(hash);
 }
 
+/*!
+ * \brief Convert a string to all lower-case
+ *
+ * \param str The string to be converted to lower case
+ *
+ * \retval str for convenience
+ */
+static force_inline char *attribute_pure ast_str_to_lower(char *str)
+{
+	char *str_orig = str;
+	if (!str) {
+		return str;
+	}
+
+	for (; *str; ++str) {
+		*str = tolower(*str);
+	}
+
+	return str_orig;
+}
+
+/*!
+ * \brief Convert a string to all upper-case
+ *
+ * \param str The string to be converted to upper case
+ *
+ * \retval str for convenience
+ */
+static force_inline char *attribute_pure ast_str_to_upper(char *str)
+{
+	char *str_orig = str;
+	if (!str) {
+		return str;
+	}
+
+	for (; *str; ++str) {
+		*str = toupper(*str);
+	}
+
+	return str_orig;
+}
+
 #endif /* _ASTERISK_STRINGS_H */

Modified: team/dlee/ari-url-shuffle/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/main/asterisk.c?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/main/asterisk.c (original)
+++ team/dlee/ari-url-shuffle/main/asterisk.c Thu Jun 13 22:09:17 2013
@@ -4323,11 +4323,6 @@
 		exit(1);
 	}
 
-	if (ast_cel_engine_init()) {
-		printf("%s", term_quit());
-		exit(1);
-	}
-
 	if (ast_device_state_engine_init()) {
 		printf("%s", term_quit());
 		exit(1);
@@ -4367,6 +4362,16 @@
 	}
 
 	if (ast_bridging_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_parking_stasis_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_cel_engine_init()) {
 		printf("%s", term_quit());
 		exit(1);
 	}

Modified: team/dlee/ari-url-shuffle/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/main/cel.c?view=diff&rev=391765&r1=391764&r2=391765
==============================================================================
--- team/dlee/ari-url-shuffle/main/cel.c (original)
+++ team/dlee/ari-url-shuffle/main/cel.c Thu Jun 13 22:09:17 2013
@@ -53,21 +53,99 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/utils.h"
 #include "asterisk/config.h"
+#include "asterisk/config_options.h"
 #include "asterisk/cli.h"
 #include "asterisk/astobj2.h"
-
-/*! Is the CEL subsystem enabled ? */
-static unsigned char cel_enabled;
-
-/*! \brief CEL is off by default */
-#define CEL_ENABLED_DEFAULT		0
-
-/*!
- * \brief which events we want to track
- *
- * \note bit field, up to 64 events
- */
-static int64_t eventset;
+#include "asterisk/stasis_message_router.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_bridging.h"
+#include "asterisk/bridging.h"
+#include "asterisk/parking.h"
+
+/*** DOCUMENTATION
+	<configInfo name="cel" language="en_US">
+		<configFile name="cel.conf">
+			<configObject name="general">
+				<synopsis>Options that apply globally to Channel Event Logging (CEL)</synopsis>
+				<configOption name="enable">
+					<synopsis>Determines whether CEL is enabled</synopsis>
+				</configOption>
+				<configOption name="dateformat">
+					<synopsis>The format to be used for dates when logging</synopsis>
+				</configOption>
+				<configOption name="apps">
+					<synopsis>List of apps for CEL to track</synopsis>
+					<description><para>A case-insensitive, comma-separated list of applications
+					to track when one or both of APP_START and APP_END events are flagged for
+					tracking</para></description>
+				</configOption>
+				<configOption name="events">
+					<synopsis>List of events for CEL to track</synopsis>
+					<description><para>A case-sensitive, comma-separated list of event names
+					to track. These event names do not include the leading <literal>AST_CEL</literal>.
+					</para>
+					<enumlist>
+						<enum name="ALL">
+							<para>Special value which tracks all events.</para>
+						</enum>
+						<enum name="CHAN_START"/>
+						<enum name="CHAN_END"/>
+						<enum name="ANSWER"/>
+						<enum name="HANGUP"/>
+						<enum name="APP_START"/>
+						<enum name="APP_END"/>
+						<enum name="BRIDGE_START"/>
+						<enum name="BRIDGE_END"/>
+						<enum name="BRIDGE_UPDATE"/>
+						<enum name="BRIDGE_TO_CONF"/>
+						<enum name="CONF_START"/>
+						<enum name="CONF_END"/>
+						<enum name="PARK_START"/>
+						<enum name="PARK_END"/>
+						<enum name="TRANSFER"/>
+						<enum name="USER_DEFINED"/>
+						<enum name="CONF_ENTER"/>
+						<enum name="CONF_EXIT"/>
+						<enum name="BLINDTRANSFER"/>
+						<enum name="ATTENDEDTRANSFER"/>
+						<enum name="PICKUP"/>
+						<enum name="FORWARD"/>
+						<enum name="3WAY_START"/>
+						<enum name="3WAY_END"/>
+						<enum name="HOOKFLASH"/>
+						<enum name="LINKEDID_END"/>
+
+					</enumlist>
+					</description>
+				</configOption>
+			</configObject>
+		</configFile>
+	</configInfo>
+ ***/
+
+/*! Message router for state that CEL needs to know about */
+static struct stasis_message_router *cel_state_router;
+
+/*! Aggregation topic for all topics CEL needs to know about */
+static struct stasis_topic *cel_state_topic;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_channel_forwarder;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_bridge_forwarder;
+
+/*! Subscription for forwarding the parking topic */
+static struct stasis_subscription *cel_parking_forwarder;
+
+/*! Container for primary channel/bridge ID listing for 2 party bridges */
+static struct ao2_container *bridge_primaries;
+
+/*! The number of buckets into which primary channel uniqueids will be hashed */
+#define BRIDGE_PRIMARY_BUCKETS 251
+
+/*! Container for dial end multichannel blobs for holding on to dial statuses */
+static struct ao2_container *cel_dialstatus_store;
 
 /*!
  * \brief Maximum possible CEL event IDs
@@ -76,14 +154,14 @@
 #define CEL_MAX_EVENT_IDS 64
 
 /*!
- * \brief Track no events by default.
- */
-#define CEL_DEFAULT_EVENTS	0
-
-/*!
  * \brief Number of buckets for the appset container
  */
 #define NUM_APP_BUCKETS		97
+
+/*!
+ * \brief Number of buckets for the dialstatus container
+ */
+#define NUM_DIALSTATUS_BUCKETS	251
 
 /*!
  * \brief Container of Asterisk application names
@@ -92,13 +170,127 @@
  * in the configuration as applications that CEL events should be generated
  * for when they start and end on a channel.
  */
-static struct ao2_container *appset;
 static struct ao2_container *linkedids;
 
-/*!
- * \brief Configured date format for event timestamps
- */
-static char cel_dateformat[256];
+/*! \brief A structure to hold global configuration-related options */
+struct cel_general_config {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
+	);
+	int enable;			/*!< Whether CEL is enabled */
+	int64_t events;			/*!< The events to be logged */
+	struct ao2_container *apps;	/*!< The apps for which to log app start and end events */
+};
+
+/*! \brief Destructor for cel_config */
+static void cel_general_config_dtor(void *obj)
+{
+	struct cel_general_config *cfg = obj;
+	ast_string_field_free_memory(cfg);
+	ao2_cleanup(cfg->apps);
+	cfg->apps = NULL;
+}
+
+static void *cel_general_config_alloc(void)
+{
+	RAII_VAR(struct cel_general_config *, cfg, NULL, ao2_cleanup);
+
+	if (!(cfg = ao2_alloc(sizeof(*cfg), cel_general_config_dtor))) {
+		return NULL;
+	}
+
+	if (ast_string_field_init(cfg, 64)) {
+		return NULL;
+	}
+
+	if (!(cfg->apps = ast_str_container_alloc(NUM_APP_BUCKETS))) {
+		return NULL;
+	}
+
+	ao2_ref(cfg, +1);
+	return cfg;
+}
+
+/*! \brief A container that holds all config-related information */
+struct cel_config {
+	struct cel_general_config *general;
+};
+
+
+static AO2_GLOBAL_OBJ_STATIC(cel_configs);
+
+/*! \brief Destructor for cel_config */
+static void cel_config_dtor(void *obj)
+{
+	struct cel_config *cfg = obj;
+	ao2_cleanup(cfg->general);
+	cfg->general = NULL;
+}
+
+static void *cel_config_alloc(void)
+{
+	RAII_VAR(struct cel_config *, cfg, NULL, ao2_cleanup);
+
+	if (!(cfg = ao2_alloc(sizeof(*cfg), cel_config_dtor))) {
+		return NULL;
+	}
+
+	if (!(cfg->general = cel_general_config_alloc())) {
+		return NULL;
+	}
+
+	ao2_ref(cfg, +1);
+	return cfg;
+}
+
+/*! \brief An aco_type structure to link the "general" category to the cel_general_config type */
+static struct aco_type general_option = {
+	.type = ACO_GLOBAL,
+	.name = "general",
+	.item_offset = offsetof(struct cel_config, general),
+	.category_match = ACO_WHITELIST,
+	.category = "^general$",
+};
+
+/*! \brief The config file to be processed for the module. */
+static struct aco_file cel_conf = {
+	.filename = "cel.conf",                  /*!< The name of the config file */
+	.types = ACO_TYPES(&general_option),     /*!< The mapping object types to be processed */
+	.skip_category = "(^manager$|^radius$)", /*!< Config sections used by existing modules. Do not add to this list. */
+};
+
+static int cel_pre_apply_config(void);
+
+CONFIG_INFO_CORE("cel", cel_cfg_info, cel_configs, cel_config_alloc,
+	.files = ACO_FILES(&cel_conf),
+	.pre_apply_config = cel_pre_apply_config,
+);
+
+static int cel_pre_apply_config(void)
+{
+	struct cel_config *cfg = aco_pending_config(&cel_cfg_info);
+
+	if (!cfg->general) {
+		return -1;
+	}
+
+	if (!ao2_container_count(cfg->general->apps)) {
+		return 0;
+	}
+
+	if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_START)) {
+		return 0;
+	}
+
+	if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_END)) {
+		return 0;
+	}
+
+	ast_log(LOG_ERROR, "Applications are listed to be tracked, but APP events are not tracked\n");
+	return -1;
+}
+
+static struct aco_type *general_options[] = ACO_TYPES(&general_option);
 
 /*!
  * \brief Map of ast_cel_event_type to strings
@@ -114,6 +306,7 @@
 	[AST_CEL_BRIDGE_START]     = "BRIDGE_START",
 	[AST_CEL_BRIDGE_END]       = "BRIDGE_END",
 	[AST_CEL_BRIDGE_UPDATE]    = "BRIDGE_UPDATE",
+	[AST_CEL_BRIDGE_TO_CONF]   = "BRIDGE_TO_CONF",
 	[AST_CEL_CONF_START]       = "CONF_START",
 	[AST_CEL_CONF_END]         = "CONF_END",
 	[AST_CEL_PARK_START]       = "PARK_START",
@@ -132,6 +325,114 @@
 	[AST_CEL_LINKEDID_END]     = "LINKEDID_END",
 };
 
+struct bridge_assoc {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(bridge_id);           /*!< UniqueID of the bridge */
+		AST_STRING_FIELD(secondary_name);      /*!< UniqueID of the secondary/dialed channel */
+	);
+	struct ast_channel_snapshot *primary_snapshot; /*!< The snapshot for the initiating channel in the bridge */
+	int track_as_conf;                             /*!< Whether this bridge will be treated like a conference in CEL terms */
+};
+
+static void bridge_assoc_dtor(void *obj)
+{
+	struct bridge_assoc *assoc = obj;
+	ast_string_field_free_memory(assoc);
+	ao2_cleanup(assoc->primary_snapshot);
+	assoc->primary_snapshot = NULL;
+}
+
+static struct bridge_assoc *bridge_assoc_alloc(struct ast_channel_snapshot *primary, const char *bridge_id, const char *secondary_name)
+{
+	RAII_VAR(struct bridge_assoc *, assoc, ao2_alloc(sizeof(*assoc), bridge_assoc_dtor), ao2_cleanup);
+	if (!primary || !assoc || ast_string_field_init(assoc, 64)) {
+		return NULL;
+	}
+
+	ast_string_field_set(assoc, bridge_id, bridge_id);
+	ast_string_field_set(assoc, secondary_name, secondary_name);
+
+	assoc->primary_snapshot = primary;
+	ao2_ref(primary, +1);
+
+	ao2_ref(assoc, +1);
+	return assoc;
+}
+
+static int add_bridge_primary(struct ast_channel_snapshot *primary, const char *bridge_id, const char *secondary_name)
+{
+	RAII_VAR(struct bridge_assoc *, assoc, bridge_assoc_alloc(primary, bridge_id, secondary_name), ao2_cleanup);
+	if (!assoc) {
+		return -1;
+	}
+
+	ao2_link(bridge_primaries, assoc);
+	return 0;
+}
+
+static void remove_bridge_primary(const char *channel_id)
+{
+	ao2_find(bridge_primaries, channel_id, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK | OBJ_KEY);
+}
+
+/*! \brief Hashing function for bridge_assoc */
+static int bridge_assoc_hash(const void *obj, int flags)
+{
+	const struct bridge_assoc *assoc = obj;
+	const char *uniqueid = obj;
+	if (!(flags & OBJ_KEY)) {
+		uniqueid = assoc->primary_snapshot->uniqueid;
+	}
+
+	return ast_str_hash(uniqueid);
+}
+
+/*! \brief Comparator function for bridge_assoc */
+static int bridge_assoc_cmp(void *obj, void *arg, int flags)
+{
+	struct bridge_assoc *assoc1 = obj, *assoc2 = arg;
+	const char *assoc2_id = arg, *assoc1_id = assoc1->primary_snapshot->uniqueid;
+	if (!(flags & OBJ_KEY)) {
+		assoc2_id = assoc2->primary_snapshot->uniqueid;
+	}
+
+	return !strcmp(assoc1_id, assoc2_id) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static const char *get_caller_uniqueid(struct ast_multi_channel_blob *blob)
+{
+	struct ast_channel_snapshot *caller = ast_multi_channel_blob_get_channel(blob, "caller");
+	if (!caller) {
+		return NULL;
+	}
+
+	return caller->uniqueid;
+}
+
+/*! \brief Hashing function for dialstatus container */
+static int dialstatus_hash(const void *obj, int flags)
+{
+	struct ast_multi_channel_blob *blob = (void *) obj;
+	const char *uniqueid = obj;
+	if (!(flags & OBJ_KEY)) {
+		uniqueid = get_caller_uniqueid(blob);
+	}
+
+	return ast_str_hash(uniqueid);
+}
+
+/*! \brief Comparator function for dialstatus container */
+static int dialstatus_cmp(void *obj, void *arg, int flags)
+{
+	struct ast_multi_channel_blob *blob1 = obj, *blob2 = arg;
+	const char *blob2_id = arg, *blob1_id = get_caller_uniqueid(blob1);
+	if (!(flags & OBJ_KEY)) {
+		blob2_id = get_caller_uniqueid(blob2);
+	}
+
+	return !strcmp(blob1_id, blob2_id) ? CMP_MATCH | CMP_STOP : 0;
+}
+
 /*!
  * \brief Map of ast_cel_ama_flags to strings
  */
@@ -144,7 +445,13 @@
 
 unsigned int ast_cel_check_enabled(void)
 {
-	return cel_enabled;
+	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+
+	if (!cfg || !cfg->general) {
+		return 0;
+	}
+
+	return cfg->general->enable;
 }
 
 static int print_app(void *obj, void *arg, int flags)
@@ -168,6 +475,7 @@
 {
 	unsigned int i;
 	struct ast_event_sub *sub;
+	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -186,16 +494,20 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	ast_cli(a->fd, "CEL Logging: %s\n", cel_enabled ? "Enabled" : "Disabled");
-
-	if (!cel_enabled) {
+	ast_cli(a->fd, "CEL Logging: %s\n", ast_cel_check_enabled() ? "Enabled" : "Disabled");
+
+	if (!cfg || !cfg->general) {
 		return CLI_SUCCESS;
 	}
 
-	for (i = 0; i < (sizeof(eventset) * 8); i++) {
+	if (!cfg->general->enable) {
+		return CLI_SUCCESS;
+	}
+
+	for (i = 0; i < (sizeof(cfg->general->events) * 8); i++) {
 		const char *name;
 
-		if (!(eventset & ((int64_t) 1 << i))) {
+		if (!(cfg->general->events & ((int64_t) 1 << i))) {
 			continue;
 		}
 
@@ -205,7 +517,7 @@
 		}
 	}
 
-	ao2_callback(appset, OBJ_NODATA, print_app, a);
+	ao2_callback(cfg->general->apps, OBJ_NODATA, print_app, a);
 
 	if (!(sub = ast_event_subscribe_new(AST_EVENT_SUB, print_cel_sub, a))) {
 		return CLI_FAILURE;
@@ -239,12 +551,19 @@
 
 static int ast_cel_track_event(enum ast_cel_event_type et)
 {
-	return (eventset & ((int64_t) 1 << et));
-}
-
-static void parse_events(const char *val)
-{
-	char *events = ast_strdupa(val);
+	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+
+	if (!cfg || !cfg->general) {
+		return 0;
+	}
+
+	return (cfg->general->events & ((int64_t) 1 << et));
+}
+
+static int events_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct cel_general_config *cfg = obj;
+	char *events = ast_strdupa(var->value);
 	char *cur_event;
 
 	while ((cur_event = strsep(&events, ","))) {
@@ -259,102 +578,46 @@
 
 		if (event_type == 0) {
 			/* All events */
-			eventset = (int64_t) -1;
+			cfg->events = (int64_t) -1;
 		} else if (event_type == -1) {
-			ast_log(LOG_WARNING, "Unknown event name '%s'\n",
-					cur_event);
+			ast_log(LOG_ERROR, "Unknown event name '%s'\n", cur_event);
+			return -1;
 		} else {
-			eventset |= ((int64_t) 1 << event_type);
-		}
-	}
-}
-
-static void parse_apps(const char *val)
-{
-	char *apps = ast_strdupa(val);
+			cfg->events |= ((int64_t) 1 << event_type);
+		}
+	}
+
+	return 0;
+}
+
+static int apps_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct cel_general_config *cfg = obj;
+	char *apps = ast_strdupa(var->value);
 	char *cur_app;
 
-	if (!ast_cel_track_event(AST_CEL_APP_START) && !ast_cel_track_event(AST_CEL_APP_END)) {
-		ast_log(LOG_WARNING, "An apps= config line, but not tracking APP events\n");
-		return;
-	}
-
 	while ((cur_app = strsep(&apps, ","))) {
-		char *app;
-
 		cur_app = ast_strip(cur_app);
 		if (ast_strlen_zero(cur_app)) {
 			continue;
 		}
 
-		if (!(app = ao2_alloc(strlen(cur_app) + 1, NULL))) {
-			continue;
-		}
-		strcpy(app, cur_app);
-
-		ao2_link(appset, app);
-		ao2_ref(app, -1);
-		app = NULL;
-	}
-}
-
-AST_MUTEX_DEFINE_STATIC(reload_lock);
+		cur_app = ast_str_to_lower(cur_app);
+		ast_str_container_add(cfg->apps, cur_app);
+	}
+
+	return 0;
+}
 
 static int do_reload(void)
 {
-	struct ast_config *config;
-	const char *enabled_value;
-	const char *val;
-	int res = 0;
-	struct ast_flags config_flags = { 0, };
-	const char *s;
-
-	ast_mutex_lock(&reload_lock);
-
-	/* Reset all settings before reloading configuration */
-	cel_enabled = CEL_ENABLED_DEFAULT;
-	eventset = CEL_DEFAULT_EVENTS;
-	*cel_dateformat = '\0';
-	ao2_callback(appset, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
-
-	config = ast_config_load2("cel.conf", "cel", config_flags);
-
-	if (config == CONFIG_STATUS_FILEMISSING) {
-		config = NULL;
-		goto return_cleanup;
-	}
-
-	if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
-		cel_enabled = ast_true(enabled_value);
-	}
-
-	if (!cel_enabled) {
-		goto return_cleanup;
-	}
-
-	/* get the date format for logging */
-	if ((s = ast_variable_retrieve(config, "general", "dateformat"))) {
-		ast_copy_string(cel_dateformat, s, sizeof(cel_dateformat));
-	}
-
-	if ((val = ast_variable_retrieve(config, "general", "events"))) {
-		parse_events(val);
-	}
-
-	if ((val = ast_variable_retrieve(config, "general", "apps"))) {
-		parse_apps(val);
-	}
-
-return_cleanup:
-	ast_verb(3, "CEL logging %sabled.\n", cel_enabled ? "en" : "dis");
-
-	ast_mutex_unlock(&reload_lock);
-
-	if (config) {
-		ast_config_destroy(config);
-	}
-
-	return res;
+	if (aco_process_config(&cel_cfg_info, 1) == ACO_PROCESS_ERROR) {
+		return -1;
+	}
+
+	ast_verb(3, "CEL logging %sabled.\n", ast_cel_check_enabled() ? "en" : "dis");
+
+	return 0;
 }
 
 const char *ast_cel_get_type_name(enum ast_cel_event_type type)
@@ -372,29 +635,125 @@
 	return S_OR(cel_ama_flags[flag], "Unknown");
 }
 
+static int cel_track_app(const char *const_app)
+{
+	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+	RAII_VAR(char *, app, NULL, ao2_cleanup);
+	char *app_lower;
+
+	if (!cfg || !cfg->general) {
+		return 0;
+	}
+
+	app_lower = ast_str_to_lower(ast_strdupa(const_app));
+	app = ao2_find(cfg->general->apps, app_lower, OBJ_KEY);
+	if (!app) {
+		return 0;
+	}
+
+	return 1;
+}
+
+static int report_event_snapshot(struct ast_channel_snapshot *snapshot,
+		enum ast_cel_event_type event_type, const char *userdefevname,
+		const char *extra, const char *peer2_name)
+{
+	struct timeval eventtime;
+	struct ast_event *ev;
+	char *linkedid = ast_strdupa(snapshot->linkedid);
+	const char *peer_name = peer2_name;
+	RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
+	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+
+	if (!cfg || !cfg->general) {
+		return 0;
+	}
+
+	if (!cfg->general->enable) {
+		return 0;
+	}
+
+	if (ast_strlen_zero(peer_name)) {
+		assoc = ao2_find(bridge_primaries, snapshot->uniqueid, OBJ_KEY);
+		if (assoc) {
+			peer_name = assoc->secondary_name;
+		}
+	}
+
+	/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
+	 * reporting on CHANNEL_START so we can track when to send LINKEDID_END */
+	if (ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
+		if (ast_cel_linkedid_ref(linkedid)) {
+			return -1;
+		}
+	}
+
+	if (!ast_cel_track_event(event_type)) {
+		return 0;
+	}
+
+	if ((event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END)
+		&& !cel_track_app(snapshot->appl)) {
+		return 0;
+	}
+
+	eventtime = ast_tvnow();
+
+	ev = ast_event_new(AST_EVENT_CEL,
+		AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
+		AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
+		AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
+		AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, S_OR(userdefevname, ""),
+		AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_name,
+		AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_number,
+		AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_ani,
+		AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_rdnis,
+		AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_dnid,
+		AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, snapshot->exten,
+		AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, snapshot->context,
+		AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->name,
+		AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->appl,
+		AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, snapshot->data,
+		AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, snapshot->amaflags,
+		AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, snapshot->accountcode,
+		AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, snapshot->peeraccount,
+		AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, snapshot->uniqueid,
+		AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
+		AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
+		AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra, ""),
+		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, S_OR(peer_name, ""),
+		AST_EVENT_IE_END);
+
+	if (ev && ast_event_queue(ev)) {
+		ast_event_destroy(ev);
+		return -1;
+	}
+
+	return 0;
+}
+
 /* called whenever a channel is destroyed or a linkedid is changed to
  * potentially emit a CEL_LINKEDID_END event */
-void ast_cel_check_retire_linkedid(struct ast_channel *chan)
-{

[... 1386 lines stripped ...]



More information about the asterisk-commits mailing list