/*---------------------------------------------------------------------- | PLT_FileMediaServer::OnAlbumArtRequest +---------------------------------------------------------------------*/ NPT_Result PLT_FileMediaServer::OnAlbumArtRequest(NPT_HttpResponse& response, NPT_String file_path) { NPT_LargeSize total_len; NPT_File file(file_path); NPT_InputStreamReference stream; // prevent hackers from accessing files outside of our root if ((file_path.Find("/..") >= 0) || (file_path.Find("\\..") >= 0)) { return NPT_FAILURE; } if (NPT_FAILED(file.Open(NPT_FILE_OPEN_MODE_READ)) || NPT_FAILED(file.GetInputStream(stream)) || NPT_FAILED(stream->GetSize(total_len)) || (total_len == 0)) { goto filenotfound; } else { NPT_String extension = NPT_FilePath::FileExtension(file_path); if (extension.GetLength() == 0) { goto filenotfound; } PLT_MetadataHandler* metadataHandler = NULL; char* caData; int caDataLen; NPT_Result ret = NPT_ContainerFind(m_MetadataHandlers, PLT_MetadataHandlerFinder(extension), metadataHandler); if (NPT_FAILED(ret) || metadataHandler == NULL) { goto filenotfound; } // load the metadatahandler and read the cover art if (NPT_FAILED(metadataHandler->Load(*stream)) || NPT_FAILED(metadataHandler->GetCoverArtData(caData, caDataLen))) { goto filenotfound; } PLT_HttpHelper::SetContentType(response, "application/octet-stream"); PLT_HttpHelper::SetBody(response, caData, caDataLen); delete caData; return NPT_SUCCESS; } filenotfound: response.SetStatus(404, "File Not Found"); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_FileMediaServer::OnAlbumArtRequest +---------------------------------------------------------------------*/ NPT_Result PLT_FileMediaServer::OnAlbumArtRequest(NPT_String filepath, NPT_HttpResponse& response) { NPT_Size total_len; NPT_File file(filepath); NPT_InputStreamReference stream; if (NPT_FAILED(file.Open(NPT_FILE_OPEN_MODE_READ)) || NPT_FAILED(file.GetInputStream(stream)) || NPT_FAILED(stream->GetSize(total_len)) || (total_len == 0)) { goto filenotfound; } else { const char* extension = PLT_MediaItem::GetExtFromFilePath(filepath, m_DirDelimiter); if (extension == NULL) { goto filenotfound; } PLT_MetadataHandler* metadataHandler = NULL; char* caData; int caDataLen; NPT_Result ret = NPT_ContainerFind(m_MetadataHandlers, PLT_MetadataHandlerFinder(extension), metadataHandler); if (NPT_FAILED(ret) || metadataHandler == NULL) { goto filenotfound; } // load the metadatahandler and read the cover art if (NPT_FAILED(metadataHandler->Load(*stream)) || NPT_FAILED(metadataHandler->GetCoverArtData(caData, caDataLen))) { goto filenotfound; } PLT_HttpHelper::SetContentType(&response, "application/octet-stream"); PLT_HttpHelper::SetBody(&response, caData, caDataLen); delete caData; return NPT_SUCCESS; } filenotfound: response.SetStatus(404, "File Not Found"); return NPT_SUCCESS; }