Patchwork Add package for mongoose web server

login
register
mail settings
Submitter Charles Manning
Date Dec. 12, 2012, 10:03 p.m.
Message ID <1355349796-4165-1-git-send-email-cdhmanning@gmail.com>
Download mbox | patch
Permalink /patch/205666/
State Accepted
Headers show

Comments

Charles Manning - Dec. 12, 2012, 10:03 p.m.
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
---
 package/Config.in                             |    1 +
 package/mongoose/Config.in                    |   13 ++++++
 package/mongoose/mongoose-3.3-init-file.patch |   44 ++++++++++++++++++++
 package/mongoose/mongoose-3.3-no-auth.patch   |   55 +++++++++++++++++++++++++
 package/mongoose/mongoose.mk                  |   38 +++++++++++++++++
 5 files changed, 151 insertions(+), 0 deletions(-)
 create mode 100644 package/mongoose/Config.in
 create mode 100644 package/mongoose/mongoose-3.3-init-file.patch
 create mode 100644 package/mongoose/mongoose-3.3-no-auth.patch
 create mode 100644 package/mongoose/mongoose.mk
Arnout Vandecappelle - Dec. 13, 2012, 10:42 p.m.
Hi Charles,

On 12/12/12 23:03, Charles Manning wrote:
> Signed-off-by: Charles Manning<cdhmanning@gmail.com>
[snip]
> diff --git a/package/mongoose/Config.in b/package/mongoose/Config.in
> new file mode 100644
> index 0000000..39806f9
> --- /dev/null
> +++ b/package/mongoose/Config.in
> @@ -0,0 +1,13 @@
> +config BR2_PACKAGE_MONGOOSE
> +	bool "mongoose wen server"

 All other web servers just give their name, so:

	bool "mongoose"

 Missing:
	depends on BR2_TOOLCHAIN_HAS_THREADS
	depends on BR2_USE_WCHAR

> +	help
> +	  Mongoose small web server
> +
> +	  https://github.com/valenok/mongoose
> +
> +config BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH
> +	bool "Disable PUT authorization"
> +	depends on BR2_PACKAGE_MONGOOSE
> +	default n

 default n is redundant because it is the default.

 I prefer package-specific extra options to be wrapped in a if...endif 
instead of using 'depends on'.


> +	help
> +	  Sometimes you don't need PUT authorization.
[snip]
> diff --git a/package/mongoose/mongoose-3.3-no-auth.patch b/package/mongoose/mongoose-3.3-no-auth.patch
> new file mode 100644
> index 0000000..a470f5e
> --- /dev/null
> +++ b/package/mongoose/mongoose-3.3-no-auth.patch
> @@ -0,0 +1,55 @@
> +From db714636f86d79be33ffe8f2408c8731b5969208 Mon Sep 17 00:00:00 2001
> +From: Charles Manning<cdhmanning@gmail.com>
> +Date: Mon, 10 Dec 2012 10:14:20 +1300
> +Subject: [PATCH] Add NO_PUT_AUTH option to allow put with not authorization
> +
> +Sometimes you really don't want the security.
> +
> +Signed-off-by: Charles Manning<cdhmanning@gmail.com>

 Although this is a useful addition, it's really a new feature and not
a cross-compilation fix. We normally don't include new features in buildroot
patches.

 Could you upstream this patch?  Sergey is pretty quick with accepting patches.

[snip]
> diff --git a/package/mongoose/mongoose.mk b/package/mongoose/mongoose.mk
> new file mode 100644
> index 0000000..ef06f41
> --- /dev/null
> +++ b/package/mongoose/mongoose.mk
> @@ -0,0 +1,38 @@
> +# Package for mongoose web server.
> +# This has been patched with an extension to allow PUT with no authorization.
> +#

 Although on the last buildroot developer meeting some doubts were voices
about its usefulness, the rule is still that the .mk file should have the
following header:

#############################################################
#
# mongoose
#
#############################################################

> +MONGOOSE_VERSION = 3.3
> +MONGOOSE_SITE = http://github.com/valenok/mongoose/tarball/master
> +MONGOOSE_LICENSE = MIT
> +MONGOOSE_LICENSE_FILES = COPYING
> +MONGOOSE_INSTALL_STAGING = YES

 Why install in staging? You're not installing libraries or headers.

 That said, mongoose is often used as an embedded web server, so it
would be useful to have the option to:

