Permalink
Browse files

webserver: re-allow access to image://-based URLs through the VFS han…

…dler
  • Loading branch information...
1 parent a2beee4 commit c9196f38488ccaa6477e6d7ab3212d9793dae7e3 @Montellese Montellese committed Oct 14, 2012
Showing with 38 additions and 25 deletions.
  1. +38 −25 xbmc/network/httprequesthandler/HTTPVfsHandler.cpp
View
63 xbmc/network/httprequesthandler/HTTPVfsHandler.cpp
@@ -41,44 +41,57 @@ int CHTTPVfsHandler::HandleHTTPRequest(const HTTPRequest &request)
if (XFILE::CFile::Exists(m_path))
{
- string sourceTypes[] = { "video", "music", "pictures" };
- unsigned int size = sizeof(sourceTypes) / sizeof(string);
-
- string realPath = URIUtils::GetRealPath(m_path);
- // for rar:// and zip:// paths we need to extract the path to the archive
- // instead of using the VFS path
- while (URIUtils::IsInArchive(realPath))
- realPath = CURL(realPath).GetHostName();
-
- VECSOURCES *sources = NULL;
- for (unsigned int index = 0; index < size; index++)
+ bool accessible = false;
+ if (m_path.substr(0, 8) == "image://")
+ accessible = true;
+ else
{
- sources = g_settings.GetSourcesFromType(sourceTypes[index]);
- if (sources == NULL)
- continue;
+ string sourceTypes[] = { "video", "music", "pictures" };
+ unsigned int size = sizeof(sourceTypes) / sizeof(string);
+
+ string realPath = URIUtils::GetRealPath(m_path);
+ // for rar:// and zip:// paths we need to extract the path to the archive
+ // instead of using the VFS path
+ while (URIUtils::IsInArchive(realPath))
+ realPath = CURL(realPath).GetHostName();
- for (VECSOURCES::const_iterator source = sources->begin(); source != sources->end(); source++)
+ VECSOURCES *sources = NULL;
+ for (unsigned int index = 0; index < size && !accessible; index++)
{
- // don't allow access to locked sources
- if (source->m_iHasLock == 2)
+ sources = g_settings.GetSourcesFromType(sourceTypes[index]);
+ if (sources == NULL)
continue;
- for (vector<CStdString>::const_iterator path = source->vecPaths.begin(); path != source->vecPaths.end(); path++)
+ for (VECSOURCES::const_iterator source = sources->begin(); source != sources->end() && !accessible; source++)
{
- string realSourcePath = URIUtils::GetRealPath(*path);
- if (URIUtils::IsInPath(realPath, realSourcePath))
+ // don't allow access to locked sources
+ if (source->m_iHasLock == 2)
+ continue;
+
+ for (vector<CStdString>::const_iterator path = source->vecPaths.begin(); path != source->vecPaths.end(); path++)
{
- m_responseCode = MHD_HTTP_OK;
- m_responseType = HTTPFileDownload;
- return MHD_YES;
+ string realSourcePath = URIUtils::GetRealPath(*path);
+ if (URIUtils::IsInPath(realPath, realSourcePath))
+ {
+ accessible = true;
+ break;
+ }
}
}
}
}
+ if (accessible)
+ {
+ m_responseCode = MHD_HTTP_OK;
+ m_responseType = HTTPFileDownload;
+ }
// the file exists but not in one of the defined sources so we deny access to it
- m_responseCode = MHD_HTTP_UNAUTHORIZED;
- m_responseType = HTTPError;
+ else
+ {
+ m_responseCode = MHD_HTTP_UNAUTHORIZED;
+ m_responseType = HTTPError;
+ }
}
else
{

4 comments on commit c9196f3

@jmarshallnz
Team Kodi member

I was wondering if you actually wanted to drop this. My reasoning is:

  1. Old clients likely need changes anyway.

  2. If we didn't image:// wrap the URLs, then it's easier for clients to just set the URL in the art. The image handler could then wrap the image:// URLs before passing off to the VFS.

@Montellese
Team Kodi member

Sounds like that might be less confusing for clients (except for the fact that they have to change from /vfs to /image) and less work if they want to change the artwork of an item using JSON-RPC. The procedure to download an image would stay the same:
1. Get an URL to an image from JSON-RPC
2a. Either call Files.PrepareDownload
2b. or URL encode the URL to the image manually
3. Call http://< ip >:< port >/image/< url-encoded-path-to-image >

What do you think?

@jmarshallnz
Team Kodi member

As long as Files.PrepareDownload knows that it's an image file - that's the tricky bit.

@Montellese
Team Kodi member

Hm yup that's a problem. Is there some kind of method that allows to check if an URL is in the texture cache? And what about auto-generated thumbs which have an URL of video@foo-bar which is not really a valid URL per se?

Please sign in to comment.