]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res/ari: Add the Asterisk EID field to outgoing events 26/4126/1
authorMatt Jordan <mjordan@digium.com>
Sun, 16 Oct 2016 01:05:05 +0000 (20:05 -0500)
committerGeorge Joseph <gjoseph@digium.com>
Mon, 17 Oct 2016 13:14:40 +0000 (08:14 -0500)
This patch adds the Asterisk EID field to all outgoing ARI events.
Because this field should be added to all events as they are
transmitted, it is appended to the JSON message just prior to it being
handed off to the application message handler. This makes it somewhat
resilient to both new events being added to ARI, as well as other
potential event transport mechanisms.

ASTERISK-26470 #close

Change-Id: Ieff0ecc24464e83f3f44e9c3e7bd9a5d70b87a1d

CHANGES
res/ari/ari_model_validators.c
res/ari/ari_model_validators.h
res/stasis/app.c
rest-api/api-docs/events.json
tests/test_res_stasis.c

diff --git a/CHANGES b/CHANGES
index 1fa978665ab3ca40fa283e6ad77b8a68398345aa..92b2a90941e6e1ee9114c078a15dd53f97dc032e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -89,6 +89,13 @@ app_dial
    when another channel answers the call.  The default of ANSWERED_ELSEWHERE
    is unchanged.
 
+res_ari
+------------------
+ * ARI events will all now include a new field in the root of the JSON message,
+   'asterisk_id'.  This will be the unique ID for the Asterisk system
+   transmitting the event.  The value can be overridden using the 'entityid'
+   setting in asterisk.conf.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 13 to Asterisk 14 --------------------
 ------------------------------------------------------------------------------
