Commit e80942e0 authored by Niels Möller's avatar Niels Möller

*** empty log message ***

Rev: src/server.c:1.1
Rev: src/server.h:1.1
parent b9090ff9
/* server.c
*
*/
#include "server.h"
#include "version.h"
#include "connection.h"
#include "abstract_io.h"
#include "read_line.h"
#include "read_packet.h"
#include "debug.h"
#include "format.h"
#include "werror.h"
#include "void.h"
#include "xalloc.h"
struct read_handler *make_server_read_line();
struct callback *make_server_close_handler();
static int server_initiate(struct server_callback *closure,
int fd)
{
struct ssh_connection *connection = ssh_connection_alloc();
struct abstract_write *write =
io_read_write(closure->backend, fd,
make_server_read_line(),
closure->block_size,
make_server_close_handler());
connection->server_version
= ssh_format("SSH-%z-%z %z\r\n",
PROTOCOL_VERSION,
SOFTWARE_SERVER_VERSION,
closure->id_comment);
/* Copies the version string, so that it is isn't freed */
return A_WRITE(write, ssh_format("%lS", connection->server_version));
}
struct server_line_handler
{
struct line_handler super;
struct ssh_connection *connection;
};
static struct read_handler *do_line(struct server_line_handler *closure,
UINT32 length,
UINT8 *line)
{
if ( (length >= 4) && !memcmp(line, "SSH-", 4))
{
/* Parse and remember format string */
if ((length >= 8) && !memcmp(line + 4, "2.0-", 4))
{
struct read_handler *new
= make_read_packet(make_debug_processor(make_packet_void(),
stderr),
closure->connection->max_packet);
closure->connection->client_version
= ssh_format("%s", length, line);
/* FIXME: Cleanup properly. */
free(closure);
return new;
}
else
{
werror("Unsupported protocol version: ");
werror_safe(length, line);
werror("\n");
fatal("server.c: do_line: Unsupported version.\n");
/* FIXME: What could be returned here? */
return 0;
}
}
else
{
/* Display line */
werror_safe(length, line);
/* Read next line */
return 0;
}
}
/* server.h
*
*/
#ifndef LSH_SERVER_H_INCLUDED
#define LSH_SERVER_H_INCLUDED
#include "io.h"
struct server_callback
{
struct fd_callback super;
struct io_backend *backend;
UINT32 block_size;
char *id_comment;
};
struct fd_callback *make_server_callback(struct io_backend *b,
char *comment,
UINT32 block_size);
#endif /* LSH_SERVER_H_INCLUDED */
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