mirror of https://github.com/eclipse/paho.mqtt.c
Merge branch 'develop' into develop
This commit is contained in:
commit
73031beafa
|
|
@ -26,5 +26,5 @@ jobs:
|
|||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Eclipse-Paho-MQTT-C-1.3.14-Linux.tar.gz
|
||||
path: /home/runner/work/paho.mqtt.c/paho.mqtt.c/build.paho/Eclipse-Paho-MQTT-C-1.3.14-Linux.tar.gz
|
||||
name: Eclipse-Paho-MQTT-C-1.3.15-Linux.tar.gz
|
||||
path: /home/runner/work/paho.mqtt.c/paho.mqtt.c/build.paho/Eclipse-Paho-MQTT-C-1.3.15-Linux.tar.gz
|
||||
|
|
|
|||
|
|
@ -26,5 +26,5 @@ jobs:
|
|||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Eclipse-Paho-MQTT-C-1.3.14-Darwin.tar.gz
|
||||
path: /Users/runner/work/paho.mqtt.c/paho.mqtt.c/build.paho/Eclipse-Paho-MQTT-C-1.3.14-Darwin.tar.gz
|
||||
name: Eclipse-Paho-MQTT-C-1.3.15-Darwin.tar.gz
|
||||
path: /Users/runner/work/paho.mqtt.c/paho.mqtt.c/build.paho/Eclipse-Paho-MQTT-C-1.3.15-Darwin.tar.gz
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project("Eclipse Paho C"
|
||||
VERSION 1.3.14
|
||||
VERSION 1.3.15
|
||||
LANGUAGES C
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "Base64.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#pragma comment(lib, "crypt32.lib")
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
|
@ -37,7 +37,7 @@ b64_size_t Base64_encode( char *out, b64_size_t out_len, const b64_data_t *in, b
|
|||
ret = (b64_size_t)dw_out_len;
|
||||
return ret;
|
||||
}
|
||||
#else /* if defined(_WIN32) || defined(_WIN64) */
|
||||
#else /* if defined(_WIN32) */
|
||||
|
||||
#if defined(OPENSSL)
|
||||
#include <openssl/bio.h>
|
||||
|
|
@ -234,7 +234,7 @@ b64_size_t Base64_encode( char *out, b64_size_t out_len, const b64_data_t *in, b
|
|||
return ret;
|
||||
}
|
||||
#endif /* else if defined(OPENSSL) */
|
||||
#endif /* if else defined(_WIN32) || defined(_WIN64) */
|
||||
#endif /* if else defined(_WIN32) */
|
||||
|
||||
b64_size_t Base64_decodeLength( const char *in, b64_size_t in_len )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include "MQTTTime.h"
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#if defined(OPENSSL)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ char* Broker_recordFFDC(char* symptoms);
|
|||
#undef realloc
|
||||
#undef free
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex_type heap_mutex;
|
||||
#else
|
||||
static pthread_mutex_t heap_mutex_store = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
|
|||
10
src/Log.c
10
src/Log.c
|
|
@ -38,7 +38,7 @@
|
|||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#include <syslog.h>
|
||||
#include <sys/stat.h>
|
||||
#define GETTIMEOFDAY 1
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
/**
|
||||
* _unlink mapping for linux
|
||||
*/
|
||||
|
|
@ -123,7 +123,7 @@ struct timeb now_ts;
|
|||
#endif
|
||||
static char msg_buf[512];
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex_type log_mutex;
|
||||
#else
|
||||
static pthread_mutex_t log_mutex_store = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
@ -135,7 +135,7 @@ int Log_initialize(Log_nameValue* info)
|
|||
{
|
||||
int rc = SOCKET_ERROR;
|
||||
char* envval = NULL;
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
struct stat buf;
|
||||
#endif
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ int Log_initialize(Log_nameValue* info)
|
|||
info++;
|
||||
}
|
||||
}
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
if (stat("/proc/version", &buf) != -1)
|
||||
{
|
||||
FILE* vfile;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#if !defined(LOG_H)
|
||||
#define LOG_H
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#define thread_id_type DWORD
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2024 IBM Corp., Ian Craggs and others
|
||||
* Copyright (c) 2009, 2025 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
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
|
|
@ -105,7 +105,7 @@ void MQTTAsync_global_init(MQTTAsync_init_options* inits)
|
|||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#if defined(_WIN32)
|
||||
void MQTTAsync_init_rand(void)
|
||||
{
|
||||
START_TIME_TYPE now = MQTTTime_start_clock();
|
||||
|
|
@ -125,7 +125,7 @@ void MQTTAsync_init_rand(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex_type mqttasync_mutex = NULL;
|
||||
mutex_type socket_mutex = NULL;
|
||||
mutex_type mqttcommand_mutex = NULL;
|
||||
|
|
@ -300,7 +300,7 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
|
|||
int rc = 0;
|
||||
MQTTAsyncs *m = NULL;
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && defined(PAHO_MQTT_STATIC)
|
||||
#if (defined(_WIN32)) && defined(PAHO_MQTT_STATIC)
|
||||
/* intializes mutexes once. Must come before FUNC_ENTRY */
|
||||
BOOL bStatus = InitOnceExecuteOnce(&g_InitOnce, InitMutexesOnce, NULL, NULL);
|
||||
#endif
|
||||
|
|
@ -335,6 +335,7 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
|
|||
&& strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0
|
||||
#if defined(OPENSSL)
|
||||
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
|
||||
&& strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0
|
||||
&& strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0
|
||||
&& strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0
|
||||
#endif
|
||||
|
|
@ -405,6 +406,11 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
|
|||
serverURI += strlen(URI_SSL);
|
||||
m->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_TLS);
|
||||
m->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_MQTTS);
|
||||
|
|
@ -583,6 +589,23 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
|
|||
rc = MQTTASYNC_NULL_PARAMETER;
|
||||
goto exit;
|
||||
}
|
||||
if (options->ssl == NULL && options->serverURIcount > 0)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < options->serverURIcount; i++)
|
||||
{
|
||||
char* serverURI = options->serverURIs[i];
|
||||
printf("checking %s\n", serverURI);
|
||||
if (strncmp(URI_SSL, serverURI, strlen(URI_SSL)) == 0 ||
|
||||
strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0 ||
|
||||
strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0 ||
|
||||
strncmp(URI_WSS, serverURI, strlen(URI_WSS)) == 0)
|
||||
{
|
||||
rc = MQTTASYNC_NULL_PARAMETER;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (options->will) /* check validity of will options structure */
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* @brief An Asynchronous MQTT client library for C.
|
||||
*
|
||||
* Version 1.3.14
|
||||
* Version 1.3.15
|
||||
*
|
||||
* An MQTT client application connects to MQTT-capable servers.
|
||||
* A typical client is responsible for collecting information from a telemetry
|
||||
|
|
@ -177,11 +177,11 @@
|
|||
/**
|
||||
* Return code: protocol prefix in serverURI should be:
|
||||
* @li @em tcp:// or @em mqtt:// - Insecure TCP
|
||||
* @li @em ssl:// or @em mqtts:// - Encrypted SSL/TLS
|
||||
* @li @em ssl:// or @em tls:// or @em mqtts:// - Encrypted SSL/TLS
|
||||
* @li @em ws:// - Insecure websockets
|
||||
* @li @em wss:// - Secure web sockets
|
||||
*
|
||||
* The TLS enabled prefixes (ssl, mqtts, wss) are only valid if the TLS
|
||||
* The TLS enabled prefixes (ssl, tls, mqtts, wss) are only valid if the TLS
|
||||
* version of the library is linked with.
|
||||
*/
|
||||
#define MQTTASYNC_BAD_PROTOCOL -14
|
||||
|
|
@ -1928,7 +1928,7 @@ LIBMQTT_API const char* MQTTAsync_strerror(int code);
|
|||
#include <OsWrapper.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
@ -2099,7 +2099,7 @@ int main(int argc, char* argv[])
|
|||
#include <OsWrapper.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientSub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ extern List* MQTTAsync_handles;
|
|||
extern List* MQTTAsync_commands;
|
||||
extern int MQTTAsync_tostop;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
|
@ -108,7 +108,7 @@ extern cond_type send_cond;
|
|||
void MQTTAsync_sleep(long milliseconds)
|
||||
{
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
@ -936,7 +936,7 @@ int MQTTAsync_addCommand(MQTTAsync_queuedCommand* command, int command_size)
|
|||
}
|
||||
exit:
|
||||
MQTTAsync_unlock_mutex(mqttcommand_mutex);
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
if ((rc1 = Thread_signal_cond(send_cond)) != 0)
|
||||
Log(LOG_ERROR, 0, "Error %d from signal cond", rc1);
|
||||
#else
|
||||
|
|
@ -1348,6 +1348,11 @@ static int MQTTAsync_processCommand(void)
|
|||
serverURI += strlen(URI_SSL);
|
||||
command->client->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_TLS);
|
||||
command->client->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_MQTTS);
|
||||
|
|
@ -1855,7 +1860,7 @@ thread_return_type WINAPI MQTTAsync_sendThread(void* n)
|
|||
command_count = MQTTAsync_commands->count;
|
||||
MQTTAsync_unlock_mutex(mqttcommand_mutex);
|
||||
}
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
if ((rc = Thread_wait_cond(send_cond, timeout)) != 0 && rc != ETIMEDOUT)
|
||||
Log(LOG_ERROR, -1, "Error %d waiting for condition variable", rc);
|
||||
#else
|
||||
|
|
@ -1880,7 +1885,7 @@ thread_return_type WINAPI MQTTAsync_sendThread(void* n)
|
|||
#endif
|
||||
|
||||
FUNC_EXIT;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
ExitThread(0);
|
||||
#endif
|
||||
return 0;
|
||||
|
|
@ -2066,7 +2071,7 @@ static int MQTTAsync_completeConnection(MQTTAsyncs* m, Connack* connack)
|
|||
}
|
||||
}
|
||||
m->pack = NULL;
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
Thread_signal_cond(send_cond);
|
||||
#else
|
||||
Thread_post_sem(send_sem);
|
||||
|
|
@ -2396,7 +2401,7 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
|
|||
receiveThread_state = STOPPED;
|
||||
receiveThread_id = 0;
|
||||
MQTTAsync_unlock_mutex(mqttasync_mutex);
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
if (sendThread_state != STOPPED)
|
||||
Thread_signal_cond(send_cond);
|
||||
#else
|
||||
|
|
@ -2413,7 +2418,7 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
|
|||
#endif
|
||||
|
||||
FUNC_EXIT;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
ExitThread(0);
|
||||
#endif
|
||||
return 0;
|
||||
|
|
@ -2896,6 +2901,11 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
|
|||
serverURI += strlen(URI_SSL);
|
||||
default_port = SECURE_MQTT_DEFAULT_PORT;
|
||||
}
|
||||
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_TLS);
|
||||
default_port = SECURE_MQTT_DEFAULT_PORT;
|
||||
}
|
||||
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_MQTTS);
|
||||
|
|
@ -3142,7 +3152,7 @@ static MQTTPacket* MQTTAsync_cycle(SOCKET* sock, unsigned long timeout, int* rc)
|
|||
{
|
||||
*rc = MQTTProtocol_handlePubcomps(pack, *sock, &pubToRemove);
|
||||
if (sendThread_state != STOPPED)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
Thread_signal_cond(send_cond);
|
||||
#else
|
||||
Thread_post_sem(send_sem);
|
||||
|
|
@ -3154,7 +3164,7 @@ static MQTTPacket* MQTTAsync_cycle(SOCKET* sock, unsigned long timeout, int* rc)
|
|||
{
|
||||
*rc = MQTTProtocol_handlePubacks(pack, *sock, &pubToRemove);
|
||||
if (sendThread_state != STOPPED)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
Thread_signal_cond(send_cond);
|
||||
#else
|
||||
Thread_post_sem(send_sem);
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ void MQTTAsync_writeComplete(SOCKET socket, int rc);
|
|||
void setRetryLoopInterval(int keepalive);
|
||||
void MQTTAsync_NULLPublishResponses(MQTTAsyncs* m);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#else
|
||||
#define WINAPI
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
|
|
@ -71,6 +71,7 @@
|
|||
#include <openssl/ssl.h>
|
||||
#else
|
||||
#define URI_SSL "ssl://"
|
||||
#define URI_TLS "tls://"
|
||||
#define URI_MQTTS "mqtts://"
|
||||
#endif
|
||||
|
||||
|
|
@ -114,7 +115,7 @@ ClientStates* bstate = &ClientState;
|
|||
|
||||
MQTTProtocol state;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
static mutex_type mqttclient_mutex = NULL;
|
||||
mutex_type socket_mutex = NULL;
|
||||
static mutex_type subscribe_mutex = NULL;
|
||||
|
|
@ -370,7 +371,7 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons
|
|||
int rc = 0;
|
||||
MQTTClients *m = NULL;
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && defined(PAHO_MQTT_STATIC)
|
||||
#if (defined(_WIN32)) && defined(PAHO_MQTT_STATIC)
|
||||
/* intializes mutexes once. Must come before FUNC_ENTRY */
|
||||
BOOL bStatus = InitOnceExecuteOnce(&g_InitOnce, InitOnceFunction, NULL, NULL);
|
||||
#endif
|
||||
|
|
@ -403,6 +404,7 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons
|
|||
&& strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0
|
||||
#if defined(OPENSSL)
|
||||
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
|
||||
&& strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0
|
||||
&& strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0
|
||||
&& strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0
|
||||
#endif
|
||||
|
|
@ -465,6 +467,16 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons
|
|||
#else
|
||||
rc = MQTTCLIENT_SSL_NOT_SUPPORTED;
|
||||
goto exit;
|
||||
#endif
|
||||
}
|
||||
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
|
||||
{
|
||||
#if defined(OPENSSL)
|
||||
serverURI += strlen(URI_TLS);
|
||||
m->ssl = 1;
|
||||
#else
|
||||
rc = MQTTCLIENT_SSL_NOT_SUPPORTED;
|
||||
goto exit;
|
||||
#endif
|
||||
}
|
||||
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
|
||||
|
|
@ -1026,7 +1038,7 @@ static thread_return_type WINAPI MQTTClient_run(void* n)
|
|||
running = tostop = 0;
|
||||
Paho_thread_unlock_mutex(mqttclient_mutex);
|
||||
FUNC_EXIT;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
ExitThread(0);
|
||||
#endif
|
||||
return 0;
|
||||
|
|
@ -1898,6 +1910,11 @@ MQTTResponse MQTTClient_connectAll(MQTTClient handle, MQTTClient_connectOptions*
|
|||
serverURI += strlen(URI_SSL);
|
||||
m->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_TLS);
|
||||
m->ssl = 1;
|
||||
}
|
||||
else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0)
|
||||
{
|
||||
serverURI += strlen(URI_MQTTS);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
*
|
||||
* @brief An MQTT client library in C.
|
||||
*
|
||||
* Version 1.3.14
|
||||
* Version 1.3.15
|
||||
*
|
||||
* These pages describe the original more synchronous API which might be
|
||||
* considered easier to use. Some of the calls will block. For the new
|
||||
|
|
@ -186,10 +186,10 @@
|
|||
/**
|
||||
* Return code: protocol prefix in serverURI should be:
|
||||
* @li @em tcp:// or @em mqtt:// - Insecure TCP
|
||||
* @li @em ssl:// or @em mqtts:// - Encrypted SSL/TLS
|
||||
* @li @em ssl:// or @em tls:// or @em mqtts:// - Encrypted SSL/TLS
|
||||
* @li @em ws:// - Insecure websockets
|
||||
* @li @em wss:// - Secure web sockets
|
||||
* The TLS enabled prefixes (ssl, mqtts, wss) are only valid if a TLS
|
||||
* The TLS enabled prefixes (ssl, tls, mqtts, wss) are only valid if a TLS
|
||||
* version of the library is linked with.
|
||||
*/
|
||||
#define MQTTCLIENT_BAD_PROTOCOL -14
|
||||
|
|
@ -1528,7 +1528,7 @@ LIBMQTT_API const char* MQTTClient_strerror(int code);
|
|||
* This server behaviour is allowed in MQTT 5.0, but not in MQTT 3.1.1, so the
|
||||
* disconnected callback will never be invoked if you use MQTT 3.1.1.
|
||||
*
|
||||
* In particular, you must make a publish call within the message arrived callback.
|
||||
* In particular, you must not make a publish call within the message arrived callback.
|
||||
* These restrictions are all lifted in the
|
||||
* <a href="../../MQTTAsync/html/index.html">MQTTAsync API</a>.
|
||||
*
|
||||
|
|
@ -1624,7 +1624,7 @@ LIBMQTT_API const char* MQTTClient_strerror(int code);
|
|||
#include <string.h>
|
||||
#include "MQTTClient.h"
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
@ -1691,7 +1691,7 @@ int main(int argc, char* argv[])
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
@ -1800,7 +1800,7 @@ exit:
|
|||
#include <string.h>
|
||||
#include "MQTTClient.h"
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientSub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#if !defined(EXPORTDECLARATIONS_H)
|
||||
#define EXPORTDECLARATIONS_H
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
# if defined(PAHO_MQTT_EXPORTS)
|
||||
# define LIBMQTT_API __declspec(dllexport)
|
||||
# elif defined(PAHO_MQTT_IMPORTS)
|
||||
|
|
|
|||
|
|
@ -945,7 +945,7 @@ int MQTTPacket_send_publish(Publish* pack, int dup, int qos, int retained, netwo
|
|||
memcpy(pack->mask, packetbufs.mask, sizeof(pack->mask));
|
||||
}
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define buflen 30
|
||||
#else
|
||||
const int buflen = 30;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "LinkedList.h"
|
||||
#include "Clients.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
|
|
@ -37,6 +38,9 @@
|
|||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef unsigned int bit;
|
||||
|
||||
typedef void* (*pf)(int, unsigned char, char*, size_t);
|
||||
|
||||
#include "MQTTProperties.h"
|
||||
|
|
@ -66,7 +70,13 @@ enum msgTypes
|
|||
#endif
|
||||
|
||||
/**
|
||||
* Bitfields for the MQTT header byte.
|
||||
*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fields for the MQTT header byte.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
|
|
@ -75,16 +85,16 @@ typedef union
|
|||
struct
|
||||
{
|
||||
unsigned int type : 4; /**< message type nibble */
|
||||
bool dup : 1; /**< DUP flag bit */
|
||||
bit dup : 1; /**< DUP flag bit */
|
||||
unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
|
||||
bool retain : 1; /**< retained flag bit */
|
||||
bit retain : 1; /**< retained flag bit */
|
||||
} bits;
|
||||
#else
|
||||
struct
|
||||
{
|
||||
bool retain : 1; /**< retained flag bit */
|
||||
bit retain : 1; /**< retained flag bit */
|
||||
unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
|
||||
bool dup : 1; /**< DUP flag bit */
|
||||
bit dup : 1; /**< DUP flag bit */
|
||||
unsigned int type : 4; /**< message type nibble */
|
||||
} bits;
|
||||
#endif
|
||||
|
|
@ -103,24 +113,24 @@ typedef struct
|
|||
#if defined(REVERSED)
|
||||
struct
|
||||
{
|
||||
bool username : 1; /**< 3.1 user name */
|
||||
bool password : 1; /**< 3.1 password */
|
||||
bool willRetain : 1; /**< will retain setting */
|
||||
bit username : 1; /**< 3.1 user name */
|
||||
bit password : 1; /**< 3.1 password */
|
||||
bit willRetain : 1; /**< will retain setting */
|
||||
unsigned int willQoS : 2; /**< will QoS value */
|
||||
bool will : 1; /**< will flag */
|
||||
bool cleanstart : 1; /**< cleansession flag */
|
||||
bit will : 1; /**< will flag */
|
||||
bit cleanstart : 1; /**< cleansession flag */
|
||||
int : 1; /**< unused */
|
||||
} bits;
|
||||
#else
|
||||
struct
|
||||
{
|
||||
int : 1; /**< unused */
|
||||
bool cleanstart : 1; /**< cleansession flag */
|
||||
bool will : 1; /**< will flag */
|
||||
bit cleanstart : 1; /**< cleansession flag */
|
||||
bit will : 1; /**< will flag */
|
||||
unsigned int willQoS : 2; /**< will QoS value */
|
||||
bool willRetain : 1; /**< will retain setting */
|
||||
bool password : 1; /**< 3.1 password */
|
||||
bool username : 1; /**< 3.1 user name */
|
||||
bit willRetain : 1; /**< will retain setting */
|
||||
bit password : 1; /**< 3.1 password */
|
||||
bit username : 1; /**< 3.1 user name */
|
||||
} bits;
|
||||
#endif
|
||||
} flags; /**< connect flags byte */
|
||||
|
|
@ -148,12 +158,12 @@ typedef struct
|
|||
struct
|
||||
{
|
||||
unsigned int reserved : 7; /**< message type nibble */
|
||||
bool sessionPresent : 1; /**< was a session found on the server? */
|
||||
bit sessionPresent : 1; /**< was a session found on the server? */
|
||||
} bits;
|
||||
#else
|
||||
struct
|
||||
{
|
||||
bool sessionPresent : 1; /**< was a session found on the server? */
|
||||
bit sessionPresent : 1; /**< was a session found on the server? */
|
||||
unsigned int reserved : 7; /**< message type nibble */
|
||||
} bits;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include "MQTTProtocolClient.h"
|
||||
#include "Heap.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
|
@ -658,7 +658,7 @@ void MQTTPersistence_wrapMsgID(Clients *client)
|
|||
int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe)
|
||||
{
|
||||
int rc = 0;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define KEYSIZE PERSISTENCE_MAX_KEY_LENGTH + 1
|
||||
#else
|
||||
const size_t KEYSIZE = PERSISTENCE_MAX_KEY_LENGTH + 1;
|
||||
|
|
@ -688,7 +688,7 @@ int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry*
|
|||
{
|
||||
int rc = 0;
|
||||
int bufindex = 0;
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
const size_t KEYSIZE = PERSISTENCE_MAX_KEY_LENGTH + 1;
|
||||
#endif
|
||||
char key[KEYSIZE];
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <direct.h>
|
||||
/* Windows doesn't have strtok_r, so remap it to strtok_s */
|
||||
#define strtok_r strtok_s
|
||||
|
|
@ -167,7 +167,7 @@ int pstmkdir( char *pPathname )
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if ( _mkdir( pPathname ) != 0 )
|
||||
{
|
||||
#else
|
||||
|
|
@ -346,7 +346,7 @@ int pstremove(void* handle, char* key)
|
|||
rc = MQTTCLIENT_PERSISTENCE_ERROR;
|
||||
else
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if ( _unlink(file) != 0 )
|
||||
{
|
||||
#else
|
||||
|
|
@ -380,7 +380,7 @@ int pstclose(void* handle)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if ( _rmdir(clientDir) != 0 )
|
||||
{
|
||||
#else
|
||||
|
|
@ -414,7 +414,7 @@ int pstcontainskey(void *handle, char *key)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = containskeyWin32(clientDir, key);
|
||||
#else
|
||||
rc = containskeyUnix(clientDir, key);
|
||||
|
|
@ -426,13 +426,13 @@ exit:
|
|||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
int containskeyWin32(char *dirname, char *key)
|
||||
{
|
||||
int notFound = MQTTCLIENT_PERSISTENCE_ERROR;
|
||||
int fFinished = 0;
|
||||
char *filekey, *ptraux;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define DIRSIZE MAX_PATH+1
|
||||
#else
|
||||
const size_t DIRSIZE = MAX_PATH+1;
|
||||
|
|
@ -552,7 +552,7 @@ int pstclear(void *handle)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = clearWin32(clientDir);
|
||||
#else
|
||||
rc = clearUnix(clientDir);
|
||||
|
|
@ -564,7 +564,7 @@ exit:
|
|||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
int clearWin32(char *dirname)
|
||||
{
|
||||
int rc = 0;
|
||||
|
|
@ -668,7 +668,7 @@ int pstkeys(void *handle, char ***keys, int *nkeys)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = keysWin32(clientDir, keys, nkeys);
|
||||
#else
|
||||
rc = keysUnix(clientDir, keys, nkeys);
|
||||
|
|
@ -680,7 +680,7 @@ exit:
|
|||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
int keysWin32(char *dirname, char ***keys, int *nkeys)
|
||||
{
|
||||
int rc = 0;
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ int MQTTProtocol_handlePublishes(void* pack, SOCKET sock)
|
|||
|
||||
/* Format and print publish data to trace */
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define buflen 30
|
||||
#else
|
||||
const int buflen = 30;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#include "MQTTTime.h"
|
||||
#include "StackTrace.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
void MQTTTime_sleep(ELAPSED_TIME_TYPE milliseconds)
|
||||
{
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep((DWORD)milliseconds);
|
||||
#else
|
||||
usleep((useconds_t)(milliseconds*1000));
|
||||
|
|
@ -35,7 +35,7 @@ void MQTTTime_sleep(ELAPSED_TIME_TYPE milliseconds)
|
|||
FUNC_EXIT;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
START_TIME_TYPE MQTTTime_start_clock(void)
|
||||
{
|
||||
#if WINVER >= _WIN32_WINNT_VISTA
|
||||
|
|
@ -69,7 +69,7 @@ START_TIME_TYPE MQTTTime_now(void)
|
|||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/*
|
||||
* @param t_new most recent time in milliseconds from GetTickCount()
|
||||
* @param t_old older time in milliseconds from GetTickCount()
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#if WINVER >= _WIN32_WINNT_VISTA
|
||||
#define START_TIME_TYPE ULONGLONG
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include <ctype.h>
|
||||
#include "MQTTAsync.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <io.h>
|
||||
|
|
@ -138,7 +138,7 @@ int loadandcall(const char* libname)
|
|||
{
|
||||
int rc = 0;
|
||||
MQTTAsync_nameValue* (*func_address)(void) = NULL;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
HMODULE APILibrary = LoadLibraryA(libname);
|
||||
if (APILibrary == NULL)
|
||||
printf("Error loading library %s, error code %d\n", libname, GetLastError());
|
||||
|
|
@ -202,7 +202,7 @@ int main(int argc, char** argv)
|
|||
{
|
||||
#if defined(__CYGWIN__)
|
||||
snprintf(namebuf, sizeof(namebuf), "cyg%s-1.dll", libraries[i]);
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
#elif defined(_WIN32)
|
||||
snprintf(namebuf, sizeof(namebuf), "%s.dll", libraries[i]);
|
||||
#elif defined(OSX)
|
||||
snprintf(namebuf, sizeof(namebuf), "lib%s.1.dylib", libraries[i]);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#include <string.h>
|
||||
// for timeout process in Proxy_connect()
|
||||
#include <time.h>
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
/* Windows doesn't have strtok_r, so remap it to strtok_s */
|
||||
#define strtok_r strtok_s
|
||||
|
|
@ -136,7 +136,7 @@ int Proxy_connect(networkHandles *net, int ssl, const char *hostname)
|
|||
rc = SOCKET_ERROR;
|
||||
break;
|
||||
}
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(250);
|
||||
#else
|
||||
usleep(250000);
|
||||
|
|
|
|||
11
src/SHA1.c
11
src/SHA1.c
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved.
|
||||
* Copyright (c) 2018, 2025 Wind River Systems, Inc. and others
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
#endif
|
||||
|
||||
#if !defined(OPENSSL)
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#pragma comment(lib, "crypt32.lib")
|
||||
|
||||
int SHA1_Init(SHA_CTX *c)
|
||||
|
|
@ -58,9 +58,8 @@ int SHA1_Final(unsigned char *md, SHA_CTX *c)
|
|||
CryptReleaseContext(c->hProv, 0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#else /* if defined(_WIN32) || defined(_WIN64) */
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
#else /* if defined(_WIN32) */
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__)
|
||||
# include <endian.h>
|
||||
#elif defined(__APPLE__)
|
||||
# include <libkern/OSByteOrder.h>
|
||||
|
|
@ -202,7 +201,7 @@ int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#endif /* else if defined(_WIN32) || defined(_WIN64) */
|
||||
#endif /* else if defined(_WIN32) */
|
||||
#endif /* elif !defined(OPENSSL) */
|
||||
|
||||
#if defined(SHA1_TEST)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#else /* if defined(OPENSSL) */
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
typedef struct SHA_CTX_S
|
||||
|
|
@ -33,7 +33,7 @@ typedef struct SHA_CTX_S
|
|||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
} SHA_CTX;
|
||||
#else /* if defined(_WIN32) || defined(_WIN64) */
|
||||
#else /* if defined(_WIN32) */
|
||||
|
||||
#include <stdint.h>
|
||||
typedef struct SHA_CTX_S {
|
||||
|
|
@ -45,7 +45,7 @@ typedef struct SHA_CTX_S {
|
|||
unsigned int size;
|
||||
unsigned int total;
|
||||
} SHA_CTX;
|
||||
#endif /* else if defined(_WIN32) || defined(_WIN64) */
|
||||
#endif /* else if defined(_WIN32) */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ static ssl_mutex_type sslCoreMutex;
|
|||
/* Used to store MQTTClient_SSLOptions for TLS-PSK callback */
|
||||
static int tls_ex_index_ssl_opts;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define iov_len len
|
||||
#define iov_base buf
|
||||
#define snprintf _snprintf
|
||||
|
|
@ -346,7 +346,7 @@ int SSL_create_mutex(ssl_mutex_type* mutex)
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
*mutex = CreateMutex(NULL, 0, NULL);
|
||||
#else
|
||||
rc = pthread_mutex_init(mutex, NULL);
|
||||
|
|
@ -360,7 +360,7 @@ int SSL_lock_mutex(ssl_mutex_type* mutex)
|
|||
int rc = -1;
|
||||
|
||||
/* don't add entry/exit trace points, as trace gets lock too, and it might happen quite frequently */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if (WaitForSingleObject(*mutex, INFINITE) != WAIT_FAILED)
|
||||
#else
|
||||
if ((rc = pthread_mutex_lock(mutex)) == 0)
|
||||
|
|
@ -375,7 +375,7 @@ int SSL_unlock_mutex(ssl_mutex_type* mutex)
|
|||
int rc = -1;
|
||||
|
||||
/* don't add entry/exit trace points, as trace gets lock too, and it might happen quite frequently */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if (ReleaseMutex(*mutex) != 0)
|
||||
#else
|
||||
if ((rc = pthread_mutex_unlock(mutex)) == 0)
|
||||
|
|
@ -390,7 +390,7 @@ int SSL_destroy_mutex(ssl_mutex_type* mutex)
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = CloseHandle(*mutex);
|
||||
#else
|
||||
rc = pthread_mutex_destroy(mutex);
|
||||
|
|
@ -404,7 +404,7 @@ int SSL_destroy_mutex(ssl_mutex_type* mutex)
|
|||
#if (OPENSSL_VERSION_NUMBER >= 0x010000000)
|
||||
extern void SSLThread_id(CRYPTO_THREADID *id)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentThreadId());
|
||||
#else
|
||||
CRYPTO_THREADID_set_numeric(id, (unsigned long)pthread_self());
|
||||
|
|
@ -413,7 +413,7 @@ extern void SSLThread_id(CRYPTO_THREADID *id)
|
|||
#else
|
||||
extern unsigned long SSLThread_id(void)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
return (unsigned long)GetCurrentThreadId();
|
||||
#else
|
||||
return (unsigned long)pthread_self();
|
||||
|
|
|
|||
|
|
@ -3,22 +3,22 @@
|
|||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Ian Craggs, Allan Stockdill-Mander - initial implementation
|
||||
* Ian Craggs, Allan Stockdill-Mander - initial implementation
|
||||
* Ian Craggs - SNI support
|
||||
* Ian Craggs - post connect checks and CApath
|
||||
*******************************************************************************/
|
||||
#if !defined(SSLSOCKET_H)
|
||||
#define SSLSOCKET_H
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define ssl_mutex_type HANDLE
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
#include "Clients.h"
|
||||
|
||||
#define URI_SSL "ssl://"
|
||||
#define URI_TLS "tls://"
|
||||
#define URI_MQTTS "mqtts://"
|
||||
|
||||
/** if we should handle openssl initialization (bool_value == 1) or depend on it to be initalized externally (bool_value == 0) */
|
||||
|
|
|
|||
24
src/Socket.c
24
src/Socket.c
|
|
@ -64,7 +64,7 @@ int Socket_continueWrite(SOCKET socket);
|
|||
char* Socket_getaddrname(struct sockaddr* sa, SOCKET sock);
|
||||
int Socket_abortWrite(SOCKET socket);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define iov_len len
|
||||
#define iov_base buf
|
||||
#define snprintf _snprintf
|
||||
|
|
@ -88,7 +88,7 @@ extern mutex_type socket_mutex;
|
|||
int Socket_setnonblocking(SOCKET sock)
|
||||
{
|
||||
int rc;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
u_long flag = 1L;
|
||||
|
||||
FUNC_ENTRY;
|
||||
|
|
@ -116,7 +116,7 @@ int Socket_error(char* aString, SOCKET sock)
|
|||
{
|
||||
int err;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
err = WSAGetLastError();
|
||||
#else
|
||||
err = errno;
|
||||
|
|
@ -129,7 +129,7 @@ int Socket_error(char* aString, SOCKET sock)
|
|||
return err;
|
||||
}
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
void SIGPIPE_ignore()
|
||||
{
|
||||
#if defined(PAHO_IGNORE_WITH_SIGNAL)
|
||||
|
|
@ -151,7 +151,7 @@ void SIGPIPE_ignore()
|
|||
*/
|
||||
void Socket_outInitialize(void)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
WORD winsockVer = 0x0202;
|
||||
WSADATA wsd;
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ void Socket_outTerminate(void)
|
|||
free(mod_s.saved.fds_read);
|
||||
#endif
|
||||
SocketBuffer_terminate();
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
FUNC_EXIT;
|
||||
|
|
@ -335,7 +335,7 @@ int Socket_addSocket(SOCKET newSd)
|
|||
|
||||
mod_s.fds_read[mod_s.nfds - 1].fd = newSd;
|
||||
mod_s.fds_write[mod_s.nfds - 1].fd = newSd;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mod_s.fds_read[mod_s.nfds - 1].events = POLLIN;
|
||||
mod_s.fds_write[mod_s.nfds - 1].events = POLLOUT;
|
||||
#else
|
||||
|
|
@ -784,7 +784,7 @@ int Socket_writev(SOCKET socket, iobuf* iovecs, int count, unsigned long* bytes)
|
|||
|
||||
FUNC_ENTRY;
|
||||
*bytes = 0L;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = WSASend(socket, iovecs, count, (LPDWORD)bytes, 0, NULL, NULL);
|
||||
if (rc == SOCKET_ERROR)
|
||||
{
|
||||
|
|
@ -955,7 +955,7 @@ int Socket_close_only(SOCKET socket)
|
|||
int rc;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if (shutdown(socket, SD_BOTH) == SOCKET_ERROR)
|
||||
Socket_error("shutdown", socket);
|
||||
if ((rc = closesocket(socket)) == SOCKET_ERROR)
|
||||
|
|
@ -1140,13 +1140,13 @@ int Socket_new(const char* addr, size_t addr_len, int port, SOCKET* sock)
|
|||
struct sockaddr_in6 address6;
|
||||
#endif
|
||||
int rc = SOCKET_ERROR;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
short family = AF_INET;
|
||||
#else
|
||||
sa_family_t family = AF_INET;
|
||||
#endif
|
||||
struct addrinfo *result = NULL;
|
||||
struct addrinfo hints = {0, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL, NULL};
|
||||
struct addrinfo hints = {AI_ADDRCONFIG, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL, NULL};
|
||||
|
||||
FUNC_ENTRY;
|
||||
*sock = SOCKET_ERROR;
|
||||
|
|
@ -1607,7 +1607,7 @@ char* Socket_getaddrname(struct sockaddr* sa, SOCKET sock)
|
|||
#define PORTLEN 10
|
||||
static char addr_string[ADDRLEN + PORTLEN];
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
int buflen = ADDRLEN*2;
|
||||
wchar_t buf[ADDRLEN*2];
|
||||
if (WSAAddressToStringW(sa, sizeof(struct sockaddr_in6), NULL, buf, (LPDWORD)&buflen) == SOCKET_ERROR)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <errno.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include "Heap.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define iov_len len
|
||||
#define iov_base buf
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <openssl/ssl.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
typedef WSABUF iobuf;
|
||||
#else
|
||||
typedef struct iovec iobuf;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ static int thread_count = 0;
|
|||
static threadEntry threads[MAX_THREADS];
|
||||
static threadEntry *my_thread = NULL;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex_type stack_mutex;
|
||||
#else
|
||||
static pthread_mutex_t stack_mutex_store = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#define FUNC_EXIT_MED_RC(x)
|
||||
#define FUNC_EXIT_MAX_RC(x)
|
||||
#else
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define inline __inline
|
||||
#define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM)
|
||||
#define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1)
|
||||
|
|
|
|||
63
src/Thread.c
63
src/Thread.c
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2023 IBM Corp. and Ian Craggs
|
||||
* Copyright (c) 2009, 2025 IBM Corp. and Ian Craggs
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
#undef realloc
|
||||
#undef free
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
|
@ -51,6 +51,10 @@
|
|||
|
||||
#include "OsWrapper.h"
|
||||
|
||||
#if !defined(NSEC_PER_SEC)
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start a new thread
|
||||
* @param fn the function to run, must be of the correct signature
|
||||
|
|
@ -58,7 +62,7 @@
|
|||
*/
|
||||
void Paho_thread_start(thread_fn fn, void* parameter)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
thread_type thread = NULL;
|
||||
#else
|
||||
thread_type thread = 0;
|
||||
|
|
@ -66,7 +70,7 @@ void Paho_thread_start(thread_fn fn, void* parameter)
|
|||
#endif
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
thread = CreateThread(NULL, 0, fn, parameter, 0, NULL);
|
||||
CloseHandle(thread);
|
||||
#else
|
||||
|
|
@ -83,13 +87,13 @@ void Paho_thread_start(thread_fn fn, void* parameter)
|
|||
int Thread_set_name(const char* thread_name)
|
||||
{
|
||||
int rc = 0;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define MAX_THREAD_NAME_LENGTH 30
|
||||
wchar_t wchars[MAX_THREAD_NAME_LENGTH];
|
||||
#endif
|
||||
FUNC_ENTRY;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/* Using NTDDI_VERSION rather than WINVER for more detailed version targeting */
|
||||
/* Can't get this conditional compilation to work so remove it for now */
|
||||
/*#if NTDDI_VERSION >= NTDDI_WIN10_RS1
|
||||
|
|
@ -124,7 +128,7 @@ mutex_type Paho_thread_create_mutex(int* rc)
|
|||
|
||||
FUNC_ENTRY;
|
||||
*rc = -1;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex = CreateMutex(NULL, 0, NULL);
|
||||
*rc = (mutex == NULL) ? GetLastError() : 0;
|
||||
#else
|
||||
|
|
@ -146,7 +150,7 @@ int Paho_thread_lock_mutex(mutex_type mutex)
|
|||
int rc = -1;
|
||||
|
||||
/* don't add entry/exit trace points as the stack log uses mutexes - recursion beckons */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/* WaitForSingleObject returns WAIT_OBJECT_0 (0), on success */
|
||||
rc = WaitForSingleObject(mutex, INFINITE);
|
||||
#else
|
||||
|
|
@ -167,7 +171,7 @@ int Paho_thread_unlock_mutex(mutex_type mutex)
|
|||
int rc = -1;
|
||||
|
||||
/* don't add entry/exit trace points as the stack log uses mutexes - recursion beckons */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/* if ReleaseMutex fails, the return value is 0 */
|
||||
if (ReleaseMutex(mutex) == 0)
|
||||
rc = GetLastError();
|
||||
|
|
@ -190,7 +194,7 @@ int Paho_thread_destroy_mutex(mutex_type mutex)
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = CloseHandle(mutex);
|
||||
#else
|
||||
rc = pthread_mutex_destroy(mutex);
|
||||
|
|
@ -207,7 +211,7 @@ int Paho_thread_destroy_mutex(mutex_type mutex)
|
|||
*/
|
||||
thread_id_type Paho_thread_getid(void)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
return pthread_self();
|
||||
|
|
@ -226,7 +230,7 @@ sem_type Thread_create_sem(int *rc)
|
|||
|
||||
FUNC_ENTRY;
|
||||
*rc = -1;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
sem = CreateEvent(
|
||||
NULL, /* default security attributes */
|
||||
FALSE, /* manual-reset event? */
|
||||
|
|
@ -259,7 +263,7 @@ int Thread_wait_sem(sem_type sem, int timeout)
|
|||
* so I've used trywait in a loop instead. Ian Craggs 23/7/2010
|
||||
*/
|
||||
int rc = -1;
|
||||
#if !defined(_WIN32) && !defined(_WIN64) && !defined(OSX)
|
||||
#if !defined(_WIN32) && !defined(OSX)
|
||||
#define USE_TRYWAIT
|
||||
#if defined(USE_TRYWAIT)
|
||||
int i = 0;
|
||||
|
|
@ -271,7 +275,7 @@ int Thread_wait_sem(sem_type sem, int timeout)
|
|||
#endif
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/* returns 0 (WAIT_OBJECT_0) on success, non-zero (WAIT_TIMEOUT) if timeout occurred */
|
||||
rc = WaitForSingleObject(sem, timeout < 0 ? 0 : timeout);
|
||||
if (rc == WAIT_TIMEOUT)
|
||||
|
|
@ -317,7 +321,7 @@ int Thread_wait_sem(sem_type sem, int timeout)
|
|||
*/
|
||||
int Thread_check_sem(sem_type sem)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
/* if the return value is not 0, the semaphore will not have been decremented */
|
||||
return WaitForSingleObject(sem, 0) == WAIT_OBJECT_0;
|
||||
#elif defined(OSX)
|
||||
|
|
@ -341,7 +345,7 @@ int Thread_post_sem(sem_type sem)
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
if (SetEvent(sem) == 0)
|
||||
rc = GetLastError();
|
||||
#elif defined(OSX)
|
||||
|
|
@ -369,7 +373,7 @@ int Thread_destroy_sem(sem_type sem)
|
|||
int rc = 0;
|
||||
|
||||
FUNC_ENTRY;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
rc = CloseHandle(sem);
|
||||
#elif defined(OSX)
|
||||
dispatch_release(sem);
|
||||
|
|
@ -382,7 +386,7 @@ int Thread_destroy_sem(sem_type sem)
|
|||
}
|
||||
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
|
||||
/**
|
||||
* Create a new condition variable
|
||||
|
|
@ -443,12 +447,8 @@ int Thread_wait_cond(cond_type condvar, int timeout_ms)
|
|||
{
|
||||
int rc = 0;
|
||||
struct timespec cond_timeout;
|
||||
struct timespec interval;
|
||||
|
||||
FUNC_ENTRY;
|
||||
interval.tv_sec = timeout_ms / 1000;
|
||||
interval.tv_nsec = (timeout_ms % 1000) * 1000000L;
|
||||
|
||||
#if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 /* for older versions of MacOS */
|
||||
struct timeval cur_time;
|
||||
gettimeofday(&cur_time, NULL);
|
||||
|
|
@ -458,13 +458,20 @@ int Thread_wait_cond(cond_type condvar, int timeout_ms)
|
|||
clock_gettime(CLOCK_REALTIME, &cond_timeout);
|
||||
#endif
|
||||
|
||||
cond_timeout.tv_sec += interval.tv_sec;
|
||||
cond_timeout.tv_nsec += (timeout_ms % 1000) * 1000000L;
|
||||
if (timeout_ms > 0) {
|
||||
struct timespec interval;
|
||||
|
||||
if (cond_timeout.tv_nsec >= 1000000000L)
|
||||
{
|
||||
cond_timeout.tv_sec++;
|
||||
cond_timeout.tv_nsec += (cond_timeout.tv_nsec - 1000000000L);
|
||||
interval.tv_sec = timeout_ms / 1000;
|
||||
interval.tv_nsec = (timeout_ms % 1000) * 1000000L;
|
||||
|
||||
cond_timeout.tv_sec += interval.tv_sec;
|
||||
cond_timeout.tv_nsec += interval.tv_nsec;
|
||||
|
||||
while (cond_timeout.tv_nsec >= NSEC_PER_SEC)
|
||||
{
|
||||
cond_timeout.tv_sec++;
|
||||
cond_timeout.tv_nsec -= NSEC_PER_SEC;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&condvar->mutex);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#if !defined(THREAD_H)
|
||||
#define THREAD_H
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
#if defined(__GNUC__) && defined(__linux__)
|
||||
#if !defined(_GNU_SOURCE)
|
||||
// for pthread_setname
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include "mutex_type.h" /* Needed for mutex_type */
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#define thread_type HANDLE
|
||||
#define thread_id_type DWORD
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
# define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
# include <sys/endian.h>
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
#elif defined(_WIN32)
|
||||
# pragma comment(lib, "rpcrt4.lib")
|
||||
# include <rpc.h>
|
||||
# if !(defined(__MINGW32__))
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
#define HTTP_PROTOCOL(x) x ? "https" : "http"
|
||||
|
||||
#if !(defined(_WIN32) || defined(_WIN64))
|
||||
#if !(defined(_WIN32))
|
||||
#if defined(USE_LIBUUID)
|
||||
#include <uuid/uuid.h>
|
||||
#else /* if defined(USE_LIBUUID) */
|
||||
|
|
@ -142,7 +142,7 @@ static void uuid_unparse( uuid_t uu, char *out )
|
|||
}
|
||||
#endif
|
||||
#endif /* else if defined(USE_LIBUUID) */
|
||||
#endif /* if !(defined(_WIN32) || defined(_WIN64)) */
|
||||
#endif /* if !(defined(_WIN32)) */
|
||||
|
||||
#include "Heap.h"
|
||||
|
||||
|
|
@ -394,11 +394,11 @@ int WebSocket_connect( networkHandles *net, int ssl, const char *uri)
|
|||
size_t hostname_len;
|
||||
int port = 80;
|
||||
const char *topic = NULL;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
UUID uuid;
|
||||
#else /* if defined(_WIN32) || defined(_WIN64) */
|
||||
#else /* if defined(_WIN32) */
|
||||
uuid_t uuid;
|
||||
#endif /* else if defined(_WIN32) || defined(_WIN64) */
|
||||
#endif /* else if defined(_WIN32) */
|
||||
|
||||
FUNC_ENTRY;
|
||||
/* Generate UUID */
|
||||
|
|
@ -422,14 +422,14 @@ int WebSocket_connect( networkHandles *net, int ssl, const char *uri)
|
|||
rc = PAHO_MEMORY_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
ZeroMemory( &uuid, sizeof(UUID) );
|
||||
UuidCreate( &uuid );
|
||||
Base64_encode( net->websocket_key, 25u, (const b64_data_t*)&uuid, sizeof(UUID) );
|
||||
#else /* if defined(_WIN32) || defined(_WIN64) */
|
||||
#else /* if defined(_WIN32) */
|
||||
uuid_generate( uuid );
|
||||
Base64_encode( net->websocket_key, 25u, uuid, sizeof(uuid_t) );
|
||||
#endif /* else if defined(_WIN32) || defined(_WIN64) */
|
||||
#endif /* else if defined(_WIN32) */
|
||||
|
||||
hostname_len = MQTTProtocol_addressPort(uri, &port, &topic, ssl ? WSS_DEFAULT_PORT : WS_DEFAULT_PORT);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#if !defined(_MUTEX_TYPE_H_)
|
||||
#define _MUTEX_TYPE_H_
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#define mutex_type HANDLE
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
#include <OsWrapper.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#include <OsWrapper.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
#include <OsWrapper.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientSub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
#include <string.h>
|
||||
#include "MQTTClient.h"
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientPub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
#include <string.h>
|
||||
#include "MQTTClient.h"
|
||||
|
||||
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
|
||||
#define ADDRESS "tcp://test.mosquitto.org:1883"
|
||||
#define CLIENTID "ExampleClientSub"
|
||||
#define TOPIC "MQTT Examples"
|
||||
#define PAYLOAD "Hello World!"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2020 IBM Corp., and others
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -314,6 +314,8 @@ void myconnect(MQTTAsync client)
|
|||
}
|
||||
|
||||
if (opts.connection && (strncmp(opts.connection, "ssl://", 6) == 0 ||
|
||||
strncmp(opts.connection, "tls://", 6) == 0 ||
|
||||
strncmp(opts.connection, "mqtts://", 7) == 0 ||
|
||||
strncmp(opts.connection, "wss://", 6) == 0))
|
||||
{
|
||||
if (opts.insecure)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2020 IBM Corp., and others
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -303,6 +303,8 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (opts.connection && (strncmp(opts.connection, "ssl://", 6) == 0 ||
|
||||
strncmp(opts.connection, "tls://", 6) == 0||
|
||||
strncmp(opts.connection, "mqtts://", 7) == 0 ||
|
||||
strncmp(opts.connection, "wss://", 6) == 0))
|
||||
{
|
||||
ssl_opts.verify = (opts.insecure) ? 0 : 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2022 IBM Corp.
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -85,6 +85,8 @@ int myconnect(MQTTClient client)
|
|||
}
|
||||
|
||||
if (opts.connection && (strncmp(opts.connection, "ssl://", 6) == 0 ||
|
||||
strncmp(opts.connection, "tls://", 6) == 0 ||
|
||||
strncmp(opts.connection, "mqtts://", 7) == 0 ||
|
||||
strncmp(opts.connection, "wss://", 6) == 0))
|
||||
{
|
||||
if (opts.insecure)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2022 IBM Corp., and others
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -82,6 +82,8 @@ int myconnect(MQTTClient client)
|
|||
}
|
||||
|
||||
if (opts.connection && (strncmp(opts.connection, "ssl://", 6) == 0 ||
|
||||
strncmp(opts.connection, "tls://", 6) == 0 ||
|
||||
strncmp(opts.connection, "mqtts://", 7) == 0 ||
|
||||
strncmp(opts.connection, "wss://", 6) == 0))
|
||||
{
|
||||
if (opts.insecure)
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
|
|||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
mutex_type deliveryCompleted_mutex = NULL;
|
||||
#else
|
||||
pthread_mutex_t deliveryCompleted_mutex_store = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
@ -679,7 +679,7 @@ int main(int argc, char** argv)
|
|||
int (*tests[])(struct Options) = {NULL, test1};
|
||||
int i;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
deliveryCompleted_mutex = CreateMutex(NULL, 0, NULL);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012, 2024 IBM Corp., Ian Craggs and others
|
||||
* Copyright (c) 2012, 2025 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
|
||||
|
|
@ -88,7 +88,7 @@ struct Options
|
|||
int websockets;
|
||||
} options =
|
||||
{
|
||||
"ssl://localhost:18883",
|
||||
"tls://localhost:18883",
|
||||
"mqtts://localhost:18884",
|
||||
"ssl://localhost:18887",
|
||||
"mqtts://localhost:18885",
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -176,14 +176,14 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WINDOWS)
|
||||
#if defined(_WIN32) || defined(_WINDOWS)
|
||||
#define START_TIME_TYPE DWORD
|
||||
static DWORD start_time = 0;
|
||||
START_TIME_TYPE start_clock(void)
|
||||
|
|
@ -210,7 +210,7 @@ START_TIME_TYPE start_clock(void)
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
long elapsed(START_TIME_TYPE start_time)
|
||||
{
|
||||
return GetTickCount() - start_time;
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ void MyLog(int LOGA_level, char* format, ...)
|
|||
|
||||
void MySleep(long milliseconds)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(_WIN32)
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds*1000);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2024 IBM Corp.
|
||||
* Copyright (c) 2009, 2025 IBM Corp.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
|
|
@ -244,7 +244,7 @@ static thread_return_type WINAPI sem_secondary(void* n)
|
|||
duration = elapsed(start);
|
||||
assert("rc 0 from lock mutex", rc == 0, "rc was %d", rc);
|
||||
MyLog(LOGA_INFO, "Lock duration was %ld", duration);
|
||||
assert("duration is 2s", duration >= 2000L, "duration was %ld", duration);
|
||||
assert("duration is 2s", duration >= 1999L && duration < 2050L, "duration was %ld", duration);
|
||||
|
||||
MyLog(LOGA_DEBUG, "Secondary thread ending");
|
||||
return 0;
|
||||
|
|
@ -288,10 +288,14 @@ int test_sem(struct Options options)
|
|||
assert("rc 0 from post_sem", rc == 0, "rc was %d\n", rc);
|
||||
}
|
||||
|
||||
rc = Thread_check_sem(sem);
|
||||
assert("rc 1 from check_sem", rc == 1, "rc was %d", rc);
|
||||
|
||||
// Binary sem, so additional checks should be zero
|
||||
for (i = 0; i < 10; ++i)
|
||||
{
|
||||
rc = Thread_check_sem(sem);
|
||||
assert("rc 1 from check_sem", rc == 1, "rc was %d", rc);
|
||||
assert("rc 0 from check_sem", rc == 0, "rc was %d", rc);
|
||||
}
|
||||
rc = Thread_check_sem(sem);
|
||||
assert("rc 0 from check_sem", rc == 0, "rc was %d", rc);
|
||||
|
|
@ -300,7 +304,11 @@ int test_sem(struct Options options)
|
|||
start = start_clock();
|
||||
rc = Thread_wait_sem(sem, 1500);
|
||||
duration = elapsed(start);
|
||||
assert("rc ETIMEDOUT from lock mutex", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
#if defined(EAGAIN)
|
||||
assert("rc ETIMEDOUT from lock mutex", rc == ETIMEDOUT || rc == EAGAIN, "rc was %d", rc);
|
||||
#else
|
||||
assert("rc ETIMEDOUT from lock mutex", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
#endif
|
||||
MyLog(LOGA_INFO, "Lock duration was %ld", duration);
|
||||
assert("duration is 2s", duration >= 1500L, "duration was %ld", duration);
|
||||
|
||||
|
|
@ -310,7 +318,7 @@ int test_sem(struct Options options)
|
|||
mysleep(2);
|
||||
MyLog(LOGA_DEBUG, "post secondary");
|
||||
rc = Thread_post_sem(sem);
|
||||
assert("rc 1 from post_sem", rc == 1, "rc was %d", rc);
|
||||
assert("rc 0 from post_sem", rc == 0, "rc was %d", rc);
|
||||
|
||||
mysleep(1);
|
||||
|
||||
|
|
@ -323,7 +331,7 @@ int test_sem(struct Options options)
|
|||
return failures;
|
||||
}
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
thread_return_type cond_secondary(void* n)
|
||||
{
|
||||
int rc = 0;
|
||||
|
|
@ -333,10 +341,10 @@ thread_return_type cond_secondary(void* n)
|
|||
|
||||
MyLog(LOGA_DEBUG, "This will time out");
|
||||
start = start_clock();
|
||||
rc = Thread_wait_cond(cond, 1);
|
||||
rc = Thread_wait_cond(cond, 1000);
|
||||
duration = elapsed(start);
|
||||
MyLog(LOGA_INFO, "Lock duration was %ld", duration);
|
||||
assert("duration is about 1s", duration >= 1000L && duration <= 1050L, "duration was %ld", duration);
|
||||
assert("duration is about 1s", duration >= 999L && duration <= 1050L, "duration was %ld", duration);
|
||||
assert("rc non 0 from wait_cond", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
|
||||
MyLog(LOGA_DEBUG, "This should hang around a few seconds");
|
||||
|
|
@ -370,11 +378,11 @@ int test_cond(struct Options options)
|
|||
|
||||
MyLog(LOGA_DEBUG, "Check timeout");
|
||||
start = start_clock();
|
||||
rc = Thread_wait_cond(cond, 2);
|
||||
rc = Thread_wait_cond(cond, 2000);
|
||||
duration = elapsed(start);
|
||||
assert("rc ETIMEDOUT from lock mutex", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
MyLog(LOGA_INFO, "Lock duration was %ld", duration);
|
||||
assert("duration is 2s", duration >= 2000L, "duration was %ld", duration);
|
||||
assert("duration is 2s", duration >= 1999L && duration < 2050L, "duration was %ld", duration);
|
||||
|
||||
/* multiple posts */
|
||||
for (i = 0; i < 10; ++i)
|
||||
|
|
@ -389,8 +397,6 @@ int test_cond(struct Options options)
|
|||
rc = Thread_wait_cond(cond, 0);
|
||||
assert("rc non-zero from wait_cond", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
}
|
||||
rc = Thread_wait_cond(cond, 0);
|
||||
assert("rc non-zero from wait_cond", rc == ETIMEDOUT, "rc was %d", rc);
|
||||
|
||||
MyLog(LOGA_DEBUG, "Post secondary but it will time out");
|
||||
rc = Thread_signal_cond(cond);
|
||||
|
|
@ -494,7 +500,7 @@ int main(int argc, char** argv)
|
|||
int (*tests[])(struct Options) = {NULL,
|
||||
test_mutex,
|
||||
test_sem,
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if !defined(_WIN32)
|
||||
test_cond
|
||||
#endif
|
||||
}; /* indexed starting from 1 */
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
14
|
||||
15
|
||||
Loading…
Reference in New Issue