/////////////////////////////////////////////////////////////////////////////
// Name:        cachedfs_inet.h
// Purpose:     HTTP and FTP file system
// Author:      Vaclav Slavik
// Modified by: Francesco Montorsi
// Copyright:   (c) 1999 Vaclav Slavik
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_FS_INET_H_
#define _WX_FS_INET_H_

#include "wx/defs.h"

#if wxUSE_FILESYSTEM && wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS

#include "wx/filesys.h"
#include "wx/mstream.h"


// ----------------------------------------------------------------------------
// wxFSFileRawData
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_NET wxFSFileRawData
{
public:

    wxFSFileRawData(size_t len, const wxString &location, const wxString &mimetype,
                    const wxString &anchor, const wxDateTime &modtime)
        {
            m_len=len;
            m_data=new char[m_len];

            m_location=location;
            m_mimetype=mimetype;
            m_anchor=anchor;
            m_modTime=modtime;
        }

    ~wxFSFileRawData()
        { if (m_data) delete [] m_data; }

public:     // getters

    void *GetData() const { return m_data; }
    size_t GetLen() const { return m_len; }

    wxString GetLocation() const { return m_location; }
    wxString GetMimeType() const { return m_mimetype; }
    wxString GetAnchor() const { return m_anchor; }
    wxDateTime GetModificationTime() const { return m_modTime; }

protected:
    char *m_data;
    size_t m_len;

    // this is always initialized with a NULL inputstream
    // and just used as a container of: anchor,location,mimetype
    // etc which is the data used to recreate instances of
    // "real" wxFSFiles from this class later
    //wxFSFile m_misc;
    wxString m_location, m_mimetype, m_anchor;
    wxDateTime m_modTime;
};


// VERY IMPORTANT: we *must* use wxFSFileRawData* as type and not wxFSFileRawData
//                 in order to avoid various (unneeded) copies done automatically
//                 by Hashmap implementation
WX_DECLARE_STRING_HASH_MAP( wxFSFileRawData*,
                            wxFSFileHashMap );



// ----------------------------------------------------------------------------
// wxInternetFSHandler
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_NET wxCachedInternetFSHandler : public wxFileSystemHandler
{
public:
    virtual bool CanOpen(const wxString& location);
    virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);

    ~wxCachedInternetFSHandler()
    {
        for( wxFSFileHashMap::iterator it = m_cache.begin(); it != m_cache.end(); ++it )
            delete ((wxFSFileRawData*)(it->second));
    }

protected:
    wxFSFileHashMap m_cache;
};


#endif
  // wxUSE_FILESYSTEM && wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS

#endif // _WX_FS_INET_H_

