A while back, Andrew and I talked about making the debug parsing code a
authorChristopher R. Hertel <crh@samba.org>
Wed, 16 Dec 1998 18:50:54 +0000 (18:50 +0000)
committerChristopher R. Hertel <crh@samba.org>
Wed, 16 Dec 1998 18:50:54 +0000 (18:50 +0000)
better "fit" with other Samba code.  This is a small first step toward
doing what (I think) we agreed to do.

I've moved the key function from ubiqx/debugparse.c into lib/debug.c.  I
have also moved the enum from ubiqx/debugparse.h into the debug section in
smb.h.

The next thing to do is to get debug2html added into the Makefile.in so
that it is always produced when compiling the suite.

Chris -)-----
(This used to be commit 782474f41e0c2bc0b1f098758a3e5cb44e87d8b1)

source3/Makefile.in
source3/include/includes.h
source3/include/proto.h
source3/include/smb.h
source3/lib/debug.c
source3/script/mkproto.awk
source3/utils/debug2html.c

index 421084bff4df55794033a64ed6a716eb07587eca..bddc221a6d6cfcf3da5c0a3618671809e4f252cb 100644 (file)
@@ -109,7 +109,7 @@ LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \
 
 
 UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
-            ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o ubiqx/debugparse.o
+            ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o
 
 PARAM_OBJ = param/loadparm.o param/params.o 
 
@@ -275,8 +275,6 @@ RPCTORTURE_OBJ = utils/rpctorture.o \
              $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
                $(PASSDB_OBJ) 
 
-DEBUG2HTML_OBJ = utils/debug2html.o ubiqx/debugparse.o
-
 PROTO_OBJ = $(SMBD_OBJ) $(NMBD_OBJ) $(SWAT_OBJ) $(CLIENT_OBJ) \
            $(RPCCLIENT_OBJ) $(SMBWRAPPER_OBJ)
 
@@ -295,8 +293,6 @@ smbtorture : CHECK bin/smbtorture
 
 rpctorture : CHECK bin/rpctorture
 
-debug2html : CHECK bin/debug2html
-
 .SUFFIXES:
 .SUFFIXES: .c .o .po .po32
 
@@ -434,10 +430,6 @@ bin/rpctorture: $(RPCTORTURE_OBJ) bin/.dummy
        @echo Linking $@
        @$(CC) $(FLAGS) -o $@ $(RPCTORTURE_OBJ) $(LDFLAGS) $(LIBS)
 
-bin/debug2html: $(DEBUG2HTML_OBJ) bin/.dummy
-       @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(DEBUG2HTML_OBJ) $(LDFLAGS) $(LIBS)
-
 bin/smbwrapper.so: $(PICOBJS)
        @echo Linking shared library $@
        @$(LD) @LDSHFLAGS@ -o $@ $(PICOBJS) $(LIBS)
index 824a5bde5db1852644c10f62b5a3ea3ec1e3e9a7..a70de0b3a9648e0e7c1142f49130d0048014fca9 100644 (file)
@@ -552,8 +552,6 @@ extern int errno;
 #include "ubi_Cache.h"
 #endif /* UBI_BINTREE_H */
 
-#include "debugparse.h"
-
 #include "version.h"
 #include "smb.h"
 #include "smbw.h"
index 8d966c61771b466702f7a70ff36abf169ffb3ca0..fc1e2926a815dcc754436266329a774ee9d606b3 100644 (file)
@@ -172,6 +172,7 @@ void reopen_logs( void );
 void force_check_log_size( void );
 void dbgflush( void );
 BOOL dbghdr( int level, char *file, char *func, int line );
+dbg_Token dbg_char2token( dbg_Token *state, int c );
 
 /*The following definitions come from  lib/domain_namemap.c  */
 
index 9c699fc42315dd0fb18062b7295f3d675406860f..9cd74dd865336f73a7b62d48651f77d119f93460 100644 (file)
@@ -67,7 +67,8 @@ typedef int BOOL;
  */
 /* I know the __attribute__ stuff is ugly, but it does ensure we get the 
    arguemnts to DEBUG() right. We have got them wrong too often in the 
-   past */
+   past.
+ */
 #ifdef HAVE_STDARG_H
 int  Debug1( char *, ... )
 #ifdef __GNUC__
