00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DEFINEH_H
00009 #define DEFINEH_H
00010
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif
00014
00015 #include "libpst.h"
00016 #include "timeconv.h"
00017 #include "libstrfunc.h"
00018 #include "vbuf.h"
00019
00020 #define DEBUG_MODE_GEN
00021 #define DEBUGPRINT
00022 #define DEBUG_MODE_WARN
00023 #define DEBUG_MODE_READ
00024 #define DEBUG_MODE_EMAIL
00025 #define DEBUG_MODE_MAIN
00026 #define DEBUG_MODE_INDEX
00027 #define DEBUG_MODE_CODE
00028 #define DEBUG_MODE_INFO
00029 #define DEBUG_MODE_HEXDUMP
00030 #define DEBUG_MODE_FUNC
00031
00032
00033 #define DEBUG_MAX_ITEMS 0
00034
00035 #define DEBUG_FILE_NO 1
00036 #define DEBUG_INDEX_NO 2
00037 #define DEBUG_EMAIL_NO 3
00038 #define DEBUG_WARN_NO 4
00039 #define DEBUG_READ_NO 5
00040 #define DEBUG_INFO_NO 6
00041 #define DEBUG_MAIN_NO 7
00042 #define DEBUG_DECRYPT_NO 8
00043 #define DEBUG_FUNCENT_NO 9
00044 #define DEBUG_FUNCRET_NO 10
00045 #define DEBUG_HEXDUMP_NO 11
00046
00047 #ifdef HAVE_TIME_H
00048 #include <time.h>
00049 #endif
00050
00051 #ifdef HAVE_STRING_H
00052 #include <string.h>
00053 #endif
00054
00055 #ifdef HAVE_CTYPE_H
00056 #include <ctype.h>
00057 #endif
00058
00059 #ifdef HAVE_LIMITS_H
00060 #include <limits.h>
00061 #endif
00062
00063 #ifdef HAVE_WCHAR_H
00064 #include <wchar.h>
00065 #endif
00066
00067 #ifdef HAVE_SIGNAL_H
00068 #include <signal.h>
00069 #endif
00070
00071 #ifdef HAVE_ERRNO_H
00072 #include <errno.h>
00073 #endif
00074
00075 #ifdef HAVE_ICONV
00076 #include <iconv.h>
00077 #endif
00078
00079 #ifdef HAVE_REGEX_H
00080 #include <regex.h>
00081 #endif
00082
00083 #ifdef HAVE_GD_H
00084 #include <gd.h>
00085 #endif
00086
00087
00088 #define PERM_DIRS 0777
00089
00090 #ifdef _WIN32
00091 #include <direct.h>
00092
00093 #define D_MKDIR(x) mkdir(x)
00094 #define chdir _chdir
00095 #define strcasecmp _stricmp
00096 #define vsnprintf _vsnprintf
00097 #define snprintf _snprintf
00098 #ifdef _MSC_VER
00099 #define ftello _ftelli64
00100 #define fseeko _fseeki64
00101 #elif defined (__MINGW32__)
00102 #define ftello ftello64
00103 #define fseeko fseeko64
00104 #else
00105 #error Only MSC and mingw supported for Windows
00106 #endif
00107 #ifndef __MINGW32__
00108 #define size_t __int64
00109 #endif
00110 #ifndef UINT64_MAX
00111 #define UINT64_MAX ((uint64_t)0xffffffffffffffff)
00112 #endif
00113 #define PRIx64 "I64x"
00114 int __cdecl _fseeki64(FILE *, __int64, int);
00115 __int64 __cdecl _ftelli64(FILE *);
00116
00117 #ifdef __MINGW32__
00118 #include <getopt.h>
00119 #else
00120 #include "XGetopt.h"
00121 #endif
00122 #else
00123 #ifdef HAVE_UNISTD_H
00124 #include <unistd.h>
00125 #else
00126 #include "XGetopt.h"
00127 #endif
00128 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
00129 #endif
00130
00131 #ifdef HAVE_SYS_STAT_H
00132 #include <sys/stat.h>
00133 #endif
00134
00135 #ifdef HAVE_SYS_TYPES_H
00136 #include <sys/types.h>
00137 #endif
00138
00139 #ifdef HAVE_DIRENT_H
00140 #include <dirent.h>
00141 #endif
00142
00143
00144 void pst_debug(const char *fmt, ...);
00145 void pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta);
00146 void pst_debug_hexprint(char *data, int size);
00147 void pst_debug_init(const char *fname);
00148 void pst_debug_msg_info (int line, const char *file, int type);
00149 void pst_debug_msg_text(const char* fmt, ...);
00150 void pst_debug_hexdump(char *x, size_t y, int cols, int delta);
00151 void pst_debug_func(const char *function);
00152 void pst_debug_func_ret();
00153 void pst_debug_close(void);
00154 void* pst_malloc(size_t size);
00155
00156 #define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
00157 pst_debug_msg_text x;}
00158
00159 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
00160
00161 #define DIE(x) {\
00162 MESSAGEPRINT(x, 0);\
00163 printf x;\
00164 exit(EXIT_FAILURE);\
00165 }
00166 #define WARN(x) {\
00167 MESSAGEPRINT(x, 0);\
00168 printf x;\
00169 }
00170
00171 #ifdef DEBUGPRINT
00172 #define DEBUG_PRINT(x) pst_debug x;
00173 #else
00174 #define DEBUG_PRINT(x) {}
00175 #endif
00176
00177 #ifdef DEBUG_MODE_GEN
00178 #define DEBUG(x) {DEBUG_PRINT(x);}
00179 #else
00180 #define DEBUG(x) {}
00181 #endif
00182
00183 #ifdef DEBUG_MODE_INDEX
00184 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
00185 #else
00186 #define DEBUG_INDEX(x) {}
00187 #endif
00188
00189 #ifdef DEBUG_MODE_EMAIL
00190 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
00191 #define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
00192 pst_debug_hexdump((char*)x, y, 0x10, 0);}
00193 #else
00194 #define DEBUG_EMAIL(x) {}
00195 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
00196 #endif
00197
00198 #ifdef DEBUG_MODE_WARN
00199 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
00200 #else
00201 #define DEBUG_WARN(x) {}
00202 #endif
00203
00204 #ifdef DEBUG_MODE_READ
00205 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
00206 #else
00207 #define DEBUG_READ(x) {}
00208 #endif
00209
00210 #ifdef DEBUG_MODE_INFO
00211 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
00212 #else
00213 #define DEBUG_INFO(x) {}
00214 #endif
00215
00216 #ifdef DEBUG_MODE_MAIN
00217 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
00218 #else
00219 #define DEBUG_MAIN(x) {}
00220 #endif
00221
00222 #ifdef DEBUG_MODE_CODE
00223 #define DEBUG_CODE(x) {x}
00224 #else
00225 #define DEBUG_CODE(x) {}
00226 #endif
00227
00228 #ifdef DEBUG_MODE_DECRYPT
00229 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
00230 #else
00231 #define DEBUG_DECRYPT(x) {}
00232 #endif
00233
00234 #ifdef DEBUG_MODE_HEXDUMP
00235 #define DEBUG_HEXDUMP(x, s)\
00236 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00237 pst_debug_hexdump((char*)x, s, 0x10, 0);}
00238 #define DEBUG_HEXDUMPC(x, s, c)\
00239 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00240 pst_debug_hexdump((char*)x, s, c, 0);}
00241 #else
00242 #define DEBUG_HEXDUMP(x, s) {}
00243 #define DEBUG_HEXDUMPC(x, s, c) {}
00244 #endif
00245
00246 #define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
00247 pst_debug_msg_text x;}
00248
00249 #ifdef DEBUG_MODE_FUNC
00250 # define DEBUG_ENT(x) \
00251 { \
00252 pst_debug_func(x); \
00253 MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \
00254 }
00255 # define DEBUG_RET() \
00256 { \
00257 MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO); \
00258 pst_debug_func_ret(); \
00259 }
00260 #else
00261 # define DEBUG_ENT(x) {}
00262 # define DEBUG_RET() {}
00263 #endif
00264
00265 #define DEBUG_INIT(fname) {pst_debug_init(fname);}
00266 #define DEBUG_CLOSE() {pst_debug_close();}
00267 #define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
00268
00269 #define RET_DERROR(res, ret_val, x)\
00270 if (res) { DIE(x);}
00271
00272 #define RET_ERROR(res, ret_val)\
00273 if (res) {return ret_val;}
00274
00275 #define DEBUG_VERSION 1
00276 struct pst_debug_file_rec_m {
00277 unsigned short int funcname;
00278 unsigned short int filename;
00279 unsigned short int text;
00280 unsigned short int end;
00281 unsigned int line;
00282 unsigned int type;
00283 };
00284
00285 struct pst_debug_file_rec_l {
00286 unsigned int funcname;
00287 unsigned int filename;
00288 unsigned int text;
00289 unsigned int end;
00290 unsigned int line;
00291 unsigned int type;
00292 };
00293
00294 #if BYTE_ORDER == BIG_ENDIAN
00295 # define LE64_CPU(x) \
00296 x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00297 (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00298 (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00299 (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00300 (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00301 (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00302 (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00303 (((x) & UINT64_C(0x00000000000000ff)) << 56));
00304 # define LE32_CPU(x) \
00305 x = ((((x) & 0xff000000) >> 24) | \
00306 (((x) & 0x00ff0000) >> 8 ) | \
00307 (((x) & 0x0000ff00) << 8 ) | \
00308 (((x) & 0x000000ff) << 24));
00309 # define LE16_CPU(x) \
00310 x = ((((x) & 0xff00) >> 8) | \
00311 (((x) & 0x00ff) << 8));
00312 #elif BYTE_ORDER == LITTLE_ENDIAN
00313 # define LE64_CPU(x) {}
00314 # define LE32_CPU(x) {}
00315 # define LE16_CPU(x) {}
00316 #else
00317 # error "Byte order not supported by this library"
00318 #endif // BYTE_ORDER
00319
00320
00321 #define PST_LE_GET_UINT64(p) \
00322 (uint64_t)((((uint8_t const *)(p))[0] << 0) | \
00323 (((uint8_t const *)(p))[1] << 8) | \
00324 (((uint8_t const *)(p))[2] << 16) | \
00325 (((uint8_t const *)(p))[3] << 24) | \
00326 (((uint8_t const *)(p))[4] << 32) | \
00327 (((uint8_t const *)(p))[5] << 40) | \
00328 (((uint8_t const *)(p))[6] << 48) | \
00329 (((uint8_t const *)(p))[7] << 56))
00330
00331 #define PST_LE_GET_INT64(p) \
00332 (int64_t)((((uint8_t const *)(p))[0] << 0) | \
00333 (((uint8_t const *)(p))[1] << 8) | \
00334 (((uint8_t const *)(p))[2] << 16) | \
00335 (((uint8_t const *)(p))[3] << 24) | \
00336 (((uint8_t const *)(p))[4] << 32) | \
00337 (((uint8_t const *)(p))[5] << 40) | \
00338 (((uint8_t const *)(p))[6] << 48) | \
00339 (((uint8_t const *)(p))[7] << 56))
00340
00341 #define PST_LE_GET_UINT32(p) \
00342 (uint32_t)((((uint8_t const *)(p))[0] << 0) | \
00343 (((uint8_t const *)(p))[1] << 8) | \
00344 (((uint8_t const *)(p))[2] << 16) | \
00345 (((uint8_t const *)(p))[3] << 24))
00346
00347 #define PST_LE_GET_INT32(p) \
00348 (int32_t)((((uint8_t const *)(p))[0] << 0) | \
00349 (((uint8_t const *)(p))[1] << 8) | \
00350 (((uint8_t const *)(p))[2] << 16) | \
00351 (((uint8_t const *)(p))[3] << 24))
00352
00353 #define PST_LE_GET_UINT16(p) \
00354 (uint16_t)((((uint8_t const *)(p))[0] << 0) | \
00355 (((uint8_t const *)(p))[1] << 8))
00356
00357 #define PST_LE_GET_INT16(p) \
00358 (int16_t)((((uint8_t const *)(p))[0] << 0) | \
00359 (((uint8_t const *)(p))[1] << 8))
00360
00361 #define PST_LE_GET_UINT8(p) (*(uint8_t const *)(p))
00362
00363 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
00364
00365
00366 #endif //DEFINEH_H