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

* src/parse.c (parse_uint16): New function.

(parse_string16): New function.

Rev: src/parse.c:1.35
Rev: src/parse.h:1.26
parent b4648a4f
......@@ -315,6 +315,36 @@ parse_atom_list(struct simple_buffer *buffer, unsigned limit)
return parse_atoms(&sub_buffer, limit);
}
/* Used by client_x11.c, for parsing xauth */
int
parse_uint16(struct simple_buffer *buffer, UINT32 *result)
{
if (LEFT < 2)
return 0;
*result = READ_UINT16(HERE);
ADVANCE(2);
return 1;
}
int
parse_string16(struct simple_buffer *buffer,
UINT32 *length, const UINT8 **start)
{
UINT32 l;
if (!parse_uint16(buffer, &l))
return 0;
if (LEFT < l)
return 0;
*length = l;
*start = HERE;
ADVANCE(l);
return 1;
}
void
parse_rest(struct simple_buffer *buffer,
UINT32 *length, const UINT8 **start)
......
......@@ -46,42 +46,60 @@ simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, const UINT8 *data);
/* Returns 1 on success, 0 on failure */
int parse_uint32(struct simple_buffer *buffer, UINT32 *result);
int
parse_uint32(struct simple_buffer *buffer, UINT32 *result);
/* Only records length and start pointer */
int parse_string(struct simple_buffer *buffer,
UINT32 *length, const UINT8 **start);
int
parse_string(struct simple_buffer *buffer,
UINT32 *length, const UINT8 **start);
/* Copies a given number of octets, without any length header */
int parse_octets(struct simple_buffer *buffer,
UINT32 length, UINT8 *start);
int
parse_octets(struct simple_buffer *buffer,
UINT32 length, UINT8 *start);
/* Copies a substring */
struct lsh_string *parse_string_copy(struct simple_buffer *buffer);
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_sub_buffer(struct simple_buffer *buffer,
struct simple_buffer *subbuffer);
int parse_uint8(struct simple_buffer *buffer, unsigned *result);
int
parse_uint8(struct simple_buffer *buffer, unsigned *result);
/* Returns 1 on success, 0 on error, and -1 at end of buffer */
int parse_utf8(struct simple_buffer *buffer, UINT32 *result);
int
parse_utf8(struct simple_buffer *buffer, UINT32 *result);
int parse_boolean(struct simple_buffer *buffer, int *result);
int parse_bignum(struct simple_buffer *buffer, mpz_t result, UINT32 limit);
int
parse_bignum(struct simple_buffer *buffer, mpz_t result, UINT32 limit);
int parse_atom(struct simple_buffer *buffer, int *result);
int
parse_atom(struct simple_buffer *buffer, int *result);
/* Reads a list of zero or more atoms. The buffer should hold the list
* body; the length field should already be stripped off (usually by
* parse_sub_buffer()). */
struct int_list *parse_atoms(struct simple_buffer *buffer, unsigned limit);
struct int_list *
parse_atoms(struct simple_buffer *buffer, unsigned limit);
/* Creates a list of integers. The 0 atom means an unknown atom was
* read. Returns a NULL pointer on error. */
struct int_list *parse_atom_list(struct simple_buffer *buffer, unsigned limit);
struct int_list *
parse_atom_list(struct simple_buffer *buffer, unsigned limit);
int
parse_uint16(struct simple_buffer *buffer, UINT32 *result);
int
parse_string16(struct simple_buffer *buffer,
UINT32 *length, const UINT8 **start);
void
parse_rest(struct simple_buffer *buffer,
......@@ -92,6 +110,7 @@ struct lsh_string *
parse_rest_copy(struct simple_buffer *buffer);
/* 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);
#endif /* LSH_PARSE_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