Wez Furlong's patch to add xterm mouse reporting and proper mouse
[u/mdw/putty] / raw.c
CommitLineData
5e1a8e27 1#include <windows.h>
2#include <stdio.h>
3#include <stdlib.h>
5e1a8e27 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
8df7a775 14static Socket s = NULL;
5e1a8e27 15
5e1a8e27 16static void raw_size(void);
17
18static int sb_opt, sb_len;
19static char *sb_buf = NULL;
20static int sb_size = 0;
21#define SB_DELTA 1024
22
8df7a775 23static void c_write (char *buf, int len) {
24 from_backend(0, buf, len);
5e1a8e27 25}
26
7e78000d 27static int raw_closing (Plug plug, char *error_msg, int error_code, int calling_back) {
28 sk_close(s);
29 s = NULL;
30 if (error_msg) {
2c94fd1c 31 /* A socket error has occurred. */
7e78000d 32 connection_fatal (error_msg);
33 } /* Otherwise, the remote side closed the connection normally. */
34 return 0;
35}
36
37static int raw_receive (Plug plug, int urgent, char *data, int len) {
8df7a775 38 c_write(data, len);
39 return 1;
5e1a8e27 40}
41
42/*
8df7a775 43 * Called to set up the raw connection.
44 *
5e1a8e27 45 * Returns an error message, or NULL on success.
46 *
47 * Also places the canonical host name into `realhost'.
48 */
8df7a775 49static char *raw_init (char *host, int port, char **realhost) {
7e78000d 50 static struct plug_function_table fn_table = {
51 raw_closing,
52 raw_receive
53 }, *fn_table_ptr = &fn_table;
54
8df7a775 55 SockAddr addr;
56 char *err;
5e1a8e27 57
58 /*
59 * Try to find host.
60 */
8df7a775 61 addr = sk_namelookup(host, realhost);
62 if ( (err = sk_addr_error(addr)) )
63 return err;
5e1a8e27 64
65 if (port < 0)
66 port = 23; /* default telnet port */
67
68 /*
69 * Open socket.
70 */
7e78000d 71 s = sk_new(addr, port, 0, 1, &fn_table_ptr);
8df7a775 72 if ( (err = sk_socket_error(s)) )
73 return err;
5e1a8e27 74
8df7a775 75 sk_addr_free(addr);
5e1a8e27 76
77 return NULL;
78}
79
80/*
5e1a8e27 81 * Called to send data down the raw connection.
82 */
83static void raw_send (char *buf, int len) {
84
8df7a775 85 if (s == NULL)
5e1a8e27 86 return;
87
8df7a775 88 sk_write(s, buf, len);
5e1a8e27 89}
90
91/*
92 * Called to set the size of the window
93 */
94static void raw_size(void) {
95 /* Do nothing! */
96 return;
97}
98
99/*
100 * Send raw special codes.
101 */
102static void raw_special (Telnet_Special code) {
103 /* Do nothing! */
104 return;
105}
106
8df7a775 107static Socket raw_socket(void) { return s; }
8ccc75b0 108
109static int raw_sendok(void) { return 1; }
4017be6d 110
0965bee0 111static int raw_ldisc(int option) {
112 if (option == LD_EDIT || option == LD_ECHO)
113 return 1;
114 return 0;
115}
116
5e1a8e27 117Backend raw_backend = {
118 raw_init,
5e1a8e27 119 raw_send,
120 raw_size,
4017be6d 121 raw_special,
8ccc75b0 122 raw_socket,
97db3be4 123 raw_sendok,
0965bee0 124 raw_ldisc,
97db3be4 125 1
5e1a8e27 126};