print.c 1.1 KB

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