From 1bb2e691e1f511025c81a73bc3918bd0b855d081 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Wed, 8 Jan 2025 17:24:27 -0500 Subject: [PATCH 01/17] - Removed unnecessary _WIN64 conditional checks - Fixed some conditional compilation using (WIN32) to (_WIN32) --- src/Base64.c | 6 ++--- src/Clients.h | 2 +- src/Heap.c | 2 +- src/Log.c | 10 ++++---- src/Log.h | 2 +- src/MQTTAsync.c | 8 +++---- src/MQTTAsyncUtils.c | 22 +++++++++--------- src/MQTTAsyncUtils.h | 2 +- src/MQTTClient.c | 8 +++---- src/MQTTExportDeclarations.h | 2 +- src/MQTTPacket.c | 2 +- src/MQTTPersistence.c | 6 ++--- src/MQTTPersistenceDefault.c | 22 +++++++++--------- src/MQTTProtocolClient.c | 2 +- src/MQTTTime.c | 8 +++---- src/MQTTTime.h | 2 +- src/MQTTVersion.c | 6 ++--- src/Proxy.c | 4 ++-- src/SHA1.c | 6 ++--- src/SHA1.h | 6 ++--- src/SSLSocket.c | 14 ++++++------ src/SSLSocket.h | 2 +- src/Socket.c | 22 +++++++++--------- src/Socket.h | 2 +- src/SocketBuffer.c | 2 +- src/SocketBuffer.h | 2 +- src/StackTrace.c | 4 ++-- src/StackTrace.h | 2 +- src/Thread.c | 34 ++++++++++++++-------------- src/Thread.h | 4 ++-- src/WebSocket.c | 18 +++++++-------- src/mutex_type.h | 2 +- src/samples/MQTTAsync_publish_time.c | 2 +- test/test2.c | 4 ++-- test/test45.c | 2 +- test/test6.c | 2 +- test/test9.c | 2 +- test/test95.c | 2 +- test/test_connect_destroy.c | 6 ++--- test/test_issue373.c | 2 +- test/test_persistence.c | 2 +- test/thread.c | 4 ++-- 42 files changed, 132 insertions(+), 132 deletions(-) diff --git a/src/Base64.c b/src/Base64.c index 4634af2f..54d3fe15 100644 --- a/src/Base64.c +++ b/src/Base64.c @@ -16,7 +16,7 @@ #include "Base64.h" -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #pragma comment(lib, "crypt32.lib") #include #include @@ -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 @@ -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 ) { diff --git a/src/Clients.h b/src/Clients.h index 577551ee..6ad84376 100644 --- a/src/Clients.h +++ b/src/Clients.h @@ -24,7 +24,7 @@ #include #include "MQTTTime.h" -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #endif #if defined(OPENSSL) diff --git a/src/Heap.c b/src/Heap.c index 78f2f299..9684c513 100644 --- a/src/Heap.c +++ b/src/Heap.c @@ -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; diff --git a/src/Log.c b/src/Log.c index 2981eec3..944c0866 100644 --- a/src/Log.c +++ b/src/Log.c @@ -38,7 +38,7 @@ #include #include -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) #include #include #define GETTIMEOFDAY 1 @@ -52,7 +52,7 @@ #include #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; diff --git a/src/Log.h b/src/Log.h index ae9bb9ef..6f3813fc 100644 --- a/src/Log.h +++ b/src/Log.h @@ -18,7 +18,7 @@ #if !defined(LOG_H) #define LOG_H -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #define thread_id_type DWORD #else diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index c548ae31..0e103286 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -41,7 +41,7 @@ #include #include -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) #include #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 diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c index c084a11e..0e64a1cd 100644 --- a/src/MQTTAsyncUtils.c +++ b/src/MQTTAsyncUtils.c @@ -17,7 +17,7 @@ #include #include -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) #include #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 @@ -1847,7 +1847,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 @@ -1872,7 +1872,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; @@ -2058,7 +2058,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); @@ -2388,7 +2388,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 @@ -2405,7 +2405,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; @@ -3134,7 +3134,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); @@ -3146,7 +3146,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); diff --git a/src/MQTTAsyncUtils.h b/src/MQTTAsyncUtils.h index 541c6611..3debd1aa 100644 --- a/src/MQTTAsyncUtils.h +++ b/src/MQTTAsyncUtils.h @@ -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 diff --git a/src/MQTTClient.c b/src/MQTTClient.c index 32d59c3b..6171d0d7 100644 --- a/src/MQTTClient.c +++ b/src/MQTTClient.c @@ -46,7 +46,7 @@ #include #include -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) #include #else #if defined(_MSC_VER) && _MSC_VER < 1900 @@ -114,7 +114,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 +370,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 @@ -1026,7 +1026,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; diff --git a/src/MQTTExportDeclarations.h b/src/MQTTExportDeclarations.h index d492ef19..e4118af4 100644 --- a/src/MQTTExportDeclarations.h +++ b/src/MQTTExportDeclarations.h @@ -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) diff --git a/src/MQTTPacket.c b/src/MQTTPacket.c index 40cb4d41..5bd6af4f 100644 --- a/src/MQTTPacket.c +++ b/src/MQTTPacket.c @@ -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; diff --git a/src/MQTTPersistence.c b/src/MQTTPersistence.c index e40ef583..f8486a85 100644 --- a/src/MQTTPersistence.c +++ b/src/MQTTPersistence.c @@ -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]; diff --git a/src/MQTTPersistenceDefault.c b/src/MQTTPersistenceDefault.c index 83d29b1a..e437eee6 100644 --- a/src/MQTTPersistenceDefault.c +++ b/src/MQTTPersistenceDefault.c @@ -36,7 +36,7 @@ #include #include -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include /* 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; diff --git a/src/MQTTProtocolClient.c b/src/MQTTProtocolClient.c index 9649db4d..90673886 100644 --- a/src/MQTTProtocolClient.c +++ b/src/MQTTProtocolClient.c @@ -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; diff --git a/src/MQTTTime.c b/src/MQTTTime.c index 9afab024..349afec6 100644 --- a/src/MQTTTime.c +++ b/src/MQTTTime.c @@ -17,7 +17,7 @@ #include "MQTTTime.h" #include "StackTrace.h" -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #else #include @@ -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() diff --git a/src/MQTTTime.h b/src/MQTTTime.h index 490cfef3..3347546c 100644 --- a/src/MQTTTime.h +++ b/src/MQTTTime.h @@ -19,7 +19,7 @@ #include -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #if WINVER >= _WIN32_WINNT_VISTA #define START_TIME_TYPE ULONGLONG diff --git a/src/MQTTVersion.c b/src/MQTTVersion.c index 92cd020c..a1903758 100644 --- a/src/MQTTVersion.c +++ b/src/MQTTVersion.c @@ -26,7 +26,7 @@ #include #include "MQTTAsync.h" -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #include #include @@ -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]); diff --git a/src/Proxy.c b/src/Proxy.c index bb9ad682..b1c34b7b 100644 --- a/src/Proxy.c +++ b/src/Proxy.c @@ -19,7 +19,7 @@ #include // for timeout process in Proxy_connect() #include -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include /* 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); diff --git a/src/SHA1.c b/src/SHA1.c index 3ef07d92..98fcc443 100644 --- a/src/SHA1.c +++ b/src/SHA1.c @@ -17,7 +17,7 @@ #include "SHA1.h" #if !defined(OPENSSL) -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #pragma comment(lib, "crypt32.lib") int SHA1_Init(SHA_CTX *c) @@ -52,7 +52,7 @@ int SHA1_Final(unsigned char *md, SHA_CTX *c) return rv; } -#else /* if defined(_WIN32) || defined(_WIN64) */ +#else /* if defined(_WIN32) */ #if defined(__linux__) || defined(__CYGWIN__) # include #elif defined(__APPLE__) @@ -195,7 +195,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) diff --git a/src/SHA1.h b/src/SHA1.h index 3ae2f0a3..770ee140 100644 --- a/src/SHA1.h +++ b/src/SHA1.h @@ -25,7 +25,7 @@ #else /* if defined(OPENSSL) */ -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #include 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 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 diff --git a/src/SSLSocket.c b/src/SSLSocket.c index 8cb090c4..3b4af662 100644 --- a/src/SSLSocket.c +++ b/src/SSLSocket.c @@ -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(); diff --git a/src/SSLSocket.h b/src/SSLSocket.h index 2e804cec..2594da20 100644 --- a/src/SSLSocket.h +++ b/src/SSLSocket.h @@ -18,7 +18,7 @@ #if !defined(SSLSOCKET_H) #define SSLSOCKET_H -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #define ssl_mutex_type HANDLE #else #include diff --git a/src/Socket.c b/src/Socket.c index ff366578..ffa53786 100644 --- a/src/Socket.c +++ b/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,7 +1140,7 @@ 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; @@ -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) diff --git a/src/Socket.h b/src/Socket.h index 6e52ab8f..5ec65eab 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -21,7 +21,7 @@ #include #include -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #include #include diff --git a/src/SocketBuffer.c b/src/SocketBuffer.c index 9d553c22..5e7c89a1 100644 --- a/src/SocketBuffer.c +++ b/src/SocketBuffer.c @@ -34,7 +34,7 @@ #include "Heap.h" -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #define iov_len len #define iov_base buf #endif diff --git a/src/SocketBuffer.h b/src/SocketBuffer.h index 1b2ab915..6b7e4a89 100644 --- a/src/SocketBuffer.h +++ b/src/SocketBuffer.h @@ -24,7 +24,7 @@ #include #endif -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) typedef WSABUF iobuf; #else typedef struct iovec iobuf; diff --git a/src/StackTrace.c b/src/StackTrace.c index d3d298de..de7193d8 100644 --- a/src/StackTrace.c +++ b/src/StackTrace.c @@ -25,7 +25,7 @@ #include #include -#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; diff --git a/src/StackTrace.h b/src/StackTrace.h index c4f0d433..1cab87a7 100644 --- a/src/StackTrace.h +++ b/src/StackTrace.h @@ -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) diff --git a/src/Thread.c b/src/Thread.c index f4d43fb6..ddfbee66 100644 --- a/src/Thread.c +++ b/src/Thread.c @@ -38,7 +38,7 @@ #undef realloc #undef free -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) #include #include #include @@ -58,7 +58,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 +66,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 +83,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 +124,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 +146,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 +167,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 +190,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 +207,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 +226,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 +259,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 +271,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 +317,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 +341,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 +369,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 +382,7 @@ int Thread_destroy_sem(sem_type sem) } -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) /** * Create a new condition variable diff --git a/src/Thread.h b/src/Thread.h index b0c823b6..bb249aee 100644 --- a/src/Thread.h +++ b/src/Thread.h @@ -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 #define thread_type HANDLE #define thread_id_type DWORD diff --git a/src/WebSocket.c b/src/WebSocket.c index 4338898b..84142fda 100644 --- a/src/WebSocket.c +++ b/src/WebSocket.c @@ -47,7 +47,7 @@ # define be64toh(x) OSSwapBigToHostInt64(x) #elif defined(__FreeBSD__) || defined(__NetBSD__) # include -#elif defined(_WIN32) || defined(_WIN64) +#elif defined(_WIN32) # pragma comment(lib, "rpcrt4.lib") # include # 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 #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); diff --git a/src/mutex_type.h b/src/mutex_type.h index 1e4b9e52..1203055a 100644 --- a/src/mutex_type.h +++ b/src/mutex_type.h @@ -14,7 +14,7 @@ #if !defined(_MUTEX_TYPE_H_) #define _MUTEX_TYPE_H_ -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #define mutex_type HANDLE #else diff --git a/src/samples/MQTTAsync_publish_time.c b/src/samples/MQTTAsync_publish_time.c index 6aad601a..7db1ef90 100644 --- a/src/samples/MQTTAsync_publish_time.c +++ b/src/samples/MQTTAsync_publish_time.c @@ -38,7 +38,7 @@ #include #endif -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #define snprintf _snprintf #endif diff --git a/test/test2.c b/test/test2.c index f11fc054..0daf8d38 100644 --- a/test/test2.c +++ b/test/test2.c @@ -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 diff --git a/test/test45.c b/test/test45.c index fafd474d..20bb2862 100644 --- a/test/test45.c +++ b/test/test45.c @@ -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); diff --git a/test/test6.c b/test/test6.c index b5e7a86b..855918da 100644 --- a/test/test6.c +++ b/test/test6.c @@ -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); diff --git a/test/test9.c b/test/test9.c index 6a9e39f6..aa6e2c4c 100644 --- a/test/test9.c +++ b/test/test9.c @@ -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); diff --git a/test/test95.c b/test/test95.c index d82bdd9f..91475d40 100644 --- a/test/test95.c +++ b/test/test95.c @@ -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); diff --git a/test/test_connect_destroy.c b/test/test_connect_destroy.c index e694b85d..93d5e1a7 100644 --- a/test/test_connect_destroy.c +++ b/test/test_connect_destroy.c @@ -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; diff --git a/test/test_issue373.c b/test/test_issue373.c index 1d516ca9..342c42eb 100644 --- a/test/test_issue373.c +++ b/test/test_issue373.c @@ -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); diff --git a/test/test_persistence.c b/test/test_persistence.c index f8d82f69..dd2d1639 100644 --- a/test/test_persistence.c +++ b/test/test_persistence.c @@ -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); diff --git a/test/thread.c b/test/thread.c index 9e6de963..b405ff57 100644 --- a/test/thread.c +++ b/test/thread.c @@ -323,7 +323,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; @@ -494,7 +494,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 */ From 05e6d71f6f98ebb49f69cbf8d7d99fb640c3927c Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Mon, 13 Jan 2025 09:43:49 -0500 Subject: [PATCH 02/17] Fixed condition variable timed wait. Updated thread test for current implementation. --- src/Thread.c | 25 +++++++++++++++---------- test/thread.c | 22 ++++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Thread.c b/src/Thread.c index f4d43fb6..f8b5279f 100644 --- a/src/Thread.c +++ b/src/Thread.c @@ -51,6 +51,8 @@ #include "OsWrapper.h" +#define NSEC_PER_SEC 1000000000L + /** * Start a new thread * @param fn the function to run, must be of the correct signature @@ -443,12 +445,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 +456,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); diff --git a/test/thread.c b/test/thread.c index 9e6de963..5f91cff3 100644 --- a/test/thread.c +++ b/test/thread.c @@ -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,7 @@ 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); + assert("rc ETIMEDOUT from lock mutex", rc == ETIMEDOUT || rc == EAGAIN, "rc was %d", rc); MyLog(LOGA_INFO, "Lock duration was %ld", duration); assert("duration is 2s", duration >= 1500L, "duration was %ld", duration); @@ -310,7 +314,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); @@ -333,10 +337,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 +374,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 +393,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); From bba72469721fd3c7628fda61e3081f802fe73907 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Mon, 17 Feb 2025 18:51:13 +0000 Subject: [PATCH 03/17] Ensure argument for isprint and isxdigit is in the correct range #1565 --- src/MQTTPacket.c | 4 ++-- src/MQTTVersion.c | 4 ++-- src/Proxy.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MQTTPacket.c b/src/MQTTPacket.c index 40cb4d41..a67c9204 100644 --- a/src/MQTTPacket.c +++ b/src/MQTTPacket.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2024 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 @@ -860,7 +860,7 @@ int MQTTPacket_formatPayload(int buflen, char* buf, int payloadlen, char* payloa for (i = 0; i < payloadlen; i++) { - if (isprint(payload[i])) + if (isprint((unsigned char)payload[i])) { if (pos >= buflen) break; diff --git a/src/MQTTVersion.c b/src/MQTTVersion.c index 92cd020c..bba9708d 100644 --- a/src/MQTTVersion.c +++ b/src/MQTTVersion.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2020 IBM Corp. + * Copyright (c) 2012, 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 @@ -96,7 +96,7 @@ char* FindString(char* filename, const char* eyecatcher_input) char* ptr = value; c = fgetc(infile); /* skip space */ c = fgetc(infile); - while (isprint(c)) + while (isprint((unsigned char)c)) { *ptr++ = c; c = fgetc(infile); diff --git a/src/Proxy.c b/src/Proxy.c index bb9ad682..60769f59 100644 --- a/src/Proxy.c +++ b/src/Proxy.c @@ -272,7 +272,7 @@ void Proxy_specialChars(char* p0, char* p1, b64_size_t *basic_auth_in_len) { *p0++ = *p1++; } - else if (isxdigit(*(p1 + 1)) && isxdigit(*(p1 + 2))) + else if (isxdigit((unsigned char)*(p1 + 1)) && isxdigit((unsigned char)*(p1 + 2))) { /* next 2 characters are hexa digits */ char hex[3]; @@ -350,4 +350,4 @@ int Proxy_setHTTPProxy(Clients* aClient, char* source, char** dest, char** auth_ } exit: return rc; -} \ No newline at end of file +} From 98af657f696a687dbc13129b5e9eb298d42f8267 Mon Sep 17 00:00:00 2001 From: Chris Ward Date: Wed, 19 Feb 2025 04:51:30 -0500 Subject: [PATCH 04/17] Updated getaddrinfo's hints struct to use AI_ADDRCONFIG to support IPv6 address resolutions Signed-off-by: Chris Ward --- src/Socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket.c b/src/Socket.c index ff366578..fa224cfb 100644 --- a/src/Socket.c +++ b/src/Socket.c @@ -1146,7 +1146,7 @@ int Socket_new(const char* addr, size_t addr_len, int port, SOCKET* sock) 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; From 0f21ce21d9325419dd4739af4e4845ffa62ceef6 Mon Sep 17 00:00:00 2001 From: Konstantin Tyurin Date: Fri, 4 Apr 2025 20:15:46 +0200 Subject: [PATCH 05/17] Support tls:// prefix Signed-off-by: Konstantin Tyurin --- src/MQTTAsync.c | 6 ++++++ src/MQTTAsyncUtils.c | 10 ++++++++++ src/MQTTClient.c | 17 +++++++++++++++++ src/SSLSocket.h | 9 +++++---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index c548ae31..6b6d96c6 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -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); diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c index c084a11e..7c203d63 100644 --- a/src/MQTTAsyncUtils.c +++ b/src/MQTTAsyncUtils.c @@ -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); @@ -2888,6 +2893,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); diff --git a/src/MQTTClient.c b/src/MQTTClient.c index 32d59c3b..eb3ab5a2 100644 --- a/src/MQTTClient.c +++ b/src/MQTTClient.c @@ -71,6 +71,7 @@ #include #else #define URI_SSL "ssl://" +#define URI_TLS "tls://" #define URI_MQTTS "mqtts://" #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) @@ -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); diff --git a/src/SSLSocket.h b/src/SSLSocket.h index 2e804cec..5a42be01 100644 --- a/src/SSLSocket.h +++ b/src/SSLSocket.h @@ -3,15 +3,15 @@ * * 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 *******************************************************************************/ @@ -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) */ From 9ef8f4d865657434ff36b24af2b8980c942bacaa Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Tue, 6 May 2025 15:36:26 +0100 Subject: [PATCH 06/17] Put MQTT 5 reason code into the connect failure reason code field #1596 --- src/MQTTAsyncUtils.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c index c084a11e..d8315514 100644 --- a/src/MQTTAsyncUtils.c +++ b/src/MQTTAsyncUtils.c @@ -1703,7 +1703,15 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message) MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer; data.token = 0; - data.code = rc; + if (rc > 0) /* MQTT Reason Codes are > 0; C client return codes are < 0 */ + { + /* MQTT 5 reason codes >= 0x00 and < 0x80 are successful, + * but in that case we should not get here but be calling + * onSuccess instead. */ + data.reasonCode = rc; + data.code = MQTTASYNC_FAILURE; + } else + data.code = rc; data.message = message; Log(TRACE_MIN, -1, "Calling connect failure for client %s", m->c->clientID); (*(m->connect.onFailure5))(m->connect.context, &data); From 9ff08fa5a78f4fd378244ea7e2f30b24298d61c8 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Wed, 14 May 2025 17:56:02 -0400 Subject: [PATCH 07/17] #1576 Changed 'bool' typedef to 'bit' --- src/MQTTPacket.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/MQTTPacket.h b/src/MQTTPacket.h index fd384ae9..04c217ef 100644 --- a/src/MQTTPacket.h +++ b/src/MQTTPacket.h @@ -28,7 +28,7 @@ #include "LinkedList.h" #include "Clients.h" -typedef unsigned int bool; +typedef unsigned int bit; typedef void* (*pf)(int, unsigned char, char*, size_t); #include "MQTTProperties.h" @@ -67,16 +67,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 @@ -95,24 +95,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 */ @@ -140,12 +140,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 From cd28c9870084407730c31e9e5a5cf434c2419f90 Mon Sep 17 00:00:00 2001 From: Ian Craggs <10279016+icraggs@users.noreply.github.com> Date: Thu, 14 Aug 2025 13:54:01 +0100 Subject: [PATCH 08/17] Update Thread.c - fix MacOS build warning --- src/Thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Thread.c b/src/Thread.c index f8b5279f..28b410aa 100644 --- a/src/Thread.c +++ b/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 @@ -51,7 +51,9 @@ #include "OsWrapper.h" +#if !defined(NSEC_PER_SEC) #define NSEC_PER_SEC 1000000000L +#endif /** * Start a new thread From 8e0029a5b6dbbbac26337a210152796cf4e373ee Mon Sep 17 00:00:00 2001 From: Ian Craggs <10279016+icraggs@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:09:45 +0100 Subject: [PATCH 09/17] Update thread.c - fix Windows build where EAGAIN is not defined --- test/thread.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/thread.c b/test/thread.c index 5f91cff3..f9089c68 100644 --- a/test/thread.c +++ b/test/thread.c @@ -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 @@ -304,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 == EAGAIN, "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); From 106cb1eadf183ffcd5de03fb0f2962889fda50cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ondr=C3=A1=C4=8Dek?= Date: Thu, 30 Jan 2025 03:00:45 +0100 Subject: [PATCH 10/17] Fix build on GNU Hurd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roman Ondráček --- src/SHA1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SHA1.c b/src/SHA1.c index 98fcc443..5c4c3496 100644 --- a/src/SHA1.c +++ b/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 @@ -51,9 +51,8 @@ int SHA1_Final(unsigned char *md, SHA_CTX *c) CryptReleaseContext(c->hProv, 0); return rv; } - #else /* if defined(_WIN32) */ -#if defined(__linux__) || defined(__CYGWIN__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) # include #elif defined(__APPLE__) # include From 9c0f42165383525dc9295a625201264262b84bbf Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 15 Aug 2025 14:08:02 +0100 Subject: [PATCH 11/17] Change mqtt.eclipseprojects.io to test.mosquitto.org --- src/MQTTAsync.h | 4 ++-- src/MQTTClient.h | 6 +++--- src/samples/MQTTAsync_publish.c | 4 ++-- src/samples/MQTTAsync_subscribe.c | 4 ++-- src/samples/MQTTClient_publish.c | 4 ++-- src/samples/MQTTClient_publish_async.c | 4 ++-- src/samples/MQTTClient_subscribe.c | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/MQTTAsync.h b/src/MQTTAsync.h index 7c5b6214..52106698 100644 --- a/src/MQTTAsync.h +++ b/src/MQTTAsync.h @@ -1928,7 +1928,7 @@ LIBMQTT_API const char* MQTTAsync_strerror(int code); #include #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 #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!" diff --git a/src/MQTTClient.h b/src/MQTTClient.h index c8a4de35..bfc74d9e 100644 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -1624,7 +1624,7 @@ LIBMQTT_API const char* MQTTClient_strerror(int code); #include #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 #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 #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!" diff --git a/src/samples/MQTTAsync_publish.c b/src/samples/MQTTAsync_publish.c index 0a4a4c6d..83c6f51f 100644 --- a/src/samples/MQTTAsync_publish.c +++ b/src/samples/MQTTAsync_publish.c @@ -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 #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!" diff --git a/src/samples/MQTTAsync_subscribe.c b/src/samples/MQTTAsync_subscribe.c index 29a504e3..39344f03 100644 --- a/src/samples/MQTTAsync_subscribe.c +++ b/src/samples/MQTTAsync_subscribe.c @@ -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 #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!" diff --git a/src/samples/MQTTClient_publish.c b/src/samples/MQTTClient_publish.c index 0cf088d5..e739136f 100644 --- a/src/samples/MQTTClient_publish.c +++ b/src/samples/MQTTClient_publish.c @@ -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 #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!" diff --git a/src/samples/MQTTClient_publish_async.c b/src/samples/MQTTClient_publish_async.c index 1e2b50cd..03a01c26 100644 --- a/src/samples/MQTTClient_publish_async.c +++ b/src/samples/MQTTClient_publish_async.c @@ -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 #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!" diff --git a/src/samples/MQTTClient_subscribe.c b/src/samples/MQTTClient_subscribe.c index 1905eb3d..77268834 100644 --- a/src/samples/MQTTClient_subscribe.c +++ b/src/samples/MQTTClient_subscribe.c @@ -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 #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!" From b289797aca8d5d0a47ddf3e14dd7843959b6319c Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 15 Aug 2025 15:55:00 +0100 Subject: [PATCH 12/17] Add tls: prefix to docs and samples --- src/MQTTAsync.h | 4 ++-- src/MQTTClient.h | 4 ++-- src/samples/paho_c_pub.c | 4 +++- src/samples/paho_c_sub.c | 4 +++- src/samples/paho_cs_pub.c | 4 +++- src/samples/paho_cs_sub.c | 4 +++- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/MQTTAsync.h b/src/MQTTAsync.h index 52106698..3d7dffd2 100644 --- a/src/MQTTAsync.h +++ b/src/MQTTAsync.h @@ -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 diff --git a/src/MQTTClient.h b/src/MQTTClient.h index bfc74d9e..1713b03c 100644 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -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 diff --git a/src/samples/paho_c_pub.c b/src/samples/paho_c_pub.c index e891ef88..72b2ab8a 100644 --- a/src/samples/paho_c_pub.c +++ b/src/samples/paho_c_pub.c @@ -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) diff --git a/src/samples/paho_c_sub.c b/src/samples/paho_c_sub.c index 85875c99..ddf42491 100644 --- a/src/samples/paho_c_sub.c +++ b/src/samples/paho_c_sub.c @@ -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; diff --git a/src/samples/paho_cs_pub.c b/src/samples/paho_cs_pub.c index 1fce350a..94bfdb27 100644 --- a/src/samples/paho_cs_pub.c +++ b/src/samples/paho_cs_pub.c @@ -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) diff --git a/src/samples/paho_cs_sub.c b/src/samples/paho_cs_sub.c index 39207376..c877bd2c 100644 --- a/src/samples/paho_cs_sub.c +++ b/src/samples/paho_cs_sub.c @@ -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) From 7a7519c9f600e12c48d5acf5d9fefd35bc3bf113 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 15 Aug 2025 17:04:31 +0100 Subject: [PATCH 13/17] Add tls: test --- test/test3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test3.c b/test/test3.c index 5987d162..5192b6ad 100644 --- a/test/test3.c +++ b/test/test3.c @@ -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", From 71fb9571bce9fbe2ecbc1b55dfe52d08515311d6 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 15 Aug 2025 17:41:14 +0100 Subject: [PATCH 14/17] Check for TLS use in serverURIs if there are no TLS options #1566 --- src/MQTTAsync.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index a3dfc840..3f310e40 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -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 @@ -589,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 */ From beb04516a0ec2e4fcb16d5baba9c8310c2b0a334 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 15 Aug 2025 17:55:34 +0100 Subject: [PATCH 15/17] Change must to must not call publish within message arrived callback #1598 --- src/MQTTClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MQTTClient.h b/src/MQTTClient.h index 1713b03c..7b3f5725 100644 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -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 * MQTTAsync API. * From 515e93eefc97ac9965e4cc625111f55a9fc49150 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Sat, 16 Aug 2025 12:07:54 +0100 Subject: [PATCH 16/17] Update version numbers to 1.3.15 --- .github/workflows/artifact_linux.yml | 4 ++-- .github/workflows/artifact_macos.yml | 4 ++-- CMakeLists.txt | 2 +- src/MQTTAsync.h | 2 +- src/MQTTClient.h | 2 +- version.patch | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/artifact_linux.yml b/.github/workflows/artifact_linux.yml index 7fbc2744..9d63a6e2 100644 --- a/.github/workflows/artifact_linux.yml +++ b/.github/workflows/artifact_linux.yml @@ -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 diff --git a/.github/workflows/artifact_macos.yml b/.github/workflows/artifact_macos.yml index a61af0a9..32cba275 100644 --- a/.github/workflows/artifact_macos.yml +++ b/.github/workflows/artifact_macos.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ef145cd9..c9fc5928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 3.5) project("Eclipse Paho C" - VERSION 1.3.14 + VERSION 1.3.15 LANGUAGES C ) diff --git a/src/MQTTAsync.h b/src/MQTTAsync.h index 3d7dffd2..e0de3449 100644 --- a/src/MQTTAsync.h +++ b/src/MQTTAsync.h @@ -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 diff --git a/src/MQTTClient.h b/src/MQTTClient.h index 7b3f5725..8d4978bf 100644 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -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 diff --git a/version.patch b/version.patch index 8351c193..60d3b2f4 100644 --- a/version.patch +++ b/version.patch @@ -1 +1 @@ -14 +15 From 00afad8fc9a7cebf45261e32916da7511ad2934c Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Sat, 16 Aug 2025 13:32:23 +0100 Subject: [PATCH 17/17] Remove newline from version.patch --- version.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.patch b/version.patch index 60d3b2f4..3f10ffe7 100644 --- a/version.patch +++ b/version.patch @@ -1 +1 @@ -15 +15 \ No newline at end of file