parse.h 1.69 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
  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);
25
26

/* Only records length and start pointer */
Niels Möller's avatar
Niels Möller committed
27
28
int parse_string(struct simple_buffer *buffer,
		 UINT32 *length, UINT8 **start);
29
30
31
32
33
34
35
36

/* 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);

Niels Möller's avatar
Niels Möller committed
37
38
39
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
		     struct simple_buffer *subbuffer);
40

Niels Möller's avatar
Niels Möller committed
41
int parse_uint8(struct simple_buffer *buffer, UINT8 *result);
42

Niels Möller's avatar
Niels Möller committed
43
int parse_boolean(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
44

45
int parse_bignum(struct simple_buffer *buffer, mpz_t result);
Niels Möller's avatar
Niels Möller committed
46
47

int parse_atom(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
48
49
50
51
52

/* 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
53
54
55
56
57
/* 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
58
59
60
61
/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);

#endif /* LSH_PARSE_H_INCLUDED */