void free_smtp_session (gpointer arg) { struct smtp_session *session = arg; if (session) { if (session->task) { rspamd_task_free (session->task, FALSE); if (session->task->msg.start) { munmap (session->task->msg.start, session->task->msg.len); } } if (session->rcpt) { g_list_free (session->rcpt); } if (session->dispatcher) { rspamd_remove_dispatcher (session->dispatcher); } close (session->sock); if (session->temp_name != NULL) { unlink (session->temp_name); } if (session->temp_fd != -1) { close (session->temp_fd); } rspamd_mempool_delete (session->pool); g_free (session); } }
static void sync_err (GError *err, void *arg) { struct rspamd_sync_ctx *ctx = arg; msg_info ("abnormally closing connection, error: %s", err->message); ctx->is_busy = FALSE; close (ctx->sock); rspamd_remove_dispatcher (ctx->dispatcher); }
static int lua_io_dispatcher_destroy (lua_State *L) { struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L); if (io_dispatcher) { rspamd_remove_dispatcher (io_dispatcher); return 0; } else { lua_pushnil (L); } return 1; }
void smtp_upstream_finalize_connection (gpointer data) { struct smtp_session *session = data; if (session->state != SMTP_STATE_CRITICAL_ERROR) { if (!rspamd_dispatcher_write (session->upstream_dispatcher, "QUIT" CRLF, 0, FALSE, TRUE)) { msg_warn ("cannot send correctly closing message to upstream"); } } rspamd_remove_dispatcher (session->upstream_dispatcher); session->upstream_dispatcher = NULL; close (session->upstream_sock); session->upstream_sock = -1; }
static gboolean sync_read (f_str_t * in, void *arg) { struct rspamd_sync_ctx *ctx = arg; gchar buf[256]; guint64 rev = 0; time_t ti = 0; if (in->len == 0) { /* Skip empty lines */ return TRUE; } switch (ctx->state) { case SYNC_STATE_GREETING: /* Skip greeting line and write sync command */ /* Write initial data */ statfile_get_revision (ctx->real_statfile, &rev, &ti); rev = rspamd_snprintf (buf, sizeof (buf), "sync %s %uL %T" CRLF, ctx->st->symbol, rev, ti); ctx->state = SYNC_STATE_READ_LINE; return rspamd_dispatcher_write (ctx->dispatcher, buf, rev, FALSE, FALSE); break; case SYNC_STATE_READ_LINE: /* Try to parse line from server */ if (!parse_revision_line (ctx, in)) { msg_info ("cannot parse line of length %z: '%*s'", in->len, (gint)in->len, in->begin); close (ctx->sock); rspamd_remove_dispatcher (ctx->dispatcher); ctx->is_busy = FALSE; return FALSE; } else if (ctx->state != SYNC_STATE_QUIT) { if (ctx->new_len > 0) { ctx->state = SYNC_STATE_READ_REV; rspamd_set_dispatcher_policy (ctx->dispatcher, BUFFER_CHARACTER, ctx->new_len); } } else { /* Quit this session */ msg_info ("sync ended for: %s", ctx->st->symbol); close (ctx->sock); rspamd_remove_dispatcher (ctx->dispatcher); ctx->is_busy = FALSE; /* Immediately return from callback */ return FALSE; } break; case SYNC_STATE_READ_REV: /* In now contains all blocks of specified revision, so we can read them directly */ if (!read_blocks (ctx, in)) { msg_info ("cannot read blocks"); close (ctx->sock); rspamd_remove_dispatcher (ctx->dispatcher); ctx->is_busy = FALSE; return FALSE; } statfile_set_revision (ctx->real_statfile, ctx->new_rev, ctx->new_time); msg_info ("set new revision: %uL, readed %z bytes", ctx->new_rev, in->len); /* Now try to read other revision or END line */ ctx->state = SYNC_STATE_READ_LINE; rspamd_set_dispatcher_policy (ctx->dispatcher, BUFFER_LINE, 0); break; case SYNC_STATE_QUIT: close (ctx->sock); rspamd_remove_dispatcher (ctx->dispatcher); ctx->is_busy = FALSE; return FALSE; } return TRUE; }