db/upnp/Device: replace std::vector with a std::string pointer
This commit is contained in:
parent
7b44dea4b1
commit
9747cc9e58
@ -33,60 +33,63 @@
|
|||||||
*/
|
*/
|
||||||
class UPnPDeviceParser final : public CommonExpatParser {
|
class UPnPDeviceParser final : public CommonExpatParser {
|
||||||
UPnPDevice &m_device;
|
UPnPDevice &m_device;
|
||||||
std::vector<std::string> m_path;
|
|
||||||
|
std::string *value;
|
||||||
|
|
||||||
UPnPService m_tservice;
|
UPnPService m_tservice;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPnPDeviceParser(UPnPDevice& device)
|
UPnPDeviceParser(UPnPDevice& device)
|
||||||
:m_device(device) {}
|
:m_device(device),
|
||||||
|
value(nullptr) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void StartElement(const XML_Char *name, const XML_Char **) {
|
virtual void StartElement(const XML_Char *name, const XML_Char **) {
|
||||||
m_path.push_back(name);
|
switch (name[0]) {
|
||||||
|
case 'c':
|
||||||
|
if (strcmp(name, "controlURL") == 0)
|
||||||
|
value = &m_tservice.controlURL;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
if (strcmp(name, "deviceType") == 0)
|
||||||
|
value = &m_device.deviceType;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
if (strcmp(name, "friendlyName") == 0)
|
||||||
|
value = &m_device.friendlyName;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
if (strcmp(name, "manufacturer") == 0)
|
||||||
|
value = &m_device.manufacturer;
|
||||||
|
else if (strcmp(name, "modelName") == 0)
|
||||||
|
value = &m_device.modelName;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (strcmp(name, "serviceType") == 0)
|
||||||
|
value = &m_tservice.serviceType;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
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) {
|
virtual void EndElement(const XML_Char *name) {
|
||||||
if (!strcmp(name, "service")) {
|
if (value != nullptr) {
|
||||||
|
trimstring(*value);
|
||||||
|
value = nullptr;
|
||||||
|
} else if (!strcmp(name, "service")) {
|
||||||
m_device.services.emplace_back(std::move(m_tservice));
|
m_device.services.emplace_back(std::move(m_tservice));
|
||||||
m_tservice.clear();
|
m_tservice.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_path.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void CharacterData(const XML_Char *s, int len) {
|
virtual void CharacterData(const XML_Char *s, int len) {
|
||||||
const auto ¤t = m_path.back();
|
if (value != nullptr)
|
||||||
std::string str = trimstring(s, len);
|
value->append(s, len);
|
||||||
switch (current[0]) {
|
|
||||||
case 'c':
|
|
||||||
if (!current.compare("controlURL"))
|
|
||||||
m_tservice.controlURL = std::move(str);
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
if (!current.compare("deviceType"))
|
|
||||||
m_device.deviceType = std::move(str);
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
if (!current.compare("friendlyName"))
|
|
||||||
m_device.friendlyName = std::move(str);
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
if (!current.compare("manufacturer"))
|
|
||||||
m_device.manufacturer = std::move(str);
|
|
||||||
else if (!current.compare("modelName"))
|
|
||||||
m_device.modelName = std::move(str);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
if (!current.compare("serviceType"))
|
|
||||||
m_tservice.serviceType = std::move(str);
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
if (!current.compare("UDN"))
|
|
||||||
m_device.UDN = std::move(str);
|
|
||||||
else if (!current.compare("URLBase"))
|
|
||||||
m_device.URLBase = std::move(str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Util.hxx"
|
#include "Util.hxx"
|
||||||
#include "util/CharUtil.hxx"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -28,17 +27,19 @@
|
|||||||
#include <upnp/ixml.h>
|
#include <upnp/ixml.h>
|
||||||
|
|
||||||
/** Get rid of white space at both ends */
|
/** Get rid of white space at both ends */
|
||||||
std::string
|
void
|
||||||
trimstring(const char *p, size_t length)
|
trimstring(std::string &s, const char *ws)
|
||||||
{
|
{
|
||||||
while (length > 0 && IsWhitespaceOrNull(p[length - 1]))
|
auto pos = s.find_first_not_of(ws);
|
||||||
--length;
|
if (pos == std::string::npos) {
|
||||||
|
s.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s.replace(0, pos, std::string());
|
||||||
|
|
||||||
const char *end = p + length;
|
pos = s.find_last_not_of(ws);
|
||||||
while (p != end && IsWhitespaceOrNull(*p))
|
if (pos != std::string::npos && pos != s.length()-1)
|
||||||
++p;
|
s.replace(pos + 1, std::string::npos, std::string());
|
||||||
|
|
||||||
return std::string(p, end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
@ -28,9 +28,8 @@
|
|||||||
std::string
|
std::string
|
||||||
caturl(const std::string& s1, const std::string& s2);
|
caturl(const std::string& s1, const std::string& s2);
|
||||||
|
|
||||||
gcc_pure
|
void
|
||||||
std::string
|
trimstring(std::string &s, const char *ws = " \t\n");
|
||||||
trimstring(const char *p, size_t length);
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
path_getfather(const std::string &s);
|
path_getfather(const std::string &s);
|
||||||
|
Loading…
Reference in New Issue
Block a user