in source/demo-tasks/shadow_device_task.c [624:713]
static void prvIncomingPublishUpdateRejectedCallback( void * pxSubscriptionContext,
MQTTPublishInfo_t * pxPublishInfo )
{
JSONStatus_t result = JSONSuccess;
char * pcOutValue = NULL;
uint32_t ulOutValueLength = 0UL;
uint32_t ulReceivedToken = 0UL;
/* Remove compiler warnings about unused parameters. */
( void ) pxSubscriptionContext;
configASSERT( pxPublishInfo != NULL );
configASSERT( pxPublishInfo->pPayload != NULL );
LogDebug( ( "/update/rejected json payload: %.*s.",
pxPublishInfo->payloadLength,
( const char * ) pxPublishInfo->pPayload ) );
/* The payload will look similar to this:
* {
* "code": error-code,
* "message": "error-message",
* "timestamp": timestamp,
* "clientToken": "token"
* }
*/
/* Make sure the payload is a valid json document. */
result = JSON_Validate( pxPublishInfo->pPayload,
pxPublishInfo->payloadLength );
if( result != JSONSuccess )
{
LogError( ( "Invalid JSON document recieved!" ) );
}
else
{
/* Get clientToken from json documents. */
result = JSON_Search( ( char * ) pxPublishInfo->pPayload,
pxPublishInfo->payloadLength,
"clientToken",
sizeof( "clientToken" ) - 1,
&pcOutValue,
( size_t * ) &ulOutValueLength );
}
if( result != JSONSuccess )
{
LogDebug( ( "Ignoring publish on /update/rejected with clientToken %lu.", ( unsigned long ) ulReceivedToken ) );
}
else
{
/* Convert the code to an unsigned integer value. */
ulReceivedToken = ( uint32_t ) strtoul( pcOutValue, NULL, 10 );
/* If we are waiting for a response, ulClientToken will be the token for the response
* we are waiting for, else it will be 0. ulRecievedToken may not match if the response is
* not for us or if it is is a response that arrived after we timed out
* waiting for it.
*/
if( ulReceivedToken != ulClientToken )
{
LogDebug( ( "Ignoring publish on /update/rejected with clientToken %lu.", ( unsigned long ) ulReceivedToken ) );
}
else
{
/* Obtain the error code. */
result = JSON_Search( ( char * ) pxPublishInfo->pPayload,
pxPublishInfo->payloadLength,
"code",
sizeof( "code" ) - 1,
&pcOutValue,
( size_t * ) &ulOutValueLength );
if( result != JSONSuccess )
{
LogWarn( ( "Received rejected response for update with token %lu and no error code.", ( unsigned long ) ulClientToken ) );
}
else
{
LogWarn( ( "Received rejected response for update with token %lu and error code %.*s.", ( unsigned long ) ulClientToken,
ulOutValueLength,
pcOutValue ) );
}
/* Wake up the shadow task which is waiting for this response. */
xTaskNotifyGive( xShadowDeviceTaskHandle );
}
}
}