b4527a95cd6fab403f62b4545d559205cb2ac960
[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
66
67 /*************************************************
68 * Version reporting entry point *
69 *************************************************/
70
71 /* See local README for interface description. */
72
73 #include "../version.h"
74
75 void
76 whoson_version_report(FILE *f)
77 {
78 fprintf(f, "Library version: Whoson: Runtime: %s\n", wso_version());
79 #ifdef DYNLOOKUP
80 fprintf(f, " Exim version %s\n", EXIM_VERSION_STR);
81 #endif
82 }
83
84 static lookup_info _lookup_info = {
85 US"whoson", /* lookup name */
86 lookup_querystyle, /* query-style lookup */
87 whoson_open, /* open function */
88 NULL, /* check function */
89 whoson_find, /* find function */
90 NULL, /* no close function */
91 NULL, /* no tidy function */
92 NULL, /* no quoting function */
93 whoson_version_report /* version reporting */
94 };
95
96 #ifdef DYNLOOKUP
97 #define whoson_lookup_module_info _lookup_module_info
98 #endif
99
100 static lookup_info *_lookup_list[] = { &_lookup_info };
101 lookup_module_info whoson_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
102
103 /* End of lookups/whoson.c */