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