| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Background reverse name resolution |
| 4 | * |
| 5 | * (c) 1999 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of the mLib utilities library. |
| 11 | * |
| 12 | * mLib is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU Library General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * mLib is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public |
| 23 | * License along with mLib; if not, write to the Free |
| 24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 25 | * MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | #ifndef MLIB_BRES_H |
| 29 | #define MLIB_BRES_H |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /*----- Header files ------------------------------------------------------*/ |
| 36 | |
| 37 | #include <sys/types.h> |
| 38 | |
| 39 | #include <sys/socket.h> |
| 40 | #include <netinet/in.h> |
| 41 | #include <arpa/inet.h> |
| 42 | #include <netdb.h> |
| 43 | |
| 44 | #ifdef HAVE_ADNS |
| 45 | # include <adns.h> |
| 46 | #endif |
| 47 | |
| 48 | #ifndef MLIB_SEL_H |
| 49 | # include "sel.h" |
| 50 | #endif |
| 51 | |
| 52 | #ifndef MLIB_SELBUF_H |
| 53 | # include "selbuf.h" |
| 54 | #endif |
| 55 | |
| 56 | /*----- Data structures ---------------------------------------------------*/ |
| 57 | |
| 58 | /* --- Client allocated request block --- */ |
| 59 | |
| 60 | typedef struct bres_client { |
| 61 | #ifdef HAVE_ADNS |
| 62 | adns_query aq; /* ADNS query handle */ |
| 63 | adns_answer *a; /* Answer for reverse resolution */ |
| 64 | struct _unused *_pad1; /* And a spare slot */ |
| 65 | #else |
| 66 | struct bres_client *next, *prev; /* Queue of waiting resolve jobs */ |
| 67 | struct bres_server *rs; /* Pointer to attached server */ |
| 68 | #endif |
| 69 | int q; /* Query type (name or address) */ |
| 70 | union { |
| 71 | struct in_addr addr; /* Address to resolve */ |
| 72 | char *name; /* Name to resolve */ |
| 73 | } u; |
| 74 | void (*func)(struct hostent */*h*/, void */*p*/); /* Handler function */ |
| 75 | void *p; /* Argument for handler function */ |
| 76 | } bres_client; |
| 77 | |
| 78 | /* --- Server maintained resolver blocks --- */ |
| 79 | |
| 80 | typedef struct bres_server { |
| 81 | struct bres_server *next, *prev; /* Doubly-linked list of servers */ |
| 82 | pid_t kid; /* Process id of server process */ |
| 83 | int fd; /* File descriptors */ |
| 84 | struct bres_client *rc; /* Pointer to attached client */ |
| 85 | sel_timer t; /* Timeout for idle servers */ |
| 86 | sel_file f; /* Read selector for server */ |
| 87 | } bres_server; |
| 88 | |
| 89 | /*----- Functions provided ------------------------------------------------*/ |
| 90 | |
| 91 | /* --- @bres_abort@ --- * |
| 92 | * |
| 93 | * Arguments: @bres_client *rc@ = pointer to client block |
| 94 | * |
| 95 | * Returns: --- |
| 96 | * |
| 97 | * Use: Removes a queued job. |
| 98 | */ |
| 99 | |
| 100 | extern void bres_abort(bres_client */*rc*/); |
| 101 | |
| 102 | /* --- @bres_byaddr@ --- * |
| 103 | * |
| 104 | * Arguments: @bres_client *rc@ = pointer to client block |
| 105 | * @struct in_addr addr@ = address to resolve |
| 106 | * @void (*func)(struct hostent *h, void *p)@ = handler function |
| 107 | * @void *p@ = argument for handler function |
| 108 | * |
| 109 | * Returns: --- |
| 110 | * |
| 111 | * Use: Adds an address lookup job to the queue. The job will be |
| 112 | * processed when there's a spare resolver process to deal with |
| 113 | * it. |
| 114 | */ |
| 115 | |
| 116 | extern void bres_byaddr(bres_client */*rc*/, struct in_addr /*addr*/, |
| 117 | void (*/*func*/)(struct hostent */*h*/, void */*p*/), |
| 118 | void */*p*/); |
| 119 | |
| 120 | /* --- @bres_byname@ --- * |
| 121 | * |
| 122 | * Arguments: @bres_client *rc@ = pointer to client block |
| 123 | * @const char *name@ = name to resolve |
| 124 | * @void (*func)(struct hostent *h, void *p)@ = handler function |
| 125 | * @void *p@ = argument for handler function |
| 126 | * |
| 127 | * Returns: --- |
| 128 | * |
| 129 | * Use: Adds a name lookup job to the queue. The job will be |
| 130 | * processed when there's a spare resolver process to deal with |
| 131 | * it. |
| 132 | */ |
| 133 | |
| 134 | extern void bres_byname(bres_client */*rc*/, const char */*name*/, |
| 135 | void (*/*func*/)(struct hostent */*h*/, void */*p*/), |
| 136 | void */*p*/); |
| 137 | |
| 138 | /* --- @bres_exec@ --- * |
| 139 | * |
| 140 | * Arguments: @const char *file@ = file containing server code or null |
| 141 | * |
| 142 | * Returns: --- |
| 143 | * |
| 144 | * Use: Makes `bres' use a standalone server rather than copies of |
| 145 | * the current process. This can reduce memory consumption for |
| 146 | * large processes, at the expense of startup time (which |
| 147 | * shouldn't be too bad anyway, because of the resolver design). |
| 148 | * If the filename is null, a default set up at install time is |
| 149 | * used. It's probably a good idea to leave it alone. |
| 150 | */ |
| 151 | |
| 152 | extern void bres_exec(const char */*file*/); |
| 153 | |
| 154 | /* --- @bres_init@ --- * |
| 155 | * |
| 156 | * Arguments: @sel_state *s@ = pointer to select multiplexor |
| 157 | * |
| 158 | * Returns: --- |
| 159 | * |
| 160 | * Use: Initializes the background resolver for use. |
| 161 | */ |
| 162 | |
| 163 | extern void bres_init(sel_state */*s*/); |
| 164 | |
| 165 | /*----- That's all, folks -------------------------------------------------*/ |
| 166 | |
| 167 | #ifdef __cplusplus |
| 168 | } |
| 169 | #endif |
| 170 | |
| 171 | #endif |