/*************************************************************************** * Copyright (C) 2005 by Joris Guisson * * joris.guisson@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include #include #include #include #include #include #include "upnpparsedescriptiontest.h" using namespace kt; using namespace bt; namespace utest { static char* test_data1 = "\n" "\n" "\n" "1\n" "0\n" "\n" "http://192.168.0.1:5678\n" "\n" "urn:schemas-upnp-org:device:InternetGatewayDevice:1\n" "http://192.168.0.1:80\n" "D-Link Router\n" "D-Link\n" "http://www.dlink.com\n" "Internet Access Router\n" "D-Link Router\n" "uuid:upnp-InternetGatewayDevice-1_0-12345678900001\n" "123456789001\n" "\n" "\n" "urn:schemas-upnp-org:service:Layer3Forwarding:1\n" "urn:upnp-org:serviceId:L3Forwarding1\n" "/Layer3Forwarding\n" "/Layer3Forwarding\n" "/Layer3Forwarding.xml\n" "\n" "\n" "\n" "\n" "urn:schemas-upnp-org:device:WANDevice:1\n" "WANDevice\n" "D-Link\n" "http://www.dlink.com\n" "Internet Access Router\n" "D-Link Router\n" "1\n" "http://support.dlink.com\n" "12345678900001\n" "uuid:upnp-WANDevice-1_0-12345678900001\n" "123456789001\n" "\n" "\n" "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1\n" "urn:upnp-org:serviceId:WANCommonInterfaceConfig\n" "/WANCommonInterfaceConfig\n" "/WANCommonInterfaceConfig\n" "/WANCommonInterfaceConfig.xml\n" "\n" "\n" "\n" "\n" "urn:schemas-upnp-org:device:WANConnectionDevice:1\n" "WAN Connection Device\n" "D-Link\n" "http://www.dlink.com\n" "Internet Access Router\n" "D-Link Router \n" "1\n" "http://support.dlink.com\n" "12345678900001\n" "uuid:upnp-WANConnectionDevice-1_0-12345678900001\n" "123456789001\n" "\n" "\n" "urn:schemas-upnp-org:service:WANIPConnection:1\n" "urn:upnp-org:serviceId:WANIPConnection \n" "/WANIPConnection\n" "/WANIPConnection\n" "/WANIPConnection.xml\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" ""; static const char* test_data2 = " \n" " \n" " \n" "1 \n" "0 \n" " \n" "http://192.168.1.1:52869 \n" " \n" "urn:schemas-upnp-org:device:InternetGatewayDevice:1 \n" "DLINK Internet Gateway Device \n" "DLINK \n" "http://www.dlink.com \n" "DLINK IGD \n" "uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \n" " \n" " \n" "image/gif \n" "118 \n" "119 \n" "8 \n" "/ligd.gif \n" " \n" " \n" " \n" " \n" "urn:schemas-microsoft-com:service:OSInfo:1 \n" "urn:microsoft-com:serviceId:OSInfo1 \n" "/upnp/control/OSInfo1 \n" "/upnp/event/OSInfo1 \n" "/gateinfoSCPD.xml \n" " \n" " \n" " \n" " \n" "urn:schemas-upnp-org:device:WANDevice:1 \n" "WANDevice \n" "DLINK \n" "http://www.dlink.com \n" "WAN Device on DLINK IGD \n" "DLINK IGD \n" "0.92 \n" "http://www.dlink.com \n" "0.92 \n" "uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \n" "DLINK IGD \n" " \n" " \n" "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 \n" "urn:upnp-org:serviceId:WANCommonIFC1 \n" "/upnp/control/WANCommonIFC1 \n" "/upnp/control/WANCommonIFC1 \n" "/gateicfgSCPD.xml \n" " \n" " \n" " \n" " \n" "urn:schemas-upnp-org:device:WANConnectionDevice:1 \n" "WANConnectionDevice \n" "DLINK \n" "http://www.dlink.com \n" "WanConnectionDevice on DLINK IGD \n" "DLINK IGD \n" "0.92 \n" "http://www.dlink.com \n" "0.92 \n" "uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \n" "DLINK IGD \n" " \n" " \n" "urn:schemas-upnp-org:service:WANIPConnection:1 \n" "urn:upnp-org:serviceId:WANIPConn1 \n" "/upnp/control/WANIPConn1 \n" "/upnp/control/WANIPConn1 \n" "/gateconnSCPD.xml \n" " \n" " \n" " \n" " \n" " \n" " \n" "http://192.168.1.1/ \n" " \n" " "; static const char* test_data3 = " \ \ \ 1 \ 0 \ \ http://192.168.0.5:5431/ \ \ urn:schemas-upnp-org:device:InternetGatewayDevice:1 \ http://192.168.0.5:80/ \ Dynalink Wireless ADSL Router \ Danalink \ http://www.dynalink.co.nz/ \ Broadcom single-chip ADSL router \ BCM6345+BCM4306 \ 1.0 \ http://www.dynalink.co.nz/ \ uuid:10740000-0000-1000-b710-107c0032dca6 \ \ \ urn:schemas-upnp-org:service:Layer3Forwarding:1 \ urn:upnp-org:serviceId:Layer3Forwarding:11 \ /uuid:10740000-0000-1000-b710-107c0032dca6/Layer3Forwarding:1 \ /uuid:10740000-0000-1000-b710-107c0032dca6/Layer3Forwarding:1 \ /dynsvc/Layer3Forwarding:1.xml \ \ \ \ \ urn:schemas-upnp-org:device:WANDevice:1 \ urn:schemas-upnp-org:device:WANDevice:1 \ Danalink \ http://www.dynalink.co.nz/ \ Broadcom single-chip ADSL router \ BCM6345+BCM4306 \ 1.0 \ http://www.dynalink.co.nz/ \ uuid:10740000-0000-1000-b710-107c0132dca6 \ \ \ urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 \ urn:upnp-org:serviceId:WANCommonIFC1 \ /uuid:10740000-0000-1000-b710-107c0132dca6/WANCommonInterfaceConfig:1 \ /uuid:10740000-0000-1000-b710-107c0132dca6/WANCommonInterfaceConfig:1 \ /dynsvc/WANCommonInterfaceConfig:1.xml \ \ \ \ \ urn:schemas-upnp-org:device:WANConnectionDevice:1 \ urn:schemas-upnp-org:device:WANConnectionDevice:1 \ Danalink \ http://www.dynalink.co.nz/ \ Broadcom single-chip ADSL router \ BCM6345+BCM4306 \ 1.0 \ http://www.dynalink.co.nz/ \ uuid:10740000-0000-1000-b710-107c0232dca6 \ \ \ urn:schemas-upnp-org:service:WANPPPConnection:1 \ urn:upnp-org:serviceId:WANPPPConn1 \ /uuid:10740000-0000-1000-b710-107c0232dca6/WANPPPConnection:1 \ /uuid:10740000-0000-1000-b710-107c0232dca6/WANPPPConnection:1 \ /dynsvc/WANPPPConnection:1.xml \ \ \ \ \ \ \ \ "; const char* test_data4 = " \ \ \ 1 \ 0 \ \ http://192.168.1.1:2869 \ \ urn:schemas-upnp-org:device:InternetGatewayDevice:1 \ OpenWrt Linux Internet Gateway Device \ OpenWrt Project \ http://www.openwrt.org \ WRT54G(S) \ uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \ \ \ image/gif \ 118 \ 119\ 8 \ /ligd.gif \ \ \ \ \ urn:schemas-microsoft-com:service:OSInfo:1 \ urn:microsoft-com:serviceId:OSInfo1 \ /upnp/control/OSInfo1 \ /upnp/event/OSInfo1 \ /gateinfoSCPD.xml \ \ \ \ \ urn:schemas-upnp-org:device:WANDevice:1 \ WANDevice \ OpenWrt Project \ http://www.openwrt.org \ WAN Device on OpenWrt Router \ WRT54G(S) \ 1.0 \ http://www.linksys.com \ XXXXXXXXXX \ uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \ Linux IGD \ \ \ urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 \ urn:upnp-org:serviceId:WANCommonIFC1 \ /upnp/control/WANCommonIFC1 \ /upnp/control/WANCommonIFC1 \ /gateicfgSCPD.xml \ \ \ \ \ urn:schemas-upnp-org:device:WANConnectionDevice:1 \ WANConnectionDevice \ OpenWrt Project \ http://www.openwrt.org \ WanConnectionDevice on OpenWrt Router \ WRT54G(S) \ 1.0 \ http://www.linksys.com \ XXXXXXXXXX \ uuid:75802409-bccb-40e7-8e6c-fa095ecce13e \ Linux IGD \ \ \ urn:schemas-upnp-org:service:WANIPConnection:1 \ urn:upnp-org:serviceId:WANIPConn1 \ /upnp/control/WANIPConn1 \ /upnp/control/WANIPConn1 \ /gateconnSCPD.xml \ \ \ \ \ \ \ http://192.168.1.1/ \ \ "; UPnPParseDescriptionTest::UPnPParseDescriptionTest() : UnitTest("UPnPParseDescriptionTest") {} UPnPParseDescriptionTest::~UPnPParseDescriptionTest() {} bool UPnPParseDescriptionTest::doParse(const char* data,bool forward_test) { QString fn = "/tmp/UPnPParseDescriptionTest"; QFile fptr(fn); if (!fptr.open(IO_WriteOnly)) { Out() << "Cannot open " << fn << " : " << fptr.errorString() << endl; return false; } fptr.writeBlock(data,strlen(data)); fptr.close(); kt::UPnPRouter router(QString::null,"http://foobar.com"); kt::UPnPDescriptionParser dp; if (!dp.parse(fn,&router)) { bt::Delete(fn,true); return false; } else { Out() << "Succesfully parsed the UPnP contents" << endl; bt::Delete(fn,true); if (forward_test) { try { Out() << "Attempting to forward port 9999" << endl; router.forward(net::Port(9999,net::TCP,true)); } catch (Error & e) { Out() << "Error forwarding : "<< e.toString() << endl; return false; } } // router.debugPrintData(); return true; } } bool UPnPParseDescriptionTest::doTest() { bool ret = true; if (!doParse(test_data1,false)) { Out() << "Test data 1 failed" << endl; ret = false; } if (!doParse(test_data2,false)) { Out() << "Test data 2 failed" << endl; ret = false; } if (!doParse(test_data3,false)) { Out() << "Test data 3 failed" << endl; ret = false; } if (!doParse(test_data4,false)) { Out() << "Test data 4 failed" << endl; ret = false; } return ret; } }