00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00040 void encode_file(const char *s,const char *outfn);
00041
00042
00043 void encode64(const char *in,size_t len,std::vector<std::string> &out);
00044
00045
00046 void encode_from_file(const char *,std::vector<std::string> &);
00047
00048 std::string encode_buffer(const std::string& );
00049
00050
00051
00052
00053
00054 void decode_file(char *s,char *outfn);
00055
00056
00057 void decode_to_file(std::vector<std::string> &body,char *outfn);
00058
00059
00060 void decode_stdout(char *fn,FILE *out = stdout);
00061
00062
00063 void decode_to_stdout(const std::string &,FILE * = stdout);
00064
00065
00066 void decode_to_stdout(std::vector<std::string> &,FILE * = stdout);
00067
00068
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 }
00084
00085 #endif // _CGI_BASE64_H