Add dynamic lookup support
[exim.git] / src / src / lookups / whoson.c
1 /* $Cambridge: exim/src/src/lookups/whoson.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 /* This code originally came from Robert Wal. */
11
12 #include "../exim.h"
13
14
15 #include <whoson.h>        /* Public header */
16
17
18 /*************************************************
19 *              Open entry point                  *
20 *************************************************/
21
22 /* See local README for interface description. */
23
24 static void *
25 whoson_open(uschar *filename, uschar **errmsg)
26 {
27 filename = filename;   /* Keep picky compilers happy */
28 errmsg = errmsg;
29 return (void *)(1);    /* Just return something non-null */
30 }
31
32
33 /*************************************************
34 *               Find entry point                 *
35 *************************************************/
36
37 /* See local README for interface description. */
38
39 static int
40 whoson_find(void *handle, uschar *filename, uschar *query, int length,
41   uschar **result, uschar **errmsg, BOOL *do_cache)
42 {
43 uschar buffer[80];
44 handle = handle;          /* Keep picky compilers happy */
45 filename = filename;
46 length = length;
47 errmsg = errmsg;
48 do_cache = do_cache;
49
50 switch (wso_query(query, CS buffer, sizeof(buffer)))
51   {
52   case 0:
53   *result = string_copy(buffer);    /* IP in database; return name of user */
54   return OK;
55
56   case +1:
57   return FAIL;                      /* IP not in database */
58
59   default:
60   *errmsg = string_sprintf("WHOSON: failed to complete: %s", buffer);
61   return DEFER;
62   }
63 }
64
65 static lookup_info _lookup_info = {
66   US"whoson",                    /* lookup name */
67   lookup_querystyle,             /* query-style lookup */
68   whoson_open,                   /* open function */
69   NULL,                          /* check function */
70   whoson_find,                   /* find function */
71   NULL,                          /* no close function */
72   NULL,                          /* no tidy function */
73   NULL                           /* no quoting function */
74 };
75
76 #ifdef DYNLOOKUP
77 #define whoson_lookup_module_info _lookup_module_info
78 #endif
79
80 static lookup_info *_lookup_list[] = { &_lookup_info };
81 lookup_module_info whoson_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
82
83 /* End of lookups/whoson.c */