Infrastructure: Strip away crufty CVS $Id$ tags.
[mLib] / bres.h
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_RES_H
29 #define MLIB_RES_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 #include "sel.h"
49 #include "selbuf.h"
50
51 /*----- Data structures ---------------------------------------------------*/
52
53 /* --- Client allocated request block --- */
54
55 typedef struct bres_client {
56 #ifdef HAVE_ADNS
57 adns_query aq; /* ADNS query handle */
58 adns_answer *a; /* Answer for reverse resolution */
59 struct _unused *_pad1; /* And a spare slot */
60 #else
61 struct bres_client *next, *prev; /* Queue of waiting resolve jobs */
62 struct bres_server *rs; /* Pointer to attached server */
63 #endif
64 int q; /* Query type (name or address) */
65 union {
66 struct in_addr addr; /* Address to resolve */
67 char *name; /* Name to resolve */
68 } u;
69 void (*func)(struct hostent */*h*/, void */*p*/); /* Handler function */
70 void *p; /* Argument for handler function */
71 } bres_client;
72
73 /* --- Server maintained resolver blocks --- */
74
75 typedef struct bres_server {
76 struct bres_server *next, *prev; /* Doubly-linked list of servers */
77 pid_t kid; /* Process id of server process */
78 int fd; /* File descriptors */
79 struct bres_client *rc; /* Pointer to attached client */
80 sel_timer t; /* Timeout for idle servers */
81 sel_file f; /* Read selector for server */
82 } bres_server;
83
84 /*----- Functions provided ------------------------------------------------*/
85
86 /* --- @bres_abort@ --- *
87 *
88 * Arguments: @bres_client *rc@ = pointer to client block
89 *
90 * Returns: ---
91 *
92 * Use: Removes a queued job.
93 */
94
95 extern void bres_abort(bres_client */*rc*/);
96
97 /* --- @bres_byaddr@ --- *
98 *
99 * Arguments: @bres_client *rc@ = pointer to client block
100 * @struct in_addr addr@ = address to resolve
101 * @void (*func)(struct hostent *h, void *p)@ = handler function
102 * @void *p@ = argument for handler function
103 *
104 * Returns: ---
105 *
106 * Use: Adds an address lookup job to the queue. The job will be
107 * processed when there's a spare resolver process to deal with
108 * it.
109 */
110
111 extern void bres_byaddr(bres_client */*rc*/, struct in_addr /*addr*/,
112 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
113 void */*p*/);
114
115 /* --- @bres_byname@ --- *
116 *
117 * Arguments: @bres_client *rc@ = pointer to client block
118 * @const char *name@ = name to resolve
119 * @void (*func)(struct hostent *h, void *p)@ = handler function
120 * @void *p@ = argument for handler function
121 *
122 * Returns: ---
123 *
124 * Use: Adds a name lookup job to the queue. The job will be
125 * processed when there's a spare resolver process to deal with
126 * it.
127 */
128
129 extern void bres_byname(bres_client */*rc*/, const char */*name*/,
130 void (*/*func*/)(struct hostent */*h*/, void */*p*/),
131 void */*p*/);
132
133 /* --- @bres_exec@ --- *
134 *
135 * Arguments: @const char *file@ = file containing server code or null
136 *
137 * Returns: ---
138 *
139 * Use: Makes `bres' use a standalone server rather than copies of
140 * the current process. This can reduce memory consumption for
141 * large processes, at the expense of startup time (which
142 * shouldn't be too bad anyway, because of the resolver design).
143 * If the filename is null, a default set up at install time is
144 * used. It's probably a good idea to leave it alone.
145 */
146
147 extern void bres_exec(const char */*file*/);
148
149 /* --- @bres_init@ --- *
150 *
151 * Arguments: @sel_state *s@ = pointer to select multiplexor
152 *
153 * Returns: ---
154 *
155 * Use: Initializes the background resolver for use.
156 */
157
158 extern void bres_init(sel_state */*s*/);
159
160 /*----- That's all, folks -------------------------------------------------*/
161
162 #ifdef __cplusplus
163 }
164 #endif
165
166 #endif