miniupnpc: validate igd_desc_parse

This commit is contained in:
Thomas Bernard 2014-11-17 20:31:11 +01:00
parent fa414c5bb6
commit 6e8106688c
6 changed files with 239 additions and 9 deletions

View File

@ -26,3 +26,5 @@ validateupnpreplyparse
testportlistingparse
validateportlistingparse
listdevices
testigddescparse
validateigddescparse

View File

@ -1,4 +1,4 @@
$Id: Changelog.txt,v 1.199 2014/11/05 06:06:37 nanard Exp $
$Id: Changelog.txt,v 1.202 2014/11/17 19:10:28 nanard Exp $
miniUPnP client Changelog.
2014/11/17:
@ -6,6 +6,7 @@ miniUPnP client Changelog.
upnpDiscoverDevices() / upnpDiscoverAll() functions
listdevices executable
increment API_VERSION to 12
validate igd_desc_parse
2014/11/13:
increment API_VERSION to 11

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.113 2014/11/01 10:37:32 nanard Exp $
# $Id: Makefile,v 1.117 2014/11/17 17:15:33 nanard Exp $
# MiniUPnP Project
# http://miniupnp.free.fr/
# http://miniupnp.tuxfamily.org/
@ -145,7 +145,7 @@ all: $(LIBRARY) $(EXECUTABLES)
test: check
check: validateminixml validateminiwget validateupnpreplyparse \
validateportlistingparse
validateportlistingparse validateigddescparse
everything: all $(EXECUTABLES_ADDTESTS)
@ -183,12 +183,18 @@ validateportlistingparse: testportlistingparse
./testportlistingparse
touch $@
validateigddescparse: testigddescparse
@echo "igd desc parse validation test"
./testigddescparse testdesc/new_LiveBox_desc.xml testdesc/new_LiveBox_desc.values
touch $@
clean:
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h
$(RM) $(EXECUTABLES_ADDTESTS)
# clean python stuff
$(RM) pythonmodule pythonmodule3
$(RM) validateminixml validateminiwget validateupnpreplyparse
$(RM) validateigddescparse
$(RM) minihttptestserver
$(RM) -r build/ dist/
#python setup.py clean
@ -340,3 +346,4 @@ testportlistingparse.o: portlistingparse.h declspec.h miniupnpctypes.h
miniupnpcmodule.o: miniupnpc.h declspec.h igd_desc_parse.h upnpcommands.h
miniupnpcmodule.o: upnpreplyparse.h portlistingparse.h miniupnpctypes.h
miniupnpcmodule.o: upnperrors.h
listdevices.o: miniupnpc.h declspec.h igd_desc_parse.h

View File

@ -0,0 +1,20 @@
# values for new_LiveBox_desc.xml
CIF:
servicetype = urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
controlurl = /87895a19/upnp/control/WANCommonIFC1
eventsuburl = /87895a19/upnp/control/WANCommonIFC1
scpdurl = /87895a19/gateicfgSCPD.xml
first:
servicetype = urn:schemas-upnp-org:service:WANPPPConnection:2
controlurl = /87895a19/upnp/control/WANIPConn1
eventsuburl = /87895a19/upnp/control/WANIPConn1
scpdurl = /87895a19/gateconnSCPD_PPP.xml
IPv6FC:
servicetype = urn:schemas-upnp-org:service:WANIPv6FirewallControl:1
controlurl = /87895a19/upnp/control/WANIPv6FwCtrl1
eventsuburl = /87895a19/upnp/control/WANIPv6FwCtrl1
scpdurl = /87895a19/wanipv6fwctrlSCPD.xml

View File

