1. I believe I have fixed all the login/logout 'broken pipe' errors
[spider.git] / src / client.c
index cd11c78b53b45446b654744c721f4abb7b672b6f..885b50efa3601a019e4038001dbb84f9787eaae5 100644 (file)
@@ -81,6 +81,7 @@ char *connsort;                                       /* the type of connection */
 fcb_t *in;                                             /* the fcb of 'stdin' that I shall use */
 fcb_t *node;                                   /* the fcb of the msg system */
 char nl = '\n';                                        /* line end character */
+char mode = 1;                  /* 0 - ax25, 1 - normal telnet, 2 - nlonly telnet */
 char ending = 0;                               /* set this to end the program */
 char send_Z = 1;                               /* set a Z record to the node on termination */
 char echo = 1;                                 /* echo characters on stdout from stdin */
@@ -89,6 +90,8 @@ char *root = "/spider";         /* root of data tree, can be overridden by DXSPI
 int timeout = 60;                              /* default timeout for logins and things */
 int paclen = DEFPACLEN;                        /* default buffer size for outgoing packets */
 int tabsize = 8;                               /* default tabsize for text messages */
+char *connsort = "local";              /* the connection variety */
+
 
 myregex_t iscallreg[] = {              /* regexes to determine whether this is a reasonable callsign */
        {
@@ -235,7 +238,8 @@ void send_text(fcb_t *f, char *s, int l)
        if (nl == '\r')
                *mp->inp++ = nl;
        else {
-               *mp->inp++ = '\r';
+               if (mode != 2)
+                       *mp->inp++ = '\r';
                *mp->inp++ = '\n';
        }
        if (!f->buffer_it)
@@ -287,7 +291,7 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
        unsigned char c;
        
        /* input modes */
-       if (in) {
+       if (ending == 0 && in) {
                char *p, buf[MAXBUFL];
                int r;
 
@@ -352,7 +356,7 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                                *mp->inp++ = *p++;
                                        }
                                        break;
-                               case '\b':
+                               case 0x08:
                                case 0x7f:
                                        if (mp->inp > mp->data)
                                                mp->inp--;
@@ -500,6 +504,29 @@ lend:;
        return 0;
 }
 
+/* 
+ * set up the various mode flags, NL endings and things
+ */
+void setmode(char *m)
+{
+       connsort = strlower(m);
+       if (eq(connsort, "telnet") || eq(connsort, "local") || eq(connsort, "nlonly")) {
+               nl = '\n';
+               echo = 1;
+               mode = eq(connsort, "nlonly") ? 2 : 1;
+       } else if (eq(connsort, "ax25")) {
+               nl = '\r';
+               echo = 0;
+               mode = 0;
+       } else if (eq(connsort, "connect")) {
+               nl = '\n';
+               echo = 0;
+               mode = 3;
+       } else {
+               die("Connection type must be \"telnet\", \"nlonly\", \"ax25\", \"login\" or \"local\"");
+       }
+}
+
 /*
  * things to do with initialisation
  */
@@ -546,24 +573,13 @@ lerr:
                die("Must have at least a callsign (for now)");
 
        if (optind < argc) {
-               connsort = strlower(argv[optind]);
-               if (eq(connsort, "telnet") || eq(connsort, "local")) {
-                       nl = '\n';
-                       echo = 1;
-               } else if (eq(connsort, "ax25")) {
-                       nl = '\r';
-                       echo = 0;
-               } else {
-                       die("2nd argument must be \"telnet\" or \"ax25\" or \"local\"");
-               }
+               setmode(argv[optind]);          
        } else {
-               connsort = "local";
-               nl = '\n';
-               echo = 1;
+               setmode("local");
        }
 
        /* this is kludgy, but hey so is the rest of this! */
-       if (!eq(connsort, "ax25") && paclen == DEFPACLEN) {
+       if (mode != 0 && paclen == DEFPACLEN) {
                paclen = MAXPACLEN;
        }
 }
@@ -613,9 +629,11 @@ void term_timeout(int i)
 
 void terminate(int i)
 {
+#if 0
        if (node && send_Z && call) {
                send_msg(node, 'Z', "bye", 3);
        }
+#endif
        
        signal(SIGALRM, term_timeout);
        alarm(10);
@@ -755,7 +773,8 @@ main(int argc, char *argv[])
        }
        
        /* is this a login? */
-       if (eq(call, "LOGIN")) {
+       if (eq(call, "LOGIN") || eq(call, "login")) {
+       
                char buf[MAXPACLEN+1];
                char callsign[MAXCALLSIGN+1];
                int r, i;
@@ -789,7 +808,7 @@ main(int argc, char *argv[])
                                if (i < MAXCALLSIGN) {
                                        if (*p == '\r' || *p == '\n')
                                                goto lgotcall;
-                                       else if (isalnum(*p))
+                                       else if (isalnum(*p) || *p == '-')
                                                callsign[i++] = *p;
                                        else
                                                die("%c is not a valid callsign character", *p);
@@ -814,6 +833,7 @@ lgotcall:
        in->sp = sel_open(0, in, "STDIN", fcb_handler, TEXT, SEL_INPUT);
        if (tcgetattr(0, &in->t) < 0) {
 /*             echo = 0; */
+               in->echo = echo;
                in->t_set = 0;
        } else {
                struct termios t = in->t;
@@ -832,9 +852,9 @@ lgotcall:
        send_msg(node, 'A', connsort, strlen(connsort));
        
        /* main processing loop */
-       while (!ending) {
+       while (ending == 0) {
                sel_run();
-               if (!ending) {
+               if (ending == 0) {
                        process_stdin();
                        process_node();
                }