From 8959d8c3ea34cbe15ceef447fa8206766bb99f70 Mon Sep 17 00:00:00 2001
From: Christof Schulze <christof.schulze@gmx.net>
Date: Fri, 13 Apr 2018 20:44:52 +0200
Subject: [PATCH] gluon-status-page: make status page mesh protocol agnostic

batman-adv-specific parts are moved to a new package
gluon-status-page-mesh-batman-adv.
---
 package/features                              |  3 ++
 .../Makefile                                  | 20 ++++++++++
 .../luasrc/lib/gluon/status-page/mesh.lua     |  0
 .../src/Makefile                              | 40 +++++++++++++++++++
 .../src/neighbours-batadv.c                   |  0
 package/gluon-status-page/Makefile            |  4 +-
 .../www/cgi-bin/dyn/neighbours-nodeinfo       |  2 +-
 .../status-page/www/cgi-bin/dyn/stations      |  2 +-
 package/gluon-status-page/src/Makefile        | 14 +------
 9 files changed, 68 insertions(+), 17 deletions(-)
 create mode 100644 package/gluon-status-page-mesh-batman-adv/Makefile
 rename package/{gluon-status-page => gluon-status-page-mesh-batman-adv}/luasrc/lib/gluon/status-page/mesh.lua (100%)
 create mode 100644 package/gluon-status-page-mesh-batman-adv/src/Makefile
 rename package/{gluon-status-page => gluon-status-page-mesh-batman-adv}/src/neighbours-batadv.c (100%)

diff --git a/package/features b/package/features
index 52c9211d3..210581d5e 100644
--- a/package/features
+++ b/package/features
@@ -21,3 +21,6 @@ packages 'web-advanced' \
 
 packages 'web-advanced & autoupdater' \
 	'gluon-web-autoupdater'
+
+packages 'status-page & (mesh-batman-adv-14 | mesh-batman-adv-15)' \
+        'gluon-status-page-mesh-batman-adv'
diff --git a/package/gluon-status-page-mesh-batman-adv/Makefile b/package/gluon-status-page-mesh-batman-adv/Makefile
new file mode 100644
index 000000000..4d2ed8f0d
--- /dev/null
+++ b/package/gluon-status-page-mesh-batman-adv/Makefile
@@ -0,0 +1,20 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=gluon-status-page-mesh-batman-adv
+PKG_VERSION:=1
+
+include ../gluon.mk
+
+define Package/gluon-status-page-mesh-batman-adv
+  TITLE:=Batman-data provider for gluon-status-page
+  DEPENDS:=+gluon-status-page gluon-mesh-batman-adv +libnl-tiny +libbatadv +libjson-c
+endef
+
+define Package/gluon-status-page-mesh-batman-adv/install
+	$(Gluon/Build/Install)
+
+	$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/providers/
+endef
+
+$(eval $(call BuildPackageGluon,gluon-status-page-mesh-batman-adv))
diff --git a/package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua b/package/gluon-status-page-mesh-batman-adv/luasrc/lib/gluon/status-page/mesh.lua
similarity index 100%
rename from package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua
rename to package/gluon-status-page-mesh-batman-adv/luasrc/lib/gluon/status-page/mesh.lua
diff --git a/package/gluon-status-page-mesh-batman-adv/src/Makefile b/package/gluon-status-page-mesh-batman-adv/src/Makefile
new file mode 100644
index 000000000..5fb4ef4fa
--- /dev/null
+++ b/package/gluon-status-page-mesh-batman-adv/src/Makefile
@@ -0,0 +1,40 @@
+all: neighbours-batadv
+
+CFLAGS += -Wall -D_GNU_SOURCE
+
+ifeq ($(origin PKG_CONFIG), undefined)
+  PKG_CONFIG = pkg-config
+  ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
+    $(error $(PKG_CONFIG) not found)
+  endif
+endif
+
+ifeq ($(origin LIBNL_CFLAGS) $(origin LIBNL_LDLIBS), undefined undefined)
+  LIBNL_NAME ?= libnl-tiny
+  ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_NAME) 2>/dev/null),)
+    $(error No $(LIBNL_NAME) development libraries found!)
+  endif
+  LIBNL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_NAME))
+  LIBNL_LDLIBS +=  $(shell $(PKG_CONFIG) --libs $(LIBNL_NAME))
+endif
+CFLAGS += $(LIBNL_CFLAGS)
+LDLIBS += $(LIBNL_LDLIBS)
+
+CFLAGS_JSONC = $(shell pkg-config --cflags json-c)
+LDFLAGS_JSONC = $(shell pkg-config --libs json-c)
+
+
+ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined)
+  LIBBATADV_NAME ?= libbatadv
+  ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBBATADV_NAME) 2>/dev/null),)
+    $(error No $(LIBBATADV_NAME) development libraries found!)
+  endif
+  LIBBATADV_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBBATADV_NAME))
+  LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
+endif
+CFLAGS += $(LIBBATADV_CFLAGS)
+LDLIBS += $(LIBBATADV_LDLIBS)
+
+neighbours-batadv: neighbours-batadv.c
+	$(CC) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -o $@ $^ $(LDLIBS)
+
diff --git a/package/gluon-status-page/src/neighbours-batadv.c b/package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c
similarity index 100%
rename from package/gluon-status-page/src/neighbours-batadv.c
rename to package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c
diff --git a/package/gluon-status-page/Makefile b/package/gluon-status-page/Makefile
index d17ce2dae..923f68c77 100644
--- a/package/gluon-status-page/Makefile
+++ b/package/gluon-status-page/Makefile
@@ -7,14 +7,14 @@ include ../gluon.mk
 
 define Package/gluon-status-page
   TITLE:=Status page showing information about the node
