parse.h 1.36 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
/* parse.h
 *
 * Parses the data formats used in ssh packets.
 */

#ifndef LSH_PARSE_H_INCLUDED
#define LSH_PARSE_H_INCLUDED
Niels Möller's avatar
Niels Möller committed
8
9
10
11

#include "atoms.h"
#include "bignum.h"

Niels Möller's avatar
Niels Möller committed
12
13
14
/* Simple buffer */
struct simple_buffer
{
Niels Möller's avatar
Niels Möller committed
15
  UINT32 capacity;
Niels Möller's avatar
Niels Möller committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  UINT32 pos;
  UINT8 *data;
};

void simple_buffer_init(struct simple_buffer *buffer,
			UINT32 capacity, UINT8 *data);

/* Returns 1 on success, 0 on failure */
int parse_uint32(struct simple_buffer *buffer, UINT32 *result);
int parse_string(struct simple_buffer *buffer,
		 UINT32 *length, UINT8 **start);
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
		     struct simple_buffer *subbuffer);
Niels Möller's avatar
Niels Möller committed
30
int parse_uint8(struct simple_buffer *buffer, UINT8 *result);
Niels Möller's avatar
Niels Möller committed
31
int parse_boolean(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
32

Niels Möller's avatar
Niels Möller committed
33
int parse_bignum(struct simple_buffer *buffer, bignum *result);
Niels Möller's avatar
Niels Möller committed
34
35
36
37
38

/* Returns 1 on success, 0 on failure, and -1 at end of buffer.
 * Unknown atoms sets result to zero. */
int parse_next_atom(struct simple_buffer *buffer, int *result);

Niels Möller's avatar
Niels Möller committed
39
40
41
42
43
/* Allocates an array of integers. The 0 atom means an unknown atom
 * was read. The list is terminated with -1. Returns a NULL pointer on
 * error. */
int *parse_atom_list(struct simple_buffer *buffer);

Niels Möller's avatar
Niels Möller committed
44
45
46
47
/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);

#endif /* LSH_PARSE_H_INCLUDED */