smbXcli: rebuild smb1.recv_iov array if we expect more than one response
[Samba/gebeck_regimport.git] / source3 / utils / debug2html.c
blob26096c9de4eb4f115374e154828847c9f4ecfdfd
1 /* ========================================================================== **
2 * debug2html.c
4 * Copyright (C) 1998 by Christopher R. Hertel
6 * Email: crh@ubiqx.mn.org
8 * -------------------------------------------------------------------------- **
9 * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
10 * -------------------------------------------------------------------------- **
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 * -------------------------------------------------------------------------- **
26 * This program provides an example of the use of debugparse.c, and also
27 * does a decent job of converting Samba logs into HTML.
28 * -------------------------------------------------------------------------- **
30 * Revision 1.4 1998/11/13 03:37:01 tridge
31 * fixes for OSF1 compilation
33 * Revision 1.3 1998/10/28 20:33:35 crh
34 * I've moved the debugparse module files into the ubiqx directory because I
35 * know that 'make proto' will ignore them there. The debugparse.h header
36 * file is included in includes.h, and includes.h is included in debugparse.c,
37 * so all of the pieces "see" each other. I've compiled and tested this,
38 * and it does seem to work. It's the same compromise model I used when
39 * adding the ubiqx modules into the system, which is why I put it all into
40 * the same directory.
42 * Chris -)-----
44 * Revision 1.1 1998/10/26 23:21:37 crh
45 * Here is the simple debug parser and the debug2html converter. Still to do:
47 * * Debug message filtering.
48 * * I need to add all this to Makefile.in
49 * (If it looks at all strange I'll ask for help.)
51 * If you want to compile debug2html, you'll need to do it by hand until I
52 * make the changes to Makefile.in. Sorry.
54 * Chris -)-----
56 * ========================================================================== **
59 #include "debugparse.h"
61 /* -------------------------------------------------------------------------- **
62 * The size of the read buffer.
65 #define DBG_BSIZE 1024
67 /* -------------------------------------------------------------------------- **
68 * Functions...
71 static dbg_Token modechange( dbg_Token newmode, dbg_Token mode )
72 /* ------------------------------------------------------------------------ **
73 * Handle a switch between header and message printing.
75 * Input: new - The token value of the current token. This indicates
76 * the lexical item currently being recognized.
77 * mode - The current mode. This is either dbg_null or
78 * dbg_message. It could really be any toggle
79 * (true/false, etc.)
81 * Output: The new mode. This will be the same as the input mode unless
82 * there was a transition in or out of message processing.
84 * Notes: The purpose of the mode value is to mark the beginning and end
85 * of the message text block. In order to show the text in its
86 * correct format, it must be included within a <PRE></PRE> block.
88 * ------------------------------------------------------------------------ **
91 switch( newmode )
93 case dbg_null:
94 case dbg_ignore:
95 return( mode );
96 case dbg_message:
97 if( dbg_message != mode )
99 /* Switching to message mode. */
100 (void)printf( "<PRE>\n" );
101 return( dbg_message );
103 break;
104 default:
105 if( dbg_message == mode )
107 /* Switching out of message mode. */
108 (void)printf( "</PRE>\n\n" );
109 return( dbg_null );
113 return( mode );
114 } /* modechange */
116 static void newblock( dbg_Token old, dbg_Token newtok )
117 /* ------------------------------------------------------------------------ **
118 * Handle the transition between tokens.
120 * Input: old - The previous token.
121 * new - The current token.
123 * Output: none.
125 * Notes: This is called whenever there is a transition from one token
126 * type to another. It first prints the markup tags that close
127 * the previous token, and then the markup tags for the new
128 * token.
130 * ------------------------------------------------------------------------ **
133 switch( old )
135 case dbg_timestamp:
136 (void)printf( ",</B>" );
137 break;
138 case dbg_level:
139 (void)printf( "</FONT>]</B>\n " );
140 break;
141 case dbg_sourcefile:
142 (void)printf( ":" );
143 break;
144 case dbg_lineno:
145 (void)printf( ")" );
146 break;
147 default:
148 break;
151 switch( newtok )
153 case dbg_timestamp:
154 (void)printf( "<B>[" );
155 break;
156 case dbg_level:
157 (void)printf( " <B><FONT COLOR=MAROON>" );
158 break;
159 case dbg_lineno:
160 (void)printf( "(" );
161 break;
162 default:
163 break;
165 } /* newblock */
167 static void charprint( dbg_Token tok, int c )
168 /* ------------------------------------------------------------------------ **
169 * Filter the input characters to determine what goes to output.
171 * Input: tok - The token value of the current character.
172 * c - The current character.
174 * Output: none.
176 * ------------------------------------------------------------------------ **
179 switch( tok )
181 case dbg_ignore:
182 case dbg_header:
183 break;
184 case dbg_null:
185 case dbg_eof:
186 (void)putchar( '\n' );
187 break;
188 default:
189 switch( c )
191 case '<':
192 (void)printf( "&lt;" );
193 break;
194 case '>':
195 (void)printf( "&gt;" );
196 break;
197 case '&':
198 (void)printf( "&amp;" );
199 break;
200 case '\"':
201 (void)printf( "&#34;" );
202 break;
203 default:
204 (void)putchar( c );
205 break;
208 } /* charprint */
210 int main( int argc, char *argv[] )
211 /* ------------------------------------------------------------------------ **
212 * This simple program scans and parses Samba debug logs, and produces HTML
213 * output.
215 * Input: argc - Currently ignored.
216 * argv - Currently ignored.
218 * Output: Always zero.
220 * Notes: The HTML output is sent to stdout.
222 * ------------------------------------------------------------------------ **
225 int i;
226 int len;
227 char bufr[DBG_BSIZE];
228 dbg_Token old = dbg_null,
229 newtok = dbg_null,
230 state = dbg_null,
231 mode = dbg_null;
233 (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
234 (void)printf( "<HTML>\n<HEAD>\n" );
235 (void)printf( " <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
237 while( (!feof( stdin ))
238 && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) )
240 for( i = 0; i < len; i++ )
242 old = newtok;
243 newtok = dbg_char2token( &state, bufr[i] );
244 if( newtok != old )
246 mode = modechange( newtok, mode );
247 newblock( old, newtok );
249 charprint( newtok, bufr[i] );
252 (void)modechange( dbg_eof, mode );
254 (void)printf( "</BODY>\n</HTML>\n" );
255 return( 0 );
256 } /* main */