From 60e7314f7b01d6e1cc4d70ccfcd15c204328d280 Mon Sep 17 00:00:00 2001
From: Sukru Senli <sukru.senli@iopsys.eu>
Date: Thu, 11 Feb 2021 19:08:45 +0100
Subject: [PATCH] update for usp5

---
 libs/cjson/.gitkeep                           |  0
 libs/cjson/Makefile                           | 53 +++++++++++++++++++
 net/mosquitto/Config.in                       | 16 ++++++
 net/mosquitto/Makefile                        | 50 +++++++++--------
 net/mosquitto/files/etc/config/mosquitto      | 35 ++++++++++--
 net/mosquitto/files/etc/init.d/mosquitto      | 12 ++---
 .../files/etc/mosquitto/mosquitto.conf        | 30 +++++++++++
 .../files/etc/mosquitto/mosquitto.password    |  2 +
 8 files changed, 168 insertions(+), 30 deletions(-)
 create mode 100644 libs/cjson/.gitkeep
 create mode 100644 libs/cjson/Makefile
 create mode 100644 net/mosquitto/files/etc/mosquitto/mosquitto.conf
 create mode 100644 net/mosquitto/files/etc/mosquitto/mosquitto.password

diff --git a/libs/cjson/.gitkeep b/libs/cjson/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/libs/cjson/Makefile b/libs/cjson/Makefile
new file mode 100644
index 0000000000..9aff81c189
--- /dev/null
+++ b/libs/cjson/Makefile
@@ -0,0 +1,53 @@
+# This Makefile is free software, SPDX codes: GPL-2.0-or-later OR MIT
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=cJSON
+PKG_VERSION:=1.7.14
+PKG_RELEASE:=2
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/DaveGamble/cJSON/tar.gz/v$(PKG_VERSION)?
+PKG_HASH:=fb50a663eefdc76bafa80c82bc045af13b1363e8f45cec8b442007aef6a41343
+
+PKG_LICENSE:=MIT
+PKG_LICENSE_FILES:=LICENSE
+PKG_CPE_ID:=cpe:/a:cjson_project:cjson
+
+CMAKE_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/cJSON
+  SECTION:=libs
+  CATEGORY:=Libraries
+  TITLE:=Ultralightweight JSON parser in ANSI C
+  URL:=https://github.com/DaveGamble/cJSON
+  MAINTAINER:=Karl Palsson <karlp@etactica.com>
+endef
+
+define Package/cJSON/description
+ Ultralightweight JSON parser in ANSI C.
+cJSON aims to be the dumbest possible parser that you can get your
+job done with. It's a single file of C, and a single header file.
+endef
+
+CMAKE_OPTIONS += -DENABLE_CJSON_TEST=OFF
+
+define Build/InstallDev
+	$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libcjson.pc $(1)/usr/lib/pkgconfig
+	$(INSTALL_DIR) $(1)/usr/include/cjson
+	$(CP) $(PKG_INSTALL_DIR)/usr/include/cjson/cJSON.h $(1)/usr/include/cjson
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libcjson.so* $(1)/usr/lib/
+endef
+
+define Package/cJSON/install
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libcjson.so* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,cJSON))
diff --git a/net/mosquitto/Config.in b/net/mosquitto/Config.in
index 4599736fcb..10c7a6bc34 100644
--- a/net/mosquitto/Config.in
+++ b/net/mosquitto/Config.in
@@ -5,6 +5,22 @@ config MOSQUITTO_LWS
     help
         Includes websockets support in the broker, via libwebsockets
 
