]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/httpget.cxx
cppbind.Ghost: clean up a bit
[simgear.git] / simgear / io / httpget.cxx
index 513bb4b22feea91243b7454dccb290d285e1da28..876ba14ff9aa9f4bf52cc882db99d30a8be54153 100644 (file)
@@ -1,15 +1,18 @@
 
 #include <cstdio>
 #include <cstring>
+#include <signal.h>
 
-#include <unistd.h> // for STDOUT_FILENO
 #include <iostream>
 #include <boost/foreach.hpp>
 
+
 #include <simgear/io/sg_file.hxx>
 #include <simgear/io/HTTPClient.hxx>
 #include <simgear/io/HTTPRequest.hxx>
 #include <simgear/io/sg_netChannel.hxx>
+#include <simgear/misc/strutils.hxx>
+#include <simgear/timing/timestamp.hxx>
 
 using namespace simgear;
 using std::cout;
@@ -45,35 +48,11 @@ public:
         }
         
         string key = h.substr(0, colonPos);
-        _headers[key] = h.substr(colonPos + 1);
+        requestHeader(key) = h.substr(colonPos + 1);
     }
     
-    virtual string_list requestHeaders() const
-    {
-        string_list r;
-        std::map<string, string>::const_iterator it;
-        for (it = _headers.begin(); it != _headers.end(); ++it) {
-            r.push_back(it->first);
-        }
-        
-        return r;
-    }
-    
-    virtual string header(const string& name) const
-    {
-        std::map<string, string>::const_iterator it = _headers.find(name);
-        if (it == _headers.end()) {
-            return string();
-        }
-        
-        return it->second;
-    }
 protected:
-    virtual void responseHeadersComplete()
-    {
-    }
-
-    virtual void responseComplete()
+    virtual void onDone()
     {
         _complete = true;
     }  
@@ -85,13 +64,12 @@ protected:
 private:    
     bool _complete;
     SGFile* _file;
-    std::map<string, string> _headers;
 };
 
 int main(int argc, char* argv[])
 {
     HTTP::Client cl;
-    SGFile* outFile;
+    SGFile* outFile = 0;
     string proxy, proxyAuth;
     string_list headers;
     string url;
@@ -119,11 +97,23 @@ int main(int argc, char* argv[])
     } // of arguments iteration
 
     if (!proxy.empty()) {
-        cl.setProxy(proxy, proxyAuth);
+        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 (!outFile) {
-        outFile = new SGFile(STDOUT_FILENO);
+        outFile = new SGFile(fileno(stdout));
     }
 
     if (url.empty()) {
@@ -140,9 +130,10 @@ int main(int argc, char* argv[])
     cl.makeRequest(req);
     
     while (!req->complete()) {
-        NetChannel::poll(100);
+        cl.update();
+        SGTimeStamp::sleepForMSec(100);
     }
-    
+        
     if (req->responseCode() != 200) {
         cerr << "got response:" << req->responseCode() << endl;
         cerr << "\treason:" << req->responseReason() << endl;