1 /* $Id$
2  *  Provides log file maintnance routines
3  *
4  *  Compiled from hpt/log & htick/log
5  *  by Stas Degteff <g@grumbler.org>, 2:5080/102@fidonet
6  *
7  *  Portions copyright (C) Matthias Tichy
8  *                         Fido:     2:2433/1245 2:2433/1247 2:2432/605.14
9  *                         Internet: mtt@tichy.de
10  *  Portions copyright (C) Max Levenkov
11  *                         Fido:     2:5000/117
12  *                         Internet: sackett@mail.ru
13  *  Portions copyright (C) Gabriel Plutzar
14  *                         Fido:     2:31/1
15  *                         Internet: gabriel@hit.priv.at
16  *
17  *  Latest version may be foind on http://husky.sourceforge.net
18  *
19  *
20  * HUSKYLIB: common defines, types and functions for HUSKY
21  *
22  * This is part of The HUSKY Fidonet Software project:
23  * see http://husky.sourceforge.net for details
24  *
25  *
26  * HUSKYLIB is free software; you can redistribute it and/or
27  * modify it under the terms of the GNU Lesser General Public
28  * License as published by the Free Software Foundation; either
29  * version 2 of the License, or (at your option) any later version.
30  *
31  * HUSKYLIB is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34  * General Public License for more details.
35  *
36  * You should have received a copy of the GNU Lesser General Public
37  * License along with this library; see file COPYING. If not, write to the
38  * Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39  *
40  * See also http://www.gnu.org, license may be found here.
41  */
42 
43 #ifndef HUSKY_LOG_H
44 #define HUSKY_LOG_H
45 
46 /* standard headers */
47 #include <stdio.h>
48 
49 /* huskylib: compiler.h */
50 #include "compiler.h"
51 
52 /* huskylib headers */
53 #include "huskyext.h"
54 
55 /***  Declarations & defines  ***********************************************/
56 
57 #define DefaultLogLevels "1234567890ABCDEF"
58 #define DefaultScreenLogLevels DefaultLogLevels
59 
60 #define LL_START        '1'      /* Program start */
61 #define LL_STOP         '1'      /* Program end */
62 #define LL_DUPE    	'2'      /* Dupecheck */
63 #define LL_DUPECHECK   LL_DUPE
64 #define LL_LINKING      '3'      /* Link messagebase */
65 #define LL_SCANNING 	'4'      /* Scan messagebase */
66 #define LL_POSTING      '5'      /* Post message */
67 #define LL_CARBON       '5'      /* Carbon operations */
68 #define LL_EXEC  	'6'      /* system() & exec() */
69 #define LL_BUNDLE	'7'      /* Bundle operations */
70 #define LL_OUTBOUND     '7'      /* Outbound operations */
71 #define LL_FLO          '7'      /* ?LO file operations */
72 #define LL_UT           '7'      /* ?UT file operations */
73 #define LL_PKT          '7'      /* PKT file operations */
74 #define LL_LINK   	'7'      /* Link operation */
75 #define LL_LINKBEGIN  LL_LINK    /* Link operations begin */
76 #define LL_LINKEND    LL_LINK    /* Link operations end */
77 #define LL_FREQ   	'7'      /* FREQ processing */
78 #define LL_ROUTE  	'7'      /* Routing */
79 #define LL_FROUTE  	'7'      /* File routing */
80 #define LL_ATTACH 	'7'      /* File attach */
81 #define LL_TIC          '7'      /* TIC file parse/create/etc. */
82 #define LL_MSGPACK    	'7'      /* Message packing */
83 #define LL_AREAFIX  	'8'      /* areafix & filefix operations */
84 #define LL_RELINK   	'8'      /* send relink message */
85 #define LL_AUTOCREATE	'8'      /* area auto cleate */
86 #define LL_CRIT    	'9'      /* Critical error: exit */
87 #define LL_FLAG         '0'      /* Create/remove/test flag */
88 #define LL_BUSY  	'0'      /* .BSY exist */
89 #define LL_LINKBUSY  LL_BUSY
90 #define LL_BSY       LL_BUSY
91 
92 #define LL_ERROR   	'A'      /* Trivial error: continue */
93 #define LL_ERR       LL_ERROR
94 #define LL_WARN    	'B'      /* Warning */
95 #define LL_WARNING   LL_WARN
96 #define LL_ALERT   	'B'      /* Alert */
97 #define LL_SECURITY	'B'      /* Security alert */
98 #define LL_INFO    	'C'      /* Information messages */
99 #define LL_STAT    	'D'      /* Statistics */
100 #define LL_SUMMARY 	'E'      /* Summary */
101 #define LL_PRG     	'F'      /* Program name */
102 #define LL_SENT  	'G'      /* Message sent */
103 #define LL_ENCODE       'H'      /* Encode file/message */
104 #define LL_DECODE       'H'      /* Decode file/message */
105 #define LL_RECODE  	'H'      /* Recoding tables (codepage translations) */
106 
107 #define LL_MSGID   	'I'      /* Generate/check MSGID */
108 #define LL_ECHOMAIL 	'J'      /* Echomail phase */
109 #define LL_FILEBOX 	'K'      /* Filebox phase/operations */
110 #define LL_BOX        LL_FILEBOX
111 #define LL_NETMAIL 	'L'      /* Netmail phase */
112 #define LL_CREAT        'M'      /* Create file */
113 #define LL_DEL     	'N'      /* Delete file */
114 #define LL_FILE    	'O'      /* Other file operations (read, write, seek, ...) */
115 #define LL_DIR     	'P'      /* Directory create/delete/etc */
116 #define LL_PATH       LL_DIR
117 #define LL_EMAIL        'Q'      /* Email parsing or construct */
118 #define LL_TRUNC   	'R'      /* Truncate file */
119 #define LL_DELETE     LL_DEL
120 #define LL_TRUNCATE   LL_TRUNC
121 #define LL_FILESENT 	'S'      /* File sent */
122 #define LL_FILETEST 	'T'      /* Test files (exist, permittions) */
123 #define LL_FILENAME  	'X'      /* Filenames construct */
124 #define LL_FUNC         'U'      /* Functions calls */
125 #define LL_LINKPASS	'Y'      /* Link messagebase pass (some phase) */
126 #define LL_SRCLINE 	'Z'      /* Source lines numbers */
127 #define LL_DEBUG        'a'      /* Debug output */
128 #define LL_DEBUGA       'a'      /* Debug output */
129 #define LL_DEBUGB       'b'      /* Debug output */
130 #define LL_DEBUGC       'c'      /* Debug output */
131 #define LL_DEBUGD       'd'      /* Debug output */
132 #define LL_DEBUGE       'e'      /* Debug output */
133 #define LL_DEBUGF       'f'      /* Debug output */
134 #define LL_DEBUGG       'g'      /* Debug output */
135 #define LL_DEBUGH       'h'      /* Debug output */
136 #define LL_DEBUGI       'i'      /* Debug output */
137 #define LL_DEBUGJ       'j'      /* Debug output */
138 #define LL_DEBUGK       'k'      /* Debug output */
139 #define LL_DEBUGL       'l'      /* Debug output */
140 #define LL_DEBUGM       'm'      /* Debug output */
141 #define LL_DEBUGN       'n'      /* Debug output */
142 #define LL_DEBUGO       'o'      /* Debug output */
143 #define LL_DEBUGP       'p'      /* Debug output */
144 #define LL_DEBUGQ       'q'      /* Debug output */
145 #define LL_DEBUGR       'r'      /* Debug output */
146 #define LL_DEBUGS       's'      /* Debug output */
147 #define LL_DEBUGT       't'      /* Debug output */
148 #define LL_DEBUGU       'u'      /* Debug output */
149 #define LL_DEBUGV       'v'      /* Debug output */
150 #define LL_DEBUGW       'w'      /* Debug output */
151 #define LL_DEBUGX       'x'      /* Debug output */
152 #define LL_DEBUGY       'y'      /* Debug output */
153 #define LL_DEBUGZ       'z'      /* Debug output */
154 #define LL_DEBUGz       'z'      /* Debug output */
155 
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159 
160 struct _log {
161    char *keysAllowed;    /*  only log-data with one of these keys will be stored */
162    char *keysPrinted;    /*  only log-data with these keys will be printed to screen */
163    char *appName;        /*  name of the application which has created this log entry */
164    FILE *logFile;        /*  in this logFile */
165    unsigned char isopen; /*  is the log-file open? */
166    unsigned int logEcho; /*  echo log to screen? */
167 };
168 
169 typedef struct _log s_log;
170 
171 HUSKYEXT void initLog(char *ext_logFileDir, int ext_logEchoToScreen, char *ext_logLevels, char *ext_screenLogLevels);
172 /*DOC
173   Input: fidoconfig variables
174   Output: none;
175   FZ: copy fidoconfig values into log processing
176 */
177 
178 HUSKYEXT void setLogDateFormat(char *_logDateFormat);
179 /*DOC
180   Input: log date format as strftime() third argument
181   Output: none;
182   FZ: copy fidoconfig value logDateFormat into log processing
183 */
184 
185 HUSKYEXT s_log *openLog(char *fileName, char *appN);
186 /*DOC
187   Input:  fileName is a valid name for a file.
188           appN contains the name of the application.
189   Output: openLog returns a pointer to an s_log struct.
190   FZ:     openLog fills the s_log struct, opens the logfile and returns the struct
191 */
192 
193 HUSKYEXT void closeLog();
194 /*DOC
195   Input:  log is a pointer to a s_log
196   Output: ./.
197   FZ:     closes the logFile and frees all mem use by log.
198 */
199 
200 HUSKYEXT void w_log(char key, char *logString, ...);
201 /*DOC
202   Input:  key is the key under which the log-entry will be stored
203           logString is the logEntry
204   Output: ./.
205   FZ:     if the key is in keysAllowed the logString will be written to the log.
206 */
207 
208 #ifdef DEBUG
209 # define w_dbglog w_log
210 #else
211 /* if your compiler supports variadic macros add its recognition here */
212 /*    vs2005 */
213 # if (_MSC_VER >= 1400)
214 #  define w_dbglog(...) ((void)0)
215 # elif (__GNUC__ >= 2)
216 #  define w_dbglog(args...) ((void)0)
217 # else
218 #  define w_dbglog(exp) ((void)0)
219 # endif
220 
221 #endif
222 
223 #ifdef __NT__
224 #include <windows.h>
225 #include <winbase.h>
226 HUSKYEXT LONG WINAPI UExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo);
227 #endif
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif
234