mirror of
https://github.com/status-im/miniupnp.git
synced 2025-01-31 08:36:16 +00:00
upnpdescgen.c: add force_igd1 param to XML description generation functions
This commit is contained in:
parent
7c112e2b39
commit
d8e5659c7b
@ -2,7 +2,7 @@
|
|||||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||||
* MiniUPnP project
|
* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* 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
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
|
||||||
@ -142,6 +142,7 @@ void stupid_test(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char * * argv)
|
main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
|
int force_igd1 = 0;
|
||||||
char * rootDesc;
|
char * rootDesc;
|
||||||
int rootDescLen;
|
int rootDescLen;
|
||||||
char * s;
|
char * s;
|
||||||
@ -160,7 +161,7 @@ main(int argc, char * * argv)
|
|||||||
return 0;
|
return 0;
|
||||||
#ifdef IGD_V2
|
#ifdef IGD_V2
|
||||||
} else if(0 == strcmp(argv[l], "--forceigdv1")) {
|
} else if(0 == strcmp(argv[l], "--forceigdv1")) {
|
||||||
SETFLAG(FORCEIGDDESCV1MASK);
|
force_igd1 = 1;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "unknown option %s\n", argv[l]);
|
fprintf(stderr, "unknown option %s\n", argv[l]);
|
||||||
@ -173,7 +174,7 @@ main(int argc, char * * argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Root Description :\n");
|
printf("Root Description :\n");
|
||||||
rootDesc = genRootDesc(&rootDescLen);
|
rootDesc = genRootDesc(&rootDescLen, force_igd1);
|
||||||
xml_pretty_print(rootDesc, rootDescLen, stdout);
|
xml_pretty_print(rootDesc, rootDescLen, stdout);
|
||||||
f = fopen("testdescs/rootdesc.xml", "w");
|
f = fopen("testdescs/rootdesc.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
@ -183,7 +184,7 @@ main(int argc, char * * argv)
|
|||||||
free(rootDesc);
|
free(rootDesc);
|
||||||
printf("\n-------------\n");
|
printf("\n-------------\n");
|
||||||
printf("WANIPConnection Description :\n");
|
printf("WANIPConnection Description :\n");
|
||||||
s = genWANIPCn(&l);
|
s = genWANIPCn(&l, force_igd1);
|
||||||
xml_pretty_print(s, l, stdout);
|
xml_pretty_print(s, l, stdout);
|
||||||
f = fopen("testdescs/wanipc_scpd.xml", "w");
|
f = fopen("testdescs/wanipc_scpd.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
@ -193,7 +194,7 @@ main(int argc, char * * argv)
|
|||||||
free(s);
|
free(s);
|
||||||
printf("\n-------------\n");
|
printf("\n-------------\n");
|
||||||
printf("WANConfig Description :\n");
|
printf("WANConfig Description :\n");
|
||||||
s = genWANCfg(&l);
|
s = genWANCfg(&l, force_igd1);
|
||||||
xml_pretty_print(s, l, stdout);
|
xml_pretty_print(s, l, stdout);
|
||||||
f = fopen("testdescs/wanconfig_scpd.xml", "w");
|
f = fopen("testdescs/wanconfig_scpd.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
@ -204,7 +205,7 @@ main(int argc, char * * argv)
|
|||||||
printf("\n-------------\n");
|
printf("\n-------------\n");
|
||||||
#ifdef ENABLE_L3F_SERVICE
|
#ifdef ENABLE_L3F_SERVICE
|
||||||
printf("Layer3Forwarding service :\n");
|
printf("Layer3Forwarding service :\n");
|
||||||
s = genL3F(&l);
|
s = genL3F(&l, force_igd1);
|
||||||
xml_pretty_print(s, l, stdout);
|
xml_pretty_print(s, l, stdout);
|
||||||
f = fopen("testdescs/l3f_scpd.xml", "w");
|
f = fopen("testdescs/l3f_scpd.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
@ -216,7 +217,7 @@ main(int argc, char * * argv)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_6FC_SERVICE
|
#ifdef ENABLE_6FC_SERVICE
|
||||||
printf("WANIPv6FirewallControl service :\n");
|
printf("WANIPv6FirewallControl service :\n");
|
||||||
s = gen6FC(&l);
|
s = gen6FC(&l, force_igd1);
|
||||||
xml_pretty_print(s, l, stdout);
|
xml_pretty_print(s, l, stdout);
|
||||||
f = fopen("testdescs/wanipv6fc_scpd.xml", "w");
|
f = fopen("testdescs/wanipv6fc_scpd.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
@ -228,7 +229,7 @@ main(int argc, char * * argv)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_DP_SERVICE
|
#ifdef ENABLE_DP_SERVICE
|
||||||
printf("DeviceProtection service :\n");
|
printf("DeviceProtection service :\n");
|
||||||
s = genDP(&l);
|
s = genDP(&l, force_igd1);
|
||||||
xml_pretty_print(s, l, stdout);
|
xml_pretty_print(s, l, stdout);
|
||||||
f = fopen("testdescs/dp_scpd.xml", "w");
|
f = fopen("testdescs/dp_scpd.xml", "w");
|
||||||
if(f) {
|
if(f) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||||
* MiniUPnP project
|
* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
* 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
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* 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 */
|
* This way, the progam stack usage is kept low */
|
||||||
static char *
|
static char *
|
||||||
genXML(char * str, int * len, int * tmplen,
|
genXML(char * str, int * len, int * tmplen,
|
||||||
const struct XMLElt * p)
|
const struct XMLElt * p,
|
||||||
|
int force_igd1)
|
||||||
{
|
{
|
||||||
#define GENXML_STACK_SIZE 16
|
#define GENXML_STACK_SIZE 16
|
||||||
unsigned short i, j;
|
unsigned short i, j;
|
||||||
@ -928,7 +929,7 @@ genXML(char * str, int * len, int * tmplen,
|
|||||||
str = strcat_str(str, len, tmplen, p[i].data);
|
str = strcat_str(str, len, tmplen, p[i].data);
|
||||||
#ifdef IGD_V2
|
#ifdef IGD_V2
|
||||||
/* checking a single 'u' saves us 4 strcmp() calls most of the time */
|
/* 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) ||
|
if ((strcmp(p[i].data, DEVICE_TYPE_IGD) == 0) ||
|
||||||
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
|
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
|
||||||
@ -1003,7 +1004,7 @@ genXML(char * str, int * len, int * tmplen,
|
|||||||
* the returned string.
|
* the returned string.
|
||||||
* - tmp_uuid argument is used to build the uuid string */
|
* - tmp_uuid argument is used to build the uuid string */
|
||||||
char *
|
char *
|
||||||
genRootDesc(int * len)
|
genRootDesc(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
char * str;
|
char * str;
|
||||||
int tmplen;
|
int tmplen;
|
||||||
@ -1014,7 +1015,7 @@ genRootDesc(int * len)
|
|||||||
* len = strlen(xmlver);
|
* len = strlen(xmlver);
|
||||||
/*strcpy(str, xmlver); */
|
/*strcpy(str, xmlver); */
|
||||||
memcpy(str, xmlver, *len + 1);
|
memcpy(str, xmlver, *len + 1);
|
||||||
str = genXML(str, len, &tmplen, rootDesc);
|
str = genXML(str, len, &tmplen, rootDesc, force_igd1);
|
||||||
str[*len] = '\0';
|
str[*len] = '\0';
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@ -1023,7 +1024,7 @@ genRootDesc(int * len)
|
|||||||
* Generate service description with allowed methods and
|
* Generate service description with allowed methods and
|
||||||
* related variables. */
|
* related variables. */
|
||||||
static char *
|
static char *
|
||||||
genServiceDesc(int * len, const struct serviceDesc * s)
|
genServiceDesc(int * len, const struct serviceDesc * s, int force_igd1)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
const struct action * acts;
|
const struct action * acts;
|
||||||
@ -1054,6 +1055,12 @@ genServiceDesc(int * len, const struct serviceDesc * s)
|
|||||||
str = strcat_str(str, len, &tmplen, "<actionList>");
|
str = strcat_str(str, len, &tmplen, "<actionList>");
|
||||||
while(acts[i].name)
|
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, "<action><name>");
|
||||||
str = strcat_str(str, len, &tmplen, acts[i].name);
|
str = strcat_str(str, len, &tmplen, acts[i].name);
|
||||||
str = strcat_str(str, len, &tmplen, "</name>");
|
str = strcat_str(str, len, &tmplen, "</name>");
|
||||||
@ -1181,40 +1188,40 @@ genServiceDesc(int * len, const struct serviceDesc * s)
|
|||||||
/* genWANIPCn() :
|
/* genWANIPCn() :
|
||||||
* Generate the WANIPConnection xml description */
|
* Generate the WANIPConnection xml description */
|
||||||
char *
|
char *
|
||||||
genWANIPCn(int * len)
|
genWANIPCn(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
return genServiceDesc(len, &scpdWANIPCn);
|
return genServiceDesc(len, &scpdWANIPCn, force_igd1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* genWANCfg() :
|
/* genWANCfg() :
|
||||||
* Generate the WANInterfaceConfig xml description. */
|
* Generate the WANInterfaceConfig xml description. */
|
||||||
char *
|
char *
|
||||||
genWANCfg(int * len)
|
genWANCfg(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
return genServiceDesc(len, &scpdWANCfg);
|
return genServiceDesc(len, &scpdWANCfg, force_igd1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_L3F_SERVICE
|
#ifdef ENABLE_L3F_SERVICE
|
||||||
char *
|
char *
|
||||||
genL3F(int * len)
|
genL3F(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
return genServiceDesc(len, &scpdL3F);
|
return genServiceDesc(len, &scpdL3F, force_igd1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_6FC_SERVICE
|
#ifdef ENABLE_6FC_SERVICE
|
||||||
char *
|
char *
|
||||||
gen6FC(int * len)
|
gen6FC(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
return genServiceDesc(len, &scpd6FC);
|
return genServiceDesc(len, &scpd6FC, force_igd1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DP_SERVICE
|
#ifdef ENABLE_DP_SERVICE
|
||||||
char *
|
char *
|
||||||
genDP(int * len)
|
genDP(int * len, int force_igd1)
|
||||||
{
|
{
|
||||||
return genServiceDesc(len, &scpdDP);
|
return genServiceDesc(len, &scpdDP, force_igd1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* $Id: upnpdescgen.h,v 1.22 2011/05/18 22:22:24 nanard Exp $ */
|
/* $Id: upnpdescgen.h,v 1.22 2011/05/18 22:22:24 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* 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
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
|
||||||
@ -53,28 +53,28 @@ struct stateVar {
|
|||||||
/* char * genRootDesc(int *);
|
/* char * genRootDesc(int *);
|
||||||
* returns: NULL on error, string allocated on the heap */
|
* returns: NULL on error, string allocated on the heap */
|
||||||
char *
|
char *
|
||||||
genRootDesc(int * len);
|
genRootDesc(int * len, int force_igd1);
|
||||||
|
|
||||||
/* for the two following functions */
|
/* for the two following functions */
|
||||||
char *
|
char *
|
||||||
genWANIPCn(int * len);
|
genWANIPCn(int * len, int force_igd1);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
genWANCfg(int * len);
|
genWANCfg(int * len, int force_igd1);
|
||||||
|
|
||||||
#ifdef ENABLE_L3F_SERVICE
|
#ifdef ENABLE_L3F_SERVICE
|
||||||
char *
|
char *
|
||||||
genL3F(int * len);
|
genL3F(int * len, int force_igd1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_6FC_SERVICE
|
#ifdef ENABLE_6FC_SERVICE
|
||||||
char *
|
char *
|
||||||
gen6FC(int * len);
|
gen6FC(int * len, int force_igd1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DP_SERVICE
|
#ifdef ENABLE_DP_SERVICE
|
||||||
char *
|
char *
|
||||||
genDP(int * len);
|
genDP(int * len, int force_igd1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_EVENTS
|
#ifdef ENABLE_EVENTS
|
||||||
|
@ -458,11 +458,15 @@ sendDummyDesc(struct upnphttp * h)
|
|||||||
|
|
||||||
/* Sends the description generated by the parameter */
|
/* Sends the description generated by the parameter */
|
||||||
static void
|
static void
|
||||||
sendXMLdesc(struct upnphttp * h, char * (f)(int *))
|
sendXMLdesc(struct upnphttp * h, char * (f)(int *, int))
|
||||||
{
|
{
|
||||||
char * desc;
|
char * desc;
|
||||||
int len;
|
int len;
|
||||||
desc = f(&len);
|
#ifdef IGD_V2
|
||||||
|
desc = f(&len, GETFLAG(FORCEIGDDESCV1MASK));
|
||||||
|
#else
|
||||||
|
desc = f(&len, 0);
|
||||||
|
#endif
|
||||||
if(!desc)
|
if(!desc)
|
||||||
{
|
{
|
||||||
static const char error500[] = "<HTML><HEAD><TITLE>Error 500</TITLE>"
|
static const char error500[] = "<HTML><HEAD><TITLE>Error 500</TITLE>"
|
||||||
@ -746,7 +750,7 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
|
|||||||
{
|
{
|
||||||
static const struct {
|
static const struct {
|
||||||
const char * path;
|
const char * path;
|
||||||
char * (* f)(int *);
|
char * (* f)(int *, int);
|
||||||
} path_desc[] = {
|
} path_desc[] = {
|
||||||
{ ROOTDESC_PATH, genRootDesc},
|
{ ROOTDESC_PATH, genRootDesc},
|
||||||
{ WANIPC_PATH, genWANIPCn},
|
{ WANIPC_PATH, genWANIPCn},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user