ze-filter  (ze-filter-0.8.0-develop-180218)
ze-lr-init.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 : Mon Dec 28 11:16:21 CET 2009
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 <libze.h>
28 #include <libml.h>
29 #include <ze-filter.h>
30 #include <ze-lr-init.h>
31 
32 
33 /* ****************************************************************************
34  * *
35  * *
36  ******************************************************************************/
37 
39 
40 static void *lr_initialize(void *);
41 
42 /* ****************************************************************************
43  * *
44  * *
45  ******************************************************************************/
46 
47 bool
48 lr_data_load(background)
49  bool background;
50 {
51  if (background) {
52  pthread_t tid;
53  int r;
54 
55  if ((r = pthread_create(&tid, NULL, lr_initialize, (void *) TRUE)) != 0) {
56  ZE_LogSysError("Error launching lr_initialize_task");
57  return FALSE;
58  }
59  } else
60  lr_initialize(FALSE);
61 
62  return TRUE;
63 }
64 
65 
66 
67 /* ****************************************************************************
68  * *
69  * *
70  ******************************************************************************/
71 static void *
72 lr_initialize(arg)
73  void *arg;
74 {
75  char path[1024];
76  char *lrname = "ze-lr.txt";
77  char *cdb_dir = NULL;
78 
79  {
80  bool is_thread = (arg != NULL);
81 
82  if (is_thread) {
83  pthread_t tid;
84 
85  tid = pthread_self();
86  (void) pthread_detach(tid);
87  }
88  }
89 
90  cdb_dir = cf_get_str(CF_CDBDIR);
91  cdb_dir = STREMPTY(cdb_dir, ZE_CDBDIR);
92  memset(path, 0, sizeof (path));
93 
94  ADJUST_FILENAME(path, lrname, cdb_dir, "ze-lr.txt");
95 
97  ZE_MessageInfo(9, "Opening perceptron data file : %s", path);
98  (void) lr_data_close();
99  if (lr_data_open(path)) {
100  ZE_MessageInfo(9, "Perceptron data file : %s : OK !", path);
101  lr_filter_ok = TRUE;
102  } else
103  ZE_MessageWarning(9, "Couldn't open perceptron data file : %s", path);
104 
105  return NULL;
106 }
bool lr_data_open(char *fname)
Definition: ze-lr-funcs.c:247
#define CF_CDBDIR
Definition: cfh-defs.h:78
#define ZE_CDBDIR
Definition: defs.h:34
bool lr_data_close()
Definition: ze-lr-funcs.c:350
#define FALSE
Definition: macros.h:160
#define ADJUST_FILENAME(path, fname, cfdir, defval)
Definition: macros.h:236
bool lr_filter_ok
Definition: ze-lr-init.c:38
#define ZE_MessageInfo(level,...)
Definition: zeSyslog.h:90
#define TRUE
Definition: macros.h:157
#define ZE_MessageWarning(level,...)
Definition: zeSyslog.h:92
bool lr_data_load(bool background)
Definition: ze-lr-init.c:48
#define ZE_LogSysError(...)
Definition: zeSyslog.h:129
char * cf_get_str(int id)
Definition: ze-cf.c:854
#define STREMPTY(x, r)
Definition: macros.h:82