Codecs.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Codecs.h
00006  *
00007  *  $Id: Codecs.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *  @author Krishnakumar B <kitty@cs.wustl.edu>
00010  *
00011  *  Codecs is a generic wrapper for various encoding and decoding
00012  *  mechanisms. Currently it includes Base64 content transfer-encoding as
00013  *  specified by RFC 2045, Multipurpose Internet Mail Extensions (MIME) Part
00014  *  One: Format of Internet Message Bodies.
00015  *
00016  */
00017 //=============================================================================
00018 
00019 #ifndef ACE_CODECS_H
00020 #define ACE_CODECS_H
00021 
00022 #include /**/ "ace/pre.h"
00023 
00024 #include /**/ "ace/ACE_export.h"
00025 
00026 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00027 # pragma once
00028 #endif /* ACE_LACKS_PRAGMA_ONCE */
00029 
00030 #include "ace/Basic_Types.h"
00031 #include "ace/Global_Macros.h"
00032 
00033 
00034 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00035 
00036 /**
00037  * @class ACE_Base64
00038  *
00039  * @brief Encode/Decode a stream of bytes according to Base64 encoding.
00040  *
00041  * This class provides methods to encode or decode a stream of bytes
00042  * to/from Base64 encoding. It doesn't convert the input stream to a
00043  * canonical form before encoding.
00044  *
00045  */
00046 class ACE_Export ACE_Base64
00047 {
00048 public:
00049 
00050   //@{
00051 
00052   /**
00053    * Encodes a stream of bytes to Base64 data
00054    *
00055    * @param input Binary data in byte stream.
00056    * @param input_len Length of the byte stream.
00057    * @param output_len Length of the encoded Base64 byte stream.
00058    * @param is_chunked If true, terminate 72 character blocks with newline
00059    * @return Encoded Base64 data in byte stream or NULL if input data cannot
00060    *         be encoded.
00061    */
00062 
00063   static ACE_Byte* encode (const ACE_Byte* input,
00064                            const size_t input_len,
00065                            size_t* output_len,
00066                            bool is_chunked = true);
00067   /**
00068    * Decodes a stream of Base64 to bytes data
00069    *
00070    * @param input Encoded Base64 data in byte stream.
00071    * @param output_len Length of the binary byte stream.
00072    * @return Binary data in byte stream or NULL if input data cannot
00073    *         be encoded.
00074    */
00075   static ACE_Byte* decode (const ACE_Byte* input,
00076                            size_t* output_len);
00077 
00078   /**
00079    * Return the length of the encoded input data
00080    *
00081    * @param input Encoded Base64 data in byte stream.
00082    * @return Length of the encoded Base64 data.
00083    *
00084    */
00085   static size_t length (const ACE_Byte* input);
00086 
00087   //@}
00088 
00089 protected:
00090 
00091   // Prevent default construction.
00092   ACE_Base64 (void) {}
00093 
00094 private:
00095 
00096   // Preventing copying and assignment.
00097   ACE_Base64 (ACE_Base64 const &);
00098   ACE_Base64 & operator= (ACE_Base64 const &);
00099 
00100   /// Initialize the tables for encoding/decoding.
00101   static void init (void);
00102 
00103 private:
00104 
00105   /// Alphabet used for decoding i.e decoder_[alphabet_[i = 0..63]] = i
00106   static ACE_Byte decoder_[];
00107 
00108   /// Alphabet used to check valid range of encoded input i.e
00109   /// member_[alphabet_[0..63]] = 1
00110   static ACE_Byte member_[];
00111 
00112   /// Boolean to denote whether initialization is complete
00113   static bool init_;
00114 
00115 };
00116 
00117 ACE_END_VERSIONED_NAMESPACE_DECL
00118 
00119 #include /**/ "ace/post.h"
00120 
00121 #endif /* ACE_CODECS_H */

Generated on Tue Feb 2 17:18:38 2010 for ACE by  doxygen 1.4.7