Back to index

openldap  2.4.31
print.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 #include "portable.h"
00017 
00018 #include <stdio.h>
00019 
00020 #include <ac/ctype.h>
00021 #include <ac/stdarg.h>
00022 #include <ac/string.h>
00023 #include <ac/time.h>
00024 
00025 #include "ldap-int.h"
00026 
00027 /*
00028  * ldap log 
00029  */
00030 
00031 static int ldap_log_check( LDAP *ld, int loglvl )
00032 {
00033        int errlvl;
00034 
00035        if(ld == NULL) {
00036               errlvl = ldap_debug;
00037        } else {
00038               errlvl = ld->ld_debug;
00039        }
00040 
00041        return errlvl & loglvl ? 1 : 0;
00042 }
00043 
00044 int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... )
00045 {
00046        char buf[ 1024 ];
00047        va_list ap;
00048 
00049        if ( !ldap_log_check( ld, loglvl )) {
00050               return 0;
00051        }
00052 
00053        va_start( ap, fmt );
00054 
00055        buf[sizeof(buf) - 1] = '\0';
00056        vsnprintf( buf, sizeof(buf)-1, fmt, ap );
00057 
00058        va_end(ap);
00059 
00060        (*ber_pvt_log_print)( buf );
00061        return 1;
00062 }