exception.h 5.04 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
/* exception.h
 *
 * $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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef LSH_EXCEPTION_H_INCLUDED
#define LSH_EXCEPTION_H_INCLUDED

#include "lsh.h"

Niels Möller's avatar
Niels Möller committed
29
#define GABA_DECLARE
Niels Möller's avatar
Niels Möller committed
30
#include "exception.h.x"
Niels Möller's avatar
Niels Möller committed
31
#undef GABA_DECLARE
Niels Möller's avatar
Niels Möller committed
32
33
34
35
36
37

/* GABA:
   (class
     (name exception)
     (vars
       (type . UINT32)
Niels Möller's avatar
Niels Möller committed
38
       (msg . "const char *")))
Niels Möller's avatar
Niels Möller committed
39
40
*/

Niels Möller's avatar
Niels Möller committed
41
42
43
#define STATIC_EXCEPTION(type, name) \
{ STATIC_HEADER, (type), (name) }

Niels Möller's avatar
Niels Möller committed
44
45
46
47
/* GABA:
   (class
     (name exception_handler)
     (vars
Niels Möller's avatar
Niels Möller committed
48
       (raise method void "const struct exception *")
49
50
51
52
       (parent object exception_handler)

       ; Provide some context for debugging unhandled exceptions
       (context . "const char *")))
Niels Möller's avatar
Niels Möller committed
53
54
*/

55
void exception_raise(struct exception_handler *e,
56
57
		     const struct exception *h,
		     const char *context);
58
59

#if DEBUG_TRACE
60
#  define EXCEPTION_RAISE(h, e) exception_raise((h), (e), HANDLER_CONTEXT)
61
62
63
#else /* !DEBUG_TRACE */
#  define EXCEPTION_RAISE(h, e)  ((h)->raise((h), (e)))
#endif /* !DEBUG_TRACE */
Niels Möller's avatar
Niels Möller committed
64

Niels Möller's avatar
Niels Möller committed
65
#define STATIC_EXCEPTION_HANDLER(r, p) \
66
67
68
69
{ STATIC_HEADER, (r), (p), __FILE__ ":" STRING_LINE ": Static" }

#define HANDLER_CONTEXT   (__FILE__ ":" STRING_LINE ": " FUNCTION_NAME)

Niels Möller's avatar
Niels Möller committed
70
71
72
73
74
75
76

/* Exception types. */

/* Used in places where no real exception is defined yet.
 * Never handled. */
#define EXC_DUMMY 0

Niels Möller's avatar
Niels Möller committed
77
78
79
/* FIXME: This is an inappropriate name, as this exception type is
 * used for all events that should result in a disconnect message. */

Niels Möller's avatar
Niels Möller committed
80
81
82
83
84
/* Protocol errors */
#define EXC_PROTOCOL 0x1000

/* IO related errors */
#define EXC_IO 0x2000
85
#define EXC_IO_CONNECT 0x2001
Niels Möller's avatar
Niels Möller committed
86
#define EXC_IO_BLOCKING_WRITE 0x2003
Niels Möller's avatar
Niels Möller committed
87
88
#define EXC_IO_READ 0x2004
#define EXC_IO_WRITE 0x2005
Niels Möller's avatar
Niels Möller committed
89
#define EXC_IO_OPEN_WRITE 0x2006
Balázs Scheidler's avatar
Balázs Scheidler committed
90
91
#define EXC_IO_OPEN_READ 0x2007
#define EXC_IO_LISTEN 0x2008
Niels Möller's avatar
Niels Möller committed
92
93
94
95
96

/* Authorization errors */
#define EXC_AUTH 0x4000
#define EXC_USERAUTH 0x4001

Niels Möller's avatar
Niels Möller committed
97
98
99
/* Implies an exception struct with a reply packet in it. */
#define EXC_USERAUTH_SPECIAL 0x4002

Niels Möller's avatar
Niels Möller committed
100
101
102
103
104
105
106
107
/* Services */
#define EXC_SERVICE 0x8000
#define EXC_GLOBAL_REQUEST 0x8001
#define EXC_CHANNEL_REQUEST 0x8002

