summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--LICENSE.txt2
-rw-r--r--Makefile2
-rw-r--r--debian/changelog6
-rw-r--r--debian/copyright2
-rw-r--r--libcommon/Makefile3
-rw-r--r--libcommon/url.cpp32
-rw-r--r--libcommon/url.h6
-rw-r--r--plugins/static-files/static-files.cpp3
-rw-r--r--plugins/webbox/webbox.cpp33
-rw-r--r--webserver.12
-rw-r--r--webserver.conf8
11 files changed, 63 insertions, 36 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index b868bb7..89ed2c4 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright 2020 Roland Reichwein
+Copyright 2021 Roland Reichwein
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/Makefile b/Makefile
index 0f214b1..8db9403 100644
--- a/Makefile
+++ b/Makefile
@@ -165,6 +165,8 @@ DISTFILES= \
libcommon/stringutil.cpp \
libcommon/tempfile.h \
libcommon/tempfile.cpp \
+ libcommon/url.h \
+ libcommon/url.cpp \
plugins/cgi/cgi.h \
plugins/cgi/Makefile \
plugins/cgi/cgi.cpp \
diff --git a/debian/changelog b/debian/changelog
index cb34ab9..ba76792 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+webserver (1.14) unstable; urgency=medium
+
+ * Bugfix: URL decoding in static files plugin
+
+ -- Roland Reichwein <mail@reichwein.it> Fri, 24 Sep 2021 10:47:07 +0200
+
webserver (1.13) unstable; urgency=medium
* Code cleanup (Boost tests instead of google tests)
diff --git a/debian/copyright b/debian/copyright
index 4b3a1b3..8e3ebb6 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,4 +1,4 @@
-This package is Copyright 2020 by Roland Reichwein <mail@reichwein.it>
+This package is Copyright 2021 by Roland Reichwein <mail@reichwein.it>
Both upstream source code and Debian packaging is licensed under the BSD
license:
diff --git a/libcommon/Makefile b/libcommon/Makefile
index d3d781d..ddff9fc 100644
--- a/libcommon/Makefile
+++ b/libcommon/Makefile
@@ -10,7 +10,8 @@ PROGSRC=\
file.cpp \
mime.cpp \
stringutil.cpp \
- tempfile.cpp
+ tempfile.cpp \
+ url.cpp
SRC=$(PROGSRC)
diff --git a/libcommon/url.cpp b/libcommon/url.cpp
new file mode 100644
index 0000000..5baf603
--- /dev/null
+++ b/libcommon/url.cpp
@@ -0,0 +1,32 @@
+#include "url.h"
+
+std::string urlDecode(std::string s)
+{
+ std::string result;
+
+ size_t pos = 0;
+ while (pos < s.size()) {
+ char c {s[pos]};
+ if (c == '+') {
+ result += ' ';
+ } else if (c == '%' && pos + 2 < s.size()) {
+ try {
+ int i = stoi(s.substr(pos + 1, 2), 0, 16);
+ if (i < 0 || i > 255)
+ return result;
+
+ result += static_cast<char>(i);
+ } catch (...) {
+ return result;
+ }
+
+ pos += 2;
+ } else {
+ result += c;
+ }
+ pos++;
+ }
+
+ return result;
+}
+
diff --git a/libcommon/url.h b/libcommon/url.h
new file mode 100644
index 0000000..bd60616
--- /dev/null
+++ b/libcommon/url.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include <string>
+
+std::string urlDecode(std::string s);
+
diff --git a/plugins/static-files/static-files.cpp b/plugins/static-files/static-files.cpp
index b2dcdca..ad78e48 100644
--- a/plugins/static-files/static-files.cpp
+++ b/plugins/static-files/static-files.cpp
@@ -1,6 +1,7 @@
#include "static-files.h"
#include "libcommon/mime.h"
+#include "libcommon/url.h"
#include <boost/algorithm/string/predicate.hpp>
@@ -81,7 +82,7 @@ std::string static_files_plugin::generate_page(
if (pos != target.npos)
target = target.substr(0, pos);
- std::string rel_target{GetRequestParam("rel_target")};
+ std::string rel_target{urlDecode(GetRequestParam("rel_target"))};
pos = rel_target.find('?');
if (pos != rel_target.npos)
rel_target = rel_target.substr(0, pos);
diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp
index 26d49c8..c8e4b38 100644
--- a/plugins/webbox/webbox.cpp
+++ b/plugins/webbox/webbox.cpp
@@ -4,6 +4,7 @@
#include "libcommon/tempfile.h"
#include "libcommon/file.h"
#include "libcommon/stringutil.h"
+#include "libcommon/url.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
@@ -45,36 +46,6 @@ namespace {
{ "500", "Internal Server Error" }
};
- std::string urlDecode(std::string s)
- {
- std::string result;
-
- size_t pos = 0;
- while (pos < s.size()) {
- char c {s[pos]};
- if (c == '+') {
- result += ' ';
- } else if (c == '%' && pos + 2 < s.size()) {
- try {
- int i = stoi(s.substr(pos + 1, 2), 0, 16);
- if (i < 0 || i > 255)
- return result;
-
- result += static_cast<char>(i);
- } catch (...) {
- return result;
- }
-
- pos += 2;
- } else {
- result += c;
- }
- pos++;
- }
-
- return result;
- }
-
std::unordered_map<std::string, std::string> ParseQueryString(const std::string& s, const std::string& webboxPath)
{
std::unordered_map<std::string, std::string> result;
@@ -376,7 +347,7 @@ protected:
virtual std::string start(CommandParameters& p)
{
p.m_SetResponseHeader("content_type", "text/plain");
- return p.m_GetServerParam("version") + "<br/>(C) 2020 <a href=\"https://www.reichwein.it/\">Reichwein.IT</a>";
+ return p.m_GetServerParam("version") + "<br/>(C) 2021 <a href=\"https://www.reichwein.it/\">Reichwein.IT</a>";
}
};
diff --git a/webserver.1 b/webserver.1
index 39da1eb..c1c4245 100644
--- a/webserver.1
+++ b/webserver.1
@@ -1,4 +1,4 @@
-.TH webserver 1 "30 April 2020" "Version 1.3" "Webserver Manual"
+.TH webserver 1 "30 April 2021" "Version 1.14" "Webserver Manual"
.SH NAME
webserver \- A small webserver
diff --git a/webserver.conf b/webserver.conf
index 9ff0b0e..5e97cd2 100644
--- a/webserver.conf
+++ b/webserver.conf
@@ -16,6 +16,8 @@
<host>ip6-localhost</host>
<host>127.0.0.1</host>
<host>[::1]</host>
+ <host>reichwein.mooo.com</host>
+ <host>[2001:a61:410:c001:5e51:4fff:fea2:ec7f]</address>
<path requested="/">
<plugin>static-files</plugin>
@@ -134,6 +136,12 @@
</socket>
<socket>
+ <address>2001:a61:410:c001:5e51:4fff:fea2:ec7f</address>
+ <port>80</port>
+ <protocol>http</protocol>
+ <site>antcom.de</site>
+ </socket>
+ <socket>
<address>::1</address>
<port>8080</port>
<protocol>http</protocol>