*** empty log message ***
[spider.git] / src / client.c
index 3dadfc59785c3dcab353538d14e7aa4e04c85384..5991ed76ffc6aa4bf1935ce5df6fce75c34ad405 100644 (file)
@@ -51,8 +51,9 @@ typedef struct
        reft *inq;                                      /* input queue */
        reft *outq;                                     /* output queue */
        sel_t *sp;                                      /* my select fcb address */
-       int echo;                                       /* echo characters back to this cnum */
        struct termios t;                       /* any termios associated with this cnum */
+       char echo;                                      /* echo characters back to this cnum */
+       char t_set;                                     /* the termios structure is valid */
 } fcb_t;
 
 char *node_addr = "localhost"; /* the node tcp address */
@@ -229,7 +230,9 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                        ++p;
                                        break;
                                default:
-                                       if (*p == nl) {
+                                       if (nl == '\n' && *p == '\r') {
+                                               p++;
+                                       } else if (*p == nl) {
                                                if (mp->inp == mp->data)
                                                        *mp->inp++ = ' ';
                                                *mp->inp = 0;              /* zero terminate it, but don't include it in the length */
@@ -269,6 +272,8 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                case 2:
                                case 3:
                                        mp->size = (mp->size << 8) | (*p++ & 0xff);
+                                       if (mp->size > MAXBUFL)
+                                               die("Message size too big from node (%d > %d)", mp->size, MAXBUFL);
                                        mp->state++;
                                        break;
                                default:
@@ -345,8 +350,14 @@ void initargs(int argc, char *argv[])
 {
        int i, c, err = 0;
 
-       while ((c = getopt(argc, argv, "x:")) > 0) {
+       while ((c = getopt(argc, argv, "h:p:x:")) > 0) {
                switch (c) {
+               case 'h':
+                       node_addr = optarg;
+                       break;
+               case 'p':
+                       node_port = atoi(optarg);
+                       break;
                case 'x':
                        dbginit("client");
                        dbgset(atoi(optarg));
@@ -423,7 +434,7 @@ void connect_to_node()
 void term_timeout(int i)
 {
        /* none of this is going to be reused so don't bother cleaning up properly */
-       if (in)
+       if (in && in->t_set)
                tcsetattr(0, TCSANOW, &in->t);
        if (node) {
                close(node->cnum);
@@ -444,7 +455,7 @@ void terminate(int i)
                   (node && !is_chain_empty(node->outq))) {
                sel_run();
        }
-       if (in)
+       if (in && in->t_set)
                tcsetattr(0, TCSANOW, &in->t);
        if (node) 
                close(node->cnum);
@@ -490,8 +501,10 @@ void process_node()
                        case 'D':
                                if (p) {
                                        int l = mp->inp - (unsigned char *) p;
+                                       if (nl == '\n' && l >= 1 && p[l-1] == '\r')       /* kludge for GB7DXM */
+                                               l--;
                                        send_text(in, p, l);
-                       }
+                               }
                                break;
                        default:
                                break;
@@ -515,19 +528,23 @@ main(int argc, char *argv[])
        signal(SIGINT, terminate);
        signal(SIGQUIT, terminate);
        signal(SIGTERM, terminate);
+#ifdef SIGPWR
        signal(SIGPWR, terminate);
+#endif
 
        /* connect up stdin, stdout and message system */
        in = fcb_new(0, TEXT);
        in->sp = sel_open(0, in, "STDIN", fcb_handler, TEXT, SEL_INPUT);
-       if (tcgetattr(0, &in->t) < 0) 
-               die("tcgetattr (%d)", errno);
-       {
+       if (tcgetattr(0, &in->t) < 0) {
+               echo = 0;
+               in->t_set = 0;
+       } else {
                struct termios t = in->t;
                t.c_lflag &= ~(ECHO|ECHONL|ICANON);
                if (tcsetattr(0, TCSANOW, &t) < 0) 
                        die("tcsetattr (%d)", errno);
                in->echo = echo;
+               in->t_set = 1;
        }
        connect_to_node();