Commit 1a4940bb authored by Max Kellermann's avatar Max Kellermann

db/upnp: free IXML_Document *request manually

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