mirror of
https://github.com/FreeRTOS/coreMQTT
synced 2025-06-29 15:16:46 +08:00
fix: MISRA 15.1 (goto) violations - part 2 (#718)
* fix: MISRA 15.1 (goto) violations - part 2 This PR has changes for iot_mqtt_api.c, iot_mqtt_operation.c. and iot_mqtt_subscription.c.
This commit is contained in:
parent
acd02af830
commit
70a2697c91
@ -56,6 +56,7 @@ iot
|
||||
iotlink
|
||||
iotlistdouble
|
||||
iotlog
|
||||
iotlogdebug
|
||||
iotmqtt
|
||||
iotmqttcallbackinfo
|
||||
iotmqttconnectinfo
|
||||
@ -85,6 +86,7 @@ keepaliveseconds
|
||||
lu
|
||||
lwt
|
||||
malloc
|
||||
misra
|
||||
mqtt
|
||||
mqttconnection
|
||||
mqttoperation
|
||||
|
@ -438,13 +438,11 @@ static IotNetworkError_t _createNetworkConnection( const IotMqttNetworkInfo_t *
|
||||
IotLogError( "Network information cannot be NULL." );
|
||||
|
||||
status = IOT_NETWORK_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else if( pNetworkInfo->createNetworkConnection == true )
|
||||
{
|
||||
/* Create a new network connection if requested. Otherwise, copy the existing
|
||||
* network connection. */
|
||||
if( pNetworkInfo->createNetworkConnection == true )
|
||||
{
|
||||
status = pNetworkInfo->pNetworkInterface->create( pNetworkInfo->u.setup.pNetworkServerInfo,
|
||||
pNetworkInfo->u.setup.pNetworkCredentialInfo,
|
||||
pNetworkConnection );
|
||||
@ -458,8 +456,6 @@ static IotNetworkError_t _createNetworkConnection( const IotMqttNetworkInfo_t *
|
||||
else
|
||||
{
|
||||
IotLogError( "Failed to create network connection: %d", status );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -470,7 +466,6 @@ static IotNetworkError_t _createNetworkConnection( const IotMqttNetworkInfo_t *
|
||||
*pCreatedNewNetworkConnection = false;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -492,7 +487,6 @@ static _mqttConnection_t * _createMqttConnection( bool awsIotMqttMode,
|
||||
IotLogError( "Failed to allocate memory for new connection." );
|
||||
|
||||
status = false;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -505,7 +499,6 @@ static _mqttConnection_t * _createMqttConnection( bool awsIotMqttMode,
|
||||
|
||||
/* Start a new MQTT connection with a reference count of 1. */
|
||||
pMqttConnection->references = 1;
|
||||
}
|
||||
|
||||
/* Create the references mutex for a new connection. It is a recursive mutex. */
|
||||
referencesMutexCreated = IotMutex_Create( &( pMqttConnection->referencesMutex ), true );
|
||||
@ -515,9 +508,11 @@ static _mqttConnection_t * _createMqttConnection( bool awsIotMqttMode,
|
||||
IotLogError( "Failed to create references mutex for new connection." );
|
||||
|
||||
status = false;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == true )
|
||||
{
|
||||
/* Create the subscription mutex for a new connection. */
|
||||
subscriptionMutexCreated = IotMutex_Create( &( pMqttConnection->subscriptionMutex ), false );
|
||||
|
||||
@ -526,9 +521,9 @@ static _mqttConnection_t * _createMqttConnection( bool awsIotMqttMode,
|
||||
IotLogError( "Failed to create subscription mutex for new connection." );
|
||||
|
||||
status = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Create the new connection's subscription and operation lists. */
|
||||
IotListDouble_Create( &( pMqttConnection->subscriptionList ) );
|
||||
IotListDouble_Create( &( pMqttConnection->pendingProcessing ) );
|
||||
@ -537,18 +532,14 @@ static _mqttConnection_t * _createMqttConnection( bool awsIotMqttMode,
|
||||
/* Check if keep-alive is active for this connection. */
|
||||
if( keepAliveSeconds != 0 )
|
||||
{
|
||||
if( _createKeepAliveOperation( pNetworkInfo,
|
||||
status = _createKeepAliveOperation( pNetworkInfo,
|
||||
keepAliveSeconds,
|
||||
pMqttConnection ) == false )
|
||||
{
|
||||
status = false;
|
||||
goto cleanup;
|
||||
pMqttConnection );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up mutexes and connection if this function failed. */
|
||||
cleanup:
|
||||
|
||||
if( status == false )
|
||||
{
|
||||
if( subscriptionMutexCreated == true )
|
||||
@ -654,9 +645,9 @@ static IotMqttError_t _subscriptionCommonSetup( IotMqttOperationType_t operation
|
||||
if( _checkInit() == false )
|
||||
{
|
||||
status = IOT_MQTT_NOT_INITIALIZED;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Check that all elements in the subscription list are valid. */
|
||||
if( _IotMqtt_ValidateSubscriptionList( operation,
|
||||
mqttConnection->awsIotMqttMode,
|
||||
@ -664,9 +655,11 @@ static IotMqttError_t _subscriptionCommonSetup( IotMqttOperationType_t operation
|
||||
subscriptionCount ) == false )
|
||||
{
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check that a reference pointer is provided for a waitable operation. */
|
||||
if( ( flags & IOT_MQTT_FLAG_WAITABLE ) == IOT_MQTT_FLAG_WAITABLE )
|
||||
{
|
||||
@ -676,11 +669,10 @@ static IotMqttError_t _subscriptionCommonSetup( IotMqttOperationType_t operation
|
||||
IotMqtt_OperationType( operation ) );
|
||||
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -704,14 +696,10 @@ static IotMqttError_t _subscriptionCreateAndSerialize( IotMqttOperationType_t op
|
||||
pCallbackInfo,
|
||||
ppSubscriptionOperation );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
pSubscriptionOperation = ( *ppSubscriptionOperation );
|
||||
}
|
||||
|
||||
|
||||
/* Check the subscription operation data and set the operation type. */
|
||||
IotMqtt_Assert( pSubscriptionOperation->u.operation.status == IOT_MQTT_STATUS_PENDING );
|
||||
@ -724,17 +712,15 @@ static IotMqttError_t _subscriptionCreateAndSerialize( IotMqttOperationType_t op
|
||||
&( pSubscriptionOperation->u.operation.pMqttPacket ),
|
||||
&( pSubscriptionOperation->u.operation.packetSize ),
|
||||
&( pSubscriptionOperation->u.operation.packetIdentifier ) );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check the serialized MQTT packet. */
|
||||
IotMqtt_Assert( pSubscriptionOperation->u.operation.pMqttPacket != NULL );
|
||||
IotMqtt_Assert( pSubscriptionOperation->u.operation.packetSize > 0 );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -762,11 +748,8 @@ static IotMqttError_t _subscriptionCommon( IotMqttOperationType_t operation,
|
||||
pCallbackInfo,
|
||||
&pSubscriptionOperation );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Add the subscription list for a SUBSCRIBE. */
|
||||
if( operation == IOT_MQTT_SUBSCRIBE )
|
||||
{
|
||||
@ -774,13 +757,11 @@ static IotMqttError_t _subscriptionCommon( IotMqttOperationType_t operation,
|
||||
pSubscriptionOperation->u.operation.packetIdentifier,
|
||||
pSubscriptionList,
|
||||
subscriptionCount );
|
||||
}
|
||||
}
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the reference, if provided. */
|
||||
_setOperationReference( pOperationReference, pSubscriptionOperation );
|
||||
|
||||
@ -810,14 +791,11 @@ static IotMqttError_t _subscriptionCommon( IotMqttOperationType_t operation,
|
||||
|
||||
/* Clear the previously set (and now invalid) reference. */
|
||||
_setOperationReference( pOperationReference, IOT_MQTT_OPERATION_INITIALIZER );
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up if this function failed. */
|
||||
cleanup:
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
if( pSubscriptionOperation != NULL )
|
||||
@ -911,8 +889,8 @@ bool _IotMqtt_IncrementConnectionReferences( _mqttConnection_t * pMqttConnection
|
||||
{
|
||||
( pMqttConnection->references )++;
|
||||
|
||||
/* In some implementations IotLog() maps to C standard printing API
|
||||
* that need specific primitive types for format specifiers. Also,
|
||||
/* In some implementations IotLogDebug() maps to C standard printing API
|
||||
* that needs specific primitive types for format specifiers. Also,
|
||||
* inttypes.h may not be available on some C99 compilers, despite
|
||||
* stdint.h being available. */
|
||||
/* coverity[misra_c_2012_directive_4_6_violation] */
|
||||
@ -944,8 +922,8 @@ void _IotMqtt_DecrementConnectionReferences( _mqttConnection_t * pMqttConnection
|
||||
( pMqttConnection->references )--;
|
||||
IotMqtt_Assert( pMqttConnection->references >= 0 );
|
||||
|
||||
/* In some implementations IotLog() maps to C standard printing API
|
||||
* that need specific primitive types for format specifiers. Also,
|
||||
/* In some implementations IotLogDebug() maps to C standard printing API
|
||||
* that needs specific primitive types for format specifiers. Also,
|
||||
* inttypes.h may not be available on some C99 compilers, despite stdint.h
|
||||
* being available. */
|
||||
/* coverity[misra_c_2012_directive_4_6_violation] */
|
||||
@ -1054,16 +1032,14 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
if( _checkInit() == false )
|
||||
{
|
||||
status = IOT_MQTT_NOT_INITIALIZED;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Validate network interface and connect info. */
|
||||
if( _IotMqtt_ValidateConnect( pConnectInfo ) == false )
|
||||
else if( _IotMqtt_ValidateConnect( pConnectInfo ) == false )
|
||||
{
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
networkStatus = _createNetworkConnection( pNetworkInfo,
|
||||
&pNetworkConnection,
|
||||
&ownNetworkConnection );
|
||||
@ -1071,9 +1047,11 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
if( networkStatus != IOT_NETWORK_SUCCESS )
|
||||
{
|
||||
status = IOT_MQTT_NETWORK_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
IotLogInfo( "Establishing new MQTT connection." );
|
||||
|
||||
/* Initialize a new MQTT connection object. */
|
||||
@ -1084,9 +1062,11 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
if( pNewMqttConnection == NULL )
|
||||
{
|
||||
status = IOT_MQTT_NO_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
/* Set the MQTT receive callback. */
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Set the network connection associated with the MQTT connection. */
|
||||
pNewMqttConnection->pNetworkConnection = pNetworkConnection;
|
||||
@ -1098,9 +1078,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
#else
|
||||
pNewMqttConnection->pSerializer = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Set the MQTT receive callback. */
|
||||
networkStatus = pNewMqttConnection->pNetworkInterface->setReceiveCallback( pNetworkConnection,
|
||||
IotMqtt_ReceiveCallback,
|
||||
pNewMqttConnection );
|
||||
@ -1110,20 +1088,19 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
IotLogError( "Failed to set MQTT network receive callback." );
|
||||
|
||||
status = IOT_MQTT_NETWORK_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Create a CONNECT operation. */
|
||||
status = _IotMqtt_CreateOperation( pNewMqttConnection,
|
||||
IOT_MQTT_FLAG_WAITABLE,
|
||||
NULL,
|
||||
&pOperation );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Ensure the members set by operation creation and serialization
|
||||
* are appropriate for a blocking CONNECT. */
|
||||
IotMqtt_Assert( pOperation->u.operation.status == IOT_MQTT_STATUS_PENDING );
|
||||
@ -1144,23 +1121,19 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
2,
|
||||
pConnectInfo->pPreviousSubscriptions,
|
||||
pConnectInfo->previousSubscriptionCount );
|
||||
}
|
||||
}
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert the connect info and will info objects to an MQTT CONNECT packet. */
|
||||
status = _getMqttConnectSerializer( pNetworkInfo->pMqttSerializer )( pConnectInfo,
|
||||
&( pOperation->u.operation.pMqttPacket ),
|
||||
&( pOperation->u.operation.packetSize ) );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check the serialized MQTT packet. */
|
||||
IotMqtt_Assert( pOperation->u.operation.pMqttPacket != NULL );
|
||||
IotMqtt_Assert( pOperation->u.operation.packetSize > 0 );
|
||||
@ -1174,6 +1147,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
/* The call to wait cleans up the CONNECT operation, so set the pointer
|
||||
* to NULL. */
|
||||
pOperation = NULL;
|
||||
}
|
||||
|
||||
/* When a connection is successfully established, schedule keep-alive job. */
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
@ -1190,13 +1164,10 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
|
||||
if( taskPoolStatus != IOT_TASKPOOL_SUCCESS )
|
||||
{
|
||||
status = IOT_MQTT_SCHEDULING_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
IotLogError( "Failed to establish new MQTT connection, error %s.",
|
||||
@ -1259,7 +1230,7 @@ void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
|
||||
uint32_t flags )
|
||||
{
|
||||
bool disconnected = false, initCalled = false;
|
||||
IotMqttError_t status = IOT_MQTT_STATUS_PENDING;
|
||||
IotMqttError_t status = IOT_MQTT_SUCCESS;
|
||||
_mqttOperation_t * pOperation = NULL;
|
||||
|
||||
/* Check that IotMqtt_Init was called. */
|
||||
@ -1267,16 +1238,20 @@ void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
|
||||
|
||||
if( initCalled == false )
|
||||
{
|
||||
goto cleanup;
|
||||
status = IOT_MQTT_STATUS_PENDING;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Only send a DISCONNECT packet if the connection is active and the "cleanup only"
|
||||
* flag is not set. */
|
||||
if( ( flags & IOT_MQTT_FLAG_CLEANUP_ONLY ) == IOT_MQTT_FLAG_CLEANUP_ONLY )
|
||||
{
|
||||
goto cleanup;
|
||||
status = IOT_MQTT_STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Read the connection status. */
|
||||
IotMutex_Lock( &( mqttConnection->referencesMutex ) );
|
||||
disconnected = mqttConnection->disconnected;
|
||||
@ -1284,9 +1259,12 @@ void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
|
||||
|
||||
if( disconnected == true )
|
||||
{
|
||||
goto cleanup;
|
||||
status = IOT_MQTT_STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
IotLogInfo( "(MQTT connection %p) Disconnecting connection.", mqttConnection );
|
||||
|
||||
/* Create a DISCONNECT operation. This function blocks until the DISCONNECT
|
||||
@ -1312,6 +1290,7 @@ void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
|
||||
status = _getMqttDisconnectSerializer( mqttConnection->pSerializer )( &( pOperation->u.operation.pMqttPacket ),
|
||||
&( pOperation->u.operation.packetSize ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
@ -1343,10 +1322,6 @@ void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
|
||||
}
|
||||
}
|
||||
|
||||
/* This function has no return value and no cleanup, but uses the cleanup
|
||||
* label to exit on error. */
|
||||
cleanup:
|
||||
|
||||
if( initCalled == true )
|
||||
{
|
||||
/* Close the underlying network connection. This also cleans up keep-alive.
|
||||
@ -1541,30 +1516,26 @@ IotMqttError_t IotMqtt_PublishAsync( IotMqttConnection_t mqttConnection,
|
||||
if( _checkInit() == false )
|
||||
{
|
||||
status = IOT_MQTT_NOT_INITIALIZED;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( _IotMqtt_ValidatePublish( mqttConnection->awsIotMqttMode,
|
||||
else if( _IotMqtt_ValidatePublish( mqttConnection->awsIotMqttMode,
|
||||
pPublishInfo,
|
||||
flags,
|
||||
pCallbackInfo,
|
||||
pPublishOperation ) == false )
|
||||
{
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Create a PUBLISH operation. */
|
||||
status = _IotMqtt_CreateOperation( mqttConnection,
|
||||
flags,
|
||||
pCallbackInfo,
|
||||
&pOperation );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check the PUBLISH operation data and set the operation type. */
|
||||
IotMqtt_Assert( pOperation->u.operation.status == IOT_MQTT_STATUS_PENDING );
|
||||
pOperation->u.operation.type = IOT_MQTT_PUBLISH_TO_SERVER;
|
||||
@ -1581,12 +1552,10 @@ IotMqttError_t IotMqtt_PublishAsync( IotMqttConnection_t mqttConnection,
|
||||
&( pOperation->u.operation.packetSize ),
|
||||
&( pOperation->u.operation.packetIdentifier ),
|
||||
pPacketIdentifierHigh );
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check the serialized MQTT packet. */
|
||||
IotMqtt_Assert( pOperation->u.operation.pMqttPacket != NULL );
|
||||
IotMqtt_Assert( pOperation->u.operation.packetSize > 0 );
|
||||
@ -1629,14 +1598,12 @@ IotMqttError_t IotMqtt_PublishAsync( IotMqttConnection_t mqttConnection,
|
||||
{
|
||||
_setOperationReference( pPublishOperation, IOT_MQTT_OPERATION_INITIALIZER );
|
||||
}
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up the PUBLISH operation if this function fails. Otherwise, set the
|
||||
* appropriate return code based on QoS. */
|
||||
cleanup:
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
@ -1711,18 +1678,17 @@ IotMqttError_t IotMqtt_Wait( IotMqttOperation_t operation,
|
||||
if( _checkInit() == false )
|
||||
{
|
||||
status = IOT_MQTT_NOT_INITIALIZED;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Validate the given operation reference. */
|
||||
if( _IotMqtt_ValidateOperation( operation ) == false )
|
||||
else if( _IotMqtt_ValidateOperation( operation ) == false )
|
||||
{
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Check the MQTT connection status. */
|
||||
pMqttConnection = operation->pMqttConnection;
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
@ -1761,7 +1727,6 @@ IotMqttError_t IotMqtt_Wait( IotMqttOperation_t operation,
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -454,10 +454,11 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
IotLogError( "Callback should not be set for a waitable operation." );
|
||||
|
||||
status = IOT_MQTT_BAD_PARAMETER;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
IotLogDebug( "(MQTT connection %p) Creating new operation record.",
|
||||
pMqttConnection );
|
||||
|
||||
@ -470,14 +471,16 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
pMqttConnection );
|
||||
|
||||
status = IOT_MQTT_NETWORK_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reference count will need to be decremented on error. */
|
||||
decrementOnError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Allocate memory for a new operation. */
|
||||
pOperation = IotMqtt_MallocOperation( sizeof( _mqttOperation_t ) );
|
||||
|
||||
@ -488,7 +491,6 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
pMqttConnection );
|
||||
|
||||
status = IOT_MQTT_NO_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -501,7 +503,10 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
pOperation->u.operation.flags = flags;
|
||||
pOperation->u.operation.status = IOT_MQTT_STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Check if the waitable flag is set. If it is, create a semaphore to
|
||||
* wait on. */
|
||||
if( waitable == true )
|
||||
@ -514,7 +519,6 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
pMqttConnection );
|
||||
|
||||
status = IOT_MQTT_NO_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -533,6 +537,8 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
}
|
||||
}
|
||||
|
||||
if( status == IOT_MQTT_SUCCESS )
|
||||
{
|
||||
/* Add this operation to the MQTT connection's operation list. */
|
||||
IotMutex_Lock( &( pMqttConnection->referencesMutex ) );
|
||||
IotListDouble_InsertHead( &( pMqttConnection->pendingProcessing ),
|
||||
@ -541,9 +547,10 @@ IotMqttError_t _IotMqtt_CreateOperation( _mqttConnection_t * pMqttConnection,
|
||||
|
||||
/* Set the output parameter. */
|
||||
*pNewOperation = pOperation;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up operation and decrement reference count if this function failed. */
|
||||
cleanup:
|
||||
|
||||
if( status != IOT_MQTT_SUCCESS )
|
||||
{
|
||||
|
@ -162,13 +162,10 @@ static bool _matchEndWildcards( const char * pTopicFilter,
|
||||
{
|
||||
/* Determine if the topic filter ends with the '#' wildcard. */
|
||||
status = ( pTopicFilter[ filterIndex + 1 ] == '/' ) && ( pTopicFilter[ filterIndex + 2 ] == '#' );
|
||||
}
|
||||
|
||||
if( status == true )
|
||||
if( status == false )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if the last character is reached for both topic name and topic
|
||||
* filter for the '+' wildcard. */
|
||||
endChar = ( nameIndex == topicNameLength - 1 ) && ( filterIndex == topicFilterLength - 2 );
|
||||
@ -178,8 +175,8 @@ static bool _matchEndWildcards( const char * pTopicFilter,
|
||||
/* Filter "sport/+" also matches the "sport/" but not "sport". */
|
||||
status = ( pTopicFilter[ filterIndex + 1 ] == '+' );
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
*pMatch = status;
|
||||
|
||||
return status;
|
||||
@ -251,7 +248,7 @@ static bool _topicFilterMatch( const char * pTopicName,
|
||||
filterIndex,
|
||||
&status ) == true )
|
||||
{
|
||||
goto cleanup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -264,7 +261,7 @@ static bool _topicFilterMatch( const char * pTopicName,
|
||||
&nameIndex,
|
||||
&status ) == true )
|
||||
{
|
||||
goto cleanup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,14 +270,12 @@ static bool _topicFilterMatch( const char * pTopicName,
|
||||
filterIndex++;
|
||||
}
|
||||
|
||||
/* If the end of both strings has been reached, they match. */
|
||||
if( ( nameIndex == topicNameLength ) && ( filterIndex == topicFilterLength ) )
|
||||
if( status == false )
|
||||
{
|
||||
status = true;
|
||||
/* If the end of both strings has been reached, they match. */
|
||||
status = ( ( nameIndex == topicNameLength ) && ( filterIndex == topicFilterLength ) );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user