index 8f05db03561aacbc4cab17c38a479a6faf2fbf81..57c79c98416c602fc9f8a923150c6e1dba81c6bd 100644 (file)
@@ -1941,6 +1941,15 @@ int ast_ari_validate_application_replaced(struct ast_json *json)
        int has_application = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ApplicationReplaced field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2009,6 +2018,15 @@ int ast_ari_validate_bridge_attended_transfer(struct ast_json *json)
        int has_transferer_second_leg = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI BridgeAttendedTransfer field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2251,6 +2269,15 @@ int ast_ari_validate_bridge_blind_transfer(struct ast_json *json)
        int has_result = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI BridgeBlindTransfer field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2417,6 +2444,15 @@ int ast_ari_validate_bridge_created(struct ast_json *json)
        int has_bridge = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI BridgeCreated field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2496,6 +2532,15 @@ int ast_ari_validate_bridge_destroyed(struct ast_json *json)
        int has_bridge = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI BridgeDestroyed field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2576,6 +2621,15 @@ int ast_ari_validate_bridge_merged(struct ast_json *json)
        int has_bridge_from = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI BridgeMerged field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2672,6 +2726,15 @@ int ast_ari_validate_channel_caller_id(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelCallerId field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2781,6 +2844,15 @@ int ast_ari_validate_channel_connected_line(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelConnectedLine field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2860,6 +2932,15 @@ int ast_ari_validate_channel_created(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelCreated field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -2941,6 +3022,15 @@ int ast_ari_validate_channel_destroyed(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelDestroyed field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3052,6 +3142,15 @@ int ast_ari_validate_channel_dialplan(struct ast_json *json)
        int has_dialplan_app_data = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelDialplan field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3163,6 +3262,15 @@ int ast_ari_validate_channel_dtmf_received(struct ast_json *json)
        int has_duration_ms = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelDtmfReceived field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3272,6 +3380,15 @@ int ast_ari_validate_channel_entered_bridge(struct ast_json *json)
        int has_bridge = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelEnteredBridge field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3360,6 +3477,15 @@ int ast_ari_validate_channel_hangup_request(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHangupRequest field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3457,6 +3583,15 @@ int ast_ari_validate_channel_hold(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHold field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3546,6 +3681,15 @@ int ast_ari_validate_channel_left_bridge(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelLeftBridge field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3640,6 +3784,15 @@ int ast_ari_validate_channel_state_change(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelStateChange field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3720,6 +3873,15 @@ int ast_ari_validate_channel_talking_finished(struct ast_json *json)
        int has_duration = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelTalkingFinished field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3814,6 +3976,15 @@ int ast_ari_validate_channel_talking_started(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelTalkingStarted field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3893,6 +4064,15 @@ int ast_ari_validate_channel_unhold(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUnhold field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -3973,6 +4153,15 @@ int ast_ari_validate_channel_userevent(struct ast_json *json)
        int has_userevent = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUserevent field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4095,6 +4284,15 @@ int ast_ari_validate_channel_varset(struct ast_json *json)
        int has_variable = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelVarset field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4278,6 +4476,15 @@ int ast_ari_validate_contact_status_change(struct ast_json *json)
        int has_endpoint = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ContactStatusChange field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4372,6 +4579,15 @@ int ast_ari_validate_device_state_changed(struct ast_json *json)
        int has_device_state = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI DeviceStateChanged field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4452,6 +4668,15 @@ int ast_ari_validate_dial(struct ast_json *json)
        int has_peer = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI Dial field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4582,6 +4807,15 @@ int ast_ari_validate_endpoint_state_change(struct ast_json *json)
        int has_endpoint = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI EndpointStateChange field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4784,6 +5018,15 @@ int ast_ari_validate_event(struct ast_json *json)
        }
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI Event field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -4976,6 +5219,15 @@ int ast_ari_validate_message(struct ast_json *json)
        }
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI Message field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5015,6 +5267,15 @@ int ast_ari_validate_missing_params(struct ast_json *json)
        int has_params = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI MissingParams field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5146,6 +5407,15 @@ int ast_ari_validate_peer_status_change(struct ast_json *json)
        int has_peer = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI PeerStatusChange field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5319,6 +5589,15 @@ int ast_ari_validate_playback_finished(struct ast_json *json)
        int has_playback = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI PlaybackFinished field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5398,6 +5677,15 @@ int ast_ari_validate_playback_started(struct ast_json *json)
        int has_playback = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI PlaybackStarted field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5477,6 +5765,15 @@ int ast_ari_validate_recording_failed(struct ast_json *json)
        int has_recording = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI RecordingFailed field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5556,6 +5853,15 @@ int ast_ari_validate_recording_finished(struct ast_json *json)
        int has_recording = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI RecordingFinished field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5635,6 +5941,15 @@ int ast_ari_validate_recording_started(struct ast_json *json)
        int has_recording = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI RecordingStarted field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5714,6 +6029,15 @@ int ast_ari_validate_stasis_end(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI StasisEnd field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5794,6 +6118,15 @@ int ast_ari_validate_stasis_start(struct ast_json *json)
        int has_channel = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI StasisStart field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
@@ -5898,6 +6231,15 @@ int ast_ari_validate_text_message_received(struct ast_json *json)
        int has_message = 0;
 
        for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("asterisk_id", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI TextMessageReceived field asterisk_id failed validation\n");
+                               res = 0;
+                       }
+               } else
                if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
                        int prop_is_valid;
                        has_type = 1;
index 2634528bacec7349c874b781fc725382f3bd8cb0..ffe82cc460a5daaad332aee402be6239ebaca2da 100644 (file)
@@ -1486,10 +1486,12 @@ ari_validator ast_ari_validate_application_fn(void);
  * - new_messages: int (required)
  * - old_messages: int (required)
  * ApplicationReplaced
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * BridgeAttendedTransfer
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1510,6 +1512,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - transferer_second_leg: Channel (required)
  * - transferer_second_leg_bridge: Bridge
  * BridgeBlindTransfer
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1522,22 +1525,26 @@ ari_validator ast_ari_validate_application_fn(void);
  * - result: string (required)
  * - transferee: Channel
  * BridgeCreated
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - bridge: Bridge (required)
  * BridgeDestroyed
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - bridge: Bridge (required)
  * BridgeMerged
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - bridge: Bridge (required)
  * - bridge_from: Bridge (required)
  * ChannelCallerId
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1545,16 +1552,19 @@ ari_validator ast_ari_validate_application_fn(void);
  * - caller_presentation_txt: string (required)
  * - channel: Channel (required)
  * ChannelConnectedLine
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * ChannelCreated
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * ChannelDestroyed
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1562,6 +1572,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - cause_txt: string (required)
  * - channel: Channel (required)
  * ChannelDialplan
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1569,6 +1580,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - dialplan_app: string (required)
  * - dialplan_app_data: string (required)
  * ChannelDtmfReceived
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1576,12 +1588,14 @@ ari_validator ast_ari_validate_application_fn(void);
  * - digit: string (required)
  * - duration_ms: int (required)
  * ChannelEnteredBridge
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - bridge: Bridge (required)
  * - channel: Channel
  * ChannelHangupRequest
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1589,39 +1603,46 @@ ari_validator ast_ari_validate_application_fn(void);
  * - channel: Channel (required)
  * - soft: boolean
  * ChannelHold
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * - musicclass: string
  * ChannelLeftBridge
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - bridge: Bridge (required)
  * - channel: Channel (required)
  * ChannelStateChange
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * ChannelTalkingFinished
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * - duration: int (required)
  * ChannelTalkingStarted
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * ChannelUnhold
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * ChannelUserevent
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1631,6 +1652,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - eventname: string (required)
  * - userevent: object (required)
  * ChannelVarset
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1643,17 +1665,20 @@ ari_validator ast_ari_validate_application_fn(void);
  * - roundtrip_usec: string
  * - uri: string (required)
  * ContactStatusChange
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - contact_info: ContactInfo (required)
  * - endpoint: Endpoint (required)
  * DeviceStateChanged
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - device_state: DeviceState (required)
  * Dial
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1664,17 +1689,21 @@ ari_validator ast_ari_validate_application_fn(void);
  * - forwarded: Channel
  * - peer: Channel (required)
  * EndpointStateChange
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - endpoint: Endpoint (required)
  * Event
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * Message
+ * - asterisk_id: string
  * - type: string (required)
  * MissingParams
+ * - asterisk_id: string
  * - type: string (required)
  * - params: List[string] (required)
  * Peer
@@ -1684,6 +1713,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - port: string
  * - time: string
  * PeerStatusChange
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1695,36 +1725,43 @@ ari_validator ast_ari_validate_application_fn(void);
  * - timestamp: Date
  * - playback: Playback (required)
  * PlaybackFinished
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - playback: Playback (required)
  * PlaybackStarted
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - playback: Playback (required)
  * RecordingFailed
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - recording: LiveRecording (required)
  * RecordingFinished
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - recording: LiveRecording (required)
  * RecordingStarted
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - recording: LiveRecording (required)
  * StasisEnd
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
  * - channel: Channel (required)
  * StasisStart
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
@@ -1732,6 +1769,7 @@ ari_validator ast_ari_validate_application_fn(void);
  * - channel: Channel (required)
  * - replace_channel: Channel
  * TextMessageReceived
+ * - asterisk_id: string
  * - type: string (required)
  * - application: string (required)
  * - timestamp: Date
index fb313df990d4fe60f841c4675be3fe8133ac649a..8bd1bc05aba27ff17faf8a709423e66f52c73c77 100644 (file)
@@ -929,8 +929,15 @@ struct stasis_topic *ast_app_get_topic(struct stasis_app *app)
 void app_send(struct stasis_app *app, struct ast_json *message)
 {
        stasis_app_cb handler;
+       char eid[20];
        RAII_VAR(void *, data, NULL, ao2_cleanup);
 
+       if (ast_json_object_set(message, "asterisk_id", ast_json_string_create(
+                       ast_eid_to_str(eid, sizeof(eid), &ast_eid_default)))) {
+               ast_log(AST_LOG_WARNING, "Failed to append EID to outgoing event %s\n",
+                       ast_json_string_get(ast_json_object_get(message, "type")));
+       }
+
        /* Copy off mutable state with lock held */
        {
                SCOPED_AO2LOCK(lock, app);
index ca26161017a6b982a8bba8efd2376b5335d6f7c4..4ef1d21a49a35d858c7711f2d11df893801c83d0 100644 (file)
                                        "type": "string",
                                        "required": true,
                                        "description": "Indicates the type of this message."
+                               },
+                               "asterisk_id": {
+                                       "type": "string",
+                                       "required": false,
+                                       "description": "The unique ID for the Asterisk instance that raised this event."
                                }
                        },
                        "subTypes": [
index 4e28d44c6368160a6caa5f6f691fe9eaa57bf9f9..45989037323ece2eaa3d97accda9abce11bf5c1e 100644 (file)
@@ -138,6 +138,7 @@ AST_TEST_DEFINE(app_replaced)
        RAII_VAR(struct ast_json *, expected_message1, NULL, ast_json_unref);
        RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
        RAII_VAR(struct ast_json *, expected_message2, NULL, ast_json_unref);
+       char eid[20];
        int res;
 
        switch (cmd) {
@@ -158,9 +159,10 @@ AST_TEST_DEFINE(app_replaced)
 
        stasis_app_register(app_name, test_handler, app_data1);
        stasis_app_register(app_name, test_handler, app_data2);
-       expected_message1 = ast_json_pack("[{s: s, s: s}]",
+       expected_message1 = ast_json_pack("[{s: s, s: s, s: s}]",
                "type", "ApplicationReplaced",
-               "application", app_name);
+               "application", app_name,
+               "asterisk_id", ast_eid_to_str(eid, sizeof(eid), &ast_eid_default));
        message = ast_json_pack("{ s: o }", "test-message", ast_json_null());
        expected_message2 = ast_json_pack("[o]", ast_json_ref(message));