summaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-01-14 18:08:39 +0000
committerLennart Poettering <lennart@poettering.net>2004-01-14 18:08:39 +0000
commit1b34f889f90cd879367f233c90d98b18dd47d338 (patch)
tree10025d8103bff429ccfdac18a70158996ba05c7f /src/stream.c
parent94fea1e00bc2115cb9163d53a0d5b25a88d35898 (diff)
initial commit
git-svn-id: file:///home/lennart/svn/public/bidilink/trunk@3 9cde1c1d-e4d0-0310-8a68-bf217395ea82
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/stream.c b/src/stream.c
new file mode 100644
index 0000000..80ad2c2
--- /dev/null
+++ b/src/stream.c
@@ -0,0 +1,52 @@
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "stream.h"
+#include "std.h"
+#include "exec.h"
+#include "client-tty.h"
+#include "server-tty.h"
+#include "client-tcp.h"
+#include "server-tcp.h"
+#include "client-unix.h"
+#include "server-unix.h"
+
+struct stream* stream_open(const char *spec) {
+ if (!spec || !strncmp(spec, "std:",4))
+ return stream_std(spec+4);
+ else if (!strncmp(spec, "exec:", 5))
+ return stream_exec(spec+5);
+ else if (!strncmp(spec, "tty:", 4))
+ return stream_client_tty(spec+4);
+ else if (!strncmp(spec, "pty:", 4))
+ return stream_server_tty(spec+4);
+ else if (!strncmp(spec, "tcp-client:", 11))
+ return stream_client_tcp(spec+11);
+ else if (!strncmp(spec, "tcp-server:", 11))
+ return stream_server_tcp(spec+11);
+ else if (!strncmp(spec, "unix-client:", 12))
+ return stream_client_unix(spec+12);
+ else if (!strncmp(spec, "unix-server:", 12))
+ return stream_server_unix(spec+12);
+
+ fprintf(stderr, "Found no stream implementation for '%s'.\n", spec);
+ return NULL;
+}
+
+
+void stream_close(struct stream *s) {
+ assert(s);
+
+ if (s->destruct)
+ s->destruct(s);
+
+ if (s->input_fd != -1)
+ close(s->input_fd);
+ if (s->output_fd != -1 && s->input_fd != s->output_fd)
+ close(s->output_fd);
+
+ free(s);
+}