Skip to content

Commit

Permalink
[UPnP] Platinum now stats files before serving via http. This means s…
Browse files Browse the repository at this point in the history
…erving files from vfs was broken. Solution is to remove all filesystem access to Platinum and expand NPT_XbmcFile. Anything apart from GetInfo:: (stat) is ignored as Platinum only serves up library items, not file systems. Thanks to elupus for fix, and pieh for spotting this in the first place
  • Loading branch information
alcoheca committed Sep 5, 2012
1 parent 0940b8f commit e195496
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 12 deletions.
4 changes: 0 additions & 4 deletions XBMC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@
43BF09241080C6BA00E25290 /* NptZip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF08E91080C6BA00E25290 /* NptZip.cpp */; };
43BF09331080C71700E25290 /* NptBsdNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF092F1080C71700E25290 /* NptBsdNetwork.cpp */; };
43BF09341080C71700E25290 /* NptBsdSockets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF09301080C71700E25290 /* NptBsdSockets.cpp */; };
43BF09491080C76E00E25290 /* NptPosixFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF093D1080C76E00E25290 /* NptPosixFile.cpp */; };
43BF094A1080C76E00E25290 /* NptPosixNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF093E1080C76E00E25290 /* NptPosixNetwork.cpp */; };
43BF094B1080C76E00E25290 /* NptPosixQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF093F1080C76E00E25290 /* NptPosixQueue.cpp */; };
43BF094C1080C76E00E25290 /* NptPosixSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF09401080C76E00E25290 /* NptPosixSystem.cpp */; };
Expand Down Expand Up @@ -1556,7 +1555,6 @@
43BF092E1080C6F600E25290 /* SConstruct */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = SConstruct; path = Neptune/SConstruct; sourceTree = "<group>"; };
43BF092F1080C71700E25290 /* NptBsdNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptBsdNetwork.cpp; path = ../../Neptune/Source/System/Bsd/NptBsdNetwork.cpp; sourceTree = "<group>"; };
43BF09301080C71700E25290 /* NptBsdSockets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptBsdSockets.cpp; path = ../../Neptune/Source/System/Bsd/NptBsdSockets.cpp; sourceTree = "<group>"; };
43BF093D1080C76E00E25290 /* NptPosixFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptPosixFile.cpp; path = ../../Neptune/Source/System/Posix/NptPosixFile.cpp; sourceTree = "<group>"; };
43BF093E1080C76E00E25290 /* NptPosixNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptPosixNetwork.cpp; path = ../../Neptune/Source/System/Posix/NptPosixNetwork.cpp; sourceTree = "<group>"; };
43BF093F1080C76E00E25290 /* NptPosixQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptPosixQueue.cpp; path = ../../Neptune/Source/System/Posix/NptPosixQueue.cpp; sourceTree = "<group>"; };
43BF09401080C76E00E25290 /* NptPosixSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NptPosixSystem.cpp; path = ../../Neptune/Source/System/Posix/NptPosixSystem.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6468,7 +6466,6 @@
43BF08C51080C6B900E25290 /* NptNetwork.cpp */,
43BF08C61080C6B900E25290 /* NptNetwork.h */,
43BF094F1080C79900E25290 /* NptPosixDynamicLibraries.cpp */,
43BF093D1080C76E00E25290 /* NptPosixFile.cpp */,
43BF093E1080C76E00E25290 /* NptPosixNetwork.cpp */,
43BF093F1080C76E00E25290 /* NptPosixQueue.cpp */,
43BF09401080C76E00E25290 /* NptPosixSystem.cpp */,
Expand Down Expand Up @@ -7268,7 +7265,6 @@
43BF09241080C6BA00E25290 /* NptZip.cpp in Sources */,
43BF09331080C71700E25290 /* NptBsdNetwork.cpp in Sources */,
43BF09341080C71700E25290 /* NptBsdSockets.cpp in Sources */,
43BF09491080C76E00E25290 /* NptPosixFile.cpp in Sources */,
43BF094A1080C76E00E25290 /* NptPosixNetwork.cpp in Sources */,
43BF094B1080C76E00E25290 /* NptPosixQueue.cpp in Sources */,
43BF094C1080C76E00E25290 /* NptPosixSystem.cpp in Sources */,
Expand Down
1 change: 0 additions & 1 deletion lib/libUPnP/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ SRCS= Platinum/Source/Core/PltAction.cpp \
Neptune/Source/System/Posix/NptPosixEnvironment.cpp \
Neptune/Source/System/Posix/NptPosixQueue.cpp \
Neptune/Source/System/Posix/NptPosixThreads.cpp \
Neptune/Source/System/Posix/NptPosixFile.cpp \
Neptune/Source/System/Posix/NptPosixTime.cpp \
Neptune/Source/System/StdC/NptStdcDebug.cpp \
Neptune/Source/System/StdC/NptStdcEnvironment.cpp \
Expand Down
3 changes: 1 addition & 2 deletions project/VS2010Express/libPlatinum.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\Core\NptXml.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\Core\NptZip.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\Bsd\NptBsdSockets.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\Posix\NptPosixFile.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\StdC\NptStdcEnvironment.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\StdC\NptStdcFile.cpp" />
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\Win32\NptWin32Debug.cpp" />
Expand All @@ -256,4 +255,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 1 addition & 4 deletions project/VS2010Express/libPlatinum.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\Bsd\NptBsdSockets.cpp">
<Filter>Neptune\System</Filter>
</ClCompile>
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\Posix\NptPosixFile.cpp">
<Filter>Neptune\System</Filter>
</ClCompile>
<ClCompile Include="..\..\lib\libUPnP\Neptune\Source\System\StdC\NptStdcEnvironment.cpp">
<Filter>Neptune\System</Filter>
</ClCompile>
Expand Down Expand Up @@ -531,4 +528,4 @@
<Filter>Platinum\MediaServer</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>
126 changes: 125 additions & 1 deletion xbmc/filesystem/NptXbmcFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "IFile.h"
#include "File.h"
#include "FileFactory.h"
#include "utils/log.h"
#include "Util.h"
Expand Down Expand Up @@ -401,6 +401,27 @@ NPT_XbmcFile::GetOutputStream(NPT_OutputStreamReference& stream)
return NPT_SUCCESS;
}

