Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

mime.h

Go to the documentation of this file.
00001 /*
00002  * mime.h
00003  *
00004  * Multipurpose Internet Mail Extensions support classes.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: mime.h,v $
00027  * Revision 1.20  2004/03/23 06:38:51  csoutheren
00028  * Update for change in location of Base64 routines
00029  *
00030  * Revision 1.19  2004/03/23 05:59:17  csoutheren
00031  * Moved the Base64 routines into cypher.cxx, which is a more sensible
00032  * place and reduces the inclusion of unrelated code
00033  *
00034  * Revision 1.18  2002/11/06 22:47:24  robertj
00035  * Fixed header comment (copyright etc)
00036  *
00037  * Revision 1.17  2002/09/16 01:08:59  robertj
00038  * Added #define so can select if #pragma interface/implementation is used on
00039  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00040  *
00041  * Revision 1.16  2001/10/03 00:24:57  robertj
00042  * Split out function for adding a single line of MIME info, reduces
00043  *    duplicated code and is useful in some other areas such as HTTP/1.1
00044  *
00045  * Revision 1.15  2001/09/28 00:41:18  robertj
00046  * Added SetInteger() function to set numeric MIME fields.
00047  * Removed HasKey() as is confusing due to ancestor Contains().
00048  * Overrides of SetAt() and Contains() to assure PCaselessString used.
00049  *
00050  * Revision 1.14  2000/11/09 00:18:26  robertj
00051  * Cosmetic change: removed blank lines.
00052  *
00053  * Revision 1.13  1999/03/09 08:01:46  robertj
00054  * Changed comments for doc++ support (more to come).
00055  *
00056  * Revision 1.12  1999/02/16 08:07:10  robertj
00057  * MSVC 6.0 compatibility changes.
00058  *
00059  * Revision 1.11  1998/11/30 02:50:52  robertj
00060  * New directory structure
00061  *
00062  * Revision 1.10  1998/09/23 06:19:42  robertj
00063  * Added open source copyright license.
00064  *
00065  * Revision 1.9  1997/02/05 11:53:11  robertj
00066  * Changed construction of MIME dictionary to be delayed untill it is used.
00067  *
00068  * Revision 1.8  1996/09/14 13:09:15  robertj
00069  * Major upgrade:
00070  *   rearranged sockets to help support IPX.
00071  *   added indirect channel class and moved all protocols to descend from it,
00072  *   separating the protocol from the low level byte transport.
00073  *
00074  * Revision 1.7  1996/07/15 10:28:31  robertj
00075  * Changed memory block base64 conversion functions to be void *.
00076  *
00077  * Revision 1.6  1996/03/16 04:38:09  robertj
00078  * Fixed bug in MIME write function, should be const.
00079  *
00080  * Revision 1.5  1996/02/25 03:04:32  robertj
00081  * Added decoding of Base64 to a block of memory instead of PBYTEArray.
00082  *
00083  * Revision 1.4  1996/01/28 14:14:30  robertj
00084  * Further implementation of secure config.
00085  *
00086  * Revision 1.3  1996/01/28 02:46:07  robertj
00087  * Removal of MemoryPointer classes as usage didn't work for GNU.
00088  *
00089  * Revision 1.2  1996/01/26 02:24:27  robertj
00090  * Further implemetation.
00091  *
00092  * Revision 1.1  1996/01/23 13:06:18  robertj
00093  * Initial revision
00094  *
00095  */
00096 
00097 #ifndef _PMIME
00098 #define _PMIME
00099 
00100 #ifdef P_USE_PRAGMA
00101 #pragma interface
00102 #endif
00103 
00104 #include <ptclib/inetprot.h>
00105 #include <ptclib/cypher.h>
00106 
00108 // PMIMEInfo
00109 
00114 #ifdef DOC_PLUS_PLUS
00115 class PMIMEInfo : public PStringToString {
00116 #endif
00117 PDECLARE_STRING_DICTIONARY(PMIMEInfo, PCaselessString);
00118   public:
00119     PMIMEInfo(
00120       istream &strm   // Stream to read the objects contents from.
00121     );
00122     PMIMEInfo(
00123       PInternetProtocol & socket   // Application socket to read MIME info.
00124     );
00125     // Construct a MIME infromation dictionary from the specified source.
00126 
00127 
00128   // Overrides from class PObject
00132     virtual void PrintOn(
00133       ostream &strm   // Stream to print the object into.
00134     ) const;
00135 
00139     virtual void ReadFrom(
00140       istream &strm   // Stream to read the objects contents from.
00141     );
00142 
00143 
00144   // Overrides from class PStringToString
00151     BOOL SetAt(
00152       const char * key,
00153       const PString value
00154     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00155 
00162     BOOL SetAt(
00163       const PString & key,
00164       const PString value
00165     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00166 
00173     BOOL SetAt(
00174       const PCaselessString & key,
00175       const PString value
00176     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00177 
00184     BOOL Contains(
00185       const char * key       // Key into MIME dictionary to get info.
00186     ) const { return GetAt(PCaselessString(key)) != NULL; }
00187 
00194     BOOL Contains(
00195       const PString & key       // Key into MIME dictionary to get info.
00196     ) const { return GetAt(PCaselessString(key)) != NULL; }
00197 
00204     BOOL Contains(
00205       const PCaselessString & key       // Key into MIME dictionary to get info.
00206     ) const { return GetAt(key) != NULL; }
00207 
00208   // New functions for class.
00214     BOOL Read(
00215       PInternetProtocol & socket   // Application socket to read MIME info.
00216     );
00217 
00223     BOOL Write(
00224       PInternetProtocol & socket   // Application socket to write MIME info.
00225     ) const;
00226 
00235     BOOL AddMIME(
00236       const PString & line
00237     );
00238 
00246     PString GetString(
00247       const PString & key,       // Key into MIME dictionary to get info.
00248       const PString & dflt       // Default value of field if not in MIME info.
00249     ) const;
00250 
00258     long GetInteger(
00259       const PString & key,    // Key into MIME dictionary to get info.
00260       long dflt = 0           // Default value of field if not in MIME info.
00261     ) const;
00262 
00265     void SetInteger(
00266       const PCaselessString & key,  // Key into MIME dictionary to get info.
00267       long value                    // New value of field.
00268     );
00269 
00270 
00308     static void SetAssociation(
00309       const PStringToString & allTypes,  // MIME content type associations.
00310       BOOL merge = TRUE                  // Flag for merging associations.
00311     );
00312     static void SetAssociation(
00313       const PString & fileType,         // File type (extension) to match.
00314       const PString & contentType       // MIME content type string.
00315     ) { GetContentTypes().SetAt(fileType, contentType); }
00316 
00324     static PString GetContentType(
00325       const PString & fileType   // File type (extension) to look up.
00326     );
00327 
00328   private:
00329     static PStringToString & GetContentTypes();
00330 };
00331 
00332 
00333 
00334 #endif
00335 
00336 
00337 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:43:09 2005 for PWLib by  doxygen 1.4.1