2004-05-06 13:55:05 +04:00
/*
ldb database library
Copyright ( C ) Andrew Tridgell 2004
* * NOTE ! The following LGPL license applies to the ldb
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
2007-07-10 06:46:15 +04:00
version 3 of the License , or ( at your option ) any later version .
2004-05-06 13:55:05 +04:00
This library 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
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
2007-07-10 07:42:26 +04:00
License along with this library ; if not , see < http : //www.gnu.org/licenses/>.
2004-05-06 13:55:05 +04:00
*/
/*
* Name : ldb
*
* Component : ldb debug
*
* Description : functions for printing debug messages
*
* Author : Andrew Tridgell
*/
2009-01-30 02:39:30 +03:00
# include "ldb_private.h"
2004-05-06 13:55:05 +04:00
/*
this allows the user to choose their own debug function
*/
int ldb_set_debug ( struct ldb_context * ldb ,
void ( * debug ) ( void * context , enum ldb_debug_level level ,
const char * fmt , va_list ap ) ,
void * context )
{
ldb - > debug_ops . debug = debug ;
ldb - > debug_ops . context = context ;
return 0 ;
}
/*
debug function for ldb_set_debug_stderr
*/
2004-08-25 11:15:21 +04:00
static void ldb_debug_stderr ( void * context , enum ldb_debug_level level ,
const char * fmt , va_list ap ) PRINTF_ATTRIBUTE ( 3 , 0 ) ;
2004-05-06 13:55:05 +04:00
static void ldb_debug_stderr ( void * context , enum ldb_debug_level level ,
const char * fmt , va_list ap )
{
if ( level < = LDB_DEBUG_WARNING ) {
vfprintf ( stderr , fmt , ap ) ;
2009-07-11 00:44:27 +04:00
fprintf ( stderr , " \n " ) ;
2004-05-06 13:55:05 +04:00
}
}
2009-09-22 02:24:14 +04:00
static void ldb_debug_stderr_all ( void * context , enum ldb_debug_level level ,
const char * fmt , va_list ap ) PRINTF_ATTRIBUTE ( 3 , 0 ) ;
static void ldb_debug_stderr_all ( void * context , enum ldb_debug_level level ,
const char * fmt , va_list ap )
{
vfprintf ( stderr , fmt , ap ) ;
fprintf ( stderr , " \n " ) ;
}
2004-05-06 13:55:05 +04:00
/*
convenience function to setup debug messages on stderr
messages of level LDB_DEBUG_WARNING and higher are printed
*/
int ldb_set_debug_stderr ( struct ldb_context * ldb )
{
return ldb_set_debug ( ldb , ldb_debug_stderr , ldb ) ;
}
/*
2012-08-09 13:40:45 +04:00
log a message ( va_list helper for ldb_tevent_debug )
2004-05-06 13:55:05 +04:00
*/
2012-08-09 13:40:45 +04:00
void ldb_vdebug ( struct ldb_context * ldb , enum ldb_debug_level level , const char * fmt , va_list ap )
2004-05-06 13:55:05 +04:00
{
if ( ldb - > debug_ops . debug = = NULL ) {
2009-09-22 02:24:14 +04:00
if ( ldb - > flags & LDB_FLG_ENABLE_TRACING ) {
ldb_set_debug ( ldb , ldb_debug_stderr_all , ldb ) ;
} else {
ldb_set_debug_stderr ( ldb ) ;
}
2004-05-06 13:55:05 +04:00
}
ldb - > debug_ops . debug ( ldb - > debug_ops . context , level , fmt , ap ) ;
2012-08-09 13:40:45 +04:00
}
/*
log a message
*/
void ldb_debug ( struct ldb_context * ldb , enum ldb_debug_level level , const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
ldb_vdebug ( ldb , level , fmt , ap ) ;
2004-05-06 13:55:05 +04:00
va_end ( ap ) ;
}
2009-09-22 04:52:21 +04:00
/*
add to an accumulated log message
*/
void ldb_debug_add ( struct ldb_context * ldb , const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
if ( ldb - > partial_debug = = NULL ) {
ldb - > partial_debug = talloc_vasprintf ( ldb , fmt , ap ) ;
} else {
ldb - > partial_debug = talloc_vasprintf_append ( ldb - > partial_debug ,
fmt , ap ) ;
}
va_end ( ap ) ;
}
/*
send the accumulated log message , and free it
*/
void ldb_debug_end ( struct ldb_context * ldb , enum ldb_debug_level level )
{
ldb_debug ( ldb , level , " %s " , ldb - > partial_debug ) ;
talloc_free ( ldb - > partial_debug ) ;
ldb - > partial_debug = NULL ;
}
2005-10-12 10:10:23 +04:00
/*
log a message , and set the ldb error string to the same message
*/
void ldb_debug_set ( struct ldb_context * ldb , enum ldb_debug_level level ,
const char * fmt , . . . )
{
va_list ap ;
char * msg ;
va_start ( ap , fmt ) ;
msg = talloc_vasprintf ( ldb , fmt , ap ) ;
va_end ( ap ) ;
if ( msg ! = NULL ) {
2006-02-22 08:21:43 +03:00
ldb_set_errstring ( ldb , msg ) ;
2005-10-12 10:10:23 +04:00
ldb_debug ( ldb , level , " %s " , msg ) ;
}
2006-08-13 11:33:57 +04:00
talloc_free ( msg ) ;
2005-10-12 10:10:23 +04:00
}