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