-  DEPENDS:=+gluon-web +gluon-neighbour-info +gluon-respondd +uhttpd +sse-multiplex +libiwinfo +libjson-c +libnl-tiny +libubus-lua +libbatadv
+  DEPENDS:=+gluon-web +gluon-neighbour-info +gluon-respondd +uhttpd +sse-multiplex +libiwinfo +libjson-c +libnl-tiny +libubus-lua
 endef
 
 define Package/gluon-status-page/install
 	$(Gluon/Build/Install)
 
 	$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/{neighbours-batadv,stations} $(1)/lib/gluon/status-page/providers/
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/stations $(1)/lib/gluon/status-page/providers/
 
 	$(INSTALL_DIR) $(1)/lib/gluon/status-page/view/
 	$(LN) /lib/gluon/web/i18n $(1)/lib/gluon/status-page/
diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
index 71b3ecff9..3f1491001 100755
--- a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
+++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo
@@ -6,6 +6,6 @@ badrequest() {
         exit 1
 }
 
-( batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" ) 2>/dev/null || badrequest
+( gluon-list-mesh-interfaces | grep -qxF "$QUERY_STRING" ) 2>/dev/null || badrequest
 
 exec gluon-neighbour-info -s neighbour -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo
diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
index a3005f7e6..5ff1f1254 100755
--- a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
+++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations
@@ -6,7 +6,7 @@ badrequest() {
         exit 1
 }
 
-( batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" ) 2>/dev/null || badrequest
+( gluon-list-mesh-interfaces | grep -qxF "$QUERY_STRING" ) 2>/dev/null || badrequest
 
 CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'"
 
diff --git a/package/gluon-status-page/src/Makefile b/package/gluon-status-page/src/Makefile
index bf5141a73..a0a14e16d 100644
--- a/package/gluon-status-page/src/Makefile
+++ b/package/gluon-status-page/src/Makefile
@@ -20,19 +20,7 @@ endif
 CFLAGS_JSONC = $(shell pkg-config --cflags json-c)
 LDFLAGS_JSONC = $(shell pkg-config --libs json-c)
 
-ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined)
-  LIBBATADV_NAME ?= libbatadv
-  ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBBATADV_NAME) 2>/dev/null),)
-    $(error No $(LIBBATADV_NAME) development libraries found!)
-  endif
-  LIBBATADV_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBBATADV_NAME))
-  LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
-endif
-
-all: neighbours-batadv stations
-
-neighbours-batadv: neighbours-batadv.c
-	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LIBNL_CFLAGS) $(LIBBATADV_CFLAGS) $(LDFLAGS) $(LDFLAGS_JSONC) $(LIBNL_LDLIBS) $(LIBBATADV_LDLIBS) -Wall -o $@ $^ $(LDLIBS)
+all: stations
 
 stations: stations.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -Wall -o $@ $^ $(LDLIBS) -liwinfo
-- 
GitLab