16
|
1 /***
|
|
2 * define.h
|
|
3 * Part of the LibPST project
|
|
4 * Written by David Smith
|
|
5 * dave.s@earthcorp.com
|
|
6 */
|
|
7
|
31
|
8 #ifdef HAVE_CONFIG_H
|
|
9 #include "config.h"
|
|
10 #endif
|
16
|
11
|
|
12 #ifndef DEFINEH_H
|
|
13 #define DEFINEH_H
|
|
14
|
|
15 #define DEBUG_MODE_GEN
|
|
16 #define DEBUGPRINT
|
|
17 #define DEBUG_MODE_WARN
|
|
18 #define DEBUG_MODE_READ
|
|
19 #define DEBUG_MODE_EMAIL
|
|
20 #define DEBUG_MODE_MAIN
|
|
21 #define DEBUG_MODE_INDEX
|
|
22 #define DEBUG_MODE_CODE
|
|
23 #define DEBUG_MODE_INFO
|
|
24 #define DEBUG_MODE_HEXDUMP
|
|
25 #define DEBUG_MODE_FUNC
|
|
26
|
|
27 //number of items to save in memory between writes
|
|
28 #define DEBUG_MAX_ITEMS 0
|
|
29
|
36
|
30 #define DEBUG_FILE_NO 1
|
|
31 #define DEBUG_INDEX_NO 2
|
|
32 #define DEBUG_EMAIL_NO 3
|
|
33 #define DEBUG_WARN_NO 4
|
|
34 #define DEBUG_READ_NO 5
|
|
35 #define DEBUG_INFO_NO 6
|
|
36 #define DEBUG_MAIN_NO 7
|
|
37 #define DEBUG_DECRYPT_NO 8
|
|
38 #define DEBUG_FUNCENT_NO 9
|
|
39 #define DEBUG_FUNCRET_NO 10
|
16
|
40 #define DEBUG_HEXDUMP_NO 11
|
|
41
|
|
42 //variable number of arguments to this macro. will expand them into
|
|
43 // ## args, then exit with status of 1
|
|
44 #include <stdio.h>
|
|
45 #include <stdlib.h>
|
|
46 #include <stdarg.h>
|
|
47
|
|
48 #ifdef __LINUX__
|
|
49 #include <netinet/in.h>
|
|
50 #include <unistd.h>
|
|
51 #endif
|
|
52
|
|
53
|
46
|
54 void pst_debug(char *fmt, ...);
|
|
55 void pst_debug_hexdumper(FILE* out, unsigned char* buf, size_t size, int col, int delta);
|
|
56 void pst_debug_hexprint(char *data, int size);
|
16
|
57
|
46
|
58 void pst_debug_init(char *fname);
|
|
59 void pst_debug_msg_info (int line, char *file, int type);
|
|
60 void pst_debug_msg_text(char* fmt, ...);
|
|
61 void pst_debug_hexdump(unsigned char *x, size_t y, int cols, int delta);
|
|
62 void pst_debug_func(char *function);
|
|
63 void pst_debug_func_ret();
|
|
64 void pst_debug_close(void);
|
|
65 void pst_debug_write();
|
16
|
66
|
|
67 void * xmalloc(size_t size);
|
|
68
|
46
|
69 #define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
|
|
70 pst_debug_msg_text x;}
|
16
|
71
|
|
72 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
|
|
73
|
|
74 #define DIE(x) {\
|
|
75 MESSAGEPRINT(x, 0);\
|
|
76 printf x;\
|
|
77 exit(EXIT_FAILURE);\
|
|
78 }
|
|
79 #define WARN(x) {\
|
|
80 MESSAGEPRINT(x, 0);\
|
|
81 printf x;\
|
|
82 }
|
|
83
|
|
84 #ifdef DEBUGPRINT
|
46
|
85 #define DEBUG_PRINT(x) pst_debug x;
|
16
|
86 #else
|
|
87 #define DEBUG_PRINT(x) {}
|
|
88 #endif
|
|
89
|
|
90 #ifdef DEBUG_MODE_GEN
|
|
91 #define DEBUG(x) {DEBUG_PRINT(x);}
|
|
92 #else
|
|
93 #define DEBUG(x) {}
|
|
94 #endif
|
|
95
|
|
96 #ifdef DEBUG_MODE_INDEX
|
|
97 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
|
|
98 #else
|
|
99 #define DEBUG_INDEX(x) {}
|
|
100 #endif
|
|
101
|
|
102 #ifdef DEBUG_MODE_EMAIL
|
|
103 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
|
46
|
104 #define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
|
|
105 pst_debug_hexdump(x, y, 0x10, 0);}
|
16
|
106 #else
|
|
107 #define DEBUG_EMAIL(x) {}
|
|
108 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
|
|
109 #endif
|
|
110
|
|
111 #ifdef DEBUG_MODE_WARN
|
|
112 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
|
|
113 #else
|
|
114 #define DEBUG_WARN(x) {}
|
|
115 #endif
|
|
116
|
|
117 #ifdef DEBUG_MODE_READ
|
|
118 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
|
|
119 #else
|
|
120 #define DEBUG_READ(x) {}
|
|
121 #endif
|
|
122
|
|
123 #ifdef DEBUG_MODE_INFO
|
|
124 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
|
|
125 #else
|
|
126 #define DEBUG_INFO(x) {}
|
|
127 #endif
|
|
128
|
|
129 #ifdef DEBUG_MODE_MAIN
|
|
130 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
|
|
131 #else
|
|
132 #define DEBUG_MAIN(x) {}
|
|
133 #endif
|
|
134
|
|
135 #ifdef DEBUG_MODE_CODE
|
|
136 #define DEBUG_CODE(x) {x}
|
|
137 #else
|
|
138 #define DEBUG_CODE(x) {}
|
|
139 #endif
|
|
140
|
|
141 #ifdef DEBUG_MODE_DECRYPT
|
|
142 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
|
|
143 #else
|
|
144 #define DEBUG_DECRYPT(x) {}
|
|
145 #endif
|
|
146
|
|
147 #ifdef DEBUG_MODE_HEXDUMP
|
|
148 #define DEBUG_HEXDUMP(x, s)\
|
46
|
149 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
|
|
150 pst_debug_hexdump(x, s, 0x10, 0);}
|
16
|
151 #define DEBUG_HEXDUMPC(x, s, c)\
|
46
|
152 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
|
|
153 pst_debug_hexdump(x, s, c, 0);}
|
16
|
154 #else
|
|
155 #define DEBUG_HEXDUMP(x, s) {}
|
|
156 #define DEBUG_HEXDUMPC(x, s, c) {}
|
|
157 #endif
|
|
158
|
46
|
159 #define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
|
|
160 pst_debug_msg_text x;}
|
16
|
161
|
|
162 #ifdef DEBUG_MODE_FUNC
|
36
|
163 # define DEBUG_ENT(x) \
|
|
164 { \
|
46
|
165 pst_debug_func(x); \
|
36
|
166 MESSAGEPRINT(("Entering function\n"),DEBUG_FUNCENT_NO); \
|
|
167 }
|
|
168 # define DEBUG_RET() \
|
|
169 { \
|
|
170 MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO); \
|
46
|
171 pst_debug_func_ret(); \
|
36
|
172 }
|
16
|
173 #else
|
|
174 # define DEBUG_ENT(x) {}
|
|
175 # define DEBUG_RET() {}
|
|
176 #endif
|
|
177
|
46
|
178 #define DEBUG_INIT(fname) {pst_debug_init(fname);}
|
|
179 #define DEBUG_CLOSE() {pst_debug_close();}
|
|
180 #define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
|
16
|
181
|
|
182 #define RET_DERROR(res, ret_val, x)\
|
|
183 if (res) { DIE(x);}
|
|
184
|
|
185 #define RET_ERROR(res, ret_val)\
|
|
186 if (res) {return ret_val;}
|
|
187
|
|
188 #define DEBUG_VERSION 1
|
46
|
189 struct pst_debug_file_rec_m {
|
16
|
190 unsigned short int funcname;
|
|
191 unsigned short int filename;
|
|
192 unsigned short int text;
|
|
193 unsigned short int end;
|
|
194 unsigned int line;
|
|
195 unsigned int type;
|
|
196 };
|
|
197
|
46
|
198 struct pst_debug_file_rec_l {
|
16
|
199 unsigned int funcname;
|
|
200 unsigned int filename;
|
|
201 unsigned int text;
|
|
202 unsigned int end;
|
|
203 unsigned int line;
|
|
204 unsigned int type;
|
|
205 };
|
|
206
|
|
207 #endif //DEFINEH_H
|