Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / filesystem / UPnPFile.cpp
1 /*
2  *      Copyright (C) 2011-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "UPnPFile.h"
22 #include "UPnPDirectory.h"
23 #include "FileFactory.h"
24 #include "FileItem.h"
25 #include "utils/log.h"
26 #include "URL.h"
27
28 using namespace XFILE;
29
30 CUPnPFile::CUPnPFile()
31 {
32 }
33
34 CUPnPFile::~CUPnPFile()
35 {
36 }
37
38 bool CUPnPFile::Open(const CURL& url)
39 {
40   CFileItem item_new;
41   if (CUPnPDirectory::GetResource(url.Get(), item_new))
42   {
43     //CLog::Log(LOGDEBUG,"FileUPnP - file redirect to %s.", item_new.GetPath().c_str());
44     IFile *pNewImp = CFileFactory::CreateLoader(item_new.GetPath());    
45     CURL *pNewUrl = new CURL(item_new.GetPath());    
46     if (pNewImp)
47     {
48       throw new CRedirectException(pNewImp, pNewUrl);
49     }
50     delete pNewUrl;    
51   }
52   return false;
53 }
54
55 int CUPnPFile::Stat(const CURL& url, struct __stat64* buffer)
56 {
57   CFileItem item_new;
58   if (CUPnPDirectory::GetResource(url.Get(), item_new))
59   {
60     //CLog::Log(LOGDEBUG,"FileUPnP - file redirect to %s.", item_new.GetPath().c_str());
61     IFile *pNewImp = CFileFactory::CreateLoader(item_new.GetPath());
62     CURL *pNewUrl = new CURL(item_new.GetPath());
63     if (pNewImp)
64     {
65       throw new CRedirectException(pNewImp, pNewUrl);
66     }
67     delete pNewUrl;
68   }
69   return -1;
70 }
71
72 bool CUPnPFile::Exists(const CURL& url)
73 {
74   CFileItem item_new;
75   if (CUPnPDirectory::GetResource(url.Get(), item_new))
76   {
77     //CLog::Log(LOGDEBUG,"FileUPnP - file redirect to %s.", item_new.GetPath().c_str());
78     IFile *pNewImp = CFileFactory::CreateLoader(item_new.GetPath());
79     CURL *pNewUrl = new CURL(item_new.GetPath());
80     if (pNewImp)
81     {
82       throw new CRedirectException(pNewImp, pNewUrl);
83     }
84     delete pNewUrl;
85   }
86   return false;
87 }