diff options
author | Max Kellermann <max@duempel.org> | 2014-01-18 15:01:19 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-18 15:01:19 +0100 |
commit | 6e55552292d4832bcefeee78346d121caf3715a1 (patch) | |
tree | 2869e0e8898e57c97d3a56d395db9463acd1f484 /src/db/upnp/ContentDirectoryService.cxx | |
parent | e569f82dd33ff0f7488e34bbb7e46d601c1ed672 (diff) | |
download | mpd-6e55552292d4832bcefeee78346d121caf3715a1.tar.gz mpd-6e55552292d4832bcefeee78346d121caf3715a1.tar.xz mpd-6e55552292d4832bcefeee78346d121caf3715a1.zip |
db/upnp/ixmlwrap: getFirstElementValue() returns const char *
Eliminate the std::string bloat.
Diffstat (limited to '')
-rw-r--r-- | src/db/upnp/ContentDirectoryService.cxx | 46 |
1 files changed, 26 insertions, 20 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; } |