debug.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/stdarg.h>
  18. #include <ac/stdlib.h>
  19. #include <ac/string.h>
  20. #include <ac/time.h>
  21. #include <ac/ctype.h>
  22. #ifdef LDAP_SYSLOG
  23. #include <ac/syslog.h>
  24. #endif
  25. #include "ldap_log.h"
  26. #include "ldap_defaults.h"
  27. #include "lber.h"
  28. #include "ldap_pvt.h"
  29. int lutil_debug_file( FILE *file )
  30. {
  31. ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
  32. return 0;
  33. }
  34. void (lutil_debug)( int debug, int level, const char *fmt, ... )
  35. {
  36. char buffer[4096];
  37. va_list vl;
  38. int len;
  39. if ( !(level & debug ) ) return;
  40. va_start( vl, fmt );
  41. len = vsnprintf( buffer, sizeof(buffer), fmt, vl );
  42. va_end( vl );
  43. if ( len >= sizeof(buffer)-2 )
  44. buffer[sizeof(buffer)-2] = '\n';
  45. ber_pvt_log_print( buffer );
  46. }
  47. #if defined(HAVE_EBCDIC) && defined(LDAP_SYSLOG)
  48. #undef syslog
  49. void eb_syslog( int pri, const char *fmt, ... )
  50. {
  51. char buffer[4096];
  52. va_list vl;
  53. va_start( vl, fmt );
  54. vsnprintf( buffer, sizeof(buffer), fmt, vl );
  55. buffer[sizeof(buffer)-1] = '\0';
  56. /* The syslog function appears to only work with pure EBCDIC */
  57. __atoe(buffer);
  58. #pragma convlit(suspend)
  59. syslog( pri, "%s", buffer );
  60. #pragma convlit(resume)
  61. va_end( vl );
  62. }
  63. #endif