Skip to content

Commit

Permalink
Make 'LogContext' a typedef visible throughout the code.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgtatham committed Sep 19, 2018
1 parent e72e8eb commit 3814a5c
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cmdgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 16 additions & 24 deletions logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion psftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions putty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -1120,22 +1120,22 @@ 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 {
int offset;
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,
Expand Down Expand Up @@ -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);

/*
Expand Down
2 changes: 1 addition & 1 deletion raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
Expand Down
2 changes: 1 addition & 1 deletion rlogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
Expand Down
4 changes: 2 additions & 2 deletions ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sshbpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
Expand Down
2 changes: 1 addition & 1 deletion terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ struct terminal_tag {

void *frontend;

void *logctx;
LogContext *logctx;

struct unicode_data *ucsdata;

Expand Down
4 changes: 2 additions & 2 deletions testback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down Expand Up @@ -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) {

}

Expand Down
2 changes: 1 addition & 1 deletion unix/gtkwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion unix/uxcons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion unix/uxpgnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }

Expand Down
2 changes: 1 addition & 1 deletion unix/uxplink.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define MAX_STDIN_BACKLOG 4096

static void *logctx;
static LogContext *logctx;

static struct termios orig_termios;

Expand Down
2 changes: 1 addition & 1 deletion unix/uxpty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion unix/uxser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
Expand Down
2 changes: 1 addition & 1 deletion windows/wincons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion windows/winser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
}
Expand Down
Loading

0 comments on commit 3814a5c

Please sign in to comment.