Infrastructure for the new design.
[fwd] / source.c
diff --git a/source.c b/source.c
new file mode 100644 (file)
index 0000000..5973547
--- /dev/null
+++ b/source.c
@@ -0,0 +1,110 @@
+/* -*-c-*-
+ *
+ * $Id: source.c,v 1.1 1999/07/26 23:33:01 mdw Exp $
+ *
+ * Standard routines for forwarding sources
+ *
+ * (c) 1999 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the `fw' port forwarder.
+ *
+ * `fw' is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * `fw' is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with `fw'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: source.c,v $
+ * Revision 1.1  1999/07/26 23:33:01  mdw
+ * Infrastructure for the new design.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "source.h"
+
+/*----- Static variables --------------------------------------------------*/
+
+static source *sources = 0;
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @source_add@ --- *
+ *
+ * Arguments:  @source *s@ = pointer to a source
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds a source to the master list.  Only do this for passive
+ *             sources (e.g., listening sockets), not active sources (e.g.,
+ *             executable programs).
+ */
+
+void source_add(source *s)
+{
+  s->next = sources;
+  s->prev = 0;
+  if (sources)
+    sources->prev = s;
+  sources = s;
+}
+
+/* --- @source_remove@ --- *
+ *
+ * Arguments:  @source *s@ = pointer to a source
+ *
+ * Returns:    ---
+ *
+ * Use:                Removes a source from the master list.
+ */
+
+void source_remove(source *s)
+{
+  if (s->next)
+    s->next->prev = s->prev;
+  if (s->prev)
+    s->prev->next = s->next;
+  else
+    sources = s->next;
+}
+
+/* --- @source_killall@ --- *
+ *
+ * Arguments:  ---
+ *
+ * Returns:    ---
+ *
+ * Use:                Frees all sources.
+ */
+
+void source_killall(void)
+{
+  source *s = sources;
+  while (s) {
+    source *ss = s;
+    s = s->next;
+    ss->ops->destroy(ss);
+  }
+  sources = 0;
+}
+
+/*----- That's all, folks -------------------------------------------------*/