chiark / gitweb /
fwd.c: Check return code from `chdir'.
[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 `fwd' port forwarder.
11  *
12  * `fwd' 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  * `fwd' 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 `fwd'; if not, write to the Free Software Foundation,
24  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 #include "fwd.h"
28
29 /*----- Static variables --------------------------------------------------*/
30
31 static source *sources = 0;
32
33 /*----- Main code ---------------------------------------------------------*/
34
35 /* --- @source_add@ --- *
36  *
37  * Arguments:   @source *s@ = pointer to a source
38  *
39  * Returns:     ---
40  *
41  * Use:         Adds a source to the master list.  Only do this for passive
42  *              sources (e.g., listening sockets), not active sources (e.g.,
43  *              executable programs).
44  */
45
46 void source_add(source *s)
47 {
48   s->next = sources;
49   s->prev = 0;
50   if (sources)
51     sources->prev = s;
52   sources = s;
53 }
54
55 /* --- @source_remove@ --- *
56  *
57  * Arguments:   @source *s@ = pointer to a source
58  *
59  * Returns:     ---
60  *
61  * Use:         Removes a source from the master list.
62  */
63
64 void source_remove(source *s)
65 {
66   if (s->next)
67     s->next->prev = s->prev;
68   if (s->prev)
69     s->prev->next = s->next;
70   else
71     sources = s->next;
72 }
73
74 /* --- @source_killall@ --- *
75  *
76  * Arguments:   ---
77  *
78  * Returns:     ---
79  *
80  * Use:         Frees all sources.
81  */
82
83 void source_killall(void)
84 {
85   source *s = sources;
86   while (s) {
87     source *ss = s;
88     s = s->next;
89     ss->ops->destroy(ss);
90   }
91   sources = 0;
92 }
93
94 /*----- That's all, folks -------------------------------------------------*/