ze-filter  (ze-filter-0.8.0-develop-180218)
av-test.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 : janvier 2002
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 #include <ze-sys.h>
26 #include <libze.h>
27 #include <libml.h>
28 
29 #include <ze-filter.h>
30 
31 #include <ze-avclient.h>
32 
33 /*
34 **
35 **
36 */
37 
38 void
40  char *s;
41 {
42  smtp_reply_T r;
43 
44  if (s == NULL)
45  return;
46 
47  printf("REPLY : %s\n", s);
48  if (jc_string2reply(&r, s));
49  {
50  printf(" RCODE : %s\n", r.rcode);
51  printf(" XCODE : %s\n", r.xcode);
52  printf(" MSG : %s\n", r.msg);
53  printf(" RES : %d\n", r.result);
54  }
55  printf("\n");
56 }
57 
58 
59 /*
60 **
61 **
62 */
63 int
64 main(argc, argv)
65  int argc;
66  char **argv;
67 {
68  char out[256];
69  int res = 0;
70  char *in = "/tmp/Yaha.P";
71 
72  char question[2048];
73  char answer[2048];
74  char msg[2048];
75  int avres;
76 
77  extern int ze_logLevel;
78 
79  configure("av-test", conf_file, FALSE);
80 
81  memset(answer, 0, sizeof (answer));
82 
84  ze_logLevel = 10;
85 
86  printf("Let's begin with serious things...\n");
87  if (0) {
88  LOG_T log = LOG_INITIALIZER;
89  bool res;
90  char *spec = NULL;
91 
92  /*
93  * file
94  */
95  spec = "/tmp/singlepath.txt";
96  log_debug(&log, TRUE);
97  res = log_open(&log, spec);
98  printf("log_open : %d\n", res);
99 
100  res = log_write(&log, "Test log_write before\n");
101 
102  res = log_reopen(&log);
103  printf("log_reopen : %d\n", res);
104 
105  res = log_write(&log, "Test log_write after\n");
106  res = log_printf(&log, "Test log_printf %s\n", "Coucou");
107 
108  res = log_close(&log);
109  printf("log_close : %d\n", res);
110 
111  /*
112  * file
113  */
114  spec = "file:/tmp/logtest.txt";
115  log_debug(&log, TRUE);
116  res = log_open(&log, spec);
117  printf("log_open : %d\n", res);
118 
119  res = log_write(&log, "Test log_write before\n");
120 
121  res = log_reopen(&log);
122  printf("log_reopen : %d\n", res);
123 
124  res = log_write(&log, "Test log_write after\n");
125  res = log_printf(&log, "Test log_printf %s\n", "Coucou");
126 
127  res = log_close(&log);
128  printf("log_close : %d\n", res);
129 
130  /*
131  * udp
132  */
133  spec = "udp:10001@127.0.0.1";
134  log_debug(&log, TRUE);
135  res = log_open(&log, spec);
136  printf("log_open : %d\n", res);
137 
138  res = log_write(&log, "Test log_write before\n");
139  res = log_printf(&log, "Test log_printf %s\n", spec);
140 
141  res = log_reopen(&log);
142  printf("log_reopen : %d\n", res);
143 
144  res = log_write(&log, "Test log_write after\n");
145  res = log_printf(&log, "Test log_printf %s\n", spec);
146 
147  res = log_close(&log);
148  printf("log_close : %d\n", res);
149 
150  /*
151  * syslog
152  */
153  spec = "syslog:av-test:warning";
154  log_debug(&log, TRUE);
155  res = log_open(&log, spec);
156  printf("log_open : %d\n", res);
157 
158  res = log_write(&log, "Test log_write before\n");
159  res = log_printf(&log, "Test log_printf %s\n", spec);
160 
161  res = log_reopen(&log);
162  printf("log_reopen : %d\n", res);
163 
164  res = log_write(&log, "Test log_write after\n");
165  res = log_printf(&log, "Test log_printf %s\n", spec);
166 
167  res = log_close(&log);
168  printf("log_close : %d\n", res);
169 
170  /*
171  * syslog
172  */
173  spec = "syslog";
174  log_debug(&log, TRUE);
175  res = log_open(&log, spec);
176  printf("log_open : %d\n", res);
177 
178  res = log_write(&log, "Test log_write before\n");
179  res = log_printf(&log, "Test log_printf %s\n", spec);
180 
181  res = log_reopen(&log);
182  printf("log_reopen : %d\n", res);
183 
184  res = log_write(&log, "Test log_write after\n");
185  res = log_printf(&log, "Test log_printf %s\n", spec);
186 
187  res = log_close(&log);
188  printf("log_close : %d\n", res);
189  }
190 
191  if (0) {
192  debug_reply_msg("error:421:4.4.0:Message with error");
193  debug_reply_msg("error:550:5.7.0:Message with error");
194  debug_reply_msg("ok");
195  debug_reply_msg("tempfail");
196  debug_reply_msg("reject");
197 
198  exit(0);
199  }
200 
201  if (argc > 1)
202  strlcpy(question, argv[1], sizeof (question));
203  else
204  strlcpy(question, "allnaturalpills.info", sizeof (question));
205 
206  {
207  db_map_T bl;
208 
209  memset(&bl, 0, sizeof (bl));
210 
211  if (db_blackliste_check("URLBL", question, &bl)) {
212  printf("Found %s\n", question);
213  printf(" WEIGHT %d\n", bl.weight);
214  printf(" DATE %d\n", bl.date);
215  printf(" IP %s\n", bl.ipres);
216  printf(" MSG %s\n", bl.msg);
217  }
218  }
219 
220  exit(0);
221 
222  if (argc > 1)
223  strlcpy(question, argv[1], sizeof (question));
224  else
225  strlcpy(question, in, sizeof (question));
226 
227  memset(out, 0, sizeof (out));
228 
229  res = av_client(out, sizeof (out), msg, sizeof (msg), question);
230  printf("OUT : RES=(%d)\n", res);
231  printf("OUT : ANSWER=(%s)\n", out);
232  printf("OUT : MSG=(%s)\n", msg);
233 }
bool log_write(LOG_T *, char *)
Definition: ze-txtlog.c:329
#define LOG_INITIALIZER
Definition: ze-txtlog.h:96
time_t date
Definition: ze-dbbl.h:44
bool log_reopen(LOG_T *)
Definition: ze-txtlog.c:275
bool log_open(LOG_T *, char *)
Definition: ze-txtlog.c:146
int ze_logLevel
Definition: zeSyslog.c:34
char ipres[24]
Definition: ze-dbbl.h:45
int weight
Definition: ze-dbbl.h:43
void zeLog_SetOutput(bool, bool)
Definition: zeSyslog.c:490
#define FALSE
Definition: macros.h:160
#define strlcpy
Definition: zeString.h:32
bool db_blackliste_check(char *why, char *key, db_map_T *r)
Definition: ze-dbbl.c:190
int main(int argc, char **argv)
Definition: av-test.c:64
bool log_printf(LOG_T *, char *,...)
Definition: ze-txtlog.c:355
#define TRUE
Definition: macros.h:157
char * conf_file
Definition: ze-cf.c:38
void debug_reply_msg(char *s)
Definition: av-test.c:39
bool log_debug(LOG_T *, bool)
Definition: ze-txtlog.c:79
int configure(char *, char *, bool)
Definition: ze-cf.c:1203
char msg[256]
bool log_close(LOG_T *)
Definition: ze-txtlog.c:296
char msg[64]
Definition: ze-dbbl.h:46
int jc_string2reply(smtp_reply_T *, char *)
int msg[MAX_SCORE+2]
Definition: ze-stats.c:41
int av_client(char *, size_t, char *, size_t, char *)
Definition: ze-avclient.c:316