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

Cleaned up and deleted old dead code.

Rev: src/abstract_io.h:1.32
Rev: src/channel.c:1.56
Rev: src/channel.h:1.43
Rev: src/channel_commands.c:1.16
Rev: src/client.c:1.75
Rev: src/command.c:1.26
Rev: src/gc.c:1.11
Rev: src/gc.h:1.6
Rev: src/io.c:1.76
Rev: src/lsh.c:1.71
Rev: src/lsh.h:1.8
Rev: src/lsh_writekey.c:1.13
Rev: src/lshd.c:1.62
Rev: src/read_data.c:1.24
Rev: src/read_packet.c:1.44
Rev: src/read_scan.c:1.9(DEAD)
Rev: src/read_scan.h:1.9(DEAD)
Rev: src/server_password.c:1.24
Rev: src/service.h:1.17
Rev: src/sexp_conv.c:1.3
Rev: src/sexp_parser.c:1.9
Rev: src/sexp_streamed_parser.c:1.11
Rev: src/tcpforward_commands.c:1.12
Rev: src/tcpforward_commands.h:1.4
Rev: src/werror.c:1.35
parent 60e58432
......@@ -50,29 +50,6 @@
(next object abstract_write)))
*/
#if 0
/* A read-function returning n means:
*
* n > 0: n bytes were read successfully.
* n = 0: No more data available, without blocking.
* n = -1: Read failed.
* n = -2: EOF.
*/
#define A_FAIL -1
#define A_EOF -2
/* ;; GABA:
(class
(name abstract_read)
(vars
;; FIXME: Should we allow that the read method is called with
;; length = 0? I think so.
(read indirect-method int
"UINT32 length" "UINT8 *buffer")))
*/
#define A_READ(f, length, buffer) (f)->read(&(f), (length), (buffer))
#endif
/* May store a new handler into *h. */
......@@ -95,42 +72,4 @@
#define READ_HANDLER(h, l, d) ((h)->handler(&(h), (l), (d)))
/* ;;GABA:
(class
(name read_consumer)
(vars
; Returns the maximum number of octets that
; can be consumed immediately.
(query method UINT32)
(consume object abstract_write)))
*/
#if 0
#define READ_QUERY(c) ((c)->query((c)))
#define READ_CONSUME(c, s) A_WRITE(c->consume, s)
#endif
#if 0
/* ;; GABA:
(class
(name read_handler)
(vars
(handler indirect-method void "struct abstract_read *read")))
;; "struct exception_handler *io")))
*/
#define READ_HANDLER(h, read) ((h)->handler(&(h), (read)))
#endif
#if 0
/* Return values */
/* Everything's fine */
#define READ_OK 0
/* Can't process any more data right now; please hold */
#define READ_HOLD 1
/* Close nicely, after flushing the write buffer */
#define READ_CLOSE 2
/* Close immediately */
#define READ_DIE 3
#endif
#endif /*LSH_ABSTRACT_IO_H_INCLUDED */
......@@ -391,61 +391,6 @@ void channel_start_receive(struct ssh_channel *channel)
(channel, channel->max_window - channel->rec_window_size));
}
#if 0
/* Process channel-related status codes. Used by the packet handlers,
* before returning. */
static int channel_process_status(struct channel_table *table,
int channel,
int status)
{
struct ssh_channel *c = table->channels[channel];
while (!LSH_CLOSEDP(status))
{
if (status & LSH_CHANNEL_CLOSE)
{ /* Close the channel now */
if (!c->flags & CHANNEL_SENT_CLOSE)
status |= channel_close(c);
break;
}
if (status & LSH_CHANNEL_READY_SEND)
{
status &= ~ LSH_CHANNEL_READY_SEND;
if (c->send_window_size)
status |= CHANNEL_SEND(c);
}
else if (status & LSH_CHANNEL_READY_REC)
{
status &= ~ LSH_CHANNEL_READY_REC;
status |= channel_start_receive(c);
}
else
break;
}
if (status & LSH_CHANNEL_FINISHED)
{
/* Clear this bit */
status &= ~LSH_CHANNEL_FINISHED;
if (c->close)
status |= CHANNEL_CLOSE(c);
dealloc_channel(table, channel);
}
if (status & LSH_CHANNEL_PENDING_CLOSE)
table->pending_close = 1;
/* If this was the last channel, close connection */
if (table->pending_close && !table->next_channel)
status |= LSH_CLOSE;
return status;
}
#endif
/* Ugly macros to make it a little simpler to free the input packet at
* the right time. */
......@@ -455,11 +400,6 @@ static int channel_process_status(struct channel_table *table,
lsh_string_free((s)); \
return; } while(0)
#if 0
#define ERROR(e, msg) \
EXCEPTION_RAISE(e, make_protocol_exception \
(SSH_DISCONNECT_PROTOCOL_ERROR, msg))
#endif
/* Channel related messages */
......@@ -639,81 +579,6 @@ do_global_request_failure(struct packet_handler *s UNUSED,
END(packet);
}
#if 0
/* HERE!!! */
/* FIXME: Split into a continuation and an exception handler */
/* Callback given to the CHANNEL_OPEN method */
static int do_channel_open_response(struct channel_open_callback *c,
struct ssh_channel *channel,
UINT32 error, char *error_msg,
struct lsh_string *args)
{
CAST(channel_open_response, closure, c);
int local_channel_number;
if (!channel)
{
if (error)
C_WRITE(closure->super.connection->write,
format_open_failure(closure->remote_channel_number,
error, error_msg, ""));
else
EXCEPTION_RAISE(closure->super.connection->e,
make_protocol_exception())
return LSH_FAIL | LSH_DIE;
}
/* FIXME: It would be better to allocate or at least reserve a channel number earlier,
* so that we can't fail at this point.
*/
if ( (local_channel_number
= register_channel(closure->super.connection,
channel)) < 0)
{
werror("Could not allocate a channel number for opened channel!\n");
return A_WRITE(closure->super.connection->write,
format_open_failure(closure->remote_channel_number,
SSH_OPEN_RESOURCE_SHORTAGE,
"Could not allocate a channel number "
"(shouldn't happen...)", ""));
}
/* FIXME: This copying could just as well be done by the
* CHANNEL_OPEN handler? Then we can remove the corresponding fields
* from the closure as well. */
channel->send_window_size = closure->window_size;
channel->send_max_packet = closure->max_packet;
channel->channel_number = closure->remote_channel_number;
/* FIXME: Is the channel->write field really needed? */
channel->write = closure->super.connection->write;
return A_WRITE(closure->super.connection->write,
args
? format_open_confirmation(channel, local_channel_number,
"%lfS", args)
: format_open_confirmation(channel, local_channel_number,
""));
}
static struct channel_open_response *
make_channel_open_response(struct ssh_connection* connection,
UINT32 remote_channel_number,
UINT32 window_size,
UINT32 max_packet)
{
NEW(channel_open_response, closure);
closure->super.response = do_channel_open_response;
closure->super.connection = connection;
closure->remote_channel_number = remote_channel_number;
closure->window_size = window_size;
closure->max_packet = max_packet;
return closure;
}
#endif
/* GABA:
(class
......@@ -1543,19 +1408,6 @@ do_connection_service(struct command *s UNUSED,
COMMAND_RETURN(c, connection);
}
#if 0
struct command *make_connection_service(struct alist *global_requests,
struct alist *channel_types)
{
NEW(connection_service, self);
self->super.call = do_connection_service;
self->global_requests = global_requests;
self->channel_types = channel_types;
return &self->super;
}
#endif
struct command
connection_service = STATIC_COMMAND(do_connection_service);
......
......@@ -197,9 +197,6 @@
))
*/
#if 0
#define CHANNEL_EXC_HANDLER(c) (&((c)->table.super))
#endif
/* SSH_MSG_GLOBAL_REQUEST */
......@@ -239,25 +236,6 @@
struct exception *make_channel_open_exception(UINT32 error_code, char *msg);
#if 0
/* Callback function, used to report success or failure for a
* requested channel open. */
/* ;;GABA:
(class
(name channel_open_callback)
(vars
(response method int
"struct ssh_channel *channel"
"UINT32 error"
"char *error_msg"
"struct lsh_string *args")
(connection object ssh_connection)))
*/
#define CHANNEL_OPEN_CALLBACK(c, ch, e, m, a) \
(c)->response((c), (ch), (e), (m), (a))
#endif
/* GABA:
(class
......@@ -361,9 +339,5 @@ struct lsh_string *channel_transmit_extended(struct ssh_channel *channel,
extern struct command connection_service;
#if 0
struct command *make_connection_service(struct alist *global_requests,
struct alist *channel_types);
#endif
#endif /* LSH_CHANNEL_H_INCLUDED */
......@@ -24,6 +24,7 @@
#include "channel_commands.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
......
......@@ -382,37 +382,27 @@ do_client_io(struct command *s UNUSED,
struct exception_handler *e UNUSED)
{
CAST(client_session, session, x);
struct ssh_channel *channel = &session->super;
assert(x);
#if 0
if (!x)
{
werror("do_client_io: Starting shell failed.\n");
return LSH_CHANNEL_CLOSE | LSH_FAIL;
}
else
#endif
{
CAST(client_session, session, x);
struct ssh_channel *channel = &session->super;
channel->receive = do_receive;
channel->receive = do_receive;
session->out->super.close_callback
= session->err->super.close_callback = make_channel_close(channel);
session->out->super.close_callback
= session->err->super.close_callback = make_channel_close(channel);
session->in->super.read = make_channel_read_data(channel);
session->in->super.read = make_channel_read_data(channel);
channel->send = do_send_first;
channel->send = do_send_first;
ALIST_SET(channel->request_types, ATOM_EXIT_STATUS,
make_handle_exit_status(session->exit_status));
ALIST_SET(channel->request_types, ATOM_EXIT_SIGNAL,
make_handle_exit_signal(session->exit_status));
ALIST_SET(channel->request_types, ATOM_EXIT_STATUS,
make_handle_exit_status(session->exit_status));
ALIST_SET(channel->request_types, ATOM_EXIT_SIGNAL,
make_handle_exit_signal(session->exit_status));
channel->eof = do_client_session_eof;
channel->eof = do_client_session_eof;
COMMAND_RETURN(c, channel);
}
COMMAND_RETURN(c, channel);
}
struct command client_io =
......
......@@ -162,24 +162,6 @@ struct lsh_object *collect_trace(const char *name, struct lsh_object *c)
return &make_trace(name, real)->super;
}
#if 0
/* This command should be obsoleted by the exception mechanism */
/* Fail if NULL. This commands returns its argument unchanged. Unless
* it is NULL, in which case it doesn't return at all, but instead
* returns an LSH_FAIL status to the mainloop. */
static int
do_command_die_on_null(struct command *s UNUSED,
struct lsh_object *x,
struct command_continuation *c,
struct exception_handler *e)
{
return x ? COMMAND_RETURN(c, x) : LSH_FAIL | LSH_DIE;
}
struct command command_die_on_null =
{ STATIC_HEADER, do_command_die_on_null};
#endif
/* Collecting arguments */
struct lsh_object *
......
......@@ -35,9 +35,6 @@ static struct lsh_object *all_objects = NULL;
static unsigned number_of_objects = 0;
static unsigned live_objects = 0;
#if 0
static struct lsh_object *globals = NULL;
#endif
#if DEBUG_ALLOC
static void sanity_check_object_list(void)
......
......@@ -28,10 +28,6 @@
#include "lsh.h"
#if 0
void gc_register_global(struct lsh_object *o);
#endif
void gc_register(struct lsh_object *o);
void gc_kill(struct lsh_object *o);
......
......@@ -265,61 +265,6 @@ int io_iter(struct io_backend *b)
}
/* ;;GABA:
(class
(name fd_read)
(super abstract_read)
(vars
(fd object lsh_fd)))
*/
#if 0
static int do_read(struct abstract_read **r, UINT32 length, UINT8 *buffer)
{
CAST(fd_read, closure, *r);
if (!length)
{
werror("io.c: do_read(): Zero length read was requested.\n");
return 0;
}
for (;;)
{
int res;
if (! (closure->fd->super.alive && closure->fd->want_read) )
return 0;
if (! (res = read(closure->fd->fd, buffer, length)) )
{
debug("Read EOF on fd %i.\n", closure->fd->fd);
return A_EOF;
}
if (res > 0)
return res;
switch(errno)
{
case EINTR:
continue; /* FIXME: Is it really worth looping here,
* instead of in the select loop? */
case EWOULDBLOCK: /* aka EAGAIN */
return 0;
case EPIPE:
werror("io.c: read() returned EPIPE! Treating it as EOF.\n");
return A_EOF;
default:
werror("io.c: do_read: read() failed (errno %i), %z\n",
errno, STRERROR(errno));
debug(" fd = %i, buffer = %xi, length = %i\n",
closure->fd, buffer, length);
return A_FAIL;
}
}
}
#endif
static void do_buffered_read(struct io_read_callback *s,
struct lsh_fd *fd)
{
......@@ -455,103 +400,6 @@ void init_consuming_read(struct io_consuming_read *self,
self->consumer = consumer;
}
#if 0
static void read_callback(struct lsh_fd *fd)
{
CAST(io_fd, self, fd);
int res;
assert(self->read_buffer);
res = read_buffer_fill_fd(self->read_buffer_fill_fd, fd->fd);
if (res < 0)
switch(errno)
{
case EINTR:
return;
case EWOULDBLOCK:
werror("io.c: read_callback: Unexpected EWOULDBLOCK\n");
case EPIPE:
fatal("EPIPE should probably be handled as EOF. Not implemented.\n");
default:
EXCEPTION_RAISE(fd->e, fd,
make_io_exception(EXC_IO_READ),
errno, NULL);
}
while (fd->super.alive && fd->want_read)
{
if (!read_buffer_flush())
{
EXCEPTION_RAISE(fd->e, make_io_exception(EXC_IO_EOF, fd, 0, "EOF"));
break;
}
}
read_buffer_justify(self->read_buffer);
assert(!(self->read_buffer->start
&& fd->super.alive && fd->want_read));
}
static void read_callback(struct lsh_fd *fd)
{
CAST(io_fd, self, fd);
int res;
struct fd_read r =
{ { STACK_HEADER, do_read }, fd->fd };
/* The handler function may install a new handler */
res = READ_HANDLER(self->handler,
&r.super);
/* NOTE: These flags are not mutually exclusive. All combinations
* must be handled correctly. */
/* NOTE: (i) If LSH_DIE is set, LSH_CLOSE is ignored. (ii) If the fd
* is read_only, LSH_CLOSE is the same as LSH_DIE. */
/* This condition must be taken care of earlier. */
assert(!(res & LSH_CHANNEL_FINISHED));
/* Not implemented */
assert(!(res & LSH_KILL_OTHERS));
if (res & LSH_HOLD)
{
/* This flag should not be combined with anything else */
assert(res == LSH_HOLD);
fd->want_read = 0;
}
if (res & LSH_DIE)
{
if (self->buffer)
write_buffer_close(self->buffer);
close_fd(fd,
LSH_FAILUREP(res) ? CLOSE_PROTOCOL_FAILURE : 0);
}
else if (res & LSH_CLOSE)
{
if (self->buffer)
{
write_buffer_close(self->buffer);
/* Don't attempt to read any further. */
/* FIXME: Is it safe to free the handler here? */
self->super.want_read = 0;
self->handler = NULL;
}
else
kill_fd(fd);
fd->close_reason
= LSH_FAILUREP(res) ? CLOSE_PROTOCOL_FAILURE : CLOSE_EOF;
}
}
#endif
static void write_callback(struct lsh_fd *fd)
{
......@@ -743,36 +591,11 @@ static void init_file(struct io_backend *b, struct lsh_fd *f, int fd,
* used to read key-files, so that change probably has to wait until
* the parser is rewritten. */
#if 0
/* ;; GABA:
(class
(name blocking_read_exception_handler)
(super exception_handler)
(vars
(flag . int)))
*/
static void
do_blocking_read_handler(struct exception_handler *s,
const struct exception *e UNUSED)
{
CAST(blocking_read_exception_handler, self, s);
self->flag = 1;
}
#endif
#define BLOCKING_READ_SIZE 4096
int blocking_read(int fd, struct read_handler *handler)
{
#if 0
struct blocking_read_exception_handler exc_handler =
{
{ STACK_HEADER, do_blocking_read_handler },
0
};
#endif
{
char *buffer = alloca(BLOCKING_READ_SIZE);
for (;;)
......@@ -1252,10 +1075,6 @@ struct io_fd *io_read_write(struct io_fd *fd,
/* Reading */
fd->super.read = read;
fd->super.want_read = !!read;
#if 0
fd->handler = handler;
fd->read_buffer = make_fd_read_buffer(READ_BUFFER_SIZE);
#endif
/* Writing */
fd->super.prepare = prepare_write;
......@@ -1278,10 +1097,6 @@ struct io_fd *io_read(struct io_fd *fd,
/* Reading */
fd->super.want_read = !!read;
fd->super.read = read;
#if 0
fd->handler = handler;
fd->read_buffer = make_fd_read_buffer(READ_BUFFER_SIZE);
#endif
fd->super.close_callback = close_callback;
......
......@@ -235,15 +235,6 @@ do_lsh_default_handler(struct exception_handler *s,
case EXC_IO_EOF:
close_fd_nicely(exc->fd, 0);
break;
#if 0
case EXC_IO_CONNECT:
case EXC_IO_READ:
case EXC_IO_WRITE:
if (exc->fd)
close_fd(exc->fd, 0);
*self->status = EXIT_FAILURE;
break;
#endif
default:
*self->status = EXIT_FAILURE;
EXCEPTION_RAISE(self->super.parent, e);
......
......@@ -110,83 +110,5 @@ struct callback
#define CALLBACK(c) ((c)->f(c))
#if 0
/* Return values.
*
* Every handler should return one or more of these values, or-ed together.
* Zero means everything is ok.
*/
/* Success/fail indication. LSH_FAIL should always be combined with
* LSH_DIE or LSH_CLOSE. */
#define LSH_OK 0