Merge pull request #5095 from koying/fixdroidappcrash
[vuplus_xbmc] / xbmc / filesystem / DAVCommon.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "DAVCommon.h"
22 #include "utils/StringUtils.h"
23 #include "utils/log.h"   
24
25 using namespace XFILE;
26
27 /*
28  * Return true if pElement value is equal value without namespace.
29  *
30  * if pElement is <DAV:foo> and value is foo then ValueWithoutNamespace is true
31  */
32 bool CDAVCommon::ValueWithoutNamespace(const TiXmlNode *pNode, const std::string& value)
33 {
34   CStdStringArray tag;
35   const TiXmlElement *pElement;
36
37   if (!pNode)
38   {
39     return false;
40   }
41
42   pElement = pNode->ToElement();
43
44   if (!pElement)
45   {
46     return false;
47   }
48
49   StringUtils::SplitString(pElement->Value(), ":", tag, 2);
50
51   if (tag.size() == 1 && tag[0] == value)
52   {
53     return true;
54   }
55   else if (tag.size() == 2 && tag[1] == value)
56   {
57     return true;
58   }
59   else if (tag.size() > 2)
60   {
61     CLog::Log(LOGERROR, "%s - Splitting %s failed, size(): %lu, value: %s", __FUNCTION__, pElement->Value(), (unsigned long int)tag.size(), value.c_str());
62   }
63
64   return false;
65 }
66
67 /*
68  * Search for <status> and return its content
69  */
70 std::string CDAVCommon::GetStatusTag(const TiXmlElement *pElement)
71 {
72   const TiXmlElement *pChild;
73
74   for (pChild = pElement->FirstChild()->ToElement(); pChild != 0; pChild = pChild->NextSibling()->ToElement())
75   {
76     if (ValueWithoutNamespace(pChild, "status"))
77     {
78       return pChild->GetText();
79     }
80   }
81
82   return "";
83 }
84