mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 15:02:56 +02:00
use xmlinterface in UPNP
This commit is contained in:
@@ -3,6 +3,8 @@ noinst_LIBRARIES = libtuxbox-upnpclient.a
|
|||||||
AM_CPPFLAGS = -fno-rtti
|
AM_CPPFLAGS = -fno-rtti
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
|
-I$(top_builddir) \
|
||||||
|
-I$(top_srcdir) \
|
||||||
-I$(top_srcdir)/lib/xmltree
|
-I$(top_srcdir)/lib/xmltree
|
||||||
|
|
||||||
libtuxbox_upnpclient_a_SOURCES = UPNPSocket.cpp UPNPDevice.cpp UPNPService.cpp
|
libtuxbox_upnpclient_a_SOURCES = UPNPSocket.cpp UPNPDevice.cpp UPNPService.cpp
|
||||||
|
@@ -18,12 +18,15 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
***********************************************************************************/
|
***********************************************************************************/
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xmltree.h>
|
#include <xmlinterface.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -133,7 +136,7 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
std::string result, head, body, charset, urlbase;
|
std::string result, head, body, charset, urlbase;
|
||||||
std::string curl, eurl, name, mimetype, iurl, rcode;
|
std::string curl, eurl, name, mimetype, iurl, rcode;
|
||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
XMLTreeNode *root, *device, *service, *node, *snode, *icon;
|
xmlNodePtr root, device, service, node, snode, icon;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
@@ -165,76 +168,76 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
|
|
||||||
if (rcode != "200")
|
if (rcode != "200")
|
||||||
throw std::runtime_error(std::string("description url returned ") + rcode);
|
throw std::runtime_error(std::string("description url returned ") + rcode);
|
||||||
XMLTreeParser parser(charset.c_str());
|
|
||||||
parser.Parse(body.c_str(), body.size(), 1);
|
xmlDocPtr parser = parseXml(body.c_str(),charset.c_str());
|
||||||
root = parser.RootNode();
|
root = xmlDocGetRootElement(parser);
|
||||||
if (!root)
|
if (!root)
|
||||||
throw std::runtime_error(std::string("XML: no root node"));
|
throw std::runtime_error(std::string("XML: no root node"));
|
||||||
|
|
||||||
if (strcmp(root->GetType(),"root"))
|
if (strcmp(xmlGetName(root),"root"))
|
||||||
throw std::runtime_error(std::string("XML: no root"));
|
throw std::runtime_error(std::string("XML: no root"));
|
||||||
|
|
||||||
for (node = root->GetChild(); node; node=node->GetNext())
|
for (node = root->xmlChildrenNode; node; node=node->xmlNextNode)
|
||||||
{
|
{
|
||||||
if (!strcmp(node->GetType(),"URLBase"))
|
if (!strcmp(xmlGetName(node),"URLBase"))
|
||||||
{
|
{
|
||||||
urlbase = std::string(node->GetData());
|
urlbase = std::string(xmlGetData(node));
|
||||||
if ((!urlbase.empty() ) && (urlbase[urlbase.length()-1] == '/'))
|
if ((!urlbase.empty() ) && (urlbase[urlbase.length()-1] == '/'))
|
||||||
urlbase.erase(urlbase.length()-1);
|
urlbase.erase(urlbase.length()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node = root->GetChild();
|
node = root->xmlChildrenNode;
|
||||||
if (!node)
|
if (!node)
|
||||||
throw std::runtime_error(std::string("XML: no root child"));
|
throw std::runtime_error(std::string("XML: no root child"));
|
||||||
|
|
||||||
while (strcmp(node->GetType(),"device"))
|
while (strcmp(xmlGetName(node),"device"))
|
||||||
{
|
{
|
||||||
node = node->GetNext();
|
node = node->xmlNextNode;
|
||||||
if (!node)
|
if (!node)
|
||||||
throw std::runtime_error(std::string("XML: no device"));
|
throw std::runtime_error(std::string("XML: no device"));
|
||||||
}
|
}
|
||||||
device = node;
|
device = node;
|
||||||
|
|
||||||
for (node=device->GetChild(); node; node=node->GetNext())
|
for (node=device->xmlChildrenNode; node; node=node->xmlNextNode)
|
||||||
{
|
{
|
||||||
if (!strcmp(node->GetType(),"deviceType"))
|
if (!strcmp(xmlGetName(node),"deviceType"))
|
||||||
devicetype = std::string(node->GetData()?node->GetData():"");
|
devicetype = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"friendlyName"))
|
if (!strcmp(xmlGetName(node),"friendlyName"))
|
||||||
friendlyname = std::string(node->GetData()?node->GetData():"");
|
friendlyname = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"manufacturer"))
|
if (!strcmp(xmlGetName(node),"manufacturer"))
|
||||||
manufacturer = std::string(node->GetData()?node->GetData():"");
|
manufacturer = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"manufacturerURL"))
|
if (!strcmp(xmlGetName(node),"manufacturerURL"))
|
||||||
manufacturerurl = std::string(node->GetData()?node->GetData():"");
|
manufacturerurl = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"modelDescription"))
|
if (!strcmp(xmlGetName(node),"modelDescription"))
|
||||||
modeldescription = std::string(node->GetData()?node->GetData():"");
|
modeldescription = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"modelName"))
|
if (!strcmp(xmlGetName(node),"modelName"))
|
||||||
modelname = std::string(node->GetData()?node->GetData():"");
|
modelname = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"modelNumber"))
|
if (!strcmp(xmlGetName(node),"modelNumber"))
|
||||||
modelnumber = std::string(node->GetData()?node->GetData():"");
|
modelnumber = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"modelURL"))
|
if (!strcmp(xmlGetName(node),"modelURL"))
|
||||||
modelurl = std::string(node->GetData()?node->GetData():"");
|
modelurl = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"serialNumber"))
|
if (!strcmp(xmlGetName(node),"serialNumber"))
|
||||||
serialnumber = std::string(node->GetData()?node->GetData():"");
|
serialnumber = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"UDN"))
|
if (!strcmp(xmlGetName(node),"UDN"))
|
||||||
udn = std::string(node->GetData()?node->GetData():"");
|
udn = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"UPC"))
|
if (!strcmp(xmlGetName(node),"UPC"))
|
||||||
upc = std::string(node->GetData()?node->GetData():"");
|
upc = std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
|
|
||||||
if (!strcmp(node->GetType(),"iconList"))
|
if (!strcmp(xmlGetName(node),"iconList"))
|
||||||
{
|
{
|
||||||
for (icon=node->GetChild(); icon; icon=icon->GetNext())
|
for (icon=node->xmlChildrenNode; icon; icon=icon->xmlNextNode)
|
||||||
{
|
{
|
||||||
bool foundm = false;
|
bool foundm = false;
|
||||||
bool foundw = false;
|
bool foundw = false;
|
||||||
@@ -242,33 +245,33 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
bool foundd = false;
|
bool foundd = false;
|
||||||
bool foundu = false;
|
bool foundu = false;
|
||||||
|
|
||||||
if (strcmp(icon->GetType(),"icon"))
|
if (strcmp(xmlGetName(icon),"icon"))
|
||||||
throw std::runtime_error(std::string("XML: no icon"));
|
throw std::runtime_error(std::string("XML: no icon"));
|
||||||
for (snode=icon->GetChild(); snode; snode=snode->GetNext())
|
for (snode=icon->xmlChildrenNode; snode; snode=snode->xmlNextNode)
|
||||||
{
|
{
|
||||||
if (!strcmp(snode->GetType(),"mimetype"))
|
if (!strcmp(xmlGetName(snode),"mimetype"))
|
||||||
{
|
{
|
||||||
mimetype=std::string(snode->GetData()?snode->GetData():"");
|
mimetype=std::string(xmlGetData(snode)?xmlGetData(snode):"");
|
||||||
foundm = true;
|
foundm = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"width"))
|
if (!strcmp(xmlGetName(snode),"width"))
|
||||||
{
|
{
|
||||||
width=snode->GetData()?atoi(snode->GetData()):0;
|
width=xmlGetData(snode)?atoi(xmlGetData(snode)):0;
|
||||||
foundw = true;
|
foundw = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"height"))
|
if (!strcmp(xmlGetName(snode),"height"))
|
||||||
{
|
{
|
||||||
height=snode->GetData()?atoi(snode->GetData()):0;
|
height=xmlGetData(snode)?atoi(xmlGetData(snode)):0;
|
||||||
foundh = true;
|
foundh = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"depth"))
|
if (!strcmp(xmlGetName(snode),"depth"))
|
||||||
{
|
{
|
||||||
depth=snode->GetData()?atoi(snode->GetData()):0;
|
depth=xmlGetData(snode)?atoi(xmlGetData(snode)):0;
|
||||||
foundd = true;
|
foundd = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"url"))
|
if (!strcmp(xmlGetName(snode),"url"))
|
||||||
{
|
{
|
||||||
url=std::string(snode->GetData()?snode->GetData():"");
|
url=std::string(xmlGetData(snode)?xmlGetData(snode):"");
|
||||||
foundu = true;
|
foundu = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,28 +289,27 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
icons.push_back(e);
|
icons.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strcmp(node->GetType(),"serviceList"))
|
if (!strcmp(xmlGetName(node),"serviceList"))
|
||||||
{
|
{
|
||||||
servicefound = true;
|
servicefound = true;
|
||||||
for (service=node->GetChild(); service; service=service->GetNext())
|
for (service=node->xmlChildrenNode; service; service=service->xmlNextNode)
|
||||||
{
|
{
|
||||||
bool foundc = false;
|
bool foundc = false;
|
||||||
bool founde = false;
|
bool founde = false;
|
||||||
bool foundn = false;
|
bool foundn = false;
|
||||||
|
|
||||||
if (strcmp(service->GetType(),"service"))
|
if (strcmp(xmlGetName(service),"service"))
|
||||||
throw std::runtime_error(std::string("XML: no service"));
|
throw std::runtime_error(std::string("XML: no service"));
|
||||||
for (snode=service->GetChild(); snode; snode=snode->GetNext())
|
for (snode=service->xmlChildrenNode; snode; snode=snode->xmlNextNode)
|
||||||
{
|
{
|
||||||
if (!strcmp(snode->GetType(),"serviceType"))
|
if (!strcmp(xmlGetName(snode),"serviceType"))
|
||||||
{
|
{
|
||||||
name=std::string(snode->GetData()?snode->GetData():"");
|
name=std::string(xmlGetData(snode)?xmlGetData(snode):"");
|
||||||
foundn = true;
|
foundn = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"eventSubURL"))
|
if (!strcmp(xmlGetName(snode),"eventSubURL"))
|
||||||
{
|
{
|
||||||
char *p;
|
const char *p = xmlGetData(snode);
|
||||||
p = snode->GetData();
|
|
||||||
if (!p)
|
if (!p)
|
||||||
eurl=urlbase + "/";
|
eurl=urlbase + "/";
|
||||||
else if (p[0]=='/')
|
else if (p[0]=='/')
|
||||||
@@ -316,10 +318,9 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
eurl=urlbase + "/" + std::string(p);
|
eurl=urlbase + "/" + std::string(p);
|
||||||
founde = true;
|
founde = true;
|
||||||
}
|
}
|
||||||
if (!strcmp(snode->GetType(),"controlURL"))
|
if (!strcmp(xmlGetName(snode),"controlURL"))
|
||||||
{
|
{
|
||||||
char *p;
|
const char *p = xmlGetData(snode);
|
||||||
p = snode->GetData();
|
|
||||||
if (!p)
|
if (!p)
|
||||||
curl=urlbase + "/";
|
curl=urlbase + "/";
|
||||||
else if (p[0]=='/')
|
else if (p[0]=='/')
|
||||||
@@ -348,6 +349,7 @@ CUPnPDevice::CUPnPDevice(std::string url)
|
|||||||
}
|
}
|
||||||
if (!servicefound)
|
if (!servicefound)
|
||||||
throw std::runtime_error(std::string("XML: no service list"));
|
throw std::runtime_error(std::string("XML: no service list"));
|
||||||
|
xmlFreeDoc(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUPnPDevice::~CUPnPDevice()
|
CUPnPDevice::~CUPnPDevice()
|
||||||
|
@@ -18,12 +18,15 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
***********************************************************************************/
|
***********************************************************************************/
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xmltree.h>
|
#include <xmlinterface.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -44,6 +47,7 @@ CUPnPService::CUPnPService(CUPnPDevice* dev, std::string curl, std::string eurl,
|
|||||||
CUPnPService::~CUPnPService()
|
CUPnPService::~CUPnPService()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UPnPAttribute> attribs)
|
std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UPnPAttribute> attribs)
|
||||||
{
|
{
|
||||||
@@ -52,7 +56,7 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
std::string result, head, body, charset, envelope, soapbody, soapresponse, rcode;
|
std::string result, head, body, charset, envelope, soapbody, soapresponse, rcode;
|
||||||
std::list<UPnPAttribute>::iterator i;
|
std::list<UPnPAttribute>::iterator i;
|
||||||
std::list<UPnPAttribute> results;
|
std::list<UPnPAttribute> results;
|
||||||
XMLTreeNode *root, *node, *snode;
|
xmlNodePtr root, node, snode;
|
||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
|
|
||||||
post << "<?xml version=\"1.0\"?>\r\n"
|
post << "<?xml version=\"1.0\"?>\r\n"
|
||||||
@@ -95,13 +99,12 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
if (!device->check_response(head, charset, rcode))
|
if (!device->check_response(head, charset, rcode))
|
||||||
throw std::runtime_error(std::string("protocol error"));
|
throw std::runtime_error(std::string("protocol error"));
|
||||||
|
|
||||||
XMLTreeParser parser(charset.c_str());
|
xmlDocPtr parser = parseXml(body.c_str(),charset.c_str());
|
||||||
parser.Parse(body.c_str(), body.size(), 1);
|
root = xmlDocGetRootElement(parser);
|
||||||
root = parser.RootNode();
|
|
||||||
if (!root)
|
if (!root)
|
||||||
throw std::runtime_error(std::string("XML: no root node"));
|
throw std::runtime_error(std::string("XML: no root node"));
|
||||||
|
|
||||||
envelope=std::string(root->GetType());
|
envelope=std::string(xmlGetName(root));
|
||||||
pos = envelope.find(":");
|
pos = envelope.find(":");
|
||||||
if (pos !=std::string::npos)
|
if (pos !=std::string::npos)
|
||||||
envelope.erase(0,pos+1);
|
envelope.erase(0,pos+1);
|
||||||
@@ -109,11 +112,11 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
if (envelope != "Envelope")
|
if (envelope != "Envelope")
|
||||||
throw std::runtime_error(std::string("XML: no envelope"));
|
throw std::runtime_error(std::string("XML: no envelope"));
|
||||||
|
|
||||||
node = root->GetChild();
|
node = root->xmlChildrenNode;
|
||||||
if (!node)
|
if (!node)
|
||||||
throw std::runtime_error(std::string("XML: no envelope child"));
|
throw std::runtime_error(std::string("XML: no envelope child"));
|
||||||
|
|
||||||
soapbody=std::string(node->GetType());
|
soapbody=std::string(xmlGetName(node));
|
||||||
pos = soapbody.find(":");
|
pos = soapbody.find(":");
|
||||||
if (pos !=std::string::npos)
|
if (pos !=std::string::npos)
|
||||||
soapbody.erase(0,pos+1);
|
soapbody.erase(0,pos+1);
|
||||||
@@ -121,11 +124,11 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
if (soapbody != "Body")
|
if (soapbody != "Body")
|
||||||
throw std::runtime_error(std::string("XML: no soap body"));
|
throw std::runtime_error(std::string("XML: no soap body"));
|
||||||
|
|
||||||
node = node->GetChild();
|
node = node->xmlChildrenNode;
|
||||||
if (!node)
|
if (!node)
|
||||||
throw std::runtime_error(std::string("XML: no soap body child"));
|
throw std::runtime_error(std::string("XML: no soap body child"));
|
||||||
|
|
||||||
soapresponse=std::string(node->GetType());
|
soapresponse=std::string(xmlGetName(node));
|
||||||
pos = soapresponse.find(":");
|
pos = soapresponse.find(":");
|
||||||
if (pos !=std::string::npos)
|
if (pos !=std::string::npos)
|
||||||
soapresponse.erase(0,pos+1);
|
soapresponse.erase(0,pos+1);
|
||||||
@@ -135,27 +138,27 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
std::string faultstring, upnpcode, upnpdesc, errstr;
|
std::string faultstring, upnpcode, upnpdesc, errstr;
|
||||||
if (soapresponse != "Fault")
|
if (soapresponse != "Fault")
|
||||||
throw std::runtime_error(std::string("XML: http error without soap fault: ")+rcode);
|
throw std::runtime_error(std::string("XML: http error without soap fault: ")+rcode);
|
||||||
for (node=node->GetChild(); node; node=node->GetNext())
|
for (node=node->xmlChildrenNode; node; node=node->xmlNextNode)
|
||||||
{
|
{
|
||||||
if (!strcmp(node->GetType(),"detail"))
|
if (!strcmp(xmlGetName(node),"detail"))
|
||||||
{
|
{
|
||||||
snode=node->GetChild();
|
snode=node->xmlChildrenNode;
|
||||||
if (snode)
|
if (snode)
|
||||||
for (snode=snode->GetChild(); snode; snode=snode->GetNext())
|
for (snode=snode->xmlChildrenNode; snode; snode=snode->xmlNextNode)
|
||||||
{
|
{
|
||||||
errstr=snode->GetType();
|
errstr=xmlGetName(snode);
|
||||||
pos = errstr.find(":");
|
pos = errstr.find(":");
|
||||||
if (pos !=std::string::npos)
|
if (pos !=std::string::npos)
|
||||||
errstr.erase(0,pos+1);
|
errstr.erase(0,pos+1);
|
||||||
if (errstr=="errorCode")
|
if (errstr=="errorCode")
|
||||||
upnpcode=std::string(snode->GetData()?snode->GetData():"");
|
upnpcode=std::string(xmlGetData(snode)?xmlGetData(snode):"");
|
||||||
if (errstr=="errorDescription")
|
if (errstr=="errorDescription")
|
||||||
upnpdesc=std::string(snode->GetData()?snode->GetData():"");
|
upnpdesc=std::string(xmlGetData(snode)?xmlGetData(snode):"");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!strcmp(node->GetType(),"faultstring"))
|
if (!strcmp(xmlGetName(node),"faultstring"))
|
||||||
faultstring=std::string(node->GetData()?node->GetData():"");
|
faultstring=std::string(xmlGetData(node)?xmlGetData(node):"");
|
||||||
}
|
}
|
||||||
if (!faultstring.empty())
|
if (!faultstring.empty())
|
||||||
throw std::runtime_error(faultstring + " " + upnpcode + " " + upnpdesc);
|
throw std::runtime_error(faultstring + " " + upnpcode + " " + upnpdesc);
|
||||||
@@ -165,8 +168,9 @@ std::list<UPnPAttribute> CUPnPService::SendSOAP(std::string action, std::list<UP
|
|||||||
if (soapresponse != action + "Response")
|
if (soapresponse != action + "Response")
|
||||||
throw std::runtime_error(std::string("XML: no soap response"));
|
throw std::runtime_error(std::string("XML: no soap response"));
|
||||||
|
|
||||||
for (node=node->GetChild(); node; node=node->GetNext())
|
for (node=node->xmlChildrenNode; node; node=node->xmlNextNode)
|
||||||
results.push_back(UPnPAttribute(node->GetType(), node->GetData()));
|
results.push_back(UPnPAttribute(xmlGetName(node), xmlGetData(node)));
|
||||||
|
|
||||||
|
xmlFreeDoc(parser);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xmltree.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
@@ -176,11 +176,11 @@ xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence /* =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* USE_LIBXML */
|
#else /* USE_LIBXML */
|
||||||
xmlDocPtr parseXml(const char * data)
|
xmlDocPtr parseXml(const char * data,const char *encoding)
|
||||||
{
|
{
|
||||||
XMLTreeParser* tree_parser;
|
XMLTreeParser* tree_parser;
|
||||||
|
|
||||||
tree_parser = new XMLTreeParser(NULL);
|
tree_parser = new XMLTreeParser(encoding);
|
||||||
|
|
||||||
if (!tree_parser->Parse(data, strlen(data), true))
|
if (!tree_parser->Parse(data, strlen(data), true))
|
||||||
{
|
{
|
||||||
@@ -201,7 +201,7 @@ xmlDocPtr parseXml(const char * data)
|
|||||||
return tree_parser;
|
return tree_parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence /* = true */)
|
xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence /* = true */,const char *encoding)
|
||||||
{
|
{
|
||||||
char buffer[2048];
|
char buffer[2048];
|
||||||
XMLTreeParser* tree_parser;
|
XMLTreeParser* tree_parser;
|
||||||
@@ -218,7 +218,7 @@ xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence /* =
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tree_parser = new XMLTreeParser(NULL);
|
tree_parser = new XMLTreeParser(encoding);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@@ -66,7 +66,7 @@ std::string Unicode_Character_to_UTF8(const int character);
|
|||||||
|
|
||||||
std::string convert_UTF8_To_UTF8_XML(const char *s);
|
std::string convert_UTF8_To_UTF8_XML(const char *s);
|
||||||
|
|
||||||
xmlDocPtr parseXml(const char *data);
|
xmlDocPtr parseXml(const char *data,const char *encoding = NULL);
|
||||||
xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence = true);
|
xmlDocPtr parseXmlFile(const char * filename, bool warning_by_nonexistence = true,const char *encoding = NULL);
|
||||||
|
|
||||||
#endif /* __xmlinterface_h__ */
|
#endif /* __xmlinterface_h__ */
|
||||||
|
@@ -39,9 +39,8 @@
|
|||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <neutrino.h>
|
#include <neutrino.h>
|
||||||
#include <xmltree.h>
|
#include <xmlinterface.h>
|
||||||
#include <upnpclient.h>
|
#include <upnpclient.h>
|
||||||
|
|
||||||
#include <driver/fontrenderer.h>
|
#include <driver/fontrenderer.h>
|
||||||
#include <driver/rcinput.h>
|
#include <driver/rcinput.h>
|
||||||
#include <driver/audioplay.h>
|
#include <driver/audioplay.h>
|
||||||
@@ -240,49 +239,47 @@ bool CUpnpBrowserGui::getResults(std::string id, unsigned int start, unsigned in
|
|||||||
|
|
||||||
std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
|
std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
|
||||||
{
|
{
|
||||||
XMLTreeParser *parser;
|
xmlNodePtr root, node, snode;
|
||||||
XMLTreeNode *root, *node, *snode;
|
|
||||||
std::vector<UPnPEntry> *entries;
|
std::vector<UPnPEntry> *entries;
|
||||||
|
|
||||||
parser = new XMLTreeParser("UTF-8");
|
xmlDocPtr parser = parseXml(result.c_str(),"UTF-8");
|
||||||
parser->Parse(result.c_str(), result.size(), 1);
|
root = xmlDocGetRootElement(parser);
|
||||||
root=parser->RootNode();
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
delete parser;
|
xmlFreeDoc(parser);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
entries = new std::vector<UPnPEntry>;
|
entries = new std::vector<UPnPEntry>;
|
||||||
|
|
||||||
for (node=root->GetChild(); node; node=node->GetNext())
|
for (node=root->xmlChildrenNode; node; node=node->xmlNextNode)
|
||||||
{
|
{
|
||||||
bool isdir;
|
bool isdir;
|
||||||
std::string title, artist = "", album = "", albumArtURI = "", id, children;
|
std::string title, artist = "", album = "", albumArtURI = "", id, children;
|
||||||
const char *type, *p;
|
const char *type, *p;
|
||||||
|
|
||||||
if (!strcmp(node->GetType(), "container"))
|
if (!strcmp(xmlGetName(node), "container"))
|
||||||
{
|
{
|
||||||
std::vector<UPnPResource> resources;
|
std::vector<UPnPResource> resources;
|
||||||
isdir=true;
|
isdir=true;
|
||||||
for (snode=node->GetChild(); snode; snode=snode->GetNext())
|
for (snode=node->xmlChildrenNode; snode; snode=snode->xmlNextNode)
|
||||||
{
|
{
|
||||||
type=snode->GetType();
|
type=xmlGetName(snode);
|
||||||
p = strchr(type,':');
|
p = strchr(type,':');
|
||||||
if (p)
|
if (p)
|
||||||
type=p+1;
|
type=p+1;
|
||||||
if (!strcmp(type,"title"))
|
if (!strcmp(type,"title"))
|
||||||
{
|
{
|
||||||
p=snode->GetData();
|
p=xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
title=std::string(p);
|
title=std::string(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = node->GetAttributeValue("id");
|
p = xmlGetAttribute(node, "id");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
id=std::string(p);
|
id=std::string(p);
|
||||||
|
|
||||||
p = node->GetAttributeValue("childCount");
|
p = xmlGetAttribute(node, "childCount");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
children=std::string(p);
|
children=std::string(p);
|
||||||
@@ -290,65 +287,65 @@ std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
|
|||||||
UPnPEntry entry={id, isdir, title, artist, album, albumArtURI, children, "", "", resources, -1, CFile::FILE_DIR};
|
UPnPEntry entry={id, isdir, title, artist, album, albumArtURI, children, "", "", resources, -1, CFile::FILE_DIR};
|
||||||
entries->push_back(entry);
|
entries->push_back(entry);
|
||||||
}
|
}
|
||||||
if (!strcmp(node->GetType(), "item"))
|
if (!strcmp(xmlGetName(node), "item"))
|
||||||
{
|
{
|
||||||
std::vector<UPnPResource> resources;
|
std::vector<UPnPResource> resources;
|
||||||
int preferred = -1;
|
int preferred = -1;
|
||||||
std::string protocol, prot, network, mime, additional;
|
std::string protocol, prot, network, mime, additional;
|
||||||
CFile::FileType ftype = CFile::FILE_UNKNOWN;
|
CFile::FileType ftype = CFile::FILE_UNKNOWN;
|
||||||
isdir=false;
|
isdir=false;
|
||||||
for (snode=node->GetChild(); snode; snode=snode->GetNext())
|
for (snode=node->xmlChildrenNode; snode; snode=snode->xmlNextNode)
|
||||||
{
|
{
|
||||||
std::string duration, url, size;
|
std::string duration, url, size;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
type=snode->GetType();
|
type=xmlGetName(snode);
|
||||||
p = strchr(type,':');
|
p = strchr(type,':');
|
||||||
if (p)
|
if (p)
|
||||||
type=p+1;
|
type=p+1;
|
||||||
|
|
||||||
if (!strcmp(type,"title"))
|
if (!strcmp(type,"title"))
|
||||||
{
|
{
|
||||||
p=snode->GetData();
|
p=xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
title=std::string(p);
|
title=std::string(p);
|
||||||
}
|
}
|
||||||
else if (!strcmp(type,"artist"))
|
else if (!strcmp(type,"artist"))
|
||||||
{
|
{
|
||||||
p=snode->GetData();
|
p=xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
artist=std::string(p);
|
artist=std::string(p);
|
||||||
}
|
}
|
||||||
else if (!strcmp(type,"album"))
|
else if (!strcmp(type,"album"))
|
||||||
{
|
{
|
||||||
p=snode->GetData();
|
p=xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
album=std::string(p);
|
album=std::string(p);
|
||||||
}
|
}
|
||||||
else if (!strcmp(type,"albumArtURI"))
|
else if (!strcmp(type,"albumArtURI"))
|
||||||
{
|
{
|
||||||
p=snode->GetData();
|
p=xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
albumArtURI=std::string(p);
|
albumArtURI=std::string(p);
|
||||||
}
|
}
|
||||||
else if (!strcmp(type,"res"))
|
else if (!strcmp(type,"res"))
|
||||||
{
|
{
|
||||||
p = snode->GetData();
|
p = xmlGetData(snode);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
url=std::string(p);
|
url=std::string(p);
|
||||||
p = snode->GetAttributeValue("size");
|
p = xmlGetAttribute(snode, "size");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "0";
|
p = "0";
|
||||||
size=std::string(p);
|
size=std::string(p);
|
||||||
p = snode->GetAttributeValue("duration");
|
p = xmlGetAttribute(snode, "duration");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
duration=std::string(p);
|
duration=std::string(p);
|
||||||
p = snode->GetAttributeValue("protocolInfo");
|
p = xmlGetAttribute(snode, "protocolInfo");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
protocol=std::string(p);
|
protocol=std::string(p);
|
||||||
@@ -419,12 +416,12 @@ std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = node->GetAttributeValue("id");
|
p = xmlGetAttribute(node, "id");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
id=std::string(p);
|
id=std::string(p);
|
||||||
|
|
||||||
p = node->GetAttributeValue("childCount");
|
p = xmlGetAttribute(node, "childCount");
|
||||||
if (!p)
|
if (!p)
|
||||||
p = "";
|
p = "";
|
||||||
children=std::string(p);
|
children=std::string(p);
|
||||||
@@ -433,7 +430,7 @@ std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
|
|||||||
entries->push_back(entry);
|
entries->push_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete parser;
|
xmlFreeDoc(parser);
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user