testback.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 size_t null_send(Backend *, const char *, size_t);
  36. static size_t loop_send(Backend *, const char *, size_t);
  37. static size_t null_sendbuffer(Backend *);
  38. static void null_size(Backend *, int, int);
  39. static void null_special(Backend *, SessionSpecialCode, int);
  40. static const SessionSpecial *null_get_specials(Backend *);
  41. static int null_connected(Backend *);
  42. static int null_exitcode(Backend *);
  43. static int null_sendok(Backend *);
  44. static int null_ldisc(Backend *, int);
  45. static void null_provide_ldisc(Backend *, Ldisc *);
  46. static void null_unthrottle(Backend *, size_t);
  47. static int null_cfg_info(Backend *);
  48. const BackendVtable null_backend = {
  49. .init = loop_init,
  50. .free = loop_free,
  51. .reconfig = null_reconfig,
  52. .send = null_send,
  53. .sendbuffer = null_sendbuffer,
  54. .size = null_size,
  55. .special = null_special,
  56. .get_specials = null_get_specials,
  57. .connected = null_connected,
  58. .exitcode = null_exitcode,
  59. .sendok = null_sendok,
  60. .ldisc_option_state = null_ldisc,
  61. .provide_ldisc = null_provide_ldisc,
  62. .unthrottle = null_unthrottle,
  63. .cfg_info = null_cfg_info,
  64. .id = "null",
  65. .displayname = "null",
  66. .protocol = -1,
  67. .default_port = 0,
  68. };
  69. const BackendVtable loop_backend = {
  70. .init = loop_init,
  71. .free = loop_free,
  72. .reconfig = null_reconfig,
  73. .send = loop_send,
  74. .sendbuffer = null_sendbuffer,
  75. .size = null_size,
  76. .special = null_special,
  77. .get_specials = null_get_specials,
  78. .connected = null_connected,
  79. .exitcode = null_exitcode,
  80. .sendok = null_sendok,
  81. .ldisc_option_state = null_ldisc,
  82. .provide_ldisc = null_provide_ldisc,
  83. .unthrottle = null_unthrottle,
  84. .cfg_info = null_cfg_info,
  85. .id = "loop",
  86. .displayname = "loop",
  87. .protocol = -1,
  88. .default_port = 0,
  89. };
  90. struct loop_state {
  91. Seat *seat;
  92. Backend backend;
  93. };
  94. static char *loop_init(const BackendVtable *vt, Seat *seat,
  95. Backend **backend_handle, LogContext *logctx,
  96. Conf *conf, const char *host, int port,
  97. char **realhost, bool nodelay, bool keepalive) {
  98. struct loop_state *st = snew(struct loop_state);
  99. /* No local authentication phase in this protocol */
  100. seat_set_trust_status(seat, false);
  101. st->seat = seat;
  102. st->backend.vt = vt;
  103. *backend_handle = &st->backend;
  104. *realhost = dupstr(host);
  105. return NULL;
  106. }
  107. static void loop_free(Backend *be)
  108. {
  109. struct loop_state *st = container_of(be, struct loop_state, backend);
  110. sfree(st);
  111. }
  112. static void null_reconfig(Backend *be, Conf *conf) {
  113. }
  114. static size_t null_send(Backend *be, const char *buf, size_t len) {
  115. return 0;
  116. }
  117. static size_t loop_send(Backend *be, const char *buf, size_t len) {
  118. struct loop_state *st = container_of(be, struct loop_state, backend);
  119. return seat_output(st->seat, 0, buf, len);
  120. }
  121. static size_t null_sendbuffer(Backend *be) {
  122. return 0;
  123. }
  124. static void null_size(Backend *be, int width, int height) {
  125. }
  126. static void null_special(Backend *be, SessionSpecialCode code, int arg) {
  127. }
  128. static const SessionSpecial *null_get_specials (Backend *be) {
  129. return NULL;
  130. }
  131. static int null_connected(Backend *be) {
  132. return 0;
  133. }
  134. static int null_exitcode(Backend *be) {
  135. return 0;
  136. }
  137. static int null_sendok(Backend *be) {
  138. return 1;
  139. }
  140. static void null_unthrottle(Backend *be, size_t backlog) {
  141. }
  142. static int null_ldisc(Backend *be, int option) {
  143. return 0;
  144. }
  145. static void null_provide_ldisc (Backend *be, Ldisc *ldisc) {
  146. }
  147. static int null_cfg_info(Backend *be)
  148. {
  149. return 0;
  150. }
  151. /*
  152. * Emacs magic:
  153. * Local Variables:
  154. * c-file-style: "simon"
  155. * End:
  156. */