summaryrefslogtreecommitdiff
path: root/test/interactive-helper
diff options
context:
space:
mode:
Diffstat (limited to 'test/interactive-helper')
-rw-r--r--test/interactive-helper/aptwebserver.cc84
-rw-r--r--test/interactive-helper/extract-control.cc5
-rw-r--r--test/interactive-helper/mthdcat.cc2
-rw-r--r--test/interactive-helper/rpmver.cc11
-rw-r--r--test/interactive-helper/test_udevcdrom.cc8
-rw-r--r--test/interactive-helper/testdeb.cc16
6 files changed, 80 insertions, 46 deletions
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc
index b7663a76a..34476e1af 100644
--- a/test/interactive-helper/aptwebserver.cc
+++ b/test/interactive-helper/aptwebserver.cc
@@ -1,29 +1,31 @@
#include <config.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/error.h>
#include <apt-pkg/cmndline.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/init.h>
-
-#include <vector>
-#include <string>
-#include <list>
-#include <sstream>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <regex.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#include <errno.h>
#include <time.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <signal.h>
+#include <unistd.h>
+#include <iostream>
+#include <sstream>
+#include <list>
+#include <string>
+#include <vector>
-char const * const httpcodeToStr(int const httpcode) /*{{{*/
+static char const * httpcodeToStr(int const httpcode) /*{{{*/
{
switch (httpcode)
{
@@ -77,7 +79,7 @@ char const * const httpcodeToStr(int const httpcode) /*{{{*/
return NULL;
}
/*}}}*/
-void addFileHeaders(std::list<std::string> &headers, FileFd &data) /*{{{*/
+static void addFileHeaders(std::list<std::string> &headers, FileFd &data)/*{{{*/
{
std::ostringstream contentlength;
contentlength << "Content-Length: " << data.FileSize();
@@ -88,14 +90,14 @@ void addFileHeaders(std::list<std::string> &headers, FileFd &data) /*{{{*/
headers.push_back(lastmodified);
}
/*}}}*/
-void addDataHeaders(std::list<std::string> &headers, std::string &data) /*{{{*/
+static void addDataHeaders(std::list<std::string> &headers, std::string &data)/*{{{*/
{
std::ostringstream contentlength;
contentlength << "Content-Length: " << data.size();
headers.push_back(contentlength.str());
}
/*}}}*/
-bool sendHead(int const client, int const httpcode, std::list<std::string> &headers)/*{{{*/
+static bool sendHead(int const client, int const httpcode, std::list<std::string> &headers)/*{{{*/
{
std::string response("HTTP/1.1 ");
response.append(httpcodeToStr(httpcode));
@@ -128,7 +130,7 @@ bool sendHead(int const client, int const httpcode, std::list<std::string> &head
return Success;
}
/*}}}*/
-bool sendFile(int const client, FileFd &data) /*{{{*/
+static bool sendFile(int const client, FileFd &data) /*{{{*/
{
bool Success = true;
char buffer[500];
@@ -144,7 +146,7 @@ bool sendFile(int const client, FileFd &data) /*{{{*/
return Success;
}
/*}}}*/
-bool sendData(int const client, std::string const &data) /*{{{*/
+static bool sendData(int const client, std::string const &data) /*{{{*/
{
if (FileFd::Write(client, data.c_str(), data.size()) == false)
{
@@ -154,7 +156,7 @@ bool sendData(int const client, std::string const &data) /*{{{*/
return true;
}
/*}}}*/
-void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/
+static void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/
bool content, std::string const &error = "")
{
std::list<std::string> headers;
@@ -179,13 +181,13 @@ void sendError(int const client, int const httpcode, std::string const &request,
if (content == true)
sendData(client, response);
}
-void sendSuccess(int const client, std::string const &request,
+static void sendSuccess(int const client, std::string const &request,
bool content, std::string const &error = "")
{
sendError(client, 200, request, content, error);
}
/*}}}*/
-void sendRedirect(int const client, int const httpcode, std::string const &uri,/*{{{*/
+static void sendRedirect(int const client, int const httpcode, std::string const &uri,/*{{{*/
std::string const &request, bool content)
{
std::list<std::string> headers;
@@ -197,9 +199,14 @@ void sendRedirect(int const client, int const httpcode, std::string const &uri,/
response.append(request).append("</pre></body></html>");
addDataHeaders(headers, response);
std::string location("Location: ");
- if (strncmp(uri.c_str(), "http://", 7) != 0)
+ if (strncmp(uri.c_str(), "http://", 7) != 0 && strncmp(uri.c_str(), "https://", 8) != 0)
{
- location.append("http://").append(LookupTag(request, "Host")).append("/");
+ std::string const host = LookupTag(request, "Host");
+ if (host.find(":4433") != std::string::npos)
+ location.append("https://");
+ else
+ location.append("http://");
+ location.append(host).append("/");
if (strncmp("/home/", uri.c_str(), strlen("/home/")) == 0 && uri.find("/public_html/") != std::string::npos)
{
std::string homeuri = SubstVar(uri, "/home/", "~");
@@ -217,7 +224,7 @@ void sendRedirect(int const client, int const httpcode, std::string const &uri,/
sendData(client, response);
}
/*}}}*/
-int filter_hidden_files(const struct dirent *a) /*{{{*/
+static int filter_hidden_files(const struct dirent *a) /*{{{*/
{
if (a->d_name[0] == '.')
return 0;
@@ -231,7 +238,7 @@ int filter_hidden_files(const struct dirent *a) /*{{{*/
#endif
return 1;
}
-int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
+static int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
#ifdef _DIRENT_HAVE_D_TYPE
if ((*a)->d_type == DT_DIR && (*b)->d_type == DT_DIR);
else if ((*a)->d_type == DT_DIR && (*b)->d_type == DT_REG)
@@ -255,7 +262,7 @@ int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
return strcasecmp((*a)->d_name, (*b)->d_name);
}
/*}}}*/
-void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
+static void sendDirectoryListing(int const client, std::string const &dir,/*{{{*/
std::string const &request, bool content)
{
std::list<std::string> headers;
@@ -307,7 +314,7 @@ void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
sendData(client, response);
}
/*}}}*/
-bool parseFirstLine(int const client, std::string const &request, /*{{{*/
+static bool parseFirstLine(int const client, std::string const &request,/*{{{*/
std::string &filename, std::string &params, bool &sendContent,
bool &closeConnection)
{
@@ -427,7 +434,7 @@ bool parseFirstLine(int const client, std::string const &request, /*{{{*/
return true;
}
/*}}}*/
-bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> const &parts)/*{{{*/
+static bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> const &parts)/*{{{*/
{
size_t const pcount = parts.size();
if (pcount == 4 && parts[1] == "set")
@@ -470,7 +477,7 @@ bool handleOnTheFlyReconfiguration(int const client, std::string const &request,
return false;
}
/*}}}*/
-void * handleClient(void * voidclient) /*{{{*/
+static void * handleClient(void * voidclient) /*{{{*/
{
int client = *((int*)(voidclient));
std::clog << "ACCEPT client " << client << std::endl;
@@ -507,7 +514,8 @@ void * handleClient(void * voidclient) /*{{{*/
std::string redirect = "/" + filename;
for (::Configuration::Item *I = Replaces->Child; I != NULL; I = I->Next)
redirect = SubstVar(redirect, I->Tag, I->Value);
- redirect.erase(0,1);
+ if (redirect.empty() == false && redirect[0] == '/')
+ redirect.erase(0,1);
if (redirect != filename)
{
sendRedirect(client, 301, redirect, *m, sendContent);
@@ -542,7 +550,13 @@ void * handleClient(void * voidclient) /*{{{*/
}
// deal with the request
- if (RealFileExists(filename) == true)
+ if (_config->FindB("aptwebserver::support::http", true) == false &&
+ LookupTag(*m, "Host").find(":4433") == std::string::npos)
+ {
+ sendError(client, 400, *m, sendContent, "HTTP disabled, all requests must be HTTPS");
+ continue;
+ }
+ else if (RealFileExists(filename) == true)
{
FileFd data(filename, FileFd::ReadOnly);
std::string condition = LookupTag(*m, "If-Modified-Since", "");
diff --git a/test/interactive-helper/extract-control.cc b/test/interactive-helper/extract-control.cc
index 3f7feabcb..852ec4ee9 100644
--- a/test/interactive-helper/extract-control.cc
+++ b/test/interactive-helper/extract-control.cc
@@ -1,13 +1,16 @@
+#include <config.h>
+
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
-bool ExtractMember(const char *File,const char *Member)
+static bool ExtractMember(const char *File,const char *Member)
{
FileFd Fd(File,FileFd::ReadOnly);
debDebFile Deb(Fd);
diff --git a/test/interactive-helper/mthdcat.cc b/test/interactive-helper/mthdcat.cc
index 25d09a3f5..2961b2080 100644
--- a/test/interactive-helper/mthdcat.cc
+++ b/test/interactive-helper/mthdcat.cc
@@ -2,6 +2,8 @@
All this does is cat a file into the method without closing the FD when
the file ends */
+#include <config.h>
+
#include <unistd.h>
int main()
diff --git a/test/interactive-helper/rpmver.cc b/test/interactive-helper/rpmver.cc
index 9fc807de8..017c92fba 100644
--- a/test/interactive-helper/rpmver.cc
+++ b/test/interactive-helper/rpmver.cc
@@ -1,7 +1,10 @@
+#include <config.h>
+
#include <apt-pkg/debversion.h>
#include <rpm/rpmio.h>
#include <rpm/misc.h>
#include <stdlib.h>
+#include <stdio.h>
#include <ctype.h>
#define xisdigit(x) isdigit(x)
@@ -12,10 +15,8 @@ using namespace std;
int rpmvercmp(const char * a, const char * b)
{
- char oldch1, oldch2;
char * str1, * str2;
char * one, * two;
- int rc;
int isnum;
/* easy comparison to see if versions are identical */
@@ -53,9 +54,9 @@ int rpmvercmp(const char * a, const char * b)
/* save character at the end of the alpha or numeric segment */
/* so that they can be restored after the comparison */
- oldch1 = *str1;
+ char oldch1 = *str1;
*str1 = '\0';
- oldch2 = *str2;
+ char oldch2 = *str2;
*str2 = '\0';
/* take care of the case where the two version segments are */
@@ -81,7 +82,7 @@ int rpmvercmp(const char * a, const char * b)
/* segments are alpha or if they are numeric. don't return */
/* if they are equal because there might be more segments to */
/* compare */
- rc = strcmp(one, two);
+ int rc = strcmp(one, two);
if (rc) return rc;
/* restore character that was replaced by null above */
diff --git a/test/interactive-helper/test_udevcdrom.cc b/test/interactive-helper/test_udevcdrom.cc
index 88f5f0153..b87dcd935 100644
--- a/test/interactive-helper/test_udevcdrom.cc
+++ b/test/interactive-helper/test_udevcdrom.cc
@@ -1,7 +1,10 @@
+#include <config.h>
+
#include <apt-pkg/cdrom.h>
-#include <stdio.h>
-#include <assert.h>
+#include <stddef.h>
+#include <string>
+#include <assert.h>
#include <vector>
#include <iostream>
@@ -17,5 +20,4 @@ int main()
std::cerr << l[i].DeviceName << " "
<< l[i].Mounted << " "
<< l[i].MountPath << std::endl;
-
}
diff --git a/test/interactive-helper/testdeb.cc b/test/interactive-helper/testdeb.cc
index d28f20114..6aae9f563 100644
--- a/test/interactive-helper/testdeb.cc
+++ b/test/interactive-helper/testdeb.cc
@@ -1,15 +1,22 @@
+#include <config.h>
+
#include <apt-pkg/dirstream.h>
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/extracttar.h>
+#include <apt-pkg/arfile.h>
+#include <apt-pkg/fileutl.h>
+
+#include <iostream>
+#include <string>
class NullStream : public pkgDirStream
{
public:
- virtual bool DoItem(Item &Itm,int &Fd) {return true;};
+ virtual bool DoItem(Item &/*Itm*/, int &/*Fd*/) {return true;};
};
-bool Test(const char *File)
+static bool Test(const char *File)
{
FileFd Fd(File,FileFd::ReadOnly);
debDebFile Deb(Fd);
@@ -33,6 +40,11 @@ bool Test(const char *File)
int main(int argc, const char *argv[])
{
+ if (argc != 2) {
+ std::cout << "One parameter expected - given " << argc << std::endl;
+ return 100;
+ }
+
Test(argv[1]);
_error->DumpErrors();
return 0;