Fix the mess with ldb includes.
[Samba/ekacnet.git] / source4 / lib / ldb / common / ldb_debug.c
blobf8009eb8a345403b64f85fe7985e45b5d22efe4b
1 /*
2 ldb database library
4 Copyright (C) Andrew Tridgell 2004
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
8 ** under the LGPL
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 * Name: ldb
27 * Component: ldb debug
29 * Description: functions for printing debug messages
31 * Author: Andrew Tridgell
34 #include "ldb_private.h"
37 this allows the user to choose their own debug function
39 int ldb_set_debug(struct ldb_context *ldb,
40 void (*debug)(void *context, enum ldb_debug_level level,
41 const char *fmt, va_list ap),
42 void *context)
44 ldb->debug_ops.debug = debug;
45 ldb->debug_ops.context = context;
46 return 0;
50 debug function for ldb_set_debug_stderr
52 static void ldb_debug_stderr(void *context, enum ldb_debug_level level,
53 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
54 static void ldb_debug_stderr(void *context, enum ldb_debug_level level,
55 const char *fmt, va_list ap)
57 if (level <= LDB_DEBUG_WARNING) {
58 vfprintf(stderr, fmt, ap);
63 convenience function to setup debug messages on stderr
64 messages of level LDB_DEBUG_WARNING and higher are printed
66 int ldb_set_debug_stderr(struct ldb_context *ldb)
68 return ldb_set_debug(ldb, ldb_debug_stderr, ldb);
72 log a message
74 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...)
76 va_list ap;
77 if (ldb->debug_ops.debug == NULL) {
78 ldb_set_debug_stderr(ldb);
80 va_start(ap, fmt);
81 ldb->debug_ops.debug(ldb->debug_ops.context, level, fmt, ap);
82 va_end(ap);
87 log a message, and set the ldb error string to the same message
89 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level,
90 const char *fmt, ...)
92 va_list ap;
93 char *msg;
94 va_start(ap, fmt);
95 msg = talloc_vasprintf(ldb, fmt, ap);
96 va_end(ap);
97 if (msg != NULL) {
98 ldb_set_errstring(ldb, msg);
99 ldb_debug(ldb, level, "%s", msg);
101 talloc_free(msg);