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
9747cc9e
Commit
9747cc9e
authored
Jan 22, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Device: replace std::vector with a std::string pointer
parent
7b44dea4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
47 deletions
+50
-47
Device.cxx
src/db/upnp/Device.cxx
+37
-34
Util.cxx
src/db/upnp/Util.cxx
+11
-10
Util.hxx
src/db/upnp/Util.hxx
+2
-3
No files found.
src/db/upnp/Device.cxx
View file @
9747cc9e
...
...
@@ -33,61 +33,64 @@
*/
class
UPnPDeviceParser
final
:
public
CommonExpatParser
{
UPnPDevice
&
m_device
;
std
::
vector
<
std
::
string
>
m_path
;
std
::
string
*
value
;
UPnPService
m_tservice
;
public
:
UPnPDeviceParser
(
UPnPDevice
&
device
)
:
m_device
(
device
)
{}
:
m_device
(
device
),
value
(
nullptr
)
{}
protected
:
virtual
void
StartElement
(
const
XML_Char
*
name
,
const
XML_Char
**
)
{
m_path
.
push_back
(
name
);
}
virtual
void
EndElement
(
const
XML_Char
*
name
)
{
if
(
!
strcmp
(
name
,
"service"
))
{
m_device
.
services
.
emplace_back
(
std
::
move
(
m_tservice
));
m_tservice
.
clear
();
}
m_path
.
pop_back
();
}
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
{
const
auto
&
current
=
m_path
.
back
();
std
::
string
str
=
trimstring
(
s
,
len
);
switch
(
current
[
0
])
{
switch
(
name
[
0
])
{
case
'c'
:
if
(
!
current
.
compare
(
"controlURL"
)
)
m_tservice
.
controlURL
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"controlURL"
)
==
0
)
value
=
&
m_tservice
.
controlURL
;
break
;
case
'd'
:
if
(
!
current
.
compare
(
"deviceType"
)
)
m_device
.
deviceType
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"deviceType"
)
==
0
)
value
=
&
m_device
.
deviceType
;
break
;
case
'f'
:
if
(
!
current
.
compare
(
"friendlyName"
)
)
m_device
.
friendlyName
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"friendlyName"
)
==
0
)
value
=
&
m_device
.
friendlyName
;
break
;
case
'm'
:
if
(
!
current
.
compare
(
"manufacturer"
)
)
m_device
.
manufacturer
=
std
::
move
(
str
)
;
else
if
(
!
current
.
compare
(
"modelName"
)
)
m_device
.
modelName
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"manufacturer"
)
==
0
)
value
=
&
m_device
.
manufacturer
;
else
if
(
strcmp
(
name
,
"modelName"
)
==
0
)
value
=
&
m_device
.
modelName
;
break
;
case
's'
:
if
(
!
current
.
compare
(
"serviceType"
)
)
m_tservice
.
serviceType
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"serviceType"
)
==
0
)
value
=
&
m_tservice
.
serviceType
;
break
;
case
'U'
:
if
(
!
current
.
compare
(
"UDN"
)
)
m_device
.
UDN
=
std
::
move
(
str
)
;
else
if
(
!
current
.
compare
(
"URLBase"
)
)
m_device
.
URLBase
=
std
::
move
(
str
)
;
if
(
strcmp
(
name
,
"UDN"
)
==
0
)
value
=
&
m_device
.
UDN
;
else
if
(
strcmp
(
name
,
"URLBase"
)
==
0
)
value
=
&
m_device
.
URLBase
;
break
;
}
}
virtual
void
EndElement
(
const
XML_Char
*
name
)
{
if
(
value
!=
nullptr
)
{
trimstring
(
*
value
);
value
=
nullptr
;
}
else
if
(
!
strcmp
(
name
,
"service"
))
{
m_device
.
services
.
emplace_back
(
std
::
move
(
m_tservice
));
m_tservice
.
clear
();
}
}
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
{
if
(
value
!=
nullptr
)
value
->
append
(
s
,
len
);
}
};
bool
...
...
src/db/upnp/Util.cxx
View file @
9747cc9e
...
...
@@ -18,7 +18,6 @@
*/
#include "Util.hxx"
#include "util/CharUtil.hxx"
#include <string>
#include <map>
...
...
@@ -28,17 +27,19 @@
#include <upnp/ixml.h>
/** Get rid of white space at both ends */
std
::
string
trimstring
(
const
char
*
p
,
size_t
length
)
void
trimstring
(
std
::
string
&
s
,
const
char
*
ws
)
{
while
(
length
>
0
&&
IsWhitespaceOrNull
(
p
[
length
-
1
]))
--
length
;
const
char
*
end
=
p
+
length
;
while
(
p
!=
end
&&
IsWhitespaceOrNull
(
*
p
))
++
p
;
auto
pos
=
s
.
find_first_not_of
(
ws
);
if
(
pos
==
std
::
string
::
npos
)
{
s
.
clear
();
return
;
}
s
.
replace
(
0
,
pos
,
std
::
string
())
;
return
std
::
string
(
p
,
end
);
pos
=
s
.
find_last_not_of
(
ws
);
if
(
pos
!=
std
::
string
::
npos
&&
pos
!=
s
.
length
()
-
1
)
s
.
replace
(
pos
+
1
,
std
::
string
::
npos
,
std
::
string
());
}
std
::
string
...
...
src/db/upnp/Util.hxx
View file @
9747cc9e
...
...
@@ -28,9 +28,8 @@
std
::
string
caturl
(
const
std
::
string
&
s1
,
const
std
::
string
&
s2
);
gcc_pure
std
::
string
trimstring
(
const
char
*
p
,
size_t
length
);
void
trimstring
(
std
::
string
&
s
,
const
char
*
ws
=
"
\t\n
"
);
std
::
string
path_getfather
(
const
std
::
string
&
s
);
...
...
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