/* Use subtypes for the different error codes? */
#define EXC_CHANNEL_OPEN 0x8003

Niels Möller's avatar
Niels Möller committed
108
109
/* Closing down things */
#define EXC_FINISH 0x10000
Niels Möller's avatar
Niels Möller committed
110

Niels Möller's avatar
Niels Möller committed
111
112
/* Close a channel */
#define EXC_FINISH_CHANNEL 0x10001
Niels Möller's avatar
Niels Möller committed
113

Niels Möller's avatar
Niels Möller committed
114
115
116
/* Stop reading on some fd */
#define EXC_FINISH_READ 0x10002

Niels Möller's avatar
Niels Möller committed
117
118
119
120
121
122
123
/* Close the connection immediately */
#define EXC_FINISH_IO 0x10003

/* Put the connection into pending-close mode,
 * i.e. don't open any new channels, and close it
 * as soon as all channels are gone. */
#define EXC_FINISH_PENDING 0x10004
Niels Möller's avatar
Niels Möller committed
124

125
126
127
128
129
130
131
132
/* DNS errors */
#define EXC_RESOLVE 0x20001

/* SEXP parse errors */
#define EXC_SEXP 0x40000
#define EXC_SEXP_SYNTAX 0x40001
#define EXC_SEXP_EOF 0x40002

133
134
135
136
137
/* SPKI errors */
#define EXC_SPKI 0x80000
/* Unexpected or unsupported expression type */
#define EXC_SPKI_TYPE 0x80001

Niels Möller's avatar
Niels Möller committed
138
139
140
141
142
143
144
#if 0
/* Serialization */
#define EXC_CONNECTION_SERIALIZE 0x100000
#define EXC_CONNECTION_LOCK 0x100001
#define EXC_CONNECTION_UNLOCK 0x100002
#endif

145
146
#define EXC_ALL (~0)

Niels Möller's avatar
Niels Möller committed
147
extern struct exception_handler default_exception_handler;
Niels Möller's avatar
Niels Möller committed
148
struct exception_handler ignore_exception_handler;
Niels Möller's avatar
Niels Möller committed
149
150
extern struct exception dummy_exception;

151
152
153
struct exception_handler *
make_report_exception_handler(UINT32 mask, UINT32 value,
			      const char *prefix,
154
155
			      struct exception_handler *parent,
			      const char *context);
Niels Möller's avatar
Niels Möller committed
156
157

struct exception *
Niels Möller's avatar
Niels Möller committed
158
make_simple_exception(UINT32 type, const char *msg);
Niels Möller's avatar
Niels Möller committed
159

Niels Möller's avatar
Niels Möller committed
160
161
162
163
/* Create a simple exception handler, with no internal state */
struct exception_handler *
make_exception_handler(void (*raise)(struct exception_handler *s,
				     const struct exception *x),
164
165
		       struct exception_handler *parent,
		       const char *context);
Niels Möller's avatar
Niels Möller committed
166

Niels Möller's avatar
Niels Möller committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* A protocol exception, that normally terminates the connection */
/* GABA:
   (class
     (name protocol_exception)
     (super exception)
     (vars
       ;; A reason code that can be passed in a SSH_MSG_DISCONNECT message.
       ;; Zero means terminate the connection without sending such a message.
       (reason . UINT32)))
*/


/* If msg is NULL, it is derived from the reason value */
struct exception *
make_protocol_exception(UINT32 reason, const char *msg);

#define STATIC_PROTOCOL_EXCEPTION(reason, msg) \
{ { STATIC_HEADER, EXC_PROTOCOL, (msg) }, (reason) }

186
187
188
189
#define PROTOCOL_ERROR(e, msg) \
EXCEPTION_RAISE((e), \
  make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR, (msg)))

Niels Möller's avatar
Niels Möller committed
190
#endif /* LSH_EXCEPTION_H_INCLUDED */