mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05: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:
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user