| 1 | /* $Id: testback.c,v 1.8 2003/04/05 14:32:58 ben Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 1999 Simon Tatham |
| 4 | * Copyright (c) 1999 Ben Harris |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person |
| 8 | * obtaining a copy of this software and associated documentation |
| 9 | * files (the "Software"), to deal in the Software without |
| 10 | * restriction, including without limitation the rights to use, |
| 11 | * copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | * sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following |
| 14 | * conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be |
| 17 | * included in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 24 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | /* PuTTY test backends */ |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | |
| 34 | #include "putty.h" |
| 35 | |
| 36 | static char *null_init(void *, void **, Config *, char *, int, char **, int); |
| 37 | static char *loop_init(void *, void **, Config *, char *, int, char **, int); |
| 38 | static void null_free(void *); |
| 39 | static void loop_free(void *); |
| 40 | static void null_reconfig(void *, Config *); |
| 41 | static int null_send(void *, char *, int); |
| 42 | static int loop_send(void *, char *, int); |
| 43 | static int null_sendbuffer(void *); |
| 44 | static void null_size(void *, int, int); |
| 45 | static void null_special(void *, Telnet_Special); |
| 46 | static const struct telnet_special *null_get_specials(void *handle); |
| 47 | static Socket null_socket(void *); |
| 48 | static int null_exitcode(void *); |
| 49 | static int null_sendok(void *); |
| 50 | static int null_ldisc(void *, int); |
| 51 | static void null_provide_ldisc(void *, void *); |
| 52 | static void null_provide_logctx(void *, void *); |
| 53 | static void null_unthrottle(void *, int); |
| 54 | |
| 55 | Backend null_backend = { |
| 56 | null_init, null_free, null_reconfig, null_send, null_sendbuffer, null_size, |
| 57 | null_special, null_get_specials, null_socket, null_exitcode, null_sendok, |
| 58 | null_ldisc, null_provide_ldisc, null_provide_logctx, null_unthrottle, 0 |
| 59 | }; |
| 60 | |
| 61 | Backend loop_backend = { |
| 62 | loop_init, loop_free, null_reconfig, loop_send, null_sendbuffer, null_size, |
| 63 | null_special, null_get_specials, null_socket, null_exitcode, null_sendok, |
| 64 | null_ldisc, null_provide_ldisc, null_provide_logctx, null_unthrottle, 0 |
| 65 | }; |
| 66 | |
| 67 | struct loop_state { |
| 68 | Terminal *term; |
| 69 | }; |
| 70 | |
| 71 | static char *null_init(void *frontend_handle, void **backend_handle, |
| 72 | Config *cfg, char *host, int port, char **realhost, |
| 73 | int nodelay) { |
| 74 | |
| 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | static char *loop_init(void *frontend_handle, void **backend_handle, |
| 79 | Config *cfg, char *host, int port, char **realhost, |
| 80 | int nodelay) { |
| 81 | struct loop_state *st = snew(struct loop_state); |
| 82 | |
| 83 | st->term = frontend_handle; |
| 84 | *backend_handle = st; |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | static void null_free(void *handle) |
| 89 | { |
| 90 | |
| 91 | } |
| 92 | |
| 93 | static void loop_free(void *handle) |
| 94 | { |
| 95 | |
| 96 | sfree(handle); |
| 97 | } |
| 98 | |
| 99 | static void null_reconfig(void *handle, Config *cfg) { |
| 100 | |
| 101 | } |
| 102 | |
| 103 | static int null_send(void *handle, char *buf, int len) { |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int loop_send(void *handle, char *buf, int len) { |
| 109 | struct loop_state *st = handle; |
| 110 | |
| 111 | return from_backend(st->term, 0, buf, len); |
| 112 | } |
| 113 | |
| 114 | static int null_sendbuffer(void *handle) { |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void null_size(void *handle, int width, int height) { |
| 120 | |
| 121 | } |
| 122 | |
| 123 | static void null_special(void *handle, Telnet_Special code) { |
| 124 | |
| 125 | } |
| 126 | |
| 127 | static const struct telnet_special *null_get_specials (void *handle) { |
| 128 | |
| 129 | return NULL; |
| 130 | } |
| 131 | |
| 132 | static Socket null_socket(void *handle) { |
| 133 | |
| 134 | return NULL; |
| 135 | } |
| 136 | |
| 137 | static int null_exitcode(void *handle) { |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int null_sendok(void *handle) { |
| 143 | |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | static void null_unthrottle(void *handle, int backlog) { |
| 148 | |
| 149 | } |
| 150 | |
| 151 | static int null_ldisc(void *handle, int option) { |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static void null_provide_ldisc (void *handle, void *ldisc) { |
| 157 | |
| 158 | } |
| 159 | |
| 160 | static void null_provide_logctx(void *handle, void *logctx) { |
| 161 | |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Emacs magic: |
| 166 | * Local Variables: |
| 167 | * c-file-style: "simon" |
| 168 | * End: |
| 169 | */ |