From c17c6a9028420e18882b1b848acb6180759a7056 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 25 Mar 2021 15:51:14 +0000 Subject: [PATCH] Move example plugins to their own directory. --- plugins/CMakeLists.txt | 5 +-- plugins/Makefile | 5 +-- plugins/README.md | 42 ++++++++++++++----- plugins/examples/CMakeLists.txt | 8 ++++ plugins/examples/Makefile | 31 ++++++++++++++ .../examples/add-properties/CMakeLists.txt | 11 +++++ .../add-properties}/Makefile | 5 ++- .../mosquitto_add_properties.c} | 0 .../{ => examples}/auth-by-ip/CMakeLists.txt | 0 plugins/{ => examples}/auth-by-ip/Makefile | 3 +- .../auth-by-ip/mosquitto_auth_by_ip.c | 0 .../examples/client-properties/CMakeLists.txt | 15 +++++++ plugins/examples/client-properties/Makefile | 28 +++++++++++++ .../mosquitto_client_properties.c} | 0 .../connection-state/CMakeLists.txt | 0 .../{ => examples}/connection-state/Makefile | 3 +- .../mosquitto_connection_state.c | 0 .../message-timestamp}/CMakeLists.txt | 0 .../{ => examples}/message-timestamp/Makefile | 3 +- .../mosquitto_message_timestamp.c | 0 .../payload-modification/CMakeLists.txt | 0 .../payload-modification/Makefile | 3 +- .../mosquitto_payload_modification.c | 0 plugins/message-timestamp/CMakeLists.txt | 11 ----- plugins/printf-example/CMakeLists.txt | 15 ------- plugins/printf-example/Makefile | 27 ------------ 26 files changed, 137 insertions(+), 78 deletions(-) create mode 100644 plugins/examples/CMakeLists.txt create mode 100644 plugins/examples/Makefile create mode 100644 plugins/examples/add-properties/CMakeLists.txt rename plugins/{add-user-properties => examples/add-properties}/Makefile (84%) rename plugins/{add-user-properties/add_properties.c => examples/add-properties/mosquitto_add_properties.c} (100%) rename plugins/{ => examples}/auth-by-ip/CMakeLists.txt (100%) rename plugins/{ => examples}/auth-by-ip/Makefile (89%) rename plugins/{ => examples}/auth-by-ip/mosquitto_auth_by_ip.c (100%) create mode 100644 plugins/examples/client-properties/CMakeLists.txt create mode 100644 plugins/examples/client-properties/Makefile rename plugins/{printf-example/printf_example.c => examples/client-properties/mosquitto_client_properties.c} (100%) rename plugins/{ => examples}/connection-state/CMakeLists.txt (100%) rename plugins/{ => examples}/connection-state/Makefile (89%) rename plugins/{ => examples}/connection-state/mosquitto_connection_state.c (100%) rename plugins/{add-user-properties => examples/message-timestamp}/CMakeLists.txt (100%) rename plugins/{ => examples}/message-timestamp/Makefile (89%) rename plugins/{ => examples}/message-timestamp/mosquitto_message_timestamp.c (100%) rename plugins/{ => examples}/payload-modification/CMakeLists.txt (100%) rename plugins/{ => examples}/payload-modification/Makefile (89%) rename plugins/{ => examples}/payload-modification/mosquitto_payload_modification.c (100%) delete mode 100644 plugins/message-timestamp/CMakeLists.txt delete mode 100644 plugins/printf-example/CMakeLists.txt delete mode 100644 plugins/printf-example/Makefile diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c9aa03df..1987ddce 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,5 +1,2 @@ add_subdirectory(dynamic-security) -if(NOT WIN32) - add_subdirectory(message-timestamp) -endif(NOT WIN32) -add_subdirectory(payload-modification) +add_subdirectory(examples) diff --git a/plugins/Makefile b/plugins/Makefile index a84288f1..4e01d1ab 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1,9 +1,6 @@ DIRS= \ - auth-by-ip \ - connection-state \ dynamic-security \ - message-timestamp \ - payload-modification + examples .PHONY : all binary check clean reallyclean test install uninstall diff --git a/plugins/README.md b/plugins/README.md index 5636737f..6c63c915 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -7,23 +7,43 @@ This is a fully functioning plugin that implements authentication and access control, with configuration via a $CONTROL topic. See the readme in dynamic-security for more information. -## Connection state +## Examples / Add properties +This is an **example** plugin that demonstrates adding MQTT v5 properties to +messages, and how to get client information. + +## Examples / Authenticate by IP address +This is an **example** plugin that demonstrates a basic authentication callback +that allows clients based on their IP address. Password based authentication is +preferred over this very simple type of access control. + +## Examples / Client properties +This is an **example** plugin that demonstrates some of the functions for +retrieving client information such as client id and username. + +## Examples / Connection state This is an **example** plugin to demonstrate the use of the connect and disconnect events. It publishes messages to $SYS/broker/connection/client//state for every client that connects to the broker, to indicate the connection state of that client. -## Message timestamp -This is an **example** plugin to demonstrate how it is possible to attach MQTT v5 properties to messages after they have been received, and before they are sent on to subscribers. - -This plugin attaches a user-property property to each message which contains the ISO-8601 timestamp of the time the message was received by the broker. This means it is possible for MQTT v5 clients to see how old a retained message is, for example. +## Examples / Message timestamp +This is an **example** plugin to demonstrate how it is possible to attach MQTT +v5 properties to messages after they have been received, and before they are +sent on to subscribers. -## Payload modification -This is an **example** plugin to demonstrate how it is possible to modify the payload of messages after they have been received, and before they are sent on to subscribers. +This plugin attaches a user-property property to each message which contains +the ISO-8601 timestamp of the time the message was received by the broker. This +means it is possible for MQTT v5 clients to see how old a retained message is, +for example. -If you are considering using this feature, you should be very certain you have verified the payload is the correct format before modifying it. +## Examples / Payload modification +This is an **example** plugin to demonstrate how it is possible to modify the +payload of messages after they have been received, and before they are sent on +to subscribers. -This plugin adds the text string "hello " to the beginning of each payload, so with anything other than simple plain text messages it will corrupt the payload contents. +If you are considering using this feature, you should be very certain you have +verified the payload is the correct format before modifying it. -## Authenticate by IP address -This is an **example** plugin that demonstrates a basic authentication callback that allows clients based on their IP address. Password based authentication is preferred over this very simple type of access control. +This plugin adds the text string "hello " to the beginning of each payload, so +with anything other than simple plain text messages it will corrupt the payload +contents. diff --git a/plugins/examples/CMakeLists.txt b/plugins/examples/CMakeLists.txt new file mode 100644 index 00000000..67f41d84 --- /dev/null +++ b/plugins/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +if(NOT WIN32) + add_subdirectory(add-properties) + add_subdirectory(message-timestamp) +endif(NOT WIN32) +add_subdirectory(auth-by-ip) +add_subdirectory(client-properties) +add_subdirectory(connection-state) +add_subdirectory(payload-modification) diff --git a/plugins/examples/Makefile b/plugins/examples/Makefile new file mode 100644 index 00000000..9fd0e665 --- /dev/null +++ b/plugins/examples/Makefile @@ -0,0 +1,31 @@ +DIRS= \ + add-properties \ + auth-by-ip \ + client-properties \ + connection-state \ + message-timestamp \ + payload-modification + +.PHONY : all binary check clean reallyclean test install uninstall + +all : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d}; done + +binary : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done + +clean : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done + +reallyclean : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done + +check : test +test : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done + +install : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done + +uninstall : + set -e; for d in ${DIRS}; do $(MAKE) -C $${d} $@; done diff --git a/plugins/examples/add-properties/CMakeLists.txt b/plugins/examples/add-properties/CMakeLists.txt new file mode 100644 index 00000000..6e036442 --- /dev/null +++ b/plugins/examples/add-properties/CMakeLists.txt @@ -0,0 +1,11 @@ +include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include + ${STDBOOL_H_PATH} ${STDINT_H_PATH}) + +add_library(mosquitto_add_properties SHARED mosquitto_add_properties.c) +set_target_properties(mosquitto_add_properties PROPERTIES + POSITION_INDEPENDENT_CODE 1 +) +set_target_properties(mosquitto_add_properties PROPERTIES PREFIX "") + +# Don't install, these are example plugins only. +#install(TARGETS mosquitto_add_properties RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/add-user-properties/Makefile b/plugins/examples/add-properties/Makefile similarity index 84% rename from plugins/add-user-properties/Makefile rename to plugins/examples/add-properties/Makefile index a06d641f..5f29f865 100644 --- a/plugins/add-user-properties/Makefile +++ b/plugins/examples/add-properties/Makefile @@ -1,8 +1,9 @@ -include ../../config.mk +include ../../../config.mk .PHONY : all binary check clean reallyclean test install uninstall -PLUGIN_NAME=add_properties +PLUGIN_NAME=mosquitto_add_properties +PLUGIN_CFLAGS+=-I../../../include -I../../../ all : binary diff --git a/plugins/add-user-properties/add_properties.c b/plugins/examples/add-properties/mosquitto_add_properties.c similarity index 100% rename from plugins/add-user-properties/add_properties.c rename to plugins/examples/add-properties/mosquitto_add_properties.c diff --git a/plugins/auth-by-ip/CMakeLists.txt b/plugins/examples/auth-by-ip/CMakeLists.txt similarity index 100% rename from plugins/auth-by-ip/CMakeLists.txt rename to plugins/examples/auth-by-ip/CMakeLists.txt diff --git a/plugins/auth-by-ip/Makefile b/plugins/examples/auth-by-ip/Makefile similarity index 89% rename from plugins/auth-by-ip/Makefile rename to plugins/examples/auth-by-ip/Makefile index a0ffe6a6..d99b8c8a 100644 --- a/plugins/auth-by-ip/Makefile +++ b/plugins/examples/auth-by-ip/Makefile @@ -1,8 +1,9 @@ -include ../../config.mk +include ../../../config.mk .PHONY : all binary check clean reallyclean test install uninstall PLUGIN_NAME=mosquitto_auth_by_ip +PLUGIN_CFLAGS+=-I../../../include -I../../../ all : binary diff --git a/plugins/auth-by-ip/mosquitto_auth_by_ip.c b/plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c similarity index 100% rename from plugins/auth-by-ip/mosquitto_auth_by_ip.c rename to plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c diff --git a/plugins/examples/client-properties/CMakeLists.txt b/plugins/examples/client-properties/CMakeLists.txt new file mode 100644 index 00000000..3ba8a208 --- /dev/null +++ b/plugins/examples/client-properties/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include + ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +link_directories(${mosquitto_SOURCE_DIR}) + +add_library(mosquitto_client_properties SHARED mosquitto_client_properties.c) +set_target_properties(mosquitto_client_properties PROPERTIES + POSITION_INDEPENDENT_CODE 1 +) +set_target_properties(mosquitto_client_properties PROPERTIES PREFIX "") +if(WIN32) + target_link_libraries(mosquitto_client_properties mosquitto) +endif(WIN32) + +# Don't install, these are example plugins only. +#install(TARGETS mosquitto_client_properties RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/client-properties/Makefile b/plugins/examples/client-properties/Makefile new file mode 100644 index 00000000..f13d952e --- /dev/null +++ b/plugins/examples/client-properties/Makefile @@ -0,0 +1,28 @@ +include ../../../config.mk + +.PHONY : all binary check clean reallyclean test install uninstall + +PLUGIN_NAME=mosquitto_client_properties +PLUGIN_CFLAGS+=-I../../../include -I../../../ + +all : binary + +binary : ${PLUGIN_NAME}.so + +${PLUGIN_NAME}.so : ${PLUGIN_NAME}.c + $(CROSS_COMPILE)$(CC) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) $(PLUGIN_LDFLAGS) -fPIC -shared $< -o $@ + +reallyclean : clean +clean: + -rm -f *.o ${PLUGIN_NAME}.so *.gcda *.gcno + +check: test +test: + +install: ${PLUGIN_NAME}.so + # Don't install, these are examples only. + #$(INSTALL) -d "${DESTDIR}$(libdir)" + #$(INSTALL) ${STRIP_OPTS} ${PLUGIN_NAME}.so "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" + +uninstall : + -rm -f "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" diff --git a/plugins/printf-example/printf_example.c b/plugins/examples/client-properties/mosquitto_client_properties.c similarity index 100% rename from plugins/printf-example/printf_example.c rename to plugins/examples/client-properties/mosquitto_client_properties.c diff --git a/plugins/connection-state/CMakeLists.txt b/plugins/examples/connection-state/CMakeLists.txt similarity index 100% rename from plugins/connection-state/CMakeLists.txt rename to plugins/examples/connection-state/CMakeLists.txt diff --git a/plugins/connection-state/Makefile b/plugins/examples/connection-state/Makefile similarity index 89% rename from plugins/connection-state/Makefile rename to plugins/examples/connection-state/Makefile index 8397e9f1..501ec299 100644 --- a/plugins/connection-state/Makefile +++ b/plugins/examples/connection-state/Makefile @@ -1,8 +1,9 @@ -include ../../config.mk +include ../../../config.mk .PHONY : all binary check clean reallyclean test install uninstall PLUGIN_NAME=mosquitto_connection_state +PLUGIN_CFLAGS+=-I../../../include -I../../../ all : binary diff --git a/plugins/connection-state/mosquitto_connection_state.c b/plugins/examples/connection-state/mosquitto_connection_state.c similarity index 100% rename from plugins/connection-state/mosquitto_connection_state.c rename to plugins/examples/connection-state/mosquitto_connection_state.c diff --git a/plugins/add-user-properties/CMakeLists.txt b/plugins/examples/message-timestamp/CMakeLists.txt similarity index 100% rename from plugins/add-user-properties/CMakeLists.txt rename to plugins/examples/message-timestamp/CMakeLists.txt diff --git a/plugins/message-timestamp/Makefile b/plugins/examples/message-timestamp/Makefile similarity index 89% rename from plugins/message-timestamp/Makefile rename to plugins/examples/message-timestamp/Makefile index f76b74cc..d704bcd3 100644 --- a/plugins/message-timestamp/Makefile +++ b/plugins/examples/message-timestamp/Makefile @@ -1,8 +1,9 @@ -include ../../config.mk +include ../../../config.mk .PHONY : all binary check clean reallyclean test install uninstall PLUGIN_NAME=mosquitto_message_timestamp +PLUGIN_CFLAGS+=-I../../../include -I../../../ all : binary diff --git a/plugins/message-timestamp/mosquitto_message_timestamp.c b/plugins/examples/message-timestamp/mosquitto_message_timestamp.c similarity index 100% rename from plugins/message-timestamp/mosquitto_message_timestamp.c rename to plugins/examples/message-timestamp/mosquitto_message_timestamp.c diff --git a/plugins/payload-modification/CMakeLists.txt b/plugins/examples/payload-modification/CMakeLists.txt similarity index 100% rename from plugins/payload-modification/CMakeLists.txt rename to plugins/examples/payload-modification/CMakeLists.txt diff --git a/plugins/payload-modification/Makefile b/plugins/examples/payload-modification/Makefile similarity index 89% rename from plugins/payload-modification/Makefile rename to plugins/examples/payload-modification/Makefile index ff3bcfc2..1eab85a2 100644 --- a/plugins/payload-modification/Makefile +++ b/plugins/examples/payload-modification/Makefile @@ -1,8 +1,9 @@ -include ../../config.mk +include ../../../config.mk .PHONY : all binary check clean reallyclean test install uninstall PLUGIN_NAME=mosquitto_payload_modification +PLUGIN_CFLAGS+=-I../../../include -I../../../ all : binary diff --git a/plugins/payload-modification/mosquitto_payload_modification.c b/plugins/examples/payload-modification/mosquitto_payload_modification.c similarity index 100% rename from plugins/payload-modification/mosquitto_payload_modification.c rename to plugins/examples/payload-modification/mosquitto_payload_modification.c diff --git a/plugins/message-timestamp/CMakeLists.txt b/plugins/message-timestamp/CMakeLists.txt deleted file mode 100644 index 5949a75f..00000000 --- a/plugins/message-timestamp/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) - -add_library(mosquitto_message_timestamp SHARED mosquitto_message_timestamp.c) -set_target_properties(mosquitto_message_timestamp PROPERTIES - POSITION_INDEPENDENT_CODE 1 -) -set_target_properties(mosquitto_message_timestamp PROPERTIES PREFIX "") - -# Don't install, these are example plugins only. -#install(TARGETS mosquitto_message_timestamp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/printf-example/CMakeLists.txt b/plugins/printf-example/CMakeLists.txt deleted file mode 100644 index 39878efc..00000000 --- a/plugins/printf-example/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) -link_directories(${mosquitto_SOURCE_DIR}) - -add_library(mosquitto_payload_modification SHARED mosquitto_payload_modification.c) -set_target_properties(mosquitto_payload_modification PROPERTIES - POSITION_INDEPENDENT_CODE 1 -) -set_target_properties(mosquitto_payload_modification PROPERTIES PREFIX "") -if(WIN32) - target_link_libraries(mosquitto_payload_modification mosquitto) -endif(WIN32) - -# Don't install, these are example plugins only. -#install(TARGETS mosquitto_payload_modification RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/printf-example/Makefile b/plugins/printf-example/Makefile deleted file mode 100644 index e1d433d5..00000000 --- a/plugins/printf-example/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -include ../../config.mk - -.PHONY : all binary check clean reallyclean test install uninstall - -PLUGIN_NAME=printf_example - -all : binary - -binary : ${PLUGIN_NAME}.so - -${PLUGIN_NAME}.so : ${PLUGIN_NAME}.c - $(CROSS_COMPILE)$(CC) $(PLUGIN_CPPFLAGS) $(PLUGIN_CFLAGS) $(PLUGIN_LDFLAGS) -fPIC -shared $< -o $@ - -reallyclean : clean -clean: - -rm -f *.o ${PLUGIN_NAME}.so *.gcda *.gcno - -check: test -test: - -install: ${PLUGIN_NAME}.so - # Don't install, these are examples only. - #$(INSTALL) -d "${DESTDIR}$(libdir)" - #$(INSTALL) ${STRIP_OPTS} ${PLUGIN_NAME}.so "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" - -uninstall : - -rm -f "${DESTDIR}${libdir}/${PLUGIN_NAME}.so"