From 3814a5cee87e759568f53df4497d48d61e66cf84 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 11 Sep 2018 15:17:16 +0100 Subject: [PATCH] Make 'LogContext' a typedef visible throughout the code. Same principle again - the more of these structures have globally visible tags (even if the structure contents are still opaque in most places), the fewer of them I can mistake for each other. --- cmdgen.c | 2 +- defs.h | 1 + logging.c | 40 ++++++++++++++++------------------------ pscp.c | 2 +- psftp.c | 2 +- putty.h | 24 ++++++++++++------------ raw.c | 2 +- rlogin.c | 2 +- ssh.c | 4 ++-- sshbpp.h | 2 +- telnet.c | 2 +- terminal.c | 2 +- terminal.h | 2 +- testback.c | 4 ++-- unix/gtkwin.c | 2 +- unix/uxcons.c | 2 +- unix/uxpgnt.c | 2 +- unix/uxplink.c | 2 +- unix/uxpty.c | 2 +- unix/uxser.c | 2 +- windows/wincons.c | 2 +- windows/winser.c | 2 +- windows/winstuff.h | 2 +- 23 files changed, 51 insertions(+), 58 deletions(-) diff --git a/cmdgen.c b/cmdgen.c index 7cf920f36..034b9154f 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -116,7 +116,7 @@ void nonfatal(const char *p, ...) /* * Stubs to let everything else link sensibly. */ -void log_eventlog(void *handle, const char *event) +void log_eventlog(LogContext *logctx, const char *event) { } char *x_get_default(const char *key) diff --git a/defs.h b/defs.h index f1d73fb50..45b56d60f 100644 --- a/defs.h +++ b/defs.h @@ -45,6 +45,7 @@ typedef struct Socket_vtable Socket_vtable; typedef struct Plug_vtable Plug_vtable; typedef struct Ldisc_tag Ldisc; +typedef struct LogContext_tag LogContext; /* Note indirection: for historical reasons (it used to be closer to * the OS socket type), the type that most code uses for a socket is diff --git a/logging.c b/logging.c index 41c5b257b..75c457e3e 100644 --- a/logging.c +++ b/logging.c @@ -12,7 +12,7 @@ #include "putty.h" /* log session to file stuff ... */ -struct LogContext { +struct LogContext_tag { FILE *lgfp; enum { L_CLOSED, L_OPENING, L_OPEN, L_ERROR } state; bufchain queue; @@ -31,7 +31,7 @@ static Filename *xlatlognam(Filename *s, char *hostname, int port, * isn't open, buffering data if it's in the process of being * opened asynchronously, etc. */ -static void logwrite(struct LogContext *ctx, void *data, int len) +static void logwrite(LogContext *ctx, void *data, int len) { /* * In state L_CLOSED, we call logfopen, which will set the state @@ -59,7 +59,7 @@ static void logwrite(struct LogContext *ctx, void *data, int len) * Convenience wrapper on logwrite() which printf-formats the * string. */ -static void logprintf(struct LogContext *ctx, const char *fmt, ...) +static void logprintf(LogContext *ctx, const char *fmt, ...) { va_list ap; char *data; @@ -75,16 +75,16 @@ static void logprintf(struct LogContext *ctx, const char *fmt, ...) /* * Flush any open log file. */ -void logflush(void *handle) { - struct LogContext *ctx = (struct LogContext *)handle; +void logflush(LogContext *ctx) +{ if (ctx->logtype > 0) if (ctx->state == L_OPEN) fflush(ctx->lgfp); } -static void logfopen_callback(void *handle, int mode) +static void logfopen_callback(void *vctx, int mode) { - struct LogContext *ctx = (struct LogContext *)handle; + LogContext *ctx = (LogContext *)vctx; char buf[256], *event; struct tm tm; const char *fmode; @@ -160,9 +160,8 @@ static void logfopen_callback(void *handle, int mode) * file and asking the user whether they want to append, overwrite * or cancel logging. */ -void logfopen(void *handle) +void logfopen(LogContext *ctx) { - struct LogContext *ctx = (struct LogContext *)handle; struct tm tm; int mode; @@ -199,9 +198,8 @@ void logfopen(void *handle) logfopen_callback(ctx, mode); /* open the file */ } -void logfclose(void *handle) +void logfclose(LogContext *ctx) { - struct LogContext *ctx = (struct LogContext *)handle; if (ctx->lgfp) { fclose(ctx->lgfp); ctx->lgfp = NULL; @@ -212,9 +210,8 @@ void logfclose(void *handle) /* * Log session traffic. */ -void logtraffic(void *handle, unsigned char c, int logmode) +void logtraffic(LogContext *ctx, unsigned char c, int logmode) { - struct LogContext *ctx = (struct LogContext *)handle; if (ctx->logtype > 0) { if (ctx->logtype == logmode) logwrite(ctx, &c, 1); @@ -230,9 +227,8 @@ void logtraffic(void *handle, unsigned char c, int logmode) * platforms. Platforms which don't have a meaningful stderr can * just avoid defining FLAG_STDERR. */ -void log_eventlog(void *handle, const char *event) +void log_eventlog(LogContext *ctx, const char *event) { - struct LogContext *ctx = (struct LogContext *)handle; if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE)) { fprintf(stderr, "%s\n", event); fflush(stderr); @@ -252,13 +248,12 @@ void log_eventlog(void *handle, const char *event) * If n_blanks != 0, blank or omit some parts. * Set of blanking areas must be in increasing order. */ -void log_packet(void *handle, int direction, int type, +void log_packet(LogContext *ctx, int direction, int type, const char *texttype, const void *data, int len, int n_blanks, const struct logblank_t *blanks, const unsigned long *seq, unsigned downstream_id, const char *additional_log_text) { - struct LogContext *ctx = (struct LogContext *)handle; char dumpdata[80], smalldata[5]; int p = 0, b = 0, omitted = 0; int output_pos = 0; /* NZ if pending output in dumpdata */ @@ -372,9 +367,9 @@ void log_packet(void *handle, int direction, int type, logflush(ctx); } -void *log_init(void *frontend, Conf *conf) +LogContext *log_init(void *frontend, Conf *conf) { - struct LogContext *ctx = snew(struct LogContext); + LogContext *ctx = snew(LogContext); ctx->lgfp = NULL; ctx->state = L_CLOSED; ctx->frontend = frontend; @@ -385,10 +380,8 @@ void *log_init(void *frontend, Conf *conf) return ctx; } -void log_free(void *handle) +void log_free(LogContext *ctx) { - struct LogContext *ctx = (struct LogContext *)handle; - logfclose(ctx); bufchain_clear(&ctx->queue); if (ctx->currlogfilename) @@ -397,9 +390,8 @@ void log_free(void *handle) sfree(ctx); } -void log_reconfig(void *handle, Conf *conf) +void log_reconfig(LogContext *ctx, Conf *conf) { - struct LogContext *ctx = (struct LogContext *)handle; int reset_logging; if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename), diff --git a/pscp.c b/pscp.c index 964e24433..bc2140f52 100644 --- a/pscp.c +++ b/pscp.c @@ -340,7 +340,7 @@ static void do_cmd(char *host, char *user, char *cmd) { const char *err; char *realhost; - void *logctx; + LogContext *logctx; if (host == NULL || host[0] == '\0') bump("Empty host name"); diff --git a/psftp.c b/psftp.c index b28c09769..cd419ebee 100644 --- a/psftp.c +++ b/psftp.c @@ -2669,7 +2669,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) { char *host, *realhost; const char *err; - void *logctx; + LogContext *logctx; /* Separate host and username */ host = userhost; diff --git a/putty.h b/putty.h index 042f66c50..14451756a 100644 --- a/putty.h +++ b/putty.h @@ -462,7 +462,7 @@ struct backend_tag { int (*sendok) (void *handle); int (*ldisc) (void *handle, int); void (*provide_ldisc) (void *handle, Ldisc *ldisc); - void (*provide_logctx) (void *handle, void *logctx); + void (*provide_logctx) (void *handle, LogContext *logctx); /* * back->unthrottle() tells the back end that the front end * buffer is clearing. @@ -1110,7 +1110,7 @@ int term_data_untrusted(Terminal *, const void *data, int len); void term_provide_resize_fn(Terminal *term, void (*resize_fn)(void *, int, int), void *resize_ctx); -void term_provide_logctx(Terminal *term, void *logctx); +void term_provide_logctx(Terminal *term, LogContext *logctx); void term_set_focus(Terminal *term, int has_focus); char *term_get_ttymode(Terminal *term, const char *mode); int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input); @@ -1120,14 +1120,14 @@ int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl); /* * Exports from logging.c. */ -void *log_init(void *frontend, Conf *conf); -void log_free(void *logctx); -void log_reconfig(void *logctx, Conf *conf); -void logfopen(void *logctx); -void logfclose(void *logctx); -void logtraffic(void *logctx, unsigned char c, int logmode); -void logflush(void *logctx); -void log_eventlog(void *logctx, const char *string); +LogContext *log_init(void *frontend, Conf *conf); +void log_free(LogContext *logctx); +void log_reconfig(LogContext *logctx, Conf *conf); +void logfopen(LogContext *logctx); +void logfclose(LogContext *logctx); +void logtraffic(LogContext *logctx, unsigned char c, int logmode); +void logflush(LogContext *logctx); +void log_eventlog(LogContext *logctx, const char *string); enum { PKT_INCOMING, PKT_OUTGOING }; enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT }; struct logblank_t { @@ -1135,7 +1135,7 @@ struct logblank_t { int len; int type; }; -void log_packet(void *logctx, int direction, int type, +void log_packet(LogContext *logctx, int direction, int type, const char *texttype, const void *data, int len, int n_blanks, const struct logblank_t *blanks, const unsigned long *sequence, @@ -1353,7 +1353,7 @@ int askappend(void *frontend, Filename *filename, */ extern int console_batch_mode; int console_get_userpass_input(prompts_t *p); -void console_provide_logctx(void *logctx); +void console_provide_logctx(LogContext *logctx); int is_interactive(void); /* diff --git a/raw.c b/raw.c index 58a500c7d..658bd0309 100644 --- a/raw.c +++ b/raw.c @@ -279,7 +279,7 @@ static void raw_provide_ldisc(void *handle, Ldisc *ldisc) /* This is a stub. */ } -static void raw_provide_logctx(void *handle, void *logctx) +static void raw_provide_logctx(void *handle, LogContext *logctx) { /* This is a stub. */ } diff --git a/rlogin.c b/rlogin.c index 7f9093e44..dcba9c0c8 100644 --- a/rlogin.c +++ b/rlogin.c @@ -371,7 +371,7 @@ static void rlogin_provide_ldisc(void *handle, Ldisc *ldisc) /* This is a stub. */ } -static void rlogin_provide_logctx(void *handle, void *logctx) +static void rlogin_provide_logctx(void *handle, LogContext *logctx) { /* This is a stub. */ } diff --git a/ssh.c b/ssh.c index d02b73215..609e1155c 100644 --- a/ssh.c +++ b/ssh.c @@ -701,7 +701,7 @@ struct ssh_tag { const Plug_vtable *plugvt; Ldisc *ldisc; - void *logctx; + LogContext *logctx; unsigned char session_key[32]; int v1_remote_protoflags; @@ -11434,7 +11434,7 @@ static void ssh_provide_ldisc(void *handle, Ldisc *ldisc) ssh->ldisc = ldisc; } -static void ssh_provide_logctx(void *handle, void *logctx) +static void ssh_provide_logctx(void *handle, LogContext *logctx) { Ssh ssh = (Ssh) handle; ssh->logctx = logctx; diff --git a/sshbpp.h b/sshbpp.h index 5ec3c6ced..c1ac7a139 100644 --- a/sshbpp.h +++ b/sshbpp.h @@ -19,7 +19,7 @@ struct BinaryPacketProtocol { bufchain *in_raw, *out_raw; PacketQueue *in_pq; PacketLogSettings *pls; - void *logctx; + LogContext *logctx; int seen_disconnect; char *error; diff --git a/telnet.c b/telnet.c index 0f958b501..ed5852764 100644 --- a/telnet.c +++ b/telnet.c @@ -1065,7 +1065,7 @@ static void telnet_provide_ldisc(void *handle, Ldisc *ldisc) telnet->ldisc = ldisc; } -static void telnet_provide_logctx(void *handle, void *logctx) +static void telnet_provide_logctx(void *handle, LogContext *logctx) { /* This is a stub. */ } diff --git a/terminal.c b/terminal.c index a368b23fd..04e222d08 100644 --- a/terminal.c +++ b/terminal.c @@ -6687,7 +6687,7 @@ int term_data_untrusted(Terminal *term, const void *vdata, int len) return 0; /* assumes that term_data() always returns 0 */ } -void term_provide_logctx(Terminal *term, void *logctx) +void term_provide_logctx(Terminal *term, LogContext *logctx) { term->logctx = logctx; } diff --git a/terminal.h b/terminal.h index 3eb60939f..244ff3bc2 100644 --- a/terminal.h +++ b/terminal.h @@ -234,7 +234,7 @@ struct terminal_tag { void *frontend; - void *logctx; + LogContext *logctx; struct unicode_data *ucsdata; diff --git a/testback.c b/testback.c index d84c77db1..78b893331 100644 --- a/testback.c +++ b/testback.c @@ -50,7 +50,7 @@ static int null_exitcode(void *); static int null_sendok(void *); static int null_ldisc(void *, int); static void null_provide_ldisc(void *, Ldisc *); -static void null_provide_logctx(void *, void *); +static void null_provide_logctx(void *, LogContext *); static void null_unthrottle(void *, int); static int null_cfg_info(void *); @@ -161,7 +161,7 @@ static void null_provide_ldisc (void *handle, Ldisc *ldisc) { } -static void null_provide_logctx(void *handle, void *logctx) { +static void null_provide_logctx(void *handle, LogContext *logctx) { } diff --git a/unix/gtkwin.c b/unix/gtkwin.c index e28146b43..18bea32f0 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -162,7 +162,7 @@ struct gui_data { Backend *back; void *backhandle; Terminal *term; - void *logctx; + LogContext *logctx; int exited; struct unicode_data ucsdata; Conf *conf; diff --git a/unix/uxcons.c b/unix/uxcons.c index d0fe986b8..e7f531dc5 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -405,7 +405,7 @@ void old_keyfile_warning(void) postmsg(&cf); } -void console_provide_logctx(void *logctx) +void console_provide_logctx(LogContext *logctx) { console_logctx = logctx; } diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 0e37c1a02..07248d397 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -92,7 +92,7 @@ int platform_default_i(const char *name, int def) { return def; } FontSpec *platform_default_fontspec(const char *name) { return fontspec_new(""); } Filename *platform_default_filename(const char *name) { return filename_from_str(""); } char *x_get_default(const char *key) { return NULL; } -void log_eventlog(void *handle, const char *event) {} +void log_eventlog(LogContext *logctx, const char *event) {} int from_backend(void *frontend, int is_stderr, const void *data, int datalen) { assert(!"only here to satisfy notional call from backend_socket_log"); } diff --git a/unix/uxplink.c b/unix/uxplink.c index a8d35b7a6..64e29c31e 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -25,7 +25,7 @@ #define MAX_STDIN_BACKLOG 4096 -static void *logctx; +static LogContext *logctx; static struct termios orig_termios; diff --git a/unix/uxpty.c b/unix/uxpty.c index 9df615322..b1204a107 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1212,7 +1212,7 @@ static void pty_provide_ldisc(void *handle, Ldisc *ldisc) /* This is a stub. */ } -static void pty_provide_logctx(void *handle, void *logctx) +static void pty_provide_logctx(void *handle, LogContext *logctx) { /* Pty pty = (Pty)handle; */ /* This is a stub. */ diff --git a/unix/uxser.c b/unix/uxser.c index 558cf0152..50eb83e6a 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -549,7 +549,7 @@ static void serial_provide_ldisc(void *handle, Ldisc *ldisc) /* This is a stub. */ } -static void serial_provide_logctx(void *handle, void *logctx) +static void serial_provide_logctx(void *handle, LogContext *logctx) { /* This is a stub. */ } diff --git a/windows/wincons.c b/windows/wincons.c index 4827ddbde..a7cbeeac1 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -335,7 +335,7 @@ void pgp_fingerprints(void) " " PGP_PREV_MASTER_KEY_FP "\n", stdout); } -void console_provide_logctx(void *logctx) +void console_provide_logctx(LogContext *logctx) { console_logctx = logctx; } diff --git a/windows/winser.c b/windows/winser.c index 2dd45fac5..f0ea94bd1 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -414,7 +414,7 @@ static void serial_provide_ldisc(void *handle, Ldisc *ldisc) /* This is a stub. */ } -static void serial_provide_logctx(void *handle, void *logctx) +static void serial_provide_logctx(void *handle, LogContext *logctx) { /* This is a stub. */ } diff --git a/windows/winstuff.h b/windows/winstuff.h index 5dc18fb1d..727c4b06b 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -240,7 +240,7 @@ void quit_help(HWND hwnd); * windlg.c. Likewise the saved-sessions list. */ GLOBAL Terminal *term; -GLOBAL void *logctx; +GLOBAL LogContext *logctx; /* * Windows-specific clipboard helper function shared with windlg.c,