mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +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:
parent
06531c3b61
commit
91bb475087
12
be_misc.c
12
be_misc.c
@ -9,14 +9,14 @@
|
||||
#include "network.h"
|
||||
|
||||
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,
|
||||
bool session_started)
|
||||
{
|
||||
char addrbuf[256], *msg;
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
case PLUGLOG_CONNECT_TRYING:
|
||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||
if (sk_addr_needs_port(addr)) {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case PLUGLOG_CONNECT_FAILED:
|
||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
||||
break;
|
||||
case 2:
|
||||
case PLUGLOG_PROXY_MSG:
|
||||
/* Proxy-related log messages have their own identifying
|
||||
* prefix already, put on by our caller. */
|
||||
{
|
||||
@ -114,7 +114,7 @@ void log_proxy_stderr(Plug *plug, ProxyStderrBuf *psb,
|
||||
endpos--;
|
||||
char *msg = dupprintf(
|
||||
"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);
|
||||
|
||||
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)) {
|
||||
char *msg = dupprintf(
|
||||
"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);
|
||||
|
||||
pos = psb->size = 0;
|
||||
|
34
network.h
34
network.h
@ -44,25 +44,33 @@ struct Plug {
|
||||
const struct PlugVtable *vt;
|
||||
};
|
||||
|
||||
typedef enum PlugLogType {
|
||||
PLUGLOG_CONNECT_TRYING,
|
||||
PLUGLOG_CONNECT_FAILED,
|
||||
PLUGLOG_PROXY_MSG,
|
||||
} PlugLogType;
|
||||
|
||||
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);
|
||||
/*
|
||||
* Passes the client progress reports on the process of setting
|
||||
* up the connection.
|
||||
*
|
||||
* - type==0 means we are about to try to connect 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
|
||||
* fatal error - we may well have other candidate addresses
|
||||
* to fall back to. When it _is_ fatal, the closing()
|
||||
* - PLUGLOG_CONNECT_TRYING means we are about to try to connect
|
||||
* to address `addr' (error_msg and error_code are ignored)
|
||||
*
|
||||
* - PLUGLOG_CONNECT_FAILED means we have failed to connect to
|
||||
* address `addr' (error_msg and error_code are supplied). This
|
||||
* 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.
|
||||
* - type==2 means that error_msg contains a line of generic
|
||||
* logging information about setting up the connection. This
|
||||
* will typically be a wodge of standard-error output from a
|
||||
* proxy command, so the receiver should probably prefix it to
|
||||
* indicate this.
|
||||
*
|
||||
* - PLUGLOG_PROXY_MSG means that error_msg contains a line of
|
||||
* logging information from whatever the connection is being
|
||||
* proxied through. This will typically be a wodge of
|
||||
* standard-error output from a local proxy command, so the
|
||||
* receiver should probably prefix it to indicate this.
|
||||
*/
|
||||
void (*closing)
|
||||
(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.
|
||||
*/
|
||||
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,
|
||||
bool session_started);
|
||||
|
||||
|
@ -95,13 +95,13 @@ static void free_portlistener_state(struct PortListener *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)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
/* we have to dump these since we have no interface to logging.c */
|
||||
|
12
proxy.c
12
proxy.c
@ -171,8 +171,8 @@ static const char * sk_proxy_socket_error (Socket *s)
|
||||
|
||||
/* basic proxy plug functions */
|
||||
|
||||
static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port,
|
||||
const char *error_msg, int error_code)
|
||||
static void plug_proxy_log(Plug *plug, PlugLogType type, SockAddr *addr,
|
||||
int port, const char *error_msg, int error_code)
|
||||
{
|
||||
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_int(conf, CONF_proxy_port),
|
||||
hostname, port);
|
||||
plug_log(plug, 2, NULL, 0, logmsg, 0);
|
||||
plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
|
||||
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),
|
||||
conf_get_int(conf, CONF_addressfamily),
|
||||
"proxy");
|
||||
plug_log(plug, 2, NULL, 0, logmsg, 0);
|
||||
plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0);
|
||||
sfree(logmsg);
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
|
||||
logmsg = dupprintf("Connecting to %s proxy at %s port %d",
|
||||
proxy_type, addrbuf,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1456,7 +1456,7 @@ int proxy_telnet_negotiate (ProxySocket *p, int change)
|
||||
*out = '\0';
|
||||
|
||||
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(reescaped);
|
||||
}
|
||||
|
2
raw.c
2
raw.c
@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Raw *raw = container_of(plug, Raw, plug);
|
||||
|
2
rlogin.c
2
rlogin.c
@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Rlogin *rlogin = container_of(plug, Rlogin, plug);
|
||||
|
@ -352,7 +352,7 @@ bool sesschan_run_subsystem(Channel *chan, ptrlen subsys)
|
||||
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)
|
||||
{ /* don't expect any weirdnesses from a listening socket */ }
|
||||
static void fwd_closing(Plug *plug, const char *error_msg, int error_code,
|
||||
|
4
ssh.c
4
ssh.c
@ -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,
|
||||
const char *error_msg, int error_code)
|
||||
static void ssh_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
|
||||
int port, const char *error_msg, int error_code)
|
||||
{
|
||||
Ssh *ssh = container_of(plug, Ssh, plug);
|
||||
|
||||
|
@ -124,8 +124,8 @@ static const SeatVtable server_seat_vt = {
|
||||
nullseat_interactive_no,
|
||||
};
|
||||
|
||||
static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port,
|
||||
const char *error_msg, int error_code)
|
||||
static void server_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
|
||||
int port, const char *error_msg, int error_code)
|
||||
{
|
||||
/* server *srv = container_of(plug, server, plug); */
|
||||
/* FIXME */
|
||||
|
2
telnet.c
2
telnet.c
@ -613,7 +613,7 @@ static void do_telnet_read(Telnet *telnet, const char *buf, size_t len)
|
||||
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)
|
||||
{
|
||||
Telnet *telnet = container_of(plug, Telnet, plug);
|
||||
|
@ -575,7 +575,8 @@ static int try_connect(NetSocket *sock)
|
||||
{
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
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) {
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
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;
|
||||
}
|
||||
@ -1421,7 +1423,8 @@ static void net_select_result(int fd, int event)
|
||||
assert(s->addr);
|
||||
|
||||
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)) {
|
||||
err = try_connect(s);
|
||||
|
@ -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
|
||||
* 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) {}
|
||||
static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {}
|
||||
static void x11_sent(Plug *plug, size_t bufsize) {}
|
||||
|
@ -33,7 +33,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ static Plug *server_conn_plug(
|
||||
&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)
|
||||
{
|
||||
log_to_stderr((unsigned)-1, error_msg);
|
||||
|
@ -908,7 +908,8 @@ static DWORD try_connect(NetSocket *sock)
|
||||
{
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
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) {
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
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;
|
||||
}
|
||||
@ -1527,7 +1529,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
||||
if (s->addr) {
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
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);
|
||||
while (err && s->addr && sk_nextaddr(s->addr, &s->step)) {
|
||||
err = try_connect(s);
|
||||
|
@ -35,7 +35,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
2
x11fwd.c
2
x11fwd.c
@ -684,7 +684,7 @@ void x11_format_auth_for_authfile(
|
||||
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)
|
||||
{
|
||||
/* We have no interface to the logging module here, so we drop these. */
|
||||
|
Loading…
Reference in New Issue
Block a user