]> git.mxchange.org Git - simgear.git/blobdiff - simgear/package/Catalog.cxx
Tweak HTTP code to always sleep.
[simgear.git] / simgear / package / Catalog.cxx
index 9a7a71f1909c3fdb434f79b41692addf0717b8df..160d2fbf7cc45e917853c4289c93c04c02fa07d4 100644 (file)
@@ -50,17 +50,12 @@ public:
     }
     
 protected:
-    virtual void responseHeadersComplete()
-    {
-        
-    }
-    
     virtual void gotBodyData(const char* s, int n)
     {
         m_buffer += std::string(s, n);
     }
     
-    virtual void responseComplete()
+    virtual void onDone()
     {        
         if (responseCode() != 200) {
             SG_LOG(SG_GENERAL, SG_ALERT, "catalog download failure:" << m_owner->url());
@@ -80,7 +75,7 @@ protected:
         }
         
         std::string ver(m_owner->root()->catalogVersion());
-        if (props->getStringValue("version") != ver) {
+        if (!checkVersion(ver, props)) {
             SG_LOG(SG_GENERAL, SG_WARN, "downloaded catalog " << m_owner->url() << ", version mismatch:\n\t"
                    << props->getStringValue("version") << " vs required " << ver);
             m_owner->refreshComplete(Delegate::FAIL_VERSION);
@@ -101,6 +96,16 @@ protected:
     }
     
 private:
+    bool checkVersion(const std::string& aVersion, SGPropertyNode* aProps)
+    {
+        BOOST_FOREACH(SGPropertyNode* v, aProps->getChildren("version")) {
+            if (v->getStringValue() == aVersion) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     Catalog* m_owner;  
     std::string m_buffer;
 };
@@ -129,7 +134,7 @@ Catalog* Catalog::createFromUrl(Root* aRoot, const std::string& aUrl)
 {
     Catalog* c = new Catalog(aRoot);
     Downloader* dl = new Downloader(c, aUrl);
-    aRoot->getHTTPClient()->makeRequest(dl);
+    aRoot->makeHTTPRequest(dl);
     
     return c;
 }
@@ -195,7 +200,7 @@ Catalog::packagesNeedingUpdate() const
 void Catalog::refresh()
 {
     Downloader* dl = new Downloader(this, url());
-    m_root->getHTTPClient()->makeRequest(dl);
+    m_root->makeHTTPRequest(dl);
     m_root->catalogRefreshBegin(this);
 }
 
@@ -280,6 +285,12 @@ unsigned int Catalog::ageInSeconds() const
     return (diff < 0) ? 0 : diff;
 }
 
+bool Catalog::needsRefresh() const
+{
+    unsigned int maxAge = m_props->getIntValue("max-age-sec", m_root->maxAgeSeconds());
+    return (ageInSeconds() > maxAge);
+}
+    
 std::string Catalog::getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const
 {
     if (aRoot->hasChild(m_root->getLocale())) {