]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fs_inet.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: HTTP and FTP file system
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
13 This FS creates local cache (in /tmp directory). The cache is freed
16 Size of cache is limited to cca 1000 items (due to GetTempFileName
23 #pragma implementation
26 #include <wx/wxprec.h>
38 #include "wx/wfstream.h"
40 #include "wx/filesys.h"
41 #include "wx/fs_inet.h"
43 class wxInetCacheNode
: public wxObject
50 wxInetCacheNode(const wxString
& l
, const wxString
& m
) : wxObject() {m_Temp
= l
; m_Mime
= m
;}
51 const wxString
& GetTemp() const {return m_Temp
;}
52 const wxString
& GetMime() const {return m_Mime
;}
59 //--------------------------------------------------------------------------------
60 // wxInternetFSHandler
61 //--------------------------------------------------------------------------------
64 bool wxInternetFSHandler::CanOpen(const wxString
& location
)
66 wxString p
= GetProtocol(location
);
67 return (p
== _T("http")) || (p
== _T("ftp"));
71 wxFSFile
* wxInternetFSHandler::OpenFile(wxFileSystem
& WXUNUSED(fs
), const wxString
& location
)
73 wxString right
= GetProtocol(location
) + _T(":") + GetRightLocation(location
);
76 wxInetCacheNode
*info
;
78 info
= (wxInetCacheNode
*) m_Cache
.Get(right
);
80 // Add item into cache:
84 s
= url
.GetInputStream();
85 content
= url
.GetProtocol().GetContentType();
86 if (content
== wxEmptyString
) content
= GetMimeTypeFromExt(location
);
91 wxGetTempFileName( "wxhtml", buf
);
92 info
= new wxInetCacheNode(buf
, content
);
93 m_Cache
.Put(right
, info
);
96 wxFileOutputStream
sout(buf
);
97 s
-> Read(sout
); // copy the stream
103 return (wxFSFile
*) NULL
; // we can't open the URL
107 // Load item from cache:
108 s
= new wxFileInputStream(info
->GetTemp());
111 return new wxFSFile(s
,
114 GetAnchor(location
));
116 else return (wxFSFile
*) NULL
;
121 wxInternetFSHandler::~wxInternetFSHandler()
127 while ((n
= m_Cache
.Next()) != NULL
)
129 n2
= (wxInetCacheNode
*) n
->GetData();
130 wxRemoveFile(n2
->GetTemp());
135 #endif // wxUSE_FS_INET