@ -0,0 +1,90 @@
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<pnpx:X_hardwareId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">VEN_0129&amp;DEV_0000&amp;SUBSYS_03&amp;REV_250417</pnpx:X_hardwareId>
<pnpx:X_compatibleId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">GenericUmPass</pnpx:X_compatibleId>
<pnpx:X_deviceCategory xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">NetworkInfrastructure.Gateway</pnpx:X_deviceCategory>
<df:X_deviceCategory xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation">Network.Gateway</df:X_deviceCategory>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:2</deviceType>
<friendlyName>Orange Livebox</friendlyName>
<manufacturer>Sagemcom</manufacturer>
<manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
<modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
<UDN>uuid:87895a19-50f9-3736-a87f-115c230155f8</UDN>
<modelDescription>Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
<modelNumber>3</modelNumber>
<serialNumber>LK14129DP441489</serialNumber>
<presentationURL>http://192.168.1.1</presentationURL>
<UPC></UPC>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<width>16</width>
<height>16</height>
<depth>8</depth>
<url>/87895a19/ligd.png</url>
</icon>
</iconList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:2</deviceType>
<friendlyName>WANDevice</friendlyName>
<manufacturer>Sagemcom</manufacturer>
<manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
<modelDescription>WAN Device on Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
<modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
<modelNumber>3</modelNumber>
<modelURL>http://www.sagemcom.com/</modelURL>
<serialNumber>LK14129DP441489</serialNumber>
<presentationURL>http://192.168.1.1</presentationURL>
<UDN>uuid:e2397374-53d8-3fc6-8306-593ba1a34625</UDN>
<UPC></UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
<controlURL>/87895a19/upnp/control/WANCommonIFC1</controlURL>
<eventSubURL>/87895a19/upnp/control/WANCommonIFC1</eventSubURL>
<SCPDURL>/87895a19/gateicfgSCPD.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:2</deviceType>
<friendlyName>WANConnectionDevice</friendlyName>
<manufacturer>Sagemcom</manufacturer>
<manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
<modelDescription>WanConnectionDevice on Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
<modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
<modelNumber>3</modelNumber>
<modelURL>http://www.sagemcom.com/</modelURL>
<serialNumber>LK14129DP441489</serialNumber>
<presentationURL>http://192.168.1.1</presentationURL>
<UDN>uuid:44598a08-288e-32c9-8a4d-d3c008ede331</UDN>
<UPC></UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANPPPConnection:2</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
<controlURL>/87895a19/upnp/control/WANIPConn1</controlURL>
<eventSubURL>/87895a19/upnp/control/WANIPConn1</eventSubURL>
<SCPDURL>/87895a19/gateconnSCPD_PPP.xml</SCPDURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPv6FirewallControl:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPv6FwCtrl1</serviceId>
<controlURL>/87895a19/upnp/control/WANIPv6FwCtrl1</controlURL>
<eventSubURL>/87895a19/upnp/control/WANIPv6FwCtrl1</eventSubURL>
<SCPDURL>/87895a19/wanipv6fwctrlSCPD.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>

View File

