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

Fixed compilation problems.

Rev: src/bignum.c:1.3
Rev: src/bignum.h:1.3
Rev: src/pad.c:1.4
Rev: src/pad.h:1.3
Rev: src/parse.c:1.4
Rev: src/parse.h:1.4
Rev: src/transport.c:1.2
Rev: src/unpad.c:1.2
Rev: src/unpad.h:1.3
Rev: src/void.c:1.2
parent 2be1a000
......@@ -5,7 +5,7 @@
#include "bignum.h"
#include "werror.h"
void parse_bignum(bignum *n, UINT32 length, UINT8 *data)
void bignum_parse(bignum *n, UINT32 length, UINT8 *data)
{
int negative = length && (*data & 0x80);
int i;
......
......@@ -11,7 +11,7 @@
#define bignum MP_INT
void parse_bignum(bignum *n, UINT32 length, UINT8 *data);
void bignum_parse(bignum *n, UINT32 length, UINT8 *data);
UINT32 bignum_format_length(bignum *n);
UINT32 bignum_format(bignum *n, UINT8 *data);
......
......@@ -3,6 +3,8 @@
*/
#include "pad.h"
#include "xalloc.h"
#include <assert.h>
static int do_pad(struct pad_processor *closure,
struct simple_packet *packet)
......@@ -20,7 +22,7 @@ static int do_pad(struct pad_processor *closure,
* ( (8 + packet->length) / closure->block_size);
padding = new_size - packet->length - 5;
assert(ssh->padding_length >= 4);
assert(padding >= 4);
new = simple_packet_alloc(new_size);
......@@ -30,7 +32,7 @@ static int do_pad(struct pad_processor *closure,
ssh->padding_length = padding;
#endif
WRITE_INT32(new->data, new_size - 4);
WRITE_UINT32(new->data, new_size - 4);
new->data[4] = padding;
memcpy(new->data + 5, packet->data, packet->length);
......@@ -38,19 +40,20 @@ static int do_pad(struct pad_processor *closure,
simple_packet_free(packet);
return apply_processor(closure->c->next, new);
return apply_processor(closure->c.next, new);
}
struct packet_processor *make_pad_processor(packet_processor *continuation,
struct packet_processor *
make_pad_processor(struct packet_processor *continuation,
unsigned block_size,
random_function random,
void *state)
{
struct pad_processor *closure = xalloc(sizeof(struct pad_processor));
closure->c->p->f = (raw_processor_function) do_pad;
closure->c->next = continuation;
closure->c.p.f = (raw_processor_function) do_pad;
closure->c.next = continuation;
closure->block_size = block_size;
closure->random = random;
closure->state = state;
......
......@@ -8,7 +8,7 @@
#include "transport.h"
typedef (*random_function)(void *state, UINT32 length, UINT8 *dst);
typedef void (*random_function)(void *state, UINT32 length, UINT8 *dst);
/* Input to the processor is a packet with the payload. Output is a
* packet containing a formatted ssh packet (with correct byte order,
......@@ -23,7 +23,8 @@ struct pad_processor
void *state;
};
struct packet_processor *make_pad_processor(packet_processor *continuation,
struct packet_processor *
make_pad_processor(struct packet_processor *continuation,
unsigned block_size,
random_function random,
void *state);
......
......@@ -3,6 +3,7 @@
*/
#include "parse.h"
#include "transport.h"
void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data)
......@@ -12,16 +13,16 @@ void simple_buffer_init(struct simple_buffer *buffer,
buffer->data = data;
}
#define BUFFER_LEFT (buffer->capacity - buffer->pos)
#define LEFT (buffer->capacity - buffer->pos)
#define HERE (buffer->data + buffer->pos)
#define ADVANCE(n) (buffer->pos += (n))
int parse_uint32(struct simple_buffer *buffer, UINT32 *result)
{
if (BUFFER_LEFT < 4)
if (LEFT < 4)
return 0;
*result = READ_INT32(HERE);
*result = READ_UINT32(HERE);
ADVANCE(4);
return 1;
}
......@@ -34,12 +35,13 @@ int parse_string(struct simple_buffer *buffer,
if (!parse_uint32(buffer, &l))
return 0;
if (BUFFER_LEFT < length)
if (LEFT < l)
return 0;
*length = l;
*start = HERE;
ADVANCE(l);
return 1;
}
/* Initializes subbuffer to parse a string from buffer */
......@@ -56,7 +58,7 @@ int parse_sub_buffer(struct simple_buffer *buffer,
return 1;
}
int parse_uint8(struct simple_buffer *buffer, uint8 *result)
int parse_uint8(struct simple_buffer *buffer, UINT8 *result)
{
if (!LEFT)
return 0;
......@@ -74,7 +76,7 @@ int parse_bignum(struct simple_buffer *buffer, bignum *result)
if (!parse_string(buffer, &length, &digits))
return 0;
parse_bignum(result, length, digits);
bignum_parse(result, length, digits);
return 1;
}
......@@ -92,21 +94,21 @@ int parse_next_atom(struct simple_buffer *buffer, int *result)
if (buffer->pos > buffer->capacity)
return -1;
for(i = 0; i < left; i++)
for(i = 0; i < LEFT; i++)
if (HERE[i] == ',')
{
*result = lookup_atom(HERE, i);
ADVANCE[i+1];
ADVANCE(i+1);
return 1;
}
*result = lookup(HERE, i);
*result = lookup_atom(HERE, i);
ADVANCE(i+1); /* Beyond end of buffer */
return 1;
}
/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);
int parse_eod(struct simple_buffer *buffer)
{
return !LEFT;
}
......@@ -12,7 +12,7 @@
/* Simple buffer */
struct simple_buffer
{
UNIT32 capacity;
UINT32 capacity;
UINT32 pos;
UINT8 *data;
};
......@@ -27,7 +27,7 @@ int parse_string(struct simple_buffer *buffer,
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
struct simple_buffer *subbuffer);
int parse_uint8(struct simple_buffer *buffer, uint8 *result);
int parse_uint8(struct simple_buffer *buffer, UINT8 *result);
#define parse_boolean parse_uint8
int parse_bignum(struct simple_buffer *buffer, bignum *result);
......
/* transport.c
*
*/
#include "transport.h"
#include "xalloc.h"
struct simple_packet *simple_packet_alloc(UINT32 length)
{
struct simple_packet *packet = xalloc(sizeof(struct simple_packet) - 1 + size);
packet->length = size;
struct simple_packet *packet
= xalloc(sizeof(struct simple_packet) - 1 + length);
packet->length = length;
return packet;
}
void simple_packet_free(struct simple_packet *packet);
void simple_packet_free(struct simple_packet *packet)
{
free(packet);
}
#if 0
void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data)
{
......@@ -35,6 +41,7 @@ UINT32 simple_buffer_avail(struct simple_buffer *buffer)
{
return buffer->capacity - buffer->pos;
}
#endif
int apply_processor(struct packet_processor *closure,
struct simple_packet *packet)
......
......@@ -2,7 +2,10 @@
*
*/
static int do_unpad(struct pad_processor *closure,
#include "unpad.h"
#include "xalloc.h"
static int do_unpad(struct unpad_processor *closure,
struct simple_packet *packet)
{
UINT8 padding_length;
......@@ -26,15 +29,16 @@ static int do_unpad(struct pad_processor *closure,
simple_packet_free(packet);
return apply_continuation(closure->next, new);
return apply_processor(closure->c.next, new);
}
struct packet_processor *make_pad_processor(packet_processor *continuation)
struct packet_processor *
make_unpad_processor(struct packet_processor *continuation)
{
struct pad_processor *closure = xalloc(sizeof(struct pad_processor));
struct unpad_processor *closure = xalloc(sizeof(struct unpad_processor));
closure->c->p->f = (raw_processor_function) do_unpad;
closure->c->next = continuation;
closure->c.p.f = (raw_processor_function) do_unpad;
closure->c.next = continuation;
return (struct packet_processor *) closure;
}
......@@ -6,7 +6,7 @@
#ifndef LSH_UNPAD_H_INCLUDED
#define LSH_UNPAD_H_INCLUDED
#include "tranport.h"
#include "transport.h"
/* Input to the processor is a padded payload. */
struct unpad_processor
......@@ -14,6 +14,7 @@ struct unpad_processor
struct chained_processor c;
};
struct packet_processor *make_unpad_processor(packet_processor *continuation);
struct packet_processor *
make_unpad_processor(struct packet_processor *continuation);
#endif /* LSH_UNPAD_H_INCLUDED */
......@@ -3,8 +3,9 @@
*/
#include "void.h"
#include "xalloc.h"
static int do_ignore(struct pad_processor *closure,
static int do_ignore(struct void_processor *closure,
struct simple_packet *packet)
{
free(packet);
......@@ -15,7 +16,7 @@ struct packet_processor *make_void_processor()
{
struct void_processor *closure = xalloc(sizeof(struct void_processor));
closure->p->f = (raw_processor_function) do_ignore;
closure->p.f = (raw_processor_function) do_ignore;
return (struct packet_processor *) 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