]>
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>
34 #define wxUSE_FS_INET 0
43 #include "wx/wfstream.h"
45 #include "wx/filesys.h"
46 #include "wx/fs_inet.h"
48 class wxInetCacheNode
: public wxObject
55 wxInetCacheNode(const wxString
& l
, const wxString
& m
) : wxObject() {m_Temp
= l
; m_Mime
= m
;}
56 const wxString
& GetTemp() const {return m_Temp
;}
57 const wxString
& GetMime() const {return m_Mime
;}
64 //--------------------------------------------------------------------------------
65 // wxInternetFSHandler
66 //--------------------------------------------------------------------------------
69 bool wxInternetFSHandler::CanOpen(const wxString
& location
)
71 wxString p
= GetProtocol(location
);
72 return (p
== _T("http")) || (p
== _T("ftp"));
76 wxFSFile
* wxInternetFSHandler::OpenFile(wxFileSystem
& WXUNUSED(fs
), const wxString
& location
)
78 wxString right
= GetProtocol(location
) + _T(":") + GetRightLocation(location
);
81 wxInetCacheNode
*info
;
83 info
= (wxInetCacheNode
*) m_Cache
.Get(right
);
85 // Add item into cache:
89 s
= url
.GetInputStream();
90 content
= url
.GetProtocol().GetContentType();
91 if (content
== wxEmptyString
) content
= GetMimeTypeFromExt(location
);
96 wxGetTempFileName( _T("wxhtml"), buf
);
97 info
= new wxInetCacheNode(buf
, content
);
98 m_Cache
.Put(right
, info
);
100 { // ok, now copy it:
101 wxFileOutputStream
sout(buf
);
102 s
-> Read(sout
); // copy the stream
108 return (wxFSFile
*) NULL
; // we can't open the URL
112 // Load item from cache:
113 s
= new wxFileInputStream(info
->GetTemp());
116 return new wxFSFile(s
,
119 GetAnchor(location
));
121 else return (wxFSFile
*) NULL
;
126 wxInternetFSHandler::~wxInternetFSHandler()
132 while ((n
= m_Cache
.Next()) != NULL
)
134 n2
= (wxInetCacheNode
*) n
->GetData();
135 wxRemoveFile(n2
->GetTemp());
140 #endif // wxUSE_FS_INET