HTTP repository testing tool.

This commit is contained in:
James Turner
2016-02-27 06:35:41 +02:00
parent 8adbefb2b7
commit 43dacf5951
2 changed files with 85 additions and 0 deletions

View File

@@ -73,6 +73,9 @@ add_test(http ${EXECUTABLE_OUTPUT_PATH}/test_http)
add_executable(httpget httpget.cxx)
target_link_libraries(httpget ${TEST_LIBS})
add_executable(http_repo_sync http_repo_sync.cxx)
target_link_libraries(http_repo_sync ${TEST_LIBS})
add_executable(decode_binobj decode_binobj.cxx)
target_link_libraries(decode_binobj ${TEST_LIBS})

View File

@@ -0,0 +1,82 @@
#include <cstdio>
#include <cstring>
#include <signal.h>
#include <iostream>
#include <boost/foreach.hpp>
#include <simgear/io/sg_file.hxx>
#include <simgear/io/HTTPClient.hxx>
#include <simgear/io/HTTPRepository.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/timing/timestamp.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/debug/logstream.hxx>
using namespace simgear;
using std::cout;
using std::endl;
using std::cerr;
using std::string;
int main(int argc, char* argv[])
{
HTTP::Client cl;
string proxy, proxyAuth;
string_list headers;
string url;
sglog().setLogLevels( SG_ALL, SG_INFO );
for (int a=0; a<argc;++a) {
if (argv[a][0] == '-') {
if (!strcmp(argv[a], "--proxy")) {
proxy = argv[++a];
} else if (!strcmp(argv[a], "--auth")) {
proxyAuth = argv[++a];
}
} else { // of argument starts with a hyphen
url = argv[a];
}
} // of arguments iteration
if (!proxy.empty()) {
int colonPos = proxy.find(':');
string proxyHost = proxy;
int proxyPort = 8800;
if (colonPos >= 0) {
proxyHost = proxy.substr(0, colonPos);
proxyPort = strutils::to_int(proxy.substr(colonPos + 1));
}
cl.setProxy(proxyHost, proxyPort, proxyAuth);
}
#ifndef WIN32
signal(SIGPIPE, SIG_IGN);
#endif
if (url.empty()) {
cerr << "no URL argument specificed" << endl;
return EXIT_FAILURE;
}
SGPath rootPath = simgear::Dir::current().path();
HTTPRepository* repo = new HTTPRepository(rootPath, &cl);
repo->setBaseUrl(url);
repo->update();
while (repo->isDoingSync()) {
cl.update();
SGTimeStamp::sleepForMSec(100);
}
if (repo->failure() != AbstractRepository::REPO_NO_ERROR) {
cerr << "got response:" << repo->failure() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}