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
f097952b
Commit
f097952b
authored
Feb 06, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/upnp: use std::unique_ptr
parent
224d5116
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
30 deletions
+66
-30
Makefile.am
Makefile.am
+1
-0
ContentDirectoryService.cxx
src/lib/upnp/ContentDirectoryService.cxx
+14
-16
UniqueIxml.hxx
src/lib/upnp/UniqueIxml.hxx
+40
-0
ixmlwrap.cxx
src/lib/upnp/ixmlwrap.cxx
+11
-14
No files found.
Makefile.am
View file @
f097952b
...
...
@@ -244,6 +244,7 @@ UPNP_SOURCES = \
src/lib/upnp/ixmlwrap.cxx src/lib/upnp/ixmlwrap.hxx
\
src/lib/upnp/Callback.hxx
\
src/lib/upnp/Util.cxx src/lib/upnp/Util.hxx
\
src/lib/upnp/UniqueIxml.hxx
\
src/lib/upnp/WorkQueue.hxx
\
src/lib/upnp/Action.hxx
...
...
src/lib/upnp/ContentDirectoryService.cxx
View file @
f097952b
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "ContentDirectoryService.hxx"
#include "UniqueIxml.hxx"
#include "Domain.hxx"
#include "Device.hxx"
#include "ixmlwrap.hxx"
...
...
@@ -56,20 +57,18 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl,
{
assert
(
result
.
empty
());
IXML_Document
*
request
=
UpnpMakeAction
(
"GetSearchCapabilities"
,
m_serviceType
.
c_str
(),
0
,
nullptr
,
nullptr
);
if
(
request
==
0
)
{
UniqueIxmlDocument
request
(
UpnpMakeAction
(
"GetSearchCapabilities"
,
m_serviceType
.
c_str
(),
0
,
nullptr
,
nullptr
));
if
(
!
request
)
{
error
.
Set
(
upnp_domain
,
"UpnpMakeAction() failed"
);
return
false
;
}
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
)
{
error
.
Format
(
upnp_domain
,
code
,
"UpnpSendAction() failed: %s"
,
...
...
@@ -77,18 +76,17 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl,
return
false
;
}
const
char
*
s
=
ixmlwrap
::
getFirstElementValue
(
response
,
"SearchCaps"
);
if
(
s
==
nullptr
||
*
s
==
0
)
{
ixmlDocument_free
(
response
);
UniqueIxmlDocument
response
(
_response
);
const
char
*
s
=
ixmlwrap
::
getFirstElementValue
(
response
.
get
(),
"SearchCaps"
);
if
(
s
==
nullptr
||
*
s
==
0
)
return
true
;
}
bool
success
=
true
;
if
(
!
csvToStrings
(
s
,
result
))
{
error
.
Set
(
upnp_domain
,
"Bad response"
);
success
=
false
;
return
false
;
}
ixmlDocument_free
(
response
);
return
success
;
return
true
;
}
src/lib/upnp/UniqueIxml.hxx
0 → 100644
View file @
f097952b
/*
* Copyright (C) 2003-2016 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_UPNP_UNIQUE_XML_HXX
#define MPD_UPNP_UNIQUE_XML_HXX
#include <upnp/ixml.h>
#include <memory>
struct
UpnpIxmlDeleter
{
void
operator
()(
IXML_Document
*
doc
)
{
ixmlDocument_free
(
doc
);
}
void
operator
()(
IXML_NodeList
*
nl
)
{
ixmlNodeList_free
(
nl
);
}
};
typedef
std
::
unique_ptr
<
IXML_Document
,
UpnpIxmlDeleter
>
UniqueIxmlDocument
;
typedef
std
::
unique_ptr
<
IXML_NodeList
,
UpnpIxmlDeleter
>
UniqueIxmlNodeList
;
#endif
src/lib/upnp/ixmlwrap.cxx
View file @
f097952b
...
...
@@ -16,29 +16,26 @@
*/
#include "ixmlwrap.hxx"
#include "UniqueIxml.hxx"
namespace
ixmlwrap
{
const
char
*
getFirstElementValue
(
IXML_Document
*
doc
,
const
char
*
name
)
{
const
char
*
ret
=
nullptr
;
IXML_NodeList
*
nodes
=
ixmlDocument_getElementsByTagName
(
doc
,
name
)
;
UniqueIxmlNodeList
nodes
(
ixmlDocument_getElementsByTagName
(
doc
,
name
))
;
if
(
!
nodes
)
return
nullptr
;
if
(
nodes
)
{
IXML_Node
*
first
=
ixmlNodeList_item
(
nodes
,
0
);
if
(
first
)
{
IXML_Node
*
dnode
=
ixmlNode_getFirstChild
(
first
);
if
(
dnode
)
{
ret
=
ixmlNode_getNodeValue
(
dnode
);
}
}
IXML_Node
*
first
=
ixmlNodeList_item
(
nodes
.
get
(),
0
);
if
(
!
first
)
return
nullptr
;
ixmlNodeList_free
(
nodes
);
}
IXML_Node
*
dnode
=
ixmlNode_getFirstChild
(
first
);
if
(
!
dnode
)
return
nullptr
;
return
ret
;
return
ixmlNode_getNodeValue
(
dnode
)
;
}
}
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