c8c3982b7a4836be5491ac3196954fa6a4986f44
1 /**
2 * collectd - src/email.c
3 * Copyright (C) 2006,2007 Sebastian Harl
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Author:
20 * Sebastian Harl <sh at tokkee.org>
21 **/
23 /*
24 * This plugin communicates with a spam filter, a virus scanner or similar
25 * software using a UNIX socket and a very simple protocol:
26 *
27 * e-mail type (e.g. ham, spam, virus, ...) and size
28 * e:<type>:<bytes>
29 *
30 * spam score
31 * s:<value>
32 *
33 * successful spam checks
34 * c:<type1>[,<type2>,...]
35 */
37 #include "collectd.h"
38 #include "common.h"
39 #include "plugin.h"
41 #include "configfile.h"
43 #if HAVE_LIBPTHREAD
44 # include <pthread.h>
45 #endif
47 #if HAVE_SYS_SELECT_H
48 # include <sys/select.h>
49 #endif /* HAVE_SYS_SELECT_H */
51 #if HAVE_SYS_SOCKET_H
52 # include <sys/socket.h>
53 #endif /* HAVE_SYS_SOCKET_H */
55 /* *sigh* glibc does not define UNIX_PATH_MAX in sys/un.h ... */
56 #if HAVE_LINUX_UN_H
57 # include <linux/un.h>
58 #elif HAVE_SYS_UN_H
59 # include <sys/un.h>
60 #endif /* HAVE_LINUX_UN_H | HAVE_SYS_UN_H */
62 /* some systems (e.g. Darwin) seem to not define UNIX_PATH_MAX at all */
63 #ifndef UNIX_PATH_MAX
64 # define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
65 #endif /* UNIX_PATH_MAX */
67 #if HAVE_GRP_H
68 # include <grp.h>
69 #endif /* HAVE_GRP_H */
71 #define MODULE_NAME "email"
73 /* 256 bytes ought to be enough for anybody ;-) */
74 #define BUFSIZE 256
76 #ifndef COLLECTD_SOCKET_PREFIX
77 # define COLLECTD_SOCKET_PREFIX "/tmp/.collectd-"
78 #endif /* COLLECTD_SOCKET_PREFIX */
80 #define SOCK_PATH COLLECTD_SOCKET_PREFIX"email"
81 #define MAX_CONNS 5
82 #define MAX_CONNS_LIMIT 16384
84 #define log_err(...) ERROR (MODULE_NAME": "__VA_ARGS__)
85 #define log_warn(...) WARNING (MODULE_NAME": "__VA_ARGS__)
87 /*
88 * Private data structures
89 */
90 /* linked list of email and check types */
91 typedef struct type {
92 char *name;
93 int value;
94 struct type *next;
95 } type_t;
97 typedef struct {
98 type_t *head;
99 type_t *tail;
100 } type_list_t;
102 /* collector thread control information */
103 typedef struct collector {
104 pthread_t thread;
106 /* socket descriptor of the current/last connection */
107 int socket;
108 } collector_t;
110 /* linked list of pending connections */
111 typedef struct conn {
112 /* socket to read data from */
113 int socket;
115 /* buffer to read data to */
116 char *buffer;
117 int idx; /* current write position in buffer */
118 int length; /* length of the current line, i.e. index of '\0' */
120 struct conn *next;
121 } conn_t;
123 typedef struct {
124 conn_t *head;
125 conn_t *tail;
126 } conn_list_t;
128 /*
129 * Private variables
130 */
131 /* valid configuration file keys */
132 static const char *config_keys[] =
133 {
134 "SocketGroup",
135 "SocketPerms",
136 "MaxConns"
137 };
138 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
140 static data_source_t gauge_dsrc[1] =
141 {
142 {"value", DS_TYPE_GAUGE, 0.0, NAN}
143 };
145 static data_set_t email_count_ds =
146 {
147 "email_count", 1, gauge_dsrc
148 };
150 static data_set_t email_size_ds =
151 {
152 "email_size", 1, gauge_dsrc
153 };
155 static data_set_t spam_check_ds =
156 {
157 "spam_check", 1, gauge_dsrc
158 };
160 static data_source_t spam_score_dsrc[1] =
161 {
162 {"score", DS_TYPE_GAUGE, NAN, NAN}
163 };
165 static data_set_t spam_score_ds =
166 {
167 "spam_score", 1, spam_score_dsrc
168 };
170 /* socket configuration */
171 static char *sock_group = COLLECTD_GRP_NAME;
172 static int sock_perms = S_IRWXU | S_IRWXG;
173 static int max_conns = MAX_CONNS;
175 /* state of the plugin */
176 static int disabled = 0;
178 /* thread managing "client" connections */
179 static pthread_t connector;
180 static int connector_socket;
182 /* tell the collector threads that a new connection is available */
183 static pthread_cond_t conn_available = PTHREAD_COND_INITIALIZER;
185 /* connections that are waiting to be processed */
186 static pthread_mutex_t conns_mutex = PTHREAD_MUTEX_INITIALIZER;
187 static conn_list_t conns;
189 /* tell the connector thread that a collector is available */
190 static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
192 /* collector threads */
193 static collector_t **collectors;
195 static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER;
196 static int available_collectors;
198 static pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
199 static type_list_t count;
201 static pthread_mutex_t size_mutex = PTHREAD_MUTEX_INITIALIZER;
202 static type_list_t size;
204 static pthread_mutex_t score_mutex = PTHREAD_MUTEX_INITIALIZER;
205 static double score;
206 static int score_count;
208 static pthread_mutex_t check_mutex = PTHREAD_MUTEX_INITIALIZER;
209 static type_list_t check;
211 /*
212 * Private functions
213 */
214 static int email_config (const char *key, const char *value)
215 {
216 if (0 == strcasecmp (key, "SocketGroup")) {
217 sock_group = sstrdup (value);
218 }
219 else if (0 == strcasecmp (key, "SocketPerms")) {
220 /* the user is responsible for providing reasonable values */
221 sock_perms = (int)strtol (value, NULL, 8);
222 }
223 else if (0 == strcasecmp (key, "MaxConns")) {
224 long int tmp = strtol (value, NULL, 0);
226 if (tmp < 1) {
227 fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
228 "value %li, will use default %i.\n",
229 tmp, MAX_CONNS);
230 max_conns = MAX_CONNS;
231 }
232 else if (tmp > MAX_CONNS_LIMIT) {
233 fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
234 "value %li, will use hardcoded limit %i.\n",
235 tmp, MAX_CONNS_LIMIT);
236 max_conns = MAX_CONNS_LIMIT;
237 }
238 else {
239 max_conns = (int)tmp;
240 }
241 }
242 else {
243 return -1;
244 }
245 return 0;
246 } /* static int email_config (char *, char *) */
248 /* Increment the value of the given name in the given list by incr. */
249 static void type_list_incr (type_list_t *list, char *name, int incr)
250 {
251 if (NULL == list->head) {
252 list->head = (type_t *)smalloc (sizeof (type_t));
254 list->head->name = sstrdup (name);
255 list->head->value = incr;
256 list->head->next = NULL;
258 list->tail = list->head;
259 }
260 else {
261 type_t *ptr;
263 for (ptr = list->head; NULL != ptr; ptr = ptr->next) {
264 if (0 == strcmp (name, ptr->name))
265 break;
266 }
268 if (NULL == ptr) {
269 list->tail->next = (type_t *)smalloc (sizeof (type_t));
270 list->tail = list->tail->next;
272 list->tail->name = sstrdup (name);
273 list->tail->value = incr;
274 list->tail->next = NULL;
275 }
276 else {
277 ptr->value += incr;
278 }
279 }
280 return;
281 } /* static void type_list_incr (type_list_t *, char *) */
283 /* Read a single character from the socket. If an error occurs or end-of-file
284 * is reached return '\0'. */
285 static char read_char (conn_t *src)
286 {
287 char ret = '\0';
289 fd_set fdset;
291 FD_ZERO (&fdset);
292 FD_SET (src->socket, &fdset);
294 if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
295 char errbuf[1024];
296 log_err ("select() failed: %s",
297 sstrerror (errno, errbuf, sizeof (errbuf)));
298 return '\0';
299 }
301 assert (FD_ISSET (src->socket, &fdset));
303 do {
304 ssize_t len = 0;
306 errno = 0;
307 if (0 > (len = read (src->socket, (void *)&ret, 1))) {
308 if (EINTR != errno) {
309 char errbuf[1024];
310 log_err ("read() failed: %s",
311 sstrerror (errno, errbuf, sizeof (errbuf)));
312 return '\0';
313 }
314 }
316 if (0 == len)
317 return '\0';
318 } while (EINTR == errno);
319 return ret;
320 } /* static char read_char (conn_t *) */
322 /* Read a single line (terminated by '\n') from the the socket.
323 *
324 * The return value is zero terminated and does not contain any newline
325 * characters.
326 *
327 * If an error occurs or end-of-file is reached return NULL.
328 *
329 * IMPORTANT NOTE: If there is no newline character found in BUFSIZE
330 * characters of the input stream, the line will will be ignored! By
331 * definition we should not get any longer input lines, thus this is
332 * acceptable in this case ;-) */
333 static char *read_line (conn_t *src)
334 {
335 int i = 0;
337 assert ((BUFSIZE >= src->idx) && (src->idx >= 0));
338 assert ((src->idx > src->length) || (src->length == 0));
340 if (src->length > 0) { /* remove old line */
341 src->idx -= (src->length + 1);
342 memmove (src->buffer, src->buffer + src->length + 1, src->idx);
343 src->length = 0;
344 }
346 for (i = 0; i < src->idx; ++i) {
347 if ('\n' == src->buffer[i])
348 break;
349 }
351 if (i == src->idx) {
352 fd_set fdset;
354 ssize_t len = 0;
356 FD_ZERO (&fdset);
357 FD_SET (src->socket, &fdset);
359 if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
360 char errbuf[1024];
361 log_err ("select() failed: %s",
362 sstrerror (errno, errbuf, sizeof (errbuf)));
363 return NULL;
364 }
366 assert (FD_ISSET (src->socket, &fdset));
368 do {
369 errno = 0;
370 if (0 > (len = read (src->socket,
371 (void *)(src->buffer + src->idx),
372 BUFSIZE - src->idx))) {
373 if (EINTR != errno) {
374 char errbuf[1024];
375 log_err ("read() failed: %s",
376 sstrerror (errno, errbuf, sizeof (errbuf)));
377 return NULL;
378 }
379 }
381 if (0 == len)
382 return NULL;
383 } while (EINTR == errno);
385 src->idx += len;
387 for (i = src->idx - len; i < src->idx; ++i) {
388 if ('\n' == src->buffer[i])
389 break;
390 }
392 if (i == src->idx) {
393 src->length = 0;
395 if (BUFSIZE == src->idx) { /* no space left in buffer */
396 while ('\n' != read_char (src))
397 /* ignore complete line */;
399 src->idx = 0;
400 }
401 return read_line (src);
402 }
403 }
405 src->buffer[i] = '\0';
406 src->length = i;
408 return src->buffer;
409 } /* static char *read_line (conn_t *) */
411 static void *collect (void *arg)
412 {
413 collector_t *this = (collector_t *)arg;
415 char *buffer = (char *)smalloc (BUFSIZE);
417 while (1) {
418 int loop = 1;
420 conn_t *connection;
422 pthread_mutex_lock (&conns_mutex);
424 while (NULL == conns.head) {
425 pthread_cond_wait (&conn_available, &conns_mutex);
426 }
428 connection = conns.head;
429 conns.head = conns.head->next;
431 if (NULL == conns.head) {
432 conns.tail = NULL;
433 }
435 this->socket = connection->socket;
437 pthread_mutex_unlock (&conns_mutex);
439 connection->buffer = buffer;
440 connection->idx = 0;
441 connection->length = 0;
443 { /* put the socket in non-blocking mode */
444 int flags = 0;
446 errno = 0;
447 if (-1 == fcntl (connection->socket, F_GETFL, &flags)) {
448 char errbuf[1024];
449 log_err ("fcntl() failed: %s",
450 sstrerror (errno, errbuf, sizeof (errbuf)));
451 loop = 0;
452 }
454 errno = 0;
455 if (-1 == fcntl (connection->socket, F_SETFL, flags | O_NONBLOCK)) {
456 char errbuf[1024];
457 log_err ("fcntl() failed: %s",
458 sstrerror (errno, errbuf, sizeof (errbuf)));
459 loop = 0;
460 }
461 }
463 while (loop) {
464 char *line = read_line (connection);
466 if (NULL == line) {
467 loop = 0;
468 break;
469 }
471 if (':' != line[1]) {
472 log_err ("syntax error in line '%s'", line);
473 continue;
474 }
476 if ('e' == line[0]) { /* e:<type>:<bytes> */
477 char *ptr = NULL;
478 char *type = strtok_r (line + 2, ":", &ptr);
479 char *tmp = strtok_r (NULL, ":", &ptr);
480 int bytes = 0;
482 if (NULL == tmp) {
483 log_err ("syntax error in line '%s'", line);
484 continue;
485 }
487 bytes = atoi (tmp);
489 pthread_mutex_lock (&count_mutex);
490 type_list_incr (&count, type, 1);
491 pthread_mutex_unlock (&count_mutex);
493 if (bytes > 0) {
494 pthread_mutex_lock (&size_mutex);
495 type_list_incr (&size, type, bytes);
496 pthread_mutex_unlock (&size_mutex);
497 }
498 }
499 else if ('s' == line[0]) { /* s:<value> */
500 pthread_mutex_lock (&score_mutex);
501 score = (score * (double)score_count + atof (line + 2))
502 / (double)(score_count + 1);
503 ++score_count;
504 pthread_mutex_unlock (&score_mutex);
505 }
506 else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
507 char *ptr = NULL;
508 char *type = strtok_r (line + 2, ",", &ptr);
510 do {
511 pthread_mutex_lock (&check_mutex);
512 type_list_incr (&check, type, 1);
513 pthread_mutex_unlock (&check_mutex);
514 } while (NULL != (type = strtok_r (NULL, ",", &ptr)));
515 }
516 else {
517 log_err ("unknown type '%c'", line[0]);
518 }
519 } /* while (loop) */
521 close (connection->socket);
523 free (connection);
525 pthread_mutex_lock (&available_mutex);
526 ++available_collectors;
527 pthread_mutex_unlock (&available_mutex);
529 pthread_cond_signal (&collector_available);
530 } /* while (1) */
532 free (buffer);
533 pthread_exit ((void *)0);
534 } /* static void *collect (void *) */
536 static void *open_connection (void *arg)
537 {
538 struct sockaddr_un addr;
540 /* create UNIX socket */
541 errno = 0;
542 if (-1 == (connector_socket = socket (PF_UNIX, SOCK_STREAM, 0))) {
543 char errbuf[1024];
544 disabled = 1;
545 log_err ("socket() failed: %s",
546 sstrerror (errno, errbuf, sizeof (errbuf)));
547 pthread_exit ((void *)1);
548 }
550 addr.sun_family = AF_UNIX;
552 strncpy (addr.sun_path, SOCK_PATH, (size_t)(UNIX_PATH_MAX - 1));
553 addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
554 unlink (addr.sun_path);
556 errno = 0;
557 if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
558 offsetof (struct sockaddr_un, sun_path)
559 + strlen(addr.sun_path))) {
560 char errbuf[1024];
561 disabled = 1;
562 log_err ("bind() failed: %s",
563 sstrerror (errno, errbuf, sizeof (errbuf)));
564 pthread_exit ((void *)1);
565 }
567 errno = 0;
568 if (-1 == listen (connector_socket, 5)) {
569 char errbuf[1024];
570 disabled = 1;
571 log_err ("listen() failed: %s",
572 sstrerror (errno, errbuf, sizeof (errbuf)));
573 pthread_exit ((void *)1);
574 }
576 if ((uid_t) 0 == geteuid ())
577 {
578 struct group sg;
579 struct group *grp;
580 char grbuf[2048];
581 int status;
583 grp = NULL;
584 status = getgrnam_r (sock_group, &sg, grbuf, sizeof (grbuf), &grp);
585 if (status != 0)
586 {
587 char errbuf[1024];
588 log_warn ("getgrnam_r (%s) failed: %s", sock_group,
589 sstrerror (errno, errbuf, sizeof (errbuf)));
590 }
591 else if (grp == NULL)
592 {
593 log_warn ("No such group: `%s'", sock_group);
594 }
595 else
596 {
597 status = chown (SOCK_PATH, (uid_t) -1, grp->gr_gid);
598 if (status != 0)
599 {
600 char errbuf[1024];
601 log_warn ("chown (%s, -1, %i) failed: %s",
602 SOCK_PATH, (int) grp->gr_gid,
603 sstrerror (errno, errbuf, sizeof (errbuf)));
604 }
605 }
606 }
607 else /* geteuid != 0 */
608 {
609 log_warn ("not running as root");
610 }
612 errno = 0;
613 if (0 != chmod (SOCK_PATH, sock_perms)) {
614 char errbuf[1024];
615 log_warn ("chmod() failed: %s",
616 sstrerror (errno, errbuf, sizeof (errbuf)));
617 }
619 { /* initialize collector threads */
620 int i = 0;
621 int err = 0;
623 pthread_attr_t ptattr;
625 conns.head = NULL;
626 conns.tail = NULL;
628 pthread_attr_init (&ptattr);
629 pthread_attr_setdetachstate (&ptattr, PTHREAD_CREATE_DETACHED);
631 available_collectors = max_conns;
633 collectors =
634 (collector_t **)smalloc (max_conns * sizeof (collector_t *));
636 for (i = 0; i < max_conns; ++i) {
637 collectors[i] = (collector_t *)smalloc (sizeof (collector_t));
638 collectors[i]->socket = 0;
640 if (0 != (err = pthread_create (&collectors[i]->thread, &ptattr,
641 collect, collectors[i]))) {
642 char errbuf[1024];
643 log_err ("pthread_create() failed: %s",
644 sstrerror (errno, errbuf, sizeof (errbuf)));
645 }
646 }
648 pthread_attr_destroy (&ptattr);
649 }
651 while (1) {
652 int remote = 0;
654 conn_t *connection;
656 pthread_mutex_lock (&available_mutex);
658 while (0 == available_collectors) {
659 pthread_cond_wait (&collector_available, &available_mutex);
660 }
662 --available_collectors;
664 pthread_mutex_unlock (&available_mutex);
666 do {
667 errno = 0;
668 if (-1 == (remote = accept (connector_socket, NULL, NULL))) {
669 if (EINTR != errno) {
670 char errbuf[1024];
671 disabled = 1;
672 log_err ("accept() failed: %s",
673 sstrerror (errno, errbuf, sizeof (errbuf)));
674 pthread_exit ((void *)1);
675 }
676 }
677 } while (EINTR == errno);
679 connection = (conn_t *)smalloc (sizeof (conn_t));
681 connection->socket = remote;
682 connection->next = NULL;
684 pthread_mutex_lock (&conns_mutex);
686 if (NULL == conns.head) {
687 conns.head = connection;
688 conns.tail = connection;
689 }
690 else {
691 conns.tail->next = connection;
692 conns.tail = conns.tail->next;
693 }
695 pthread_mutex_unlock (&conns_mutex);
697 pthread_cond_signal (&conn_available);
698 }
699 pthread_exit ((void *)0);
700 } /* static void *open_connection (void *) */
702 static int email_init (void)
703 {
704 int err = 0;
706 if (0 != (err = pthread_create (&connector, NULL,
707 open_connection, NULL))) {
708 char errbuf[1024];
709 disabled = 1;
710 log_err ("pthread_create() failed: %s",
711 sstrerror (errno, errbuf, sizeof (errbuf)));
712 return (-1);
713 }
715 return (0);
716 } /* int email_init */
718 static int email_shutdown (void)
719 {
720 int i = 0;
722 if (disabled)
723 return (0);
725 pthread_kill (connector, SIGTERM);
726 close (connector_socket);
728 /* don't allow any more connections to be processed */
729 pthread_mutex_lock (&conns_mutex);
731 for (i = 0; i < max_conns; ++i) {
732 pthread_kill (collectors[i]->thread, SIGTERM);
733 close (collectors[i]->socket);
734 }
736 pthread_mutex_unlock (&conns_mutex);
738 unlink (SOCK_PATH);
740 return (0);
741 } /* static void email_shutdown (void) */
743 static void email_submit (const char *type, const char *type_instance, gauge_t value)
744 {
745 value_t values[1];
746 value_list_t vl = VALUE_LIST_INIT;
748 values[0].gauge = value;
750 vl.values = values;
751 vl.values_len = 1;
752 vl.time = time (NULL);
753 strcpy (vl.host, hostname_g);
754 strcpy (vl.plugin, "email");
755 strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
757 plugin_dispatch_values (type, &vl);
758 } /* void email_submit */
760 /* Copy list l1 to list l2. l2 may partly exist already, but it is assumed
761 * that neither the order nor the name of any element of either list is
762 * changed and no elements are deleted. The values of l1 are reset to zero
763 * after they have been copied to l2. */
764 static void copy_type_list (type_list_t *l1, type_list_t *l2)
765 {
766 type_t *ptr1;
767 type_t *ptr2;
769 type_t *last = NULL;
771 for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1;
772 ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) {
773 if (NULL == ptr2) {
774 ptr2 = (type_t *)smalloc (sizeof (type_t));
775 ptr2->name = NULL;
776 ptr2->next = NULL;
778 if (NULL == last) {
779 l2->head = ptr2;
780 }
781 else {
782 last->next = ptr2;
783 }
785 l2->tail = ptr2;
786 }
788 if (NULL == ptr2->name) {
789 ptr2->name = sstrdup (ptr1->name);
790 }
792 ptr2->value = ptr1->value;
793 ptr1->value = 0;
794 }
795 return;
796 }
798 static int email_read (void)
799 {
800 type_t *ptr;
802 double sc;
804 static type_list_t *cnt;
805 static type_list_t *sz;
806 static type_list_t *chk;
808 if (disabled)
809 return (-1);
811 if (NULL == cnt) {
812 cnt = (type_list_t *)smalloc (sizeof (type_list_t));
813 cnt->head = NULL;
814 }
816 if (NULL == sz) {
817 sz = (type_list_t *)smalloc (sizeof (type_list_t));
818 sz->head = NULL;
819 }
821 if (NULL == chk) {
822 chk = (type_list_t *)smalloc (sizeof (type_list_t));
823 chk->head = NULL;
824 }
826 /* email count */
827 pthread_mutex_lock (&count_mutex);
829 copy_type_list (&count, cnt);
831 pthread_mutex_unlock (&count_mutex);
833 for (ptr = cnt->head; NULL != ptr; ptr = ptr->next) {
834 email_submit ("email_count", ptr->name, ptr->value);
835 }
837 /* email size */
838 pthread_mutex_lock (&size_mutex);
840 copy_type_list (&size, sz);
842 pthread_mutex_unlock (&size_mutex);
844 for (ptr = sz->head; NULL != ptr; ptr = ptr->next) {
845 email_submit ("email_size", ptr->name, ptr->value);
846 }
848 /* spam score */
849 pthread_mutex_lock (&score_mutex);
851 sc = score;
852 score = 0.0;
853 score_count = 0;
855 pthread_mutex_unlock (&score_mutex);
857 email_submit ("spam_score", "", sc);
859 /* spam checks */
860 pthread_mutex_lock (&check_mutex);
862 copy_type_list (&check, chk);
864 pthread_mutex_unlock (&check_mutex);
866 for (ptr = chk->head; NULL != ptr; ptr = ptr->next)
867 email_submit ("spam_check", ptr->name, ptr->value);
869 return (0);
870 } /* int email_read */
872 void module_register (void)
873 {
874 plugin_register_data_set (&email_count_ds);
875 plugin_register_data_set (&email_size_ds);
876 plugin_register_data_set (&spam_check_ds);
877 plugin_register_data_set (&spam_score_ds);
879 plugin_register_config ("email", email_config, config_keys, config_keys_num);
880 plugin_register_init ("email", email_init);
881 plugin_register_read ("email", email_read);
882 plugin_register_shutdown ("email", email_shutdown);
883 } /* void module_register (void) */
885 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */