1/*	$OpenBSD: scheduler_backend.c,v 1.18 2021/06/14 17:58:16 eric Exp $	*/
2
3/*
4 * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <string.h>
20
21#include "smtpd.h"
22
23extern struct scheduler_backend scheduler_backend_null;
24extern struct scheduler_backend scheduler_backend_proc;
25extern struct scheduler_backend scheduler_backend_ramqueue;
26
27struct scheduler_backend *
28scheduler_backend_lookup(const char *name)
29{
30	if (!strcmp(name, "null"))
31		return &scheduler_backend_null;
32	if (!strcmp(name, "ramqueue"))
33		return &scheduler_backend_ramqueue;
34
35	return &scheduler_backend_proc;
36}
37
38void
39scheduler_info(struct scheduler_info *sched, struct envelope *evp)
40{
41	struct dispatcher *disp;
42
43	disp = evp->type == D_BOUNCE ?
44	    env->sc_dispatcher_bounce :
45	    dict_xget(env->sc_dispatchers, evp->dispatcher);
46
47	switch (disp->type) {
48	case DISPATCHER_LOCAL:
49		sched->type = D_MDA;
50		break;
51	case DISPATCHER_REMOTE:
52		sched->type = D_MTA;
53		break;
54	case DISPATCHER_BOUNCE:
55		sched->type = D_BOUNCE;
56		break;
57	}
58	sched->ttl = disp->ttl ? disp->ttl : env->sc_ttl;
59
60	sched->evpid = evp->id;
61	sched->creation = evp->creation;
62	sched->retry = evp->retry;
63	sched->lasttry = evp->lasttry;
64	sched->lastbounce = evp->lastbounce;
65	sched->nexttry	= 0;
66}
67