Google
Web alhem.net

Base64.h

Go to the documentation of this file.
00001 // Base64.h
00002 /*
00003 This program is free software; you can redistribute it and/or
00004 modify it under the terms of the GNU General Public License
00005 as published by the Free Software Foundation; either version 2
00006 of the License, or (at your option) any later version.
00007 
00008 This program is distributed in the hope that it will be useful,
00009 but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License
00014 along with this program; if not, write to the Free Software
00015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016 */
00017 
00018 #ifndef _CGI_BASE64_H
00019 #define _CGI_BASE64_H
00020 
00021 #ifdef _WIN32
00022 #define STL_USING_STRING
00023 #define STL_USING_VECTOR
00024 #include <stlhelper.h>
00025 #else
00026 #include <string>
00027 #include <vector>
00028 #endif
00029 
00030 
00031 namespace Cgi {
00032 
00033 class Base64
00034 {
00035 public:
00036         Base64(char = '=');
00037         ~Base64();
00038 
00039         // file to file
00040         void encode_file(const char *s,const char *outfn);
00041 
00042         // input buffer to std::vector<std::string>
00043         void encode64(const char *in,size_t len,std::vector<std::string> &out);
00044 
00045         // file to std::vector<std::string>
00046         void encode_from_file(const char *,std::vector<std::string> &);
00047 
00048         std::string encode_buffer(const std::string& );
00049 
00050         // buffer to std::string
00051 //      void encode_buffer(const char *,size_t l,std::string& );
00052 
00053         // file to file
00054         void decode_file(char *s,char *outfn);
00055 
00056         // std::vector<std::string> to file
00057         void decode_to_file(std::vector<std::string> &body,char *outfn);
00058 
00059         // file to FILE *
00060         void decode_stdout(char *fn,FILE *out = stdout);
00061 
00062         // string to FILE *
00063         void decode_to_stdout(const std::string &,FILE * = stdout);
00064 
00065         // std::vector<std::string> to FILE *
00066         void decode_to_stdout(std::vector<std::string> &,FILE * = stdout);
00067 
00068         // string to buffer
00069         void decode_to_buffer(const std::string& ,char *,size_t max);
00070 
00071         size_t decode_length(const std::string& );
00072 
00073 private:
00074         void setupbase64();
00075         char setupdecode(char c);
00076         unsigned char reverse(char c);
00077         void encode(const char *in,char *out);
00078         int decode(char c);
00079         void decode_string(char *s, unsigned char *output, int &l);
00080         char m_eqchar;
00081 };
00082 
00083 } // namespace
00084 
00085 #endif // _CGI_BASE64_H

Generated for cgi++ by doxygen 1.3.7

Page, code, and content Copyright (C) 2004 by Anders Hedström