ARI: Don't leak implementation details

This change prevents channels used as implementation details from
leaking out to ARI. It does this by preventing creation of JSON blobs
of channel snapshots created from those channels and sanitizing JSON
blobs of bridge snapshots as they are created. This introduces a
framework for excluding information from output targeted at Stasis
applications on a consumer-by-consumer basis using channel sanitization
callbacks which could be extended to bridges or endpoints if necessary.

This prevents unhelpful error messages from being generated by
ast_json_pack.

This also corrects a bug where BridgeCreated events would not be
created.

(closes issue ASTERISK-22744)
Review: https://reviewboard.asterisk.org/r/2987/
Reported by: David M. Lee


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@403069 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kinsey Moore
2013-11-22 20:01:26 +00:00
parent 1ac597135a
commit 0045449943
16 changed files with 314 additions and 80 deletions

View File

@@ -186,6 +186,36 @@ struct stasis_message_type;
*/
struct stasis_message;
/*!
* \brief Structure containing callbacks for Stasis message sanitization
*
* \note If either callback is implemented, both should be implemented since
* not all callers may have access to the full snapshot.
*/
struct stasis_message_sanitizer {
/*!
* \brief Callback which determines whether a channel should be sanitized from
* a message based on the channel's unique ID
*
* \param channel_id The unique ID of the channel
*
* \retval non-zero if the channel should be left out of the message
* \retval zero if the channel should remain in the message
*/
int (*channel_id)(const char *channel_id);
/*!
* \brief Callback which determines whether a channel should be sanitized from
* a message based on the channel's snapshot
*
* \param snapshot A snapshot generated from the channel
*
* \retval non-zero if the channel should be left out of the message
* \retval zero if the channel should remain in the message
*/
int (*channel_snapshot)(const struct ast_channel_snapshot *snapshot);
};
/*!
* \brief Virtual table providing methods for messages.
* \since 12
@@ -198,17 +228,19 @@ struct stasis_message_vtable {
* The returned object should be ast_json_unref()'ed.
*
* \param message Message to convert to JSON string.
* \param sanitize Snapshot sanitization callback.
*
* \return Newly allocated JSON message.
* \return \c NULL on error.
* \return \c NULL if JSON format is not supported.
*/
struct ast_json *(*to_json)(struct stasis_message *message);
struct ast_json *(*to_json)(struct stasis_message *message, const struct stasis_message_sanitizer *sanitize);
/*!
* \brief Build the AMI representation of the message.
*
* May be \c NULL, or may return \c NULL, to indicate no representation.
* The returned object should be ao2_cleankup()'ed.
* The returned object should be ao2_cleanup()'ed.
*
* \param message Message to convert to AMI string.
* \return Newly allocated \ref ast_manager_event_blob.
@@ -292,11 +324,13 @@ const struct timeval *stasis_message_timestamp(const struct stasis_message *msg)
* be ast_json_unref()'ed.
*
* \param message Message to convert to JSON string.
* \param sanitize Snapshot sanitization callback.
*
* \return Newly allocated string with JSON message.
* \return \c NULL on error.
* \return \c NULL if JSON format is not supported.
*/
struct ast_json *stasis_message_to_json(struct stasis_message *message);
struct ast_json *stasis_message_to_json(struct stasis_message *message, struct stasis_message_sanitizer *sanitize);
/*!
* \brief Build the AMI representation of the message.

View File

@@ -532,6 +532,13 @@ void stasis_app_ref(void);
*/
void stasis_app_unref(void);
/*!
* \brief Get the Stasis message sanitizer for app_stasis applications
*
* \retval The stasis message sanitizer
*/
struct stasis_message_sanitizer *stasis_app_get_sanitizer(void);
/*! @} */
#endif /* _ASTERISK_STASIS_APP_H */

View File

@@ -231,10 +231,15 @@ void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *cha
/*!
* \brief Build a JSON object from a \ref ast_bridge_snapshot.
*
* \param snapshot The bridge snapshot to convert to JSON
* \param sanitize The message sanitizer to use on the snapshot
*
* \return JSON object representing bridge snapshot.
* \return \c NULL on error
*/
struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot);
struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot,
const struct stasis_message_sanitizer *sanitize);
/*!
* \brief Pair showing a bridge snapshot and a specific channel snapshot belonging to the bridge

View File

@@ -541,10 +541,15 @@ void ast_publish_channel_state(struct ast_channel *chan);
/*!
* \brief Build a JSON object from a \ref ast_channel_snapshot.
*
* \param snapshot The snapshot to convert to JSON
* \param sanitize The message sanitizer to use on the snapshot
*
* \return JSON object representing channel snapshot.
* \return \c NULL on error
*/
struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot);
struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot,
const struct stasis_message_sanitizer *sanitize);
/*!
* \brief Compares the context, exten and priority of two snapshots.

View File

@@ -208,11 +208,14 @@ struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
* \brief Build a JSON object from a \ref ast_endpoint_snapshot.
*
* \param snapshot Endpoint snapshot.
* \param sanitize The message sanitizer to use on the snapshot
*
* \return JSON object representing endpoint snapshot.
* \return \c NULL on error
*/
struct ast_json *ast_endpoint_snapshot_to_json(
const struct ast_endpoint_snapshot *snapshot);
const struct ast_endpoint_snapshot *snapshot,
const struct stasis_message_sanitizer *sanitize);
/*!
* \brief Initialization function for endpoint stasis support.