Commit 7acbee3d authored by Niels Möller's avatar Niels Möller
Browse files

*** empty log message ***

Rev: src/client.c:1.27
parent 4712b748
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
*/ */
/* FIXME: Why include stdio? */ /* FIXME: Why include stdio? */
#include <stdio.h> /* #include <stdio.h> */
#include "client.h" #include "client.h"
...@@ -254,28 +254,28 @@ static int do_accept_service(struct packet_handler *c, ...@@ -254,28 +254,28 @@ static int do_accept_service(struct packet_handler *c,
return LSH_FAIL | LSH_DIE; return LSH_FAIL | LSH_DIE;
} }
struct service_request
{
struct ssh_service super;
int service_name;
struct ssh_service *service;
};
/* FIXME: This should be a packet handler */
struct ssh_service *make_accept_service_handler(int service_name, struct ssh_service *make_accept_service_handler(int service_name,
struct ssh_service *service) struct ssh_service *service)
{ {
struct service_request *closure; struct accept_service_handler *closure;
NEW(closure); NEW(closure);
closure->super.init = do_accept_service; closure->super.handler = do_accept_service;
closure->service_name = service_name; closure->service_name = service_name;
closure->service = service; closure->service = service;
return &closure->super; return &closure->super;
} }
struct service_request
{
struct ssh_service super;
int service_name;
struct ssh_service *service;
};
static int do_request_service(struct ssh_service *c, static int do_request_service(struct ssh_service *c,
struct ssh_connection *connection) struct ssh_connection *connection)
{ {
...@@ -283,8 +283,10 @@ static int do_request_service(struct ssh_service *c, ...@@ -283,8 +283,10 @@ static int do_request_service(struct ssh_service *c,
MDEBUG(c); MDEBUG(c);
connection->dispatch[SSH_MSG_SERVICE_ACCEPT] = make_accept_service_handler(...); connection->dispatch[SSH_MSG_SERVICE_ACCEPT]
= make_accept_service_handler(closure->service_name,
closure->service);
return A_WRITE(connection->write, format_service_request(closure->service_name)); return A_WRITE(connection->write, format_service_request(closure->service_name));
} }
...@@ -301,6 +303,7 @@ struct ssh_service *request_service(int service_name, ...@@ -301,6 +303,7 @@ struct ssh_service *request_service(int service_name,
return &closure->super; return &closure->super;
} }
/* Initiate and manage a session */
struct session struct session
{ {
struct ssh_channel super; struct ssh_channel super;
...@@ -330,6 +333,7 @@ static int client_session_die(struct ssh_channel *c, struct abstract_write *writ ...@@ -330,6 +333,7 @@ static int client_session_die(struct ssh_channel *c, struct abstract_write *writ
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Recieve channel data */
static int do_recieve(struct ssh_channel *c, struct abstract_write *write, static int do_recieve(struct ssh_channel *c, struct abstract_write *write,
int type, struct lsh_string *data) int type, struct lsh_string *data)
{ {
...@@ -357,15 +361,16 @@ static int do_recieve(struct ssh_channel *c, struct abstract_write *write, ...@@ -357,15 +361,16 @@ static int do_recieve(struct ssh_channel *c, struct abstract_write *write,
fatal("Internal error!\n"); fatal("Internal error!\n");
} }
} }
/* We have a remote shell */ /* We have a remote shell */
static int do_start_session(struct ssh_channel *c, struct abstract_write *write) static int do_shell(struct ssh_channel *c, struct abstract_write *write)
{ {
struct session *closure = (struct session *) c; struct session *closure = (struct session *) c;
MDEBUG(closure); MDEBUG(closure);
closure->super.recieve = do_recieve; closure->super.recieve = do_recieve;
closure->in->handler = read_data
} }
/* We have opened a channel of type "session" */ /* We have opened a channel of type "session" */
...@@ -384,6 +389,30 @@ static int do_open_confirm(struct ssh_channel *c, struct abstract_write *write) ...@@ -384,6 +389,30 @@ static int do_open_confirm(struct ssh_channel *c, struct abstract_write *write)
return A_WRITE(write, format_channel_request(ATOM_SHELL, c, 1, "")); return A_WRITE(write, format_channel_request(ATOM_SHELL, c, 1, ""));
} }
struct ssh_channel *make_session(struct io_fd *in,
abstract_write *out, abstract_write *err)
{
struct session *self;
NEW(self);
self->super.request_types = make_alist(0, -1);
self->super.recieve = NULL;
self->super.close = NULL;
self->super.eof = NULL;
self->super.open_confirm = do_open_confirm;
self->super.open_failure = client_session_die;
self->super.channel_success = NULL;
self->super.channel_failure = NULL;
self->expect_close = 0;
self->in = in;
self->out = out;
self->err = err;
return &self->super;
}
struct client_startup struct client_startup
{ {
struct connection_startup super; struct connection_startup super;
...@@ -393,23 +422,30 @@ struct client_startup ...@@ -393,23 +422,30 @@ struct client_startup
}; };
static int do_client_startup(struct connection_startup *c, static int do_client_startup(struct connection_startup *c,
struct channel_table *table, struct channel_table *table,
struct abstract_write *write) struct abstract_write *write)
{ {
struct client_startup *closure = (struct client_startup *) c; struct client_startup *closure = (struct client_startup *) c;
MDEBUG(closure); MDEBUG(closure);
A_WRITE(write, prepare_channel_open(table, ATOM_SESSION,
} }
/* Request opening a session. */ /* Request opening a session. */
struct connection_startup *make_client_startup(int want_shell) struct connection_startup *make_client_startup(struct io_fd in,
struct abstract_write out,
struct abstract_write err,
int want_shell)
{ {
struct client_startup *closure; struct client_startup *closure;
struct ssh_channel *session;
NEW(closure); NEW(closure);
closure->super.start = do_client_startup; closure->super.start = do_client_startup;
closure->session = make_session(in, out, err);
closure->shell = want_shell; closure->shell = want_shell;
return &closure->super; return &closure->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