From 220949d94d1bc461f87f4163cc8f248641407af2 Mon Sep 17 00:00:00 2001 From: Dominik Kuhn Date: Fri, 23 Aug 2024 10:24:25 +0200 Subject: [PATCH] building release type --- CMakeSettings.json | 11 +++++--- plugins/wamo/CMakeLists.txt | 52 ++++++++++++++++++------------------- plugins/wamo/json_help.c | 9 ++++--- plugins/wamo/wamo.c | 23 +++++++--------- 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index d0d6a43a..cb4204ec 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,10 +1,10 @@ { "configurations": [ { - "name": "x64-Debug", + "name": "x64-Release", "generator": "Ninja", - "configurationType": "Debug", - "inheritEnvironments": [ "clang_cl_x64" ], + "configurationType": "Release", + "inheritEnvironments": [ "msvc_x64" ], "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeCommandArgs": "", @@ -53,6 +53,11 @@ }, { "name": "WITH_STATIC_LIBRARIES", + "value": "True", + "type": "BOOL" + }, + { + "name": "WITH_LIB_CPP", "value": "False", "type": "BOOL" } diff --git a/plugins/wamo/CMakeLists.txt b/plugins/wamo/CMakeLists.txt index aa6f5953..6a81fbd8 100644 --- a/plugins/wamo/CMakeLists.txt +++ b/plugins/wamo/CMakeLists.txt @@ -18,37 +18,37 @@ if (CJSON_FOUND ) add_definitions("-DWITH_CJSON") - set( CLIENT_INC ${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH} ${mosquitto_SOURCE_DIR}/deps - ${mosquitto_SOURCE_DIR}/src ${CJSON_INCLUDE_DIRS} ) + set (MOSQUITTO_IDIR "" CACHE FILEPATH "C:/Program Files/mosquitto/devel/" ) + set (MOSQUITTO_LIBRARIES "" CACHE FILEPATH "C:/Program Files/mosquitto/devel/") + set (PLUGIN_NAME wamo) - set( CLIENT_DIR ${mosquitto_BINARY_DIR}/lib ${CJSON_DIR}) - - include_directories(${CLIENT_INC}) - link_directories(${CLIENT_DIR} ${mosquitto_SOURCE_DIR}) - - add_library(wamo MODULE + add_library(${PLUGIN_NAME} MODULE + ${PLUGIN_NAME}.c json_help.c json_help.h - wamo.c) - - set_target_properties(wamo PROPERTIES + ) + + target_include_directories(${PLUGIN_NAME} PRIVATE + "${CJSON_INCLUDE_DIRS}" + "${STDBOOL_H_PATH} ${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "C:/Program Files/mosquitto/devel/" + ) + + target_link_directories(${PLUGIN_NAME} PRIVATE ${MOSQUITTO_LIBRARIES} ) + + set_target_properties(${PLUGIN_NAME} PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) - set_target_properties(wamo PROPERTIES PREFIX "") - set_target_properties(wamo PROPERTIES IMPORTED_IMPLIB ${CJSON_LIBRARIES}) - target_link_libraries(wamo ${CJSON_LIBRARIES}) + set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "") + set_target_properties(${PLUGIN_NAME} PROPERTIES IMPORTED_IMPLIB ${CJSON_LIBRARIES}) + + target_link_libraries(${PLUGIN_NAME} PRIVATE ${CJSON_LIBRARIES}) + if(WIN32) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - set_target_properties(wamo PROPERTIES IMPORTED_IMPLIB mosquitto) - target_link_libraries(wamo mosquitto) - install(TARGETS wamo - DESTINATION "${CMAKE_INSTALL_BINDIR}") - else() - install(TARGETS wamo - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") - endif() + target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) + endif() -endif() +endif() \ No newline at end of file diff --git a/plugins/wamo/json_help.c b/plugins/wamo/json_help.c index 8c06a898..d7c02922 100644 --- a/plugins/wamo/json_help.c +++ b/plugins/wamo/json_help.c @@ -71,22 +71,23 @@ int json_del_id_from_array(cJSON* json, const char* name, const char* id) jtmp = cJSON_GetObjectItem(json, name); if (jtmp) { - mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 1"); + // mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 1"); if (cJSON_IsArray(jtmp) == true) { // cJSON_DeleteItemFromObject(json, name); - mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 2"); + // mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 2"); cJSON_ArrayForEach(tid, jtmp) { if ( strcmp( cJSON_GetStringValue(tid),id) == 0) { - mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 3"); + // mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 3"); detached_item = cJSON_DetachItemFromArray(jtmp, array_index); } else { - mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 4"); + return MOSQ_ERR_INVAL; + // mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: deleting item from array .. debug 4"); } array_index++; } diff --git a/plugins/wamo/wamo.c b/plugins/wamo/wamo.c index b71b57c4..b0cd24df 100644 --- a/plugins/wamo/wamo.c +++ b/plugins/wamo/wamo.c @@ -51,9 +51,7 @@ static cJSON* subscribedTopics = NULL; static int callback_control(int event, void* event_data, void* userdata) { struct mosquitto_evt_acl_check* ed = event_data; - char* payload = NULL; - uint32_t payload_len; - + UNUSED(event); UNUSED(userdata); @@ -67,38 +65,37 @@ static int callback_control(int event, void* event_data, void* userdata) json_create_array(subscribedTopics, topic); json_add_id_to_array(subscribedTopics, topic, client_id); char* json_string = cJSON_Print(subscribedTopics); - payload = cJSON_PrintUnformatted(subscribedTopics); + char* payload = cJSON_PrintUnformatted(subscribedTopics); mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: client with id %s subscribed to topic %s", client_id, topic); mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: subscribed topics %s", json_string); if (payload == NULL) return MOSQ_ERR_MALFORMED_PACKET; - payload_len = strlen(payload); + uint32_t payload_len = strlen(payload); if (payload_len > MQTT_MAX_PAYLOAD) { free(payload); return MOSQ_ERR_PAYLOAD_SIZE; } - mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: DEBUG MESSAGE BEFORE PUBLISHING ..."); - - mosquitto_broker_publish(NULL, "mqtt/subscriptions", - (int)payload_len, payload, 0, true, NULL); + + mosquitto_broker_publish_copy(NULL, "mqtt/subscriptions", + (int)payload_len, payload, 0, 0, NULL); } else if (access == MOSQ_ACL_UNSUBSCRIBE) { json_del_id_from_array(subscribedTopics, topic, client_id); char* json_string = cJSON_Print(subscribedTopics); - payload = cJSON_PrintUnformatted(subscribedTopics); + char* payload = cJSON_PrintUnformatted(subscribedTopics); mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: client with id %s unscribed to topic %s", client_id, topic); mosquitto_log_printf(MOSQ_LOG_INFO, "wamo: subscribed topics %s", json_string); if (payload == NULL) return MOSQ_ERR_MALFORMED_PACKET; - payload_len = strlen(payload); + uint32_t payload_len = strlen(payload); if (payload_len > MQTT_MAX_PAYLOAD) { free(payload); return MOSQ_ERR_PAYLOAD_SIZE; } - mosquitto_broker_publish(NULL, "mqtt/subscriptions", - (int)payload_len, payload, 0, true, NULL); + mosquitto_broker_publish_copy(NULL, "mqtt/subscriptions", + (int)payload_len, payload, 0, 0, NULL); }