eclipse / mita

mita
Eclipse Public License 2.0
56 stars 20 forks source link

MQTT with authentification generates bad source code #271

Closed XDK-Support closed 5 years ago

XDK-Support commented 5 years ago

MQTT with authentification generates bad C code

When using MQTT with an authentification like this setup

// Create a MQTT instance
setup messaging : MQTT {
   authentication = Login(username = "myID", password = "12312" );
   clientId = "1234";
   cleanSession = true;
   transport = wireless;
   url = "mqtt://demo.thingsboard.io:1883";
   var Test = topic("xdktest123123123",0);
}

It will generate C code inside src-gen/base/ConnectivityMQTTMessaging.c as follows:

/**< Handle for MQTT subscribe operation  */
static SemaphoreHandle_t mqttSubscribeHandle;
/**< Handle for MQTT publish operation  */
static SemaphoreHandle_t mqttPublishHandle;
/**< Handle for MQTT send operation  */
static SemaphoreHandle_t mqttSendHandle;
/**< Handle for MQTT send operation  */
static SemaphoreHandle_t mqttConnectHandle;
/**< MQTT session instance */
static MqttSession_T mqttSession;
/**< MQTT connection status */
static bool mqttIsConnected = false;
/**< MQTT subscription status */
static bool mqttIsSubscribed = false;
/**< MQTT publish status */
static bool mqttWasPublished = false;
#define TASK_PRIORITY_SERVALPAL_CMD_PROC            UINT32_C(3)
#define TASK_STACK_SIZE_SERVALPAL_CMD_PROC          UINT32_C(600)
#define TASK_QUEUE_LEN_SERVALPAL_CMD_PROC           UINT32_C(10)

StringDescr_T username;
const char* usernameBuf = "myID";
StringDescr_wrap(&username, usernameBuf);  // -- syntax error here

StringDescr_T password;
const char* passwordBuf = "12312";
StringDescr_wrap(&password, passwordBuf);  // -- syntax error here
static retcode_t MqttEventHandler(MqttSession_T* session, MqttEvent_t event, const MqttEventData_t* eventData);
static Retcode_T connectToBackend(void);

Furthermore, the function calls of StringDescr_wrap() will cause syntax error, because these are called outside of a function context.

To fix this, this functions should be moved inside the body of the function ConnectivityMQTTMessaging_Enable() and should process username and password in the same manner as with the clientID to make the generated C code working properly.

Kind Regards