From e1ae0531bfad0fce8590c26d1e38825df22d812a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 24 Nov 2016 12:14:39 +0100 Subject: optional write aptwebserver log to client specific files The test test-handle-redirect-as-used-mirror-change serves multiple clients at the same time, so the order of the output is undefined and once in a while the two clients will intermix their lines causing the grep we perform on it later to fail making our tests fail. Solved by introducing client-specific logfiles which we all grep and sort the result to have the results more stable. Git-Dch: Ignore --- test/interactive-helper/aptwebserver.cc | 155 +++++++++++++++----------------- test/interactive-helper/teestream.h | 62 +++++++++++++ 2 files changed, 136 insertions(+), 81 deletions(-) create mode 100644 test/interactive-helper/teestream.h (limited to 'test/interactive-helper') diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc index 950a17bc1..4b98cbd7c 100644 --- a/test/interactive-helper/aptwebserver.cc +++ b/test/interactive-helper/aptwebserver.cc @@ -6,6 +6,8 @@ #include #include +#include "teestream.h" + #include #include #include @@ -22,9 +24,11 @@ #include #include +#include #include #include #include +#include #include static std::string httpcodeToStr(int const httpcode) /*{{{*/ @@ -114,7 +118,7 @@ static void addDataHeaders(std::list &headers, std::string &data)/* } } /*}}}*/ -static bool sendHead(int const client, int const httpcode, std::list &headers)/*{{{*/ +static bool sendHead(std::ostream &log, int const client, int const httpcode, std::list &headers)/*{{{*/ { std::string response("HTTP/1.1 "); response.append(httpcodeToStr(httpcode)); @@ -137,7 +141,7 @@ static bool sendHead(int const client, int const httpcode, std::list>> RESPONSE to " << client << " >>>" << std::endl; + log << ">>> RESPONSE to " << client << " >>>" << std::endl; bool Success = true; for (std::list::const_iterator h = headers.begin(); Success == true && h != headers.end(); ++h) @@ -145,11 +149,11 @@ static bool sendHead(int const client, int const httpcode, std::listc_str(), h->size()); if (Success == true) Success &= FileFd::Write(client, "\r\n", 2); - std::clog << *h << std::endl; + log << *h << std::endl; } if (Success == true) Success &= FileFd::Write(client, "\r\n", 2); - std::clog << "<<<<<<<<<<<<<<<<" << std::endl; + log << "<<<<<<<<<<<<<<<<" << std::endl; return Success; } /*}}}*/ @@ -209,7 +213,7 @@ static bool sendData(int const client, std::list const &headers, st return true; } /*}}}*/ -static void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/ +static void sendError(std::ostream &log, int const client, int const httpcode, std::string const &request,/*{{{*/ bool const content, std::string const &error, std::list &headers) { std::string response(""); @@ -234,18 +238,18 @@ static void sendError(int const client, int const httpcode, std::string const &r headers.push_back("Connection: close"); } addDataHeaders(headers, response); - sendHead(client, httpcode, headers); + sendHead(log, client, httpcode, headers); if (content == true) sendData(client, headers, response); } -static void sendSuccess(int const client, std::string const &request, +static void sendSuccess(std::ostream &log, int const client, std::string const &request, bool const content, std::string const &error, std::list<std::string> &headers) { - sendError(client, 200, request, content, error, headers); + sendError(log, client, 200, request, content, error, headers); } /*}}}*/ -static void sendRedirect(int const client, int const httpcode, std::string const &uri,/*{{{*/ - std::string const &request, bool content) +static void sendRedirect(std::ostream &log, int const client, int const httpcode,/*{{{*/ + std::string const &uri, std::string const &request, bool content) { std::list<std::string> headers; std::string response("<!doctype html><html><head><title>"); @@ -279,7 +283,7 @@ static void sendRedirect(int const client, int const httpcode, std::string const else location.append(uri); headers.push_back(location); - sendHead(client, httpcode, headers); + sendHead(log, client, httpcode, headers); if (content == true) sendData(client, headers, response); } @@ -322,19 +326,18 @@ static int grouped_alpha_case_sort(const struct dirent **a, const struct dirent return strcasecmp((*a)->d_name, (*b)->d_name); } /*}}}*/ -static void sendDirectoryListing(int const client, std::string const &dir,/*{{{*/ +static void sendDirectoryListing(std::ostream &log, int const client, std::string const &dir,/*{{{*/ std::string const &request, bool content, std::list<std::string> &headers) { - std::ostringstream listing; - struct dirent **namelist; int const counter = scandir(dir.c_str(), &namelist, filter_hidden_files, grouped_alpha_case_sort); if (counter == -1) { - sendError(client, 500, request, content, "scandir failed", headers); + sendError(log, client, 500, request, content, "scandir failed", headers); return; } + std::ostringstream listing; listing << "<!doctype html><html><head><title>Index of " << dir << "" << "