From b2c24e2bff2873acbd39c7a513cea98962390350 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 2 Jan 2020 16:06:31 -0500 Subject: Fix event argument population Forwarded events from voiceagents have their argument JSON as a whole stuck into a json-c string object which is then used as the outgoing event argument. The effect is the whole argument JSON is quoted and unusable until run through a JSON parser on the receiver side. This is contrary to the vshl-core event documentation and inconvenient for client implementors, so fix it by tokenizing the internal JSON string into a json_object tree and passing that as the event argument. Bug-AGL: SPEC-3084 Signed-off-by: Scott Murray Change-Id: If6a80de68c7932742b7cb83d5b128d5458d5e049 (cherry picked from commit a10448fa4784c2f88937db2e7fe341cf8f832647) --- src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp b/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp index 3b55505..bff9d8c 100644 --- a/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp +++ b/src/plugins/voiceagents/src/VoiceAgentEventsHandler.cpp @@ -14,6 +14,8 @@ */ #include "voiceagents/include/VoiceAgentEventsHandler.h" +#include + static string TAG = "vshlcore::voiceagents::VoiceAgentEventsHandler"; static string VA_VERB_SUBSCRIBE = "subscribe"; @@ -101,7 +103,17 @@ bool VoiceAgentEventsHandler::onIncomingEvent(const string eventName, const stri string eventNameWithVAId = createEventNameWithVAId(eventName, voiceAgentId); auto it = mEventsMap.find(eventNameWithVAId); if (it != mEventsMap.end()) { - return it->second->publishEvent(json_object_new_string(payload.c_str())); + json_object* payloadJ = NULL; + if(payload.length()) { + payloadJ = json_tokener_parse(payload.c_str()); + } else { + payloadJ = json_object_new_string(""); + } + if(!payloadJ) { + mLogger->log(Level::ERROR, TAG, "Unable to parse payload JSON: " + payload); + return false; + } + return it->second->publishEvent(payloadJ); } return true; -- cgit 1.2.3-korg