/[imapfilter]/imapfilter/log.c
ViewVC logotype

Annotation of /imapfilter/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Sun Aug 12 16:58:21 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.3: +1 -1 lines
File MIME type: text/plain
Fix bug with no filters in config file, and introduce inverted DENY filters functionality

1 lefcha 1.1 #include <stdio.h>
2     #include <stdlib.h>
3     #include <errno.h>
4     #include <string.h>
5     #include <stdarg.h>
6     #include <limits.h>
7    
8     #include "config.h"
9     #include "imapfilter.h"
10     #include "log.h"
11    
12    
13     extern int options;
14     extern account_data account;
15     static FILE *logfp; /* Points to logfile. */
16    
17    
18     /*
19     * Print message if in OPTION_DETAILS_VERBOSE mode.
20     */
21     void verbose(const char *info, ...)
22     {
23     va_list args;
24    
25     if (options & OPTION_DETAILS_VERBOSE) {
26     va_start(args, info);
27     vprintf(info, args);
28     va_end(args);
29     }
30     }
31    
32     /*
33     * Prints error message and writes it into logfile.
34     */
35     void error(const char *errmsg, ...)
36     {
37     va_list args;
38    
39     va_start(args, errmsg);
40    
41 lefcha 1.3 if (account.logfile[0]) {
42 lefcha 1.1 vfprintf(logfp, errmsg, args);
43     }
44    
45     vfprintf(stderr, errmsg, args);
46     va_end(args);
47     }
48    
49    
50     /*
51     * Opens the file to save logging information.
52     */
53     int open_logfile(void)
54     {
55 lefcha 1.3 if (!(account.logfile[0]))
56     return SUCCESS; /* Logging not enabled. */
57 lefcha 1.4
58 lefcha 1.1 #ifdef DEBUG
59     printf("debug: logfile: %s\n", account.logfile);
60     #endif
61    
62     logfp = fopen(account.logfile, "a");
63    
64     if (!logfp) {
65     fprintf(stderr, "imapfilter: opening logfile %s: %s\n",
66     account.logfile, strerror(errno));
67     return FAILURE;
68     }
69    
70     return SUCCESS;
71     }
72    
73    
74     /*
75     * Closes the logfile.
76     */
77     int close_logfile(void)
78     {
79 lefcha 1.3 if (!(account.logfile[0]))
80 lefcha 1.1 return SUCCESS;
81     else
82     return fclose(logfp);
83     }
84    
85    
86 lefcha 1.2 /*
87     * Writes information to logfile.
88     */
89 lefcha 1.1 void log_info(const char *info, ...)
90     {
91     va_list args;
92    
93 lefcha 1.3 if (account.logfile[0]) {
94 lefcha 1.1 va_start(args, info);
95     vfprintf(logfp, info, args);
96     va_end(args);
97     }
98     }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26