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
6e555522
Commit
6e555522
authored
Jan 18, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/ixmlwrap: getFirstElementValue() returns const char *
Eliminate the std::string bloat.
parent
e569f82d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
27 deletions
+33
-27
ContentDirectoryService.cxx
src/db/upnp/ContentDirectoryService.cxx
+26
-20
Directory.cxx
src/db/upnp/Directory.cxx
+2
-2
Directory.hxx
src/db/upnp/Directory.hxx
+1
-1
ixmlwrap.cxx
src/db/upnp/ixmlwrap.cxx
+2
-2
ixmlwrap.hxx
src/db/upnp/ixmlwrap.hxx
+2
-2
No files found.
src/db/upnp/ContentDirectoryService.cxx
View file @
6e555522
...
...
@@ -59,6 +59,16 @@ public:
}
};
static
bool
ReadResultTag
(
UPnPDirContent
&
dirbuf
,
IXML_Document
*
response
,
Error
&
error
)
{
const
char
*
p
=
ixmlwrap
::
getFirstElementValue
(
response
,
"Result"
);
if
(
p
==
nullptr
)
p
=
""
;
return
dirbuf
.
parse
(
p
,
error
);
}
bool
ContentDirectoryService
::
readDirSlice
(
UpnpClient_Handle
hdl
,
const
char
*
objectId
,
int
offset
,
...
...
@@ -100,9 +110,9 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
DirBResFree
cleaner
(
&
response
);
int
didread
=
-
1
;
std
::
string
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"NumberReturned"
);
if
(
!
tbuf
.
empty
()
)
didread
=
atoi
(
tbuf
.
c_str
()
);
const
char
*
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"NumberReturned"
);
if
(
value
!=
nullptr
)
didread
=
atoi
(
value
);
if
(
count
==
-
1
||
count
==
0
)
{
// TODO: what's this?
...
...
@@ -110,13 +120,11 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl,
return
false
;
}
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"TotalMatches"
);
if
(
!
tbuf
.
empty
())
*
totalp
=
atoi
(
tbuf
.
c_str
());
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"Result"
);
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"TotalMatches"
);
if
(
value
!=
nullptr
)
*
totalp
=
atoi
(
value
);
if
(
!
dirbuf
.
parse
(
tbuf
,
error
))
if
(
!
ReadResultTag
(
dirbuf
,
response
,
error
))
return
false
;
*
didreadp
=
didread
;
...
...
@@ -189,10 +197,10 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
DirBResFree
cleaner
(
&
response
);
int
count
=
-
1
;
std
::
string
tbuf
=
const
char
*
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"NumberReturned"
);
if
(
!
tbuf
.
empty
()
)
count
=
atoi
(
tbuf
.
c_str
()
);
if
(
value
!=
nullptr
)
count
=
atoi
(
value
);
if
(
count
==
-
1
||
count
==
0
)
{
// TODO: what's this?
...
...
@@ -202,13 +210,11 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
offset
+=
count
;
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"TotalMatches"
);
if
(
!
tbuf
.
empty
())
total
=
atoi
(
tbuf
.
c_str
());
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"Result"
);
value
=
ixmlwrap
::
getFirstElementValue
(
response
,
"TotalMatches"
);
if
(
value
!=
nullptr
)
total
=
atoi
(
value
);
if
(
!
dirbuf
.
parse
(
tbuf
,
error
))
if
(
!
ReadResultTag
(
dirbuf
,
response
,
error
))
return
false
;
}
...
...
@@ -291,7 +297,7 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
return
false
;
}
std
::
string
tbuf
=
ixmlwrap
::
getFirstElementValue
(
response
,
"Result"
);
bool
success
=
ReadResultTag
(
dirbuf
,
response
,
error
);
ixmlDocument_free
(
response
);
return
dirbuf
.
parse
(
tbuf
,
error
)
;
return
success
;
}
src/db/upnp/Directory.cxx
View file @
6e555522
...
...
@@ -186,8 +186,8 @@ protected:
};
bool
UPnPDirContent
::
parse
(
const
std
::
string
&
input
,
Error
&
error
)
UPnPDirContent
::
parse
(
const
char
*
input
,
Error
&
error
)
{
UPnPDirParser
parser
(
*
this
);
return
parser
.
Parse
(
input
.
data
(),
input
.
length
(
),
true
,
error
);
return
parser
.
Parse
(
input
,
strlen
(
input
),
true
,
error
);
}
src/db/upnp/Directory.hxx
View file @
6e555522
...
...
@@ -58,7 +58,7 @@ public:
* actually global, nothing really bad will happen if you mix
* up...
*/
bool
parse
(
const
std
::
string
&
didltext
,
Error
&
error
);
bool
parse
(
const
char
*
didltext
,
Error
&
error
);
};
#endif
/* _UPNPDIRCONTENT_H_X_INCLUDED_ */
src/db/upnp/ixmlwrap.cxx
View file @
6e555522
...
...
@@ -19,10 +19,10 @@
namespace
ixmlwrap
{
std
::
string
const
char
*
getFirstElementValue
(
IXML_Document
*
doc
,
const
char
*
name
)
{
std
::
string
ret
;
const
char
*
ret
=
nullptr
;
IXML_NodeList
*
nodes
=
ixmlDocument_getElementsByTagName
(
doc
,
name
);
...
...
src/db/upnp/ixmlwrap.hxx
View file @
6e555522
...
...
@@ -24,10 +24,10 @@
namespace
ixmlwrap
{
/**
* Retrieve the text content for the first element of given
* name. Returns
an empty string
if the element does not
* name. Returns
nullptr
if the element does not
* contain a text node
*/
std
::
string
getFirstElementValue
(
IXML_Document
*
doc
,
const
char
*
getFirstElementValue
(
IXML_Document
*
doc
,
const
char
*
name
);
};
...
...
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