5256e872b80e130b138bba6ac28b6da1c21482c9
[fwd] / source.c
1 /* -*-c-*-
2 *
3 * Standard routines for 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 /*----- Header files ------------------------------------------------------*/
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "source.h"
34
35 /*----- Static variables --------------------------------------------------*/
36
37 static source *sources = 0;
38
39 /*----- Main code ---------------------------------------------------------*/
40
41 /* --- @source_add@ --- *
42 *
43 * Arguments: @source *s@ = pointer to a source
44 *
45 * Returns: ---
46 *
47 * Use: Adds a source to the master list. Only do this for passive
48 * sources (e.g., listening sockets), not active sources (e.g.,
49 * executable programs).
50 */
51
52 void source_add(source *s)
53 {
54 s->next = sources;
55 s->prev = 0;
56 if (sources)
57 sources->prev = s;
58 sources = s;
59 }
60
61 /* --- @source_remove@ --- *
62 *
63 * Arguments: @source *s@ = pointer to a source
64 *
65 * Returns: ---
66 *
67 * Use: Removes a source from the master list.
68 */
69
70 void source_remove(source *s)
71 {
72 if (s->next)
73 s->next->prev = s->prev;
74 if (s->prev)
75 s->prev->next = s->next;
76 else
77 sources = s->next;
78 }
79
80 /* --- @source_killall@ --- *
81 *
82 * Arguments: ---
83 *
84 * Returns: ---
85 *
86 * Use: Frees all sources.
87 */
88
89 void source_killall(void)
90 {
91 source *s = sources;
92 while (s) {
93 source *ss = s;
94 s = s->next;
95 ss->ops->destroy(ss);
96 }
97 sources = 0;
98 }
99
100 /*----- That's all, folks -------------------------------------------------*/