@@ -268,4 +268,81 @@ define_function NAVCloudLog(dev device, long level, char message[]) {
268268}
269269
270270
271+ /* *
272+ * @function NAVCloudLogResponseInit
273+ * @public
274+ * @description Initializes a _NAVCloudLogResponse structure with empty values.
275+ * Useful for creating a clean response structure before parsing.
276+ *
277+ * @param {_NAVCloudLogResponse} response - The response structure to initialize
278+ *
279+ * @example
280+ * stack_var _NAVCloudLogResponse response
281+ * NAVCloudLogResponseInit(response)
282+ */
283+ define_function NAVCloudLogResponseInit (_NAVCloudLogResponse response ) {
284+ response .status = ' '
285+ response .id = ' '
286+ response .timestamp = ' '
287+ response .type = ' '
288+ response .message = ' '
289+ }
290+
291+
292+ /* *
293+ * @function NAVCloudLogResponseParse
294+ * @public
295+ * @description Parses a JSON response from the cloud logging service into a structured format.
296+ * Automatically initializes the response structure and extracts all fields
297+ * from the JSON payload (status, id, timestamp, type, message).
298+ *
299+ * @param {char[]} payload - JSON string containing the cloud logging service response
300+ * @param {_NAVCloudLogResponse} response - Output parameter to receive the parsed response data
301+ *
302+ * @returns {char} True if parsing succeeded, false if JSON parsing failed
303+ *
304+ * @example
305+ * stack_var _NAVCloudLogResponse response
306+ * stack_var char jsonPayload[1024]
307+ * jsonPayload = '{"status":"success","id":"abc-123","timestamp":"2026-01-29T10:30:00Z","type":"control_system"}'
308+ * if (NAVCloudLogResponseParse(jsonPayload, response)) {
309+ * // Response successfully parsed
310+ * if (response.status == 'success') {
311+ * send_string 0, "'Log submitted successfully: ', response.id"
312+ * }
313+ * }
314+ */
315+ define_function char NAVCloudLogResponseParse (char payload [], _NAVCloudLogResponse response ) {
316+ stack_var _NAVJson json
317+
318+ if (! NAVJsonParse (payload , json )) {
319+ NAVLibraryFunctionErrorLog (NAV_LOG_LEVEL_WARNING ,
320+ __NAV_FOUNDATION_CLOUDLOG__ ,
321+ ' NAVCloudLogResponseParse' ,
322+ ' Failed to parse JSON response' )
323+ return false
324+ }
325+
326+ NAVCloudLogResponseInit (response )
327+
328+ // Query all response fields
329+ NAVJsonQueryString (json , ' .status' , response .status )
330+ NAVJsonQueryString (json , ' .id' , response .id )
331+ NAVJsonQueryString (json , ' .timestamp' , response .timestamp )
332+ NAVJsonQueryString (json , ' .type' , response .type )
333+ NAVJsonQueryString (json , ' .message' , response .message )
334+
335+ // Validate that critical fields were found
336+ if (! length_array (response .status )) {
337+ NAVLibraryFunctionErrorLog (NAV_LOG_LEVEL_WARNING ,
338+ __NAV_FOUNDATION_CLOUDLOG__ ,
339+ ' NAVCloudLogResponseParse' ,
340+ ' Response missing required field: status' )
341+ return false
342+ }
343+
344+ return true
345+ }
346+
347+
271348#END_IF // __NAV_FOUNDATION_CLOUDLOG__
0 commit comments