parse.h 2.67 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
35
36

/* Simple buffer
 * NOTE: All instances are allocated on the stack.
 * No object header is needed. */

Niels Möller's avatar
Niels Möller committed
37
38
struct simple_buffer
{
Niels Möller's avatar
Niels Möller committed
39
  UINT32 capacity;
Niels Möller's avatar
Niels Möller committed
40
41
42
43
44
45
46
47
48
  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);
49
50

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

/* 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
61
62
63
/* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer,
		     struct simple_buffer *subbuffer);
64

65
int parse_uint8(struct simple_buffer *buffer, int *result);
66

Niels Möller's avatar
Niels Möller committed
67
68
69
/* Returns 1 on success, 0 on error, and -1 at end of buffer */
int parse_utf8(struct simple_buffer *buffer, UINT32 *result);

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

72
int parse_bignum(struct simple_buffer *buffer, mpz_t result);
Niels Möller's avatar
Niels Möller committed
73
74

int parse_atom(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
75
76
77
78
79

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

80
81
/* Creates a list of integers. The 0 atom means an unknown atom was
 * read. Returns a NULL pointer on error. */
82
struct int_list *parse_atom_list(struct simple_buffer *buffer, unsigned limit);
Niels Möller's avatar
Niels Möller committed
83

Niels Möller's avatar
Niels Möller committed
84
85
86
87
/* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer);

#endif /* LSH_PARSE_H_INCLUDED */