Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

debug.c

Go to the documentation of this file.
00001 /* $Id$ */
00002 /*
00003 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include "config.h"
00022 #endif
00023 
00024 #include <syslog.h>
00025 #include <stdarg.h>
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include "debug.h"
00029 
00030 #include "snort.h"
00031 
00032 
00033 
00034 #ifdef DEBUG
00035 
00036 
00037 int debuglevel = DEBUG_ALL;
00038 char *DebugMessageFile = NULL;
00039 int DebugMessageLine = 0;
00040 
00041 int DebugThis(int level)
00042 {
00043     if (!(level & GetDebugLevel()))
00044     {
00045         return 0;
00046     }
00047     
00048     return 1;
00049 }
00050 
00051 int GetDebugLevel (void)
00052 {
00053     static int debug_init = 0;
00054     static int debug_level = 0;
00055 
00056     if(debug_init) {
00057         return debug_level;
00058     }
00059 
00060     if (getenv(DEBUG_VARIABLE))
00061         debug_level = atoi(getenv(DEBUG_VARIABLE));
00062     else
00063         debug_level = 0;
00064 
00065     debug_init = 1;
00066     return debug_level;
00067 }
00068 
00069 
00070 void DebugMessageFunc(int level, char *fmt, ...)
00071 {
00072     va_list ap;
00073     char buf[STD_BUF+1];
00074 
00075 
00076     if (!(level & GetDebugLevel()))
00077     {
00078         return;
00079     }
00080 
00081     /* filename and line number information */
00082     if (DebugMessageFile != NULL)
00083         printf("%s:%d: ", DebugMessageFile, DebugMessageLine);
00084 
00085     va_start(ap, fmt);
00086         
00087     if(pv.daemon_flag)
00088     {
00089         vsnprintf(buf, STD_BUF, fmt, ap);
00090         syslog(LOG_DAEMON | LOG_DEBUG, "%s", buf);
00091     }
00092     else
00093     {
00094         vprintf(fmt, ap);
00095     }
00096 
00097     va_end(ap);
00098 }
00099 #endif /* DEBUG */

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2