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