aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/upnp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/upnp')
-rw-r--r--src/db/upnp/ContentDirectoryService.cxx46
-rw-r--r--src/db/upnp/Directory.cxx4
-rw-r--r--src/db/upnp/Directory.hxx2
-rw-r--r--src/db/upnp/ixmlwrap.cxx4
-rw-r--r--src/db/upnp/ixmlwrap.hxx4
5 files changed, 33 insertions, 27 deletions
diff --git a/src/db/upnp/ContentDirectoryService.cxx b/src/db/upnp/ContentDirectoryService.cxx
index 337690a54..9349c1163 100644
--- a/src/db/upnp/ContentDirectoryService.cxx
+++ b/src/db/upnp/ContentDirectoryService.cxx
@@ -59,6 +59,16 @@ public:
}
};
+static bool
+ReadResultTag(UPnPDirContent &dirbuf, IXML_Document *response, Error &error)
+{
+ const char *p = ixmlwrap::getFirstElementValue(response, "Result");
+ if (p == nullptr)
+ p = "";
+
+ return dirbuf.parse(p, error);
+}
+
bool
ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
const char *objectId, int offset,
@@ -100,9 +110,9 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
DirBResFree cleaner(&response);
int didread = -1;
- std::string tbuf = ixmlwrap::getFirstElementValue(response, "NumberReturned");
- if (!tbuf.empty())
- didread = atoi(tbuf.c_str());
+ const char *value = ixmlwrap::getFirstElementValue(response, "NumberReturned");
+ if (value != nullptr)
+ didread = atoi(value);
if (count == -1 || count == 0) {
// TODO: what's this?
@@ -110,13 +120,11 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
return false;
}
- tbuf = ixmlwrap::getFirstElementValue(response, "TotalMatches");
- if (!tbuf.empty())
- *totalp = atoi(tbuf.c_str());
-
- tbuf = ixmlwrap::getFirstElementValue(response, "Result");
+ value = ixmlwrap::getFirstElementValue(response, "TotalMatches");
+ if (value != nullptr)
+ *totalp = atoi(value);
- if (!dirbuf.parse(tbuf, error))
+ if (!ReadResultTag(dirbuf, response, error))
return false;
*didreadp = didread;
@@ -189,10 +197,10 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
DirBResFree cleaner(&response);
int count = -1;
- std::string tbuf =
+ const char *value =
ixmlwrap::getFirstElementValue(response, "NumberReturned");
- if (!tbuf.empty())
- count = atoi(tbuf.c_str());
+ if (value != nullptr)
+ count = atoi(value);
if (count == -1 || count == 0) {
// TODO: what's this?
@@ -202,13 +210,11 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
offset += count;
- tbuf = ixmlwrap::getFirstElementValue(response, "TotalMatches");
- if (!tbuf.empty())
- total = atoi(tbuf.c_str());
-
- tbuf = ixmlwrap::getFirstElementValue(response, "Result");
+ value = ixmlwrap::getFirstElementValue(response, "TotalMatches");
+ if (value != nullptr)
+ total = atoi(value);
- if (!dirbuf.parse(tbuf, error))
+ if (!ReadResultTag(dirbuf, response, error))
return false;
}
@@ -291,7 +297,7 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
return false;
}
- std::string tbuf = ixmlwrap::getFirstElementValue(response, "Result");
+ bool success = ReadResultTag(dirbuf, response, error);
ixmlDocument_free(response);
- return dirbuf.parse(tbuf, error);
+ return success;
}
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index 00ce68816..b9c92dabd 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -186,8 +186,8 @@ protected:
};
bool
-UPnPDirContent::parse(const std::string &input, Error &error)
+UPnPDirContent::parse(const char *input, Error &error)
{
UPnPDirParser parser(*this);
- return parser.Parse(input.data(), input.length(), true, error);
+ return parser.Parse(input, strlen(input), true, error);
}
diff --git a/src/db/upnp/Directory.hxx b/src/db/upnp/Directory.hxx
index 80b52ff2b..8858c9325 100644
--- a/src/db/upnp/Directory.hxx
+++ b/src/db/upnp/Directory.hxx
@@ -58,7 +58,7 @@ public:
* actually global, nothing really bad will happen if you mix
* up...
*/
- bool parse(const std::string &didltext, Error &error);
+ bool parse(const char *didltext, Error &error);
};
#endif /* _UPNPDIRCONTENT_H_X_INCLUDED_ */
diff --git a/src/db/upnp/ixmlwrap.cxx b/src/db/upnp/ixmlwrap.cxx
index 2bc8658a3..6a2829cf9 100644
--- a/src/db/upnp/ixmlwrap.cxx
+++ b/src/db/upnp/ixmlwrap.cxx
@@ -19,10 +19,10 @@
namespace ixmlwrap {
-std::string
+const char *
getFirstElementValue(IXML_Document *doc, const char *name)
{
- std::string ret;
+ const char *ret = nullptr;
IXML_NodeList *nodes =
ixmlDocument_getElementsByTagName(doc, name);
diff --git a/src/db/upnp/ixmlwrap.hxx b/src/db/upnp/ixmlwrap.hxx
index 8677d691a..0d519a323 100644
--- a/src/db/upnp/ixmlwrap.hxx
+++ b/src/db/upnp/ixmlwrap.hxx
@@ -24,10 +24,10 @@
namespace ixmlwrap {
/**
* Retrieve the text content for the first element of given
- * name. Returns an empty string if the element does not
+ * name. Returns nullptr if the element does not
* contain a text node
*/
- std::string getFirstElementValue(IXML_Document *doc,
+ const char *getFirstElementValue(IXML_Document *doc,
const char *name);
};