Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
cd2f65aa
Commit
cd2f65aa
authored
Feb 06, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upnp/ContentDirectoryService: use AtScopeExit() for ixmlDocument_free()
For exception-safety.
parent
3ee5093b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
35 deletions
+36
-35
ContentDirectoryService.cxx
src/db/plugins/upnp/ContentDirectoryService.cxx
+36
-35
No files found.
src/db/plugins/upnp/ContentDirectoryService.cxx
View file @
cd2f65aa
...
...
@@ -21,12 +21,14 @@
#include "lib/upnp/ContentDirectoryService.hxx"
#include "lib/upnp/Domain.hxx"
#include "lib/upnp/ixmlwrap.hxx"
#include "lib/upnp/UniqueIxml.hxx"
#include "lib/upnp/Action.hxx"
#include "Directory.hxx"
#include "util/NumberParser.hxx"
#include "util/UriUtil.hxx"
#include "util/RuntimeError.hxx"
#include "util/Error.hxx"
#include "util/ScopeExit.hxx"
#include <stdio.h>
...
...
@@ -63,14 +65,17 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
if
(
request
==
nullptr
)
throw
std
::
runtime_error
(
"UpnpMakeAction() failed"
);
AtScopeExit
(
request
)
{
ixmlDocument_free
(
request
);
};
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
)
throw
FormatRuntimeError
(
"UpnpSendAction() failed: %s"
,
UpnpGetErrorMessage
(
code
));
AtScopeExit
(
response
)
{
ixmlDocument_free
(
response
);
};
const
char
*
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"NumberReturned"
);
didreadp
=
value
!=
nullptr
?
ParseUnsigned
(
value
)
...
...
@@ -80,9 +85,7 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
if
(
value
!=
nullptr
)
totalp
=
ParseUnsigned
(
value
);
bool
success
=
ReadResultTag
(
dirbuf
,
response
,
error
);
ixmlDocument_free
(
response
);
return
success
;
return
ReadResultTag
(
dirbuf
,
response
,
error
);
}
bool
...
...
@@ -117,41 +120,42 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
char
ofbuf
[
100
];
sprintf
(
ofbuf
,
"%d"
,
offset
);
IXML_Document
*
request
=
MakeActionHelper
(
"Search"
,
m_serviceType
.
c_str
(),
"ContainerID"
,
objectId
,
"SearchCriteria"
,
ss
,
"Filter"
,
"*"
,
"SortCriteria"
,
""
,
"StartingIndex"
,
ofbuf
,
"RequestedCount"
,
"0"
);
// Setting a value here gets twonky into fits
if
(
request
==
0
)
UniqueIxmlDocument
request
(
MakeActionHelper
(
"Search"
,
m_serviceType
.
c_str
(),
"ContainerID"
,
objectId
,
"SearchCriteria"
,
ss
,
"Filter"
,
"*"
,
"SortCriteria"
,
""
,
"StartingIndex"
,
ofbuf
,
"RequestedCount"
,
"0"
));
// Setting a value here gets twonky into fits
if
(
!
request
)
throw
std
::
runtime_error
(
"UpnpMakeAction() failed"
);
IXML_Document
*
response
;
IXML_Document
*
_
response
;
auto
code
=
UpnpSendAction
(
hdl
,
m_actionURL
.
c_str
(),
m_serviceType
.
c_str
(),
0
/*devUDN*/
,
request
,
&
response
);
ixmlDocument_free
(
request
);
0
/*devUDN*/
,
request
.
get
(),
&
_response
);
if
(
code
!=
UPNP_E_SUCCESS
)
throw
FormatRuntimeError
(
"UpnpSendAction() failed: %s"
,
UpnpGetErrorMessage
(
code
));
UniqueIxmlDocument
response
(
_response
);
const
char
*
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"NumberReturned"
);
ixmlwrap
::
getFirstElementValue
(
response
.
get
(),
"NumberReturned"
);
count
=
value
!=
nullptr
?
ParseUnsigned
(
value
)
:
0
;
offset
+=
count
;
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"TotalMatches"
);
value
=
ixmlwrap
::
getFirstElementValue
(
response
.
get
(),
"TotalMatches"
);
if
(
value
!=
nullptr
)
total
=
ParseUnsigned
(
value
);
bool
success
=
ReadResultTag
(
dirbuf
,
response
,
error
);
ixmlDocument_free
(
response
);
if
(
!
success
)
if
(
!
ReadResultTag
(
dirbuf
,
response
.
get
(),
error
))
return
false
;
}
while
(
count
>
0
&&
offset
<
total
);
...
...
@@ -165,27 +169,24 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
Error
&
error
)
const
{
// Create request
IXML_Document
*
request
=
MakeActionHelper
(
"Browse"
,
m_serviceType
.
c_str
(),
"ObjectID"
,
objectId
,
"BrowseFlag"
,
"BrowseMetadata"
,
"Filter"
,
"*"
,
"SortCriteria"
,
""
,
"StartingIndex"
,
"0"
,
"RequestedCount"
,
"1"
);
UniqueIxmlDocument
request
(
MakeActionHelper
(
"Browse"
,
m_serviceType
.
c_str
(),
"ObjectID"
,
objectId
,
"BrowseFlag"
,
"BrowseMetadata"
,
"Filter"
,
"*"
,
"SortCriteria"
,
""
,
"StartingIndex"
,
"0"
,
"RequestedCount"
,
"1"
));
if
(
request
==
nullptr
)
throw
std
::
runtime_error
(
"UpnpMakeAction() failed"
);
IXML_Document
*
response
;
IXML_Document
*
_
response
;
auto
code
=
UpnpSendAction
(
hdl
,
m_actionURL
.
c_str
(),
m_serviceType
.
c_str
(),
0
/*devUDN*/
,
request
,
&
response
);
ixmlDocument_free
(
request
);
0
/*devUDN*/
,
request
.
get
(),
&
_response
);
if
(
code
!=
UPNP_E_SUCCESS
)
throw
FormatRuntimeError
(
"UpnpSendAction() failed: %s"
,
UpnpGetErrorMessage
(
code
));
bool
success
=
ReadResultTag
(
dirbuf
,
response
,
error
);
ixmlDocument_free
(
response
);
return
success
;
UniqueIxmlDocument
response
(
_response
);
return
ReadResultTag
(
dirbuf
,
response
.
get
(),
error
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment