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

New functions parse_octets() and parse_string_copy().

Rev: src/parse.c:1.10
Rev: src/parse.h:1.9
parent b8fcbc2e
......@@ -4,6 +4,7 @@
#include "parse.h"
#include "xalloc.h"
#include "format.h"
void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data)
......@@ -44,6 +45,27 @@ int parse_string(struct simple_buffer *buffer,
return 1;
}
int parse_octets(struct simple_buffer *buffer,
UINT32 length, UINT8 *start)
{
if (LEFT < length)
return 0;
memcpy(start, HERE, length);
ADVANCE(length);
return 1;
}
struct lsh_string *parse_string_copy(struct simple_buffer *buffer)
{
UINT32 length;
UINT8 *start;
if (!parse_string(buffer, &length, &data))
return NULL;
return ssh_format("%ls", length, start);
}
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
struct simple_buffer *subbuffer)
......@@ -77,7 +99,7 @@ int parse_boolean(struct simple_buffer *buffer, int *result)
return 1;
}
int parse_bignum(struct simple_buffer *buffer, bignum result)
int parse_bignum(struct simple_buffer *buffer, mpz_t result)
{
UINT32 length;
UINT8 *digits;
......
......@@ -22,15 +22,27 @@ void simple_buffer_init(struct simple_buffer *buffer,
/* Returns 1 on success, 0 on failure */
int parse_uint32(struct simple_buffer *buffer, UINT32 *result);
/* Only records length and start pointer */
int parse_string(struct simple_buffer *buffer,
UINT32 *length, UINT8 **start);
/* Copies a given number of octets, without any length header */
int parse_octets(struct simple_buffer *buffer,
UINT32 length, UINT8 *start);
/* Copies a substring */
struct lsh_string *parse_string_copy(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_boolean(struct simple_buffer *buffer, int *result);
int parse_bignum(struct simple_buffer *buffer, bignum result);
int parse_bignum(struct simple_buffer *buffer, mpz_t result);
int parse_atom(struct simple_buffer *buffer, int *result);
......
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