SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / lookups / whoson.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2015 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
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(const uschar * filename, uschar ** errmsg)
26 {
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
37 static int
38 whoson_find(void * handle, const uschar * filename, uschar * query, int length,
39   uschar ** result, uschar ** errmsg, uint * do_cache, const uschar * opts)
40 {
41 uschar buffer[80];
42
43 switch (wso_query(CS query, CS buffer, sizeof(buffer)))
44   {
45   case 0:
46   *result = string_copy(buffer);    /* IP in database; return name of user */
47   return OK;
48
49   case +1:
50   return FAIL;                      /* IP not in database */
51
52   default:
53   *errmsg = string_sprintf("WHOSON: failed to complete: %s", buffer);
54   return DEFER;
55   }
56 }
57
58
59
60 /*************************************************
61 *         Version reporting entry point          *
62 *************************************************/
63
64 /* See local README for interface description. */
65
66 #include "../version.h"
67
68 gstring *
69 whoson_version_report(gstring * g)
70 {
71 g = string_fmt_append(g,
72   "Library version: Whoson: Runtime: %s\n", wso_version());
73 #ifdef DYNLOOKUP
74 g = string_fmt_append(g,
75   "                         Exim version %s\n", EXIM_VERSION_STR);
76 #endif
77 return g;
78 }
79
80 static lookup_info _lookup_info = {
81   .name = US"whoson",                   /* lookup name */
82   .type = lookup_querystyle,            /* query-style lookup */
83   .open = whoson_open,                  /* open function */
84   .check = NULL,                        /* check function */
85   .find = whoson_find,                  /* find function */
86   .close = NULL,                        /* no close function */
87   .tidy = NULL,                         /* no tidy function */
88   .quote = NULL,                        /* no quoting function */
89   .version_report = whoson_version_report          /* version reporting */
90 };
91
92 #ifdef DYNLOOKUP
93 #define whoson_lookup_module_info _lookup_module_info
94 #endif
95
96 static lookup_info *_lookup_list[] = { &_lookup_info };
97 lookup_module_info whoson_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
98
99 /* End of lookups/whoson.c */