]>
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
== "http") || (p
== "ftp");
73 wxFSFile
* wxInternetFSHandler::OpenFile(wxFileSystem
& WXUNUSED(fs
), const wxString
& location
)
75 wxString right
= GetProtocol(location
) + ":" + GetRightLocation(location
);
78 wxInetCacheNode
*info
;
80 info
= (wxInetCacheNode
*) m_Cache
.Get(right
);
82 // Add item into cache:
85 s
= url
.GetInputStream();
86 content
= url
.GetProtocol().GetContentType();
87 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
101 else return NULL
; //we can't open the URL
104 // Load item from cache:
105 s
= new wxFileInputStream(info
-> GetTemp());
107 return new wxFSFile(s
,
110 GetAnchor(location
));
117 wxInternetFSHandler::~wxInternetFSHandler()
123 while ((n
= m_Cache
.Next()) != NULL
) {
124 n2
= (wxInetCacheNode
*) n
-> GetData();
125 wxRemoveFile(n2
-> GetTemp());
130 #endif // wxUSE_FS_INET