1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Make the plug_log type code into an enum.

Those magic numbers have been annoying for ages. Now they have names
that I havea fighting chance of remembering the meanings of.
This commit is contained in:
Simon Tatham 2020-02-07 19:17:45 +00:00
parent 06531c3b61
commit 91bb475087
17 changed files with 59 additions and 46 deletions

View File

@ -9,14 +9,14 @@
#include "network.h" #include "network.h"
void backend_socket_log(Seat *seat, LogContext *logctx, void backend_socket_log(Seat *seat, LogContext *logctx,
int type, SockAddr *addr, int port, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code, Conf *conf, const char *error_msg, int error_code, Conf *conf,
bool session_started) bool session_started)
{ {
char addrbuf[256], *msg; char addrbuf[256], *msg;
switch (type) { switch (type) {
case 0: case PLUGLOG_CONNECT_TRYING:
sk_getaddr(addr, addrbuf, lenof(addrbuf)); sk_getaddr(addr, addrbuf, lenof(addrbuf));
if (sk_addr_needs_port(addr)) { if (sk_addr_needs_port(addr)) {
msg = dupprintf("Connecting to %s port %d", addrbuf, port); msg = dupprintf("Connecting to %s port %d", addrbuf, port);
@ -24,11 +24,11 @@ void backend_socket_log(Seat *seat, LogContext *logctx,
msg = dupprintf("Connecting to %s", addrbuf); msg = dupprintf("Connecting to %s", addrbuf);
} }
break; break;
case 1: case PLUGLOG_CONNECT_FAILED:
sk_getaddr(addr, addrbuf, lenof(addrbuf)); sk_getaddr(addr, addrbuf, lenof(addrbuf));
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg); msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
break; break;
case 2: case PLUGLOG_PROXY_MSG:
/* Proxy-related log messages have their own identifying /* Proxy-related log messages have their own identifying
* prefix already, put on by our caller. */ * prefix already, put on by our caller. */
{ {
@ -114,7 +114,7 @@ void log_proxy_stderr(Plug *plug, ProxyStderrBuf *psb,
endpos--; endpos--;
char *msg = dupprintf( char *msg = dupprintf(
"proxy: %.*s", (int)(endpos - pos), psb->buf + pos); "proxy: %.*s", (int)(endpos - pos), psb->buf + pos);
plug_log(plug, 2, NULL, 0, msg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0);
sfree(msg); sfree(msg);
pos = nlpos - psb->buf + 1; pos = nlpos - psb->buf + 1;
@ -129,7 +129,7 @@ void log_proxy_stderr(Plug *plug, ProxyStderrBuf *psb,
if (pos == 0 && psb->size == lenof(psb->buf)) { if (pos == 0 && psb->size == lenof(psb->buf)) {
char *msg = dupprintf( char *msg = dupprintf(
"proxy (partial line): %.*s", (int)psb->size, psb->buf); "proxy (partial line): %.*s", (int)psb->size, psb->buf);
plug_log(plug, 2, NULL, 0, msg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0);
sfree(msg); sfree(msg);
pos = psb->size = 0; pos = psb->size = 0;

View File

@ -44,25 +44,33 @@ struct Plug {
const struct PlugVtable *vt; const struct PlugVtable *vt;
}; };
typedef enum PlugLogType {
PLUGLOG_CONNECT_TRYING,
PLUGLOG_CONNECT_FAILED,
PLUGLOG_PROXY_MSG,
} PlugLogType;
struct PlugVtable { struct PlugVtable {
void (*log)(Plug *p, int type, SockAddr *addr, int port, void (*log)(Plug *p, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code); const char *error_msg, int error_code);
/* /*
* Passes the client progress reports on the process of setting * Passes the client progress reports on the process of setting
* up the connection. * up the connection.
* *
* - type==0 means we are about to try to connect to address * - PLUGLOG_CONNECT_TRYING means we are about to try to connect
* `addr' (error_msg and error_code are ignored) * to address `addr' (error_msg and error_code are ignored)
* - type==1 means we have failed to connect to address `addr' *
* (error_msg and error_code are supplied). This is not a * - PLUGLOG_CONNECT_FAILED means we have failed to connect to
* fatal error - we may well have other candidate addresses * address `addr' (error_msg and error_code are supplied). This
* to fall back to. When it _is_ fatal, the closing() * is not a fatal error - we may well have other candidate
* addresses to fall back to. When it _is_ fatal, the closing()
* function will be called. * function will be called.
* - type==2 means that error_msg contains a line of generic *
* logging information about setting up the connection. This * - PLUGLOG_PROXY_MSG means that error_msg contains a line of
* will typically be a wodge of standard-error output from a * logging information from whatever the connection is being
* proxy command, so the receiver should probably prefix it to * proxied through. This will typically be a wodge of
* indicate this. * standard-error output from a local proxy command, so the
* receiver should probably prefix it to indicate this.
*/ */
void (*closing) void (*closing)
(Plug *p, const char *error_msg, int error_code, bool calling_back); (Plug *p, const char *error_msg, int error_code, bool calling_back);
@ -287,7 +295,7 @@ extern Plug *const nullplug;
* Exports from be_misc.c. * Exports from be_misc.c.
*/ */
void backend_socket_log(Seat *seat, LogContext *logctx, void backend_socket_log(Seat *seat, LogContext *logctx,
int type, SockAddr *addr, int port, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code, Conf *conf, const char *error_msg, int error_code, Conf *conf,
bool session_started); bool session_started);

View File

@ -95,13 +95,13 @@ static void free_portlistener_state(struct PortListener *pl)
sfree(pl); sfree(pl);
} }
static void pfd_log(Plug *plug, int type, SockAddr *addr, int port, static void pfd_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
/* we have to dump these since we have no interface to logging.c */ /* we have to dump these since we have no interface to logging.c */
} }
static void pfl_log(Plug *plug, int type, SockAddr *addr, int port, static void pfl_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
/* we have to dump these since we have no interface to logging.c */ /* we have to dump these since we have no interface to logging.c */

12
proxy.c
View File

@ -171,8 +171,8 @@ static const char * sk_proxy_socket_error (Socket *s)
/* basic proxy plug functions */ /* basic proxy plug functions */
static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, static void plug_proxy_log(Plug *plug, PlugLogType type, SockAddr *addr,
const char *error_msg, int error_code) int port, const char *error_msg, int error_code)
{ {
ProxySocket *ps = container_of(plug, ProxySocket, plugimpl); ProxySocket *ps = container_of(plug, ProxySocket, plugimpl);
@ -455,7 +455,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
conf_get_str(conf, CONF_proxy_host), conf_get_str(conf, CONF_proxy_host),
conf_get_int(conf, CONF_proxy_port), conf_get_int(conf, CONF_proxy_port),
hostname, port); hostname, port);
plug_log(plug, 2, NULL, 0, logmsg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
sfree(logmsg); sfree(logmsg);
} }
@ -463,7 +463,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
char *logmsg = dns_log_msg(conf_get_str(conf, CONF_proxy_host), char *logmsg = dns_log_msg(conf_get_str(conf, CONF_proxy_host),
conf_get_int(conf, CONF_addressfamily), conf_get_int(conf, CONF_addressfamily),
"proxy"); "proxy");
plug_log(plug, 2, NULL, 0, logmsg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
sfree(logmsg); sfree(logmsg);
} }
@ -484,7 +484,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
logmsg = dupprintf("Connecting to %s proxy at %s port %d", logmsg = dupprintf("Connecting to %s proxy at %s port %d",
proxy_type, addrbuf, proxy_type, addrbuf,
conf_get_int(conf, CONF_proxy_port)); conf_get_int(conf, CONF_proxy_port));
plug_log(plug, 2, NULL, 0, logmsg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
sfree(logmsg); sfree(logmsg);
} }
@ -1456,7 +1456,7 @@ int proxy_telnet_negotiate (ProxySocket *p, int change)
*out = '\0'; *out = '\0';
logmsg = dupprintf("Sending Telnet proxy command: %s", reescaped); logmsg = dupprintf("Sending Telnet proxy command: %s", reescaped);
plug_log(p->plug, 2, NULL, 0, logmsg, 0); plug_log(p->plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
sfree(logmsg); sfree(logmsg);
sfree(reescaped); sfree(reescaped);
} }

2
raw.c
View File

@ -33,7 +33,7 @@ static void c_write(Raw *raw, const void *buf, size_t len)
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
} }
static void raw_log(Plug *plug, int type, SockAddr *addr, int port, static void raw_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
Raw *raw = container_of(plug, Raw, plug); Raw *raw = container_of(plug, Raw, plug);

View File

@ -37,7 +37,7 @@ static void c_write(Rlogin *rlogin, const void *buf, size_t len)
sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG);
} }
static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, static void rlogin_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
Rlogin *rlogin = container_of(plug, Rlogin, plug); Rlogin *rlogin = container_of(plug, Rlogin, plug);

