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