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