From 8fc1c1e07f745beb14d3b30db704f7c0712cf339 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 11 Jul 2025 00:39:56 +0100 Subject: [PATCH] Various fixes Dashboard include paths Libcommon.so not being installed snacraft packaging update http-api able to use compile time definition --- dashboard/src/consts.js | 4 +- dashboard/src/index.html | 6 +-- libcommon/Makefile | 3 ++ snap/snapcraft.yaml | 82 +++++++++++++-------------------- src/http_api.c | 39 ++++++++++++++-- src/listeners.c | 2 +- src/mosquitto_broker_internal.h | 1 + 7 files changed, 78 insertions(+), 59 deletions(-) diff --git a/dashboard/src/consts.js b/dashboard/src/consts.js index 136cc37e..15a922ae 100644 --- a/dashboard/src/consts.js +++ b/dashboard/src/consts.js @@ -14,6 +14,6 @@ const SMOOTHED_CHART_UPDATE_INTERVAL_IN_MILLISECONDS = 5; // 5 minutes const INTERVAL_5SECS_IN_MILLISECONDS = 1000 * 5; const CHARTJS_ANIMATION_DURATION_MS = 400; -const SYSTOPIC_ENDPOINT = "/api/systree"; -const LISTENERS_ENDPOINT = "/api/listeners"; +const SYSTOPIC_ENDPOINT = "/api/v1/systree"; +const LISTENERS_ENDPOINT = "/api/v1/listeners"; const CHART_DISPLAY_WINDOW = 16; diff --git a/dashboard/src/index.html b/dashboard/src/index.html index 754df49e..657ce8fc 100644 --- a/dashboard/src/index.html +++ b/dashboard/src/index.html @@ -696,9 +696,9 @@ - - - + + + diff --git a/libcommon/Makefile b/libcommon/Makefile index 23167638..d0a467af 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -44,6 +44,9 @@ OBJS= \ all : libmosquitto_common.a libmosquitto_common.so.${SOVERSION} install : + $(INSTALL) -d "${DESTDIR}${libdir}/" + $(INSTALL) ${STRIP_OPTS} libmosquitto_common.so.${SOVERSION} "${DESTDIR}${libdir}/libmosquitto_common.so.${SOVERSION}" + ln -sf libmosquitto_common.so.${SOVERSION} "${DESTDIR}${libdir}/libmosquitto_common.so" uninstall : diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d6559801..f7f388dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -10,7 +10,7 @@ description: This is a message broker that supports version 5.0, 3.1.1, and 3.1 example. confinement: strict grade: stable -base: core20 +base: core24 apps: mosquitto: @@ -31,6 +31,10 @@ apps: command: usr/bin/mosquitto_rr plugs: [home, network] + signal: + command: usr/bin/mosquitto_signal + plugs: [home, network] + sub: command: usr/bin/mosquitto_sub plugs: [home, network] @@ -53,78 +57,58 @@ parts: prime: - mosquitto.conf + dashboard: + plugin: dump + source: dashboard/src + organize: + '*': dashboard/ mosquitto: - after: - - lws plugin: make make-parameters: - prefix=/usr - - WITH_WEBSOCKETS=lws - WITH_ADNS=yes - - CFLAGS="-Wall -ggdb -O2 -I$SNAPCRAFT_STAGE/usr/include -D_GNU_SOURCE" - source: https://github.com/eclipse/mosquitto + - CFLAGS="-Wall -ggdb -O3 -I$SNAPCRAFT_STAGE/usr/include" + source: https://github.com/eclipse-mosquitto/mosquitto source-type: git + source-branch: develop build-packages: + - docbook-xsl + - g++ + - gcc + - libcjson-dev + - libedit-dev + - libmicrohttpd-dev + - libsqlite3-dev - libssl-dev - xsltproc - - docbook-xsl - - gcc - - g++ stage-packages: - - libssl1.1 - ca-certificates + - libcjson1 + - libmicrohttpd12t64 + - libssl3t64 prime: - usr/sbin/mosquitto - usr/bin/mosquitto_ctrl - usr/bin/mosquitto_pub - usr/bin/mosquitto_rr + - usr/bin/mosquitto_signal - usr/bin/mosquitto_sub - usr/bin/mosquitto_passwd - usr/lib/libmosquitto.so* + - usr/lib/libmosquitto_common.so* + - usr/lib/mosquitto_acl_file.so* - usr/lib/mosquitto_dynamic_security.so* - - lib/*-linux-gnu/libcrypto.so* - - lib/*-linux-gnu/libssl.so* + - usr/lib/mosquitto_password_file.so* + - usr/lib/mosquitto_persist_sqlite.so* + - usr/lib/mosquitto_sparkplug_aware.so* + - usr/lib/*-linux-gnu/libcjson.so* + - usr/lib/*-linux-gnu/libcrypto.so* + - usr/lib/*-linux-gnu/libmicrohttpd.so* + - usr/lib/*-linux-gnu/libssl.so* - usr/include/mosquitto.h - usr/include/mosquitto_broker.h - usr/include/mosquitto_plugin.h - usr/include/mqtt_protocol.h - usr/include/mosquitto/*.h - - lws: - after: - - cjson - plugin: cmake - cmake-parameters: - - -DCMAKE_INSTALL_PREFIX=/usr - - -DLWS_IPV6=ON - - -DLWS_WITHOUT_CLIENT=ON - - -DLWS_WITHOUT_EXTENSIONS=ON - - -DLWS_WITH_ZIP_FOPS=OFF - - -DLWS_WITH_ZLIB=OFF - - -DLWS_WITH_SHARED=OFF - source: https://github.com/warmcat/libwebsockets/archive/v2.4.2.tar.gz - source-type: tar - stage: - - usr/include/libwebsockets.h - - usr/include/lws_config.h - - usr/lib/libwebsockets.a - prime: [-*] - - cjson: - plugin: cmake - cmake-parameters: - - -DCMAKE_INSTALL_PREFIX=/usr - - -DCMAKE_C_FLAGS=-fPIC - - -DBUILD_SHARED_AND_STATIC_LIBS=OFF - - -DBUILD_SHARED_LIBS=OFF - - -DCJSON_BUILD_SHARED_LIBS=OFF - - -DCJSON_OVERRIDE_BUILD_SHARED_LIBS=OFF - - -DENABLE_CJSON_TEST=OFF - source: https://github.com/DaveGamble/cJSON/archive/v1.7.14.tar.gz - source-type: tar - stage: - - usr/include/cjson/cJSON.h - - usr/lib/libcjson.a - prime: [-*] diff --git a/src/http_api.c b/src/http_api.c index 3dd78c04..00f78c84 100644 --- a/src/http_api.c +++ b/src/http_api.c @@ -31,6 +31,10 @@ Contributors: #ifdef WITH_HTTP_API +#ifndef HTTP_API_DIR +# define HTTP_API_DIR "" +#endif + struct metric{ int64_t current; int64_t next; @@ -337,10 +341,35 @@ static enum MHD_Result http_api_handler(void *cls, struct MHD_Connection } +int http_api__start_local(struct mosquitto__listener *listener) +{ + listener->host = mosquitto_strdup("127.0.0.1"); + if(!listener->host){ + return MOSQ_ERR_NOMEM; + } + listener->port = 9883; + + if(listener->http_dir == NULL && strlen(HTTP_API_DIR) > 1){ +#ifdef WIN32 + char *http_dir_canonical = _fullpath(NULL, HTTP_API_DIR, 0); +#else + char *http_dir_canonical = realpath(HTTP_API_DIR, NULL); +#endif + if(!http_dir_canonical){ + return MOSQ_ERR_NOMEM; + } + mosquitto_FREE(listener->http_dir); + listener->http_dir = mosquitto_strdup(http_dir_canonical); + mosquitto_FREE(http_dir_canonical); + } + + return http_api__start(listener); +} + int http_api__start(struct mosquitto__listener *listener) { unsigned int flags = MHD_USE_AUTO_INTERNAL_THREAD; - const char *bind_address = "127.0.0.1"; + const char *bind_address; uint16_t port = 9883; char *x509_cert = NULL; char *x509_key = NULL; @@ -352,11 +381,10 @@ int http_api__start(struct mosquitto__listener *listener) } } listener->security_options->allow_anonymous = true; + listener->protocol = mp_http_api; bind_address = listener->host; - if(listener->port){ - port = listener->port; - } + port = listener->port; if(listener->certfile && listener->keyfile){ if(mosquitto_read_file(listener->certfile, &x509_cert)){ @@ -426,6 +454,9 @@ int http_api__start(struct mosquitto__listener *listener) if(listener->mhd){ log__printf(NULL, MOSQ_LOG_INFO, "Opening http api listen socket on port %d.", port); + if(listener->http_dir){ + log__printf(NULL, MOSQ_LOG_INFO, "Using http_dir %s", listener->http_dir); + } return MOSQ_ERR_SUCCESS; }else{ return MOSQ_ERR_UNKNOWN; diff --git a/src/listeners.c b/src/listeners.c index 6a2df04d..5ab447e8 100644 --- a/src/listeners.c +++ b/src/listeners.c @@ -224,7 +224,7 @@ static int listeners__start_local_only(void) if(db.config->listener_count > 0){ #ifdef WITH_HTTP_API db.config->listener_count++; - http_api__start(&db.config->listeners[db.config->listener_count-1]); + http_api__start_local(&db.config->listeners[db.config->listener_count-1]); #endif return MOSQ_ERR_SUCCESS; }else{ diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 66d249b5..a5d234dd 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -987,6 +987,7 @@ void will_delay__remove(struct mosquitto *mosq); /* ============================================================ * HTTP Info * ============================================================ */ +int http_api__start_local(struct mosquitto__listener *listener); int http_api__start(struct mosquitto__listener *listener); void http_api__stop(struct mosquitto__listener *listener);