| 1 | /* $Cambridge: exim/src/src/lookups/whoson.c,v 1.4 2007/01/08 10:50:19 ph10 Exp $ */ |
| 2 | |
| 3 | /************************************************* |
| 4 | * Exim - an Internet mail transport agent * |
| 5 | *************************************************/ |
| 6 | |
| 7 | /* Copyright (c) University of Cambridge 1995 - 2007 */ |
| 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 | /* We can't just compile this code and allow the library mechanism to omit the |
| 16 | functions if they are not wanted, because we need to have the WHOSON headers |
| 17 | available for compiling. Therefore, compile these functions only if |
| 18 | LOOKUP_WHOSON is defined. However, some compilers don't like compiling empty |
| 19 | modules, so keep them happy with a dummy when skipping the rest. Make it |
| 20 | reference itself to stop picky compilers complaining that it is unused, and put |
| 21 | in a dummy argument to stop even pickier compilers complaining about infinite |
| 22 | loops. */ |
| 23 | |
| 24 | #ifndef LOOKUP_WHOSON |
| 25 | static void dummy(int x) { dummy(x-1); } |
| 26 | #else |
| 27 | |
| 28 | |
| 29 | #include <whoson.h> /* Public header */ |
| 30 | #include "whoson.h" /* Local header */ |
| 31 | |
| 32 | |
| 33 | /************************************************* |
| 34 | * Open entry point * |
| 35 | *************************************************/ |
| 36 | |
| 37 | /* See local README for interface description. */ |
| 38 | |
| 39 | void * |
| 40 | whoson_open(uschar *filename, uschar **errmsg) |
| 41 | { |
| 42 | filename = filename; /* Keep picky compilers happy */ |
| 43 | errmsg = errmsg; |
| 44 | return (void *)(1); /* Just return something non-null */ |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /************************************************* |
| 49 | * Find entry point * |
| 50 | *************************************************/ |
| 51 | |
| 52 | /* See local README for interface description. */ |
| 53 | |
| 54 | int |
| 55 | whoson_find(void *handle, uschar *filename, uschar *query, int length, |
| 56 | uschar **result, uschar **errmsg, BOOL *do_cache) |
| 57 | { |
| 58 | uschar buffer[80]; |
| 59 | handle = handle; /* Keep picky compilers happy */ |
| 60 | filename = filename; |
| 61 | length = length; |
| 62 | errmsg = errmsg; |
| 63 | do_cache = do_cache; |
| 64 | |
| 65 | switch (wso_query(query, CS buffer, sizeof(buffer))) |
| 66 | { |
| 67 | case 0: |
| 68 | *result = string_copy(buffer); /* IP in database; return name of user */ |
| 69 | return OK; |
| 70 | |
| 71 | case +1: |
| 72 | return FAIL; /* IP not in database */ |
| 73 | |
| 74 | default: |
| 75 | *errmsg = string_sprintf("WHOSON: failed to complete: %s", buffer); |
| 76 | return DEFER; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | #endif /* LOOKUP_WHOSON */ |
| 81 | |
| 82 | /* End of lookups/whoson.c */ |