+config MOSQUITTO_CTRL
+    bool "Include mosquitto_ctrl utility"
+    depends on PACKAGE_mosquitto-ssl
+    default y
+    help
+        mosquitto_ctrl is a tool for managing the broker at run time.
+
+config MOSQUITTO_DYNAMIC_SECURITY
+    bool "Install mosquitto_dynamic_security.so"
+    depends on PACKAGE_mosquitto-ssl
+    default y
+    help
+        This enables the dynamic security modes documented at
+        https://mosquitto.org/documentation/dynamic-security/
+        but does add ~88kB.  If you're not using it, you can disable it
+
 config MOSQUITTO_PASSWD
     bool "Include mosquitto_passwd utility"
     depends on PACKAGE_mosquitto-ssl
diff --git a/net/mosquitto/Makefile b/net/mosquitto/Makefile
index 4367ee8bba..e934c70130 100644
--- a/net/mosquitto/Makefile
+++ b/net/mosquitto/Makefile
@@ -9,16 +9,15 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mosquitto
-PKG_VERSION:=1.6.9
+PKG_VERSION:=2.0.2
 PKG_RELEASE:=1
-PKG_LICENSE:=BSD-3-Clause
+PKG_LICENSE:=EPL-2.0
 PKG_LICENSE_FILES:=LICENSE.txt
 PKG_CPE_ID:=cpe:/a:eclipse:mosquitto
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://mosquitto.org/files/source/
-PKG_HASH:=412979b2db0a0020bd02fa64f0a0de9e7000b84462586e32b67f29bb1f6c1685
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
+PKG_HASH:=5ea9ebf0a5ed3e95cecd75f30ebcf84f054584eff5617ac0f2e60428d3ad9707
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -35,7 +34,7 @@ endef
 define Package/mosquitto-ssl
     $(call Package/mosquitto/default)
     TITLE+= (with SSL support)
-    DEPENDS+= +libopenssl +MOSQUITTO_LWS:libwebsockets-openssl
+    DEPENDS+= +libopenssl +MOSQUITTO_LWS:libwebsockets-openssl +MOSQUITTO_DYNAMIC_SECURITY:cJSON
     VARIANT:=ssl
     PROVIDES:=mosquitto
 endef
@@ -53,7 +52,7 @@ endef
 
 define Package/mosquitto/default/description
 Mosquitto is an open source (BSD licensed) message broker that implements
-the MQTT protocol version 3.1 and 3.1.1. MQTT provides a lightweight
+the MQTT protocol version 3.1, 3.1.1 and 5. MQTT provides a lightweight
 method of carrying out messaging using a publish/subscribe model.
 
 This package also includes some basic support for configuring via UCI
@@ -74,7 +73,7 @@ endef
 define Package/mosquitto-client/default
     $(Package/mosquitto/default)
     TITLE:= mosquitto - client tools
-    DEPENDS+=+libcares
+    DEPENDS+=+libcares +cJSON
     PROVIDES:=mosquitto-client
 endef
 define Package/mosquitto-client-ssl
@@ -91,8 +90,9 @@ define Package/mosquitto-client-nossl
 endef
 
 define Package/mosquitto-client/default/description
- Command line client tools for publishing messages to MQTT servers
-and subscribing to topics.
+ Command line client tools for working with mosquitto.
+This includes mosquitto_sub, mosquitto_pub, mosquitto_rr
+and the mosquitto_ctrl tool.
 endef
 
 define Package/mosquitto-client-ssl/description
@@ -127,11 +127,11 @@ endef
 
 define Package/libmosquitto/default/description
  Library required for mosquitto's command line client tools, also for
-use by any third party software that wants to communicate with a
-mosquitto server.
+use by any third party software that wants to communicate with _any_
+MQTT server.
 
-Should be useable for communicating with any MQTT v3.1/3.1.1 compatible
-server, such as IBM's RSMB, in addition to Mosquitto
+Should be useable for communicating with any MQTT v3.1/3.1.1/5 compatible
+server, in addition to Mosquitto.
 endef
 
 define Package/libmosquitto-ssl/description
