00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef INCL_ENCODING_HELPER
00037 #define INCL_ENCODING_HELPER
00038
00040 #include "base/fscapi.h"
00041 #include "base/constants.h"
00042 #include "base/globalsdef.h"
00043 #include "base/util/StringBuffer.h"
00044
00045 BEGIN_NAMESPACE
00046
00051 class EncodingHelper {
00052
00053 private:
00054
00058 StringBuffer encoding;
00059
00063 StringBuffer encryption;
00064
00068 StringBuffer credential;
00069
00074 StringBuffer from;
00075
00079 StringBuffer dataEncoding;
00080
00081 char* transformData(const char* name, bool encode, const char* password,
00082 char* buff, unsigned long *len);
00083
00084 void setEncoding(const char* encoding);
00085 void setEncryption(const char* encryption);
00086 void setCredential(const char* credential);
00087
00088 void setDataEncoding(const char* dataEnc);
00089
00100 char* transform(const char* from, char* buffer, unsigned long *len);
00101
00102 public:
00103
00104
00105 EncodingHelper(const char* encoding, const char* encryption, const char* credential);
00106
00107 ~EncodingHelper();
00108
00109 StringBuffer getDataEncoding() { return dataEncoding; }
00110
00119 char* encode(const char* from, char* buffer, unsigned long *len);
00120
00129 char* decode(const char* from, char* buffer, unsigned long *len);
00130
00131
00144 long getMaxDataSizeToEncode(long size);
00145
00151 long getDataSizeAfterEncoding(long size);
00152
00156 struct encodings {
00157 static const char* const plain;
00158 static const char* const escaped;
00159 static const char* const des;
00163 static const char* encodingString(const char* encoding) {
00164 return encoding ? encoding : plain;
00165 }
00166
00168 static const bool isSupported(const char* encoding) {
00169 const char* enc = encodingString(encoding);
00170 return !strcmp(enc, plain) ||
00171 !strcmp(enc, escaped) ||
00172 !strcmp(enc, des);
00173 }
00174 };
00175 };
00176
00177
00178 END_NAMESPACE
00179
00181 #endif