1 /*
2 ** Copyright (C) 2003 Meder Kydyraliev <meder@areopag.net>
3 ** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
4 **                    Ofir Arkin       <ofir@sys-security.com>
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef LOGH
23 #define LOGH
24 
25 #include "xprobe.h"
26 #include "interface.h"
27 
28 extern Interface *ui;
29 
30 class Log {
31 		string logfile;
32 		bool logopened;
33 		FILE *ofile;
34 		int open();
35 	protected:
36 		int write(const char *, ...);
37 	public:
Log()38 		Log() { logopened = false; }
~Log()39 		virtual ~Log() { if (logopened) fclose(ofile); }
Log(const char * lfile)40 		Log(const char *lfile) { set_logfile(lfile); logopened = false; }
set_logfile(const char * lfile)41 		int set_logfile(const char *lfile) {
42 			if (lfile != NULL && logopened != true) {
43 				logfile = lfile;
44 				return open();
45 			}
46 			return OK;
47 		}
48 		virtual int log(unsigned int type, const char *, ...)=0;
flush()49 		void flush() { if (logopened) fflush(ofile); }
is_opened()50 		bool is_opened() { return logopened; }
51 };
52 
53 class XML_Log: public Log {
54 		int tags_opened;
55 		int log_mod(const char *, va_list);
56 		int log_start(const char *fmt, va_list varg);
57 		int log_run(const char *fmt, va_list varg);
58 		int log_module(const char *fmt, va_list varg);
59 		int log_target(const char *fmt, va_list varg);
60 		int log_state(const char *fmt, va_list varg);
61 		int log_rtt(const char *fmt, va_list varg);
62 		int log_pscan(const char *fmt, va_list varg);
63 		int log_port_stats(char, const char *fmt, va_list varg);
64 		int log_port(const char *fmt, va_list varg);
65 		int log_guess(int, const char *, va_list);
66 		int log_other_ports(char, const char *, va_list);
write_tabs()67 		void write_tabs() { int k; for (k=0; k < tags_opened; k++) write("\t"); }
68 	public:
XML_Log()69 		XML_Log() { tags_opened=0; }
XML_Log(const char * lfile)70 		XML_Log(const char *lfile): Log(lfile) { tags_opened=0; }
~XML_Log()71 		~XML_Log() { return; }
72 		int log(unsigned int type, const char *, ...);
73 };
74 
75 #endif
76