XML_Codecs.cpp

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

Generated on Thu Nov 9 11:45:40 2006 for ACEXML by doxygen 1.3.6