Add dynamic lookup support
[exim.git] / src / src / lookups / testdb.c
1 /* $Cambridge: exim/src/src/lookups/testdb.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
2
3 /*************************************************
4 *     Exim - an Internet mail transport agent    *
5 *************************************************/
6
7 /* Copyright (c) University of Cambridge 1995 - 2009 */
8 /* See the file NOTICE for conditions of use and distribution. */
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(uschar *filename, uschar **errmsg)
27 {
28 filename = filename;   /* Keep picky compilers happy */
29 errmsg = errmsg;
30 return (void *)(1);    /* Just return something non-null */
31 }
32
33
34
35 /*************************************************
36 *               Find entry point                 *
37 *************************************************/
38
39 /* See local README for interface description. */
40
41 static int
42 testdb_find(void *handle, uschar *filename, uschar *query, int length,
43   uschar **result, uschar **errmsg, BOOL *do_cache)
44 {
45 handle = handle;          /* Keep picky compilers happy */
46 filename = filename;
47 length = length;
48
49 if (Ustrcmp(query, "fail") == 0)
50   {
51   *errmsg = US"testdb lookup forced FAIL";
52   DEBUG(D_lookup) debug_printf("%s\n", *errmsg);
53   return FAIL;
54   }
55 if (Ustrcmp(query, "defer") == 0)
56   {
57   *errmsg = US"testdb lookup forced DEFER";
58   DEBUG(D_lookup) debug_printf("%s\n", *errmsg);
59   return DEFER;
60   }
61
62 if (Ustrcmp(query, "nocache") == 0) *do_cache = FALSE;
63
64 *result = string_copy(query);
65 return OK;
66 }
67
68 static lookup_info _lookup_info = {
69   US"testdb",                    /* lookup name */
70   lookup_querystyle,             /* query-style lookup */
71   testdb_open,                   /* open function */
72   NULL,                          /* check function */
73   testdb_find,                   /* find function */
74   NULL,                          /* no close function */
75   NULL,                          /* no tidy function */
76   NULL                           /* no quoting function */
77 };
78
79 #ifdef DYNLOOKUP
80 #define testdb_lookup_module_info _lookup_module_info
81 #endif
82
83 static lookup_info *_lookup_list[] = { &_lookup_info };
84 lookup_module_info testdb_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
85
86 /* End of lookups/testdb.c */