]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - testback.c
Removing one bug, and hunting another
[PuTTY.git] / testback.c
1 /* $Id: testback.c,v 1.1.2.8 1999/09/01 22:16:15 ben Exp $ */
2 /*
3  * Copyright (c) 1999 Simon Tatham
4  * Copyright (c) 1999 Ben Harris
5  * All rights reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person
8  * obtaining a copy of this software and associated documentation
9  * files (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use,
11  * copy, modify, merge, publish, distribute, sublicense, and/or
12  * sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following
14  * conditions:
15  * 
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  * 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.
27  */
28
29 /* PuTTY test backends */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33
34 #include "putty.h"
35
36 static char *null_init(Session *);
37 static int null_msg(Session *, SOCKET, Net_Event_Type);
38 static void null_send(Session *, char *, int);
39 static void loop_send(Session *, char *, int);
40 static void hexdump_send(Session *, char *, int);
41 static void null_size(Session *);
42 static void null_special(Session *, Telnet_Special);
43 static char *rawtcp_init(Session *);
44 static int rawtcp_msg(Session *, SOCKET, Net_Event_Type);
45
46 Backend null_backend = {
47     null_init, null_msg, null_send, null_size, null_special
48 };
49
50 Backend loop_backend = {
51     null_init, null_msg, loop_send, null_size, null_special
52 };
53
54 Backend hexdump_backend = {
55     null_init, null_msg, hexdump_send, null_size, null_special
56 };
57
58 Backend rawtcp_backend = {
59     rawtcp_init, rawtcp_msg, null_send, null_size, null_special
60 };
61
62 static char *null_init(Session *s) {
63
64     return NULL;
65 }
66
67 static int null_msg(Session *s, SOCKET sock, Net_Event_Type ne) {
68
69     return 1;
70 }
71
72 static void null_send(Session *s, char *buf, int len) {
73
74 }
75
76 static void loop_send (Session *s, char *buf, int len) {
77
78     while (len--) {
79         int new_head = (s->inbuf_head + 1) & INBUF_MASK;
80         int c = (unsigned char) *buf;
81         if (new_head != s->inbuf_reap) {
82             s->inbuf[s->inbuf_head] = *buf++;
83             s->inbuf_head = new_head;
84         }
85     }
86     term_out(s);
87     term_update(s);
88 }
89
90 static void hexdump_send(Session *s, char *buf, int len) {
91     static char mybuf[10];
92     int mylen;
93
94     while (len--) {
95         mylen = sprintf(mybuf, "%02x\015\012", (unsigned char)*buf++);
96         loop_send(s, mybuf, mylen);
97     }
98 }
99
100 static void null_size(Session *s) {
101
102 }
103
104 static void null_special(Session *s, Telnet_Special code) {
105
106 }
107
108 struct rawtcp_private {
109     SOCKET s;
110 };
111
112 static char *rawtcp_init(Session *sess) {
113     struct rawtcp_private *rp;
114
115     sess->back_priv = smalloc(sizeof(struct rawtcp_private));
116     rp = (struct rawtcp_private *)sess->back_priv;
117     rp->s = net_open(sess, sess->cfg.host, sess->cfg.port);
118     if (rp->s == INVALID_SOCKET)
119         fatalbox("Open failed");
120 }
121
122 static int rawtcp_msg(Session *sess, SOCKET sock, Net_Event_Type ne) {
123     struct rawtcp_private *rp = (struct rawtcp_private *)sess->back_priv;
124
125     switch (ne) {
126       case NE_NULL:
127         break;
128       case NE_OPEN:
129         break;
130       case NE_NOHOST:
131       case NE_REFUSED:
132       case NE_NOOPEN:
133         rp->s = INVALID_SOCKET;
134         fatalbox("Open failed");
135         break;
136       case NE_DATA:
137         break;
138       case NE_URGENT:
139         break;
140       case NE_CLOSING:
141         /* net_close(rp->s);*/
142         break;
143       case NE_CLOSED:
144         rp->s = INVALID_SOCKET;
145         fatalbox("Connection closed");
146         break;
147       case NE_TIMEOUT:
148       case NE_ABORT:
149       case NE_DIED:
150         fatalbox("Connection died");
151         rp->s = INVALID_SOCKET;
152         break;
153     }
154 }
155
156
157
158 /*
159  * Emacs magic:
160  * Local Variables:
161  * c-file-style: "simon"
162  * End:
163  */