Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XML_Codecs.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: XML_Codecs.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00002 
00003 #include "ace/Auto_Ptr.h"
00004 #include "ACEXML/common/XML_Codecs.h"
00005 
00006 ACE_RCSID (common, XML_Codecs, "$Id: XML_Codecs.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $")
00007 
00008 ACEXML_Char*
00009 ACEXML_Base64::encode (const ACEXML_Char* input,
00010                        size_t* output_len)
00011 {
00012   if (!input)
00013     return 0;
00014   size_t len = ACE_OS::strlen (input);
00015 
00016   ACE_Byte* buf = 0;
00017   ACE_NEW_RETURN (buf,
00018                   ACE_Byte[len],
00019                   0);
00020   ACE_Auto_Basic_Array_Ptr<ACE_Byte> cleanup_buf (buf);
00021 
00022   for (size_t i = 0; i < len; ++i)
00023     buf[i] = (ACE_Byte)input[i];
00024   buf[len] = 0;
00025 
00026   size_t encode_len = 0;
00027   ACE_Byte* encodedBuf = ACE_Base64::encode (buf, len, &encode_len);
00028 
00029   if (!encodedBuf)
00030     return 0;
00031 
00032   ACEXML_Char* result = 0;
00033   ACE_NEW_RETURN (result,
00034                   ACEXML_Char[encode_len+1],
00035                   0);
00036 
00037   for (size_t j = 0; j < encode_len; ++j)
00038     result[j] = (ACEXML_Char)encodedBuf[j];
00039   result[encode_len] = 0;
00040 
00041   *output_len = encode_len;
00042   delete[] encodedBuf;
00043   return result;
00044 }
00045 
00046 
00047 ACEXML_Char*
00048 ACEXML_Base64::decode (const ACEXML_Char* input,
00049                        size_t* output_len)
00050 {
00051   if (!input)
00052     return 0;
00053 
00054   size_t len = ACE_OS::strlen (input);
00055 
00056   ACE_Byte* buf = 0;
00057 
00058   ACE_NEW_RETURN (buf,
00059                   ACE_Byte[len],
00060                   0);
00061 
00062   ACE_Auto_Basic_Array_Ptr<ACE_Byte> cleanup (buf);
00063 
00064   for (size_t i = 0; i < len; ++i)
00065     buf[i] = (ACE_Byte)input[i];
00066 
00067   buf[len] = 0;
00068 
00069   size_t decode_len = 0;
00070 
00071   ACE_Byte* decodedBuf = ACE_Base64::decode (buf, &decode_len);
00072 
00073   if (!decodedBuf)
00074     return 0;
00075 
00076   ACEXML_Char* result = 0;
00077 
00078   ACE_NEW_RETURN (result,
00079                   ACEXML_Char[decode_len+1],
00080                   0);
00081 
00082   for (size_t j = 0; j < decode_len; ++j)
00083     result[j] = (ACEXML_Char)decodedBuf[j];
00084 
00085   result[decode_len] = 0;
00086 
00087   *output_len = decode_len;
00088   delete[] decodedBuf;
00089 
00090   return result;
00091 }
00092 
00093 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00094 template class ACE_Auto_Basic_Array_Ptr<ACE_Byte>;
00095 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00096 #pragma instantiate ACE_Auto_Basic_Array_Ptr<ACE_Byte>
00097 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

Generated on Mon Jun 16 13:23:28 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002