Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use a helper function to retrieve the CPluginDirectory instance from …

…the handle, thanks to ulion
  • Loading branch information...
commit 2c1be2ce5a8bf58ef0d52ed2f8c3b9fe681e13b0 1 parent 88e6ffa
Jonathan Marshall authored
85 xbmc/filesystem/PluginDirectory.cpp
View
@@ -76,6 +76,15 @@ void CPluginDirectory::removeHandle(int handle)
globalHandles.erase(globalHandles.begin() + handle);
}
+CPluginDirectory *CPluginDirectory::dirFromHandle(int handle)
+{
+ CSingleLock lock(m_handleLock);
+ if (handle >= 0 && handle < (int)globalHandles.size())
+ return globalHandles[handle];
+ CLog::Log(LOGWARNING, "Attempt to use invalid handle %i", handle);
+ return NULL;
+}
+
bool CPluginDirectory::StartScript(const CStdString& strPath, bool retrievingDir)
{
CURL url(strPath);
@@ -161,13 +170,10 @@ bool CPluginDirectory::GetPluginResult(const CStdString& strPath, CFileItem &res
bool CPluginDirectory::AddItem(int handle, const CFileItem *item, int totalItems)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, " %s - called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return false;
- }
- CPluginDirectory *dir = globalHandles[handle];
CFileItemPtr pItem(new CFileItem(*item));
dir->m_listItems->Add(pItem);
dir->m_totalItems = totalItems;
@@ -178,13 +184,10 @@ bool CPluginDirectory::AddItem(int handle, const CFileItem *item, int totalItems
bool CPluginDirectory::AddItems(int handle, const CFileItemList *items, int totalItems)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, " %s - called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return false;
- }
- CPluginDirectory *dir = globalHandles[handle];
CFileItemList pItemList;
pItemList.Copy(*items);
dir->m_listItems->Append(pItemList);
@@ -196,12 +199,9 @@ bool CPluginDirectory::AddItems(int handle, const CFileItemList *items, int tota
void CPluginDirectory::EndOfDirectory(int handle, bool success, bool replaceListing, bool cacheToDisc)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, " %s - called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return;
- }
- CPluginDirectory *dir = globalHandles[handle];
// set cache to disc
dir->m_listItems->SetCacheToDisc(cacheToDisc ? CFileItemList::CACHE_IF_SLOW : CFileItemList::CACHE_NEVER);
@@ -219,13 +219,9 @@ void CPluginDirectory::EndOfDirectory(int handle, bool success, bool replaceList
void CPluginDirectory::AddSortMethod(int handle, SORT_METHOD sortMethod, const CStdString &label2Mask)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, "%s - called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return;
- }
-
- CPluginDirectory *dir = globalHandles[handle];
// TODO: Add all sort methods and fix which labels go on the right or left
switch(sortMethod)
@@ -556,12 +552,9 @@ bool CPluginDirectory::WaitOnScriptResult(const CStdString &scriptPath, int scri
void CPluginDirectory::SetResolvedUrl(int handle, bool success, const CFileItem *resultItem)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, " %s - called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return;
- }
- CPluginDirectory* dir = globalHandles[handle];
dir->m_success = success;
*dir->m_fileResult = *resultItem;
@@ -572,14 +565,9 @@ void CPluginDirectory::SetResolvedUrl(int handle, bool success, const CFileItem
CStdString CPluginDirectory::GetSetting(int handle, const CStdString &strID)
{
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, "%s called with an invalid handle.", __FUNCTION__);
- return "";
- }
-
- CPluginDirectory *dir = globalHandles[handle];
- if(dir->m_addon)
+ CSingleLock lock(m_handleLock);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if(dir && dir->m_addon)
return dir->m_addon->GetSetting(strID);
else
return "";
@@ -587,39 +575,26 @@ CStdString CPluginDirectory::GetSetting(int handle, const CStdString &strID)
void CPluginDirectory::SetSetting(int handle, const CStdString &strID, const CStdString &value)
{
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, "%s called with an invalid handle.", __FUNCTION__);
- return;
- }
-
- CPluginDirectory *dir = globalHandles[handle];
+ CSingleLock lock(m_handleLock);
+ CPluginDirectory *dir = dirFromHandle(handle);
if(dir->m_addon)
ulion Collaborator
ulion added a note

didn't check dir non-NULL here, although it's not likely to be NULL.

jmarshallnz Owner

Thanks for picking it up - will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
dir->m_addon->UpdateSetting(strID, value);
}
void CPluginDirectory::SetContent(int handle, const CStdString &strContent)
{
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, "%s called with an invalid handle.", __FUNCTION__);
- return;
- }
-
- CPluginDirectory *dir = globalHandles[handle];
- dir->m_listItems->SetContent(strContent);
+ CSingleLock lock(m_handleLock);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (dir)
+ dir->m_listItems->SetContent(strContent);
}
void CPluginDirectory::SetProperty(int handle, const CStdString &strProperty, const CStdString &strValue)
{
CSingleLock lock(m_handleLock);
- if (handle < 0 || handle >= (int)globalHandles.size())
- {
- CLog::Log(LOGERROR, "%s called with an invalid handle.", __FUNCTION__);
+ CPluginDirectory *dir = dirFromHandle(handle);
+ if (!dir)
return;
- }
-
- CPluginDirectory *dir = globalHandles[handle];
if (strProperty == "fanart_image")
dir->m_listItems->SetArt("fanart", strValue);
else
1  xbmc/filesystem/PluginDirectory.h
View
@@ -71,6 +71,7 @@ class CPluginDirectory : public IDirectory
static std::vector<CPluginDirectory*> globalHandles;
static int getNewHandle(CPluginDirectory *cp);
static void removeHandle(int handle);
+ static CPluginDirectory *dirFromHandle(int handle);
static CCriticalSection m_handleLock;
CFileItemList* m_listItems;
ulion

didn't check dir non-NULL here, although it's not likely to be NULL.

jmarshallnz

Thanks for picking it up - will fix.

Please sign in to comment.
Something went wrong with that request. Please try again.