SPDX: license tags (mostly by guesswork)
[exim.git] / src / src / lookups / testdb.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2015 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-only */
9
10 #include "../exim.h"
11 #include "lf_functions.h"
12
13
14 /* These are not real lookup functions; they are just a way of testing the
15 rest of Exim by providing an easy way of specifying particular yields from
16 the find function. */
17
18
19 /*************************************************
20 *              Open entry point                  *
21 *************************************************/
22
23 /* See local README for interface description. */
24
25 static void *
26 testdb_open(const uschar * filename, uschar ** errmsg)
27 {
28 return (void *)(1);    /* Just return something non-null */
29 }
30
31
32
33 /*************************************************
34 *               Find entry point                 *
35 *************************************************/
36
37 /* See local README for interface description. */
38
39 static int
40 testdb_find(void * handle, const uschar * filename, const uschar * query,
41   int length, uschar ** result, uschar ** errmsg, uint * do_cache,
42   const uschar * opts)
43 {
44 if (Ustrcmp(query, "fail") == 0)
45   {
46   *errmsg = US"testdb lookup forced FAIL";
47   DEBUG(D_lookup) debug_printf_indent("%s\n", *errmsg);
48   return FAIL;
49   }
50 if (Ustrcmp(query, "defer") == 0)
51   {
52   *errmsg = US"testdb lookup forced DEFER";
53   DEBUG(D_lookup) debug_printf_indent("%s\n", *errmsg);
54   return DEFER;
55   }
56
57 if (Ustrcmp(query, "nocache") == 0) *do_cache = 0;
58
59 *result = string_copy(query);
60 return OK;
61 }
62
63
64 /*************************************************
65 *         Version reporting entry point          *
66 *************************************************/
67
68 /* See local README for interface description. */
69
70 #include "../version.h"
71
72 gstring *
73 testdb_version_report(gstring * g)
74 {
75 #ifdef DYNLOOKUP
76 g = string_fmt_append(g, "Library version: TestDB: Exim version %s\n", EXIM_VERSION_STR);
77 #endif
78 return g;
79 }
80
81
82 static lookup_info _lookup_info = {
83   .name = US"testdb",                   /* lookup name */
84   .type = lookup_querystyle,            /* query-style lookup */
85   .open = testdb_open,                  /* open function */
86   .check = NULL,                        /* check function */
87   .find = testdb_find,                  /* find function */
88   .close = NULL,                        /* no close function */
89   .tidy = NULL,                         /* no tidy function */
90   .quote = NULL,                        /* no quoting function */
91   .version_report = testdb_version_report          /* version reporting */
92 };
93
94 #ifdef DYNLOOKUP
95 #define testdb_lookup_module_info _lookup_module_info
96 #endif
97
98 static lookup_info *_lookup_list[] = { &_lookup_info };
99 lookup_module_info testdb_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
100
101 /* End of lookups/testdb.c */