e82f7154 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: bres.h,v 1.1 1999/07/01 08:56:23 mdw Exp $ |
4 | * |
5 | * Background reverse name resolution |
6 | * |
7 | * (c) 1999 Mark Wooding |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of the `fw' port forwarder. |
13 | * |
14 | * `fw' is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2 of the License, or |
17 | * (at your option) any later version. |
18 | * |
19 | * `fw' 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 General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License |
25 | * along with `fw'; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | */ |
28 | |
29 | /*----- Revision history --------------------------------------------------* |
30 | * |
31 | * $Log: bres.h,v $ |
32 | * Revision 1.1 1999/07/01 08:56:23 mdw |
33 | * Initial revision |
34 | * |
35 | */ |
36 | |
37 | #ifndef RES_H |
38 | #define RES_H |
39 | |
40 | #ifdef __cplusplus |
41 | extern "C" { |
42 | #endif |
43 | |
44 | /*----- Header files ------------------------------------------------------*/ |
45 | |
46 | #include <sys/types.h> |
47 | |
48 | #include <sys/socket.h> |
49 | #include <netinet/in.h> |
50 | #include <arpa/inet.h> |
51 | |
52 | #include <mLib/sel.h> |
53 | #include <mLib/selbuf.h> |
54 | |
55 | /*----- Data structures ---------------------------------------------------*/ |
56 | |
57 | /* --- Client allocated request block --- */ |
58 | |
59 | typedef struct bres_client { |
60 | struct bres_client *next, *prev; /* Queue of waiting resolve jobs */ |
61 | struct bres_server *rs; /* Pointer to attached server */ |
62 | struct in_addr addr; /* Address to be resolved */ |
63 | void (*func)(const char */*host*/, void */*p*/); /* Handler function */ |
64 | void *p; /* Argument for handler function */ |
65 | } bres_client; |
66 | |
67 | /* --- Server maintained resolver blocks --- */ |
68 | |
69 | typedef struct bres_server { |
70 | struct bres_server *next, *prev; /* Doubly-linked list of servers */ |
71 | pid_t kid; /* Process id of server process */ |
72 | selbuf b; /* Input line-buffer selector */ |
73 | sel_timer t; /* Timeout for idle servers */ |
74 | int fd; /* File descriptor for writing */ |
75 | struct bres_client *rc; /* Pointer to attached client */ |
76 | } bres_server; |
77 | |
78 | /*----- Functions provided ------------------------------------------------*/ |
79 | |
80 | /* --- @bres_abort@ --- * |
81 | * |
82 | * Arguments: @bres_client *rc@ = pointer to client block |
83 | * |
84 | * Returns: --- |
85 | * |
86 | * Use: Removes a queued job. |
87 | */ |
88 | |
89 | extern void bres_abort(bres_client */*rc*/); |
90 | |
91 | /* --- @bres_resolve@ --- * |
92 | * |
93 | * Arguments: @bres_client *rc@ = pointer to client block |
94 | * @struct in_addr addr@ = address to resolve |
95 | * @void (*func)(const char *host, void *p)@ = handler function |
96 | * @void *p@ = argument for handler function |
97 | * |
98 | * Returns: --- |
99 | * |
100 | * Use: Adds a resolver job to the queue. The job will be processed |
101 | * when there's a spare resolver process to deal with it. |
102 | */ |
103 | |
104 | extern void bres_resolve(bres_client */*rc*/, struct in_addr /*addr*/, |
105 | void (*/*func*/)(const char */*host*/, void */*p*/), |
106 | void */*p*/); |
107 | |
108 | /* --- @bres_init@ --- * |
109 | * |
110 | * Arguments: @sel_state *s@ = pointer to select multiplexor |
111 | * |
112 | * Returns: --- |
113 | * |
114 | * Use: Initializes the background resolver for use. |
115 | */ |
116 | |
117 | extern void bres_init(sel_state */*s*/); |
118 | |
119 | /*----- That's all, folks -------------------------------------------------*/ |
120 | |
121 | #ifdef __cplusplus |
122 | } |
123 | #endif |
124 | |
125 | #endif |