parse.h 1.33 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* parse.h
 *
 * Parses the data formats used in ssh packets.
 */

#ifndef LSH_PARSE_H_INCLUDED
#define LSH_PARSE_H_INCLUDED
  
/* Simple buffer */
struct simple_buffer
{
  UNIT32 capacity;
  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);
int parse_uint8(struct simple_buffer *buffer, uint8 *result);
#define parse_boolean parse_uint8

Niels Möller's avatar
Niels Möller committed
30
int parse_bignum(struct simple_buffer *buffer, bignum result);
Niels Möller's avatar
Niels Möller committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

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

/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);

#if 0
/* Returns the number of octets that were actually written into the buffer */

UINT32 simple_buffer_write(struct simple_buffer *buffer,
			   UINT32 length, UINT32 *data);

UINT32 simple_buffer_avail(struct simple_buffer *buffer);
#endif

#endif /* LSH_PARSE_H_INCLUDED */