ze-filter  (ze-filter-0.8.0-develop-180218)
ze-log-files.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : Tue Jan 17 14:47:25 CET 2006
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
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.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include <ze-filter-data.h>
29 #include <ze-log-files.h>
30 
31 
32 /* ****************************************************************************
33  * *
34  * *
35  ******************************************************************************/
36 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
37 
38 static LOG_T logt = LOG_INITIALIZER;
39 
40 /* ****************************************************************************
41  * *
42  * *
43  ******************************************************************************/
44 bool
46 {
47  bool res = TRUE;
48 
49  MUTEX_LOCK(&mutex);
50 
51  if (!log_ready(&logt)) {
52  char path[1024];
53  char *wkdir = cf_get_str(CF_WORKDIR);
54  char *logname = cf_get_str(CF_XFILES_LOG_FILE);
55 
56  ADJUST_LOG_NAME(path, logname, wkdir, "none:");
57 
58  res = log_open(&logt, path);
59  } else
60  res = log_reopen(&logt);
61 
63 
64  return res;
65 }
66 
67 /* ****************************************************************************
68  * *
69  * *
70  ******************************************************************************/
71 bool
73  char *id;
74  char *ip;
75  attachment_T *files;
76 {
77  attachment_T *p;
78  time_t t = time(NULL);
79  int r;
80 
81  char ipbuf[SZ_IP];
82 
83  bool res = TRUE;
84 
85  if (id == NULL)
86  id = "00000000.000";
87 
88  if (!log_ready(&logt) && !log_attached_files_reopen())
89  return FALSE;
90 
91  snprintf(ipbuf, sizeof (ipbuf), "%s", STRNULL(ip, "0.0.0.0"));
92 
93  MUTEX_LOCK(&mutex);
94 
95  if (log_ready(&logt)) {
96  p = files;
97  while (p != NULL) {
98  char *serror = "???";
99 
100  if ((p->name == NULL) || (strlen(p->name) == 0))
101  continue;
102 
103  serror = STRBOOL(p->xfile, "XXX", "---");
104  log_printf(&logt, "%10ld %-12s ADDR=(%s) CLASS=(%s) MIME=(%s) %s\n",
105  (long) t, id, ipbuf, serror,
106  STRNULL(p->mimetype, "mime-unknown"), p->name);
107  p = p->next;
108  }
109  }
110 
111 fin:
113 
114  return res;
115 }
#define STRBOOL(x, t, f)
Definition: macros.h:87
#define LOG_INITIALIZER
Definition: ze-txtlog.h:96
bool log_ready(LOG_T *)
Definition: ze-txtlog.c:130
bool log_reopen(LOG_T *)
Definition: ze-txtlog.c:275
#define MUTEX_UNLOCK(mutex)
Definition: macros.h:101
bool log_open(LOG_T *, char *)
Definition: ze-txtlog.c:146
#define STRNULL(x, r)
Definition: macros.h:81
#define MUTEX_LOCK(mutex)
Definition: macros.h:93
pthread_mutex_t mutex
Definition: ze-connopen.c:63
#define FALSE
Definition: macros.h:160
#define SZ_IP
Definition: ze-libjc.h:77
bool log_printf(LOG_T *, char *,...)
Definition: ze-txtlog.c:355
#define TRUE
Definition: macros.h:157
#define CF_XFILES_LOG_FILE
Definition: cfh-defs.h:96
char * cf_get_str(int id)
Definition: ze-cf.c:854
char * mimetype
Definition: ze-mimelist.h:72
bool log_attached_files(char *id, char *ip, attachment_T *files)
Definition: ze-log-files.c:72
bool log_attached_files_reopen()
Definition: ze-log-files.c:45
char * name
Definition: ze-mimelist.h:70
struct attachment_T * next
Definition: ze-mimelist.h:74
#define CF_WORKDIR
Definition: cfh-defs.h:67
#define ADJUST_LOG_NAME(path, fname, dir, defval)
Definition: ze-txtlog.h:133