1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 06:38:37 -05:00

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.
This commit is contained in:
Simon Tatham 2018-09-11 15:17:16 +01:00
parent e72e8ebe59
commit 3814a5cee8
23 changed files with 51 additions and 58 deletions

View File

@ -116,7 +116,7 @@ void nonfatal(const char *p, ...)
/* /*
* Stubs to let everything else link sensibly. * 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) char *x_get_default(const char *key)

1
defs.h
View File

@ -45,6 +45,7 @@ typedef struct Socket_vtable Socket_vtable;
typedef struct Plug_vtable Plug_vtable; typedef struct Plug_vtable Plug_vtable;
typedef struct Ldisc_tag Ldisc; typedef struct Ldisc_tag Ldisc;
typedef struct LogContext_tag LogContext;
/* Note indirection: for historical reasons (it used to be closer to /* 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 * the OS socket type), the type that most code uses for a socket is

View File

@ -12,7 +12,7 @@
#include "putty.h" #include "putty.h"
/* log session to file stuff ... */ /* log session to file stuff ... */
struct LogContext { struct LogContext_tag {
FILE *lgfp; FILE *lgfp;
enum { L_CLOSED, L_OPENING, L_OPEN, L_ERROR } state; enum { L_CLOSED, L_OPENING, L_OPEN, L_ERROR } state;
bufchain queue; 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 * isn't open, buffering data if it's in the process of being
* opened asynchronously, etc. * 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 * 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 * Convenience wrapper on logwrite() which printf-formats the
* string. * string.
*/ */
static void logprintf(struct LogContext *ctx, const char *fmt, ...) static void logprintf(LogContext *ctx, const char *fmt, ...)
{ {
va_list ap; va_list ap;
char *data; char *data;
@ -75,16 +75,16 @@ static void logprintf(struct LogContext *ctx, const char *fmt, ...)
/* /*
* Flush any open log file. * Flush any open log file.
*/ */
void logflush(void *handle) { void logflush(LogContext *ctx)
struct LogContext *ctx = (struct LogContext *)handle; {
if (ctx->logtype > 0) if (ctx->logtype > 0)
if (ctx->state == L_OPEN) if (ctx->state == L_OPEN)
fflush(ctx->lgfp); 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; char buf[256], *event;
struct tm tm; struct tm tm;
const char *fmode; 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 * file and asking the user whether they want to append, overwrite
* or cancel logging. * or cancel logging.
*/ */
void logfopen(void *handle) void logfopen(LogContext *ctx)
{ {
struct LogContext *ctx = (struct LogContext *)handle;
struct tm tm; struct tm tm;
int mode; int mode;
@ -199,9 +198,8 @@ void logfopen(void *handle)
logfopen_callback(ctx, mode); /* open the file */ logfopen_callback(ctx, mode); /* open the file */
} }
void logfclose(void *handle) void logfclose(LogContext *ctx)
{ {
struct LogContext *ctx = (struct LogContext *)handle;
if (ctx->lgfp) { if (ctx->lgfp) {
fclose(ctx->lgfp); fclose(ctx->lgfp);
ctx->lgfp = NULL; ctx->lgfp = NULL;
@ -212,9 +210,8 @@ void logfclose(void *handle)
/* /*
* Log session traffic. * 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 > 0) {
if (ctx->logtype == logmode) if (ctx->logtype == logmode)
logwrite(ctx, &c, 1); 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 * platforms. Platforms which don't have a meaningful stderr can
* just avoid defining FLAG_STDERR. * 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)) { if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE)) {
fprintf(stderr, "%s\n", event); fprintf(stderr, "%s\n", event);
fflush(stderr); fflush(stderr);
@ -252,13 +248,12 @@ void log_eventlog(void *handle, const char *event)
* If n_blanks != 0, blank or omit some parts. * If n_blanks != 0, blank or omit some parts.
* Set of blanking areas must be in increasing order. * 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, const char *texttype, const void *data, int len,
int n_blanks, const struct logblank_t *blanks, int n_blanks, const struct logblank_t *blanks,
const unsigned long *seq, const unsigned long *seq,
unsigned downstream_id, const char *additional_log_text) unsigned downstream_id, const char *additional_log_text)
{ {
struct LogContext *ctx = (struct LogContext *)handle;
char dumpdata[80], smalldata[5]; char dumpdata[80], smalldata[5];
int p = 0, b = 0, omitted = 0; int p = 0, b = 0, omitted = 0;
int output_pos = 0; /* NZ if pending output in dumpdata */ 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); 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->lgfp = NULL;
ctx->state = L_CLOSED; ctx->state = L_CLOSED;
ctx->frontend = frontend; ctx->frontend = frontend;
@ -385,10 +380,8 @@ void *log_init(void *frontend, Conf *conf)
return ctx; return ctx;
} }
void log_free(void *handle) void log_free(LogContext *ctx)
{ {
struct LogContext *ctx = (struct LogContext *)handle;
logfclose(ctx); logfclose(ctx);
bufchain_clear(&ctx->queue); bufchain_clear(&ctx->queue);
if (ctx->currlogfilename) if (ctx->currlogfilename)
@ -397,9 +390,8 @@ void log_free(void *handle)
sfree(ctx); 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; int reset_logging;
if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename), if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename),

2
pscp.c
View File

@ -340,7 +340,7 @@ static void do_cmd(char *host, char *user, char *cmd)
{ {
const char *err; const char *err;
char *realhost; char *realhost;
void *logctx; LogContext *logctx;
if (host == NULL || host[0] == '\0') if (host == NULL || host[0] == '\0')
bump("Empty host name"); bump("Empty host name");

View File

@ -2669,7 +2669,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
{ {
char *host, *realhost; char *host, *realhost;
const char *err; const char *err;
void *logctx; LogContext *logctx;
/* Separate host and username */ /* Separate host and username */
host = userhost; host = userhost;

24
putty.h
View File

@ -462,7 +462,7 @@ struct backend_tag {
int (*sendok) (void *handle); int (*sendok) (void *handle);
int (*ldisc) (void *handle, int); int (*ldisc) (void *handle, int);
void (*provide_ldisc) (void *handle, Ldisc *ldisc); 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 * back->unthrottle() tells the back end that the front end
* buffer is clearing. * 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 term_provide_resize_fn(Terminal *term,
void (*resize_fn)(void *, int, int), void (*resize_fn)(void *, int, int),
void *resize_ctx); 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); void term_set_focus(Terminal *term, int has_focus);
char *term_get_ttymode(Terminal *term, const char *mode); char *term_get_ttymode(Terminal *term, const char *mode);
int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input); 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. * Exports from logging.c.
*/ */
void *log_init(void *frontend, Conf *conf); LogContext *log_init(void *frontend, Conf *conf);
void log_free(void *logctx); void log_free(LogContext *logctx);
void log_reconfig(void *logctx, Conf *conf); void log_reconfig(LogContext *logctx, Conf *conf);
void logfopen(void *logctx); void logfopen(LogContext *logctx);
void logfclose(void *logctx); void logfclose(LogContext *logctx);
void logtraffic(void *logctx, unsigned char c, int logmode); void logtraffic(LogContext *logctx, unsigned char c, int logmode);
void logflush(void *logctx); void logflush(LogContext *logctx);
void log_eventlog(void *logctx, const char *string); void log_eventlog(LogContext *logctx, const char *string);
enum { PKT_INCOMING, PKT_OUTGOING }; enum { PKT_INCOMING, PKT_OUTGOING };
enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT }; enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
struct logblank_t { struct logblank_t {
@ -1135,7 +1135,7 @@ struct logblank_t {
int len; int len;
int type; 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, const char *texttype, const void *data, int len,
int n_blanks, const struct logblank_t *blanks, int n_blanks, const struct logblank_t *blanks,
const unsigned long *sequence, const unsigned long *sequence,
@ -1353,7 +1353,7 @@ int askappend(void *frontend, Filename *filename,
*/ */
extern int console_batch_mode; extern int console_batch_mode;
int console_get_userpass_input(prompts_t *p); int console_get_userpass_input(prompts_t *p);
void console_provide_logctx(void *logctx); void console_provide_logctx(LogContext *logctx);
int is_interactive(void); int is_interactive(void);
/* /*

2
raw.c
View File

@ -279,7 +279,7 @@ static void raw_provide_ldisc(void *handle, Ldisc *ldisc)
/* This is a stub. */ /* 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. */ /* This is a stub. */
} }

View File

@ -371,7 +371,7 @@ static void rlogin_provide_ldisc(void *handle, Ldisc *ldisc)
/* This is a stub. */ /* 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. */ /* This is a stub. */
} }

4
ssh.c
View File

@ -701,7 +701,7 @@ struct ssh_tag {
const Plug_vtable *plugvt; const Plug_vtable *plugvt;
Ldisc *ldisc; Ldisc *ldisc;
void *logctx; LogContext *logctx;
unsigned char session_key[32]; unsigned char session_key[32];
int v1_remote_protoflags; int v1_remote_protoflags;
@ -11434,7 +11434,7 @@ static void ssh_provide_ldisc(void *handle, Ldisc *ldisc)
ssh->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 ssh = (Ssh) handle;
ssh->logctx = logctx; ssh->logctx = logctx;

View File

@ -19,7 +19,7 @@ struct BinaryPacketProtocol {
bufchain *in_raw, *out_raw; bufchain *in_raw, *out_raw;
PacketQueue *in_pq; PacketQueue *in_pq;
PacketLogSettings *pls; PacketLogSettings *pls;
void *logctx; LogContext *logctx;
int seen_disconnect; int seen_disconnect;
char *error; char *error;

View File

@ -1065,7 +1065,7 @@ static void telnet_provide_ldisc(void *handle, Ldisc *ldisc)
telnet->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. */ /* This is a stub. */
} }

View File

@ -6687,7 +6687,7 @@ int term_data_untrusted(Terminal *term, const void *vdata, int len)
return 0; /* assumes that term_data() always returns 0 */ 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; term->logctx = logctx;
} }

View File

@ -234,7 +234,7 @@ struct terminal_tag {
void *frontend; void *frontend;
void *logctx; LogContext *logctx;
struct unicode_data *ucsdata; struct unicode_data *ucsdata;

View File

@ -50,7 +50,7 @@ static int null_exitcode(void *);
static int null_sendok(void *); static int null_sendok(void *);
static int null_ldisc(void *, int); static int null_ldisc(void *, int);
static void null_provide_ldisc(void *, Ldisc *); 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 void null_unthrottle(void *, int);
static int null_cfg_info(void *); 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) {
} }

View File

@ -162,7 +162,7 @@ struct gui_data {
Backend *back; Backend *back;
void *backhandle; void *backhandle;
Terminal *term; Terminal *term;
void *logctx; LogContext *logctx;
int exited; int exited;
struct unicode_data ucsdata; struct unicode_data ucsdata;
Conf *conf; Conf *conf;

View File

@ -405,7 +405,7 @@ void old_keyfile_warning(void)
postmsg(&cf); postmsg(&cf);
} }
void console_provide_logctx(void *logctx) void console_provide_logctx(LogContext *logctx)
{ {
console_logctx = logctx; console_logctx = logctx;
} }

View File

@ -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(""); } FontSpec *platform_default_fontspec(const char *name) { return fontspec_new(""); }
Filename *platform_default_filename(const char *name) { return filename_from_str(""); } Filename *platform_default_filename(const char *name) { return filename_from_str(""); }
char *x_get_default(const char *key) { return NULL; } 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) int from_backend(void *frontend, int is_stderr, const void *data, int datalen)
{ assert(!"only here to satisfy notional call from backend_socket_log"); } { assert(!"only here to satisfy notional call from backend_socket_log"); }

View File

@ -25,7 +25,7 @@
#define MAX_STDIN_BACKLOG 4096 #define MAX_STDIN_BACKLOG 4096
static void *logctx; static LogContext *logctx;
static struct termios orig_termios; static struct termios orig_termios;

View File

@ -1212,7 +1212,7 @@ static void pty_provide_ldisc(void *handle, Ldisc *ldisc)
/* This is a stub. */ /* 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; */ /* Pty pty = (Pty)handle; */
/* This is a stub. */ /* This is a stub. */

View File

@ -549,7 +549,7 @@ static void serial_provide_ldisc(void *handle, Ldisc *ldisc)
/* This is a stub. */ /* 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. */ /* This is a stub. */
} }

View File

@ -335,7 +335,7 @@ void pgp_fingerprints(void)
" " PGP_PREV_MASTER_KEY_FP "\n", stdout); " " PGP_PREV_MASTER_KEY_FP "\n", stdout);
} }
void console_provide_logctx(void *logctx) void console_provide_logctx(LogContext *logctx)
{ {
console_logctx = logctx; console_logctx = logctx;
} }

View File

@ -414,7 +414,7 @@ static void serial_provide_ldisc(void *handle, Ldisc *ldisc)
/* This is a stub. */ /* 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. */ /* This is a stub. */
} }

View File

@ -240,7 +240,7 @@ void quit_help(HWND hwnd);
* windlg.c. Likewise the saved-sessions list. * windlg.c. Likewise the saved-sessions list.
*/ */
GLOBAL Terminal *term; GLOBAL Terminal *term;
GLOBAL void *logctx; GLOBAL LogContext *logctx;
/* /*
* Windows-specific clipboard helper function shared with windlg.c, * Windows-specific clipboard helper function shared with windlg.c,