Debian Codegraph @

src/miscmods/README

raw
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 Copyright (c) The Exim Maintainers 2024 - 2025
6
7 This directory contains source for modules that can be built as part
8 of Exim, either static-linked or as dynamic-load modules. Doing the
9 latter keeps the runtime binary smaller when a feature is not used
10 by the configuration, especially when a library is involved.
11
12 Which modules are built, and the choice of static vs. dynamic, is
13 under the control of the Local/Makefile at build time.
14 Any combination of static/dynamic is valid.
15
16 Moudules built for dynamic load must be installed in a directory
17 which is defined in Local/Makefile.
18
19 The API starts with a struct with a known name <foo>_module_info.
20 For dynamic builds this includes a magic number permitting versioning
21 of the highlevel interface.
22 The structure has elements for some commonly-needed call types
23 (init, version-report etc.). Any may be left as null pointers;
24 those present will be called at appropriate times.
25
26 The current list is
27 init (Exim startup if static, modload if dynamic)
28 lib_vers_report
29 conn_init
30 smtp_reset
31 msg_init
32
33 Then there are three pairs of elements, each being a table pointer
34 and table length, for options, functions, and variable that the
35 module provides.
36
37 The options table defines main-section configuration options, using
38 the same definition entry struct as the main table in readconf.c;
39 entries here should have their proper opt_<type> and
40 should be duplicated in the main table, but with opt_module and the
41 module name (this supports both getting the module loaded, if dynamic,
42 and writing the value from the config). Entries must be in order by
43 the option name.
44
45 The functions table defines service functions additional to the "common"
46 ones noted above. Each offset in the table should have a #define in an
47 include-file brought in to the general set by exim.h.
48
49 The variables table defins $variables for expansion, using the same
50 definition entry struct as the main var_table in expand.c;
51 entries here should have their proper vtype_<type> and should be duplicated
52 in the main table but with vtype_module and the module name.
53 Entries must be in order by the variable name.
54
55 There are service functions to locate and to locate-or-load modules
56 by name; these hide the static/dynamic aspect of a module. Most
57 new coding will only need these for calls to the "additiona" custom
58 functions a module provides. The example code is:
59
60 {
61 /* You need to know the function's prototype */
62 typedef int (*fn_t)(const uschar **, const uschar *, int);
63 fn_t fn;
64 misc_module_info * mi = misc_mod_find(US"spf", &log_message);
65
66 if (mi)
67 {
68 fn = ((fn_t *) mi->functions)[SPF_PROCESS];
69 rc = fn(args...);
70 }
71 }
72
73
74
75 Adding new modules
76 ------------------
77
78 Put the code in this directory. Use filenames starting with the module name.
79 Write an include file with anything callers need to know, in particular
80 #defines for the function call numbers. Include that file from exim.h
81 and add it to HDRS and PHDRS in OS/Makefile-Base.
82 Add a SUPPORT_<foo> line to Local/Makefile, and (if dynamic) any
83 SUPPORT_<foo>_INCLUDE or SUPPORT_<foo>_LIBS required.
84 Add the capitalised module name <foo> to the "miscmods" line in
85 scripts/Configure-Makefile.
86 Add all the filenames to the "miscmods" list in scripts/Makelinks
87
88 For statically-linked modules the SUPPORT_<foo> line should say "yes",
89 for dynamic: "2".
90
91 If include-by-default is wanted for the module, use DISABLE_<foo> instead
92 of SUPPORT_<foo> (and leave it commented out as appropriate), and prefix
93 the name in the "miscmods" line with an underbar ("_").
94 For dynamic builds, a SUPPORT_ line is still needed.