Ticket #2338: fix-trac-2338-style2_v2.patch
File fix-trac-2338-style2_v2.patch, 2.3 KB (added by , 10 years ago) |
---|
-
source/network/NetServer.cpp
225 225 if (!rootDescURL.empty()) 226 226 LOGMESSAGE(L"Net server: attempting to use cached root descriptor URL: %hs", rootDescURL.c_str()); 227 227 228 // Init the return variable for UPNP_GetValidIGD to 1 so things behave when using cached URLs. 229 int ret = 1; 228 // Init the return variable for UPNP_GetValidIGD to 0. 229 int ret = 0; 230 bool bAllocatedDescriptorURL = false; 230 231 231 232 // If we have a cached URL, try that first, otherwise try getting a valid UPnP device for 10 seconds. We also get our LAN address here. 232 if (!((!rootDescURL.empty() && UPNP_GetIGDFromUrl(rootDescURL.c_str(), &urls, &data, internalIPAddress, sizeof(internalIPAddress))) 233 || ((devlist = upnpDiscover(10000, 0, 0, 0, 0, 0)) != NULL && (ret = UPNP_GetValidIGD(devlist, &urls, &data, internalIPAddress, sizeof(internalIPAddress))) != 0))) 233 if (!rootDescURL.empty() && UPNP_GetIGDFromUrl(rootDescURL.c_str(), &urls, &data, internalIPAddress, sizeof(internalIPAddress))) 234 234 { 235 LOGMESSAGE(L"Net server: using cached IGD = %hs", urls.controlURL); 236 // Init the return variable for UPNP_GetValidIGD to 1 so things behave when using cached URLs. 237 ret = 1; 238 } else if ((devlist = upnpDiscover(10000, 0, 0, 0, 0, 0)) != NULL) { 239 // Else if we don't have a cached URL, or the one cached didn't respond. Try getting a valid UPnP device for 10 seconds 240 241 // UPNP_GetValidIGD() allocates struct UPNPUrls urls on the stack for all non-zero return value. 242 if (ret = UPNP_GetValidIGD(devlist, &urls, &data, internalIPAddress, sizeof(internalIPAddress))) 243 bAllocatedDescriptorURL = true; 244 } else { 235 245 LOGMESSAGE(L"Net server: upnpDiscover failed and no working cached URL."); 236 246 return NULL; 237 247 } 238 248 239 249 switch (ret) 240 250 { 251 case 0: 252 LOGMESSAGE(L"Net server: No IGD found"); 253 break; 241 254 case 1: 242 255 LOGMESSAGE(L"Net server: found valid IGD = %hs", urls.controlURL); 243 256 break; … … 295 308 LOGMESSAGE(L"Net server: cached UPnP root descriptor URL as %hs", urls.controlURL); 296 309 297 310 // Make sure everything is properly freed. 298 FreeUPNPUrls(&urls); 311 if (bAllocatedDescriptorURL) 312 FreeUPNPUrls(&urls); 313 299 314 freeUPNPDevlist(devlist); 300 315 301 316 return NULL;