@ -1,8 +1,8 @@
/* $Id: testigddescparse.c,v 1.4 2012/06/28 18:52:12 nanard Exp $ */
/* $Id: testigddescparse.c,v 1.7 2014/11/17 19:28:20 nanard Exp $ */
/* Project : miniupnp
* http://miniupnp.free.fr/
* Author : Thomas Bernard
* Copyright (c) 2008-2012 Thomas Bernard
* Copyright (c) 2008-2014 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution.
* */
@ -13,11 +13,108 @@
#include "minixml.h"
#include "miniupnpc.h"
int test_igd_desc_parse(char * buffer, int len)
/* count number of differences */
int compare_service(struct IGDdatas_service * s, FILE * f)
{
int n = 0;
char line[1024];
while(fgets(line, sizeof(line), f)) {
char * value;
char * equal;
char * name;
char * parsedvalue;
int l;
l = strlen(line);
while((l > 0) && ((line[l-1] == '\r') || (line[l-1] == '\n') || (line[l-1] == ' ')))
line[--l] = '\0';
if(l == 0)
break; /* end on blank line */
if(line[0] == '#')
continue; /* skip comments */
equal = strchr(line, '=');
if(equal == NULL) {
fprintf(stderr, "Warning, line does not contain '=' : %s\n", line);
continue;
}
*equal = '\0';
name = line;
while(*name == ' ' || *name == '\t')
name++;
l = strlen(name);
while((l > 0) && (name[l-1] == ' ' || name[l-1] == '\t'))
name[--l] = '\0';
value = equal + 1;
while(*value == ' ' || *value == '\t')
value++;
if(strcmp(name, "controlurl") == 0)
parsedvalue = s->controlurl;
else if(strcmp(name, "eventsuburl") == 0)
parsedvalue = s->eventsuburl;
else if(strcmp(name, "scpdurl") == 0)
parsedvalue = s->scpdurl;
else if(strcmp(name, "servicetype") == 0)
parsedvalue = s->servicetype;
else {
fprintf(stderr, "unknown field '%s'\n", name);
continue;
}
if(0 != strcmp(parsedvalue, value)) {
fprintf(stderr, "difference : '%s' != '%s'\n", parsedvalue, value);
n++;
}
}
return n;
}
int compare_igd(struct IGDdatas * p, FILE * f)
{
int n = 0;
char line[1024];
struct IGDdatas_service * s;
while(fgets(line, sizeof(line), f)) {
char * colon;
int l = (int)strlen(line);
while((l > 0) && (line[l-1] == '\r' || (line[l-1] == '\n')))
line[--l] = '\0';
if(l == 0 || line[0] == '#')
continue; /* skip blank lines and comments */
colon = strchr(line, ':');
if(colon == NULL) {
fprintf(stderr, "Warning, no ':' : %s\n", line);
continue;
}
s = NULL;
*colon = '\0';
if(strcmp(line, "CIF") == 0)
s = &p->CIF;
else if(strcmp(line, "first") == 0)
s = &p->first;
else if(strcmp(line, "second") == 0)
s = &p->second;
else if(strcmp(line, "IPv6FC") == 0)
s = &p->IPv6FC;
else {
s = NULL;
fprintf(stderr, "*** unknown service '%s' ***\n", line);
n++;
continue;
}
n += compare_service(s, f);
}
if(n > 0)
fprintf(stderr, "*** %d difference%s ***\n", n, (n > 1) ? "s" : "");
return n;
}
int test_igd_desc_parse(char * buffer, int len, FILE * f)
{
int n;
struct IGDdatas igd;
struct xmlparser parser;
struct UPNPUrls urls;
memset(&igd, 0, sizeof(struct IGDdatas));
memset(&parser, 0, sizeof(struct xmlparser));
parser.xmlstart = buffer;
@ -27,13 +124,16 @@ int test_igd_desc_parse(char * buffer, int len)
parser.endeltfunc = IGDendelt;
parser.datafunc = IGDdata;
parsexml(&parser);
#ifdef DEBUG
printIGD(&igd);
#endif /* DEBUG */
GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0);
printf("ipcondescURL='%s'\n", urls.ipcondescURL);
printf("controlURL='%s'\n", urls.controlURL);
printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
n = f ? compare_igd(&igd, f) : 0;
FreeUPNPUrls(&urls);
return 0;
return n;
}
int main(int argc, char * * argv)
@ -43,7 +143,7 @@ int main(int argc, char * * argv)
int len;
int r = 0;
if(argc<2) {
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]);
return 1;
}
f = fopen(argv[1], "r");
@ -57,8 +157,18 @@ int main(int argc, char * * argv)
buffer = malloc(len);
fread(buffer, 1, len, f);
fclose(f);
r = test_igd_desc_parse(buffer, len);
f = NULL;
if(argc > 2) {
f = fopen(argv[2], "r");
if(!f) {
fprintf(stderr, "Cannot open %s for reading.\n", argv[2]);
return 1;
}
}
r = test_igd_desc_parse(buffer, len, f);
free(buffer);
if(f)
fclose(f);
return r;
}