summaryrefslogtreecommitdiffstats
path: root/src/tsnif.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tsnif.c')
-rw-r--r--src/tsnif.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/src/tsnif.c b/src/tsnif.c
index b6f4150..102d2d2 100644
--- a/src/tsnif.c
+++ b/src/tsnif.c
@@ -10,15 +10,25 @@
#include "autoconf.h"
#include "intf.h"
+#include "storage.h"
-struct tsnif_handle handle;
-struct tsnif_term term;
+
+static struct tsnif_handle handle;
+static struct tsnif_term term;
+
+static struct tsnif_storage_opts storage_opts = {
+ .flags = TSNIF_STORAGE_OPT_CREATE | TSNIF_STORAGE_OPT_WRITE,
+ .size_max = 1024*1024,
+};
+static struct tsnif_storage_handle storage_handle;
static int killed = 0;
+static int store = 0;
static int type = -1;
static int idx = -1;
static int display_slave = 1;
static int display_master = 0;
+static char *storage_file = NULL;
static int display_pty(int flags)
{
@@ -33,6 +43,17 @@ static int display_pty(int flags)
return 1;
}
+static int store_data(struct tsnif_data *data)
+{
+ struct tsnif_storage_rec rec = {
+ .ptr = data->ptr,
+ .len = data->len,
+ .flags = data->flags,
+ };
+
+ return tsnif_storage_write(&storage_handle, &rec);
+}
+
static int data_cb(struct tsnif_term* term, struct tsnif_data *data)
{
/* rule out unwanted PTY channel */
@@ -42,6 +63,10 @@ static int data_cb(struct tsnif_term* term, struct tsnif_data *data)
fwrite(data->ptr, data->len, 1, stdout);
fflush(NULL);
+
+ if (store)
+ return store_data(data);
+
return 0;
}
@@ -69,7 +94,7 @@ struct tsnif_ops ops = {
static void usage()
{
- printf("tsnif -t <terminal type> -i <terminal index>\n");
+ printf("tsnif -t <terminal type> -i <terminal index> [ -s<file> ]\n");
printf(" where types can be 'tty', 'ttys' or 'pty'\n");
_exit(-1);
}
@@ -118,13 +143,14 @@ static int get_args(int argc, char **argv)
static struct option long_options[] = {
{"type", required_argument, 0, 't'},
{"idx", required_argument, 0, 'i'},
+ {"store", required_argument, 0, 's'},
{"version", no_argument, 0, 'v'},
{"debug", no_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "t:i:vdh",
+ c = getopt_long(argc, argv, "t:i:s:vdh",
long_options, &option_index);
if (c == -1)
@@ -147,6 +173,11 @@ static int get_args(int argc, char **argv)
}
break;
+ case 's':
+ storage_file = optarg;
+ store = 1;
+ break;
+
case 'v':
printf("tsnif "CONFIG_TSNIF_VER"\n");
break;
@@ -208,9 +239,14 @@ int main(int argc, char **argv)
return err;
if ((ret = setjmp(env))) {
+ if (ret > 2) {
+ set_term(1);
+ if (store)
+ tsnif_storage_close(&storage_handle);
+ }
+
if (ret > 1) {
tsnif_detach(&term);
- set_term(1);
}
tsnif_close(&handle);
@@ -218,6 +254,7 @@ int main(int argc, char **argv)
return err;
}
+ /* attach the term */
err = tsnif_term_add(&handle, &term, type, idx);
if (err)
longjmp(env, 1);
@@ -226,6 +263,13 @@ int main(int argc, char **argv)
if (err)
longjmp(env, 1);
+ /* initialize storage unit if needed */
+ if (store) {
+ err = tsnif_storage_init(&storage_handle, &storage_opts, storage_file);
+ if (err)
+ longjmp(env, 2);
+ }
+
set_term(0);
signal(SIGINT, sig_handler);
@@ -248,12 +292,12 @@ int main(int argc, char **argv)
if (FD_ISSET(ts_fd, &rfds) &&
tsnif_process(&handle))
- longjmp(env, 2);
+ longjmp(env, 3);
if (FD_ISSET(in_fd, &rfds) &&
process_input())
- longjmp(env, 2);
+ longjmp(env, 3);
}
- longjmp(env, 2);
+ longjmp(env, 3);
}