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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/*
* keydis.c:
*
* Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
* All rights reserved.
*
*/
static char rcsid[] = "$Id$";
/*
* $Log$
* Revision 1.5 2008/02/23 11:48:37 james
* *** empty log message ***
*
* Revision 1.4 2008/02/22 17:07:00 james
* *** empty log message ***
*
* Revision 1.3 2008/02/15 23:52:12 james
* *** empty log message ***
*
* Revision 1.2 2008/02/15 03:32:07 james
* *** empty log message ***
*
* Revision 1.1 2008/02/14 02:46:44 james
* *** empty log message ***
*
* Revision 1.1 2008/02/14 01:55:57 james
* *** empty log message ***
*
*/
#include "project.h"
#define CMD_BUFLEN 128
typedef struct
{
KEYDIS_SIGNATURE;
} KeyDis_VT102;
typedef struct
{
KEYDIS_SIGNATURE;
Socket *s;
} KeyDis_IPC;
static void
keydis_close (KeyDis * t)
{
free (t);
}
static int
keydis_ipc_key (KeyDis * _t, Context * c, int key)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
return ipc_msg_send_key (t->s, key);
}
static int
keydis_ipc_set_baud (KeyDis * _t, Context * c, int baud)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
ipc_msg_send_setbaud (t->s, baud);
return 0;
}
static int
keydis_ipc_send_break (KeyDis * _t, Context * c)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
ipc_msg_send_sendbreak (t->s);
return 0;
}
static int
keydis_ipc_set_flow (KeyDis * _t, Context * c, int flow)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
ipc_msg_send_setflow (t->s, flow);
return 0;
}
static int
keydis_ipc_set_ansi (KeyDis * _t, Context * c, int ansi)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
vt102_set_ansi (c->v, ansi);
ipc_msg_send_setansi (t->s, ansi);
return 0;
}
static int
keydis_ipc_hangup (KeyDis * _t, Context * c)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
ipc_msg_send_hangup (t->s);
return 0;
}
static int
keydis_vt102_key (KeyDis * _t, Context * c, int key)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
vt102_send (c, key);
return 0;
}
static int
keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
tty_set_baud (c->t, baud);
tty_parse_reset (c);
log_f (c->l, "<baud changed to %d>", baud);
return 0;
}
static int
keydis_vt102_send_break (KeyDis * _t, Context * c)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
tty_send_break (c->t);
return 0;
}
static int
keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
tty_set_flow (c->t, flow);
return 0;
}
static int
keydis_vt102_set_ansi (KeyDis * _t, Context * c, int ansi)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
if (c->v)
c->v->xn_glitch = ansi ? 0 : 1;
return 0;
}
static int
keydis_vt102_hangup (KeyDis * _t, Context * c)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
tty_hangup (c->t);
return 0;
}
KeyDis *
keydis_vt102_new (void)
{
KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102));
t->key = keydis_vt102_key;
t->close = keydis_close;
t->set_baud = keydis_vt102_set_baud;
t->send_break = keydis_vt102_send_break;
t->set_flow = keydis_vt102_set_flow;
t->set_ansi = keydis_vt102_set_ansi;
t->hangup = keydis_vt102_hangup;
return (KeyDis *) t;
}
KeyDis *
keydis_ipc_new (Socket * s)
{
KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC));
t->key = keydis_ipc_key;
t->close = keydis_close;
t->set_baud = keydis_ipc_set_baud;
t->send_break = keydis_ipc_send_break;
t->set_flow = keydis_ipc_set_flow;
t->set_ansi = keydis_ipc_set_ansi;
t->hangup = keydis_ipc_hangup;
t->s = s;
return (KeyDis *) t;
}
int
keydis_key (KeyDis * t, Context * c, int key)
{
if (!c->d)
return t->key (t, c, key);
cmd_show_status (c->d, c);
if (c->d->active)
return cmd_key (c->d, c, key);
if (key == CMD_KEY)
return cmd_activate (c->d, c);
return t->key (t, c, key);
}
|