Skip to content

Commit

Permalink
Merge pull request #4392 from sysown/v2.x-webui_fixes
Browse files Browse the repository at this point in the history
Several required fixes for the `WebInterfacePlugin`
  • Loading branch information
renecannao authored Dec 1, 2023
2 parents 5775b6a + c2d58b3 commit 91b04d5
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 3 deletions.
4 changes: 3 additions & 1 deletion deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a: libmicrohttpd/libmi
#endif
cd libhttpserver/libhttpserver && patch -p1 < ../final_val_post_process.patch
cd libhttpserver/libhttpserver && patch -p1 < ../empty_uri_log_crash.patch
cd libhttpserver/libhttpserver && patch -p0 < ../expose_raw_url.patch
cd libhttpserver/libhttpserver && patch -p0 < ../replace_static_global_strings.patch
ifeq ($(UNAME_S),FreeBSD)
sed -i -e 's/\/bin\/bash/\/usr\/local\/bin\/bash/' libhttpserver/libhttpserver/bootstrap
endif
cd libhttpserver/libhttpserver && ./bootstrap && mkdir build
cd libhttpserver/libhttpserver/build && LDFLAGS=-L$(shell pwd)/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/ CPPFLAGS=-I$(shell pwd)/libmicrohttpd/libmicrohttpd/src/include ../configure --disable-doxygen-doc --disable-doxygen-dot --disable-doxygen-man --disable-doxygen-html --enable-fastopen=false
cd libhttpserver/libhttpserver/build && LDFLAGS=-L$(shell pwd)/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/ CPPFLAGS=-I$(shell pwd)/libmicrohttpd/libmicrohttpd/src/include ../configure --disable-doxygen-doc --disable-doxygen-dot --disable-doxygen-man --disable-doxygen-html --enable-fastopen=false --disable-examples
cd libhttpserver/libhttpserver/build && CC=${CC} CXX=${CXX} ${MAKE}

libhttpserver: libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a
Expand Down
109 changes: 109 additions & 0 deletions deps/libhttpserver/expose_raw_url.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
diff --git src/httpserver/details/modded_request.hpp src/httpserver/details/modded_request.hpp
index 1ebe5b1..32d4154 100644
--- src/httpserver/details/modded_request.hpp
+++ src/httpserver/details/modded_request.hpp
@@ -38,6 +38,7 @@ struct modded_request
struct MHD_PostProcessor *pp = 0x0;
std::string* complete_uri = 0x0;
std::string* standardized_url = 0x0;
+ std::string* url = 0x0;
webserver* ws = 0x0;

const std::shared_ptr<http_response> (httpserver::http_resource::*callback)(const httpserver::http_request&);
@@ -65,6 +66,9 @@ struct modded_request
delete dhr; //TODO: verify. It could be an error
delete complete_uri;
delete standardized_url;
+ if (url) {
+ delete url;
+ }
}

};
diff --git src/httpserver/http_request.hpp src/httpserver/http_request.hpp
index 0b83fa2..419585d 100644
--- src/httpserver/http_request.hpp
+++ src/httpserver/http_request.hpp
@@ -77,6 +77,15 @@ class http_request
return path;
}

+ /**
+ * Method used to get the path requested
+ * @return string representing the path requested.
+ **/
+ const std::string& get_url() const
+ {
+ return url;
+ }
+
/**
* Method used to get all pieces of the path requested; considering an url splitted by '/'.
* @return a vector of strings containing all pieces
@@ -86,6 +95,22 @@ class http_request
return http::http_utils::tokenize_url(path);
}

+ /**
+ * Method used to get all pieces of the path requested; considering an url splitted by '/'.
+ * @return a vector of strings containing all pieces
+ **/
+ const std::vector<std::string> get_url_pieces() const
+ {
+ const std::vector<std::string> url_pieces { http::http_utils::tokenize_url(url) };
+ std::vector<std::string> dec_pieces { url_pieces };
+
+ for (std::string& p : dec_pieces) {
+ http::base_unescaper(p, nullptr);
+ }
+
+ return dec_pieces;
+ }
+
/**
* Method used to obtain a specified piece of the path; considering an url splitted by '/'.
* @param index the index of the piece selected
@@ -233,6 +258,7 @@ class http_request
http_request& operator=(http_request&& b) = default;

std::string path;
+ std::string url;
std::string method;
std::map<std::string, std::string, http::arg_comparator> args;
std::string content = "";
@@ -317,6 +343,15 @@ class http_request
this->path = path;
}

+ /**
+ * Sets the raw (unescaped) URL path. Used for 'get_pieces()'
+ * @param url The path searched by the request
+ **/
+ void set_url(const std::string& url)
+ {
+ this->url = url;
+ }
+
/**
* Method used to set the request METHOD
* @param method The method to set for the request
diff --git src/webserver.cpp src/webserver.cpp
index e7dd335..96e53b5 100644
--- src/webserver.cpp
+++ src/webserver.cpp
@@ -750,6 +750,7 @@ MHD_Result webserver::complete_request(
mr->ws = this;

mr->dhr->set_path(mr->standardized_url->c_str());
+ mr->dhr->set_url(mr->url->c_str());
mr->dhr->set_method(method);
mr->dhr->set_version(version);

@@ -793,6 +794,7 @@ MHD_Result webserver::answer_to_connection(void* cls, MHD_Connection* connection

base_unescaper(t_url, static_cast<webserver*>(cls)->unescaper);
mr->standardized_url = new string(http_utils::standardize_url(t_url));
+ mr->url = new string(url);

mr->has_body = false;

Loading

0 comments on commit 91b04d5

Please sign in to comment.