AWS IoT Device Defender v1.4.0
AWS IoT Device Defender Client Library
 
Loading...
Searching...
No Matches
Defender_MatchTopic
uint16_t topicLength,
DefenderTopic_t * pOutApi,
const char ** ppOutThingName,
uint16_t * pOutThingNameLength );
DefenderStatus_t Defender_MatchTopic(const char *pTopic, uint16_t topicLength, DefenderTopic_t *pOutApi, const char **ppOutThingName, uint16_t *pOutThingNameLength)
Check if the given topic is one of the Device Defender topics.
Definition: defender.c:465
DefenderStatus_t
Return codes from defender APIs.
Definition: defender.h:58
DefenderTopic_t
Topic values for subscription requests.
Definition: defender.h:71

Check if the given topic is one of the Device Defender topics.

The function outputs which API the topic is for. It also optionally outputs the starting location and length of the thing name in the given topic.

Parameters
[in]pTopicThe topic string to check.
[in]topicLengthThe length of the topic string.
[out]pOutApiThe defender topic API value.
[out]ppOutThingNameOptional parameter to output the beginning of the thing name in the topic string. Pass NULL if not needed.
[out]pOutThingNameLengthOptional parameter to output the length of the thing name in the topic string. Pass NULL if not needed.
Returns
DefenderSuccess if the topic is one of the defender topics; DefenderBadParameter if invalid parameters are passed; DefenderNoMatch if the topic is NOT one of the defender topics (parameter pOutApi gets DefenderInvalidTopic).

Example

// The following example shows how to use the Defender_MatchTopic API to
// check if an incoming MQTT publish message is a Device Defender message.
// pTopic and topicLength are the topic string and length of the topic on
// which the publish message is received. These are usually provided by the
// MQTT client used. We pass the last two argument as NULL as we are not
// interested in the thing name in the topic string.
status = Defender_MatchTopic( pTopic,
topicLength,
&( api ),
NULL,
NULL );
if( status == DefenderSuccess )
{
{
// The published JSON report was accepted by the AWS IoT Device
// Defender service. You can parse the response using your choice
// of JSON parser and ensure that the report Id is same as was sent
// in the defender report.
}
else if( api == DefenderJsonReportRejected )
{
// The published JSON report was rejected by the AWS IoT Device
// Defender service.
}
else
{
// Unexpected response.
}
}
@ DefenderSuccess
Definition: defender.h:60
@ DefenderJsonReportAccepted
Definition: defender.h:74
@ DefenderJsonReportRejected
Definition: defender.h:75