ze-filter  (ze-filter-0.8.0-develop-180218)
ze-txtlog.h
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 : Mon Jan 9 17:31:39 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 #ifndef __ZE_TXTLOG_H
27 
33 #define JC_LOG_NONE 0
34 #define JC_LOG_SYSLOG 1
35 #define JC_LOG_FILE 2
36 #define JC_LOG_UDP 3
37 
38 /* Format :
39 ** syslog:prefix:priority
40 ** file:/path/to/file
41 ** udp:port@address
42 */
43 
44 #define ARGVM 9
45 
46 #define LOGNAME_REGEX "^(none|syslog|file|udp):"
47 
48 typedef struct {
50  pthread_mutex_t gmutex;
51  pthread_mutex_t mutex;
53  bool init;
54  bool debug;
56  int error;
57  int nberror;
58  time_t lasterror;
60  bool open;
61  int logtype;
63  char *spec;
64  char *args;
65  int argc;
66  char *argv[ARGVM];
68  union {
69  /*
70  * syslog
71  */
72  struct {
73  int priority;
74  char *c;
75  } syslog;
76  /*
77  * file
78  */
79  struct {
80  int fd;
81  } file;
82  /*
83  * udp
84  */
85  struct {
86  int fd;
87  int port;
88  char udpSrv[64];
89  bool connect;
91  struct sockaddr_in sock;
92  } udp;
93  } log;
94 } LOG_T;
95 
96 #define LOG_INITIALIZER \
97  { \
98  SIGNATURE, \
99  PTHREAD_MUTEX_INITIALIZER, \
100  PTHREAD_MUTEX_INITIALIZER, \
101  FALSE, \
102  FALSE, \
103  0, \
104  0, \
105  (time_t ) 0, \
106  FALSE, \
107  JC_LOG_NONE, \
108  NULL, \
109  NULL, \
110  0 \
111  }
112 
113 bool log_init(LOG_T *);
114 bool log_debug(LOG_T *, bool);
115 
116 bool log_lock(LOG_T *);
117 bool log_unlock(LOG_T *);
118 
119 bool log_ready(LOG_T *);
120 bool log_open(LOG_T *, char *);
121 bool log_reopen(LOG_T *);
122 
123 bool log_close(LOG_T *);
124 
125 bool log_write(LOG_T *, char *);
126 bool log_printf(LOG_T *, char *, ...);
127 
128 int log_error(LOG_T *);
129 
130 #define log_check_and_open(log,name) \
131  (log_ready(log) || log_open(log, name))
132 
133 #define ADJUST_LOG_NAME(path, fname, dir, defval) \
134  do { \
135  char *name = NULL; \
136  name = (fname != NULL && strlen(fname) > 0) ? fname : defval; \
137  if (zeStrRegex(name, LOGNAME_REGEX, NULL, NULL, TRUE)) { \
138  strlcpy(path, name, sizeof(path)); \
139  } else { \
140  strcpy(path, ""); \
141  if (*name == '/') \
142  snprintf(path, sizeof(path), "file:%s", name); \
143  else \
144  snprintf(path, sizeof(path), "file:%s/%s", dir, name); \
145  } \
146  zeLog_MessageInfo(12, "Adjusted path is %s", path); \
147  } while (FALSE);
148 
151 #define __ZE_TXTLOG_H 1
152 #endif /* __ZE_TXTLOG_H */
bool log_write(LOG_T *, char *)
Definition: ze-txtlog.c:329
time_t lasterror
Definition: ze-txtlog.h:58
bool log_ready(LOG_T *)
Definition: ze-txtlog.c:130
int log_error(LOG_T *)
Definition: ze-txtlog.c:383
bool log_lock(LOG_T *)
Definition: ze-txtlog.c:98
bool log_reopen(LOG_T *)
Definition: ze-txtlog.c:275
bool connect
Definition: ze-txtlog.h:89
bool log_open(LOG_T *, char *)
Definition: ze-txtlog.c:146
pthread_mutex_t mutex
Definition: ze-txtlog.h:51
bool log_init(LOG_T *)
Definition: ze-txtlog.c:61
#define ARGVM
Definition: ze-txtlog.h:44
int error
Definition: ze-txtlog.h:56
int port
Definition: ze-txtlog.h:87
bool debug
Definition: ze-txtlog.h:54
bool open
Definition: ze-txtlog.h:60
uint32_t signature
Definition: ze-txtlog.h:49
bool log_unlock(LOG_T *)
Definition: ze-txtlog.c:114
pthread_mutex_t gmutex
Definition: ze-txtlog.h:50
bool init
Definition: ze-txtlog.h:53
int priority
Definition: ze-txtlog.h:73
char * c
Definition: ze-txtlog.h:74
bool log_printf(LOG_T *, char *,...)
Definition: ze-txtlog.c:355
char * spec
Definition: ze-txtlog.h:63
char * args
Definition: ze-txtlog.h:64
int fd
Definition: ze-txtlog.h:80
bool log_debug(LOG_T *, bool)
Definition: ze-txtlog.c:79
int logtype
Definition: ze-txtlog.h:61
int nberror
Definition: ze-txtlog.h:57
bool log_close(LOG_T *)
Definition: ze-txtlog.c:296
int argc
Definition: ze-txtlog.h:65
long uint32_t
Definition: ze-sys.h:489