Skip to content

Commit

Permalink
Set default port for WSS to 443 #1048
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed Jan 28, 2022
1 parent 40f7862 commit 5e6e389
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/MQTTAsyncUtils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -2719,7 +2719,7 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
else if (strncmp(URI_WSS, serverURI, strlen(URI_WSS)) == 0)
{
serverURI += strlen(URI_WSS);
default_port = WS_DEFAULT_PORT;
default_port = WSS_DEFAULT_PORT;
}
#endif
}
Expand Down Expand Up @@ -2779,7 +2779,7 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
if ( m->websocket )
{
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
if ((rc = WebSocket_connect(&m->c->net, serverURI)) == SOCKET_ERROR )
if ((rc = WebSocket_connect(&m->c->net, m->ssl, serverURI)) == SOCKET_ERROR )
goto exit;
}
else
Expand Down Expand Up @@ -2815,7 +2815,7 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
if ( m->websocket )
{
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
if ((rc = WebSocket_connect(&m->c->net, serverURI)) == SOCKET_ERROR )
if ((rc = WebSocket_connect(&m->c->net, 0, serverURI)) == SOCKET_ERROR )
goto exit;
}
else
Expand Down Expand Up @@ -2846,7 +2846,7 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
if ( m->websocket )
{
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
if ((rc = WebSocket_connect(&m->c->net, serverURI)) == SOCKET_ERROR )
if ((rc = WebSocket_connect(&m->c->net, 1, serverURI)) == SOCKET_ERROR )
goto exit;
}
else
Expand Down
8 changes: 4 additions & 4 deletions src/MQTTClient.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -1267,7 +1267,7 @@ static MQTTResponse MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_c
if (m->websocket)
{
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
rc = WebSocket_connect(&m->c->net, serverURI);
rc = WebSocket_connect(&m->c->net, 1, serverURI);
if ( rc == SOCKET_ERROR )
goto exit;
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ static MQTTResponse MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_c
if (m->websocket)
{
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
if ( WebSocket_connect(&m->c->net, serverURI) == SOCKET_ERROR )
if ( WebSocket_connect(&m->c->net, 0, serverURI) == SOCKET_ERROR )
{
rc = SOCKET_ERROR;
goto exit;
Expand Down Expand Up @@ -1339,7 +1339,7 @@ static MQTTResponse MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_c
{
/* wait for websocket connect */
m->c->connect_state = WEBSOCKET_IN_PROGRESS;
rc = WebSocket_connect( &m->c->net, serverURI );
rc = WebSocket_connect( &m->c->net, 1, serverURI);
if ( rc != 1 )
{
rc = SOCKET_ERROR;
Expand Down
8 changes: 5 additions & 3 deletions src/MQTTProtocolOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int websocket
#endif
else {
#if defined(OPENSSL)
addr_len = MQTTProtocol_addressPort(ip_address, &port, NULL, ssl ? SECURE_MQTT_DEFAULT_PORT : MQTT_DEFAULT_PORT);
addr_len = MQTTProtocol_addressPort(ip_address, &port, NULL, ssl ?
(websocket ? WSS_DEFAULT_PORT : SECURE_MQTT_DEFAULT_PORT) :
(websocket ? WS_DEFAULT_PORT : MQTT_DEFAULT_PORT) );
#else
addr_len = MQTTProtocol_addressPort(ip_address, &port, NULL, MQTT_DEFAULT_PORT);
addr_len = MQTTProtocol_addressPort(ip_address, &port, NULL, websocket ? WS_DEFAULT_PORT : MQTT_DEFAULT_PORT);
#endif
#if defined(__GNUC__) && defined(__linux__)
if (timeout < 0)
Expand Down Expand Up @@ -331,7 +333,7 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int websocket
}
if ( websocket )
{
rc = WebSocket_connect( &aClient->net, ip_address );
rc = WebSocket_connect( &aClient->net, 0, ip_address );
if ( rc == TCPSOCKET_INTERRUPTED )
aClient->connect_state = WEBSOCKET_IN_PROGRESS; /* Websocket connect called - wait for completion */
}
Expand Down
3 changes: 2 additions & 1 deletion src/MQTTProtocolOut.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -33,6 +33,7 @@
#define MQTT_DEFAULT_PORT 1883
#define SECURE_MQTT_DEFAULT_PORT 8883
#define WS_DEFAULT_PORT 80
#define WSS_DEFAULT_PORT 443
#define PROXY_DEFAULT_PORT 8080

size_t MQTTProtocol_addressPort(const char* uri, int* port, const char **topic, int default_port);
Expand Down
5 changes: 3 additions & 2 deletions src/WebSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,15 @@ static void WebSocket_unmaskData(size_t idx, PacketBuffers* bufs)
* sends out a websocket request on the given uri
*
* @param[in] net network connection
* @param[in] ssl ssl flag
* @param[in] uri uri to connect to
*
* @retval SOCKET_ERROR on failure
* @retval 1 on success
*
* @see WebSocket_upgrade
*/
int WebSocket_connect( networkHandles *net, const char *uri)
int WebSocket_connect( networkHandles *net, int ssl, const char *uri)
{
int rc;
char *buf = NULL;
Expand Down Expand Up @@ -413,7 +414,7 @@ int WebSocket_connect( networkHandles *net, const char *uri)
Base64_encode( net->websocket_key, 25u, uuid, sizeof(uuid_t) );
#endif /* else if defined(_WIN32) || defined(_WIN64) */

hostname_len = MQTTProtocol_addressPort(uri, &port, &topic, WS_DEFAULT_PORT);
hostname_len = MQTTProtocol_addressPort(uri, &port, &topic, ssl ? WSS_DEFAULT_PORT : WS_DEFAULT_PORT);

/* if no topic, use default */
if ( !topic )
Expand Down
4 changes: 2 additions & 2 deletions src/WebSocket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 Wind River Systems, Inc. and others. All Rights Reserved.
* Copyright (c) 2018, 2022 Wind River Systems, Inc. and others. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -55,7 +55,7 @@
void WebSocket_close(networkHandles *net, int status_code, const char *reason);

/* sends upgrade request */
int WebSocket_connect(networkHandles *net, const char *uri);
int WebSocket_connect(networkHandles *net, int ssl, const char *uri);

/* obtain data from network socket */
int WebSocket_getch(networkHandles *net, char* c);
Expand Down

0 comments on commit 5e6e389

Please sign in to comment.