]> git.sur5r.net Git - openldap/blob - libraries/libldap/print.c
Validate outvalue after session param.
[openldap] / libraries / libldap / print.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #include "portable.h"
7
8 #include <stdio.h>
9
10 #include <ac/ctype.h>
11 #include <ac/stdarg.h>
12 #include <ac/string.h>
13 #include <ac/time.h>
14
15 #include "ldap-int.h"
16
17 /*
18  * ldap log 
19  */
20
21 static int ldap_log_check( LDAP *ld, int loglvl )
22 {
23         int errlvl;
24
25         if(ld == NULL) {
26                 errlvl = ldap_debug;
27         } else {
28                 errlvl = ld->ld_errno;
29         }
30
31         return errlvl & loglvl ? 1 : 0;
32 }
33
34 int ldap_log_printf
35 #ifdef HAVE_STDARG
36         ( LDAP *ld, int loglvl, const char *fmt, ... )
37 #else
38         ( va_alist )
39 va_dcl
40 #endif
41 {
42         char buf[ 1024 ];
43         va_list ap;
44
45 #ifdef HAVE_STDARG
46         va_start( ap, fmt );
47 #else
48         LDAP *ld;
49         int loglvl;
50         char *fmt;
51
52         va_start( ap );
53
54         ld = va_arg( ap, LDAP * );
55         loglvl = va_arg( ap, int );
56         fmt = va_arg( ap, char * );
57 #endif
58
59         if ( !ldap_log_check( ld, loglvl )) {
60                 return 0;
61         }
62
63 #ifdef HAVE_VSNPRINTF
64         buf[sizeof(buf) - 1] = '\0';
65         vsnprintf( buf, sizeof(buf)-1, fmt, ap );
66 #elif HAVE_VSPRINTF
67         vsprintf( buf, fmt, ap ); /* hope it's not too long */
68 #else
69         /* use doprnt() */
70         chokeme = "choke me! I don't have a doprnt manual handy!";
71 #endif
72
73         va_end(ap);
74
75         (*ber_pvt_log_print)( buf );
76         return 1;
77 }