mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Factor out the back ends' plug log functions.
I'm about to want to make a change to all those functions at once, and since they're almost identical, it seemed easiest to pull them out into a common helper. The new source file be_misc.c is intended to contain helper code common to all network back ends (crypto and non-crypto, in particular), and initially it contains a backend_socket_log() function which is the common part of ssh_log(), telnet_log(), rlogin_log() etc.
This commit is contained in:
parent
bb66e9870e
commit
a6e76ae453
2
Recipe
2
Recipe
@ -233,7 +233,7 @@ SFTP = sftp int64 logging
|
|||||||
|
|
||||||
# Miscellaneous objects appearing in all the network utilities (not
|
# Miscellaneous objects appearing in all the network utilities (not
|
||||||
# Pageant or PuTTYgen).
|
# Pageant or PuTTYgen).
|
||||||
MISC = timing callback misc version settings tree234 proxy conf
|
MISC = timing callback misc version settings tree234 proxy conf be_misc
|
||||||
WINMISC = MISC winstore winnet winhandl cmdline windefs winmisc winproxy
|
WINMISC = MISC winstore winnet winhandl cmdline windefs winmisc winproxy
|
||||||
+ wintime winhsock errsock
|
+ wintime winhsock errsock
|
||||||
UXMISC = MISC uxstore uxsel uxnet uxpeer cmdline uxmisc uxproxy time
|
UXMISC = MISC uxstore uxsel uxnet uxpeer cmdline uxmisc uxproxy time
|
||||||
|
36
be_misc.c
Normal file
36
be_misc.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* be_misc.c: helper functions shared between main network backends.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "putty.h"
|
||||||
|
#include "network.h"
|
||||||
|
|
||||||
|
void backend_socket_log(void *frontend, int type, SockAddr addr, int port,
|
||||||
|
const char *error_msg, int error_code)
|
||||||
|
{
|
||||||
|
char addrbuf[256], *msg;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||||
|
if (sk_addr_needs_port(addr)) {
|
||||||
|
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
||||||
|
} else {
|
||||||
|
msg = dupprintf("Connecting to %s", addrbuf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||||
|
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
msg = NULL; /* shouldn't happen, but placate optimiser */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
logevent(frontend, msg);
|
||||||
|
sfree(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
12
network.h
12
network.h
@ -212,4 +212,16 @@ char *get_hostname(void);
|
|||||||
*/
|
*/
|
||||||
Socket new_error_socket(const char *errmsg, Plug plug);
|
Socket new_error_socket(const char *errmsg, Plug plug);
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
* Functions defined outside the network code, which have to be
|
||||||
|
* declared in this header file rather than the main putty.h because
|
||||||
|
* they use types defined here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exports from be_misc.c.
|
||||||
|
*/
|
||||||
|
void backend_socket_log(void *frontend, int type, SockAddr addr, int port,
|
||||||
|
const char *error_msg, int error_code);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
13
raw.c
13
raw.c
@ -40,17 +40,8 @@ static void raw_log(Plug plug, int type, SockAddr addr, int port,
|
|||||||
const char *error_msg, int error_code)
|
const char *error_msg, int error_code)
|
||||||
{
|
{
|
||||||
Raw raw = (Raw) plug;
|
Raw raw = (Raw) plug;
|
||||||
char addrbuf[256], *msg;
|
backend_socket_log(raw->frontend, type, addr, port,
|
||||||
|
error_msg, error_code);
|
||||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
|
||||||
|
|
||||||
if (type == 0)
|
|
||||||
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
|
||||||
else
|
|
||||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
|
||||||
|
|
||||||
logevent(raw->frontend, msg);
|
|
||||||
sfree(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raw_check_close(Raw raw)
|
static void raw_check_close(Raw raw)
|
||||||
|
13
rlogin.c
13
rlogin.c
@ -48,17 +48,8 @@ static void rlogin_log(Plug plug, int type, SockAddr addr, int port,
|
|||||||
const char *error_msg, int error_code)
|
const char *error_msg, int error_code)
|
||||||
{
|
{
|
||||||
Rlogin rlogin = (Rlogin) plug;
|
Rlogin rlogin = (Rlogin) plug;
|
||||||
char addrbuf[256], *msg;
|
backend_socket_log(rlogin->frontend, type, addr, port,
|
||||||
|
error_msg, error_code);
|
||||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
|
||||||
|
|
||||||
if (type == 0)
|
|
||||||
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
|
||||||
else
|
|
||||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
|
||||||
|
|
||||||
logevent(rlogin->frontend, msg);
|
|
||||||
sfree(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rlogin_closing(Plug plug, const char *error_msg, int error_code,
|
static int rlogin_closing(Plug plug, const char *error_msg, int error_code,
|
||||||
|
37
ssh.c
37
ssh.c
@ -3452,34 +3452,19 @@ static void ssh_socket_log(Plug plug, int type, SockAddr addr, int port,
|
|||||||
const char *error_msg, int error_code)
|
const char *error_msg, int error_code)
|
||||||
{
|
{
|
||||||
Ssh ssh = (Ssh) plug;
|
Ssh ssh = (Ssh) plug;
|
||||||
char addrbuf[256], *msg;
|
|
||||||
|
|
||||||
if (ssh->attempting_connshare) {
|
/*
|
||||||
/*
|
* While we're attempting connection sharing, don't loudly log
|
||||||
* While we're attempting connection sharing, don't loudly log
|
* everything that happens. Real TCP connections need to be logged
|
||||||
* everything that happens. Real TCP connections need to be
|
* when we _start_ trying to connect, because it might be ages
|
||||||
* logged when we _start_ trying to connect, because it might
|
* before they respond if something goes wrong; but connection
|
||||||
* be ages before they respond if something goes wrong; but
|
* sharing is local and quick to respond, and it's sufficient to
|
||||||
* connection sharing is local and quick to respond, and it's
|
* simply wait and see whether it worked afterwards.
|
||||||
* sufficient to simply wait and see whether it worked
|
*/
|
||||||
* afterwards.
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
|
||||||
|
|
||||||
if (type == 0) {
|
if (!ssh->attempting_connshare)
|
||||||
if (sk_addr_needs_port(addr)) {
|
backend_socket_log(ssh->frontend, type, addr, port,
|
||||||
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
error_msg, error_code);
|
||||||
} else {
|
|
||||||
msg = dupprintf("Connecting to %s", addrbuf);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
logevent(msg);
|
|
||||||
sfree(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_connshare_log(Ssh ssh, int event, const char *logtext,
|
void ssh_connshare_log(Ssh ssh, int event, const char *logtext,
|
||||||
|
13
telnet.c
13
telnet.c
@ -652,17 +652,8 @@ static void telnet_log(Plug plug, int type, SockAddr addr, int port,
|
|||||||
const char *error_msg, int error_code)
|
const char *error_msg, int error_code)
|
||||||
{
|
{
|
||||||
Telnet telnet = (Telnet) plug;
|
Telnet telnet = (Telnet) plug;
|
||||||
char addrbuf[256], *msg;
|
backend_socket_log(telnet->frontend, type, addr, port,
|
||||||
|
error_msg, error_code);
|
||||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
|
||||||
|
|
||||||
if (type == 0)
|
|
||||||
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
|
||||||
else
|
|
||||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
|
||||||
|
|
||||||
logevent(telnet->frontend, msg);
|
|
||||||
sfree(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int telnet_closing(Plug plug, const char *error_msg, int error_code,
|
static int telnet_closing(Plug plug, const char *error_msg, int error_code,
|
||||||
|
Loading…
Reference in New Issue
Block a user