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

Use the read_line abstraction.

Rev: src/client.c:1.2
parent 7c7ba170
...@@ -21,57 +21,32 @@ static int client_initiate(struct client_callback *closure, ...@@ -21,57 +21,32 @@ static int client_initiate(struct client_callback *closure,
io_read(closure->backend, fd, make_client_read_line()); io_read(closure->backend, fd, make_client_read_line());
} }
/* This limit follows the ssh specification */ struct client_line_handler
#define MAX_LINE 255
/* FIXME: Abstract this out, so that it can be used by the server as
* well. */
static int do_read_line(struct ... *closure, struct abstract_read *read)
{ {
int n = A_READ(read, closure->line, MAX_LINE - closure->pos); struct line_handler super;
UINT8 *eol; struct session *session;
UINT32 length; };
if (n<0)
{
werror("do_read_1: read() failed, %s\n", strerror(errno));
return 0;
}
closure->pos += n;
/* Check for eol */ static struct read_handler *do_line(struct client_line_handler *closure,
eol = memchr(closure->buffer, '\n', closure->pos); UINT32 length,
if (!eol) UINT8 *line)
{ {
if (closure->pos == MAX_LINE) if ( (length >= 4) && !memcmp(line, "SSH-", 4))
{
werror("Too long line from server\n");
return NULL;
}
return closure;
}
if ( (eol > closure->buffer)
&& (eol[-1] == '\r'))
eol--;
length = eol - closure->buffer;
if ( (length >= 4) && !memcmp(closure->buffer, "SSH-", 4))
{ {
/* Parse and remember format string */ /* Parse and remember format string */
if ( ((length >= 8) && !memcmp(closure->buffer + 4, "2.0-", 4)) if ( ((length >= 8) && !memcmp(line + 4, "2.0-", 4))
|| ((length >= 9) && !memcmp(closure->buffer +4, "1.99-", 5))) || ((length >= 9) && !memcmp(line + 4, "1.99-", 5)))
{ {
session->recieved_version = ssh_format("%s", length, closure->buffer); closure->session->recieved_version
= ssh_format("%s", length, line);
/* FIXME: Unget any extra data */
/* return a new read-handler */ /* return a new read-handler */
return 0; return ...
} }
else else
{ {
werror("Unsupported protocol version: "); werror("Unsupported protocol version: ");
werror_safe(length, closure->buffer); werror_safe(length, line);
werror("\n"); werror("\n");
return 0; return 0;
} }
...@@ -79,9 +54,7 @@ static int do_read_line(struct ... *closure, struct abstract_read *read) ...@@ -79,9 +54,7 @@ static int do_read_line(struct ... *closure, struct abstract_read *read)
else else
{ {
/* Display line */ /* Display line */
werror_safe(length, closure->buffer); werror_safe(length, line);
memcpy(closure->buffer, closure->buffer + length, length);
closure->pos = 0;
/* Read next line */ /* Read next line */
return closure; return closure;
......
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