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 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 d48c847..060e7ea 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -16,9 +16,9 @@ #include #include -#include #include #include +#include #include using std::string; @@ -27,40 +27,36 @@ using std::cout; using std::uint32_t; using std::system; -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)); + const uint32_t length = message.length() + 2; + cout.write(reinterpret_cast(&length), sizeof(uint32_t)); cout << '"' << message << '"'; } @@ -78,40 +74,18 @@ int launch(const string &args) int main() { - string args = read_input(); - // size_t pos = args.find("TEMPFILE"); - // string tmpfile; + const string args = read_input(); - // 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; - // } - // } - - int ret = launch(args); + const 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; 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: {