1 /* $OpenBSD: scheduler_backend.c,v 1.16 2018/05/24 11:38:24 gilles 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 <sys/types.h> 20 #include <sys/queue.h> 21 #include <sys/tree.h> 22 #include <sys/socket.h> 23 24 #include <ctype.h> 25 #include <err.h> 26 #include <event.h> 27 #include <fcntl.h> 28 #include <imsg.h> 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <string.h> 32 #include <limits.h> 33 34 #include "smtpd.h" 35 #include "log.h" 36 37 extern struct scheduler_backend scheduler_backend_null; 38 extern struct scheduler_backend scheduler_backend_proc; 39 extern struct scheduler_backend scheduler_backend_ramqueue; 40 41 struct scheduler_backend * 42 scheduler_backend_lookup(const char *name) 43 { 44 if (!strcmp(name, "null")) 45 return &scheduler_backend_null; 46 if (!strcmp(name, "ramqueue")) 47 return &scheduler_backend_ramqueue; 48 49 return &scheduler_backend_proc; 50 } 51 52 void 53 scheduler_info(struct scheduler_info *sched, struct envelope *evp) 54 { 55 struct dispatcher *disp; 56 57 disp = evp->type == D_BOUNCE ? 58 env->sc_dispatcher_bounce : 59 dict_xget(env->sc_dispatchers, evp->dispatcher); 60 61 switch (disp->type) { 62 case DISPATCHER_LOCAL: 63 sched->type = D_MDA; 64 break; 65 case DISPATCHER_REMOTE: 66 sched->type = D_MTA; 67 break; 68 case DISPATCHER_BOUNCE: 69 sched->type = D_BOUNCE; 70 break; 71 } 72 sched->ttl = disp->ttl ? disp->ttl : env->sc_ttl; 73 74 sched->evpid = evp->id; 75 sched->creation = evp->creation; 76 sched->retry = evp->retry; 77 sched->lasttry = evp->lasttry; 78 sched->lastbounce = evp->lastbounce; 79 sched->nexttry = 0; 80 } 81