diff options
author | elupus <elupus@xbmc.org> | 2012-03-31 20:19:09 +0200 |
---|---|---|
committer | elupus <elupus@xbmc.org> | 2012-03-31 20:22:11 +0200 |
commit | cb110ea28b7506cb31d6ab4fd347fad1c96ec9ed (patch) | |
tree | ab05d8fac59a44a8225e812794ab59d23d72abdd /lib | |
parent | 7cb1420b17046330d6d340daea176f03da78bb9e (diff) |
[UPnP] use server provided item count to iterate browse req
This could potentially solve issues where server returns
a different number of items than it says it returns
or we fail to parse a returned item properly.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp index 00e3df36dc..dac36f7d07 100644 --- a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp +++ b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp @@ -35,6 +35,7 @@ | includes +---------------------------------------------------------------------*/ #include "PltSyncMediaBrowser.h" +#include <algorithm> NPT_SET_LOCAL_LOGGER("platinum.media.server.syncbrowser") @@ -237,6 +238,7 @@ PLT_SyncMediaBrowser::BrowseSync(PLT_DeviceDataReference& device, { NPT_Result res = NPT_FAILURE; NPT_Int32 index = start; + NPT_UInt32 count = 0; bool cache = m_UseCache && metadata && start == 0 && max_results == 0; // reset output params @@ -265,9 +267,14 @@ PLT_SyncMediaBrowser::BrowseSync(PLT_DeviceDataReference& device, NPT_CHECK_LABEL_WARNING(res, done); } - if (browse_data->info.items->GetItemCount() == 0) + if (browse_data->info.nr == 0) break; + if (browse_data->info.nr != browse_data->info.items->GetItemCount()) { + NPT_LOG_WARNING_2("Server unexpected number of items (%d vs %d)", browse_data->info.items->GetItemCount(), browse_data->info.nr); + } + count += std::max<NPT_UInt32>(browse_data->info.nr, browse_data->info.items->GetItemCount()); + if (list.IsNull()) { list = browse_data->info.items; } else { @@ -284,12 +291,12 @@ PLT_SyncMediaBrowser::BrowseSync(PLT_DeviceDataReference& device, // nothing is returned back by the server. // Unless we were told to stop after reaching a certain amount to avoid // length delays - if ((browse_data->info.tm && browse_data->info.tm <= list->GetItemCount()) || - (max_results && list->GetItemCount() >= max_results)) + if ((browse_data->info.tm && browse_data->info.tm <= count) || + (max_results && count >= max_results)) break; // ask for the next chunk of entries - index = list->GetItemCount(); + index = count; } while(1); done: |