mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 13:32:48 -05:00
Refactor the LogContext type.
LogContext is now the owner of the logevent() function that back ends and so forth are constantly calling. Previously, logevent was owned by the Frontend, which would store the message into its list for the GUI Event Log dialog (or print it to standard error, or whatever) and then pass it _back_ to LogContext to write to the currently open log file. Now it's the other way round: LogContext gets the message from the back end first, writes it to its log file if it feels so inclined, and communicates it back to the front end. This means that lots of parts of the back end system no longer need to have a pointer to a full-on Frontend; the only thing they needed it for was logging, so now they just have a LogContext (which many of them had to have anyway, e.g. for logging SSH packets or session traffic). LogContext itself also doesn't get a full Frontend pointer any more: it now talks back to the front end via a little vtable of its own called LogPolicy, which contains the method that passes Event Log entries through, the old askappend() function that decides whether to truncate a pre-existing log file, and an emergency function for printing an especially prominent message if the log file can't be created. One minor nice effect of this is that console and GUI apps can implement that last function subtly differently, so that Unix console apps can write it with a plain \n instead of the \r\n (harmless but inelegant) that the old centralised implementation generated. One other consequence of this is that the LogContext has to be provided to backend_init() so that it's available to backends from the instant of creation, rather than being provided via a separate API call a couple of function calls later, because backends have typically started doing things that need logging (like making network connections) before the call to backend_provide_logctx. Fortunately, there's no case in the whole code base where we don't already have logctx by the time we make a backend (so I don't actually remember why I ever delayed providing one). So that shortens the backend API by one function, which is always nice. While I'm tidying up, I've also moved the printf-style logeventf() and the handy logevent_and_free() into logging.c, instead of having copies of them scattered around other places. This has also let me remove some stub functions from a couple of outlying applications like Pageant. Finally, I've removed the pointless "_tag" at the end of LogContext's official struct name.
This commit is contained in:
@ -220,13 +220,6 @@ int sk_startup(int hi, int lo)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
{
|
||||
char buf[80];
|
||||
sprintf(buf, "Using WinSock %d.%d", hi, lo);
|
||||
logevent(NULL, buf);
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -252,9 +245,6 @@ void sk_init(void)
|
||||
#ifndef NO_IPV6
|
||||
/* Check if we have getaddrinfo in Winsock */
|
||||
if (GetProcAddress(winsock_module, "getaddrinfo") != NULL) {
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "Native WinSock IPv6 support detected");
|
||||
#endif
|
||||
GET_WINDOWS_FUNCTION(winsock_module, getaddrinfo);
|
||||
GET_WINDOWS_FUNCTION(winsock_module, freeaddrinfo);
|
||||
GET_WINDOWS_FUNCTION(winsock_module, getnameinfo);
|
||||
@ -266,25 +256,15 @@ void sk_init(void)
|
||||
/* Fall back to wship6.dll for Windows 2000 */
|
||||
wship6_module = load_system32_dll("wship6.dll");
|
||||
if (wship6_module) {
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "WSH IPv6 support detected");
|
||||
#endif
|
||||
GET_WINDOWS_FUNCTION(wship6_module, getaddrinfo);
|
||||
GET_WINDOWS_FUNCTION(wship6_module, freeaddrinfo);
|
||||
GET_WINDOWS_FUNCTION(wship6_module, getnameinfo);
|
||||
/* See comment above about type check */
|
||||
GET_WINDOWS_FUNCTION_NO_TYPECHECK(winsock_module, gai_strerror);
|
||||
} else {
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "No IPv6 support detected");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
GET_WINDOWS_FUNCTION(winsock2_module, WSAAddressToStringA);
|
||||
#else
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "PuTTY was built without IPv6 support");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GET_WINDOWS_FUNCTION(winsock_module, WSAAsyncSelect);
|
||||
@ -559,9 +539,6 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
|
||||
*/
|
||||
if (p_getaddrinfo) {
|
||||
struct addrinfo hints;
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "Using getaddrinfo() for resolving");
|
||||
#endif
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = hint_family;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
@ -576,9 +553,6 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname,
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#ifdef NET_SETUP_DIAGNOSTICS
|
||||
logevent(NULL, "Using gethostbyname() for resolving");
|
||||
#endif
|
||||
/*
|
||||
* Otherwise use the IPv4-only gethostbyname...
|
||||
* (NOTE: we don't use gethostbyname as a fallback!)
|
||||
@ -796,7 +770,7 @@ static int ipv4_is_local_addr(struct in_addr addr)
|
||||
&retbytes, NULL, NULL) == 0)
|
||||
n_local_interfaces = retbytes / sizeof(INTERFACE_INFO);
|
||||
else
|
||||
logevent(NULL, "Unable to get list of local IP addresses");
|
||||
n_local_interfaces = -1;
|
||||
}
|
||||
if (n_local_interfaces > 0) {
|
||||
int i;
|
||||
|
Reference in New Issue
Block a user