]> git.ozlabs.org Git - ppp.git/blobdiff - chat/chat.c
use strlog on SNI
[ppp.git] / chat / chat.c
index 115ab2d8bdcbba115d25ad4b93cde0b491c2ead3..812a785fb5e453293d9a1a6d706974da7dac4ddc 100644 (file)
  *
  */
 
-static char rcsid[] = "$Id: chat.c,v 1.12 1996/06/26 00:51:06 paulus Exp $";
+#ifndef lint
+static char rcsid[] = "$Id: chat.c,v 1.14 1997/04/30 05:40:50 paulus Exp $";
+#endif
 
 #include <stdio.h>
+#include <ctype.h>
 #include <time.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <syslog.h>
@@ -160,6 +164,9 @@ char *clean __P((register char *s, int sending));
 void break_sequence __P((void));
 void terminate __P((int status));
 void die __P((void));
+char *expect_strtok __P((char *, char *));
+
+int main __P((int, char *[]));
 
 void *dup_mem(b, c)
 void *b;
@@ -197,7 +204,7 @@ char **argv;
     program_name = *argv;
     tzset();
 
-    while (option = OPTION(argc, argv))
+    while ((option = OPTION(argc, argv)) != 0)
         {
        switch (option)
            {
@@ -214,7 +221,7 @@ char **argv;
                break;
 
            case 'f':
-               if (arg = OPTARG(argc, argv))
+               if ((arg = OPTARG(argc, argv)) != NULL)
                    {
                    chat_file = copy_of(arg);
                    }
@@ -225,7 +232,7 @@ char **argv;
                break;
 
            case 't':
-               if (arg = OPTARG(argc, argv))
+               if ((arg = OPTARG(argc, argv)) != NULL)
                    {
                    timeout = atoi(arg);
                    }
@@ -301,37 +308,19 @@ char **argv;
        }
     else
        {
-       while (arg = ARG(argc, argv))
+       while ((arg = ARG(argc, argv)) != NULL)
            {
            chat_expect(arg);
 
-           if (arg = ARG(argc, argv))
+           if ((arg = ARG(argc, argv)) != NULL)
                {
                chat_send(arg);
                }
            }
        }
-/*
- * Allow the last of the report string to be gathered before we terminate.
- */
-    while (report_gathering)
-        {
-       int c;
-       c = get_char();
-       if (!iscntrl (c))
-           {
-           int rep_len = strlen (report_buffer);
-           report_buffer[rep_len]     = c;
-           report_buffer[rep_len + 1] = '\0';
-           }
-       else
-           {
-           report_gathering = 0;
-           fprintf (report_fp, "chat:  %s\n", report_buffer);
-           }
-        }
 
     terminate(0);
+    return 0;
     }
 
 /*
@@ -341,7 +330,7 @@ char **argv;
 void do_file (chat_file)
 char *chat_file;
     {
-    int linect, len, sendflg;
+    int linect, sendflg;
     char *sp, *arg, quote;
     char buf [STR_LEN];
     FILE *cfp;
@@ -435,21 +424,25 @@ Usage: %s [-e] [-v] [-t timeout] [-r report-file] {-f chat-file | chat-script}\n
     exit(1);
     }
 
-char line[256];
+char line[128];
 char *p;
 
 void logf (str)
 const char *str;
-    {
-    p = line + strlen(line);
-    strcat (p, str);
+{
+    int l = strlen(line);
 
-    if (str[strlen(str)-1] == '\n')
-       {
+    if (l + strlen(str) >= sizeof(line)) {
+       syslog(LOG_INFO, "%s", line);
+       l = 0;
+    }
+    strcpy(line + l, str);
+
+    if (str[strlen(str)-1] == '\n') {
        syslog (LOG_INFO, "%s", line);
        line[0] = 0;
-       }
     }
+}
 
 void logflush()
     {
@@ -608,7 +601,26 @@ int status;
     {
     echo_stderr(-1);
     if (report_file != (char *) 0 && report_fp != (FILE *) NULL)
-        {
+       {
+/*
+ * Allow the last of the report string to be gathered before we terminate.
+ */
+       if (report_gathering) {
+           int c, rep_len;
+
+           rep_len = strlen(report_buffer);
+           while (rep_len + 1 <= sizeof(report_buffer)) {
+               alarm(1);
+               c = get_char();
+               alarm(0);
+               if (c < 0 || iscntrl(c))
+                   break;
+               report_buffer[rep_len] = c;
+               ++rep_len;
+           }
+           report_buffer[rep_len] = 0;
+           fprintf (report_fp, "chat:  %s\n", report_buffer);
+       }
        if (verbose)
            {
            fprintf (report_fp, "Closing \"%s\".\n", report_file);
@@ -710,7 +722,7 @@ int sending;
            break;
 
        case 'q':
-           quiet = ! quiet;
+           quiet = 1;
            break;
 
        case 'r':
@@ -1175,6 +1187,7 @@ int c;
 int put_string (s)
 register char *s;
     {
+    quiet = 0;
     s = clean(s, 1);
 
     if (verbose)