00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INCL_BASE_UTILS
00020 #define INCL_BASE_UTILS
00021
00023 #include "base/fscapi.h"
00024 #include "base/util/ArrayList.h"
00025 #include "base/md5.h"
00026 #include "base/base64.h"
00027
00028 #include <stdio.h>
00029
00030
00031 #define STRINGDUP_NOLEN 0xFFFFFFFF
00032
00033 #define B64_ENCODING "b64"
00034 #define TEXT_PLAIN_ENCODING "text/plain"
00035
00036
00037
00038
00039
00040
00041 void safeDelete(char* p[]) EXTRA_SECTION_00;
00042
00043 void safeDel(char** p) EXTRA_SECTION_00;
00044
00051 void timestampToAnchor(unsigned long timestamp, char anchor[21]) EXTRA_SECTION_00;
00052
00056 unsigned long anchorToTimestamp(const char* anchor) EXTRA_SECTION_00;
00057
00058 char* stringdup(const char* s, size_t len = STRINGDUP_NOLEN) EXTRA_SECTION_00 ;
00059 WCHAR* wstrdup(const WCHAR* s, size_t len = STRINGDUP_NOLEN) EXTRA_SECTION_00;
00060
00061 char* strtolower(const char *s) EXTRA_SECTION_00;
00062
00063 char* wcstoupper(const char *s) EXTRA_SECTION_00;
00064
00068 const char *brfind(const char *s1, const char *s2, size_t len=STRINGDUP_NOLEN) EXTRA_SECTION_00 ;
00069
00073 inline BOOL isEmpty(const char* s) {
00074 return ((s == NULL) || (strlen(s) == 0));
00075 }
00076
00080 inline BOOL isNotEmpty(const char* s) {
00081 return (s && (strlen(s) > 0));
00082 }
00083
00084
00085
00086
00087
00088 bool wcscmpIgnoreCase(const char* p, const char* q);
00089
00090
00091
00092
00093 char* itow(int i);
00094
00095
00096
00097
00098 char* ltow(long i);
00099
00100
00101
00102
00103
00104 char* MD5CredentialData(char* userName, char* password, char* nonce);
00105
00106
00107
00108
00109 char* calculateMD5(const void* token, int len, char* wdigest);
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 char *mkTempFileName(const char *name);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 bool saveFile(const char *filename, const char *buffer, size_t len,
00133 bool binary = false );
00134
00135
00136
00137
00138
00139
00140
00141 size_t fgetsize(FILE *f);
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 bool readFile(const char* name, char **message, size_t *len, bool binary = false );
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 char** readDir(char* name, int *count, bool onlyCount = false);
00165
00171 unsigned long getFileModTime(const char* name);
00172
00173
00174 long int getLenEncoding(const char* s, const char* encoding);
00175 char *toMultibyte(const WCHAR *wc, const char *encoding = 0 );
00176 WCHAR *toWideChar(const char *mb, const char *encoding = 0 );
00177
00178
00179
00180
00181
00182
00183 inline const char *_wcc(const WCHAR *wc, const char *enc=0) {
00184 static char* encodeBuf = 0;
00185
00186 if (encodeBuf){
00187 delete [] encodeBuf;
00188 encodeBuf = 0;
00189 }
00190 if (wc) {
00191 encodeBuf = toMultibyte(wc, enc);
00192 }
00193 return encodeBuf;
00194 }
00195
00196
00198 #endif