File: define.h

package info (click to toggle)
libpst 0.5.3-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 516 kB
  • ctags: 714
  • sloc: ansic: 7,115; makefile: 98; sh: 23
file content (201 lines) | stat: -rw-r--r-- 4,611 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/***
 * define.h
 * Part of the LibPST project
 * Written by David Smith
 *            dave.s@earthcorp.com
 */

//#define DEBUG_ALL
#ifndef DEFINEH_H
#define DEFINEH_H

#ifdef DEBUG_ALL
#define DEBUG_MODE_GEN
#define DEBUGPRINT
#define DEBUG_MODE_WARN
#define DEBUG_MODE_READ
#define DEBUG_MODE_EMAIL
#define DEBUG_MODE_MAIN
#define DEBUG_MODE_INDEX
#define DEBUG_MODE_CODE
#define DEBUG_MODE_INFO
#define DEBUG_MODE_HEXDUMP
#define DEBUG_MODE_FUNC
//#define DEBUG_MODE_DECRYPT
#endif

//number of items to save in memory between writes
#define DEBUG_MAX_ITEMS 0

#define DEBUG_FILE_NO  1
#define DEBUG_INDEX_NO 2
#define DEBUG_EMAIL_NO 3
#define DEBUG_WARN_NO  4
#define DEBUG_READ_NO  5
#define DEBUG_INFO_NO  6
#define DEBUG_MAIN_NO  7
#define DEBUG_DECRYPT_NO 8
#define DEBUG_FUNC_NO 10
#define DEBUG_HEXDUMP_NO 11

//variable number of arguments to this macro. will expand them into 
// ## args, then exit with status of 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#ifdef __LINUX__
#include <netinet/in.h>
#include <unistd.h>
#endif


void _pst_debug(char *fmt, ...);
void _pst_debug_hexdump(FILE* out, unsigned char* buf, size_t size, int col);
void _pst_debug_hexprint(char *data, int size);

void _debug_init(char *fname);
void _debug_msg_info (int line, char *file, int type);
void _debug_msg_text(char* fmt, ...);
void _debug_hexdump(unsigned char *x, int y, int cols);
void _debug_func(char *function);
void _debug_func_ret();
void _debug_close(void);
void _debug_write();

void * xmalloc(size_t size);

#define MESSAGEPRINT(x,y) {_debug_msg_info(__LINE__,__FILE__,y);\
                           _debug_msg_text x;}

#define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}

#define DIE(x) {\
 MESSAGEPRINT(x, 0);\
 printf x;\
 exit(EXIT_FAILURE);\
}
#define WARN(x) {\
 MESSAGEPRINT(x, 0);\
 printf x;\
}

#ifdef DEBUGPRINT
#define DEBUG_PRINT(x) _pst_debug x;
#else
#define DEBUG_PRINT(x) {}
#endif

#ifdef DEBUG_MODE_GEN
#define DEBUG(x) {DEBUG_PRINT(x);}
#else
#define DEBUG(x) {}
#endif

#ifdef DEBUG_MODE_INDEX
#define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
#else
#define DEBUG_INDEX(x) {}
#endif

#ifdef DEBUG_MODE_EMAIL
#define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
#define DEBUG_EMAIL_HEXPRINT(x,y) {_debug_msg_info(__LINE__, __FILE__, 11);\
                                   _debug_hexdump(x, y, 0x10);}
#else
#define DEBUG_EMAIL(x) {}
#define DEBUG_EMAIL_HEXPRINT(x,y) {}
#endif

#ifdef DEBUG_MODE_WARN
#define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
#else
#define DEBUG_WARN(x) {}
#endif

#ifdef DEBUG_MODE_READ
#define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
#else
#define DEBUG_READ(x) {}
#endif

#ifdef DEBUG_MODE_INFO
#define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
#else
#define DEBUG_INFO(x) {}
#endif

#ifdef DEBUG_MODE_MAIN
#define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
#else
#define DEBUG_MAIN(x) {}
#endif

#ifdef DEBUG_MODE_CODE
#define DEBUG_CODE(x) {x}
#else
#define DEBUG_CODE(x) {}
#endif

#ifdef DEBUG_MODE_DECRYPT
#define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
#else
#define DEBUG_DECRYPT(x) {}
#endif

#ifdef DEBUG_MODE_HEXDUMP
#define DEBUG_HEXDUMP(x, s)\
  {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
   _debug_hexdump(x, s, 0x10);}
#define DEBUG_HEXDUMPC(x, s, c)\
  {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
   _debug_hexdump(x, s, c);}
#else
#define DEBUG_HEXDUMP(x, s) {}
#define DEBUG_HEXDUMPC(x, s, c) {}
#endif

#define DEBUG_FILE(x) {_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
                       _debug_msg_text x;}

#ifdef DEBUG_MODE_FUNC
# define DEBUG_ENT(x) \
  {MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNC_NO);\
   _debug_func(x);}
# define DEBUG_RET() {MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNC_NO);\
                      _debug_func_ret();}
#else
# define DEBUG_ENT(x) {}
# define DEBUG_RET() {}
#endif

#define DEBUG_INIT(fname) {_debug_init(fname);}
#define DEBUG_CLOSE() {_debug_close();}
#define DEBUG_REGISTER_CLOSE() {if(atexit(_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}

#define RET_DERROR(res, ret_val, x)\
	if (res) { DIE(x);}

#define RET_ERROR(res, ret_val)\
	if (res) {return ret_val;}	

#define DEBUG_VERSION 1
struct _debug_file_rec_m {
  unsigned short int funcname;
  unsigned short int filename;
  unsigned short int text;
  unsigned short int end;
  unsigned int line;
  unsigned int type;
};

struct _debug_file_rec_l {
  unsigned int funcname;
  unsigned int filename;
  unsigned int text;
  unsigned int end;
  unsigned int line;
  unsigned int type;
};

#endif //DEFINEH_H