diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-05-13 23:43:10 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-05-13 23:43:10 +0200 |
commit | 3e854ba53063062a4824966ae1b6c93e6100cea4 (patch) | |
tree | dd5de5c014018d7c4ba50dde77d886d2f1c42d10 /src/protocol.c | |
parent | d336c8771f617df35c43f28feae6c3f83512deaf (diff) |
POTD skeleton #49.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/protocol.c')
-rw-r--r-- | src/protocol.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/protocol.c b/src/protocol.c new file mode 100644 index 0000000..0bea5a3 --- /dev/null +++ b/src/protocol.c @@ -0,0 +1,49 @@ +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "protocol.h" +#include "log.h" +#include "socket.h" + + +int proto_init_ctx(protocol_ctx **ctx, proto_init_cb init_fn) +{ + assert(ctx && init_fn); + if (!*ctx) + *ctx = (protocol_ctx *) malloc(sizeof(**ctx)); + assert(*ctx); + + memset(*ctx, 0, sizeof(**ctx)); + if (init_fn(*ctx)) + return 1; + + return 0; +} + +int proto_setup(protocol_ctx *ctx, const char *listen_addr, + const char *listen_port, const char *jail_host, + const char *jail_port) +{ + assert(ctx); + + if (fwd_setup_server(&ctx->src, listen_addr, listen_port)) + return 1; + if (fwd_setup_client_silent(&ctx->dst, jail_host, jail_port)) + return 1; + + if (!ctx->cbs.on_listen) + return 1; + if (ctx->cbs.on_listen(ctx, listen_addr, listen_port)) + return 1; + + return 0; +} + +int proto_validate_ctx(const protocol_ctx *ctx) +{ + assert(ctx); + assert(ctx->cbs.on_listen && ctx->cbs.on_shutdown); + + return 0; +} |