Merge branch 'develop' into main

This commit is contained in:
tastytea 2019-09-22 23:45:41 +02:00
commit c8598fca42
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 26 additions and 53 deletions

View File

@ -6,6 +6,7 @@ root = true
[*] [*]
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
tab_width = 4
end_of_line = lf end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true

View File

@ -2,8 +2,6 @@ set(INSTALL_MOZILLA_NMH_DIR "${CMAKE_INSTALL_PREFIX}/${MOZILLA_NMH_DIR}")
add_executable(${PROJECT_NAME}_wrapper ${PROJECT_NAME}_wrapper.cpp) 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}) install(TARGETS ${PROJECT_NAME}_wrapper DESTINATION ${MOZILLA_NMH_DIR})
configure_file("${PROJECT_NAME}.json.in" configure_file("${PROJECT_NAME}.json.in"

View File

@ -16,9 +16,9 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <experimental/filesystem>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <sys/wait.h> #include <sys/wait.h>
using std::string; using std::string;
@ -27,40 +27,36 @@ using std::cout;
using std::uint32_t; using std::uint32_t;
using std::system; using std::system;
namespace fs = std::experimental::filesystem;
const string read_input() 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; string input;
char c; char c;
bool start = false; for (; length > 0; --length)
while (cin.read(&c, 1).good())
{ {
if (!start) cin.read(&c, 1);
{ input += c;
if (c == '"')
{
start = true;
}
continue;
}
if (c != '"')
{
input += c;
}
else
{
break;
}
} }
return input; return input;
} }
void send_message(const string &message) void send_message(const string &message)
{ {
uint32_t length = message.length() + 2; const uint32_t length = message.length() + 2;
cout.write(reinterpret_cast<const char*>(&length), sizeof(length)); cout.write(reinterpret_cast<const char*>(&length), sizeof(uint32_t));
cout << '"' << message << '"'; cout << '"' << message << '"';
} }
@ -78,40 +74,18 @@ int launch(const string &args)
int main() int main()
{ {
string args = read_input(); const string args = read_input();
// size_t pos = args.find("TEMPFILE");
// string tmpfile;
// if (pos != string::npos) const int ret = launch(args);
// {
// 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);
if (ret == 0) if (ret == 0)
{ {
// if (!tmpfile.empty()) send_message("Command successful.");
// {
// send_message("FILE:" + tmpfile);
// }
// else
// {
send_message("Command successful.");
// }
} }
else else
{ {
send_message("Command failed with status: " + std::to_string(ret) + '.'); send_message("Command failed with status: "
+ std::to_string(ret) + '.');
} }
return ret; return ret;

View File

@ -186,7 +186,7 @@ namespace remwharead
location = poco_uri.getScheme() + "://" + poco_uri.getHost() location = poco_uri.getScheme() + "://" + poco_uri.getHost()
+ location; + location;
} }
return make_request(location); return make_request(location, archive);
} }
case HTTPResponse::HTTP_OK: case HTTPResponse::HTTP_OK:
{ {