@@ -177,24 +177,32 @@ define Package/mosquitto-ssl/install
 	$(call Package/mosquitto/install/default,$(1))
 ifeq ($(CONFIG_MOSQUITTO_PASSWD),y)
 	$(INSTALL_DIR) $(1)/usr/bin
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/mosquitto_passwd $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/apps/mosquitto_passwd/mosquitto_passwd $(1)/usr/bin
+endif
+ifeq ($(CONFIG_MOSQUITTO_DYNAMIC_SECURITY),y)
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/plugins/dynamic-security/mosquitto_dynamic_security.so $(1)/usr/lib
 endif
 endef
 
-define Package/mosquitto-client-ssl/install
+define Package/mosquitto-client-nossl/install
 	$(INSTALL_DIR) $(1)/usr/bin
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/mosquitto_pub $(1)/usr/bin/mosquitto_pub
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/mosquitto_sub $(1)/usr/bin/mosquitto_sub
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/mosquitto_pub $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/mosquitto_sub $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/mosquitto_rr $(1)/usr/bin
+endef
+define Package/mosquitto-client-ssl/install
+	$(call Package/mosquitto-client-nossl/install,$(1))
+ifeq ($(CONFIG_MOSQUITTO_CTRL),y)
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/apps/mosquitto_ctrl/mosquitto_ctrl $(1)/usr/bin
+endif
 endef
-Package/mosquitto-client-nossl/install = $(Package/mosquitto-client-ssl/install)
 
 # This installs files into ./staging_dir/. so that you can cross compile from the host
 define Build/InstallDev
 	$(INSTALL_DIR) $(1)/usr/include