View File

@ -352,7 +352,7 @@ bool sesschan_run_subsystem(Channel *chan, ptrlen subsys)
return false; return false;
} }
static void fwd_log(Plug *plug, int type, SockAddr *addr, int port, static void fwd_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ /* don't expect any weirdnesses from a listening socket */ } { /* don't expect any weirdnesses from a listening socket */ }
static void fwd_closing(Plug *plug, const char *error_msg, int error_code, static void fwd_closing(Plug *plug, const char *error_msg, int error_code,

4
ssh.c
View File

@ -576,8 +576,8 @@ void ssh_sw_abort_deferred(Ssh *ssh, const char *fmt, ...)
} }
} }
static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, static void ssh_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
const char *error_msg, int error_code) int port, const char *error_msg, int error_code)
{ {
Ssh *ssh = container_of(plug, Ssh, plug); Ssh *ssh = container_of(plug, Ssh, plug);

View File

@ -124,8 +124,8 @@ static const SeatVtable server_seat_vt = {
nullseat_interactive_no, nullseat_interactive_no,
}; };
static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port, static void server_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
const char *error_msg, int error_code) int port, const char *error_msg, int error_code)
{ {
/* server *srv = container_of(plug, server, plug); */ /* server *srv = container_of(plug, server, plug); */
/* FIXME */ /* FIXME */

View File

@ -613,7 +613,7 @@ static void do_telnet_read(Telnet *telnet, const char *buf, size_t len)
strbuf_free(outbuf); strbuf_free(outbuf);
} }
static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, static void telnet_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
Telnet *telnet = container_of(plug, Telnet, plug); Telnet *telnet = container_of(plug, Telnet, plug);

