|
a/libupnpp/description.cxx |
|
b/libupnpp/description.cxx |
|
... |
|
... |
29 |
#include "expatmm.hxx"
|
29 |
#include "expatmm.hxx"
|
30 |
#include "description.hxx"
|
30 |
#include "description.hxx"
|
31 |
|
31 |
|
32 |
class UPnPDeviceParser : public expatmm::inputRefXMLParser {
|
32 |
class UPnPDeviceParser : public expatmm::inputRefXMLParser {
|
33 |
public:
|
33 |
public:
|
34 |
UPnPDeviceParser(const string& input, UPnPDeviceDesc& device)
|
34 |
UPnPDeviceParser(const string& input, UPnPDeviceDesc& device)
|
35 |
: expatmm::inputRefXMLParser(input), m_device(device)
|
35 |
: expatmm::inputRefXMLParser(input), m_device(device)
|
36 |
{}
|
36 |
{}
|
37 |
|
37 |
|
38 |
protected:
|
38 |
protected:
|
39 |
virtual void StartElement(const XML_Char *name, const XML_Char **)
|
39 |
virtual void StartElement(const XML_Char *name, const XML_Char **)
|
40 |
{
|
40 |
{
|
41 |
m_tabs.push_back('\t');
|
41 |
m_tabs.push_back('\t');
|
42 |
m_path.push_back(name);
|
42 |
m_path.push_back(name);
|
43 |
}
|
43 |
}
|
44 |
virtual void EndElement(const XML_Char *name)
|
44 |
virtual void EndElement(const XML_Char *name)
|
45 |
{
|
45 |
{
|
46 |
if (!strcmp(name, "service")) {
|
46 |
if (!strcmp(name, "service")) {
|
47 |
m_device.services.push_back(m_tservice);
|
47 |
m_device.services.push_back(m_tservice);
|
48 |
m_tservice.clear();
|
48 |
m_tservice.clear();
|
49 |
}
|
49 |
}
|
50 |
if (m_tabs.size())
|
50 |
if (m_tabs.size())
|
51 |
m_tabs.erase(m_tabs.size()-1);
|
51 |
m_tabs.erase(m_tabs.size()-1);
|
52 |
m_path.pop_back();
|
52 |
m_path.pop_back();
|
53 |
}
|
53 |
}
|
54 |
virtual void CharacterData(const XML_Char *s, int len)
|
54 |
virtual void CharacterData(const XML_Char *s, int len)
|
55 |
{
|
55 |
{
|
56 |
if (s == 0 || *s == 0)
|
56 |
if (s == 0 || *s == 0)
|
57 |
return;
|
57 |
return;
|
58 |
string str(s, len);
|
58 |
string str(s, len);
|
59 |
trimstring(str);
|
59 |
trimstring(str);
|
60 |
switch (m_path.back()[0]) {
|
60 |
switch (m_path.back()[0]) {
|
61 |
case 'c':
|
61 |
case 'c':
|
62 |
if (!m_path.back().compare("controlURL"))
|
62 |
if (!m_path.back().compare("controlURL"))
|
63 |
m_tservice.controlURL += str;
|
63 |
m_tservice.controlURL += str;
|
64 |
break;
|
64 |
break;
|
65 |
case 'd':
|
65 |
case 'd':
|
66 |
if (!m_path.back().compare("deviceType"))
|
66 |
if (!m_path.back().compare("deviceType"))
|
67 |
m_device.deviceType += str;
|
67 |
m_device.deviceType += str;
|
68 |
break;
|
68 |
break;
|
69 |
case 'e':
|
69 |
case 'e':
|
70 |
if (!m_path.back().compare("eventSubURL"))
|
70 |
if (!m_path.back().compare("eventSubURL"))
|
71 |
m_tservice.eventSubURL += str;
|
71 |
m_tservice.eventSubURL += str;
|
72 |
break;
|
72 |
break;
|
73 |
case 'f':
|
73 |
case 'f':
|
74 |
if (!m_path.back().compare("friendlyName"))
|
74 |
if (!m_path.back().compare("friendlyName"))
|
75 |
m_device.friendlyName += str;
|
75 |
m_device.friendlyName += str;
|
76 |
break;
|
76 |
break;
|
77 |
case 'm':
|
77 |
case 'm':
|
78 |
if (!m_path.back().compare("manufacturer"))
|
78 |
if (!m_path.back().compare("manufacturer"))
|
79 |
m_device.manufacturer += str;
|
79 |
m_device.manufacturer += str;
|
80 |
else if (!m_path.back().compare("modelName"))
|
80 |
else if (!m_path.back().compare("modelName"))
|
81 |
m_device.modelName += str;
|
81 |
m_device.modelName += str;
|
82 |
break;
|
82 |
break;
|
83 |
case 's':
|
83 |
case 's':
|
84 |
if (!m_path.back().compare("serviceType"))
|
84 |
if (!m_path.back().compare("serviceType"))
|
85 |
m_tservice.serviceType = str;
|
85 |
m_tservice.serviceType = str;
|
86 |
else if (!m_path.back().compare("serviceId"))
|
86 |
else if (!m_path.back().compare("serviceId"))
|
87 |
m_tservice.serviceId += str;
|
87 |
m_tservice.serviceId += str;
|
88 |
case 'S':
|
88 |
case 'S':
|
89 |
if (!m_path.back().compare("SCPDURL"))
|
89 |
if (!m_path.back().compare("SCPDURL"))
|
90 |
m_tservice.SCPDURL = str;
|
90 |
m_tservice.SCPDURL = str;
|
91 |
break;
|
91 |
break;
|
92 |
case 'U':
|
92 |
case 'U':
|
93 |
if (!m_path.back().compare("UDN"))
|
93 |
if (!m_path.back().compare("UDN"))
|
94 |
m_device.UDN = str;
|
94 |
m_device.UDN = str;
|
95 |
else if (!m_path.back().compare("URLBase"))
|
95 |
else if (!m_path.back().compare("URLBase"))
|
96 |
m_device.URLBase += str;
|
96 |
m_device.URLBase += str;
|
97 |
break;
|
97 |
break;
|
98 |
}
|
98 |
}
|
99 |
}
|
99 |
}
|
100 |
|
100 |
|
101 |
private:
|
101 |
private:
|
102 |
UPnPDeviceDesc& m_device;
|
102 |
UPnPDeviceDesc& m_device;
|
103 |
string m_tabs;
|
103 |
string m_tabs;
|
104 |
std::vector<std::string> m_path;
|
104 |
std::vector<std::string> m_path;
|
105 |
UPnPServiceDesc m_tservice;
|
105 |
UPnPServiceDesc m_tservice;
|
106 |
};
|
106 |
};
|
107 |
|
107 |
|
108 |
UPnPDeviceDesc::UPnPDeviceDesc(const string& url, const string& description)
|
108 |
UPnPDeviceDesc::UPnPDeviceDesc(const string& url, const string& description)
|
109 |
: ok(false)
|
109 |
: ok(false)
|
110 |
{
|
110 |
{
|
111 |
//cerr << "UPnPDeviceDesc::UPnPDeviceDesc: url: " << url << endl;
|
111 |
//cerr << "UPnPDeviceDesc::UPnPDeviceDesc: url: " << url << endl;
|
112 |
//cerr << " description " << endl << description << endl;
|
112 |
//cerr << " description " << endl << description << endl;
|
113 |
|
113 |
|
114 |
UPnPDeviceParser mparser(description, *this);
|
114 |
UPnPDeviceParser mparser(description, *this);
|
115 |
if (!mparser.Parse())
|
115 |
if (!mparser.Parse())
|
116 |
return;
|
116 |
return;
|
117 |
if (URLBase.empty()) {
|
117 |
if (URLBase.empty()) {
|
118 |
// The standard says that if the URLBase value is empty, we
|
118 |
// The standard says that if the URLBase value is empty, we
|
119 |
// should use the url the description was retrieved
|
119 |
// should use the url the description was retrieved
|
120 |
// from. However this is sometimes something like
|
120 |
// from. However this is sometimes something like
|
121 |
// http://host/desc.xml, sometimes something like http://host/
|
121 |
// http://host/desc.xml, sometimes something like http://host/
|
122 |
// (rare, but e.g. sent by the server on a dlink nas).
|
122 |
// (rare, but e.g. sent by the server on a dlink nas).
|
123 |
URLBase = baseurl(url);
|
123 |
URLBase = baseurl(url);
|
124 |
}
|
124 |
}
|
125 |
ok = true;
|
125 |
ok = true;
|
126 |
//cerr << "URLBase: [" << URLBase << "]" << endl;
|
126 |
//cerr << "URLBase: [" << URLBase << "]" << endl;
|
127 |
//cerr << dump() << endl;
|
127 |
//cerr << dump() << endl;
|
128 |
}
|
128 |
}
|
129 |
|
|
|
130 |
/* Local Variables: */
|
|
|
131 |
/* mode: c++ */
|
|
|
132 |
/* c-basic-offset: 4 */
|
|
|
133 |
/* tab-width: 4 */
|
|
|
134 |
/* indent-tabs-mode: t */
|
|
|
135 |
/* End: */
|
|
|