Rethink the whole line discipline architecture. Instead of having
[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
8df7a775 27static int raw_receive (Socket s, int urgent, char *data, int len) {
2c94fd1c 28 if (urgent==3) {
29 /* A socket error has occurred. */
30 connection_fatal(data);
31 len = 0;
32 }
8df7a775 33 if (!len) {
34 /* Connection has closed. */
35 sk_close(s);
36 s = NULL;
37 return 0;
5e1a8e27 38 }
8df7a775 39 c_write(data, len);
40 return 1;
5e1a8e27 41}
42
43/*
8df7a775 44 * Called to set up the raw connection.
45 *
5e1a8e27 46 * Returns an error message, or NULL on success.
47 *
48 * Also places the canonical host name into `realhost'.
49 */
8df7a775 50static char *raw_init (char *host, int port, char **realhost) {
51 SockAddr addr;
52 char *err;
5e1a8e27 53
54 /*
55 * Try to find host.
56 */
8df7a775 57 addr = sk_namelookup(host, realhost);
58 if ( (err = sk_addr_error(addr)) )
59 return err;
5e1a8e27 60
61 if (port < 0)
62 port = 23; /* default telnet port */
63
64 /*
65 * Open socket.
66 */
c91409da 67 s = sk_new(addr, port, 0, raw_receive);
8df7a775 68 if ( (err = sk_socket_error(s)) )
69 return err;
5e1a8e27 70
8df7a775 71 sk_addr_free(addr);
5e1a8e27 72
73 return NULL;
74}
75
76/*
5e1a8e27 77 * Called to send data down the raw connection.
78 */
79static void raw_send (char *buf, int len) {
80
8df7a775 81 if (s == NULL)
5e1a8e27 82 return;
83
8df7a775 84 sk_write(s, buf, len);
5e1a8e27 85}
86
87/*
88 * Called to set the size of the window
89 */
90static void raw_size(void) {
91 /* Do nothing! */
92 return;
93}
94
95/*
96 * Send raw special codes.
97 */
98static void raw_special (Telnet_Special code) {
99 /* Do nothing! */
100 return;
101}
102
8df7a775 103static Socket raw_socket(void) { return s; }
8ccc75b0 104
105static int raw_sendok(void) { return 1; }
4017be6d 106
0965bee0 107static int raw_ldisc(int option) {
108 if (option == LD_EDIT || option == LD_ECHO)
109 return 1;
110 return 0;
111}
112
5e1a8e27 113Backend raw_backend = {
114 raw_init,
5e1a8e27 115 raw_send,
116 raw_size,
4017be6d 117 raw_special,
8ccc75b0 118 raw_socket,
97db3be4 119 raw_sendok,
0965bee0 120 raw_ldisc,
97db3be4 121 1
5e1a8e27 122};