db/upnp: free IXML_Document *request manually

This commit is contained in:
Max Kellermann 2014-01-18 14:38:52 +01:00
parent 22dd3c8048
commit 1a4940bbda
1 changed files with 40 additions and 38 deletions

View File

@ -49,13 +49,11 @@ ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device,
class DirBResFree {
public:
IXML_Document **rqpp, **rspp;
DirBResFree(IXML_Document** _rqpp, IXML_Document **_rspp)
:rqpp(_rqpp), rspp(_rspp) {}
IXML_Document **rspp;
DirBResFree(IXML_Document **_rspp)
:rspp(_rspp) {}
~DirBResFree()
{
if (*rqpp)
ixmlDocument_free(*rqpp);
if (*rspp)
ixmlDocument_free(*rspp);
}
@ -68,17 +66,14 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
int *didreadp, int *totalp,
Error &error)
{
IXML_Document *request(0);
IXML_Document *response(0);
DirBResFree cleaner(&request, &response);
// Create request
char ofbuf[100], cntbuf[100];
sprintf(ofbuf, "%d", offset);
sprintf(cntbuf, "%d", count);
int argcnt = 6;
// Some devices require an empty SortCriteria, else bad params
request = UpnpMakeAction("Browse", m_serviceType.c_str(), argcnt,
IXML_Document *request =
UpnpMakeAction("Browse", m_serviceType.c_str(), argcnt,
"ObjectID", objectId,
"BrowseFlag", "BrowseDirectChildren",
"Filter", "*",
@ -91,8 +86,10 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
return false;
}
IXML_Document *response;
int code = UpnpSendAction(hdl, m_actionURL.c_str(), m_serviceType.c_str(),
0 /*devUDN*/, request, &response);
ixmlDocument_free(request);
if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code,
"UpnpSendAction() failed: %s",
@ -100,6 +97,8 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
return false;
}
DirBResFree cleaner(&response);
int didread = -1;
std::string tbuf = ixmlwrap::getFirstElementValue(response, "NumberReturned");
if (!tbuf.empty())
@ -152,19 +151,17 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
UPnPDirContent &dirbuf,
Error &error)
{
IXML_Document *request(0);
IXML_Document *response(0);
int offset = 0;
int total = 1000;// Updated on first read.
while (offset < total) {
DirBResFree cleaner(&request, &response);
char ofbuf[100];
sprintf(ofbuf, "%d", offset);
// Create request
int argcnt = 6;
request = UpnpMakeAction("Search", m_serviceType.c_str(), argcnt,
IXML_Document *request =
UpnpMakeAction("Search", m_serviceType.c_str(), argcnt,
"ContainerID", objectId,
"SearchCriteria", ss,
"Filter", "*",
@ -177,9 +174,11 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
return false;
}
IXML_Document *response;
auto code = UpnpSendAction(hdl, m_actionURL.c_str(),
m_serviceType.c_str(),
0 /*devUDN*/, request, &response);
ixmlDocument_free(request);
if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code,
"UpnpSendAction() failed: %s",
@ -187,6 +186,8 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
return false;
}
DirBResFree cleaner(&response);
int count = -1;
std::string tbuf =
ixmlwrap::getFirstElementValue(response, "NumberReturned");
@ -219,10 +220,8 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl,
std::set<std::string> &result,
Error &error)
{
IXML_Document *request(0);
IXML_Document *response(0);
request = UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(),
IXML_Document *request =
UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(),
0,
nullptr, nullptr);
if (request == 0) {
@ -230,9 +229,11 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl,
return false;
}
IXML_Document *response;
auto code = UpnpSendAction(hdl, m_actionURL.c_str(),
m_serviceType.c_str(),
0 /*devUDN*/, request, &response);
ixmlDocument_free(request);
if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code,
"UpnpSendAction() failed: %s",
@ -241,6 +242,7 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl,
}
std::string tbuf = ixmlwrap::getFirstElementValue(response, "SearchCaps");
ixmlDocument_free(response);
result.clear();
if (!tbuf.compare("*")) {
@ -261,8 +263,6 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
UPnPDirContent &dirbuf,
Error &error)
{
IXML_Document *response(0);
// Create request
int argcnt = 6;
IXML_Document *request =
@ -274,15 +274,16 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
"StartingIndex", "0",
"RequestedCount", "1",
nullptr, nullptr);
DirBResFree cleaner(&request, &response);
if (request == nullptr) {
error.Set(upnp_domain, "UpnpMakeAction() failed");
return false;
}
IXML_Document *response;
auto code = UpnpSendAction(hdl, m_actionURL.c_str(),
m_serviceType.c_str(),
0 /*devUDN*/, request, &response);
ixmlDocument_free(request);
if (code != UPNP_E_SUCCESS) {
error.Format(upnp_domain, code,
"UpnpSendAction() failed: %s",
@ -291,5 +292,6 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
}
std::string tbuf = ixmlwrap::getFirstElementValue(response, "Result");
ixmlDocument_free(response);
return dirbuf.parse(tbuf, error);
}