Commit 4f797ec6 authored by Niels Möller's avatar Niels Möller
Browse files

* src/tcpforward_commands.c (open_forwarded_tcpip): Redefined

using DEFINE_COMMAND2.
(open_direct_tcpip): Likewise.
(remote_listen_command): Likewise.
(make_request_tcpip_forward_command): Deleted function. Moved code
to remote_listen_command.
(make_direct_tcpip_handler): Redefined using DEFINE_COMMAND.
(make_tcpip_forward_handler): Likewise.

Rev: src/tcpforward_commands.c:1.30
parent edaf6a36
...@@ -37,25 +37,28 @@ ...@@ -37,25 +37,28 @@
/* Forward declarations */ /* Forward declarations */
extern struct collect_info_1 open_direct_tcpip; extern struct command_2 open_direct_tcpip;
extern struct collect_info_1 remote_listen_command; extern struct command_2 remote_listen_command;
extern struct collect_info_1 open_forwarded_tcpip; extern struct command_2 open_forwarded_tcpip;
extern struct command tcpip_start_io; extern struct command tcpip_start_io;
extern struct command tcpip_connect_io; extern struct command tcpip_connect_io;
struct collect_info_1 install_direct_tcpip_handler; struct collect_info_1 install_direct_tcpip_handler;
struct collect_info_1 install_forwared_tcpip_handler; struct collect_info_1 install_forwared_tcpip_handler;
static struct command make_direct_tcpip_handler; /* FIXME: Should be static? */
struct command make_direct_tcpip_handler;
struct collect_info_1 install_tcpip_forward_handler; struct collect_info_1 install_tcpip_forward_handler;
static struct command make_tcpip_forward_handler;
#define OPEN_DIRECT_TCPIP (&open_direct_tcpip.super.super.super) /* FIXME: Should be static? */
#define REMOTE_LISTEN (&remote_listen_command.super.super.super) struct command make_tcpip_forward_handler;
#define OPEN_DIRECT_TCPIP (&open_direct_tcpip.super.super)
#define REMOTE_LISTEN (&remote_listen_command.super.super)
#define TCPIP_START_IO (&tcpip_start_io.super) #define TCPIP_START_IO (&tcpip_start_io.super)
#define TCPIP_CONNECT_IO (&tcpip_connect_io.super) #define TCPIP_CONNECT_IO (&tcpip_connect_io.super)
#define OPEN_FORWARDED_TCPIP (&open_forwarded_tcpip.super.super.super) #define OPEN_FORWARDED_TCPIP (&open_forwarded_tcpip.super.super)
#define DIRECT_TCPIP_HANDLER (&make_direct_tcpip_handler.super) #define DIRECT_TCPIP_HANDLER (&make_direct_tcpip_handler.super)
#define INSTALL_DIRECT_TCPIP (&install_direct_tcpip_handler.super.super.super) #define INSTALL_DIRECT_TCPIP (&install_direct_tcpip_handler.super.super.super)
...@@ -188,46 +191,36 @@ make_open_tcpip_command(int type, UINT32 initial_window, ...@@ -188,46 +191,36 @@ make_open_tcpip_command(int type, UINT32 initial_window,
return &self->super.super; return &self->super.super;
} }
static struct lsh_object * DEFINE_COMMAND2(open_forwarded_tcpip)
collect_open_forwarded_tcpip(struct collect_info_2 *info, (struct lsh_object *a1,
struct lsh_object *a, struct lsh_object *a2,
struct lsh_object *b) struct command_continuation *c,
struct exception_handler *e UNUSED)
{ {
CAST(address_info, local, a); CAST(address_info, local, a1);
CAST(listen_value, peer, b); CAST(listen_value, peer, a2);
assert(!info->next); COMMAND_RETURN(c,
make_open_tcpip_command(ATOM_FORWARDED_TCPIP,
return &make_open_tcpip_command(ATOM_FORWARDED_TCPIP, TCPIP_WINDOW_SIZE, TCPIP_WINDOW_SIZE,
local, peer)->super; local, peer));
} }
static struct collect_info_2 collect_open_forwarded_tcpip_2 = DEFINE_COMMAND2(open_direct_tcpip)
STATIC_COLLECT_2_FINAL(collect_open_forwarded_tcpip); (struct lsh_object *a1,
struct lsh_object *a2,
struct collect_info_1 open_forwarded_tcpip = struct command_continuation *c,
STATIC_COLLECT_1(&collect_open_forwarded_tcpip_2); struct exception_handler *e UNUSED)
static struct lsh_object *
collect_open_direct_tcpip(struct collect_info_2 *info,
struct lsh_object *a,
struct lsh_object *b)
{ {
CAST(address_info, local, a); CAST(address_info, local, a1);
CAST(listen_value, peer, b); CAST(listen_value, peer, a2);
assert(!info->next); COMMAND_RETURN(c,
make_open_tcpip_command(ATOM_DIRECT_TCPIP,
return &make_open_tcpip_command(ATOM_DIRECT_TCPIP, TCPIP_WINDOW_SIZE, TCPIP_WINDOW_SIZE,
local, peer)->super; local, peer));
} }
static struct collect_info_2 collect_open_direct_tcpip_2 =
STATIC_COLLECT_2_FINAL(collect_open_direct_tcpip);
struct collect_info_1 open_direct_tcpip =
STATIC_COLLECT_1(&collect_open_direct_tcpip_2);
/* Requesting remote forwarding of a port */ /* Requesting remote forwarding of a port */
...@@ -324,41 +317,32 @@ do_format_request_tcpip_forward(struct global_request_command *s, ...@@ -324,41 +317,32 @@ do_format_request_tcpip_forward(struct global_request_command *s,
return format_global_request(ATOM_TCPIP_FORWARD, want_reply, "%S%i", return format_global_request(ATOM_TCPIP_FORWARD, want_reply, "%S%i",
self->port->ip, self->port->port); self->port->ip, self->port->port);
} }
static struct command *
make_request_tcpip_forward_command(struct command *callback,
struct address_info *listen)
{
NEW(request_tcpip_forward_command, self);
debug("tcpforward_commands.c: make_request_tcpip_forward_command\n");
self->super.super.call = do_channel_global_command;
self->super.format_request = do_format_request_tcpip_forward;
self->callback = callback;
self->port = listen;
return &self->super.super;
}
static struct lsh_object * DEFINE_COMMAND2(remote_listen_command)
collect_remote_listen(struct collect_info_2 *info, (struct lsh_object *a1,
struct lsh_object *a, struct lsh_object *b) struct lsh_object *a2,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{ {
CAST_SUBTYPE(command, callback, a); trace("remote_listen_command\n");
CAST(address_info, port, b);
assert(!info->next); {
CAST_SUBTYPE(command, callback, a1);
return &make_request_tcpip_forward_command(callback, port)->super; CAST(address_info, port, a2);
NEW(request_tcpip_forward_command, self);
self->super.super.call = do_channel_global_command;
self->super.format_request = do_format_request_tcpip_forward;
self->callback = callback;
self->port = port;
COMMAND_RETURN(c, self);
}
} }
static struct collect_info_2 collect_info_remote_listen_2 =
STATIC_COLLECT_2_FINAL(collect_remote_listen);
static struct collect_info_1 remote_listen_command =
STATIC_COLLECT_1(&collect_info_remote_listen_2);
/* Cancel a remotely forwarded port. /* Cancel a remotely forwarded port.
* FIXME: Not implemented */ * FIXME: Not implemented */
...@@ -433,11 +417,11 @@ make_forward_remote_port(struct io_backend *backend, ...@@ -433,11 +417,11 @@ make_forward_remote_port(struct io_backend *backend,
/* Takes a callback function and returns a channel_open /* Takes a callback function and returns a channel_open
* handler. */ * handler. */
static void DEFINE_COMMAND(make_direct_tcpip_handler)
do_make_direct_tcpip_handler(struct command *s UNUSED, (struct command *s UNUSED,
struct lsh_object *x, struct lsh_object *x,
struct command_continuation *c, struct command_continuation *c,
struct exception_handler *e UNUSED) struct exception_handler *e UNUSED)
{ {
CAST_SUBTYPE(command, callback, x); CAST_SUBTYPE(command, callback, x);
...@@ -447,27 +431,26 @@ do_make_direct_tcpip_handler(struct command *s UNUSED, ...@@ -447,27 +431,26 @@ do_make_direct_tcpip_handler(struct command *s UNUSED,
&make_channel_open_direct_tcpip(callback)->super); &make_channel_open_direct_tcpip(callback)->super);
} }
static struct command
make_direct_tcpip_handler = STATIC_COMMAND(do_make_direct_tcpip_handler);
/* Takes a callback function and returns a global_request handler. */ /* Takes a callback function and returns a global_request handler. */
static void DEFINE_COMMAND(make_tcpip_forward_handler)
do_make_tcpip_forward_handler(struct command *s UNUSED, (struct command *s UNUSED,
struct lsh_object *x, struct lsh_object *x,
struct command_continuation *c, struct command_continuation *c,
struct exception_handler *e UNUSED) struct exception_handler *e UNUSED)
{ {
CAST_SUBTYPE(command, callback, x); CAST_SUBTYPE(command, callback, x);
debug("tcpforward_commands.c: do_make_tcpip_forward_handler\n"); debug("tcpforward_commands.c: make_tcpip_forward_handler\n");
COMMAND_RETURN(c, COMMAND_RETURN(c,
&make_tcpip_forward_request(callback)->super); &make_tcpip_forward_request(callback)->super);
} }
#if 0
static struct command static struct command
make_tcpip_forward_handler make_tcpip_forward_handler
= STATIC_COMMAND(do_make_tcpip_forward_handler); = STATIC_COMMAND(do_make_tcpip_forward_handler);
#endif
/* Commands to install handlers */ /* Commands to install handlers */
...@@ -519,6 +502,7 @@ STATIC_COLLECT_1(&install_tcpip_forward_info_2.super); ...@@ -519,6 +502,7 @@ STATIC_COLLECT_1(&install_tcpip_forward_info_2.super);
/* GABA: /* GABA:
(expr (expr
(name tcpip_forward_hook) (name tcpip_forward_hook)
; FIXME: Don't use globals.
(globals (globals
(install "&install_tcpip_forward_handler.super.super.super") (install "&install_tcpip_forward_handler.super.super.super")
(handler "&make_tcpip_forward_handler.super")) (handler "&make_tcpip_forward_handler.super"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment