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

Adapted to new object system and gc.

Rev: src/abstract_io.c:1.1
Rev: src/abstract_io.h:1.18
Rev: src/connection.c:1.17
Rev: src/connection.h:1.18
parent 82a46d98
/* abstract_io.c
*
* This is the layer separating protocol processing from actual io.
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "abstract_io.h"
#define CLASS_DEFINE
#include "abstract_io.h.x"
#undef CLASS_DEFINE
......@@ -28,6 +28,10 @@
#include "lsh_types.h"
#define CLASS_DECLARE
#include "abstract_io.h.x"
#undef CLASS_DECLARE
/* A read-function returning n means:
*
* n > 0: n bytes were read successfully.
......@@ -38,40 +42,78 @@
#define A_FAIL -1
#define A_EOF -2
/* CLASS:
(class
(name abstract_read)
(vars
(read method int
"UINT32 length" "UINT8 *buffer")))
*/
#if 0
struct abstract_read
{
struct lsh_object header;
int (*read)(struct abstract_read **r,
UINT32 length, UINT8 *buffer);
};
#endif
#define A_READ(f, length, buffer) (f)->read(&(f), (length), (buffer))
/* May store a new handler into *h. */
/* CLASS:
(class
(name read_handler)
(vars
(handler method int "struct abstract_read *read")))
*/
#if 0
struct read_handler
{
struct lsh_object header;
int (*handler)(struct read_handler **h,
struct abstract_read *read);
};
#endif
#define READ_HANDLER(h, read) ((h)->handler(&(h), (read)))
/* CLASS:
(class
(name abstract_write)
(vars
(write method int "struct lsh_string *packet")))
*/
#if 0
struct abstract_write
{
struct lsh_object header;
int (*write)(struct abstract_write *w,
struct lsh_string *packet);
};
#endif
#define A_WRITE(f, packet) ((f)->write((f), (packet)))
/* A handler that passes packets on to another processor */
/* CLASS:
(class
(name abstract_write_pipe)
(super abstract_write)
(vars
(next object abstract_write)))
*/
#if 0
struct abstract_write_pipe
{
struct abstract_write super;
struct abstract_write *next;
};
#endif
#endif /*LSH_ABSTRACT_IO_H_INCLUDED */
......@@ -2,6 +2,25 @@
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "connection.h"
#include "debug.h"
......@@ -15,10 +34,14 @@
#include "werror.h"
#include "xalloc.h"
#define CLASS_DEFINE
#include "connection.h.x"
#undef CLASS_DEFINE
static int handle_connection(struct abstract_write *w,
struct lsh_string *packet)
{
struct ssh_connection *closure = (struct ssh_connection *) w;
CAST(closure, ssh_connection, w);
UINT8 msg;
if (!packet->length)
......@@ -82,7 +105,7 @@ static int do_fail(struct packet_handler *closure,
struct ssh_connection *connection,
struct lsh_string *packet)
{
MDEBUG(closure);
CHECK_TYPE(packet_handler, closure);
lsh_string_free(packet);
return LSH_FAIL | LSH_DIE;
......@@ -90,9 +113,7 @@ static int do_fail(struct packet_handler *closure,
struct packet_handler *make_fail_handler(void)
{
struct packet_handler *res;
NEW(res);
NEW(packet_handler, res);
res->handler = do_fail;
return res;
......@@ -103,8 +124,7 @@ static int do_unimplemented(struct packet_handler *closure,
struct lsh_string *packet)
{
int res;
MDEBUG(closure);
CHECK_TYPE(packet_handler, closure);
res = A_WRITE(connection->write,
ssh_format("%c%i",
......@@ -119,9 +139,7 @@ static int do_unimplemented(struct packet_handler *closure,
struct packet_handler *make_unimplemented_handler(void)
{
struct packet_handler *res;
NEW(res);
NEW(packet_handler, res);
res->handler = do_unimplemented;
return res;
......@@ -130,10 +148,10 @@ struct packet_handler *make_unimplemented_handler(void)
struct ssh_connection *make_ssh_connection(struct packet_handler *kex_handler)
{
struct ssh_connection *connection;
int i;
NEW(connection);
NEW(ssh_connection, connection);
connection->super.write = handle_connection;
/* Initialize instance variables */
......
......@@ -2,6 +2,25 @@
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LSH_CONNECTION_H_INCLUDED
#define LSH_CONNECTION_H_INCLUDED
......@@ -11,9 +30,23 @@
/* Forward declaration */
struct ssh_connection;
#define CLASS_DECLARE
#include "connection.h.x"
#undef CLASS_DECLARE
/* This is almost a write handler; difference is that it gets an extra
* argument with a connection object. */
/* CLASS:
(class
(name packet_handler)
(vars
(handler method int
"struct ssh_connection *connection"
"struct lsh_string *packet")))
*/
#if 0
struct packet_handler
{
struct lsh_object header;
......@@ -21,13 +54,64 @@ struct packet_handler
struct ssh_connection *connection,
struct lsh_string *packet);
};
#endif
#define HANDLE_PACKET(closure, connection, packet) \
((closure)->handler((closure), (connection), (packet)))
#define CONNECTION_SERVER 0
#define CONNECTION_CLIENT 1
/* CLASS:
(class
(name ssh_connection)
(super abstract_write)
(vars
; Sent and recieved version strings
(client_version string)
(server_version string)
(session_id string)
; Recieveing
(rec_max_packet simple UINT32)
(rec_mac object mac_instance)
(rec_crypto object crypto_instance)
; Sending
(raw object abstract_write) ; Socket connected to the other end
(write object abstract_write) ; Where to send packets through the
; pipeline.
(send_mac object mac_instance)
(send_crypto object crypto_instance)
; Key exchange
(kex_state simple int)
; (simple make_kexinit make_kexinit)
(kexinits array (object kexinit) 2)
;;; struct kexinit *kexinits[2];
(literal_kexinits array (string) 2)
;;; struct lsh_string *literal_kexinits[2];
; Negotiated algorithms
(newkeys object newkeys_info)
; Table of all known message types
(dispatch array (object packet_handler) "0x100");
; Shared handlers
(ignore object packet_handler)
(unimplemented object packet_handler)
(fail object packet_handler)
; (provides_privacy simple int)
; (provides_integrity simple int)
))
*/
#if 0
struct ssh_connection
{
struct abstract_write super;
......@@ -81,6 +165,7 @@ struct ssh_connection
int provides_integrity;
#endif
};
#endif
struct ssh_connection *make_ssh_connection(struct packet_handler *kex_handler);
void connection_init_io(struct ssh_connection *connection,
......
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