parent
9b89eba536
commit
254194dfc6
2 changed files with 16 additions and 2 deletions
|
@ -183,6 +183,12 @@ static void _mqtt_connect(MQTTHandle *handle, MQTTEventHandler callback, void *c
|
|||
}
|
||||
|
||||
MQTTHandle *mqtt_connect(MQTTConfig *config, MQTTEventHandler callback, void *context, MQTTErrorHandler error_callback) {
|
||||
// sanity check
|
||||
if ((config->client_id != NULL) && (strlen(config->client_id) > 23)) {
|
||||
DEBUG_LOG("Client ID has to be shorter than 24 characters");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MQTTHandle *handle = calloc(sizeof(struct _MQTTHandle), 1);
|
||||
initialize_platform(handle);
|
||||
|
||||
|
|
|
@ -40,14 +40,22 @@ void mqtt_connected(MQTTHandle *handle, void *context) {
|
|||
int main(int argc, char **argv) {
|
||||
MQTTConfig config = { 0 };
|
||||
|
||||
config.client_id = "libmqtt_testsuite";
|
||||
config.client_id = "libmqtt_testsuite_this_is_too_long";
|
||||
config.hostname = "localhost";
|
||||
|
||||
config.last_will_topic = "testsuite/last_will";
|
||||
config.last_will_message = "RIP";
|
||||
|
||||
LOG("Trying to connect to %s", config.hostname);
|
||||
LOG("Testing too long client id...");
|
||||
MQTTHandle *mqtt = mqtt_connect(&config, mqtt_connected, NULL, err_handler);
|
||||
if (mqtt != NULL) {
|
||||
LOG("Handle should be NULL, but it wasn't");
|
||||
return 1;
|
||||
}
|
||||
|
||||
config.client_id = "libmqtt_testsuite";
|
||||
LOG("Trying to connect to %s", config.hostname);
|
||||
mqtt = mqtt_connect(&config, mqtt_connected, NULL, err_handler);
|
||||
|
||||
if (mqtt == NULL) {
|
||||
LOG("Connection failed!");
|
||||
|
|
Loading…
Reference in a new issue