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.21  2005/11/30 12:47:37  csoutheren
00028  * Removed tabs, reformatted some code, and changed tags for Doxygen
00029  *
00030  * Revision 1.20  2004/03/23 06:38:51  csoutheren
00031  * Update for change in location of Base64 routines
00032  *
00033  * Revision 1.19  2004/03/23 05:59:17  csoutheren
00034  * Moved the Base64 routines into cypher.cxx, which is a more sensible
00035  * place and reduces the inclusion of unrelated code
00036  *
00037  * Revision 1.18  2002/11/06 22:47:24  robertj
00038  * Fixed header comment (copyright etc)
00039  *
00040  * Revision 1.17  2002/09/16 01:08:59  robertj
00041  * Added #define so can select if #pragma interface/implementation is used on
00042  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00043  *
00044  * Revision 1.16  2001/10/03 00:24:57  robertj
00045  * Split out function for adding a single line of MIME info, reduces
00046  *    duplicated code and is useful in some other areas such as HTTP/1.1
00047  *
00048  * Revision 1.15  2001/09/28 00:41:18  robertj
00049  * Added SetInteger() function to set numeric MIME fields.
00050  * Removed HasKey() as is confusing due to ancestor Contains().
00051  * Overrides of SetAt() and Contains() to assure PCaselessString used.
00052  *
00053  * Revision 1.14  2000/11/09 00:18:26  robertj
00054  * Cosmetic change: removed blank lines.
00055  *
00056  * Revision 1.13  1999/03/09 08:01:46  robertj
00057  * Changed comments for doc++ support (more to come).
00058  *
00059  * Revision 1.12  1999/02/16 08:07:10  robertj
00060  * MSVC 6.0 compatibility changes.
00061  *
00062  * Revision 1.11  1998/11/30 02:50:52  robertj
00063  * New directory structure
00064  *
00065  * Revision 1.10  1998/09/23 06:19:42  robertj
00066  * Added open source copyright license.
00067  *
00068  * Revision 1.9  1997/02/05 11:53:11  robertj
00069  * Changed construction of MIME dictionary to be delayed untill it is used.
00070  *
00071  * Revision 1.8  1996/09/14 13:09:15  robertj
00072  * Major upgrade:
00073  *   rearranged sockets to help support IPX.
00074  *   added indirect channel class and moved all protocols to descend from it,
00075  *   separating the protocol from the low level byte transport.
00076  *
00077  * Revision 1.7  1996/07/15 10:28:31  robertj
00078  * Changed memory block base64 conversion functions to be void *.
00079  *
00080  * Revision 1.6  1996/03/16 04:38:09  robertj
00081  * Fixed bug in MIME write function, should be const.
00082  *
00083  * Revision 1.5  1996/02/25 03:04:32  robertj
00084  * Added decoding of Base64 to a block of memory instead of PBYTEArray.
00085  *
00086  * Revision 1.4  1996/01/28 14:14:30  robertj
00087  * Further implementation of secure config.
00088  *
00089  * Revision 1.3  1996/01/28 02:46:07  robertj
00090  * Removal of MemoryPointer classes as usage didn't work for GNU.
00091  *
00092  * Revision 1.2  1996/01/26 02:24:27  robertj
00093  * Further implemetation.
00094  *
00095  * Revision 1.1  1996/01/23 13:06:18  robertj
00096  * Initial revision
00097  *
00098  */
00099 
00100 #ifndef _PMIME
00101 #define _PMIME
00102 
00103 #ifdef P_USE_PRAGMA
00104 #pragma interface
00105 #endif
00106 
00107 #include <ptclib/inetprot.h>
00108 #include <ptclib/cypher.h>
00109 
00111 // PMIMEInfo
00112 
00117 #ifdef DOC_PLUS_PLUS
00118 class PMIMEInfo : public PStringToString {
00119 #endif
00120 PDECLARE_STRING_DICTIONARY(PMIMEInfo, PCaselessString);
00121   public:
00122     PMIMEInfo(
00123       istream &strm   
00124     );
00125     PMIMEInfo(
00126       PInternetProtocol & socket   
00127     );
00128     // Construct a MIME infromation dictionary from the specified source.
00129 
00130 
00131   // Overrides from class PObject
00135     virtual void PrintOn(
00136       ostream &strm   
00137     ) const;
00138 
00142     virtual void ReadFrom(
00143       istream &strm   
00144     );
00145 
00146 
00147   // Overrides from class PStringToString
00154     BOOL SetAt(
00155       const char * key,
00156       const PString value
00157     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00158 
00165     BOOL SetAt(
00166       const PString & key,
00167       const PString value
00168     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00169 
00176     BOOL SetAt(
00177       const PCaselessString & key,
00178       const PString value
00179     ) { return AbstractSetAt(PCaselessString(key), PNEW PString(value)); }
00180 
00187     BOOL Contains(
00188       const char * key       
00189     ) const { return GetAt(PCaselessString(key)) != NULL; }
00190 
00197     BOOL Contains(
00198       const PString & key       
00199     ) const { return GetAt(PCaselessString(key)) != NULL; }
00200 
00207     BOOL Contains(
00208       const PCaselessString & key       
00209     ) const { return GetAt(key) != NULL; }
00210 
00211   // New functions for class.
00217     BOOL Read(
00218       PInternetProtocol & socket   
00219     );
00220 
00226     BOOL Write(
00227       PInternetProtocol & socket   
00228     ) const;
00229 
00238     BOOL AddMIME(
00239       const PString & line
00240     );
00241 
00249     PString GetString(
00250       const PString & key,       
00251       const PString & dflt       
00252     ) const;
00253 
00261     long GetInteger(
00262       const PString & key,    
00263       long dflt = 0           
00264     ) const;
00265 
00268     void SetInteger(
00269       const PCaselessString & key,  
00270       long value                    
00271     );
00272 
00273 
00311     static void SetAssociation(
00312       const PStringToString & allTypes,  
00313       BOOL merge = TRUE                  
00314     );
00315     static void SetAssociation(
00316       const PString & fileType,         
00317       const PString & contentType       
00318     ) { GetContentTypes().SetAt(fileType, contentType); }
00319 
00327     static PString GetContentType(
00328       const PString & fileType   
00329     );
00330 
00331   private:
00332     static PStringToString & GetContentTypes();
00333 };
00334 
00335 
00336 
00337 #endif
00338 
00339 
00340 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Sep 21 14:40:11 2007 for PWLib by  doxygen 1.5.3