[go: up one dir, main page]

Menu

[1d06a9]: / src / flom_trace.h  Maximize  Restore  History

Download this file

242 lines (173 with data), 5.6 kB

  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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* Copyright (c) 2013-2014, Christian Ferrari <tiian@users.sourceforge.net>
* All rights reserved.
*
* This file is part of FLOM.
*
* FLOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* FLOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FLOM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FLOM_TRACE_H
# define FLOM_TRACE_H
#include <config.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif /* HAVE_STDIO_H */
#include <flom_defines.h>
/**
* Name of the environment variable must be used to set the trace mask
*/
#define FLOM_TRACE_MASK_ENV_VAR "FLOM_TRACE_MASK"
/**
* trace module for files do not need trace feature
*/
#define FLOM_TRACE_MOD_NO_TRACE 0x00000000
/**
* trace module for generic functions
*/
#define FLOM_TRACE_MOD_GENERIC 0x00000001
/**
* trace module for config functions
*/
#define FLOM_TRACE_MOD_CONFIG 0x00000002
/**
* trace module for fork & exec functions
*/
#define FLOM_TRACE_MOD_EXEC 0x00000004
/**
* trace module for client functions
*/
#define FLOM_TRACE_MOD_CLIENT 0x00000008
/**
* trace module for daemon functions
*/
#define FLOM_TRACE_MOD_DAEMON 0x00000010
/**
* trace module for conns (utility) functions
*/
#define FLOM_TRACE_MOD_CONNS 0x00000020
/**
* trace module for parser functions
*/
#define FLOM_TRACE_MOD_PARSER 0x00000040
/**
* trace module for messages functions
*/
#define FLOM_TRACE_MOD_MSG 0x00000080
/**
* trace module for locker functions
*/
#define FLOM_TRACE_MOD_LOCKER 0x00000100
/**
* trace module for rsrc (resource) functions
*/
#define FLOM_TRACE_MOD_RSRC 0x00000200
/**
* trace module for simple resource functions
*/
#define FLOM_TRACE_MOD_RESOURCE_SIMPLE 0x00000400
/**
* Status of the trace: TRUE = initialized, FALSE = uninitialized
*/
extern int flom_trace_initialized;
/**
* This is the mask retrieved from environment var FLOM_TRACE_MASK and
* determines which modules are traced
*/
extern unsigned long flom_trace_mask;
/**
* FLOM_TRACE_INIT macro is used to compile @ref flom_trace_init function
* only if _TRACE macro is defined
*/
#ifdef _TRACE
# define FLOM_TRACE_INIT flom_trace_init()
#else
# define FLOM_TRACE_INIT
#endif
/**
* FLOM_TRACE_REOPEN macro is used to compile
* @ref flom_trace_reopen function
* only if _TRACE macro is defined
*/
#ifdef _TRACE
# define FLOM_TRACE_REOPEN(a) flom_trace_reopen(a)
#else
# define FLOM_TRACE_REOPEN
#endif
/**
* FLOM_TRACE macro is used to compile trace messages only if _TRACE macro is
* defined
* trace message is printed only for modules (FLOM_TRACE_MODULE) covered by
* trace mask (FLOM_TRACE_MASK) specified as environment variable
*/
#ifdef _TRACE
# define FLOM_TRACE(a) (FLOM_TRACE_MODULE & flom_trace_mask ? \
flom_trace a : 0)
#else
# define FLOM_TRACE(a)
#endif /* _TRACE */
/**
* FLOM_TRACE_HEX_DATA macro is used to compile trace messages only if _TRACE
* macro is defined;
* trace message is printed only for modules (FLOM_TRACE_MODULE) covered by
* trace mask (FLOM_TRACE_MASK) specified as environment variable
*/
#ifdef _TRACE
# define FLOM_TRACE_HEX_DATA(a,b,c) (FLOM_TRACE_MODULE & flom_trace_mask ? \
flom_trace_hex_data(a,b,c,stderr) : 0)
#else
# define FLOM_TRACE_HEX_DATA(a,b,c)
#endif /* _TRACE */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* This method MUST be called BEFORE first log call to avoid lock
* contention in multithread environments
*/
void flom_trace_init(void);
/**
* Open a new stream for trace
* @param file_name IN name of the file must be used for trace or NULL
* for stderr
*/
void flom_trace_reopen(const char *file_name);
/**
* Send trace record to stderr
* @param fmt IN record format
* @param ... IN record data
*/
void flom_trace(const char *fmt, ...);
/**
* Dump the content of a piece of memory to a stream (hex format)
* @param prefix IN trace prefix to print before dump (it is a fixed
* prefix, not a format with values)
* @param data IN pointer to base memory
* @param size IN number of bytes to dump
* @param out_stream IN destination standard I/O stream
*/
void flom_trace_hex_data(const char *prefix, const byte_t *data,
size_t size, FILE *out_stream);
/**
* Dump the content of a piece of memory to a stream (text format)
* @param prefix IN trace prefix to print before dump (it is a fixed
* prefix, not a format with values)
* @param data IN pointer to base memory
* @param size IN number of bytes to dump
* @param out_stream IN destination standard I/O stream
*/
void flom_trace_text_data(const char *prefix, const byte_t *data,
size_t size, FILE *out_stream);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* FLOM_TRACE_H */