aboutsummaryrefslogtreecommitdiffstats
path: root/src/lmtp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-02 17:09:38 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-02 17:09:38 +0400
commitf3ad9c6f1e91c9912dbe730fdec350b5fc908672 (patch)
tree005e5568431db09becaa9b67a33dfc11f80bba7f /src/lmtp.c
parente6a1d22de250c10992b484635fd95a03f197f779 (diff)
downloadrspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.tar.gz
rspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.zip
* Retab, no functional changes
Diffstat (limited to 'src/lmtp.c')
-rw-r--r--src/lmtp.c193
1 files changed, 96 insertions, 97 deletions
diff --git a/src/lmtp.c b/src/lmtp.c
index 3becb1dfe..087be2e1a 100644
--- a/src/lmtp.c
+++ b/src/lmtp.c
@@ -33,19 +33,20 @@
#include "modules.h"
#include "message.h"
-static char greetingbuf[1024];
-static struct timeval io_tv;
+static char greetingbuf[1024];
+static struct timeval io_tv;
-static gboolean lmtp_write_socket (void *arg);
+static gboolean lmtp_write_socket (void *arg);
-static
-void sig_handler (int signo)
+static
+ void
+sig_handler (int signo)
{
switch (signo) {
- case SIGINT:
- case SIGTERM:
- _exit (1);
- break;
+ case SIGINT:
+ case SIGTERM:
+ _exit (1);
+ break;
}
}
@@ -55,9 +56,9 @@ void sig_handler (int signo)
static void
sigusr_handler (int fd, short what, void *arg)
{
- struct rspamd_worker *worker = (struct rspamd_worker *)arg;
+ struct rspamd_worker *worker = (struct rspamd_worker *)arg;
/* Do not accept new connections, preparing to end worker's process */
- struct timeval tv;
+ struct timeval tv;
tv.tv_sec = SOFT_SHUTDOWN_TIME;
tv.tv_usec = 0;
event_del (&worker->sig_ev);
@@ -74,7 +75,7 @@ sigusr_handler (int fd, short what, void *arg)
static void
rcpt_destruct (void *pointer)
{
- struct worker_task *task = (struct worker_task *)pointer;
+ struct worker_task *task = (struct worker_task *)pointer;
if (task->rcpt) {
g_list_free (task->rcpt);
@@ -87,8 +88,8 @@ rcpt_destruct (void *pointer)
static void
free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft)
{
- GList *part;
- struct mime_part *p;
+ GList *part;
+ struct mime_part *p;
if (lmtp) {
msg_debug ("free_lmtp_task: free pointer %p", lmtp->task);
@@ -121,47 +122,47 @@ free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft)
/*
* Callback that is called when there is data to read in buffer
*/
-static gboolean
-lmtp_read_socket (f_str_t *in, void *arg)
+static gboolean
+lmtp_read_socket (f_str_t * in, void *arg)
{
- struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
- struct worker_task *task = lmtp->task;
- ssize_t r;
+ struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
+ struct worker_task *task = lmtp->task;
+ ssize_t r;
switch (task->state) {
- case READ_COMMAND:
- case READ_HEADER:
- if (read_lmtp_input_line (lmtp, in) != 0) {
- msg_info ("read_lmtp_socket: closing lmtp connection due to protocol error");
- lmtp->task->state = CLOSING_CONNECTION;
- }
- /* Task was read, recall read handler once more with new state to process message and write reply */
- if (task->state == READ_MESSAGE) {
- lmtp_read_socket (in, arg);
- }
- break;
- case READ_MESSAGE:
- r = process_message (lmtp->task);
- r = process_filters (lmtp->task);
- if (r == -1) {
- task->last_error = "Filter processing error";
- task->error_code = LMTP_FAILURE;
- task->state = WRITE_ERROR;
- lmtp_write_socket (lmtp);
- }
- else if (r == 0) {
- task->state = WAIT_FILTER;
- rspamd_dispatcher_pause (lmtp->task->dispatcher);
- }
- else {
- process_statfiles (lmtp->task);
- task->state = WRITE_REPLY;
- lmtp_write_socket (lmtp);
- }
- break;
- default:
- msg_debug ("lmtp_read_socket: invalid state while reading from socket %d", lmtp->task->state);
- break;
+ case READ_COMMAND:
+ case READ_HEADER:
+ if (read_lmtp_input_line (lmtp, in) != 0) {
+ msg_info ("read_lmtp_socket: closing lmtp connection due to protocol error");
+ lmtp->task->state = CLOSING_CONNECTION;
+ }
+ /* Task was read, recall read handler once more with new state to process message and write reply */
+ if (task->state == READ_MESSAGE) {
+ lmtp_read_socket (in, arg);
+ }
+ break;
+ case READ_MESSAGE:
+ r = process_message (lmtp->task);
+ r = process_filters (lmtp->task);
+ if (r == -1) {
+ task->last_error = "Filter processing error";
+ task->error_code = LMTP_FAILURE;
+ task->state = WRITE_ERROR;
+ lmtp_write_socket (lmtp);
+ }
+ else if (r == 0) {
+ task->state = WAIT_FILTER;
+ rspamd_dispatcher_pause (lmtp->task->dispatcher);
+ }
+ else {
+ process_statfiles (lmtp->task);
+ task->state = WRITE_REPLY;
+ lmtp_write_socket (lmtp);
+ }
+ break;
+ default:
+ msg_debug ("lmtp_read_socket: invalid state while reading from socket %d", lmtp->task->state);
+ break;
}
return TRUE;
@@ -170,32 +171,32 @@ lmtp_read_socket (f_str_t *in, void *arg)
/*
* Callback for socket writing
*/
-static gboolean
+static gboolean
lmtp_write_socket (void *arg)
{
- struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
-
+ struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
+
switch (lmtp->task->state) {
- case WRITE_REPLY:
- if (write_lmtp_reply (lmtp) == 1) {
- lmtp->task->state = WAIT_FILTER;
- }
- else {
- lmtp->task->state = CLOSING_CONNECTION;
- }
- break;
- case WRITE_ERROR:
- write_lmtp_reply (lmtp);
+ case WRITE_REPLY:
+ if (write_lmtp_reply (lmtp) == 1) {
+ lmtp->task->state = WAIT_FILTER;
+ }
+ else {
lmtp->task->state = CLOSING_CONNECTION;
- break;
- case CLOSING_CONNECTION:
- msg_debug ("lmtp_write_socket: normally closing connection");
- free_lmtp_task (lmtp, TRUE);
- return FALSE;
- break;
- default:
- msg_debug ("lmtp_write_socket: invalid state while writing to socket %d", lmtp->task->state);
- break;
+ }
+ break;
+ case WRITE_ERROR:
+ write_lmtp_reply (lmtp);
+ lmtp->task->state = CLOSING_CONNECTION;
+ break;
+ case CLOSING_CONNECTION:
+ msg_debug ("lmtp_write_socket: normally closing connection");
+ free_lmtp_task (lmtp, TRUE);
+ return FALSE;
+ break;
+ default:
+ msg_debug ("lmtp_write_socket: invalid state while writing to socket %d", lmtp->task->state);
+ break;
}
return TRUE;
@@ -205,9 +206,9 @@ lmtp_write_socket (void *arg)
* Called if something goes wrong
*/
static void
-lmtp_err_socket (GError *err, void *arg)
+lmtp_err_socket (GError * err, void *arg)
{
- struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
+ struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg;
msg_info ("lmtp_err_socket: abnormally closing connection, error: %s", err->message);
/* Free buffers */
free_lmtp_task (lmtp, FALSE);
@@ -219,12 +220,12 @@ lmtp_err_socket (GError *err, void *arg)
static void
accept_socket (int fd, short what, void *arg)
{
- struct rspamd_worker *worker = (struct rspamd_worker *)arg;
- struct sockaddr_storage ss;
- struct worker_task *new_task;
- struct rspamd_lmtp_proto *lmtp;
- socklen_t addrlen = sizeof(ss);
- int nfd;
+ struct rspamd_worker *worker = (struct rspamd_worker *)arg;
+ struct sockaddr_storage ss;
+ struct worker_task *new_task;
+ struct rspamd_lmtp_proto *lmtp;
+ socklen_t addrlen = sizeof (ss);
+ int nfd;
if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
msg_warn ("accept_socket: accept failed: %s", strerror (errno));
@@ -240,17 +241,15 @@ accept_socket (int fd, short what, void *arg)
new_task->cfg = worker->srv->cfg;
new_task->task_pool = memory_pool_new (memory_pool_get_size ());
/* Add destructor for recipients list (it would be better to use anonymous function here */
- memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)rcpt_destruct, new_task);
+ memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func) rcpt_destruct, new_task);
new_task->results = g_hash_table_new (g_str_hash, g_str_equal);
- memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)g_hash_table_destroy, new_task->results);
- worker->srv->stat->connections_count ++;
+ memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func) g_hash_table_destroy, new_task->results);
+ worker->srv->stat->connections_count++;
lmtp->task = new_task;
lmtp->state = LMTP_READ_LHLO;
/* Set up dispatcher */
- new_task->dispatcher = rspamd_create_dispatcher (nfd, BUFFER_LINE, lmtp_read_socket,
- lmtp_write_socket, lmtp_err_socket, &io_tv,
- (void *)lmtp);
+ new_task->dispatcher = rspamd_create_dispatcher (nfd, BUFFER_LINE, lmtp_read_socket, lmtp_write_socket, lmtp_err_socket, &io_tv, (void *)lmtp);
rspamd_dispatcher_write (lmtp->task->dispatcher, greetingbuf, strlen (greetingbuf), FALSE, FALSE);
}
@@ -260,10 +259,10 @@ accept_socket (int fd, short what, void *arg)
void
start_lmtp_worker (struct rspamd_worker *worker)
{
- struct sigaction signals;
- int i;
- char *hostbuf;
- long int hostmax;
+ struct sigaction signals;
+ int i;
+ char *hostbuf;
+ long int hostmax;
worker->srv->pid = getpid ();
worker->srv->type = TYPE_LMTP;
@@ -274,15 +273,15 @@ start_lmtp_worker (struct rspamd_worker *worker)
sigprocmask (SIG_UNBLOCK, &signals.sa_mask, NULL);
/* SIGUSR2 handler */
- signal_set (&worker->sig_ev, SIGUSR2, sigusr_handler, (void *) worker);
+ signal_set (&worker->sig_ev, SIGUSR2, sigusr_handler, (void *)worker);
signal_add (&worker->sig_ev, NULL);
-
+
/* Accept event */
- event_set(&worker->bind_ev, worker->cf->listen_sock, EV_READ | EV_PERSIST, accept_socket, (void *)worker);
- event_add(&worker->bind_ev, NULL);
+ event_set (&worker->bind_ev, worker->cf->listen_sock, EV_READ | EV_PERSIST, accept_socket, (void *)worker);
+ event_add (&worker->bind_ev, NULL);
/* Perform modules configuring */
- for (i = 0; i < MODULES_NUM; i ++) {
+ for (i = 0; i < MODULES_NUM; i++) {
modules[i].module_config_func (worker->srv->cfg);
}