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

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Möller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Niels Möller's avatar
Niels Möller committed
24
25
26
27
 */

#ifndef LSH_PARSE_H_INCLUDED
#define LSH_PARSE_H_INCLUDED
Niels Möller's avatar
Niels Möller committed
28
29
30
31

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

Niels Möller's avatar
Niels Möller committed
32
33
34
/* Simple buffer */
struct simple_buffer
{
Niels Möller's avatar
Niels Möller committed
35
  UINT32 capacity;
Niels Möller's avatar
Niels Möller committed
36
37
38
39
40
41
42
43
44
  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);
45
46

/* Only records length and start pointer */
Niels Möller's avatar
Niels Möller committed
47
48
int parse_string(struct simple_buffer *buffer,
		 UINT32 *length, UINT8 **start);
49
50
51
52
53
54
55
56

/* 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
57
58
59
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
		     struct simple_buffer *subbuffer);
60

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

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

65
int parse_bignum(struct simple_buffer *buffer, mpz_t result);
Niels Möller's avatar
Niels Möller committed
66
67

int parse_atom(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
68
69
70
71
72

/* 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
73
74
75
76
77
/* 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
78
79
80
81
/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);

#endif /* LSH_PARSE_H_INCLUDED */