1 /* $NetBSD: print.c,v 1.3 2021/08/14 16:14:56 christos Exp $ */
2
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 1998-2021 The OpenLDAP Foundation.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
12 *
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
16 */
17
18 #include <sys/cdefs.h>
19 __RCSID("$NetBSD: print.c,v 1.3 2021/08/14 16:14:56 christos Exp $");
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/ctype.h>
26 #include <ac/stdarg.h>
27 #include <ac/string.h>
28 #include <ac/time.h>
29
30 #include "ldap-int.h"
31
32 /*
33 * ldap log
34 */
35
ldap_log_check(LDAP * ld,int loglvl)36 static int ldap_log_check( LDAP *ld, int loglvl )
37 {
38 int errlvl;
39
40 if(ld == NULL) {
41 errlvl = ldap_debug;
42 } else {
43 errlvl = ld->ld_debug;
44 }
45
46 return errlvl & loglvl ? 1 : 0;
47 }
48
ldap_log_printf(LDAP * ld,int loglvl,const char * fmt,...)49 int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... )
50 {
51 char buf[ 1024 ];
52 va_list ap;
53
54 if ( !ldap_log_check( ld, loglvl )) {
55 return 0;
56 }
57
58 va_start( ap, fmt );
59
60 buf[sizeof(buf) - 1] = '\0';
61 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
62
63 va_end(ap);
64
65 (*ber_pvt_log_print)( buf );
66 return 1;
67 }
68