Add send-receive channels
This commit is contained in:
102
adsbus/opts.c
102
adsbus/opts.c
@@ -13,6 +13,7 @@
|
||||
#include "outgoing.h"
|
||||
#include "receive.h"
|
||||
#include "send.h"
|
||||
#include "send_receive.h"
|
||||
|
||||
#include "opts.h"
|
||||
|
||||
@@ -26,7 +27,7 @@ static char *opts_split(char **arg, char delim) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void opts_add_listen(char *host_port, struct flow *flow, void *passthrough) {
|
||||
static bool opts_add_listen(char *host_port, struct flow *flow, void *passthrough) {
|
||||
char *host = opts_split(&host_port, '/');
|
||||
if (host) {
|
||||
incoming_new(host, host_port, flow, passthrough);
|
||||
@@ -34,6 +35,33 @@ static void opts_add_listen(char *host_port, struct flow *flow, void *passthroug
|
||||
} else {
|
||||
incoming_new(NULL, host_port, flow, passthrough);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opts_add_connect(char *host_port, struct flow *flow, void *passthrough) {
|
||||
char *host = opts_split(&host_port, '/');
|
||||
if (!host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outgoing_new(host, host_port, flow, passthrough);
|
||||
free(host);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opts_add_file_write_int(char *path, struct flow *flow, void *passthrough) {
|
||||
file_write_new(path, flow, passthrough);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opts_add_file_append_int(char *path, struct flow *flow, void *passthrough) {
|
||||
file_append_new(path, flow, passthrough);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool opts_add_exec(char *cmd, struct flow *flow, void *passthrough) {
|
||||
exec_new(cmd, flow, passthrough);
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct serializer *opts_get_serializer(char **arg) {
|
||||
@@ -51,46 +79,36 @@ static struct serializer *opts_get_serializer(char **arg) {
|
||||
return serializer;
|
||||
}
|
||||
|
||||
bool opts_add_connect_receive(char *arg) {
|
||||
char *host = opts_split(&arg, '/');
|
||||
if (!host) {
|
||||
static bool opts_add_send(bool (*next)(char *, struct flow *, void *), struct flow *flow, char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return next(arg, flow, serializer);
|
||||
}
|
||||
|
||||
outgoing_new(host, arg, receive_flow, NULL);
|
||||
free(host);
|
||||
return true;
|
||||
bool opts_add_connect_receive(char *arg) {
|
||||
return opts_add_connect(arg, receive_flow, NULL);
|
||||
}
|
||||
|
||||
bool opts_add_connect_send(char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return opts_add_send(opts_add_connect, send_flow, arg);
|
||||
}
|
||||
|
||||
char *host = opts_split(&arg, '/');
|
||||
if (!host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outgoing_new(host, arg, send_flow, serializer);
|
||||
free(host);
|
||||
return true;
|
||||
bool opts_add_connect_send_receive(char *arg) {
|
||||
return opts_add_send(opts_add_connect, send_receive_flow, arg);
|
||||
}
|
||||
|
||||
bool opts_add_listen_receive(char *arg) {
|
||||
opts_add_listen(arg, receive_flow, NULL);
|
||||
return true;
|
||||
return opts_add_listen(arg, receive_flow, NULL);
|
||||
}
|
||||
|
||||
bool opts_add_listen_send(char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return opts_add_send(opts_add_listen, send_flow, arg);
|
||||
}
|
||||
|
||||
opts_add_listen(arg, send_flow, serializer);
|
||||
return true;
|
||||
bool opts_add_listen_send_receive(char *arg) {
|
||||
return opts_add_send(opts_add_listen, send_receive_flow, arg);
|
||||
}
|
||||
|
||||
bool opts_add_file_read(char *arg) {
|
||||
@@ -99,23 +117,19 @@ bool opts_add_file_read(char *arg) {
|
||||
}
|
||||
|
||||
bool opts_add_file_write(char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return opts_add_send(opts_add_file_write_int, send_flow, arg);
|
||||
}
|
||||
|
||||
file_write_new(arg, send_flow, serializer);
|
||||
return true;
|
||||
bool opts_add_file_write_read(char *arg) {
|
||||
return opts_add_send(opts_add_file_write_int, send_receive_flow, arg);
|
||||
}
|
||||
|
||||
bool opts_add_file_append(char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return opts_add_send(opts_add_file_append_int, send_flow, arg);
|
||||
}
|
||||
|
||||
file_append_new(arg, send_flow, serializer);
|
||||
return true;
|
||||
bool opts_add_file_append_read(char *arg) {
|
||||
return opts_add_send(opts_add_file_append_int, send_receive_flow, arg);
|
||||
}
|
||||
|
||||
bool opts_add_exec_receive(char *arg) {
|
||||
@@ -124,13 +138,11 @@ bool opts_add_exec_receive(char *arg) {
|
||||
}
|
||||
|
||||
bool opts_add_exec_send(char *arg) {
|
||||
struct serializer *serializer = opts_get_serializer(&arg);
|
||||
if (!serializer) {
|
||||
return false;
|
||||
}
|
||||
return opts_add_send(opts_add_exec, send_flow, arg);
|
||||
}
|
||||
|
||||
exec_new(arg, send_flow, serializer);
|
||||
return true;
|
||||
bool opts_add_exec_send_receive(char *arg) {
|
||||
return opts_add_send(opts_add_exec, send_receive_flow, arg);
|
||||
}
|
||||
|
||||
bool opts_add_stdin(char __attribute__((unused)) *arg) {
|
||||
|
||||
Reference in New Issue
Block a user