]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - raw.c
Rethink the whole line discipline architecture. Instead of having
[PuTTY.git] / raw.c
1 #include <windows.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include "putty.h"
6
7 #ifndef FALSE
8 #define FALSE 0
9 #endif
10 #ifndef TRUE
11 #define TRUE 1
12 #endif
13
14 static Socket s = NULL;
15
16 static void raw_size(void);
17
18 static int sb_opt, sb_len;
19 static char *sb_buf = NULL;
20 static int sb_size = 0;
21 #define SB_DELTA 1024
22
23 static void c_write (char *buf, int len) {
24     from_backend(0, buf, len);
25 }
26
27 static int raw_receive (Socket s, int urgent, char *data, int len) {
28     if (urgent==3) {
29         /* A socket error has occurred. */
30         connection_fatal(data);
31         len = 0;
32     }
33     if (!len) {
34         /* Connection has closed. */
35         sk_close(s);
36         s = NULL;
37         return 0;
38     }
39     c_write(data, len);
40     return 1;
41 }
42
43 /*
44  * Called to set up the raw connection.
45  * 
46  * Returns an error message, or NULL on success.
47  *
48  * Also places the canonical host name into `realhost'.
49  */
50 static char *raw_init (char *host, int port, char **realhost) {
51     SockAddr addr;
52     char *err;
53
54     /*
55      * Try to find host.
56      */
57     addr = sk_namelookup(host, realhost);
58     if ( (err = sk_addr_error(addr)) )
59         return err;
60
61     if (port < 0)
62         port = 23;                     /* default telnet port */
63
64     /*
65      * Open socket.
66      */
67     s = sk_new(addr, port, 0, raw_receive);
68     if ( (err = sk_socket_error(s)) )
69         return err;
70
71     sk_addr_free(addr);
72
73     return NULL;
74 }
75
76 /*
77  * Called to send data down the raw connection.
78  */
79 static void raw_send (char *buf, int len) {
80
81     if (s == NULL)
82         return;
83
84     sk_write(s, buf, len);
85 }
86
87 /*
88  * Called to set the size of the window
89  */
90 static void raw_size(void) {
91     /* Do nothing! */
92     return;
93 }
94
95 /*
96  * Send raw special codes.
97  */
98 static void raw_special (Telnet_Special code) {
99     /* Do nothing! */
100     return;
101 }
102
103 static Socket raw_socket(void) { return s; }
104
105 static int raw_sendok(void) { return 1; }
106
107 static int raw_ldisc(int option) {
108     if (option == LD_EDIT || option == LD_ECHO)
109         return 1;
110     return 0;
111 }
112
113 Backend raw_backend = {
114     raw_init,
115     raw_send,
116     raw_size,
117     raw_special,
118     raw_socket,
119     raw_sendok,
120     raw_ldisc,
121     1
122 };