miniupnpc.c: change upnpDiscoverDevice() to stop when devices are
This commit is contained in:
parent
cb054ef580
commit
91602e129d
|
@ -338,7 +338,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
"MAN: \"ssdp:discover\"\r\n"
|
||||
"MX: %u\r\n"
|
||||
"\r\n";
|
||||
int deviceIndex = 0;
|
||||
int deviceIndex;
|
||||
char bufr[1536]; /* reception and emission buffer */
|
||||
int sudp;
|
||||
int n;
|
||||
|
@ -361,7 +361,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
/* first try to get infos from minissdpd ! */
|
||||
if(!minissdpdsock)
|
||||
minissdpdsock = "/var/run/minissdpd.sock";
|
||||
while(!devlist && deviceTypes[deviceIndex]) {
|
||||
for(deviceIndex = 0; !devlist && deviceTypes[deviceIndex]; deviceIndex++) {
|
||||
devlist = getDevicesFromMiniSSDPD(deviceTypes[deviceIndex],
|
||||
minissdpdsock);
|
||||
/* We return what we have found if it was not only a rootdevice */
|
||||
|
@ -370,9 +370,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
*error = UPNPDISCOVER_SUCCESS;
|
||||
return devlist;
|
||||
}
|
||||
deviceIndex++;
|
||||
}
|
||||
deviceIndex = 0;
|
||||
#endif
|
||||
/* fallback to direct discovery */
|
||||
#ifdef _WIN32
|
||||
|
@ -536,8 +534,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
/* Calculating maximum response time in seconds */
|
||||
mx = ((unsigned int)delay) / 1000u;
|
||||
/* receiving SSDP response packet */
|
||||
for(n = 0; deviceTypes[deviceIndex]; deviceIndex++) {
|
||||
if(n == 0) {
|
||||
for(deviceIndex = 0; deviceTypes[deviceIndex]; deviceIndex++) {
|
||||
/* sending the SSDP M-SEARCH packet */
|
||||
n = snprintf(bufr, sizeof(bufr),
|
||||
MSearchMsgFmt,
|
||||
|
@ -617,7 +614,6 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
break;
|
||||
}
|
||||
#endif /* #ifdef NO_GETADDRINFO */
|
||||
}
|
||||
/* Waiting for SSDP REPLY packet to M-SEARCH */
|
||||
do {
|
||||
n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id);
|
||||
|
@ -629,14 +625,13 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
} else if (n == 0) {
|
||||
/* no data or Time Out */
|
||||
if (devlist) {
|
||||
/* no more device type to look for... */
|
||||
/* found some devices, stop now*/
|
||||
if(error)
|
||||
*error = UPNPDISCOVER_SUCCESS;
|
||||
#if 0
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
if(ipv6) {
|
||||
/* switch linklocal flag */
|
||||
if(linklocal) {
|
||||
linklocal = 0;
|
||||
--deviceIndex;
|
||||
|
@ -649,7 +644,6 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
int urlsize=0;
|
||||
const char * st=NULL;
|
||||
int stsize=0;
|
||||
/*printf("%d byte(s) :\n%s\n", n, bufr);*/ /* affichage du message */
|
||||
parseMSEARCHReply(bufr, n, &descURL, &urlsize, &st, &stsize);
|
||||
if(st&&descURL) {
|
||||
#ifdef DEBUG
|
||||
|
@ -672,7 +666,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
|
|||
/* memory allocation error */
|
||||
if(error)
|
||||
*error = UPNPDISCOVER_MEMORY_ERROR;
|
||||
break;
|
||||
goto error;
|
||||
}
|
||||
tmp->pNext = devlist;
|
||||
tmp->descURL = tmp->buffer;
|
||||
|
|
Loading…
Reference in New Issue