Skip to content

Commit

Permalink
Merge pull request aws#14 from aws/refactor/remove-client-id
Browse files Browse the repository at this point in the history
Remove "clientID" from RegisterThing payload response
  • Loading branch information
aggarw13 authored Nov 19, 2019
2 parents 59f1225 + 457f48f commit 475a7d3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 114 deletions.
13 changes: 3 additions & 10 deletions demos/src/aws_iot_demo_provisioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ static void _demoRegisterThingCallback( void * contextParam,

if( pResponseInfo->statusCode == AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED )
{
if( pResponseInfo->u.acceptedResponse.pClientId != NULL )
{
IotLogInfo( "ClientID = %.*s",
pResponseInfo->u.acceptedResponse.clientIdLength,
pResponseInfo->u.acceptedResponse.pClientId );
}

if( pResponseInfo->u.acceptedResponse.pThingName != NULL )
{
IotLogInfo( "ThingName = %.*s",
Expand Down Expand Up @@ -386,9 +379,9 @@ static int _establishMqttConnection( const char * pIdentifier,
* @param[in] awsIotMqttMode Ignored for the Provisioning demo.
* @param[in] pIdentifier NULL-terminated Provisioning Thing Name.
* @param[in] pNetworkServerInfo Passed to the MQTT connect function when
* establishing the MQTT connection for Provisionings.
* establishing the MQTT connection for testing the Fleet Provisioning feature of AWS Iot Core service.
* @param[in] pNetworkCredentialInfo Passed to the MQTT connect function when
* establishing the MQTT connection for Provisionings.
* establishing the MQTT connection for testing the Fleet Provisioning feature of AWS Iot Core service.
* @param[in] pNetworkInterface The network interface to use for this demo.
*
* @return `EXIT_SUCCESS` if the demo completes successfully; `EXIT_FAILURE` otherwise.
Expand Down Expand Up @@ -424,7 +417,7 @@ int RunProvisioningDemo( bool awsIotMqttMode,
/* Flags for tracking which cleanup functions must be called. */
bool librariesInitialized = false, connectionEstablished = false;

/* The first parameter of this demo function is not used. Provisionings are specific
/* The first parameter of this demo function is not used. Provisioning feature is specific
* to AWS IoT, so this value is hardcoded to true whenever needed. */
( void ) awsIotMqttMode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,6 @@ typedef struct AwsIotProvisioningRegisterThingResponse
/**< The length of the Thing resource name. */
size_t thingNameLength;

/**< The client ID used in the connection to the AWS IoT server for provisioning the device.*/
const char * pClientId;

/**< The length of the client ID text. */
size_t clientIdLength;

/**< A list of device configuration data that is received from the server. */
const AwsIotProvisioningResponseDeviceConfigurationEntry_t * pDeviceConfigList;

Expand Down
46 changes: 4 additions & 42 deletions libraries/aws/provisioning/src/aws_iot_provisioning_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

/**
* @file aws_iot_onbording_parser.c
* @file aws_iot_provisioning_parser.c
* @brief Implements the internal functions for parsing server responses for the Provisioning library.
*/

Expand Down Expand Up @@ -149,9 +149,9 @@ static AwsIotProvisioningError_t _parseRejectedResponse( IotSerializerDecoderObj
/*------------------------------------------------------------------*/

AwsIotProvisioningError_t _AwsIotProvisioning_ParseKeysAndCertificateResponse( AwsIotStatus_t responseType,
const void * pKeysAndCertificateResponse,
size_t keysAndCertificateResponseLength,
const _provisioningCallbackInfo_t * userCallbackInfo )
const void * pKeysAndCertificateResponse,
size_t keysAndCertificateResponseLength,
const _provisioningCallbackInfo_t * userCallbackInfo )
{
AwsIotProvisioning_Assert( pKeysAndCertificateResponse != NULL );
AwsIotProvisioning_Assert( userCallbackInfo != NULL );
Expand Down Expand Up @@ -349,7 +349,6 @@ AwsIotProvisioningError_t _AwsIotProvisioning_ParseRegisterThingResponse( AwsIot
AwsIotProvisioningResponseDeviceConfigurationEntry_t * pDeviceConfigurationList = NULL;
bool configurationListAllocated = false;
IotSerializerDecoderObject_t thingNameDecoder = IOT_SERIALIZER_DECODER_OBJECT_INITIALIZER;
IotSerializerDecoderObject_t clientIdDecoder = IOT_SERIALIZER_DECODER_OBJECT_INITIALIZER;

if( _pAwsIotProvisioningDecoder->init( &payloadDecoder,
pResponsePayload,
Expand Down Expand Up @@ -551,42 +550,6 @@ AwsIotProvisioningError_t _AwsIotProvisioning_ParseRegisterThingResponse( AwsIot
userCallbackParam.u.acceptedResponse.thingNameLength = thingNameDecoder.u.value.u.string.length;
}

/* Look for the client ID entry. */
decoderStatus = _pAwsIotProvisioningDecoder->find( &payloadDecoder,
PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_CLIENT_ID_STRING,
&clientIdDecoder );

/* Client ID entry NOT found in payload. */
if( decoderStatus != IOT_SERIALIZER_SUCCESS )
{
IotLogError(
"Client ID entry (searched with \"%s\" key) NOT present in server response for %s operation",
PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_CLIENT_ID_STRING,
REGISTER_THING_OPERATION_LOG );
IOT_SET_AND_GOTO_CLEANUP( AWS_IOT_PROVISIONING_BAD_RESPONSE );
}
else if( decoderStatus != IOT_SERIALIZER_SUCCESS )
{
IOT_SET_AND_GOTO_CLEANUP( AWS_IOT_PROVISIONING_INTERNAL_FAILURE );
}
/* Client ID entry FOUND in payload. */
else
{
if( clientIdDecoder.type != IOT_SERIALIZER_SCALAR_TEXT_STRING )
{
IotLogError(
"Invalid \"%s\" data received in server response for %s operation. Value is expected to be a text string.",
PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_CLIENT_ID_STRING,
REGISTER_THING_OPERATION_LOG );
IOT_SET_AND_GOTO_CLEANUP( AWS_IOT_PROVISIONING_BAD_RESPONSE );
}

/* Populate information for the "Client ID" data. */
userCallbackParam.u.acceptedResponse.pClientId = ( const char * )
clientIdDecoder.u.value.u.string.pString;
userCallbackParam.u.acceptedResponse.clientIdLength = clientIdDecoder.u.value.u.string.length;
}

/* Populate the status code information to represent success response from the server. */
userCallbackParam.statusCode = AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED;

Expand Down Expand Up @@ -626,7 +589,6 @@ AwsIotProvisioningError_t _AwsIotProvisioning_ParseRegisterThingResponse( AwsIot

_pAwsIotProvisioningDecoder->destroy( &deviceConfigurationDecoder );
_pAwsIotProvisioningDecoder->destroy( &thingNameDecoder );
_pAwsIotProvisioningDecoder->destroy( &clientIdDecoder );
_pAwsIotProvisioningDecoder->destroy( &payloadDecoder );

IOT_FUNCTION_CLEANUP_END();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,6 @@
*/
#define PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_THING_NAME_STRING "thingName"

/**
* @brief The key for the connection client ID's entry in the response payload of the Provisioning RegisterThing service
* API.
*
* @note This should be utilized in parsing the success case response payload received from the server.
*/
#define PROVISIONING_REGISTER_THING_RESPONSE_PAYLOAD_CLIENT_ID_STRING "clientId"

/**
* @brief The key for the status code entry in the "rejected" response payload from the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,6 @@ static void _printRegisterThingResponseCallback( void * contextParam,

if( pResponseInfo->statusCode == AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED )
{
if( pResponseInfo->u.acceptedResponse.pClientId != NULL )
{
IotLogInfo( "ClientID = %.*s",
pResponseInfo->u.acceptedResponse.clientIdLength,
pResponseInfo->u.acceptedResponse.pClientId );
}

if( pResponseInfo->u.acceptedResponse.pThingName != NULL )
{
IotLogInfo( "ThingName = %.*s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static const char * _registerThingRejectedResponseTopic = "$aws/provisioning-tem
*/
static const uint8_t _sampleRegisterThingResponsePayload[] =
{
0xA3, /* # map(2) */
0xA2, /* # map(2) */
0x73, /* # text(19) */
0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6F, 0x6E, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74,
0x69, 0x6F, 0x6E, /* # "deviceConfiguration" */
Expand All @@ -279,10 +279,7 @@ static const uint8_t _sampleRegisterThingResponsePayload[] =
0x74, 0x68, 0x69, 0x6E, 0x67, 0x4E, 0x61, 0x6D, 0x65, /* # "thingName" */
0x69, /* # text(9) */
0x54, 0x65, 0x73, 0x74, 0x54, 0x68, 0x69, 0x6E, 0x67, /* # "TestThing" */
0x68, /*# text(8) */
0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x49, 0x64, /*# "clientId" */
0x65, /*# text(5) */
0x44, 0x75, 0x6D, 0x6D, 0x79 /*# "Dummy" */
0x68 /* # text(8) */
};

static const AwsIotProvisioningResponseDeviceConfigurationEntry_t _expectedDeviceConfigList[] =
Expand Down Expand Up @@ -311,8 +308,6 @@ static AwsIotProvisioningRegisterThingResponse_t _expectedRegisterThingCallbackP
.statusCode = AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED,
.u.acceptedResponse.pThingName = ( const char * ) &_sampleRegisterThingResponsePayload[ 113 ],
.u.acceptedResponse.thingNameLength = 9,
.u.acceptedResponse.pClientId = ( const char * ) &_sampleRegisterThingResponsePayload[ 132 ],
.u.acceptedResponse.clientIdLength = 5,
.u.acceptedResponse.pDeviceConfigList = _expectedDeviceConfigList,
.u.acceptedResponse.numOfConfigurationEntries = sizeof( _expectedDeviceConfigList ) /
sizeof( AwsIotProvisioningResponseDeviceConfigurationEntry_t )
Expand Down Expand Up @@ -435,18 +430,6 @@ static void _testRegisterThingCallback( void * contextParam,
pExpectedParams->u.acceptedResponse.thingNameLength ) );
}

AwsIotProvisioning_Assert(
pExpectedParams->u.acceptedResponse.clientIdLength ==
pResponseInfo->u.acceptedResponse.clientIdLength );

if( pExpectedParams->u.acceptedResponse.clientIdLength > 0 )
{
AwsIotProvisioning_Assert( 0 == memcmp(
pExpectedParams->u.acceptedResponse.pClientId,
pResponseInfo->u.acceptedResponse.pClientId,
pExpectedParams->u.acceptedResponse.clientIdLength ) );
}

AwsIotProvisioning_Assert(
pExpectedParams->u.acceptedResponse.numOfConfigurationEntries ==
pResponseInfo->u.acceptedResponse.numOfConfigurationEntries );
Expand Down Expand Up @@ -1207,7 +1190,7 @@ TEST( Provisioning_Unit_API, RegisterThingAPICorruptDataInResponse )
0x02, /* # unsigned(2), */
0x69, /* # text(9) */
0x74, 0x68, 0x69, 0x6E, 0x67, 0x4E, 0x61, 0x6D, 0x65, /* # "thingName" */
0x04 /* # unisgned(4) */
0x04 /* # unsigned(4) */
};

corruptResponseContext.pPublishData = serverResponseWithInvalidThingNameEntry;
Expand Down Expand Up @@ -1250,15 +1233,12 @@ TEST( Provisioning_Unit_API, RegisterThingAPIServerResponseWithoutDeviceConfigur
{
const uint8_t pResponseWithoutDeviceConfigData[] =
{
0xA2, /* # map(2) */
0xA1, /* # map(1) */
0x69, /* # text(9) */
0x74, 0x68, 0x69, 0x6E, 0x67, 0x4E, 0x61, 0x6D, 0x65, /* # "thingName" */
0x69, /* # text(9) */
0x54, 0x65, 0x73, 0x74, 0x54, 0x68, 0x69, 0x6E, 0x67, /* # "TestThing" */
0x68, /*# text(8) */
0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x49, 0x64, /*# "clientId" */
0x65, /*# text(5) */
0x44, 0x75, 0x6D, 0x6D, 0x79 /*# "Dummy" */
0x68, /* # text(8) */
};

_serverResponseThreadContext_t serverResponse =
Expand All @@ -1274,8 +1254,6 @@ TEST( Provisioning_Unit_API, RegisterThingAPIServerResponseWithoutDeviceConfigur
.statusCode = AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED,
.u.acceptedResponse.pThingName = ( const char * ) &pResponseWithoutDeviceConfigData[ 12 ],
.u.acceptedResponse.thingNameLength = 9,
.u.acceptedResponse.pClientId = ( const char * ) &pResponseWithoutDeviceConfigData[ 31 ],
.u.acceptedResponse.clientIdLength = 5,
.u.acceptedResponse.pDeviceConfigList = NULL,
.u.acceptedResponse.numOfConfigurationEntries = 0
};
Expand All @@ -1301,19 +1279,16 @@ TEST( Provisioning_Unit_API, RegisterThingAPIServerResponseWithoutThingName )
{
const uint8_t pServerResponseWithoutThingName[] =
{
0xA2, /* # map(2) */
0x73, /* # text(19) */
0xA1, /* # map(1) */
0x73, /* # text(19) */
0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6F, 0x6E, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61,
0x74, 0x69, 0x6F, 0x6E, /* # "deviceConfiguration" */
0xA1, /* # map(1), */
0x61, /* # text(1), */
0x31, /* # "1", */
0x61, /* # text(1), */
0x32, /* # "2" */
0x68, /*# text(8) */
0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x49, 0x64, /*# "clientId" */
0x65, /*# text(5) */
0x44, 0x75, 0x6D, 0x6D, 0x79 /*# "Dummy" */
0x74, 0x69, 0x6F, 0x6E, /* # "deviceConfiguration" */
0xA1, /* # map(1), */
0x61, /* # text(1), */
0x31, /* # "1", */
0x61, /* # text(1), */
0x32, /* # "2" */
0x68, /*# text(8) */
};

_serverResponseThreadContext_t serverResponse =
Expand All @@ -1339,8 +1314,6 @@ TEST( Provisioning_Unit_API, RegisterThingAPIServerResponseWithoutThingName )
.statusCode = AWS_IOT_PROVISIONING_SERVER_STATUS_ACCEPTED,
.u.acceptedResponse.pThingName = NULL,
.u.acceptedResponse.thingNameLength = 0,
.u.acceptedResponse.pClientId = ( const char * ) &pServerResponseWithoutThingName[ 36 ],
.u.acceptedResponse.clientIdLength = 5,
.u.acceptedResponse.pDeviceConfigList = pExpectedDeviceConfigList,
.u.acceptedResponse.numOfConfigurationEntries = 1
};
Expand Down

0 comments on commit 475a7d3

Please sign in to comment.