X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/00db133f300dd6aa08111d2b42c749a940ecede9..1b56c05584652dba13d7f4f54e7ac2560dab92fe:/logging.c diff --git a/logging.c b/logging.c index 3caa94a4..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) @@ -60,6 +73,7 @@ void log_packet(int direction, int type, char *texttype, void *data, int len) strcpy(dumpdata + 10+1+3*16+2+j, "\n"); fputs(dumpdata, lgfp); } + fflush(lgfp); } } @@ -71,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 */ @@ -97,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); } }