home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / itapefs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.1 KB  |  177 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef ITAPEFS_H
  20. #define ITAPEFS_H
  21.  
  22. #ifdef EDITOR
  23. //
  24. // Abstract output file stream.
  25. //
  26. class IStreamOut {
  27. public:
  28.     IStreamOut();
  29.     virtual ~IStreamOut();
  30.  
  31.     virtual void Write( char *pBuffer, int32 iCount )=0;
  32.  
  33.     // NOTICE: the implementation is not pure.  There is a default
  34.     //  implementation that implements this function interms of 
  35.     //  'Write'.
  36.     virtual int Printf( char * pFormat, ... );
  37.  
  38.     enum EOutStreamStatus {
  39.         EOS_NoError,
  40.         EOS_DeviceFull,
  41.         EOS_FileError
  42.     };
  43.  
  44.     virtual EOutStreamStatus Status(){ return EOS_NoError; }
  45.  
  46.     // implemented in terms of the interface.
  47.     void WriteInt( int32 i ){ Write( (char*)&i, sizeof( int32 ) ); }
  48.     void WriteZString( char* pString);
  49.     void WritePartialZString( char* pString, int32 start, int32 end);
  50. private:
  51.     char* stream_buffer; // used to implement Printf
  52. };
  53.  
  54.  
  55. //-----------------------------------------------------------------------
  56. // Abstract File System
  57. //-----------------------------------------------------------------------
  58. typedef void
  59. EDT_ITapeFileSystemComplete( XP_Bool bSuccess, void *pArg );
  60.  
  61. class ITapeFileSystem {
  62.     PRBool m_FirstBinary; // is the first file really binary, not text?
  63. public:
  64.     ITapeFileSystem() { m_FirstBinary = PR_FALSE; }
  65.     // ITapeFileSystem::File, ITapeFileSystem::Publish, or
  66.     // ITapeFileSystem::MailSend, 
  67.     enum {File,Publish,MailSend};
  68.     virtual intn GetType() = 0;
  69.  
  70.     // This function is called before anything else.  It tells the file
  71.     //  system the base url for the URLs added in AddFile().
  72.     // An actual file, not a directory.
  73.     virtual void SetSourceBaseURL( char* pURL )=0;
  74.  
  75.     // DESCRIPTION:
  76.     //
  77.     // Add a name to the file system.  It is up to the file system to localize
  78.     //  the name.  For example, I could add 'http://home.netsacpe.com/
  79.     //  and the file system might decide that it should be called 'index.html'
  80.     //  if the file system were DOS, the url might be converted to INDEX.HTML
  81.     //
  82.     // pMIMEType may be NULL.  In this case if the tape file system needs the
  83.     // MIME type, it must figure it out by itself.
  84.     //
  85.     // RETURNS: index of the file (0 based), OR
  86.     // ITapeFileSystem::Error if an error adding name, OR
  87.     // ITapeFileSystem::SourceDestSame if adding
  88.     // this name would result in the source and destination being the same, and thus 
  89.     // no point in copying the file.  
  90.     //   
  91.     // The first file added must be the root HTML document. (It is ok for the root
  92.     // document to have the same source and dest URL).
  93.     //
  94.     virtual intn AddFile( char* pURL, char *pMIMEType, int16 iCharSetID)=0;
  95.  
  96.     // Return the number of files added to the file system.
  97.     virtual intn GetNumFiles()=0;
  98.  
  99.     // Returns the absolute version of the URL given in AddFile(), using the 
  100.     // URL given in SetSourceBaseURL() as the base.
  101.     // Allocated with XP_STRDUP().
  102.     virtual char* GetSourceURL(intn iFileIndex)=0;
  103.  
  104.     // Return the absolute destination of the HTML doc if meaningful, else return 
  105.     // NULL.  Almost the same as "GetDestPathURL()+GetDestURL(0)" except that this call
  106.     // will work before file 0 has been added to the file system.
  107.     virtual char* GetDestAbsURL()=0;
  108.  
  109.     // Gets the name of the RELATIVE url to place in the file.  String is 
  110.     //  allocated with XP_STRDUP();
  111.     //  
  112.     virtual char* GetDestURL( intn iFileIndex )=0;
  113.  
  114.     // Return the path URL associated with the ITapeFilesystem or NULL if there is none.
  115.     // If NULL is returned, all URLs returned by GetDestURL() must be absolute.
  116.     //
  117.     // i.e. for a file or remote HTTP based ITapeFileSystem, this is the directory where the images are 
  118.     // stored.  For a MHTML ITapeFileSystem this is NULL.
  119.     //
  120.     // String is allocated with XP_STRDUP().
  121.     virtual char* GetDestPathURL() = 0;
  122.  
  123.     //
  124.     // Returns the name to display when saving the file, can be the same as 
  125.     //  GetURLName. String is allocated with XP_STRDUP();
  126.     //
  127.     virtual char* GetHumanName( intn iFileIndex )=0;
  128.  
  129.     enum {
  130.         Error = -1, SourceDestSame = -2
  131.     };
  132.  
  133.     // Does the file referenced by iFileIndex already exist?
  134.     // E.g. for the MHTML version, this will always return FALSE.
  135.     virtual XP_Bool FileExists(intn iFileIndex) = 0;
  136.  
  137.     // Will we be creating a new non-temporary file on the local machine.
  138.     // Used to update SiteManager.
  139.     virtual XP_Bool IsLocalPersistentFile(intn iFileIndex) = 0;
  140.  
  141.     // ### mwelch Added so that multipart/related message saver can properly construct
  142.     //            messages using quoted/forwarded part data.
  143.     // Tell the tape file system the mime type of a particular part.
  144.     // Calling this overrides any previously determined mime type for this part.
  145.     virtual void CopyURLInfo(intn iFileIndex, const URL_Struct *pURL) = 0;
  146.     
  147.     //
  148.     // Opens the output stream. Returns a stream that can be written to or NULL if error.  All
  149.     //  'AddFile's occur before the first OpenStream.
  150.     // Do not delete the returned stream, just call CloseStream() when done.
  151.     //
  152.     virtual IStreamOut *OpenStream( intn iFileIndex )=0;
  153.  
  154.     virtual void CloseStream( intn iFileIndex )=0;
  155.  
  156.     // Called on completion, TRUE if completed successfully, FALSE if it failed.
  157.     // The caller should not reference the ITapeFileSystem after calling Complete().
  158.     // Caller does not free up memory for ITapeFileSystem, Complete() causes file system to delete itself.
  159.     //  
  160.     // The tape file system will call pfComplete with pArg and with whether the ITapeFileSystem 
  161.     // completed successfully.  Note: the ITapeFileSystem may call pfComplete() with TRUE even if
  162.     // ITapeFileSystem::Complete() was given FALSE.
  163.     // pfComplete may be NULL.  Call to pfComplete may be synchronous or asynchronous.  
  164.     //
  165.     // The ITapeFileSystem will call pfComplete(success,pArg) before deleting itself.  I.e. the ITapeFileSystem is still valid 
  166.     // when it calls pfComplete().
  167.     virtual void Complete( Bool bSuccess, EDT_ITapeFileSystemComplete *pfComplete, void *pArg )=0;
  168.  
  169.     inline PRBool IsFirstBinary(void) { return m_FirstBinary; }
  170.     inline void SetFirstBinary(void) { m_FirstBinary = PR_TRUE; }
  171.     inline void ResetFirstBinary(void) { m_FirstBinary = PR_FALSE; }
  172. };
  173.  
  174. #endif // EDITOR
  175.  
  176. #endif
  177.