Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Copyright (C) Andrew Tridgell 2003
4 :
5 : This program is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU General Public License as published by
7 : the Free Software Foundation; either version 3 of the License, or
8 : (at your option) any later version.
9 :
10 : This program is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public License
16 : along with this program. If not, see <http://www.gnu.org/licenses/>.
17 : */
18 :
19 : #include "includes.h"
20 : #include <tevent.h>
21 :
22 : #undef DBGC_CLASS
23 : #define DBGC_CLASS DBGC_TEVENT
24 :
25 : static void samba_tevent_debug(void *context,
26 : enum tevent_debug_level level,
27 : const char *fmt,
28 : va_list ap) PRINTF_ATTRIBUTE(3,0);
29 :
30 45842691 : static void samba_tevent_debug(void *context,
31 : enum tevent_debug_level level,
32 : const char *fmt,
33 : va_list ap)
34 : {
35 45842691 : int samba_level = -1;
36 :
37 45210474 : switch (level) {
38 0 : case TEVENT_DEBUG_FATAL:
39 0 : samba_level = 0;
40 0 : break;
41 59 : case TEVENT_DEBUG_ERROR:
42 59 : samba_level = 1;
43 59 : break;
44 0 : case TEVENT_DEBUG_WARNING:
45 0 : samba_level = 2;
46 0 : break;
47 45210415 : case TEVENT_DEBUG_TRACE:
48 45210415 : samba_level = 50;
49 45210415 : break;
50 : };
51 :
52 45842691 : if (CHECK_DEBUGLVL(samba_level)) {
53 59 : const char *name = (const char *)context;
54 59 : char *message = NULL;
55 : int ret;
56 :
57 59 : ret = vasprintf(&message, fmt, ap);
58 59 : if (ret == -1) {
59 0 : return;
60 : }
61 :
62 59 : if (name == NULL) {
63 0 : name = "samba_tevent";
64 : }
65 :
66 59 : DEBUG(samba_level, ("%s: %s", name, message));
67 59 : free(message);
68 : }
69 : }
70 :
71 1606496 : void samba_tevent_set_debug(struct tevent_context *ev, const char *name)
72 : {
73 1606496 : void *p = discard_const(name);
74 1606496 : tevent_set_debug(ev, samba_tevent_debug, p);
75 1606496 : }
76 :
77 1295757 : struct tevent_context *samba_tevent_context_init(TALLOC_CTX *mem_ctx)
78 : {
79 : struct tevent_context *ev;
80 :
81 1295757 : ev = tevent_context_init(mem_ctx);
82 1295757 : if (ev) {
83 1295757 : samba_tevent_set_debug(ev, NULL);
84 : }
85 :
86 1295757 : return ev;
87 : }
|