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