From fb89f7ffb1d51a743bc2820dde96e0a798dc40c9 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 15 Sep 2002 13:21:32 +0000 Subject: [PATCH] Log file tinkering: copy Event Log entries into the SSH packet log, so that when people send us a packet log they never forget to send the Event Log alongside it :-) git-svn-id: svn://svn.tartarus.org/sgt/putty@1960 cda61777-01e9-0310-a592-d414129be87e --- logging.c | 36 +++++++++++++++++++++++++++--------- putty.h | 1 + windlg.c | 2 ++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/logging.c b/logging.c index 76dcb950..b311784b 100644 --- a/logging.c +++ b/logging.c @@ -33,11 +33,24 @@ void logtraffic(unsigned char c, int logmode) } /* + * Log an Event Log entry (used in SSH packet logging mode). + */ +void log_eventlog(char *event) +{ + if (cfg.logtype != LGTYP_PACKETS) + return; + if (!lgfp) + logfopen(); + if (lgfp) + fprintf(lgfp, "Event Log: %s\n", event); +} + +/* * Log an SSH packet. */ void log_packet(int direction, int type, char *texttype, void *data, int len) { - int i, j, c; + int i, j; char dumpdata[80], smalldata[5]; if (cfg.logtype != LGTYP_PACKETS) @@ -72,6 +85,10 @@ void logfopen(void) struct tm tm; char writemod[4]; + /* Prevent repeat calls */ + if (lgfp) + return; + if (!cfg.logtype) return; sprintf(writemod, "wb"); /* default to rewrite */ @@ -98,20 +115,21 @@ void logfopen(void) lgfp = fopen(currlogfilename, writemod); if (lgfp) { /* enter into event log */ - sprintf(buf, "%s session log (%s mode) to file : ", + /* --- write header line into log file */ + fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", lgfp); + strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm); + fputs(buf, lgfp); + fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", lgfp); + + sprintf(buf, "%s session log (%s mode) to file: ", (writemod[0] == 'a') ? "Appending" : "Writing new", (cfg.logtype == LGTYP_ASCII ? "ASCII" : - cfg.logtype == LGTYP_DEBUG ? "raw" : "")); + cfg.logtype == LGTYP_DEBUG ? "raw" : + cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "")); /* Make sure we do not exceed the output buffer size */ strncat(buf, currlogfilename, 128); buf[strlen(buf)] = '\0'; logevent(buf); - - /* --- write header line into log file */ - fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", lgfp); - strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm); - fputs(buf, lgfp); - fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", lgfp); } } diff --git a/putty.h b/putty.h index e2a7fea7..d69339a8 100644 --- a/putty.h +++ b/putty.h @@ -518,6 +518,7 @@ void term_reconfig(void); */ void logtraffic(unsigned char c, int logmode); enum { PKT_INCOMING, PKT_OUTGOING }; +void log_eventlog(char *string); void log_packet(int direction, int type, char *texttype, void *data, int len); /* diff --git a/windlg.c b/windlg.c index 76d4804f..c8f7ec1e 100644 --- a/windlg.c +++ b/windlg.c @@ -3705,6 +3705,8 @@ void logevent(char *string) char timebuf[40]; time_t t; + log_eventlog(string); + if (nevents >= negsize) { negsize += 64; events = srealloc(events, negsize * sizeof(*events)); -- 2.11.0