]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - raw.c
Run entire source base through GNU indent to tidy up the varying
[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 {
25     from_backend(0, buf, len);
26 }
27
28 static int raw_closing(Plug plug, char *error_msg, int error_code,
29                        int calling_back)
30 {
31     sk_close(s);
32     s = NULL;
33     if (error_msg) {
34         /* A socket error has occurred. */
35         connection_fatal(error_msg);
36     }                                  /* Otherwise, the remote side closed the connection normally. */
37     return 0;
38 }
39
40 static int raw_receive(Plug plug, int urgent, char *data, int len)
41 {
42     c_write(data, len);
43     return 1;
44 }
45
46 /*
47  * Called to set up the raw connection.
48  * 
49  * Returns an error message, or NULL on success.
50  *
51  * Also places the canonical host name into `realhost'.
52  */
53 static char *raw_init(char *host, int port, char **realhost)
54 {
55     static struct plug_function_table fn_table = {
56         raw_closing,
57         raw_receive
58     }, *fn_table_ptr = &fn_table;
59
60     SockAddr addr;
61     char *err;
62
63     /*
64      * Try to find host.
65      */
66     addr = sk_namelookup(host, realhost);
67     if ((err = sk_addr_error(addr)))
68         return err;
69
70     if (port < 0)
71         port = 23;                     /* default telnet port */
72
73     /*
74      * Open socket.
75      */
76     s = sk_new(addr, port, 0, 1, &fn_table_ptr);
77     if ((err = sk_socket_error(s)))
78         return err;
79
80     sk_addr_free(addr);
81
82     return NULL;
83 }
84
85 /*
86  * Called to send data down the raw connection.
87  */
88 static void raw_send(char *buf, int len)
89 {
90
91     if (s == NULL)
92         return;
93
94     sk_write(s, buf, len);
95 }
96
97 /*
98  * Called to set the size of the window
99  */
100 static void raw_size(void)
101 {
102     /* Do nothing! */
103     return;
104 }
105
106 /*
107  * Send raw special codes.
108  */
109 static void raw_special(Telnet_Special code)
110 {
111     /* Do nothing! */
112     return;
113 }
114
115 static Socket raw_socket(void)
116 {
117     return s;
118 }
119
120 static int raw_sendok(void)
121 {
122     return 1;
123 }
124
125 static int raw_ldisc(int option)
126 {
127     if (option == LD_EDIT || option == LD_ECHO)
128         return 1;
129     return 0;
130 }
131
132 Backend raw_backend = {
133     raw_init,
134     raw_send,
135     raw_size,
136     raw_special,
137     raw_socket,
138     raw_sendok,
139     raw_ldisc,
140     1
141 };