-	$(CP) $(PKG_BUILD_DIR)/lib/mosquitto.h $(1)/usr/include
+	$(CP) $(PKG_BUILD_DIR)/include/*.h $(1)/usr/include
 	$(CP) $(PKG_BUILD_DIR)/lib/cpp/mosquittopp.h $(1)/usr/include
-	$(CP) $(PKG_BUILD_DIR)/src/mosquitto_plugin.h $(1)/usr/include
-	$(CP) $(PKG_BUILD_DIR)/src/mosquitto_broker.h $(1)/usr/include
 	$(INSTALL_DIR) $(1)/usr/lib
 	$(CP) $(PKG_BUILD_DIR)/lib/libmosquitto.so.1 $(1)/usr/lib/
 	$(CP) $(PKG_BUILD_DIR)/lib/cpp/libmosquittopp.so.1 $(1)/usr/lib/
diff --git a/net/mosquitto/files/etc/config/mosquitto b/net/mosquitto/files/etc/config/mosquitto
index fc7544c690..eb015913ef 100644
--- a/net/mosquitto/files/etc/config/mosquitto
+++ b/net/mosquitto/files/etc/config/mosquitto
@@ -1,4 +1,33 @@
-config owrt owrt
-    option use_uci 0
+config owrt 'owrt'
+	option use_uci '1'
+
+config mosquitto 'mosquitto'
+	option log_facility '5'
+	option log_dest 'file /tmp/mosquitto.log'
+	option per_listener_settings '1'
+
+config listener 'listener_1883'
+	option port '1883'
+	option no_remote_access '1'
+	option protocol 'mqtt'
+	option allow_anonymous '1'
+	option use_identity_as_username '1'
+
+config listener 'listener_9001'
+	option port '9001'
+	option no_remote_access '0'
+	option protocol 'websockets'
+	option require_certificate '0'
+	option use_identity_as_username '1'
+	option allow_anonymous '0'
+	option password_file '/etc/mosquitto/mosquitto.password'
+
+config listener 'listener_11883'
+	option port '11883'
+	option no_remote_access '0'
+	option protocol 'mqtt'
+	option require_certificate '0'
+	option use_identity_as_username '1'
+	option allow_anonymous '0'
+	option password_file '/etc/mosquitto/mosquitto.password'
 
-config mosquitto mosquitto
diff --git a/net/mosquitto/files/etc/init.d/mosquitto b/net/mosquitto/files/etc/init.d/mosquitto
index b42fa8866c..99fbfadc90 100755
--- a/net/mosquitto/files/etc/init.d/mosquitto
+++ b/net/mosquitto/files/etc/init.d/mosquitto
@@ -54,17 +54,15 @@ append_optional_bool() {
 convert_mosq_general() {
 	local cfg="$1"
 	config_get destinations "$1" log_dest
-	for dest in $destinations; do
-		echo "log_dest $dest" >> $TCONF
-	done
+	[ -n "$destinations" ] && echo "log_dest $destinations" >> $TCONF
 
 	config_get_bool no_remote "$1" no_remote_access 0
 	if [ "$no_remote" -eq 1 ]; then
 		echo "bind_address localhost" >> $TCONF
 	fi
 
-	config_get port "$1" port 1883
-	echo "port $port" >> $TCONF
+	config_get port "$1" port #1883
+	[ -n "$port" ] && echo "port $port" >> $TCONF
 	append_if "$1" acl_file
 	append_optional_bool "$1" allow_anonymous
 	append_optional_bool "$1" allow_duplicate_messages
@@ -75,7 +73,7 @@ convert_mosq_general() {
 	append_optional_bool "$1" log_timestamp
 	config_get log_types "$1" log_types
 	for log_type in $log_types; do
-		echo "log_dest $log_type" >> $TCONF
+		echo "log_type $log_type" >> $TCONF
 	done
 	append_if "$1" max_inflight_bytes
 	append_if "$1" max_inflight_messages
@@ -146,6 +144,8 @@ add_listener() {
     append_optional_bool "$1" use_subject_as_username
     append_if "$1" psk_hint
     append_if "$1" auth_plugin
+    append_if "$1" password_file
+    append_optional_bool "$1" allow_anonymous
 
     # Careful, this relies on internal behaviour of the cfg_load functions!
     set | grep "CONFIG_$1_auth_opt_" | sed "s/^.*_\(auth_opt_.*\)='\(.*\)'/\1 \2/" >> $TCONF
diff --git a/net/mosquitto/files/etc/mosquitto/mosquitto.conf b/net/mosquitto/files/etc/mosquitto/mosquitto.conf
new file mode 100644
index 0000000000..9c4052fbbc
--- /dev/null
+++ b/net/mosquitto/files/etc/mosquitto/mosquitto.conf
@@ -0,0 +1,30 @@
+log_type all
+log_dest file /tmp/mosquitto.log
+log_facility 5
+
+per_listener_settings true
+
+listener 1883 localhost
+socket_domain ipv4
+allow_anonymous true
+
+listener 9001
+socket_domain ipv4
+protocol websockets
+require_certificate false
+use_identity_as_username true
+allow_anonymous false
+password_file /etc/mosquitto/mosquitto.password
+
+#listener 1883 0.0.0.0 does not work
+listener 11883
+socket_domain ipv4
+protocol mqtt
+require_certificate false
+use_identity_as_username true
+allow_anonymous false
+password_file /etc/mosquitto/mosquitto.password
+
+
+
+
diff --git a/net/mosquitto/files/etc/mosquitto/mosquitto.password b/net/mosquitto/files/etc/mosquitto/mosquitto.password
new file mode 100644
index 0000000000..650a398658
--- /dev/null
+++ b/net/mosquitto/files/etc/mosquitto/mosquitto.password
@@ -0,0 +1,2 @@
+admin:$7$101$GYCG2oFryQQFTaRN$KrAULxvEn1HEPDrASwqbl4hfW6I3G9OCAi2WhtY5fWpYrJe5hBz9MOqTZUdruFWEiQZ/ktSEDvFxocnPMU0A1A==
+user:$7$101$93cvCJbz79YuypKi$2+7YMrGOGXP3o2VTc0TbNuuKC/L5uq4qPh9QXWeZGimLCjW8ILrk3wWkuBkAFOHhCZfBgNaj4/9YT4LYmGWtyQ==
-- 
GitLab