Commit | Line | Data |
---|---|---|
0756eb3c PH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
8d6d5106 | 5 | /* Copyright (c) University of Cambridge 1995 - 2015 */ |
0756eb3c PH |
6 | /* See the file NOTICE for conditions of use and distribution. */ |
7 | ||
8 | /* This code originally came from Robert Wal. */ | |
9 | ||
10 | #include "../exim.h" | |
11 | ||
12 | ||
0756eb3c | 13 | #include <whoson.h> /* Public header */ |
0756eb3c PH |
14 | |
15 | ||
16 | /************************************************* | |
17 | * Open entry point * | |
18 | *************************************************/ | |
19 | ||
20 | /* See local README for interface description. */ | |
21 | ||
e6d225ae | 22 | static void * |
0756eb3c PH |
23 | whoson_open(uschar *filename, uschar **errmsg) |
24 | { | |
25 | filename = filename; /* Keep picky compilers happy */ | |
26 | errmsg = errmsg; | |
27 | return (void *)(1); /* Just return something non-null */ | |
28 | } | |
29 | ||
30 | ||
31 | /************************************************* | |
32 | * Find entry point * | |
33 | *************************************************/ | |
34 | ||
35 | /* See local README for interface description. */ | |
36 | ||
e6d225ae | 37 | static int |
0756eb3c | 38 | whoson_find(void *handle, uschar *filename, uschar *query, int length, |
14b3c5bc | 39 | uschar **result, uschar **errmsg, uint *do_cache) |
0756eb3c PH |
40 | { |
41 | uschar buffer[80]; | |
42 | handle = handle; /* Keep picky compilers happy */ | |
43 | filename = filename; | |
44 | length = length; | |
45 | errmsg = errmsg; | |
46 | do_cache = do_cache; | |
47 | ||
b3c261f7 | 48 | switch (wso_query(CS query, CS buffer, sizeof(buffer))) |
0756eb3c PH |
49 | { |
50 | case 0: | |
51 | *result = string_copy(buffer); /* IP in database; return name of user */ | |
52 | return OK; | |
53 | ||
54 | case +1: | |
55 | return FAIL; /* IP not in database */ | |
56 | ||
57 | default: | |
58 | *errmsg = string_sprintf("WHOSON: failed to complete: %s", buffer); | |
59 | return DEFER; | |
60 | } | |
61 | } | |
62 | ||
6545de78 PP |
63 | |
64 | ||
65 | /************************************************* | |
66 | * Version reporting entry point * | |
67 | *************************************************/ | |
68 | ||
69 | /* See local README for interface description. */ | |
70 | ||
71 | #include "../version.h" | |
72 | ||
73 | void | |
74 | whoson_version_report(FILE *f) | |
75 | { | |
76 | fprintf(f, "Library version: Whoson: Runtime: %s\n", wso_version()); | |
77 | #ifdef DYNLOOKUP | |
78 | fprintf(f, " Exim version %s\n", EXIM_VERSION_STR); | |
79 | #endif | |
80 | } | |
81 | ||
e6d225ae DW |
82 | static lookup_info _lookup_info = { |
83 | US"whoson", /* lookup name */ | |
84 | lookup_querystyle, /* query-style lookup */ | |
85 | whoson_open, /* open function */ | |
86 | NULL, /* check function */ | |
87 | whoson_find, /* find function */ | |
88 | NULL, /* no close function */ | |
89 | NULL, /* no tidy function */ | |
6545de78 PP |
90 | NULL, /* no quoting function */ |
91 | whoson_version_report /* version reporting */ | |
e6d225ae DW |
92 | }; |
93 | ||
94 | #ifdef DYNLOOKUP | |
95 | #define whoson_lookup_module_info _lookup_module_info | |
96 | #endif | |
97 | ||
98 | static lookup_info *_lookup_list[] = { &_lookup_info }; | |
99 | lookup_module_info whoson_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 }; | |
0756eb3c PH |
100 | |
101 | /* End of lookups/whoson.c */ |