1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | Copyright (C) Andrew Tridgell 2005
|
---|
5 | Copyright (C) Jelmer Vernooij 2005
|
---|
6 |
|
---|
7 | ** NOTE! The following LGPL license applies to the tevent
|
---|
8 | ** library. This does NOT imply that all of Samba is released
|
---|
9 | ** under the LGPL
|
---|
10 |
|
---|
11 | This library is free software; you can redistribute it and/or
|
---|
12 | modify it under the terms of the GNU Lesser General Public
|
---|
13 | License as published by the Free Software Foundation; either
|
---|
14 | version 3 of the License, or (at your option) any later version.
|
---|
15 |
|
---|
16 | This library is distributed in the hope that it will be useful,
|
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | Lesser General Public License for more details.
|
---|
20 |
|
---|
21 | You should have received a copy of the GNU Lesser General Public
|
---|
22 | License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
---|
23 | */
|
---|
24 |
|
---|
25 | #include "replace.h"
|
---|
26 | #include "tevent.h"
|
---|
27 | #include "tevent_internal.h"
|
---|
28 |
|
---|
29 | /********************************************************************
|
---|
30 | * Debug wrapper functions, modeled (with lot's of code copied as is)
|
---|
31 | * after the ev debug wrapper functions
|
---|
32 | ********************************************************************/
|
---|
33 |
|
---|
34 | /*
|
---|
35 | this allows the user to choose their own debug function
|
---|
36 | */
|
---|
37 | int tevent_set_debug(struct tevent_context *ev,
|
---|
38 | void (*debug)(void *context,
|
---|
39 | enum tevent_debug_level level,
|
---|
40 | const char *fmt,
|
---|
41 | va_list ap) PRINTF_ATTRIBUTE(3,0),
|
---|
42 | void *context)
|
---|
43 | {
|
---|
44 | ev->debug_ops.debug = debug;
|
---|
45 | ev->debug_ops.context = context;
|
---|
46 | return 0;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*
|
---|
50 | debug function for ev_set_debug_stderr
|
---|
51 | */
|
---|
52 | static void tevent_debug_stderr(void *private_data,
|
---|
53 | enum tevent_debug_level level,
|
---|
54 | const char *fmt,
|
---|
55 | va_list ap) PRINTF_ATTRIBUTE(3,0);
|
---|
56 | static void tevent_debug_stderr(void *private_data,
|
---|
57 | enum tevent_debug_level level,
|
---|
58 | const char *fmt, va_list ap)
|
---|
59 | {
|
---|
60 | if (level <= TEVENT_DEBUG_WARNING) {
|
---|
61 | vfprintf(stderr, fmt, ap);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | /*
|
---|
66 | convenience function to setup debug messages on stderr
|
---|
67 | messages of level TEVENT_DEBUG_WARNING and higher are printed
|
---|
68 | */
|
---|
69 | int tevent_set_debug_stderr(struct tevent_context *ev)
|
---|
70 | {
|
---|
71 | return tevent_set_debug(ev, tevent_debug_stderr, ev);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * log a message
|
---|
76 | *
|
---|
77 | * The default debug action is to ignore debugging messages.
|
---|
78 | * This is the most appropriate action for a library.
|
---|
79 | * Applications using the library must decide where to
|
---|
80 | * redirect debugging messages
|
---|
81 | */
|
---|
82 | void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
|
---|
83 | const char *fmt, ...)
|
---|
84 | {
|
---|
85 | va_list ap;
|
---|
86 | if (!ev) {
|
---|
87 | return;
|
---|
88 | }
|
---|
89 | if (ev->debug_ops.debug == NULL) {
|
---|
90 | return;
|
---|
91 | }
|
---|
92 | va_start(ap, fmt);
|
---|
93 | ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
|
---|
94 | va_end(ap);
|
---|
95 | }
|
---|
96 |
|
---|