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
efdb41f2
Commit
efdb41f2
authored
Jan 14, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Object: add attribute "name"
Call titleToPathElt() only once for each object.
parent
26b850c1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
24 deletions
+33
-24
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+5
-19
Directory.cxx
src/db/upnp/Directory.cxx
+20
-3
Object.hxx
src/db/upnp/Object.hxx
+8
-2
No files found.
src/db/UpnpDatabasePlugin.cxx
View file @
efdb41f2
...
...
@@ -40,7 +40,6 @@
#include "Log.hxx"
#include "SongFilter.hxx"
#include <algorithm>
#include <string>
#include <vector>
#include <map>
...
...
@@ -210,19 +209,6 @@ UpnpDatabase::ReturnSong(Song *song) const
song
->
Free
();
}
/**
* Transform titles to turn '/' into '_' to make them acceptable path
* elements. There is a very slight risk of collision in doing
* this. Twonky returns directory names (titles) like 'Artist/Album'.
*/
gcc_pure
static
std
::
string
titleToPathElt
(
std
::
string
s
)
{
std
::
replace
(
s
.
begin
(),
s
.
end
(),
'/'
,
'_'
);
return
s
;
}
// If uri is empty, we use the object's url instead. This happens
// when the target of a Visit() is a song, which only happens when
// "add"ing AFAIK. Visit() calls us with a null uri so that the url
...
...
@@ -528,7 +514,7 @@ UpnpDatabase::BuildPath(ContentDirectoryService *server,
if
(
!
ReadNode
(
server
,
pid
,
dirent
,
error
))
return
false
;
pid
=
dirent
.
m_pid
.
c_str
();
path
=
titleToPathElt
(
dirent
.
m_title
)
+
(
path
.
empty
()
?
""
:
"/"
+
path
);
path
=
dirent
.
name
+
(
path
.
empty
()
?
""
:
"/"
+
path
);
}
path
=
std
::
string
(
server
->
getFriendlyName
())
+
"/"
+
path
;
return
true
;
...
...
@@ -563,7 +549,7 @@ UpnpDatabase::Namei(ContentDirectoryService* server,
// Look for the name in the sub-container list
for
(
auto
&
dirent
:
dirbuf
.
m_containers
)
{
if
(
!
vpath
[
i
].
compare
(
titleToPathElt
(
dirent
.
m_title
)
))
{
if
(
!
vpath
[
i
].
compare
(
dirent
.
name
))
{
objid
=
dirent
.
m_id
;
// Next readdir target
found
=
true
;
if
(
i
==
vpath
.
size
()
-
1
)
{
...
...
@@ -581,7 +567,7 @@ UpnpDatabase::Namei(ContentDirectoryService* server,
// Path elt was not a container, look at the items list
for
(
auto
&
dirent
:
dirbuf
.
m_items
)
{
if
(
!
vpath
[
i
].
compare
(
titleToPathElt
(
dirent
.
m_title
)
))
{
if
(
!
vpath
[
i
].
compare
(
dirent
.
name
))
{
// If this is the last path elt, we found the target,
// else it does not exist
if
(
i
==
vpath
.
size
()
-
1
)
{
...
...
@@ -689,7 +675,7 @@ UpnpDatabase::VisitServer(ContentDirectoryService* server,
if
(
visit_directory
)
{
for
(
auto
&
dirent
:
dirbuf
.
m_containers
)
{
Directory
d
((
selection
.
uri
+
"/"
+
titleToPathElt
(
dirent
.
m_title
)
).
c_str
(),
dirent
.
name
).
c_str
(),
m_root
);
if
(
!
visit_directory
(
d
,
error
))
return
false
;
...
...
@@ -709,7 +695,7 @@ UpnpDatabase::VisitServer(ContentDirectoryService* server,
std
::
string
p
;
if
(
!
selection
.
recursive
)
p
=
selection
.
uri
+
"/"
+
titleToPathElt
(
dirent
.
m_title
)
;
dirent
.
name
;
if
(
!
visitSong
(
dirent
,
p
.
c_str
(),
selection
,
visit_song
,
error
))
...
...
src/db/upnp/Directory.cxx
View file @
efdb41f2
...
...
@@ -22,6 +22,7 @@
#include "Util.hxx"
#include "Expat.hxx"
#include <algorithm>
#include <string>
#include <vector>
...
...
@@ -58,6 +59,19 @@ ParseDuration(const std::string &duration)
}
/**
* Transform titles to turn '/' into '_' to make them acceptable path
* elements. There is a very slight risk of collision in doing
* this. Twonky returns directory names (titles) like 'Artist/Album'.
*/
gcc_pure
static
std
::
string
titleToPathElt
(
std
::
string
s
)
{
std
::
replace
(
s
.
begin
(),
s
.
end
(),
'/'
,
'_'
);
return
s
;
}
/**
* An XML parser which builds directory contents from DIDL lite input.
*/
class
UPnPDirParser
final
:
public
CommonExpatParser
{
...
...
@@ -125,7 +139,7 @@ protected:
bool
checkobjok
()
{
if
(
m_tobj
.
m_id
.
empty
()
||
m_tobj
.
m_pid
.
empty
()
||
m_tobj
.
m_titl
e
.
empty
()
||
m_tobj
.
nam
e
.
empty
()
||
(
m_tobj
.
type
==
UPnPDirObject
::
Type
::
ITEM
&&
m_tobj
.
item_class
==
UPnPDirObject
::
ItemClass
::
UNKNOWN
))
return
false
;
...
...
@@ -154,8 +168,11 @@ protected:
trimstring
(
str
);
switch
(
m_path
.
back
()[
0
])
{
case
'd'
:
if
(
!
m_path
.
back
().
compare
(
"dc:title"
))
m_tobj
.
m_title
+=
str
;
if
(
!
m_path
.
back
().
compare
(
"dc:title"
))
{
m_tobj
.
m_title
=
str
;
m_tobj
.
name
=
titleToPathElt
(
str
);
}
break
;
case
'r'
:
if
(
!
m_path
.
back
().
compare
(
"res"
))
{
...
...
src/db/upnp/Object.hxx
View file @
efdb41f2
...
...
@@ -52,6 +52,12 @@ public:
std
::
string
m_id
;
// ObjectId
std
::
string
m_pid
;
// Parent ObjectId
std
::
string
url
;
/**
* A copy of "dc:title" sanitized as a file name.
*/
std
::
string
name
;
std
::
string
m_title
;
// dc:title. Directory name for a container.
Type
type
;
ItemClass
item_class
;
...
...
@@ -71,8 +77,8 @@ public:
* @param[out] value
* @return true if found.
*/
const
char
*
getprop
(
const
char
*
name
)
const
{
auto
it
=
m_props
.
find
(
name
);
const
char
*
getprop
(
const
char
*
_
name
)
const
{
auto
it
=
m_props
.
find
(
_
name
);
if
(
it
==
m_props
.
end
())
return
nullptr
;
return
it
->
second
.
c_str
();
...
...
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