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[]);
00042
00043 void safeDel(char** p);
00044
00051 void timestampToAnchor(unsigned long timestamp, char anchor[21]);
00052
00056 unsigned long anchorToTimestamp(const char* anchor);
00057
00058 char* stringdup(const char* s, size_t len = STRINGDUP_NOLEN) ;
00059 WCHAR* wstrdup(const WCHAR* s, size_t len = STRINGDUP_NOLEN);
00060
00061 char* strtolower(const char *s);
00062
00063 char* wcstoupper(const char *s);
00064
00068 const char *brfind(const char *s1, const char *s2, size_t len=STRINGDUP_NOLEN) ;
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
00105 char* MD5CredentialData(const char* userName, const char* password, const char* nonce);
00106
00107
00108
00109
00110 char* calculateMD5(const void* token, int len, char* wdigest);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 char *mkTempFileName(const char *name);
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 bool saveFile(const char *filename, const char *buffer, size_t len,
00134 bool binary = false );
00135
00136
00137
00138
00139
00140
00141
00142 size_t fgetsize(FILE *f);
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 bool readFile(const char* name, char **message, size_t *len, bool binary = false );
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 char** readDir(char* name, int *count, bool onlyCount = false);
00166
00172 unsigned long getFileModTime(const char* name);
00173
00174
00175 long int getLenEncoding(const char* s, const char* encoding);
00176 char *toMultibyte(const WCHAR *wc, const char *encoding = 0 );
00177 WCHAR *toWideChar(const char *mb, const char *encoding = 0 );
00178
00179
00180
00181
00182
00183
00184 inline const char *_wcc(const WCHAR *wc, const char *enc=0) {
00185 static char* encodeBuf = 0;
00186
00187 if (encodeBuf){
00188 delete [] encodeBuf;
00189 encodeBuf = 0;
00190 }
00191 if (wc) {
00192 encodeBuf = toMultibyte(wc, enc);
00193 }
00194 return encodeBuf;
00195 }
00196
00197
00199 #endif