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