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