@@ -127,6 +128,24 @@ BOOL dbgtext();
 #define DEBUGADD( level, body ) \
   (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
 
+/* -------------------------------------------------------------------------- **
+ * These are the tokens returned by dbg_char2token().
+ */
+
+typedef enum
+  {
+  dbg_null = 0,
+  dbg_ignore,
+  dbg_header,
+  dbg_timestamp,
+  dbg_level,
+  dbg_sourcefile,
+  dbg_function,
+  dbg_lineno,
+  dbg_message,
+  dbg_eof
+  } dbg_Token;
+
 /* End Debugging code section.
  * -------------------------------------------------------------------------- **
  */
index 3a90da2f3d2a9c41d027947277cf7100e671f8ac..ab11d81a212c96c08a265ef1093113be66a09f06 100644 (file)
@@ -125,7 +125,6 @@ static int     format_pos     = 0;
  * tells us if interactive logging was requested
  * ************************************************************************** **
  */
-
 BOOL dbg_interactive(void)
 {
        return stdout_logging;
@@ -597,4 +596,163 @@ BOOL dbghdr( int level, char *file, char *func, int line )
 
 #endif
 
+dbg_Token dbg_char2token( dbg_Token *state, int c )
+  /* ************************************************************************ **
+   * Parse input one character at a time.
+   *
+   *  Input:  state - A pointer to a token variable.  This is used to
+   *                  maintain the parser state between calls.  For
+   *                  each input stream, you should set up a separate
+   *                  state variable and initialize it to dbg_null.
+   *                  Pass a pointer to it into this function with each
+   *                  character in the input stream.  See dbg_test()
+   *                  for an example.
+   *          c     - The "current" character in the input stream.
+   *
+   *  Output: A token.
+   *          The token value will change when delimiters are found,
+   *          which indicate a transition between syntactical objects.
+   *          Possible return values are:
+   *
+   *          dbg_null        - The input character was an end-of-line.
+   *                            This resets the parser to its initial state
+   *                            in preparation for parsing the next line.
+   *          dbg_eof         - Same as dbg_null, except that the character
+   *                            was an end-of-file.
+   *          dbg_ignore      - Returned for whitespace and delimiters.
+   *                            These lexical tokens are only of interest
+   *                            to the parser.
+   *          dbg_header      - Indicates the start of a header line.  The
+   *                            input character was '[' and was the first on
+   *                            the line.
+   *          dbg_timestamp   - Indicates that the input character was part
+   *                            of a header timestamp.
+   *          dbg_level       - Indicates that the input character was part
+   *                            of the debug-level value in the header.
+   *          dbg_sourcefile  - Indicates that the input character was part
+   *                            of the sourcefile name in the header.
+   *          dbg_function    - Indicates that the input character was part
+   *                            of the function name in the header.
+   *          dbg_lineno      - Indicates that the input character was part
+   *                            of the DEBUG call line number in the header.
+   *          dbg_message     - Indicates that the input character was part
+   *                            of the DEBUG message text.
+   *
+   * ************************************************************************ **
+   */
+  {
+  /* The terminating characters that we see will greatly depend upon
+   * how they are read.  For example, if gets() is used instead of
+   * fgets(), then we will not see newline characters.  A lot also
+   * depends on the calling function, which may handle terminators
+   * itself.
+   *
+   * '\n', '\0', and EOF are all considered line terminators.  The
+   * dbg_eof token is sent back if an EOF is encountered.
+   *
+   * Warning:  only allow the '\0' character to be sent if you are
+   *           using gets() to read whole lines (thus replacing '\n'
+   *           with '\0').  Sending '\0' at the wrong time will mess
+   *           up the parsing.
+   */
+  switch( c )
+    {
+    case EOF:
+      *state = dbg_null;   /* Set state to null (initial state) so */
+      return( dbg_eof );   /* that we can restart with new input.  */
+    case '\n':
+    case '\0':
+      *state = dbg_null;   /* A newline or eoln resets to the null state. */
+      return( dbg_null );
+    }
+
+  /* When within the body of the message, only a line terminator
+   * can cause a change of state.  We've already checked for line
+   * terminators, so if the current state is dbg_msgtxt, simply
+   * return that as our current token.
+   */
+  if( dbg_message == *state )
+    return( dbg_message );
+
+  /* If we are at the start of a new line, and the input character 
+   * is an opening bracket, then the line is a header line, otherwise
+   * it's a message body line.
+   */
+  if( dbg_null == *state )
+    {
+    if( '[' == c )
+      {
+      *state = dbg_timestamp;
+      return( dbg_header );
+      }
+    *state = dbg_message;
+    return( dbg_message );
+    }
+
+  /* We've taken care of terminators, text blocks and new lines.
+   * The remaining possibilities are all within the header line
+   * itself.
+   */
+
+  /* Within the header line, whitespace can be ignored *except*
+   * within the timestamp.
+   */
+  if( isspace( c ) )
+    {
+    /* Fudge.  The timestamp may contain space characters. */
+    if( (' ' == c) && (dbg_timestamp == *state) )
+      return( dbg_timestamp );
+    /* Otherwise, ignore whitespace. */
+    return( dbg_ignore );
+    }
+
+  /* Okay, at this point we know we're somewhere in the header.
+   * Valid header *states* are: dbg_timestamp, dbg_level,
+   * dbg_sourcefile, dbg_function, and dbg_lineno.
+   */
+  switch( c )
+    {
+    case ',':
+      if( dbg_timestamp == *state )
+        {
+        *state = dbg_level;
+        return( dbg_ignore );
+        }
+      break;
+    case ']':
+      if( dbg_level == *state )
+        {
+        *state = dbg_sourcefile;
+        return( dbg_ignore );
+        }
+      break;
+    case ':':
+      if( dbg_sourcefile == *state )
+        {
+        *state = dbg_function;
+        return( dbg_ignore );
+        }
+      break;
+    case '(':
+      if( dbg_function == *state )
+        {
+        *state = dbg_lineno;
+        return( dbg_ignore );
+        }
+      break;
+    case ')':
+      if( dbg_lineno == *state )
+        {
+        *state = dbg_null;
+        return( dbg_ignore );
+        }
+      break;
+    }
+
+  /* If the previous block did not result in a state change, then
+   * return the current state as the current token.
+   */
+  return( *state );
+  } /* dbg_char2token */
+
 /* ************************************************************************** */
index e54984e4e55f5763b18fdb06759d98c41cfbe8e8..3309e89a0f83bda33cc85f8a944e6637ba062ecf 100644 (file)
@@ -98,7 +98,7 @@ END {
     gotstart = 1;
   }
 
-  if( $0 ~ /^long|^char|^uint|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^enum remote_arch_types|^FILE|^SMB_OFF_T|^size_t|^ssize_t|^SMB_BIG_UINT/ ) {
+  if( $0 ~ /^long|^char|^uint|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^enum remote_arch_types|^FILE|^SMB_OFF_T|^size_t|^ssize_t|^SMB_BIG_UINT|dbg_Token/ ) {
     gotstart = 1;
   }
   if(!gotstart) {
index fa2be4133662bf276a1beec10ace71c11aeafe1a..d5d8fb872ce6320cc2330704ee777ec0ca06d363 100644 (file)
  * does a decent job of converting Samba logs into HTML.
  * -------------------------------------------------------------------------- **
  *
- * $Log: debug2html.c,v $
- * Revision 1.4  1998/11/13 03:37:01  tridge
- * fixes for OSF1 compilation
- *
- * Revision 1.3  1998/10/28 20:33:35  crh
- * I've moved the debugparse module files into the ubiqx directory because I
- * know that 'make proto' will ignore them there.  The debugparse.h header
- * file is included in includes.h, and includes.h is included in debugparse.c,
- * so all of the pieces "see" each other.  I've compiled and tested this,
- * and it does seem to work.  It's the same compromise model I used when
- * adding the ubiqx modules into the system, which is why I put it all into
- * the same directory.
- *
- * Chris -)-----
- *
- * Revision 1.1  1998/10/26 23:21:37  crh
- * Here is the simple debug parser and the debug2html converter.  Still to do:
- *
- *   * Debug message filtering.
- *   * I need to add all this to Makefile.in
- *     (If it looks at all strange I'll ask for help.)
- *
- * If you want to compile debug2html, you'll need to do it by hand until I
- * make the changes to Makefile.in.  Sorry.
- *
- * Chris -)-----
+ * $Revision: 1.5 $
  *
  * ========================================================================== **
  */
 
-#include "debugparse.h"
+#include "include.h"
 
 /* -------------------------------------------------------------------------- **
  * The size of the read buffer.