XML parsing fixes
GIPdA opened this issue ยท 7 comments
Hello,
Found a small issue in the XML parsing that happens when the XML has multiple <serviceType>
tags, like with my router.
It's just a matter of passing a "from" index to some String::indexOf() calls, and the right substring to getTagContent()
. The issue might repeat elsewhere, I didn't checked everything. But it worked for me after this fix.
Line 702-ish in getIGDEventURLs(), TinyUPnP.cpp:
int service_type_index_start = 0;
int service_type_1_index = line.indexOf(UPNP_SERVICE_TYPE_TAG_START + UPNP_SERVICE_TYPE_1);
if (service_type_1_index >= 0) {
service_type_index_start = service_type_1_index;
service_type_1_index = line.indexOf(UPNP_SERVICE_TYPE_TAG_END, service_type_1_index);
}
int service_type_2_index = line.indexOf(UPNP_SERVICE_TYPE_TAG_START + UPNP_SERVICE_TYPE_2);
if (service_type_2_index >= 0) {
service_type_index_start = service_type_2_index;
service_type_2_index = line.indexOf(UPNP_SERVICE_TYPE_TAG_END, service_type_2_index);
}
if (!upnpServiceFound && service_type_1_index >= 0) {
index_in_line += service_type_1_index;
upnpServiceFound = true;
deviceInfo->serviceTypeName = getTagContent(line.substring(service_type_index_start), UPNP_SERVICE_TYPE_TAG_NAME);
debugPrintln(deviceInfo->serviceTypeName + " service found!");
// will start looking for 'controlURL' now
} else if (!upnpServiceFound && service_type_2_index >= 0) {
index_in_line += service_type_2_index;
upnpServiceFound = true;
deviceInfo->serviceTypeName = getTagContent(line.substring(service_type_index_start), UPNP_SERVICE_TYPE_TAG_NAME);
debugPrintln(deviceInfo->serviceTypeName + " service found!");
// will start looking for 'controlURL' now
}
Thanks for letting me know.
Can you please include the xml file from your router so I can test this?
Here it is.
gatedesc1.txt
I also made it work with an ESP32, but there are a few changes to make so I'll try to push a PR soon.
Also, the loads of debug when enabled is enough to crash an ESP32...
Hey @GIPdA,
Made the change you suggested, any chance you can upload this and check with your device?
multiServiceTypeTags
Hello,
Tested, and it's working great (still using a ESP32).
I also have a crash issue, but unrelated so I will open a new one.
Thanks for confirming.
Please open a separate issue for the crash with all the needed information, will try to help you there.
Hi, nice work.
Just wanted to let you know this issue should be closed.
Thanks @gnalbandian.