testback.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 1999 Simon Tatham
  3. * Copyright (c) 1999 Ben Harris
  4. * All rights reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use,
  10. * copy, modify, merge, publish, distribute, sublicense, and/or
  11. * sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  23. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. */
  27. /* PuTTY test backends */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include "putty.h"
  31. static char *loop_init(const BackendVtable *, Seat *, Backend **, LogContext *,
  32. Conf *, const char *, int, char **, bool, bool);
  33. static void loop_free(Backend *);
  34. static void null_reconfig(Backend *, Conf *);
  35. static void null_send(Backend *, const char *, size_t);
  36. static void loop_send(Backend *, const char *, size_t);
  37. static size_t null_sendbuffer(Backend *);
  38. static size_t loop_sendbuffer(Backend *);
  39. static void null_size(Backend *, int, int);
  40. static void null_special(Backend *, SessionSpecialCode, int);
  41. static const SessionSpecial *null_get_specials(Backend *);
  42. static bool null_connected(Backend *);
  43. static int null_exitcode(Backend *);
  44. static bool null_sendok(Backend *);
  45. static bool null_ldisc(Backend *, int);
  46. static void null_provide_ldisc(Backend *, Ldisc *);
  47. static void null_unthrottle(Backend *, size_t);
  48. static int null_cfg_info(Backend *);
  49. const BackendVtable null_backend = {
  50. .init = loop_init,
  51. .free = loop_free,
  52. .reconfig = null_reconfig,
  53. .send = null_send,
  54. .sendbuffer = null_sendbuffer,
  55. .size = null_size,
  56. .special = null_special,
  57. .get_specials = null_get_specials,
  58. .connected = null_connected,
  59. .exitcode = null_exitcode,
  60. .sendok = null_sendok,
  61. .ldisc_option_state = null_ldisc,
  62. .provide_ldisc = null_provide_ldisc,
  63. .unthrottle = null_unthrottle,
  64. .cfg_info = null_cfg_info,
  65. .id = "null",
  66. .displayname_tc = "Null",
  67. .displayname_lc = "null",
  68. .protocol = -1,
  69. .default_port = 0,
  70. };
  71. const BackendVtable loop_backend = {
  72. .init = loop_init,
  73. .free = loop_free,
  74. .reconfig = null_reconfig,
  75. .send = loop_send,
  76. .sendbuffer = loop_sendbuffer,
  77. .size = null_size,
  78. .special = null_special,
  79. .get_specials = null_get_specials,
  80. .connected = null_connected,
  81. .exitcode = null_exitcode,
  82. .sendok = null_sendok,
  83. .ldisc_option_state = null_ldisc,
  84. .provide_ldisc = null_provide_ldisc,
  85. .unthrottle = null_unthrottle,
  86. .cfg_info = null_cfg_info,
  87. .id = "loop",
  88. .displayname_tc = "Loop",
  89. .displayname_lc = "loop",
  90. .protocol = -1,
  91. .default_port = 0,
  92. };
  93. struct loop_state {
  94. Seat *seat;
  95. Backend backend;
  96. size_t sendbuffer;
  97. };
  98. static char *loop_init(const BackendVtable *vt, Seat *seat,
  99. Backend **backend_handle, LogContext *logctx,
  100. Conf *conf, const char *host, int port,
  101. char **realhost, bool nodelay, bool keepalive) {
  102. struct loop_state *st = snew(struct loop_state);
  103. /* No local authentication phase in this protocol */
  104. seat_set_trust_status(seat, false);
  105. st->seat = seat;
  106. st->backend.vt = vt;
  107. *backend_handle = &st->backend;
  108. *realhost = dupstr(host);
  109. return NULL;
  110. }
  111. static void loop_free(Backend *be)
  112. {
  113. struct loop_state *st = container_of(be, struct loop_state, backend);
  114. sfree(st);
  115. }
  116. static void null_reconfig(Backend *be, Conf *conf) {
  117. }
  118. static void null_send(Backend *be, const char *buf, size_t len) {
  119. }
  120. static void loop_send(Backend *be, const char *buf, size_t len) {
  121. struct loop_state *st = container_of(be, struct loop_state, backend);
  122. st->sendbuffer = seat_output(st->seat, 0, buf, len);
  123. }
  124. static size_t null_sendbuffer(Backend *be) {
  125. return 0;
  126. }
  127. static size_t loop_sendbuffer(Backend *be) {
  128. struct loop_state *st = container_of(be, struct loop_state, backend);
  129. return st->sendbuffer;
  130. }
  131. static void null_size(Backend *be, int width, int height) {
  132. }
  133. static void null_special(Backend *be, SessionSpecialCode code, int arg) {
  134. }
  135. static const SessionSpecial *null_get_specials (Backend *be) {
  136. return NULL;
  137. }
  138. static bool null_connected(Backend *be) {
  139. return false;
  140. }
  141. static int null_exitcode(Backend *be) {
  142. return 0;
  143. }
  144. static bool null_sendok(Backend *be) {
  145. return true;
  146. }
  147. static void null_unthrottle(Backend *be, size_t backlog) {
  148. }
  149. static bool null_ldisc(Backend *be, int option) {
  150. return false;
  151. }
  152. static void null_provide_ldisc (Backend *be, Ldisc *ldisc) {
  153. }
  154. static int null_cfg_info(Backend *be)
  155. {
  156. return 0;
  157. }