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