remove -0 on callsigns
[spider.git] / src / client.c
index 7864e9d13dc70cfab79b90f3f98e118ea7c7e47d..167ef647acacc5101cf152223117d25e9023f62c 100644 (file)
@@ -44,7 +44,7 @@
 #define MAXPATHLEN 256
 #endif
 
-#define DEFPACLEN 128
+#define DEFPACLEN 236
 #define MAXPACLEN 236
 #define MAXCALLSIGN 9
 
@@ -112,10 +112,10 @@ myregex_t iscallreg[] = {         /* regexes to determine whether this is a reasonable
                "^[0-9]+[A-Z]+[0-9]+[A-Z]+[1-9]?$", 0          /* 2E0AAA 2E0AAA1 */
        },
        {
-               "^[A-Z]+[0-9]+[A-Z]+-[1-9]$", 0                /* G1TLH-2 */
+               "^[A-Z]+[0-9]+[A-Z]+-[0-9]$", 0                /* G1TLH-2 */
        },
        {
-               "^[0-9]+[A-Z]+[0-9]+[A-Z]+-[1-9]$", 0          /* 2E0AAA-2 */
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+-[0-9]$", 0          /* 2E0AAA-2 */
        },
        {
                "^[A-Z]+[0-9]+[A-Z]+-1[0-5]$", 0               /* G1TLH-11 */
@@ -300,6 +300,26 @@ void send_msg(fcb_t *f, char let, UC *s, int l)
        f->sp->flags |= SEL_OUTPUT;
 }
 
+/* 
+ * send a file out to the user
+ */
+void send_file(char *name)
+{
+       int i;
+       char buf[MAXPACLEN+1];
+       
+       FILE *f = xopen("data", name, "r");
+       if (f) {
+               while (fgets(buf, paclen, f)) {
+                       i = strlen(buf);
+                       if (i && buf[i-1] == '\n') 
+                               buf[--i] = 0;
+                       send_text(in, buf, i, 1);
+               }
+               fclose(f);
+       }
+}
+
 /*
  * the callback (called by sel_run) that handles all the inputs and outputs
  */
@@ -387,6 +407,8 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                default:
                                        if (nl == '\n' && *p == '\r') {   /* ignore \r in telnet mode (ugh) */
                                                p++;
+                                       } else if (nl == '\r' && *p == '\n') {  /* and ignore \n in ax25 mode (double ugh) */
+                                               p++;
                                        } else if (*p == nl) {
                                                if (mp->inp == mp->data)
                                                        *mp->inp++ = ' ';
@@ -450,10 +472,8 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                                c = (ch - '0') << 4;
                                        else if (ch >= 'A' && ch <= 'F')
                                                c = (ch - 'A' + 10) << 4;
-                                       else if (ch >= 'a' && ch <= 'a')
-                                               c = (ch - 'a' + 10) << 4;
                                        else {
-                                               dbg(DMSG, "Illegal hex char (%c) received in state %d", ch, mp->state);
+                                               dbg(DMSG, "Illegal hex char (%c) received in state 1", ch);
                                                mp->inp = mp->data;
                                                mp->state = 0;
                                        }
@@ -464,10 +484,8 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                                                *mp->inp++ = c | (ch - '0');
                                        else if (ch >= 'A' && ch <= 'F')
                                                *mp->inp++ = c | (ch - 'A' + 10);
-                                       else if (ch >= 'a' && ch <= 'a')
-                                               *mp->inp++ = c | (ch - 'a' + 10);
                                        else {
-                                               dbg(DMSG, "Illegal hex char (%c) received in state %d", ch, mp->state);
+                                               dbg(DMSG, "Illegal hex char (%c) received in state 2", ch);
                                                mp->inp = mp->data;
                                        }
                                        mp->state = 0;
@@ -595,6 +613,11 @@ void process_stdin()
                        if (!iscallsign(call)) {
                                die("Sorry, %s isn't a valid callsign", call);
                        }
+                       
+                       /* strip off a '-0' at the end */
+                       i = strlen(call);
+                       if (call[i-1] == '0' && call[i-2] == '-')
+                               call[i-2] = 0;
 
                        alarm(0);
                        signal(SIGALRM, SIG_IGN);
@@ -603,6 +626,7 @@ void process_stdin()
                        send_msg(node, 'A', connsort, strlen(connsort));
                        
                        chgstate(CONNECTED);
+                       send_file("connected");
                }
 
                cmsg_callback(mp, 0);
@@ -854,34 +878,29 @@ main(int argc, char *argv[])
 
        /* is this a login? */
        if (eq(call, "LOGIN") || eq(call, "login")) {
-       
-               char buf[MAXPACLEN+1];
-               int r, i;
-               FILE *f = xopen("data", "issue", "r");
-               if (f) {
-                       while (fgets(buf, paclen, f)) {
-                               i = strlen(buf);
-                               if (i && buf[i-1] == '\n') 
-                                       buf[--i] = 0;
-                               send_text(in, buf, i, 1);
-                       }
-                       fclose(f);
-               }
+               send_file("issue");
                signal(SIGALRM, login_timeout);
                alarm(timeout);
                send_text(in, "login: ", 7, 0);
                chgstate(WAITLOGIN);
        } else {
-
+               int i;
+               
                /* check the callsign against the regexes */
                if (!iscallsign(call)) {
                        die("Sorry, %s isn't a valid callsign", call);
                }
 
+               /* strip off a '-0' at the end */
+               i = strlen(call);
+               if (call[i-1] == '0' && call[i-2] == '-')
+                       call[i-2] = 0;
+               
                /* tell the cluster who I am */
                send_msg(node, 'A', connsort, strlen(connsort));
        
                chgstate(CONNECTED);
+               send_file("connected");
        }