fixed connect code in client.pl so it doesn't falsely recognise /spider
[spider.git] / src / client.c
index b50514fa618f47bb0895bbdb61977ac1c43d0402..8c52d53ffa921839d491a76ed137c0aeccfef971 100644 (file)
 #define MAXPATHLEN 256
 #endif
 
+#define DEFPACLEN 128
 #define MAXPACLEN 236
+#define MAXCALLSIGN 9
+
 #define DBUF 1
 #define DMSG 2
 
@@ -84,15 +87,27 @@ char echo = 1;                                      /* echo characters on stdout from stdin */
 char int_tabs = 0;                             /* interpret tabs -> spaces */
 char *root = "/spider";         /* root of data tree, can be overridden by DXSPIDER_ROOT  */
 int timeout = 60;                              /* default timeout for logins and things */
-int paclen = 128;                              /* default buffer size for outgoing packets */
+int paclen = DEFPACLEN;                        /* default buffer size for outgoing packets */
 int tabsize = 8;                               /* default tabsize for text messages */
 
 myregex_t iscallreg[] = {              /* regexes to determine whether this is a reasonable callsign */
        {
-               "^[A-Z]+[0-9]+[A-Z]+", 0
+               "^[A-Z]+[0-9]+[A-Z]+[1-9]?$", 0                /* G1TLH G1TLH1 */
+       },
+       {
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+[1-9]?$", 0          /* 2E0AAA 2E0AAA1 */
+       },
+       {
+               "^[A-Z]+[0-9]+[A-Z]+-[1-9]$", 0                /* G1TLH-2 */
+       },
+       {
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+-[1-9]$", 0          /* 2E0AAA-2 */
+       },
+       {
+               "^[A-Z]+[0-9]+[A-Z]+-1[0-5]$", 0               /* G1TLH-11 */
        },
        {
-               "^[0-9]+[A-Z]+[0-9]+[A-Z]+", 0
+               "^[0-9]+[A-Z]+[0-9]+[A-Z]+-1[0-5]$", 0         /* 2E0AAA-11 */
        },
        {
                0, 0
@@ -154,6 +169,10 @@ int xopen(char *dir, char *name, int mode)
 int iscallsign(char *s)
 {
        myregex_t *rp;
+
+       if (strlen(s) > MAXCALLSIGN)
+               return 0;
+       
        for (rp = iscallreg; rp->in; ++rp) {
                if (regexec(rp->regex, s, 0, 0, 0) == 0)
                        return 1;
@@ -198,6 +217,10 @@ void send_text(fcb_t *f, char *s, int l)
                f->obuf = mp = cmsg_new(paclen+1, f->sort, f);
        }
 
+       /* remove trailing spaces  */
+       while (l > 0 &&isspace(s[l-1]))
+               --l;
+
        for (p = s; p < s+l; ) {
                if (mp->inp >= mp->data + paclen) {
                        flush_text(f);
@@ -488,6 +511,11 @@ lerr:
                nl = '\n';
                echo = 1;
        }
+
+       /* this is kludgy, but hey so is the rest of this! */
+       if (!eq(connsort, "ax25") && paclen == DEFPACLEN) {
+               paclen = MAXPACLEN;
+       }
 }
 
 void connect_to_node()
@@ -707,9 +735,11 @@ main(int argc, char *argv[])
                }
                buf[r] = 0;
                call = strupper(buf);
-               if (!iscallsign(call)) {
-                       die("Sorry, %s isn't a valid callsign", buf);
-               }
+       }
+
+       /* check the callsign */
+       if (!iscallsign(call)) {
+               die("Sorry, %s isn't a valid callsign", call);
        }
        
        /* connect up stdin */