]> git.mxchange.org Git - simgear.git/commitdiff
HTTP repository testing tool.
authorJames Turner <zakalawe@mac.com>
Sat, 27 Feb 2016 04:35:41 +0000 (06:35 +0200)
committerJames Turner <zakalawe@mac.com>
Sat, 27 Feb 2016 04:35:41 +0000 (06:35 +0200)
simgear/io/CMakeLists.txt
simgear/io/http_repo_sync.cxx [new file with mode: 0644]

index cfe6c7fd784d1a59ded5e0e309fb5b1a5962fad8..3e8775655243e3b4eb5542630785da36bd50540d 100644 (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})
 
diff --git a/simgear/io/http_repo_sync.cxx b/simgear/io/http_repo_sync.cxx
new file mode 100644 (file)
index 0000000..f8186b4
--- /dev/null
@@ -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;
+}