View File

@ -575,7 +575,8 @@ static int try_connect(NetSocket *sock)
{ {
SockAddr thisaddr = sk_extractaddr_tmp( SockAddr thisaddr = sk_extractaddr_tmp(
sock->addr, &sock->step); sock->addr, &sock->step);
plug_log(sock->plug, 0, &thisaddr, sock->port, NULL, 0); plug_log(sock->plug, PLUGLOG_CONNECT_TRYING,
&thisaddr, sock->port, NULL, 0);
} }
/* /*
@ -746,7 +747,8 @@ static int try_connect(NetSocket *sock)
if (err) { if (err) {
SockAddr thisaddr = sk_extractaddr_tmp( SockAddr thisaddr = sk_extractaddr_tmp(
sock->addr, &sock->step); sock->addr, &sock->step);
plug_log(sock->plug, 1, &thisaddr, sock->port, strerror(err), err); plug_log(sock->plug, PLUGLOG_CONNECT_FAILED,
&thisaddr, sock->port, strerror(err), err);
} }
return err; return err;
} }
@ -1421,7 +1423,8 @@ static void net_select_result(int fd, int event)
assert(s->addr); assert(s->addr);
thisaddr = sk_extractaddr_tmp(s->addr, &s->step); thisaddr = sk_extractaddr_tmp(s->addr, &s->step);
plug_log(s->plug, 1, &thisaddr, s->port, errmsg, err); plug_log(s->plug, PLUGLOG_CONNECT_FAILED,
&thisaddr, s->port, errmsg, err);
while (err && s->addr && sk_nextaddr(s->addr, &s->step)) { while (err && s->addr && sk_nextaddr(s->addr, &s->step)) {
err = try_connect(s); err = try_connect(s);

View File

@ -199,7 +199,7 @@ void chan_no_request_response(Channel *chan, bool success) {}
* except that x11_closing has to signal back to the main loop that * except that x11_closing has to signal back to the main loop that
* it's time to terminate. * it's time to terminate.
*/ */
static void x11_log(Plug *p, int type, SockAddr *addr, int port, static void x11_log(Plug *p, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) {} const char *error_msg, int error_code) {}
static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {} static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {}
static void x11_sent(Plug *plug, size_t bufsize) {} static void x11_sent(Plug *plug, size_t bufsize) {}

