in source/otaJobParser/job_parser.c [28:196]
static JSONStatus_t populateCommonFields( const char * jobDoc,
const size_t jobDocLength,
int32_t fileIndex,
AfrOtaJobDocumentFields_t * result );
/**
* @brief Populates optional, common job document fields in result
*
* @param jobDoc FreeRTOS OTA job document
* @param jobDocLength OTA job document length
* @param fileIndex The index of the file to use
* @param result Job document structure to populate
* @return JSONStatus_t JSON parsing status
*/
static JSONStatus_t populateOptionalCommonFields( const char * jobDoc,
const size_t jobDocLength,
int32_t fileIndex,
AfrOtaJobDocumentFields_t * result );
/**
* @brief Populates MQTT job document fields in result
*
* @param jobDoc FreeRTOS OTA job document
* @param jobDocLength OTA job document length
* @param result Job document structure to populate
* @return JSONStatus_t JSON parsing status
*/
static JSONStatus_t populateMqttStreamingFields( const char * jobDoc,
const size_t jobDocLength,
AfrOtaJobDocumentFields_t * result );
/**
* @brief Populates HTTP job document fields in result
*
* @param jobDoc FreeRTOS OTA job document
* @param jobDocLength OTA job document length
* @param fileIndex The index of the file to use
* @param result Job document structure to populate
* @return JSONStatus_t JSON parsing status
*/
static JSONStatus_t populateHttpStreamingFields( const char * jobDoc,
const size_t jobDocLength,
int32_t fileIndex,
AfrOtaJobDocumentFields_t * result );
/**
* @brief Assembles an indexed OTA file query
*
* @param fileIndex The file index
* @param queryString The JSON element inside of the File JSON structure to
* search for
* @param queryStringLength The length of the query
* @param result The resulting value of the query key
* @param resultLength The length of the value
*/
static void buildIndexedFileQueryString( int32_t fileIndex,
const char * queryString,
size_t queryStringLength,
char * result,
size_t * resultLength );
/**
* @brief Searches the JSON document for the uint32_t value
*
* @param jobDoc FreeRTOS OTA job document
* @param jobDocLength OTA job document length
* @param query The JSON path to query
* @param queryLength The length of the JSON path
* @param value Pointer to set uint32_t value
* @return JSONStatus_t JSON parsing status
*/
static JSONStatus_t searchUintValue( const char * jobDoc,
const size_t jobDocLength,
const char * query,
const size_t queryLength,
uint32_t * value );
/**
* @brief Convert a non-null terminated string to a unsigned 32-bit integer
*
* @param string String representation of 32-bit unsigned integer
* @param length Length of the integer when represented as a string
* @param value Unsigned 32-bit integer representation of the value
* @return true Successfully converted to uint32
* @return false Unsuccessfully converted to uint32
*/
static bool uintFromString( const char * string,
const uint32_t length,
uint32_t * value );
/**
* @brief Check if a character is a digit
*
* @param c Character to validate
* @return true Character is a 0-9 digit
* @return false Character is not a digit
*/
static bool charIsDigit( const char c );
/**
* @brief Check for multiplication overflow between two uint32 values
*
* @param a First uint32 value
* @param b Second uint32 value
* @return true If overflow will occur
* @return false If overflow will not occur
*/
static bool multOverflowUnit32( const uint32_t a,
const uint32_t b );
/**
* @brief Check for addition overflow between two uint32 values
*
* @param a First uint32 value
* @param b Second uint32 value
* @return true If overflow will occur
* @return false If overflow will not occur
*/
static bool addOverflowUint32( const uint32_t a,
const uint32_t b );
bool populateJobDocFields( const char * jobDoc,
const size_t jobDocLength,
int32_t fileIndex,
AfrOtaJobDocumentFields_t * result )
{
bool populatedJobDocFields = false;
JSONStatus_t jsonResult = JSONNotFound;
const char * protocol = NULL;
size_t protocolLength = 0U;
/* TODO - Add assertions for NULL job docs or 0 length documents*/
jsonResult = populateCommonFields( jobDoc, jobDocLength, fileIndex, result );
if( jsonResult == JSONSuccess )
{
jsonResult = JSON_SearchConst( jobDoc,
jobDocLength,
"afr_ota.protocols[0]",
20U,
&protocol,
&protocolLength,
NULL );
}
/* Determine if the supported protocol is MQTT or HTTP */
if( ( jsonResult == JSONSuccess ) && ( protocolLength == 4U ) )
{
if( strncmp( "MQTT", protocol, protocolLength ) == 0 )
{
jsonResult = populateMqttStreamingFields( jobDoc,
jobDocLength,
result );
}
else
{
jsonResult = populateHttpStreamingFields( jobDoc,
jobDocLength,
fileIndex,
result );
}
}
populatedJobDocFields = ( jsonResult == JSONSuccess );
/* Should this nullify the fields which have been populated before
* returning? */
return populatedJobDocFields;
}