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.23  2007/09/18 06:20:56  csoutheren
00028  * Fix spelling mistakes
00029  *
00030  * Revision 1.22  2007/02/01 23:56:44  csoutheren
00031  * Added extra AddMIME with seperate key and value fields
00032  *
00033  * Revision 1.21  2005/11/30 12:47:37  csoutheren
00034  * Removed tabs, reformatted some code, and changed tags for Doxygen
00035  *
00036  * Revision 1.20  2004/03/23 06:38:51  csoutheren
00037  * Update for change in location of Base64 routines
00038  *
00039  * Revision 1.19  2004/03/23 05:59:17  csoutheren
00040  * Moved the Base64 routines into cypher.cxx, which is a more sensible
00041  * place and reduces the inclusion of unrelated code
00042  *
00043  * Revision 1.18  2002/11/06 22:47:24  robertj
00044  * Fixed header comment (copyright etc)
00045  *
00046  * Revision 1.17  2002/09/16 01:08:59  robertj
00047  * Added #define so can select if #pragma interface/implementation is used on
00048  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00049  *
00050  * Revision 1.16  2001/10/03 00:24:57  robertj
00051  * Split out function for adding a single line of MIME info, reduces
00052  *    duplicated code and is useful in some other areas such as HTTP/1.1
00053  *
00054  * Revision 1.15  2001/09/28 00:41:18  robertj
00055  * Added SetInteger() function to set numeric MIME fields.
00056  * Removed HasKey() as is confusing due to ancestor Contains().
00057  * Overrides of SetAt() and Contains() to assure PCaselessString used.
00058  *
00059  * Revision 1.14  2000/11/09 00:18:26  robertj
00060  * Cosmetic change: removed blank lines.
00061  *
00062  * Revision 1.13  1999/03/09 08:01:46  robertj
00063  * Changed comments for doc++ support (more to come).
00064  *
00065  * Revision 1.12  1999/02/16 08:07:10  robertj
00066  * MSVC 6.0 compatibility changes.
00067  *
00068  * Revision 1.11  1998/11/30 02:50:52  robertj
00069  * New directory structure
00070  *
00071  * Revision 1.10  1998/09/23 06:19:42  robertj
00072  * Added open source copyright license.
00073  *
00074  * Revision 1.9  1997/02/05 11:53:11  robertj
00075  * Changed construction of MIME dictionary to be delayed untill it is used.
00076  *
00077  * Revision 1.8  1996/09/14 13:09:15  robertj
00078  * Major upgrade:
00079  *   rearranged sockets to help support IPX.
00080  *   added indirect channel class and moved all protocols to descend from it,
00081  *   separating the protocol from the low level byte transport.
00082  *
00083  * Revision 1.7  1996/07/15 10:28:31  robertj
00084  * Changed memory block base64 conversion functions to be void *.
00085  *
00086  * Revision 1.6  1996/03/16 04:38:09  robertj
00087  * Fixed bug in MIME write function, should be const.
00088  *
00089  * Revision 1.5  1996/02/25 03:04:32  robertj
00090  * Added decoding of Base64 to a block of memory instead of PBYTEArray.
00091  *
00092  * Revision 1.4  1996/01/28 14:14:30  robertj
00093  * Further implementation of secure config.
00094  *
00095  * Revision 1.3  1996/01/28 02:46:07  robertj
00096  * Removal of MemoryPointer classes as usage didn't work for GNU.
00097  *
00098  * Revision 1.2  1996/01/26 02:24:27  robertj
00099  * Further implemetation.
00100  *
00101  * Revision 1.1  1996/01/23 13:06:18  robertj
00102  * Initial revision
00103  *
00104  */
00105 
00106 #ifndef _PMIME
00107 #define _PMIME
00108 
00109 #ifdef P_USE_PRAGMA
00110 #pragma interface
00111 #endif
00112 
00113 #include <ptclib/inetprot.h>
00114 #include <ptclib/cypher.h>
00115 
00117 // PMIMEInfo
00118 
00123 #ifdef DOC_PLUS_PLUS
00124 class PMIMEInfo : public PStringToString {
00125 #endif
00126 PDECLARE_STRING_DICTIONARY(PMIMEInfo, PCaselessString);
00127   public:
00128     PMIMEInfo(
00129       istream &strm   
00130     );
00131     PMIMEInfo(
00132       PInternetProtocol & socket   
00133     );
00134     // Construct a MIME information dictionary from the specified source.
00135 
00136 
00137   // Overrides from class PObject
00141     virtual void PrintOn(
00142       ostream &strm   
00143     ) const;
00144 
00148     virtual void ReadFrom(
00149       istream &strm   
00150     );
00151 
00152 
00153   // Overrides from class PStringToString
00160     BOOL SetAt(
00161       const char * key,
00162       const PString value
00163     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00164 
00171     BOOL SetAt(
00172       const PString & key,
00173       const PString value
00174     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00175 
00182     BOOL SetAt(
00183       const PCaselessString & key,
00184       const PString value
00185     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00186 
00193     BOOL Contains(
00194       const char * key       
00195     ) const { return GetAt(PCaselessString(key)) != NULL; }
00196 
00203     BOOL Contains(
00204       const PString & key       
00205     ) const { return GetAt(PCaselessString(key)) != NULL; }
00206 
00213     BOOL Contains(
00214       const PCaselessString & key       
00215     ) const { return GetAt(key) != NULL; }
00216 
00217   // New functions for class.
00223     BOOL Read(
00224       PInternetProtocol & socket   
00225     );
00226 
00232     BOOL Write(
00233       PInternetProtocol & socket   
00234     ) const;
00235 
00244     BOOL AddMIME(
00245       const PString & line
00246     );
00247     BOOL AddMIME(
00248       const PString & fieldName, 
00249       const PString & _fieldValue
00250     );
00251 
00259     PString GetString(
00260       const PString & key,       
00261       const PString & dflt       
00262     ) const;
00263 
00271     long GetInteger(
00272       const PString & key,    
00273       long dflt = 0           
00274     ) const;
00275 
00278     void SetInteger(
00279       const PCaselessString & key,  
00280       long value                    
00281     );
00282 
00283 
00321     static void SetAssociation(
00322       const PStringToString & allTypes,  
00323       BOOL merge = TRUE                  
00324     );
00325     static void SetAssociation(
00326       const PString & fileType,         
00327       const PString & contentType       
00328     ) { GetContentTypes().SetAt(fileType, contentType); }
00329 
00337     static PString GetContentType(
00338       const PString & fileType   
00339     );
00340 
00341   private:
00342     static PStringToString & GetContentTypes();
00343 };
00344 
00345 
00346 
00347 #endif
00348 
00349 
00350 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1