View File

@ -33,7 +33,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
{ {
char *logmsg = dupprintf("Starting local proxy command: %s", cmd); char *logmsg = dupprintf("Starting local proxy command: %s", cmd);
plug_log(plug, 2, NULL, 0, logmsg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
sfree(logmsg); sfree(logmsg);
} }

View File

@ -447,7 +447,7 @@ static Plug *server_conn_plug(
&inst->ap, &inst->logpolicy, &unix_live_sftpserver_vt); &inst->ap, &inst->logpolicy, &unix_live_sftpserver_vt);
} }
static void server_log(Plug *plug, int type, SockAddr *addr, int port, static void server_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
log_to_stderr((unsigned)-1, error_msg); log_to_stderr((unsigned)-1, error_msg);

View File

@ -908,7 +908,8 @@ static DWORD try_connect(NetSocket *sock)
{ {
SockAddr thisaddr = sk_extractaddr_tmp( SockAddr thisaddr = sk_extractaddr_tmp(
sock->addr, &sock->step); sock->addr, &sock->step);
plug_log(sock->plug, 0, &thisaddr, sock->port, NULL, 0); plug_log(sock->plug, PLUGLOG_CONNECT_TRYING,
&thisaddr, sock->port, NULL, 0);
} }
/* /*
@ -1081,7 +1082,8 @@ static DWORD try_connect(NetSocket *sock)
if (err) { if (err) {
SockAddr thisaddr = sk_extractaddr_tmp( SockAddr thisaddr = sk_extractaddr_tmp(
sock->addr, &sock->step); sock->addr, &sock->step);
plug_log(sock->plug, 1, &thisaddr, sock->port, sock->error, err); plug_log(sock->plug, PLUGLOG_CONNECT_FAILED,
&thisaddr, sock->port, sock->error, err);
} }
return err; return err;
} }
@ -1527,7 +1529,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
if (s->addr) { if (s->addr) {
SockAddr thisaddr = sk_extractaddr_tmp( SockAddr thisaddr = sk_extractaddr_tmp(
s->addr, &s->step); s->addr, &s->step);
plug_log(s->plug, 1, &thisaddr, s->port, plug_log(s->plug, PLUGLOG_CONNECT_FAILED, &thisaddr, s->port,
winsock_error_string(err), err); winsock_error_string(err), err);
while (err && s->addr && sk_nextaddr(s->addr, &s->step)) { while (err && s->addr && sk_nextaddr(s->addr, &s->step)) {
err = try_connect(s); err = try_connect(s);

View File

@ -35,7 +35,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
{ {
char *msg = dupprintf("Starting local proxy command: %s", cmd); char *msg = dupprintf("Starting local proxy command: %s", cmd);
plug_log(plug, 2, NULL, 0, msg, 0); plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0);
sfree(msg); sfree(msg);
} }

View File

@ -684,7 +684,7 @@ void x11_format_auth_for_authfile(
put_stringpl_xauth(bs, authdata); put_stringpl_xauth(bs, authdata);
} }
static void x11_log(Plug *p, int type, SockAddr *addr, int port, static void x11_log(Plug *p, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code) const char *error_msg, int error_code)
{ {
/* We have no interface to the logging module here, so we drop these. */ /* We have no interface to the logging module here, so we drop these. */