Only try to fetch XML description once in UPNP_GetValidIGD()
This commit is contained in:
parent
175bd2894f
commit
f42e4060cb
|
@ -2,6 +2,7 @@ $Id: Changelog.txt,v 1.166 2012/04/09 12:49:26 nanard Exp $
|
|||
miniUPnP client Changelog.
|
||||
|
||||
2012/04/09:
|
||||
Only try to fetch XML description once in UPNP_GetValidIGD()
|
||||
Added -ansi flag to compilation, and fixed C++ comments to ANSI C comments.
|
||||
|
||||
2012/04/05:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: miniupnpc.c,v 1.102 2012/01/21 13:56:41 nanard Exp $ */
|
||||
/* $Id: miniupnpc.c,v 1.104 2012/04/09 12:40:11 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* Web : http://miniupnp.free.fr/
|
||||
* Author : Thomas BERNARD
|
||||
|
@ -816,6 +816,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data)
|
|||
|
||||
/* UPNP_GetValidIGD() :
|
||||
* return values :
|
||||
* -1 = Internal error
|
||||
* 0 = NO IGD found
|
||||
* 1 = A valid connected IGD has been found
|
||||
* 2 = A valid IGD has been found but it reported as
|
||||
|
@ -832,11 +833,14 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
|
|||
struct IGDdatas * data,
|
||||
char * lanaddr, int lanaddrlen)
|
||||
{
|
||||
char * descXML;
|
||||
int descXMLsize = 0;
|
||||
struct xml_desc {
|
||||
char * xml;
|
||||
int size;
|
||||
} * desc = NULL;
|
||||
struct UPNPDev * dev;
|
||||
int ndev = 0;
|
||||
int state; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */
|
||||
int i;
|
||||
int state = -1; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */
|
||||
if(!devlist)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
@ -844,22 +848,36 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
for(dev = devlist; dev; dev = dev->pNext)
|
||||
ndev++;
|
||||
if(ndev > 0)
|
||||
{
|
||||
desc = calloc(ndev, sizeof(struct xml_desc));
|
||||
if(!desc)
|
||||
return -1; /* memory allocation error */
|
||||
}
|
||||
for(state = 1; state <= 3; state++)
|
||||
{
|
||||
for(dev = devlist; dev; dev = dev->pNext)
|
||||
for(dev = devlist, i = 0; dev; dev = dev->pNext, i++)
|
||||
{
|
||||
/* we should choose an internet gateway device.
|
||||
* with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */
|
||||
descXML = miniwget_getaddr(dev->descURL, &descXMLsize,
|
||||
lanaddr, lanaddrlen);
|
||||
if(descXML)
|
||||
if(state == 1)
|
||||
{
|
||||
desc[i].xml = miniwget_getaddr(dev->descURL, &(desc[i].size),
|
||||
lanaddr, lanaddrlen);
|
||||
#ifdef DEBUG
|
||||
if(!desc[i].xml)
|
||||
{
|
||||
printf("error getting XML description %s\n", dev->descURL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if(desc[i].xml)
|
||||
{
|
||||
ndev++;
|
||||
memset(data, 0, sizeof(struct IGDdatas));
|
||||
memset(urls, 0, sizeof(struct UPNPUrls));
|
||||
parserootdesc(descXML, descXMLsize, data);
|
||||
free(descXML);
|
||||
descXML = NULL;
|
||||
parserootdesc(desc[i].xml, desc[i].size, data);
|
||||
if(0==strcmp(data->CIF.servicetype,
|
||||
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")
|
||||
|| state >= 3 )
|
||||
|
@ -872,7 +890,7 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
|
|||
UPNPIGD_IsConnected(urls, data));
|
||||
#endif
|
||||
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
|
||||
return state;
|
||||
goto free_and_return;
|
||||
FreeUPNPUrls(urls);
|
||||
if(data->second.servicetype[0] != '\0') {
|
||||
#ifdef DEBUG
|
||||
|
@ -890,21 +908,18 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
|
|||
UPNPIGD_IsConnected(urls, data));
|
||||
#endif
|
||||
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
|
||||
return state;
|
||||
goto free_and_return;
|
||||
FreeUPNPUrls(urls);
|
||||
}
|
||||
}
|
||||
memset(data, 0, sizeof(struct IGDdatas));
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
{
|
||||
printf("error getting XML description %s\n", dev->descURL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
state = 0;
|
||||
free_and_return:
|
||||
free(desc);
|
||||
return state;
|
||||
}
|
||||
|
||||
/* UPNP_GetIGDFromUrl()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: miniupnpc.h,v 1.25 2011/10/09 16:17:29 nanard Exp $ */
|
||||
/* $Id: miniupnpc.h,v 1.26 2012/04/09 12:40:11 nanard Exp $ */
|
||||
/* Project: miniupnp
|
||||
* http://miniupnp.free.fr/
|
||||
* Author: Thomas Bernard
|
||||
|
@ -83,6 +83,7 @@ struct UPNPUrls {
|
|||
|
||||
/* UPNP_GetValidIGD() :
|
||||
* return values :
|
||||
* -1 = Internal error
|
||||
* 0 = NO IGD found
|
||||
* 1 = A valid connected IGD has been found
|
||||
* 2 = A valid IGD has been found but it reported as
|
||||
|
|
Loading…
Reference in New Issue