Skip to content

Commit 0f21ce2

Browse files
committed
Support tls:// prefix
Signed-off-by: Konstantin Tyurin <konstantin@pluraf.com>
1 parent bba7246 commit 0f21ce2

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/MQTTAsync.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
335335
&& strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0
336336
#if defined(OPENSSL)
337337
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
338+
&& strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0
338339
&& strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0
339340
&& strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0
340341
#endif
@@ -405,6 +406,11 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
405406
serverURI += strlen(URI_SSL);
406407
m->ssl = 1;
407408
}
409+
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
410+
{
411+
serverURI += strlen(URI_TLS);
412+
m->ssl = 1;
413+
}
408414
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
409415
{
410416
serverURI += strlen(URI_MQTTS);

src/MQTTAsyncUtils.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,11 @@ static int MQTTAsync_processCommand(void)
13481348
serverURI += strlen(URI_SSL);
13491349
command->client->ssl = 1;
13501350
}
1351+
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
1352+
{
1353+
serverURI += strlen(URI_TLS);
1354+
command->client->ssl = 1;
1355+
}
13511356
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
13521357
{
13531358
serverURI += strlen(URI_MQTTS);
@@ -2888,6 +2893,11 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
28882893
serverURI += strlen(URI_SSL);
28892894
default_port = SECURE_MQTT_DEFAULT_PORT;
28902895
}
2896+
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
2897+
{
2898+
serverURI += strlen(URI_TLS);
2899+
default_port = SECURE_MQTT_DEFAULT_PORT;
2900+
}
28912901
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
28922902
{
28932903
serverURI += strlen(URI_MQTTS);

src/MQTTClient.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <openssl/ssl.h>
7272
#else
7373
#define URI_SSL "ssl://"
74+
#define URI_TLS "tls://"
7475
#define URI_MQTTS "mqtts://"
7576
#endif
7677

@@ -403,6 +404,7 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons
403404
&& strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0
404405
#if defined(OPENSSL)
405406
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
407+
&& strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0
406408
&& strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0
407409
&& strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0
408410
#endif
@@ -465,6 +467,16 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons
465467
#else
466468
rc = MQTTCLIENT_SSL_NOT_SUPPORTED;
467469
goto exit;
470+
#endif
471+
}
472+
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
473+
{
474+
#if defined(OPENSSL)
475+
serverURI += strlen(URI_TLS);
476+
m->ssl = 1;
477+
#else
478+
rc = MQTTCLIENT_SSL_NOT_SUPPORTED;
479+
goto exit;
468480
#endif
469481
}
470482
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
@@ -1898,6 +1910,11 @@ MQTTResponse MQTTClient_connectAll(MQTTClient handle, MQTTClient_connectOptions*
18981910
serverURI += strlen(URI_SSL);
18991911
m->ssl = 1;
19001912
}
1913+
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
1914+
{
1915+
serverURI += strlen(URI_TLS);
1916+
m->ssl = 1;
1917+
}
19011918
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
19021919
{
19031920
serverURI += strlen(URI_MQTTS);

src/SSLSocket.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
6-
* and Eclipse Distribution License v1.0 which accompany this distribution.
6+
* and Eclipse Distribution License v1.0 which accompany this distribution.
77
*
8-
* The Eclipse Public License is available at
8+
* The Eclipse Public License is available at
99
* https://www.eclipse.org/legal/epl-2.0/
10-
* and the Eclipse Distribution License is available at
10+
* and the Eclipse Distribution License is available at
1111
* http://www.eclipse.org/org/documents/edl-v10.php.
1212
*
1313
* Contributors:
14-
* Ian Craggs, Allan Stockdill-Mander - initial implementation
14+
* Ian Craggs, Allan Stockdill-Mander - initial implementation
1515
* Ian Craggs - SNI support
1616
* Ian Craggs - post connect checks and CApath
1717
*******************************************************************************/
@@ -31,6 +31,7 @@
3131
#include "Clients.h"
3232

3333
#define URI_SSL "ssl://"
34+
#define URI_TLS "tls://"
3435
#define URI_MQTTS "mqtts://"
3536

3637
/** if we should handle openssl initialization (bool_value == 1) or depend on it to be initalized externally (bool_value == 0) */

0 commit comments

Comments
 (0)