]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - testback.c
Initial simple raw TCP backend
[PuTTY.git] / testback.c
index b2ccd17a67e76835bf43777c7dcbce6641eff424..b3f01e90e0fdbf15c3e50293b3553bdeb2821a4f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: testback.c,v 1.1.2.3 1999/03/21 23:23:43 ben Exp $ */
+/* $Id: testback.c,v 1.1.2.8 1999/09/01 22:16:15 ben Exp $ */
 /*
  * Copyright (c) 1999 Simon Tatham
  * Copyright (c) 1999 Ben Harris
 
 /* PuTTY test backends */
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "putty.h"
 
-static char *null_init(char *, int, char **);
-static int null_msg(void);
-static void null_send(char *, int);
-static void loop_send(char *, int);
-static void null_size(void);
-static void null_special(Telnet_Special);
+static char *null_init(Session *);
+static int null_msg(Session *, SOCKET, Net_Event_Type);
+static void null_send(Session *, char *, int);
+static void loop_send(Session *, char *, int);
+static void hexdump_send(Session *, char *, int);
+static void null_size(Session *);
+static void null_special(Session *, Telnet_Special);
+static char *rawtcp_init(Session *);
+static int rawtcp_msg(Session *, SOCKET, Net_Event_Type);
 
 Backend null_backend = {
     null_init, null_msg, null_send, null_size, null_special
@@ -47,39 +51,113 @@ Backend loop_backend = {
     null_init, null_msg, loop_send, null_size, null_special
 };
 
-static char *null_init(char *host, int port, char **realhost) {
+Backend hexdump_backend = {
+    null_init, null_msg, hexdump_send, null_size, null_special
+};
+
+Backend rawtcp_backend = {
+    rawtcp_init, rawtcp_msg, null_send, null_size, null_special
+};
+
+static char *null_init(Session *s) {
 
     return NULL;
 }
 
-static int null_msg(void) {
+static int null_msg(Session *s, SOCKET sock, Net_Event_Type ne) {
 
     return 1;
 }
 
-static void null_send(char *buf, int len) {
+static void null_send(Session *s, char *buf, int len) {
 
 }
 
-static void loop_send (char *buf, int len) {
+static void loop_send (Session *s, char *buf, int len) {
+
     while (len--) {
-       int new_head = (inbuf_head + 1) & INBUF_MASK;
+       int new_head = (s->inbuf_head + 1) & INBUF_MASK;
        int c = (unsigned char) *buf;
-       if (new_head != inbuf_reap) {
-           inbuf[inbuf_head] = *buf++;
-           inbuf_head = new_head;
+       if (new_head != s->inbuf_reap) {
+           s->inbuf[s->inbuf_head] = *buf++;
+           s->inbuf_head = new_head;
        }
     }
-    term_out();
-    term_update();
+    term_out(s);
+    term_update(s);
 }
 
+static void hexdump_send(Session *s, char *buf, int len) {
+    static char mybuf[10];
+    int mylen;
 
+    while (len--) {
+       mylen = sprintf(mybuf, "%02x\015\012", (unsigned char)*buf++);
+       loop_send(s, mybuf, mylen);
+    }
+}
 
-static void null_size(void) {
+static void null_size(Session *s) {
 
 }
 
-static void null_special(Telnet_Special code) {
+static void null_special(Session *s, Telnet_Special code) {
 
 }
+
+struct rawtcp_private {
+    SOCKET s;
+};
+
+static char *rawtcp_init(Session *sess) {
+    struct rawtcp_private *rp;
+
+    sess->back_priv = smalloc(sizeof(struct rawtcp_private));
+    rp = (struct rawtcp_private *)sess->back_priv;
+    rp->s = net_open(sess, sess->cfg.host, sess->cfg.port);
+    if (rp->s == INVALID_SOCKET)
+       fatalbox("Open failed");
+}
+
+static int rawtcp_msg(Session *sess, SOCKET sock, Net_Event_Type ne) {
+    struct rawtcp_private *rp = (struct rawtcp_private *)sess->back_priv;
+
+    switch (ne) {
+      case NE_NULL:
+       break;
+      case NE_OPEN:
+       break;
+      case NE_NOHOST:
+      case NE_REFUSED:
+      case NE_NOOPEN:
+       rp->s = INVALID_SOCKET;
+       fatalbox("Open failed");
+       break;
+      case NE_DATA:
+       break;
+      case NE_URGENT:
+       break;
+      case NE_CLOSING:
+       /* net_close(rp->s);*/
+       break;
+      case NE_CLOSED:
+       rp->s = INVALID_SOCKET;
+       fatalbox("Connection closed");
+       break;
+      case NE_TIMEOUT:
+      case NE_ABORT:
+      case NE_DIED:
+       fatalbox("Connection died");
+       rp->s = INVALID_SOCKET;
+       break;
+    }
+}
+
+
+
+/*
+ * Emacs magic:
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */