From 8db8f97bde88ac1c62c0602415e785568bcd9182 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 20:58:25 +0200 Subject: [PATCH 1/6] Add tab_with to EditorConfig. --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 1100de0..66c443a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ root = true [*] indent_style = space indent_size = 4 +tab_width = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From d746b8c2663f97cafaf4a2da5f6bf293f2dd4db5 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 20:58:59 +0200 Subject: [PATCH 2/6] Remove obsolete code from wrapper. --- .../native-wrapper/remwharead_wrapper.cpp | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index d48c847..5972644 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -78,40 +78,18 @@ int launch(const string &args) int main() { - string args = read_input(); - // size_t pos = args.find("TEMPFILE"); - // string tmpfile; - - // if (pos != string::npos) - // { - // try - // { - // tmpfile = fs::temp_directory_path() / "remwharead.html"; - // args.replace(pos, 8, tmpfile); - // } - // catch (const fs::filesystem_error &e) - // { - // send_message("Could not create temporary file."); - // return 3; - // } - // } + const string args = read_input(); int ret = launch(args); if (ret == 0) { - // if (!tmpfile.empty()) - // { - // send_message("FILE:" + tmpfile); - // } - // else - // { - send_message("Command successful."); - // } + send_message("Command successful."); } else { - send_message("Command failed with status: " + std::to_string(ret) + '.'); + send_message("Command failed with status: " + + std::to_string(ret) + '.'); } return ret; From 7ac7bd2edb51b4eda918bb1d7e9f167570ff4c8a Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 21:59:46 +0200 Subject: [PATCH 3/6] Make reading input in wrapper more robust. We read the size of the message now instead of getting everything between quotes. --- .../native-wrapper/remwharead_wrapper.cpp | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 5972644..e1aadd0 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include using std::string; @@ -31,36 +32,34 @@ namespace fs = std::experimental::filesystem; const string read_input() { + // Read message length. + uint32_t length; + char buffer[4]; + + cin.read(buffer, sizeof(uint32_t)); + std::memcpy(&length, buffer, 4); + + // Ignore quotes. + length -= 2; + cin.ignore(1); + + // Read message. string input; char c; - bool start = false; - while (cin.read(&c, 1).good()) + for (; length > 0; --length) { - if (!start) - { - if (c == '"') - { - start = true; - } - continue; - } - if (c != '"') - { - input += c; - } - else - { - break; - } + cin.read(&c, 1); + input += c; } + return input; } void send_message(const string &message) { uint32_t length = message.length() + 2; - cout.write(reinterpret_cast(&length), sizeof(length)); + cout.write(reinterpret_cast(&length), sizeof(uint32_t)); cout << '"' << message << '"'; } From d5b07b51c737b4f2b8e74f79ea383e41781ad1f0 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 22:04:35 +0200 Subject: [PATCH 4/6] Remove filesystem from wrapper. It was a leftover from an obsolete feature. --- browser-plugins/webextension/native-wrapper/CMakeLists.txt | 2 -- .../webextension/native-wrapper/remwharead_wrapper.cpp | 3 --- 2 files changed, 5 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/CMakeLists.txt b/browser-plugins/webextension/native-wrapper/CMakeLists.txt index 7896ae9..f6e58f3 100644 --- a/browser-plugins/webextension/native-wrapper/CMakeLists.txt +++ b/browser-plugins/webextension/native-wrapper/CMakeLists.txt @@ -2,8 +2,6 @@ set(INSTALL_MOZILLA_NMH_DIR "${CMAKE_INSTALL_PREFIX}/${MOZILLA_NMH_DIR}") add_executable(${PROJECT_NAME}_wrapper ${PROJECT_NAME}_wrapper.cpp) -target_link_libraries(${PROJECT_NAME}_wrapper PRIVATE stdc++fs) - install(TARGETS ${PROJECT_NAME}_wrapper DESTINATION ${MOZILLA_NMH_DIR}) configure_file("${PROJECT_NAME}.json.in" diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index e1aadd0..93bbded 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -28,8 +27,6 @@ using std::cout; using std::uint32_t; using std::system; -namespace fs = std::experimental::filesystem; - const string read_input() { // Read message length. From ab3085023bae898b679af6528eeabb01153d85fa Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 22:05:44 +0200 Subject: [PATCH 5/6] Mark numbers in wrapper const if possible. --- .../webextension/native-wrapper/remwharead_wrapper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 93bbded..060e7ea 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -55,7 +55,7 @@ const string read_input() void send_message(const string &message) { - uint32_t length = message.length() + 2; + const uint32_t length = message.length() + 2; cout.write(reinterpret_cast(&length), sizeof(uint32_t)); cout << '"' << message << '"'; } @@ -76,7 +76,7 @@ int main() { const string args = read_input(); - int ret = launch(args); + const int ret = launch(args); if (ret == 0) { From e3744058634af1d577da48e080c4cf2a5c93e2b9 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 22 Sep 2019 23:43:46 +0200 Subject: [PATCH 6/6] Retain archive-flag on HTTP redirects. --- src/lib/uri.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index 02ed9ca..45020f7 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -186,7 +186,7 @@ namespace remwharead location = poco_uri.getScheme() + "://" + poco_uri.getHost() + location; } - return make_request(location); + return make_request(location, archive); } case HTTPResponse::HTTP_OK: {