4ec5d65dea391383d41311ed1e2049befaa91042
[fwd] / source.h
1 /* -*-c-*-
2 *
3 * Description of forwarding sources
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of the `fw' port forwarder.
11 *
12 * `fw' is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * `fw' 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 General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with `fw'; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27 #ifndef SOURCE_H
28 #define SOURCE_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*----- Header files ------------------------------------------------------*/
35
36 #include <stdio.h>
37
38 #ifndef SCAN_H
39 # include "scan.h"
40 #endif
41
42 #ifndef TARGET_H
43 # include "target.h"
44 #endif
45
46 /*----- Data structures ---------------------------------------------------*/
47
48 /* --- A basic source object --- */
49
50 typedef struct source {
51 struct source *next, *prev;
52 struct source_ops *ops;
53 char *desc;
54 } source;
55
56 /* --- Forwarding source operations --- */
57
58 typedef struct source_ops {
59 const char *name; /* Name of this source */
60
61 /* --- @option@ --- *
62 *
63 * Arguments: @scanner *sc@ = scanner to read from
64 * @source *s@ = pointer to source object, or zero if global
65 *
66 * Returns: Nonzero to claim the option.
67 *
68 * Use: Handles an option string from the configuration file.
69 */
70
71 int (*option)(source */*s*/, scanner */*sc*/);
72
73 /* --- @read@ --- *
74 *
75 * Arguments: @scanner *sc@ = pointer to scanner to read from
76 *
77 * Returns: Pointer to a source object to claim, null to reject.
78 *
79 * Use: Parses a source description from the configuration file.
80 * Only the socket source is allowed to omit the prefix on a
81 * source specification.
82 */
83
84 source *(*read)(scanner */*sc*/);
85
86 /* --- @attach@ --- *
87 *
88 * Arguments: @source *s@ = pointer to source
89 * @scanner *sc@ = scanner (for error reporting)
90 * @target *t@ = pointer to target to attach
91 *
92 * Returns: ---
93 *
94 * Use: Attaches a target to a source.
95 */
96
97 void (*attach)(source */*s*/, scanner */*sc*/, target */*t*/);
98
99 /* --- @destroy@ --- *
100 *
101 * Arguments: @source *s@ = pointer to source
102 *
103 * Returns: ---
104 *
105 * Use: Destroys a source. Used when closing the system down, for
106 * example as a result of a signal.
107 */
108
109 void (*destroy)(source */*s*/);
110
111 } source_ops;
112
113 /*----- Functions provided ------------------------------------------------*/
114
115 /* --- @source_add@ --- *
116 *
117 * Arguments: @source *s@ = pointer to a source
118 *
119 * Returns: ---
120 *
121 * Use: Adds a source to the master list. Only do this for passive
122 * sources (e.g., listening sockets), not active sources (e.g.,
123 * executable programs).
124 */
125
126 extern void source_add(source */*s*/);
127
128 /* --- @source_remove@ --- *
129 *
130 * Arguments: @source *s@ = pointer to a source
131 *
132 * Returns: ---
133 *
134 * Use: Removes a source from the master list.
135 */
136
137 extern void source_remove(source */*s*/);
138
139 /* --- @source_killall@ --- *
140 *
141 * Arguments: ---
142 *
143 * Returns: ---
144 *
145 * Use: Frees all sources.
146 */
147
148 extern void source_killall(void);
149
150 /*----- That's all, folks -------------------------------------------------*/
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 #endif