lib: Fix CID 1306765 Unchecked return value from library
[samba.git] / lib / util / debug.h
index c61fd13165a468320fe3e931498ed340c1c1eb36..8d8f43d417f3985b646f4cf96ea8adb4f98dccff 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef _DEBUG_H
-#define _DEBUG_H
+#ifndef _SAMBA_DEBUG_H
+#define _SAMBA_DEBUG_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "attr.h"
+
 
 /* -------------------------------------------------------------------------- **
  * Debugging code.  See also debug.c
@@ -36,7 +42,7 @@
 #define MAX_DEBUG_LEVEL 1000
 #endif
 
-int  Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
+bool dbgtext_va(const char *, va_list ap) PRINTF_ATTRIBUTE(1,0);
 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
 bool dbghdrclass( int level, int cls, const char *location, const char *func);
 bool dbghdr( int level, const char *location, const char *func);
@@ -80,9 +86,11 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_DMAPI             18
 #define DBGC_REGISTRY          19
 #define DBGC_SCAVENGER         20
+#define DBGC_DNS               21
+#define DBGC_LDB               22
 
 /* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
-#define DBGC_MAX_FIXED         20
+#define DBGC_MAX_FIXED         22
 
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
@@ -160,10 +168,17 @@ extern int  *DEBUGLEVEL_CLASS;
   ( ((level) <= MAX_DEBUG_LEVEL) && \
     unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
 
+#define CHECK_DEBUGLVLC( dbgc_class, level ) \
+  ( ((level) <= MAX_DEBUG_LEVEL) && \
+    unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
+
 #define DEBUGLVL( level ) \
   ( CHECK_DEBUGLVL(level) \
    && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
 
+#define DEBUGLVLC( dbgc_class, level ) \
+  ( CHECK_DEBUGLVLC( dbgc_class, level ) \
+   && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
 
 #define DEBUG( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
@@ -191,6 +206,21 @@ extern int  *DEBUGLEVEL_CLASS;
 #define DEBUGSEP(level)\
        DEBUG((level),("===============================================================\n"))
 
+/*
+ * Debug levels matching RFC 3164
+ */
+#define DBGLVL_ERR      0      /* error conditions */
+#define DBGLVL_WARNING  1      /* warning conditions */
+#define DBGLVL_NOTICE   3      /* normal, but significant, condition */
+#define DBGLVL_INFO     5      /* informational message */
+#define DBGLVL_DEBUG   10      /* debug-level message */
+
+#define DBG_ERR(...)           DEBUG(DBGLVL_ERR,       (__VA_ARGS__))
+#define DBG_WARNING(...)       DEBUG(DBGLVL_WARNING,   (__VA_ARGS__))
+#define DBG_NOTICE(...)        DEBUG(DBGLVL_NOTICE,    (__VA_ARGS__))
+#define DBG_INFO(...)          DEBUG(DBGLVL_INFO,      (__VA_ARGS__))
+#define DBG_DEBUG(...)         DEBUG(DBGLVL_DEBUG,     (__VA_ARGS__))
+
 /* The following definitions come from lib/debug.c  */
 
 /** Possible destinations for the debug log (in order of precedence -
@@ -198,12 +228,17 @@ extern int  *DEBUGLEVEL_CLASS;
  * for example.  This makes it easy to override for debug to stderr on
  * the command line, as the smb.conf cannot reset it back to
  * file-based logging */
-enum debug_logtype {DEBUG_DEFAULT_STDERR = 0, DEBUG_DEFAULT_STDOUT = 1, DEBUG_FILE = 2, DEBUG_STDOUT = 3, DEBUG_STDERR = 4, DEBUG_CALLBACK = 5};
+enum debug_logtype {
+       DEBUG_DEFAULT_STDERR = 0,
+       DEBUG_DEFAULT_STDOUT = 1,
+       DEBUG_FILE = 2,
+       DEBUG_STDOUT = 3,
+       DEBUG_STDERR = 4,
+       DEBUG_CALLBACK = 5
+};
 
 struct debug_settings {
        size_t max_log_size;
-       int syslog;
-       bool syslog_only;
        bool timestamp_logs;
        bool debug_prefix_timestamp;
        bool debug_hires_timestamp;
@@ -214,21 +249,20 @@ struct debug_settings {
 
 void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
 
-void debug_close_dbf(void);
 void gfree_debugsyms(void);
 int debug_add_class(const char *classname);
-int debug_lookup_classname(const char *classname);
 bool debug_parse_levels(const char *params_str);
 void debug_setup_talloc_log(void);
 void debug_set_logfile(const char *name);
-void debug_set_settings(struct debug_settings *settings);
+void debug_set_settings(struct debug_settings *settings,
+                       const char *logging_param,
+                       int syslog_level, bool syslog_only);
 bool reopen_logs_internal( void );
 void force_check_log_size( void );
 bool need_to_check_log_size( void );
 void check_log_size( void );
 void dbgflush( void );
 bool dbghdrclass(int level, int cls, const char *location, const char *func);
-bool dbghdr(int level, const char *location, const char *func);
 bool debug_get_output_is_stderr(void);
 bool debug_get_output_is_stdout(void);
 void debug_schedule_reopen_logs(void);
@@ -241,38 +275,4 @@ typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg)
  */
 void debug_set_callback(void *private_ptr, debug_callback_fn fn);
 
-/**
-  log suspicious usage - print comments and backtrace
-*/     
-_PUBLIC_ void log_suspicious_usage(const char *from, const char *info);
-
-/**
-  print suspicious usage - print comments and backtrace
-*/     
-_PUBLIC_ void print_suspicious_usage(const char* from, const char* info);
-_PUBLIC_ uint32_t get_task_id(void);
-_PUBLIC_ void log_task_id(void);
-
-/* the debug operations structure - contains function pointers to
-   various debug implementations of each operation */
-struct debug_ops {
-       /* function to log (using DEBUG) suspicious usage of data structure */
-       void (*log_suspicious_usage)(const char* from, const char* info);
-
-       /* function to log (using printf) suspicious usage of data structure.
-        * To be used in circumstances when using DEBUG would cause loop. */
-       void (*print_suspicious_usage)(const char* from, const char* info);
-
-       /* function to return process/thread id */
-       uint32_t (*get_task_id)(void);
-
-       /* function to log process/thread id */
-       void (*log_task_id)(int fd);
-};
-
-/**
-  register a set of debug handlers. 
-*/
-_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops);
-
-#endif
+#endif /* _SAMBA_DEBUG_H */