upnpdescgen.c: add force_igd1 param to XML description generation functions

This commit is contained in:
Thomas Bernard 2021-08-11 13:39:21 +02:00
parent 7c112e2b39
commit d8e5659c7b
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
4 changed files with 46 additions and 34 deletions

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard
* (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -142,6 +142,7 @@ void stupid_test(void)
int
main(int argc, char * * argv)
{
int force_igd1 = 0;
char * rootDesc;
int rootDescLen;
char * s;
@ -160,7 +161,7 @@ main(int argc, char * * argv)
return 0;
#ifdef IGD_V2
} else if(0 == strcmp(argv[l], "--forceigdv1")) {
SETFLAG(FORCEIGDDESCV1MASK);
force_igd1 = 1;
#endif
} else {
fprintf(stderr, "unknown option %s\n", argv[l]);
@ -173,7 +174,7 @@ main(int argc, char * * argv)
}
}
printf("Root Description :\n");
rootDesc = genRootDesc(&rootDescLen);
rootDesc = genRootDesc(&rootDescLen, force_igd1);
xml_pretty_print(rootDesc, rootDescLen, stdout);
f = fopen("testdescs/rootdesc.xml", "w");
if(f) {
@ -183,7 +184,7 @@ main(int argc, char * * argv)
free(rootDesc);
printf("\n-------------\n");
printf("WANIPConnection Description :\n");
s = genWANIPCn(&l);
s = genWANIPCn(&l, force_igd1);
xml_pretty_print(s, l, stdout);
f = fopen("testdescs/wanipc_scpd.xml", "w");
if(f) {
@ -193,7 +194,7 @@ main(int argc, char * * argv)
free(s);
printf("\n-------------\n");
printf("WANConfig Description :\n");
s = genWANCfg(&l);
s = genWANCfg(&l, force_igd1);
xml_pretty_print(s, l, stdout);
f = fopen("testdescs/wanconfig_scpd.xml", "w");
if(f) {
@ -204,7 +205,7 @@ main(int argc, char * * argv)
printf("\n-------------\n");
#ifdef ENABLE_L3F_SERVICE
printf("Layer3Forwarding service :\n");
s = genL3F(&l);
s = genL3F(&l, force_igd1);
xml_pretty_print(s, l, stdout);
f = fopen("testdescs/l3f_scpd.xml", "w");
if(f) {
@ -216,7 +217,7 @@ main(int argc, char * * argv)
#endif
#ifdef ENABLE_6FC_SERVICE
printf("WANIPv6FirewallControl service :\n");
s = gen6FC(&l);
s = gen6FC(&l, force_igd1);
xml_pretty_print(s, l, stdout);
f = fopen("testdescs/wanipv6fc_scpd.xml", "w");
if(f) {
@ -228,7 +229,7 @@ main(int argc, char * * argv)
#endif
#ifdef ENABLE_DP_SERVICE
printf("DeviceProtection service :\n");
s = genDP(&l);
s = genDP(&l, force_igd1);
xml_pretty_print(s, l, stdout);
f = fopen("testdescs/dp_scpd.xml", "w");
if(f) {

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard
* (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -887,7 +887,8 @@ strcat_int(char * str, int * len, int * tmplen, int i)
* This way, the progam stack usage is kept low */
static char *
genXML(char * str, int * len, int * tmplen,
const struct XMLElt * p)
const struct XMLElt * p,
int force_igd1)
{
#define GENXML_STACK_SIZE 16
unsigned short i, j;
@ -928,7 +929,7 @@ genXML(char * str, int * len, int * tmplen,
str = strcat_str(str, len, tmplen, p[i].data);
#ifdef IGD_V2
/* checking a single 'u' saves us 4 strcmp() calls most of the time */
if (GETFLAG(FORCEIGDDESCV1MASK) && (p[i].data[0] == 'u'))
if (force_igd1 && (p[i].data[0] == 'u'))
{
if ((strcmp(p[i].data, DEVICE_TYPE_IGD) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
@ -1003,7 +1004,7 @@ genXML(char * str, int * len, int * tmplen,
* the returned string.
* - tmp_uuid argument is used to build the uuid string */
char *
genRootDesc(int * len)
genRootDesc(int * len, int force_igd1)
{
char * str;
int tmplen;
@ -1014,7 +1015,7 @@ genRootDesc(int * len)
* len = strlen(xmlver);
/*strcpy(str, xmlver); */
memcpy(str, xmlver, *len + 1);
str = genXML(str, len, &tmplen, rootDesc);
str = genXML(str, len, &tmplen, rootDesc, force_igd1);
str[*len] = '\0';
return str;
}
@ -1023,7 +1024,7 @@ genRootDesc(int * len)
* Generate service description with allowed methods and
* related variables. */
static char *
genServiceDesc(int * len, const struct serviceDesc * s)
genServiceDesc(int * len, const struct serviceDesc * s, int force_igd1)
{
int i, j;
const struct action * acts;
@ -1054,6 +1055,12 @@ genServiceDesc(int * len, const struct serviceDesc * s)
str = strcat_str(str, len, &tmplen, "<actionList>");
while(acts[i].name)
{
#if defined(IGD_V2)
/* fake a IGD v1 for Microsoft clients :
* no DeletePortMappingRange, GetListOfPortMappings, AddAnyPortMapping */
if (force_igd1 && strcmp(acts[i].name, "DeletePortMappingRange") == 0)
break;
#endif
str = strcat_str(str, len, &tmplen, "<action><name>");
str = strcat_str(str, len, &tmplen, acts[i].name);
str = strcat_str(str, len, &tmplen, "</name>");
@ -1181,40 +1188,40 @@ genServiceDesc(int * len, const struct serviceDesc * s)
/* genWANIPCn() :
* Generate the WANIPConnection xml description */
char *
genWANIPCn(int * len)
genWANIPCn(int * len, int force_igd1)
{
return genServiceDesc(len, &scpdWANIPCn);
return genServiceDesc(len, &scpdWANIPCn, force_igd1);
}
/* genWANCfg() :
* Generate the WANInterfaceConfig xml description. */
char *
genWANCfg(int * len)
genWANCfg(int * len, int force_igd1)
{
return genServiceDesc(len, &scpdWANCfg);
return genServiceDesc(len, &scpdWANCfg, force_igd1);
}
#ifdef ENABLE_L3F_SERVICE
char *
genL3F(int * len)
genL3F(int * len, int force_igd1)
{
return genServiceDesc(len, &scpdL3F);
return genServiceDesc(len, &scpdL3F, force_igd1);
}
#endif
#ifdef ENABLE_6FC_SERVICE
char *
gen6FC(int * len)
gen6FC(int * len, int force_igd1)
{
return genServiceDesc(len, &scpd6FC);
return genServiceDesc(len, &scpd6FC, force_igd1);
}
#endif
#ifdef ENABLE_DP_SERVICE
char *
genDP(int * len)
genDP(int * len, int force_igd1)
{
return genServiceDesc(len, &scpdDP);
return genServiceDesc(len, &scpdDP, force_igd1);
}
#endif

View File

@ -1,7 +1,7 @@
/* $Id: upnpdescgen.h,v 1.22 2011/05/18 22:22:24 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2011 Thomas Bernard
* (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -53,28 +53,28 @@ struct stateVar {
/* char * genRootDesc(int *);
* returns: NULL on error, string allocated on the heap */
char *
genRootDesc(int * len);
genRootDesc(int * len, int force_igd1);
/* for the two following functions */
char *
genWANIPCn(int * len);
genWANIPCn(int * len, int force_igd1);
char *
genWANCfg(int * len);
genWANCfg(int * len, int force_igd1);
#ifdef ENABLE_L3F_SERVICE
char *
genL3F(int * len);
genL3F(int * len, int force_igd1);
#endif
#ifdef ENABLE_6FC_SERVICE
char *
gen6FC(int * len);
gen6FC(int * len, int force_igd1);
#endif
#ifdef ENABLE_DP_SERVICE
char *
genDP(int * len);
genDP(int * len, int force_igd1);
#endif
#ifdef ENABLE_EVENTS

View File

@ -458,11 +458,15 @@ sendDummyDesc(struct upnphttp * h)
/* Sends the description generated by the parameter */
static void
sendXMLdesc(struct upnphttp * h, char * (f)(int *))
sendXMLdesc(struct upnphttp * h, char * (f)(int *, int))
{
char * desc;
int len;
desc = f(&len);
#ifdef IGD_V2
desc = f(&len, GETFLAG(FORCEIGDDESCV1MASK));
#else
desc = f(&len, 0);
#endif
if(!desc)
{
static const char error500[] = "<HTML><HEAD><TITLE>Error 500</TITLE>"
@ -746,7 +750,7 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
{
static const struct {
const char * path;
char * (* f)(int *);
char * (* f)(int *, int);
} path_desc[] = {
{ ROOTDESC_PATH, genRootDesc},
{ WANIPC_PATH, genWANIPCn},