]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/DAVMultiStatus.cxx
Lots of (mostly) doxygen fixes/cleanup.
[simgear.git] / simgear / io / DAVMultiStatus.cxx
index 54c23870ed0eb5e38d6665a0977a377d2a30d74f..a805a214a5a4b76056ff28d00fe4b075be0152e1 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+     
 #include "DAVMultiStatus.hxx"
 
 #include <iostream>
 #include <boost/foreach.hpp>
 
 #include "simgear/debug/logstream.hxx"
-#include "simgear/xml/xmlparse.h"
 #include "simgear/misc/strutils.hxx"
 #include "simgear/structure/exception.hxx"
 
-using std::cout;
-using std::cerr;
-using std::endl;
+#ifdef SYSTEM_EXPAT
+#  include <expat.h>
+#else
+#  include "sg_expat.h"     
+#endif
+
 using std::string;
 
 using namespace simgear;
@@ -61,7 +67,10 @@ DAVResource::DAVResource(const string& href) :
   _url(href),
   _container(NULL)
 {
-    assert(!href.empty()); 
+    assert(!href.empty());
+    if (strutils::ends_with(href, "/")) {
+        _url = href.substr(0, _url.size() - 1);
+    }
 }
 
 void DAVResource::setVersionName(const std::string& aVersion)
@@ -113,13 +122,6 @@ void DAVCollection::addChild(DAVResource *res)
   
   assert(res->container() == NULL);
   assert(std::find(_contents.begin(), _contents.end(), res) == _contents.end());
-  
-  if (!strutils::starts_with(res->url(), _url)) {
-      std::cerr << "us: " << _url << std::endl;
-      std::cerr << "child:" << res->url() << std::endl;
-      
-  }
-  
   assert(strutils::starts_with(res->url(), _url));
   assert(childWithUrl(res->url()) == NULL);
   
@@ -181,7 +183,8 @@ class DAVMultiStatus::DAVMultiStatusPrivate
 {
 public:
   DAVMultiStatusPrivate() :
-  parserInited(false)
+      parserInited(false),
+      valid(false)
   {
     rootResource = NULL;
   }
@@ -276,7 +279,7 @@ public:
   
   string tagN(const unsigned int n) const
   {
-    int sz = tagStack.size();
+    size_t sz = tagStack.size();
     if (n >= sz) {
       return string();
     }
@@ -285,6 +288,7 @@ public:
   }
   
   bool parserInited;
+  bool valid;
   XML_Parser xmlParser;
   DAVResource* rootResource;
   
@@ -364,13 +368,21 @@ void DAVMultiStatus::parseXML(const char* data, int size)
     
     XML_ParserFree(_d->xmlParser);
     _d->parserInited = false;
+    _d->valid = false;
   }
 }
 
 void DAVMultiStatus::finishParse()
 {
   if (_d->parserInited) {
-    XML_Parse(_d->xmlParser, NULL, 0, true);
+    if (!XML_Parse(_d->xmlParser, NULL, 0, true)) {
+        SG_LOG(SG_IO, SG_WARN, "DAV parse error:" << XML_ErrorString(XML_GetErrorCode(_d->xmlParser))
+               << " at line:" << XML_GetCurrentLineNumber(_d->xmlParser)
+               << " column " << XML_GetCurrentColumnNumber(_d->xmlParser));
+        _d->valid = false;
+    } else {
+        _d->valid = true;
+    }
     XML_ParserFree(_d->xmlParser);
   }
   
@@ -382,4 +394,9 @@ DAVResource* DAVMultiStatus::resource()
   return _d->rootResource;
 }
 
+bool DAVMultiStatus::isValid() const
+{
+    return _d->valid;
+}
+