parse.h 2.79 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
 *
 * $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
J.H.M. Dassen's avatar
J.H.M. Dassen committed
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
  UINT32 pos;
Niels Möller's avatar
Niels Möller committed
41
  const UINT8 *data;
Niels Möller's avatar
Niels Möller committed
42
43
};

Niels Möller's avatar
Niels Möller committed
44
45
46
void
simple_buffer_init(struct simple_buffer *buffer,
		  UINT32 capacity, const UINT8 *data);
Niels Möller's avatar
Niels Möller committed
47
48
49

/* Returns 1 on success, 0 on failure */
int parse_uint32(struct simple_buffer *buffer, UINT32 *result);
50
51

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

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

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

Niels Möller's avatar
Niels Möller committed
68
69
70
/* 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
71
int parse_boolean(struct simple_buffer *buffer, int *result);
Niels Möller's avatar
Niels Möller committed
72

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

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

77
78
/* Reads a list of zero or more atoms. The buffer should hold the list
 * body; the length field should already be stripped off (usually by
79
80
81
 * parse_sub_buffer()). */
struct int_list *parse_atoms(struct simple_buffer *buffer, unsigned limit);

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

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

#endif /* LSH_PARSE_H_INCLUDED */