- install the library and include file in staging;
- not install the executable and init script to target.

 But it's OK if you're not ready to do this; in that case, just
remove the INSTALL_STAGING line.

> +MONGOOSE_INSTALL_TARGET = YES

 This is the default.

> +
> +MONGOOSE_OPTIONAL_DEFINES = -DNO_SSL

 Ideally, SSL should be enabled if BR2_PACKAGE_OPENSSL is y.

 Adding support for HAVE_MD5, NDEBUG, NO_CGI and USE_LUA would also be
nice.

> +ifeq ($(BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH),y)
> +MONGOOSE_OPTIONAL_DEFINES += -DNO_PUT_AUTH

 If the patch is removed then obviously this should also be removed.

> +endif
> +
> +define MONGOOSE_BUILD_CMDS
> +	$(MAKE) CC="$(TARGET_CC)" LD="$TARGETLD)" -C $(@D) linux COPT="$(MONGOOSE_OPTIONAL_DEFINES)"

 Missing ( in $(TARGET_LD). But the Makefile doesn't use LD so it's
redundant.

 TARGET_CFLAGS and TARGET_LDFLAGS should also be passed - but mongoose's
Makefile doesn't support that. Your options are:

- Patch the Makefile to use CFLAGS += instead of CFLAGS =; if you do that,
also rename LINFLAGS to LDFLAGS, and use += instead of = for that as well.
And of course upstream this patch.

- Add TARGET_CFLAGS to COPT. You could also ad TARGET_LDFLAGS because
there is anyway no object file compilation, but it's not ideal. If you
leave out TARGET_LDFLAGS it's not such a big deal anyway because it's
not often used.

- Don't use the Makefile, but just run:

	cd $(@D); $(TARGET_CC) $(TARGET_CFLAGS) mongoose.c main.c \
		$(TARGET_LDFLAGS) -ldl -pthread


> +endef
> +
> +define MONGOOSE_INSTALL_STAGING_CMDS
> +	$(INSTALL) -d $(STAGING_DIR)/sbin
> +	$(INSTALL) -d $(STAGING_DIR)/etc
> +	$(INSTALL) -d $(STAGING_DIR)/etc/init.d
> +	$(INSTALL) -D -m 755 $(@D)/mongoose $(STAGING_DIR)/sbin/mongoose
> +	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(STAGING_DIR)/etc/init.d/mongoose

 Neither of these should be installed in staging. As I said earlier, it does
make sense to install the header and the .so.

> +endef
> +
> +define MONGOOSE_INSTALL_TARGET_CMDS
> +	$(INSTALL) -d $(TARGET_DIR)/sbin
> +	$(INSTALL) -d $(TARGET_DIR)/etc
> +	$(INSTALL) -d $(TARGET_DIR)/etc/init.d

 The install -D below already creates the directories, so these three are redundant.

> +	$(INSTALL) -D -m 755 $(@D)/mongoose $(TARGET_DIR)/sbin/mongoose
> +	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(TARGET_DIR)/etc/init.d/mongoose
> +endef
> +
> +
> +$(eval $(generic-package))
> +

 Redundant empty line.


 Regards,
 Arnout
Peter Korsgaard - May 2, 2013, 9:03 p.m.
>>>>> "Charles" == Charles Manning <cdhmanning@gmail.com> writes:

 Charles> Signed-off-by: Charles Manning <cdhmanning@gmail.com>
 Charles> ---
 Charles>  package/Config.in                             |    1 +
 Charles>  package/mongoose/Config.in                    |   13 ++++++
 Charles>  package/mongoose/mongoose-3.3-init-file.patch |   44 ++++++++++++++++++++
 Charles>  package/mongoose/mongoose-3.3-no-auth.patch   |   55 +++++++++++++++++++++++++
 Charles>  package/mongoose/mongoose.mk                  |   38 +++++++++++++++++

Hi,

I fixed up a number of issues here (see below) and committed, thanks.

A lot of the issues were also pointed out by Arnout in his review.


 Charles>  5 files changed, 151 insertions(+), 0 deletions(-)
 Charles>  create mode 100644 package/mongoose/Config.in
 Charles>  create mode 100644 package/mongoose/mongoose-3.3-init-file.patch
 Charles>  create mode 100644 package/mongoose/mongoose-3.3-no-auth.patch
 Charles>  create mode 100644 package/mongoose/mongoose.mk

 Charles> diff --git a/package/Config.in b/package/Config.in
 Charles> index 5ba1f05..a3d2590 100644
 Charles> --- a/package/Config.in
 Charles> +++ b/package/Config.in
 Charles> @@ -603,6 +603,7 @@ source "package/linphone/Config.in"
 Charles>  source "package/lrzsz/Config.in"
 Charles>  source "package/macchanger/Config.in"
 Charles>  source "package/mii-diag/Config.in"
 Charles> +source "package/mongoose/Config.in"
 Charles>  source "package/mrouted/Config.in"
 Charles>  source "package/msmtp/Config.in"
 Charles>  source "package/mutt/Config.in"
 Charles> diff --git a/package/mongoose/Config.in b/package/mongoose/Config.in
 Charles> new file mode 100644
 Charles> index 0000000..39806f9
 Charles> --- /dev/null
 Charles> +++ b/package/mongoose/Config.in
 Charles> @@ -0,0 +1,13 @@
 Charles> +config BR2_PACKAGE_MONGOOSE

It needs threads support in toolchain.


 Charles> +	bool "mongoose wen server"

I simply made this "mongoose"

 Charles> +	help
 Charles> +	  Mongoose small web server
 Charles> +
 Charles> +	  https://github.com/valenok/mongoose
 Charles> +
 Charles> +config BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH
 Charles> +	bool "Disable PUT authorization"
 Charles> +	depends on BR2_PACKAGE_MONGOOSE
 Charles> +	default n
 Charles> +	help
 Charles> +	  Sometimes you don't need PUT authorization.

We really don't want to carry feature patches in buildroot, so I've
dropped the patch and this option.

 Charles> diff --git a/package/mongoose/mongoose-3.3-init-file.patch b/package/mongoose/mongoose-3.3-init-file.patch

This should just be a file in package/mongoose, instead of a patch
adding it in the build directory.


 Charles> +++ b/package/mongoose/mongoose.mk
 Charles> @@ -0,0 +1,38 @@
 Charles> +# Package for mongoose web server.
 Charles> +# This has been patched with an extension to allow PUT with no authorization.

I've changed this to use our normal file header.

 Charles> +#
 Charles> +MONGOOSE_VERSION = 3.3
 Charles> +MONGOOSE_SITE = http://github.com/valenok/mongoose/tarball/master

This doesn't seem to download the real 3.3 version, so I've changed it
to the google code download location.


 Charles> +MONGOOSE_LICENSE = MIT
 Charles> +MONGOOSE_LICENSE_FILES = COPYING
 Charles> +MONGOOSE_INSTALL_STAGING = YES
 Charles> +MONGOOSE_INSTALL_TARGET = YES

INSTALL_TARGET defaults to yes, and installing the webserver to staging
doesn't make much sense. I know mongoose can be embedded in
applications, but this is done by copying mongoose.{c,h} into your
project, not by linking to a library.


 Charles> +
 Charles> +MONGOOSE_OPTIONAL_DEFINES = -DNO_SSL
 Charles> +ifeq ($(BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH),y)
 Charles> +MONGOOSE_OPTIONAL_DEFINES += -DNO_PUT_AUTH
 Charles> +endif
 Charles> +
 Charles> +define MONGOOSE_BUILD_CMDS
 Charles> +	$(MAKE) CC="$(TARGET_CC)" LD="$TARGETLD)" -C $(@D) linux COPT="$(MONGOOSE_OPTIONAL_DEFINES)"

It is TARGET_LD, not TARGETLD.

We should also ensure TARGET_CFLAGS and TARGET_LDFLAGS are used, so I've
added those to COPTS (and called the variable MONGOOSE_CFLAGS).

 Charles> +endef
 Charles> +
 Charles> +define MONGOOSE_INSTALL_STAGING_CMDS
 Charles> +	$(INSTALL) -d $(STAGING_DIR)/sbin
 Charles> +	$(INSTALL) -d $(STAGING_DIR)/etc
 Charles> +	$(INSTALL) -d $(STAGING_DIR)/etc/init.d
 Charles> +	$(INSTALL) -D -m 755 $(@D)/mongoose $(STAGING_DIR)/sbin/mongoose
 Charles> +	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(STAGING_DIR)/etc/init.d/mongoose
 Charles> +endef

This can be dropped.

 Charles> +
 Charles> +define MONGOOSE_INSTALL_TARGET_CMDS
 Charles> +	$(INSTALL) -d $(TARGET_DIR)/sbin
 Charles> +	$(INSTALL) -d $(TARGET_DIR)/etc
 Charles> +	$(INSTALL) -d $(TARGET_DIR)/etc/init.d
 Charles> +	$(INSTALL) -D -m 755 $(@D)/mongoose $(TARGET_DIR)/sbin/mongoose
 Charles> +	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(TARGET_DIR)/etc/init.d/mongoose
 Charles> +endef

install -D creates the needed directories, so all the -d lines can be
dropped. As mentioned above, the init script should just be a file in
package/mongoose, and be copied to etc/init.d/SXXmongoose, where XX is a
number. To match E.G. tinyhttpd I've used XX = 85.

 Charles> +
 Charles> +$(eval $(generic-package))
 Charles> +

No empty line after generic-package.

Patch

diff --git a/package/Config.in b/package/Config.in
index 5ba1f05..a3d2590 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -603,6 +603,7 @@  source "package/linphone/Config.in"
 source "package/lrzsz/Config.in"
 source "package/macchanger/Config.in"
 source "package/mii-diag/Config.in"
+source "package/mongoose/Config.in"
 source "package/mrouted/Config.in"
 source "package/msmtp/Config.in"
 source "package/mutt/Config.in"
diff --git a/package/mongoose/Config.in b/package/mongoose/Config.in
new file mode 100644
index 0000000..39806f9
--- /dev/null
+++ b/package/mongoose/Config.in
@@ -0,0 +1,13 @@ 
+config BR2_PACKAGE_MONGOOSE
+	bool "mongoose wen server"
+	help
+	  Mongoose small web server
+
+	  https://github.com/valenok/mongoose
+
+config BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH
+	bool "Disable PUT authorization"
+	depends on BR2_PACKAGE_MONGOOSE
+	default n
+	help
+	  Sometimes you don't need PUT authorization.
diff --git a/package/mongoose/mongoose-3.3-init-file.patch b/package/mongoose/mongoose-3.3-init-file.patch
new file mode 100644
index 0000000..b62e4ca
--- /dev/null
+++ b/package/mongoose/mongoose-3.3-init-file.patch
@@ -0,0 +1,44 @@ 
+--- /dev/null	2012-12-10 08:42:11.241266044 +1300
++++ files/mongoose.init	2010-07-28 09:01:23.000000000 +1200
+@@ -0,0 +1,41 @@
++#!/bin/sh
++#
++# Start/stop the mongoose HTTP server
++#
++
++set -e
++
++PATH=/sbin:/bin:/usr/sbin:/usr/bin
++NAME=mongoose
++DESC="Mongoose HTTP server"
++
++DAEMON=`which mongoose`
++OPTIONS="-max_threads 3 -root /var/www  -ports 80"
++
++[ -e /etc/default/mongoose ] && . /etc/default/mongoose
++
++case "$1" in
++  start)
++	echo "Starting $DESC:"
++	start-stop-daemon -S -x "$DAEMON" -b -- $OPTIONS
++	echo "$NAME."
++	;;
++  stop)
++	echo -n "Stopping $DESC: "
++	start-stop-daemon -K -x "$DAEMON"
++	echo "$NAME."
++	;;
++  restart|force-reload)
++	echo -n "Restarting $DESC: "
++	start-stop-daemon -K -x "$DAEMON"
++	start-stop-daemon -S -x "$DAEMON" -b -- $OPTIONS
++	echo "$NAME."
++	;;
++  *)
++	N=/etc/init.d/$NAME
++	echo "Usage: $N {start|stop|restart|force-reload}" >&2
++	exit 1
++	;;
++esac
++
++exit 0
diff --git a/package/mongoose/mongoose-3.3-no-auth.patch b/package/mongoose/mongoose-3.3-no-auth.patch
new file mode 100644
index 0000000..a470f5e
--- /dev/null
+++ b/package/mongoose/mongoose-3.3-no-auth.patch
@@ -0,0 +1,55 @@ 
+From db714636f86d79be33ffe8f2408c8731b5969208 Mon Sep 17 00:00:00 2001
+From: Charles Manning <cdhmanning@gmail.com>
+Date: Mon, 10 Dec 2012 10:14:20 +1300
+Subject: [PATCH] Add NO_PUT_AUTH option to allow put with not authorization
+
+Sometimes you really don't want the security.
+
+Signed-off-by: Charles Manning <cdhmanning@gmail.com>
+---
+ Makefile   |    2 +-
+ mongoose.c |    8 +++++++-
+ 2 files changed, 8 insertions(+), 2 deletions(-)
+
+diff --git a/Makefile b/Makefile
+index 14f986a..ae4755b 100644
+--- a/Makefile
++++ b/Makefile
+@@ -17,7 +17,7 @@ all:
+ # -DSSL_LIB=\"libssl.so.<version>\"   - use system versioned SSL shared object
+ # -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
+ # -DUSE_LUA               - embed Lua in Mongoose (+100kb)
+-
++# -DNO_PUT_AUTH           - disable authorization for PUT/DELETE
+ 
+ ##########################################################################
+ ###                 UNIX build: linux, bsd, mac, rtems
+diff --git a/mongoose.c b/mongoose.c
+index 2b5e586..327b419 100644
+--- a/mongoose.c
++++ b/mongoose.c
+@@ -64,6 +64,12 @@
+ #include <stddef.h>
+ #include <stdio.h>
+ 
++#ifdef NO_PUT_AUTH
++static int put_authorization_required = 0;
++#else
++static int put_authorization_required = 1;
++#endif
++
+ #if defined(_WIN32) && !defined(__SYMBIAN32__) // Windows specific
+ #define _WIN32_WINNT 0x0400 // To make it link in VS2005
+ #include <windows.h>
+@@ -4182,7 +4188,7 @@ static void handle_request(struct mg_connection *conn) {
+     send_options(conn);
+   } else if (conn->ctx->config[DOCUMENT_ROOT] == NULL) {
+     send_http_error(conn, 404, "Not Found", "Not Found");
+-  } else if ((!strcmp(ri->request_method, "PUT") ||
++  } else if (put_authorization_required && (!strcmp(ri->request_method, "PUT") ||
+         !strcmp(ri->request_method, "DELETE")) &&
+       (conn->ctx->config[PUT_DELETE_PASSWORDS_FILE] == NULL ||
+        is_authorized_for_put(conn) != 1)) {
+-- 
+1.7.1
+
diff --git a/package/mongoose/mongoose.mk b/package/mongoose/mongoose.mk
new file mode 100644
index 0000000..ef06f41
--- /dev/null
+++ b/package/mongoose/mongoose.mk
@@ -0,0 +1,38 @@ 
+# Package for mongoose web server.
+# This has been patched with an extension to allow PUT with no authorization.
+#
+MONGOOSE_VERSION = 3.3
+MONGOOSE_SITE = http://github.com/valenok/mongoose/tarball/master
+MONGOOSE_LICENSE = MIT
+MONGOOSE_LICENSE_FILES = COPYING
+MONGOOSE_INSTALL_STAGING = YES
+MONGOOSE_INSTALL_TARGET = YES
+
+MONGOOSE_OPTIONAL_DEFINES = -DNO_SSL
+ifeq ($(BR2_PACKAGE_MONGOOSE_NO_PUT_AUTH),y)
+MONGOOSE_OPTIONAL_DEFINES += -DNO_PUT_AUTH
+endif
+
+define MONGOOSE_BUILD_CMDS
+	$(MAKE) CC="$(TARGET_CC)" LD="$TARGETLD)" -C $(@D) linux COPT="$(MONGOOSE_OPTIONAL_DEFINES)"
+endef
+
+define MONGOOSE_INSTALL_STAGING_CMDS
+	$(INSTALL) -d $(STAGING_DIR)/sbin
+	$(INSTALL) -d $(STAGING_DIR)/etc
+	$(INSTALL) -d $(STAGING_DIR)/etc/init.d
+	$(INSTALL) -D -m 755 $(@D)/mongoose $(STAGING_DIR)/sbin/mongoose
+	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(STAGING_DIR)/etc/init.d/mongoose
+endef
+
+define MONGOOSE_INSTALL_TARGET_CMDS
+	$(INSTALL) -d $(TARGET_DIR)/sbin
+	$(INSTALL) -d $(TARGET_DIR)/etc
+	$(INSTALL) -d $(TARGET_DIR)/etc/init.d
+	$(INSTALL) -D -m 755 $(@D)/mongoose $(TARGET_DIR)/sbin/mongoose
+	$(INSTALL) -D -m 755 $(@D)/mongoose.init $(TARGET_DIR)/etc/init.d/mongoose
+endef
+
+
+$(eval $(generic-package))
+