static NPT_Result
MapErrno(int err) {
switch (err) {
case EACCES: return NPT_ERROR_PERMISSION_DENIED;
case EPERM: return NPT_ERROR_PERMISSION_DENIED;
case ENOENT: return NPT_ERROR_NO_SUCH_FILE;
case ENAMETOOLONG: return NPT_ERROR_INVALID_PARAMETERS;
case EBUSY: return NPT_ERROR_FILE_BUSY;
case EROFS: return NPT_ERROR_FILE_NOT_WRITABLE;
case ENOTDIR: return NPT_ERROR_FILE_NOT_DIRECTORY;
case EEXIST: return NPT_ERROR_FILE_ALREADY_EXISTS;
case ENOSPC: return NPT_ERROR_FILE_NOT_ENOUGH_SPACE;
case ENOTEMPTY: return NPT_ERROR_DIRECTORY_NOT_EMPTY;
default: return NPT_ERROR_ERRNO(err);
}
}
/*----------------------------------------------------------------------
| NPT_FilePath::Separator
+---------------------------------------------------------------------*/
const char* const NPT_FilePath::Separator = "/";

/*----------------------------------------------------------------------
| NPT_File::NPT_File
+---------------------------------------------------------------------*/
Expand All @@ -423,3 +444,106 @@ NPT_File::operator=(const NPT_File& file)
return *this;
}

/*----------------------------------------------------------------------
| NPT_File::GetRoots
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::GetRoots(NPT_List<NPT_String>& roots)
{
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| NPT_File::CreateDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::CreateDir(const char* path)
{
return NPT_ERROR_PERMISSION_DENIED;
}

/*----------------------------------------------------------------------
| NPT_File::RemoveFile
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::RemoveFile(const char* path)
{
return NPT_ERROR_PERMISSION_DENIED;
}

/*----------------------------------------------------------------------
| NPT_File::RemoveDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::RemoveDir(const char* path)
{
return NPT_ERROR_PERMISSION_DENIED;
}

/*----------------------------------------------------------------------
| NPT_File::Rename
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::Rename(const char* from_path, const char* to_path)
{
return NPT_ERROR_PERMISSION_DENIED;
}

/*----------------------------------------------------------------------
| NPT_File::ListDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::ListDir(const char* path,
NPT_List<NPT_String>& entries,
NPT_Ordinal start /* = 0 */,
NPT_Cardinal max /* = 0 */)
{
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| NPT_File::GetWorkingDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::GetWorkingDir(NPT_String& path)
{
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| NPT_File::GetInfo
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::GetInfo(const char* path, NPT_FileInfo* info)
{
struct __stat64 stat_buffer = {0};
int result;

if (!info)
return NPT_FAILURE;

NPT_SetMemory(info, 0, sizeof(*info));

result = CFile::Stat(path, &stat_buffer);
if (result !=0) return MapErrno(errno);
if (info)
{
info->m_Size = stat_buffer.st_size;
if (S_ISREG(stat_buffer.st_mode)) {
info->m_Type = NPT_FileInfo::FILE_TYPE_REGULAR;
} else if (S_ISDIR(stat_buffer.st_mode)) {
info->m_Type = NPT_FileInfo::FILE_TYPE_DIRECTORY;
} else {
info->m_Type = NPT_FileInfo::FILE_TYPE_OTHER;
}
info->m_AttributesMask &= NPT_FILE_ATTRIBUTE_READ_ONLY;
if ((stat_buffer.st_mode & S_IWUSR) == 0) {
info->m_Attributes &= NPT_FILE_ATTRIBUTE_READ_ONLY;
}
info->m_CreationTime.SetSeconds(0);
info->m_ModificationTime.SetSeconds(stat_buffer.st_mtime);
}

return NPT_SUCCESS;
}

0 comments on commit e195496

Please sign in to comment.