2000-10-18 15:36:32 +00:00
|
|
|
/*
|
2021-04-18 06:58:27 +00:00
|
|
|
* windows/platform.h: Windows-specific inter-module stuff.
|
2000-10-18 15:36:32 +00:00
|
|
|
*/
|
|
|
|
|
2021-04-18 06:58:27 +00:00
|
|
|
#ifndef PUTTY_WINDOWS_PLATFORM_H
|
|
|
|
#define PUTTY_WINDOWS_PLATFORM_H
|
2002-10-07 16:45:23 +00:00
|
|
|
|
Replace mkfiles.pl with a CMake build system.
This brings various concrete advantages over the previous system:
- consistent support for out-of-tree builds on all platforms
- more thorough support for Visual Studio IDE project files
- support for Ninja-based builds, which is particularly useful on
Windows where the alternative nmake has no parallel option
- a really simple set of build instructions that work the same way on
all the major platforms (look how much shorter README is!)
- better decoupling of the project configuration from the toolchain
configuration, so that my Windows cross-building doesn't need
(much) special treatment in CMakeLists.txt
- configure-time tests on Windows as well as Linux, so that a lot of
ad-hoc #ifdefs second-guessing a particular feature's presence from
the compiler version can now be replaced by tests of the feature
itself
Also some longer-term software-engineering advantages:
- other people have actually heard of CMake, so they'll be able to
produce patches to the new build setup more easily
- unlike the old mkfiles.pl, CMake is not my personal problem to
maintain
- most importantly, mkfiles.pl was just a horrible pile of
unmaintainable cruft, which even I found it painful to make changes
to or to use, and desperately needed throwing in the bin. I've
already thrown away all the variants of it I had in other projects
of mine, and was only delaying this one so we could make the 0.75
release branch first.
This change comes with a noticeable build-level restructuring. The
previous Recipe worked by compiling every object file exactly once,
and then making each executable by linking a precisely specified
subset of the same object files. But in CMake, that's not the natural
way to work - if you write the obvious command that puts the same
source file into two executable targets, CMake generates a makefile
that compiles it once per target. That can be an advantage, because it
gives you the freedom to compile it differently in each case (e.g.
with a #define telling it which program it's part of). But in a
project that has many executable targets and had carefully contrived
to _never_ need to build any module more than once, all it does is
bloat the build time pointlessly!
To avoid slowing down the build by a large factor, I've put most of
the modules of the code base into a collection of static libraries
organised vaguely thematically (SSH, other backends, crypto, network,
...). That means all those modules can still be compiled just once
each, because once each library is built it's reused unchanged for all
the executable targets.
One upside of this library-based structure is that now I don't have to
manually specify exactly which objects go into which programs any more
- it's enough to specify which libraries are needed, and the linker
will figure out the fine detail automatically. So there's less
maintenance to do in CMakeLists.txt when the source code changes.
But that reorganisation also adds fragility, because of the trad Unix
linker semantics of walking along the library list once each, so that
cyclic references between your libraries will provoke link errors. The
current setup builds successfully, but I suspect it only just manages
it.
(In particular, I've found that MinGW is the most finicky on this
score of the Windows compilers I've tried building with. So I've
included a MinGW test build in the new-look Buildscr, because
otherwise I think there'd be a significant risk of introducing
MinGW-only build failures due to library search order, which wasn't a
risk in the previous library-free build organisation.)
In the longer term I hope to be able to reduce the risk of that, via
gradual reorganisation (in particular, breaking up too-monolithic
modules, to reduce the risk of knock-on references when you included a
module for function A and it also contains function B with an
unsatisfied dependency you didn't really need). Ideally I want to
reach a state in which the libraries all have sensibly described
purposes, a clearly documented (partial) order in which they're
permitted to depend on each other, and a specification of what stubs
you have to put where if you're leaving one of them out (e.g.
nocrypto) and what callbacks you have to define in your non-library
objects to satisfy dependencies from things low in the stack (e.g.
out_of_memory()).
One thing that's gone completely missing in this migration,
unfortunately, is the unfinished MacOS port linked against Quartz GTK.
That's because it turned out that I can't currently build it myself,
on my own Mac: my previous installation of GTK had bit-rotted as a
side effect of an Xcode upgrade, and I haven't yet been able to
persuade jhbuild to make me a new one. So I can't even build the MacOS
port with the _old_ makefiles, and hence, I have no way of checking
that the new ones also work. I hope to bring that port back to life at
some point, but I don't want it to block the rest of this change.
2021-04-10 14:21:11 +00:00
|
|
|
#include <winsock2.h>
|
2003-10-12 13:46:12 +00:00
|
|
|
#include <windows.h>
|
2019-09-08 19:29:00 +00:00
|
|
|
#include <stdio.h> /* for FILENAME_MAX */
|
2003-02-01 12:54:40 +00:00
|
|
|
|
2015-09-28 18:52:38 +00:00
|
|
|
/* We use uintptr_t for Win32/Win64 portability, so we should in
|
|
|
|
* principle include stdint.h, which defines it according to the C
|
Replace mkfiles.pl with a CMake build system.
This brings various concrete advantages over the previous system:
- consistent support for out-of-tree builds on all platforms
- more thorough support for Visual Studio IDE project files
- support for Ninja-based builds, which is particularly useful on
Windows where the alternative nmake has no parallel option
- a really simple set of build instructions that work the same way on
all the major platforms (look how much shorter README is!)
- better decoupling of the project configuration from the toolchain
configuration, so that my Windows cross-building doesn't need
(much) special treatment in CMakeLists.txt
- configure-time tests on Windows as well as Linux, so that a lot of
ad-hoc #ifdefs second-guessing a particular feature's presence from
the compiler version can now be replaced by tests of the feature
itself
Also some longer-term software-engineering advantages:
- other people have actually heard of CMake, so they'll be able to
produce patches to the new build setup more easily
- unlike the old mkfiles.pl, CMake is not my personal problem to
maintain
- most importantly, mkfiles.pl was just a horrible pile of
unmaintainable cruft, which even I found it painful to make changes
to or to use, and desperately needed throwing in the bin. I've
already thrown away all the variants of it I had in other projects
of mine, and was only delaying this one so we could make the 0.75
release branch first.
This change comes with a noticeable build-level restructuring. The
previous Recipe worked by compiling every object file exactly once,
and then making each executable by linking a precisely specified
subset of the same object files. But in CMake, that's not the natural
way to work - if you write the obvious command that puts the same
source file into two executable targets, CMake generates a makefile
that compiles it once per target. That can be an advantage, because it
gives you the freedom to compile it differently in each case (e.g.
with a #define telling it which program it's part of). But in a
project that has many executable targets and had carefully contrived
to _never_ need to build any module more than once, all it does is
bloat the build time pointlessly!
To avoid slowing down the build by a large factor, I've put most of
the modules of the code base into a collection of static libraries
organised vaguely thematically (SSH, other backends, crypto, network,
...). That means all those modules can still be compiled just once
each, because once each library is built it's reused unchanged for all
the executable targets.
One upside of this library-based structure is that now I don't have to
manually specify exactly which objects go into which programs any more
- it's enough to specify which libraries are needed, and the linker
will figure out the fine detail automatically. So there's less
maintenance to do in CMakeLists.txt when the source code changes.
But that reorganisation also adds fragility, because of the trad Unix
linker semantics of walking along the library list once each, so that
cyclic references between your libraries will provoke link errors. The
current setup builds successfully, but I suspect it only just manages
it.
(In particular, I've found that MinGW is the most finicky on this
score of the Windows compilers I've tried building with. So I've
included a MinGW test build in the new-look Buildscr, because
otherwise I think there'd be a significant risk of introducing
MinGW-only build failures due to library search order, which wasn't a
risk in the previous library-free build organisation.)
In the longer term I hope to be able to reduce the risk of that, via
gradual reorganisation (in particular, breaking up too-monolithic
modules, to reduce the risk of knock-on references when you included a
module for function A and it also contains function B with an
unsatisfied dependency you didn't really need). Ideally I want to
reach a state in which the libraries all have sensibly described
purposes, a clearly documented (partial) order in which they're
permitted to depend on each other, and a specification of what stubs
you have to put where if you're leaving one of them out (e.g.
nocrypto) and what callbacks you have to define in your non-library
objects to satisfy dependencies from things low in the stack (e.g.
out_of_memory()).
One thing that's gone completely missing in this migration,
unfortunately, is the unfinished MacOS port linked against Quartz GTK.
That's because it turned out that I can't currently build it myself,
on my own Mac: my previous installation of GTK had bit-rotted as a
side effect of an Xcode upgrade, and I haven't yet been able to
persuade jhbuild to make me a new one. So I can't even build the MacOS
port with the _old_ makefiles, and hence, I have no way of checking
that the new ones also work. I hope to bring that port back to life at
some point, but I don't want it to block the rest of this change.
2021-04-10 14:21:11 +00:00
|
|
|
* standard. But older versions of Visual Studio don't provide
|
2015-09-28 18:52:38 +00:00
|
|
|
* stdint.h at all, but do (non-standardly) define uintptr_t in
|
|
|
|
* stddef.h. So here we try to make sure _some_ standard header is
|
|
|
|
* included which defines uintptr_t. */
|
|
|
|
#include <stddef.h>
|
Replace mkfiles.pl with a CMake build system.
This brings various concrete advantages over the previous system:
- consistent support for out-of-tree builds on all platforms
- more thorough support for Visual Studio IDE project files
- support for Ninja-based builds, which is particularly useful on
Windows where the alternative nmake has no parallel option
- a really simple set of build instructions that work the same way on
all the major platforms (look how much shorter README is!)
- better decoupling of the project configuration from the toolchain
configuration, so that my Windows cross-building doesn't need
(much) special treatment in CMakeLists.txt
- configure-time tests on Windows as well as Linux, so that a lot of
ad-hoc #ifdefs second-guessing a particular feature's presence from
the compiler version can now be replaced by tests of the feature
itself
Also some longer-term software-engineering advantages:
- other people have actually heard of CMake, so they'll be able to
produce patches to the new build setup more easily
- unlike the old mkfiles.pl, CMake is not my personal problem to
maintain
- most importantly, mkfiles.pl was just a horrible pile of
unmaintainable cruft, which even I found it painful to make changes
to or to use, and desperately needed throwing in the bin. I've
already thrown away all the variants of it I had in other projects
of mine, and was only delaying this one so we could make the 0.75
release branch first.
This change comes with a noticeable build-level restructuring. The
previous Recipe worked by compiling every object file exactly once,
and then making each executable by linking a precisely specified
subset of the same object files. But in CMake, that's not the natural
way to work - if you write the obvious command that puts the same
source file into two executable targets, CMake generates a makefile
that compiles it once per target. That can be an advantage, because it
gives you the freedom to compile it differently in each case (e.g.
with a #define telling it which program it's part of). But in a
project that has many executable targets and had carefully contrived
to _never_ need to build any module more than once, all it does is
bloat the build time pointlessly!
To avoid slowing down the build by a large factor, I've put most of
the modules of the code base into a collection of static libraries
organised vaguely thematically (SSH, other backends, crypto, network,
...). That means all those modules can still be compiled just once
each, because once each library is built it's reused unchanged for all
the executable targets.
One upside of this library-based structure is that now I don't have to
manually specify exactly which objects go into which programs any more
- it's enough to specify which libraries are needed, and the linker
will figure out the fine detail automatically. So there's less
maintenance to do in CMakeLists.txt when the source code changes.
But that reorganisation also adds fragility, because of the trad Unix
linker semantics of walking along the library list once each, so that
cyclic references between your libraries will provoke link errors. The
current setup builds successfully, but I suspect it only just manages
it.
(In particular, I've found that MinGW is the most finicky on this
score of the Windows compilers I've tried building with. So I've
included a MinGW test build in the new-look Buildscr, because
otherwise I think there'd be a significant risk of introducing
MinGW-only build failures due to library search order, which wasn't a
risk in the previous library-free build organisation.)
In the longer term I hope to be able to reduce the risk of that, via
gradual reorganisation (in particular, breaking up too-monolithic
modules, to reduce the risk of knock-on references when you included a
module for function A and it also contains function B with an
unsatisfied dependency you didn't really need). Ideally I want to
reach a state in which the libraries all have sensibly described
purposes, a clearly documented (partial) order in which they're
permitted to depend on each other, and a specification of what stubs
you have to put where if you're leaving one of them out (e.g.
nocrypto) and what callbacks you have to define in your non-library
objects to satisfy dependencies from things low in the stack (e.g.
out_of_memory()).
One thing that's gone completely missing in this migration,
unfortunately, is the unfinished MacOS port linked against Quartz GTK.
That's because it turned out that I can't currently build it myself,
on my own Mac: my previous installation of GTK had bit-rotted as a
side effect of an Xcode upgrade, and I haven't yet been able to
persuade jhbuild to make me a new one. So I can't even build the MacOS
port with the _old_ makefiles, and hence, I have no way of checking
that the new ones also work. I hope to bring that port back to life at
some point, but I don't want it to block the rest of this change.
2021-04-10 14:21:11 +00:00
|
|
|
#if !HAVE_NO_STDINT_H
|
2015-09-28 18:52:38 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
2018-05-24 07:59:01 +00:00
|
|
|
#include "defs.h"
|
2019-02-20 06:52:54 +00:00
|
|
|
#include "marshal.h"
|
2018-05-24 07:59:01 +00:00
|
|
|
|
2003-03-05 22:07:40 +00:00
|
|
|
#include "tree234.h"
|
|
|
|
|
2021-04-23 05:19:05 +00:00
|
|
|
#include "help.h"
|
2003-03-05 22:07:40 +00:00
|
|
|
|
2018-05-31 17:12:01 +00:00
|
|
|
#if defined _M_IX86 || defined _M_AMD64
|
|
|
|
#define BUILDINFO_PLATFORM "x86 Windows"
|
|
|
|
#elif defined _M_ARM || defined _M_ARM64
|
|
|
|
#define BUILDINFO_PLATFORM "Arm Windows"
|
|
|
|
#else
|
2017-01-21 14:55:53 +00:00
|
|
|
#define BUILDINFO_PLATFORM "Windows"
|
2018-05-31 17:12:01 +00:00
|
|
|
#endif
|
2017-01-21 14:55:53 +00:00
|
|
|
|
2003-02-01 12:54:40 +00:00
|
|
|
struct Filename {
|
2011-10-02 11:01:57 +00:00
|
|
|
char *path;
|
2003-02-01 12:54:40 +00:00
|
|
|
};
|
2019-02-27 19:47:12 +00:00
|
|
|
static inline FILE *f_open(const Filename *filename, const char *mode,
|
|
|
|
bool isprivate)
|
|
|
|
{
|
|
|
|
return fopen(filename->path, mode);
|
|
|
|
}
|
2003-02-01 12:54:40 +00:00
|
|
|
|
|
|
|
struct FontSpec {
|
2011-10-01 17:38:59 +00:00
|
|
|
char *name;
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool isbold;
|
2003-02-01 12:54:40 +00:00
|
|
|
int height;
|
|
|
|
int charset;
|
|
|
|
};
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
struct FontSpec *fontspec_new(
|
|
|
|
const char *name, bool bold, int height, int charset);
|
2003-02-01 12:54:40 +00:00
|
|
|
|
2006-01-11 23:42:02 +00:00
|
|
|
#ifndef CLEARTYPE_QUALITY
|
|
|
|
#define CLEARTYPE_QUALITY 5
|
|
|
|
#endif
|
|
|
|
#define FONT_QUALITY(fq) ( \
|
|
|
|
(fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
|
|
|
|
(fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
|
|
|
|
(fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
|
|
|
|
CLEARTYPE_QUALITY)
|
|
|
|
|
2009-03-24 22:24:31 +00:00
|
|
|
#define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
|
2019-09-08 19:29:00 +00:00
|
|
|
* wchar_t strings with environment */
|
2009-03-24 22:24:31 +00:00
|
|
|
|
2017-12-09 12:00:13 +00:00
|
|
|
#define PLATFORM_CLIPBOARDS(X) \
|
|
|
|
X(CLIP_SYSTEM, "system clipboard") \
|
|
|
|
/* end of list */
|
|
|
|
|
2006-01-27 20:49:59 +00:00
|
|
|
/*
|
|
|
|
* Where we can, we use GetWindowLongPtr and friends because they're
|
|
|
|
* more useful on 64-bit platforms, but they're a relatively recent
|
|
|
|
* innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
|
|
|
|
* (NB that on some systems, some of these things are available but
|
|
|
|
* not others...)
|
|
|
|
*/
|
2006-01-11 23:42:02 +00:00
|
|
|
|
2006-01-27 20:49:59 +00:00
|
|
|
#ifndef GCLP_HCURSOR
|
|
|
|
/* GetClassLongPtr and friends */
|
|
|
|
#undef GetClassLongPtr
|
|
|
|
#define GetClassLongPtr GetClassLong
|
|
|
|
#undef SetClassLongPtr
|
|
|
|
#define SetClassLongPtr SetClassLong
|
|
|
|
#define GCLP_HCURSOR GCL_HCURSOR
|
|
|
|
/* GetWindowLongPtr and friends */
|
|
|
|
#undef GetWindowLongPtr
|
2006-01-11 23:42:02 +00:00
|
|
|
#define GetWindowLongPtr GetWindowLong
|
2006-01-27 20:49:59 +00:00
|
|
|
#undef SetWindowLongPtr
|
2006-01-11 23:42:02 +00:00
|
|
|
#define SetWindowLongPtr SetWindowLong
|
2006-01-27 20:49:59 +00:00
|
|
|
#undef GWLP_USERDATA
|
2006-01-11 23:42:02 +00:00
|
|
|
#define GWLP_USERDATA GWL_USERDATA
|
2006-01-27 20:49:59 +00:00
|
|
|
#undef DWLP_MSGRESULT
|
2006-01-11 23:42:02 +00:00
|
|
|
#define DWLP_MSGRESULT DWL_MSGRESULT
|
2006-01-27 20:49:59 +00:00
|
|
|
/* Since we've clobbered the above functions, we should clobber the
|
|
|
|
* associated type regardless of whether it's defined. */
|
|
|
|
#undef LONG_PTR
|
|
|
|
#define LONG_PTR LONG
|
2006-01-11 23:42:02 +00:00
|
|
|
#endif
|
|
|
|
|
New library-style 'utils' subdirectories.
Now that the new CMake build system is encouraging us to lay out the
code like a set of libraries, it seems like a good idea to make them
look more _like_ libraries, by putting things into separate modules as
far as possible.
This fixes several previous annoyances in which you had to link
against some object in order to get a function you needed, but that
object also contained other functions you didn't need which included
link-time symbol references you didn't want to have to deal with. The
usual offender was subsidiary supporting programs including misc.c for
some innocuous function and then finding they had to deal with the
requirements of buildinfo().
This big reorganisation introduces three new subdirectories called
'utils', one at the top level and one in each platform subdir. In each
case, the directory contains basically the same files that were
previously placed in the 'utils' build-time library, except that the
ones that were extremely miscellaneous (misc.c, utils.c, uxmisc.c,
winmisc.c, winmiscs.c, winutils.c) have been split up into much
smaller pieces.
2021-04-17 14:22:20 +00:00
|
|
|
#if !HAVE_STRTOUMAX
|
|
|
|
/* Work around lack of strtoumax in older MSVC libraries */
|
|
|
|
static inline uintmax_t strtoumax(const char *nptr, char **endptr, int base)
|
|
|
|
{ return _strtoui64(nptr, endptr, base); }
|
|
|
|
#endif
|
|
|
|
|
2003-06-18 17:25:18 +00:00
|
|
|
#define BOXFLAGS DLGWINDOWEXTRA
|
2005-05-21 14:16:43 +00:00
|
|
|
#define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
|
2003-06-16 23:55:26 +00:00
|
|
|
#define DF_END 0x0001
|
|
|
|
|
2017-02-14 23:19:13 +00:00
|
|
|
#ifndef __WINE__
|
2017-02-05 11:13:45 +00:00
|
|
|
/* Up-to-date Windows headers warn that the unprefixed versions of
|
|
|
|
* these names are deprecated. */
|
|
|
|
#define stricmp _stricmp
|
|
|
|
#define strnicmp _strnicmp
|
2017-02-14 23:19:13 +00:00
|
|
|
#else
|
|
|
|
/* Compiling with winegcc, _neither_ version of these functions
|
|
|
|
* exists. Use the POSIX names. */
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
#define strnicmp strncasecmp
|
|
|
|
#endif
|
2017-02-05 11:13:45 +00:00
|
|
|
|
2021-04-22 16:58:40 +00:00
|
|
|
#define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in ssh/sharing.c */
|
2015-09-25 11:05:55 +00:00
|
|
|
|
2009-11-08 18:47:41 +00:00
|
|
|
/*
|
2010-03-13 15:14:30 +00:00
|
|
|
* Dynamically linked functions. These come in two flavours:
|
|
|
|
*
|
|
|
|
* - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
|
|
|
|
* so will always dynamically link against exactly what is specified
|
|
|
|
* in "name". If you're not sure, use this one.
|
|
|
|
*
|
|
|
|
* - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
|
|
|
|
* preprocessor definitions like "#define foo bar"; this is principally
|
|
|
|
* intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
|
|
|
|
* If your function has an argument of type "LPTSTR" or similar, this
|
|
|
|
* is the variant to use.
|
|
|
|
* (However, it can't always be used, as it trips over more complicated
|
|
|
|
* macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
|
|
|
|
*
|
|
|
|
* (DECL_WINDOWS_FUNCTION works with both these variants.)
|
2009-11-08 18:47:41 +00:00
|
|
|
*/
|
Add automatic type-checking to GET_WINDOWS_FUNCTION.
This gives me an extra safety-check against having mistyped one of the
function prototypes that we load at run time from DLLs: we verify that
the typedef we defined based on the prototype in our source code
matches the type of the real function as declared in the Windows
headers.
This was an idea I had while adding a pile of further functions using
this mechanism. It didn't catch any errors (either in the new
functions or in the existing collection), but that's no reason not to
keep it anyway now that I've thought of it!
In VS2015, this automated type-check works for most functions, but a
couple manage to break it. SetCurrentProcessExplicitAppUserModelID in
winjump.c can't be type-checked, because including <shobjidl.h> where
that function is declared would also bring in a load of other stuff
that conflicts with the painful manual COM declarations in winjump.c.
(That stuff could probably be removed now we're on an up-to-date
Visual Studio, on the other hand, but that's a separate chore.) And
gai_strerror, used in winnet.c, does _have_ an implementation in a
DLL, but the header files like to provide an inline version with a
different calling convention, which defeats this error-checking trick.
And in the older VS2003 that we still precautionarily build with,
several more type-checks have to be #ifdeffed out because the
functions they check against just aren't there at all.
2017-04-11 17:56:55 +00:00
|
|
|
#define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
|
|
|
|
typedef rettype (WINAPI *t_##name) params; \
|
2009-11-08 18:47:41 +00:00
|
|
|
linkage t_##name p_##name
|
2020-02-02 10:00:43 +00:00
|
|
|
/* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to
|
|
|
|
* define the function pointer in a source file */
|
|
|
|
#define DEF_WINDOWS_FUNCTION(name) t_##name p_##name
|
2009-11-08 18:47:41 +00:00
|
|
|
#define STR1(x) #x
|
|
|
|
#define STR(x) STR1(x)
|
Add automatic type-checking to GET_WINDOWS_FUNCTION.
This gives me an extra safety-check against having mistyped one of the
function prototypes that we load at run time from DLLs: we verify that
the typedef we defined based on the prototype in our source code
matches the type of the real function as declared in the Windows
headers.
This was an idea I had while adding a pile of further functions using
this mechanism. It didn't catch any errors (either in the new
functions or in the existing collection), but that's no reason not to
keep it anyway now that I've thought of it!
In VS2015, this automated type-check works for most functions, but a
couple manage to break it. SetCurrentProcessExplicitAppUserModelID in
winjump.c can't be type-checked, because including <shobjidl.h> where
that function is declared would also bring in a load of other stuff
that conflicts with the painful manual COM declarations in winjump.c.
(That stuff could probably be removed now we're on an up-to-date
Visual Studio, on the other hand, but that's a separate chore.) And
gai_strerror, used in winnet.c, does _have_ an implementation in a
DLL, but the header files like to provide an inline version with a
different calling convention, which defeats this error-checking trick.
And in the older VS2003 that we still precautionarily build with,
several more type-checks have to be #ifdeffed out because the
functions they check against just aren't there at all.
2017-04-11 17:56:55 +00:00
|
|
|
#define GET_WINDOWS_FUNCTION_PP(module, name) \
|
|
|
|
TYPECHECK((t_##name)NULL == name, \
|
|
|
|
(p_##name = module ? \
|
|
|
|
(t_##name) GetProcAddress(module, STR(name)) : NULL))
|
|
|
|
#define GET_WINDOWS_FUNCTION(module, name) \
|
|
|
|
TYPECHECK((t_##name)NULL == name, \
|
|
|
|
(p_##name = module ? \
|
|
|
|
(t_##name) GetProcAddress(module, #name) : NULL))
|
|
|
|
#define GET_WINDOWS_FUNCTION_NO_TYPECHECK(module, name) \
|
|
|
|
(p_##name = module ? \
|
|
|
|
(t_##name) GetProcAddress(module, #name) : NULL)
|
2009-11-08 18:47:41 +00:00
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
|
|
|
|
#define PUTTY_REG_PARENT "Software\\SimonTatham"
|
|
|
|
#define PUTTY_REG_PARENT_CHILD "PuTTY"
|
|
|
|
#define PUTTY_REG_GPARENT "Software"
|
|
|
|
#define PUTTY_REG_GPARENT_CHILD "SimonTatham"
|
|
|
|
|
2010-12-23 17:32:28 +00:00
|
|
|
/* Result values for the jumplist registry functions. */
|
|
|
|
#define JUMPLISTREG_OK 0
|
|
|
|
#define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
|
|
|
|
#define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
|
|
|
|
#define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
|
|
|
|
#define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
|
|
|
|
#define JUMPLISTREG_ERROR_INVALID_VALUE 5
|
|
|
|
|
2006-12-17 11:16:07 +00:00
|
|
|
#define PUTTY_CHM_FILE "putty.chm"
|
2005-02-16 01:47:10 +00:00
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
#define GETTICKCOUNT GetTickCount
|
|
|
|
#define CURSORBLINK GetCaretBlinkTime()
|
2019-09-08 19:29:00 +00:00
|
|
|
#define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
|
2002-10-07 16:45:23 +00:00
|
|
|
|
|
|
|
#define DEFAULT_CODEPAGE CP_ACP
|
2012-04-22 14:22:10 +00:00
|
|
|
#define USES_VTLINE_HACK
|
2002-10-07 16:45:23 +00:00
|
|
|
|
2008-11-24 23:44:55 +00:00
|
|
|
#ifndef NO_GSSAPI
|
|
|
|
/*
|
|
|
|
* GSS-API stuff
|
|
|
|
*/
|
2010-05-19 18:22:17 +00:00
|
|
|
#define GSS_CC CALLBACK
|
|
|
|
/*
|
2008-11-24 23:44:55 +00:00
|
|
|
typedef struct Ssh_gss_buf {
|
2010-05-19 18:22:17 +00:00
|
|
|
size_t length;
|
2008-11-24 23:44:55 +00:00
|
|
|
char *value;
|
|
|
|
} Ssh_gss_buf;
|
|
|
|
|
|
|
|
#define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
|
2008-12-01 21:18:29 +00:00
|
|
|
typedef void *Ssh_gss_name;
|
2010-05-19 18:22:17 +00:00
|
|
|
*/
|
2008-11-24 23:44:55 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
/*
|
Remove remaining uses of the GLOBAL macro.
We now have no remaining things in header files that switch from being
a declaration to a definition depending on an awkward #define at the
point of including that header. There are still a few mutable
variables with external linkage, but at least now each one is defined
in a specific source file file appropriate to its purpose and context.
The remaining globals as of this commit were:
- 'logctx' and 'term', which never needed to be globals in the first
place, because they were never actually shared between source
files. Now 'term' is just a static in window.c, and 'logctx' is a
static in each of that and winplink.c.
- 'hinst', which still has external linkage, but is now defined
separately in each source file that sets it up (i.e. those with a
WinMain)
- osMajorVersion, osMinorVersion and osPlatformId, whose definitions
now live in winmisc.c alongside the code which sets them up.
(Actually they were defined there all along, it turns out, but
every toolchain I've built with has commoned them together with the
version defined by the GLOBAL in the header.)
- 'hwnd', which nothing was actually _using_ any more after previous
commits, so all this commit had to do was delete it.
2020-02-02 10:00:43 +00:00
|
|
|
* The all-important instance handle, saved from WinMain in every GUI
|
|
|
|
* program and exported for other GUI code to pass back to the Windows
|
|
|
|
* API.
|
2002-10-07 16:45:23 +00:00
|
|
|
*/
|
Remove remaining uses of the GLOBAL macro.
We now have no remaining things in header files that switch from being
a declaration to a definition depending on an awkward #define at the
point of including that header. There are still a few mutable
variables with external linkage, but at least now each one is defined
in a specific source file file appropriate to its purpose and context.
The remaining globals as of this commit were:
- 'logctx' and 'term', which never needed to be globals in the first
place, because they were never actually shared between source
files. Now 'term' is just a static in window.c, and 'logctx' is a
static in each of that and winplink.c.
- 'hinst', which still has external linkage, but is now defined
separately in each source file that sets it up (i.e. those with a
WinMain)
- osMajorVersion, osMinorVersion and osPlatformId, whose definitions
now live in winmisc.c alongside the code which sets them up.
(Actually they were defined there all along, it turns out, but
every toolchain I've built with has commoned them together with the
version defined by the GLOBAL in the header.)
- 'hwnd', which nothing was actually _using_ any more after previous
commits, so all this commit had to do was delete it.
2020-02-02 10:00:43 +00:00
|
|
|
extern HINSTANCE hinst;
|
2000-10-18 15:36:32 +00:00
|
|
|
|
2002-10-26 10:33:59 +00:00
|
|
|
/*
|
2006-12-17 11:16:07 +00:00
|
|
|
* Help file stuff in winhelp.c.
|
2002-10-26 10:33:59 +00:00
|
|
|
*/
|
2006-12-17 11:16:07 +00:00
|
|
|
void init_help(void);
|
|
|
|
void shutdown_help(void);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool has_help(void);
|
2006-12-17 11:16:07 +00:00
|
|
|
void launch_help(HWND hwnd, const char *topic);
|
|
|
|
void quit_help(HWND hwnd);
|
2019-01-26 20:26:09 +00:00
|
|
|
int has_embedded_chm(void); /* 1 = yes, 0 = no, -1 = N/A */
|
2002-10-26 10:33:59 +00:00
|
|
|
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
/*
|
2018-11-03 10:06:33 +00:00
|
|
|
* GUI seat methods in windlg.c, so that the vtable definition in
|
|
|
|
* window.c can refer to them.
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
*/
|
|
|
|
int win_seat_verify_ssh_host_key(
|
2021-03-13 10:59:47 +00:00
|
|
|
Seat *seat, const char *host, int port, const char *keytype,
|
|
|
|
char *keystr, const char *keydisp, char **key_fingerprints,
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
void (*callback)(void *ctx, int result), void *ctx);
|
|
|
|
int win_seat_confirm_weak_crypto_primitive(
|
|
|
|
Seat *seat, const char *algtype, const char *algname,
|
|
|
|
void (*callback)(void *ctx, int result), void *ctx);
|
|
|
|
int win_seat_confirm_weak_cached_hostkey(
|
|
|
|
Seat *seat, const char *algname, const char *betteralgs,
|
|
|
|
void (*callback)(void *ctx, int result), void *ctx);
|
2002-10-26 12:58:13 +00:00
|
|
|
|
2017-12-09 11:57:34 +00:00
|
|
|
/*
|
|
|
|
* Windows-specific clipboard helper function shared with windlg.c,
|
|
|
|
* which takes the data string in the system code page instead of
|
|
|
|
* Unicode.
|
|
|
|
*/
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
void write_aclip(int clipboard, char *, int, bool);
|
2017-12-09 11:57:34 +00:00
|
|
|
|
2005-08-10 18:31:24 +00:00
|
|
|
#define WM_NETEVENT (WM_APP + 5)
|
2002-10-07 16:45:23 +00:00
|
|
|
|
2002-10-13 11:24:25 +00:00
|
|
|
/*
|
|
|
|
* On Windows, we send MA_2CLK as the only event marking the second
|
|
|
|
* press of a mouse button. Compare unix.h.
|
|
|
|
*/
|
|
|
|
#define MULTICLICK_ONLY_EVENT 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On Windows, data written to the clipboard must be NUL-terminated.
|
|
|
|
*/
|
|
|
|
#define SELECTION_NUL_TERMINATED 1
|
|
|
|
|
2002-10-14 09:06:31 +00:00
|
|
|
/*
|
|
|
|
* On Windows, copying to the clipboard terminates lines with CRLF.
|
|
|
|
*/
|
|
|
|
#define SEL_NL { 13, 10 }
|
|
|
|
|
2003-01-11 09:31:54 +00:00
|
|
|
/*
|
|
|
|
* sk_getxdmdata() does not exist under Windows (not that I
|
|
|
|
* couldn't write it if I wanted to, but I haven't bothered), so
|
2005-01-28 11:39:45 +00:00
|
|
|
* it's a macro which always returns NULL. With any luck this will
|
2003-01-11 09:31:54 +00:00
|
|
|
* cause the compiler to notice it can optimise away the
|
2021-04-22 16:58:40 +00:00
|
|
|
* implementation of XDM-AUTHORIZATION-1 in ssh/x11fwd.c :-)
|
2003-01-11 09:31:54 +00:00
|
|
|
*/
|
2005-01-28 11:39:45 +00:00
|
|
|
#define sk_getxdmdata(socket, lenp) (NULL)
|
2003-01-11 09:31:54 +00:00
|
|
|
|
2003-03-05 22:07:40 +00:00
|
|
|
/*
|
|
|
|
* File-selector filter strings used in the config box. On Windows,
|
|
|
|
* these strings are of exactly the type needed to go in
|
|
|
|
* `lpstrFilter' in an OPENFILENAME structure.
|
|
|
|
*/
|
|
|
|
#define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
|
2019-09-08 19:29:00 +00:00
|
|
|
"All Files (*.*)\0*\0\0\0")
|
2003-03-05 22:07:40 +00:00
|
|
|
#define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
|
2019-09-08 19:29:00 +00:00
|
|
|
"All Files (*.*)\0*\0\0\0")
|
2010-09-25 07:16:56 +00:00
|
|
|
#define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
|
2019-09-08 19:29:00 +00:00
|
|
|
"All Files (*.*)\0*\0\0\0")
|
2003-03-05 22:07:40 +00:00
|
|
|
|
2013-08-17 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* Exports from winnet.c.
|
|
|
|
*/
|
2018-11-03 10:06:33 +00:00
|
|
|
/* Report an event notification from WSA*Select */
|
|
|
|
void select_result(WPARAM, LPARAM);
|
|
|
|
/* Enumerate all currently live OS-level SOCKETs */
|
|
|
|
SOCKET first_socket(int *);
|
|
|
|
SOCKET next_socket(int *);
|
|
|
|
/* Ask winnet.c whether we currently want to try to write to a SOCKET */
|
|
|
|
bool socket_writable(SOCKET skt);
|
|
|
|
/* Force a refresh of the SOCKET list by re-calling do_select for each one */
|
|
|
|
void socket_reselect_all(void);
|
|
|
|
/* Make a SockAddr which just holds a named pipe address. */
|
|
|
|
SockAddr *sk_namedpipe_addr(const char *pipename);
|
2020-01-01 11:10:22 +00:00
|
|
|
/* Turn a WinSock error code into a string. */
|
|
|
|
const char *winsock_error_string(int error);
|
2013-08-17 16:06:35 +00:00
|
|
|
|
2003-10-12 13:46:12 +00:00
|
|
|
/*
|
|
|
|
* winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
|
|
|
|
* what it can get, which means any WinSock routines used outside
|
|
|
|
* that module must be exported from it as function pointers. So
|
|
|
|
* here they are.
|
|
|
|
*/
|
2020-02-02 10:00:43 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(extern, int, WSAAsyncSelect,
|
2019-09-08 19:29:00 +00:00
|
|
|
(SOCKET, HWND, u_int, long));
|
2020-02-02 10:00:43 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(extern, int, WSAEventSelect,
|
2019-09-08 19:29:00 +00:00
|
|
|
(SOCKET, WSAEVENT, long));
|
2020-02-02 10:00:43 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(extern, int, WSAGetLastError, (void));
|
|
|
|
DECL_WINDOWS_FUNCTION(extern, int, WSAEnumNetworkEvents,
|
2019-09-08 19:29:00 +00:00
|
|
|
(SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
|
2017-02-14 23:19:13 +00:00
|
|
|
#ifdef NEED_DECLARATION_OF_SELECT
|
|
|
|
/* This declaration is protected by an ifdef for the sake of building
|
|
|
|
* against winelib, in which you have to include winsock2.h before
|
|
|
|
* stdlib.h so that the right fd_set type gets defined. It would be a
|
|
|
|
* pain to do that throughout this codebase, so instead I arrange that
|
|
|
|
* only a modules actually needing to use (or define, or initialise)
|
|
|
|
* this function pointer will see its declaration, and _those_ modules
|
|
|
|
* - which will be Windows-specific anyway - can take more care. */
|
2020-02-02 10:00:43 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(extern, int, select,
|
2019-09-08 19:29:00 +00:00
|
|
|
(int, fd_set FAR *, fd_set FAR *,
|
|
|
|
fd_set FAR *, const struct timeval FAR *));
|
2017-02-14 23:19:13 +00:00
|
|
|
#endif
|
2003-10-12 13:46:12 +00:00
|
|
|
|
2018-11-03 10:06:33 +00:00
|
|
|
/*
|
2020-01-01 11:10:22 +00:00
|
|
|
* Implemented differently depending on the client of winnet.c, and
|
|
|
|
* called by winnet.c to turn on or off WSA*Select for a given socket.
|
2018-11-03 10:06:33 +00:00
|
|
|
*/
|
2020-01-01 15:46:59 +00:00
|
|
|
const char *do_select(SOCKET skt, bool enable);
|
2004-11-27 13:20:21 +00:00
|
|
|
|
2020-01-01 11:10:22 +00:00
|
|
|
/*
|
|
|
|
* Exports from winselgui.c and winselcli.c, each of which provides an
|
|
|
|
* implementation of do_select.
|
|
|
|
*/
|
|
|
|
void winselgui_set_hwnd(HWND hwnd);
|
|
|
|
void winselgui_clear_hwnd(void);
|
|
|
|
|
|
|
|
void winselcli_setup(void);
|
|
|
|
SOCKET winselcli_unique_socket(void);
|
|
|
|
extern HANDLE winselcli_event;
|
|
|
|
|
2018-11-03 10:06:33 +00:00
|
|
|
/*
|
|
|
|
* Network-subsystem-related functions provided in other Windows modules.
|
|
|
|
*/
|
|
|
|
Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
|
2021-09-13 13:34:46 +00:00
|
|
|
SockAddr *addr, int port, Plug *plug,
|
|
|
|
bool overlapped); /* winhsock */
|
2018-11-03 10:06:33 +00:00
|
|
|
Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
|
|
|
|
Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */
|
2007-01-08 19:38:39 +00:00
|
|
|
|
2020-01-01 18:58:11 +00:00
|
|
|
/* A lower-level function in winnpc.c, which does most of the work of
|
|
|
|
* new_named_pipe_client (including checking the ownership of what
|
|
|
|
* it's connected to), but returns a plain HANDLE instead of wrapping
|
|
|
|
* it into a Socket. */
|
|
|
|
HANDLE connect_to_named_pipe(const char *pipename, char **err);
|
|
|
|
|
2000-10-18 15:36:32 +00:00
|
|
|
/*
|
|
|
|
* Exports from winctrls.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ctlpos {
|
|
|
|
HWND hwnd;
|
|
|
|
WPARAM font;
|
|
|
|
int dlu4inpix;
|
|
|
|
int ypos, width;
|
|
|
|
int xoff;
|
2001-01-22 17:17:26 +00:00
|
|
|
int boxystart, boxid;
|
2000-10-18 15:36:32 +00:00
|
|
|
char *boxtext;
|
|
|
|
};
|
2017-03-13 21:42:44 +00:00
|
|
|
void init_common_controls(void); /* also does some DLL-loading */
|
2000-10-18 15:36:32 +00:00
|
|
|
|
2002-08-04 21:18:56 +00:00
|
|
|
/*
|
|
|
|
* Exports from winutils.c.
|
|
|
|
*/
|
2005-02-28 02:40:43 +00:00
|
|
|
typedef struct filereq_tag filereq; /* cwd for file requester */
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
|
2005-02-28 02:40:43 +00:00
|
|
|
filereq *filereq_new(void);
|
|
|
|
void filereq_free(filereq *state);
|
2020-02-02 10:00:42 +00:00
|
|
|
void pgp_fingerprints_msgbox(HWND owner);
|
|
|
|
int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
|
|
|
|
DWORD style, DWORD helpctxid);
|
2021-04-06 20:14:51 +00:00
|
|
|
void MakeDlgItemBorderless(HWND parent, int id);
|
2011-10-02 13:53:58 +00:00
|
|
|
char *GetDlgItemText_alloc(HWND hwnd, int id);
|
2002-08-06 17:57:37 +00:00
|
|
|
void split_into_argv(char *, int *, char ***, char ***);
|
2002-08-04 21:18:56 +00:00
|
|
|
|
2001-08-25 19:33:33 +00:00
|
|
|
/*
|
|
|
|
* Private structure for prefslist state. Only in the header file
|
|
|
|
* so that we can delegate allocation to callers.
|
|
|
|
*/
|
|
|
|
struct prefslist {
|
|
|
|
int listid, upbid, dnbid;
|
|
|
|
int srcitem;
|
|
|
|
int dummyitem;
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool dragging;
|
2001-08-25 19:33:33 +00:00
|
|
|
};
|
|
|
|
|
2003-03-05 22:07:40 +00:00
|
|
|
/*
|
|
|
|
* This structure is passed to event handler functions as the `dlg'
|
|
|
|
* parameter, and hence is passed back to winctrls access functions.
|
|
|
|
*/
|
|
|
|
struct dlgparam {
|
2019-09-08 19:29:00 +00:00
|
|
|
HWND hwnd; /* the hwnd of the dialog box */
|
2003-03-05 22:07:40 +00:00
|
|
|
struct winctrls *controltrees[8]; /* can have several of these */
|
|
|
|
int nctrltrees;
|
2019-09-08 19:29:00 +00:00
|
|
|
char *wintitle; /* title of actual window */
|
|
|
|
char *errtitle; /* title of error sub-messageboxes */
|
|
|
|
void *data; /* data to pass in refresh events */
|
2003-03-05 22:07:40 +00:00
|
|
|
union control *focused, *lastfocused; /* which ctrl has focus now/before */
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool shortcuts[128]; /* track which shortcuts in use */
|
|
|
|
bool coloursel_wanted; /* has an event handler asked for
|
2019-09-08 19:29:00 +00:00
|
|
|
* a colour selector? */
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
struct {
|
|
|
|
unsigned char r, g, b; /* 0-255 */
|
|
|
|
bool ok;
|
|
|
|
} coloursel_result;
|
2019-09-08 19:29:00 +00:00
|
|
|
tree234 *privdata; /* stores per-control private data */
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool ended; /* has the dialog been ended? */
|
|
|
|
int endresult; /* and if so, what was the result? */
|
|
|
|
bool fixed_pitch_fonts; /* are we constrained to fixed fonts? */
|
2003-03-05 22:07:40 +00:00
|
|
|
};
|
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
/*
|
|
|
|
* Exports from winctrls.c.
|
|
|
|
*/
|
2000-10-18 15:36:32 +00:00
|
|
|
void ctlposinit(struct ctlpos *cp, HWND hwnd,
|
2019-09-08 19:29:00 +00:00
|
|
|
int leftborder, int rightborder, int topborder);
|
2001-08-25 19:33:33 +00:00
|
|
|
HWND doctl(struct ctlpos *cp, RECT r,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *wclass, int wstyle, int exstyle, char *wtext, int wid);
|
2000-10-18 15:36:32 +00:00
|
|
|
void bartitle(struct ctlpos *cp, char *name, int id);
|
2001-01-22 17:17:26 +00:00
|
|
|
void beginbox(struct ctlpos *cp, char *name, int idbox);
|
2000-10-18 15:36:32 +00:00
|
|
|
void endbox(struct ctlpos *cp);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
void editboxfw(struct ctlpos *cp, bool password, char *text,
|
2019-09-08 19:29:00 +00:00
|
|
|
int staticid, int editid);
|
2001-05-06 14:35:20 +00:00
|
|
|
void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
|
2001-08-08 20:44:35 +00:00
|
|
|
void bareradioline(struct ctlpos *cp, int nacross, ...);
|
2000-10-18 15:36:32 +00:00
|
|
|
void radiobig(struct ctlpos *cp, char *text, int id, ...);
|
|
|
|
void checkbox(struct ctlpos *cp, char *text, int id);
|
2001-09-09 09:58:20 +00:00
|
|
|
void statictext(struct ctlpos *cp, char *text, int lines, int id);
|
2000-10-18 15:36:32 +00:00
|
|
|
void staticbtn(struct ctlpos *cp, char *stext, int sid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *btext, int bid);
|
2001-08-27 17:40:03 +00:00
|
|
|
void static2btn(struct ctlpos *cp, char *stext, int sid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *btext1, int bid1, char *btext2, int bid2);
|
2000-10-18 15:36:32 +00:00
|
|
|
void staticedit(struct ctlpos *cp, char *stext,
|
2019-09-08 19:29:00 +00:00
|
|
|
int sid, int eid, int percentedit);
|
2002-09-08 13:28:38 +00:00
|
|
|
void staticddl(struct ctlpos *cp, char *stext,
|
2019-09-08 19:29:00 +00:00
|
|
|
int sid, int lid, int percentlist);
|
2001-09-05 21:01:04 +00:00
|
|
|
void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
|
2000-10-19 15:43:08 +00:00
|
|
|
void staticpassedit(struct ctlpos *cp, char *stext,
|
2019-09-08 19:29:00 +00:00
|
|
|
int sid, int eid, int percentedit);
|
2000-10-19 15:43:08 +00:00
|
|
|
void bigeditctrl(struct ctlpos *cp, char *stext,
|
2019-09-08 19:29:00 +00:00
|
|
|
int sid, int eid, int lines);
|
2001-05-06 14:35:20 +00:00
|
|
|
void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
|
2000-10-18 15:36:32 +00:00
|
|
|
void editbutton(struct ctlpos *cp, char *stext, int sid,
|
2019-09-08 19:29:00 +00:00
|
|
|
int eid, char *btext, int bid);
|
2000-10-18 15:36:32 +00:00
|
|
|
void sesssaver(struct ctlpos *cp, char *text,
|
2019-09-08 19:29:00 +00:00
|
|
|
int staticid, int editid, int listid, ...);
|
2000-10-18 15:36:32 +00:00
|
|
|
void envsetter(struct ctlpos *cp, char *stext, int sid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *e1stext, int e1sid, int e1id,
|
|
|
|
char *e2stext, int e2sid, int e2id,
|
|
|
|
int listid, char *b1text, int b1id, char *b2text, int b2id);
|
2000-10-18 15:36:32 +00:00
|
|
|
void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *btext, int bid, int eid, char *s2text, int s2id);
|
2000-10-18 15:36:32 +00:00
|
|
|
void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *btext, int bid, ...);
|
2003-03-05 22:07:40 +00:00
|
|
|
void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *stext, int sid, int listid, int upbid, int dnbid);
|
2001-08-25 19:33:33 +00:00
|
|
|
int handle_prefslist(struct prefslist *hdl,
|
2019-09-08 19:29:00 +00:00
|
|
|
int *array, int maxmemb,
|
|
|
|
bool is_dlmsg, HWND hwnd,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
2000-10-19 15:43:08 +00:00
|
|
|
void progressbar(struct ctlpos *cp, int id);
|
2001-08-08 20:44:35 +00:00
|
|
|
void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *e1stext, int e1sid, int e1id,
|
|
|
|
char *e2stext, int e2sid, int e2id,
|
|
|
|
char *btext, int bid,
|
|
|
|
char *r1text, int r1id, char *r2text, int r2id);
|
2002-10-07 16:45:23 +00:00
|
|
|
|
2018-09-13 11:58:44 +00:00
|
|
|
void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
|
|
|
|
void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag);
|
2010-12-29 14:11:25 +00:00
|
|
|
|
2003-03-05 22:07:40 +00:00
|
|
|
#define MAX_SHORTCUTS_PER_CTRL 16
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure is what's stored for each `union control' in the
|
|
|
|
* portable-dialog interface.
|
|
|
|
*/
|
|
|
|
struct winctrl {
|
|
|
|
union control *ctrl;
|
|
|
|
/*
|
|
|
|
* The control may have several components at the Windows
|
|
|
|
* level, with different dialog IDs. To avoid needing N
|
|
|
|
* separate platformsidectrl structures (which could be stored
|
|
|
|
* separately in a tree234 so that lookup by ID worked), we
|
|
|
|
* impose the constraint that those IDs must be in a contiguous
|
|
|
|
* block.
|
|
|
|
*/
|
|
|
|
int base_id;
|
|
|
|
int num_ids;
|
2021-04-03 16:45:31 +00:00
|
|
|
/*
|
|
|
|
* For vertical alignment, the id of a particular representative
|
|
|
|
* control that has the y-extent of the sensible part of the
|
|
|
|
* control.
|
|
|
|
*/
|
|
|
|
int align_id;
|
2003-03-05 22:07:40 +00:00
|
|
|
/*
|
|
|
|
* Remember what keyboard shortcuts were used by this control,
|
|
|
|
* so that when we remove it again we can take them out of the
|
|
|
|
* list in the dlgparam.
|
|
|
|
*/
|
|
|
|
char shortcuts[MAX_SHORTCUTS_PER_CTRL];
|
|
|
|
/*
|
|
|
|
* Some controls need a piece of allocated memory in which to
|
|
|
|
* store temporary data about the control.
|
|
|
|
*/
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* And this structure holds a set of the above, in two separate
|
|
|
|
* tree234s so that it can find an item by `union control' or by
|
|
|
|
* dialog ID.
|
|
|
|
*/
|
|
|
|
struct winctrls {
|
|
|
|
tree234 *byctrl, *byid;
|
|
|
|
};
|
2003-03-06 12:41:39 +00:00
|
|
|
struct controlset;
|
|
|
|
struct controlbox;
|
|
|
|
|
2003-03-05 22:07:40 +00:00
|
|
|
void winctrl_init(struct winctrls *);
|
|
|
|
void winctrl_cleanup(struct winctrls *);
|
|
|
|
void winctrl_add(struct winctrls *, struct winctrl *);
|
|
|
|
void winctrl_remove(struct winctrls *, struct winctrl *);
|
|
|
|
struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
|
|
|
|
struct winctrl *winctrl_findbyid(struct winctrls *, int);
|
|
|
|
struct winctrl *winctrl_findbyindex(struct winctrls *, int);
|
|
|
|
void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
2019-09-08 19:29:00 +00:00
|
|
|
struct ctlpos *cp, struct controlset *s, int *id);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
2003-03-06 12:41:39 +00:00
|
|
|
void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
|
2003-03-06 12:41:39 +00:00
|
|
|
|
2003-03-08 11:46:42 +00:00
|
|
|
void dp_init(struct dlgparam *dp);
|
|
|
|
void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
|
|
|
|
void dp_cleanup(struct dlgparam *dp);
|
|
|
|
|
2003-03-06 12:41:39 +00:00
|
|
|
/*
|
|
|
|
* Exports from wincfg.c.
|
|
|
|
*/
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
|
2019-09-08 19:29:00 +00:00
|
|
|
bool midsession, int protocol);
|
2003-03-05 22:07:40 +00:00
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
/*
|
|
|
|
* Exports from windlg.c.
|
|
|
|
*/
|
|
|
|
void defuse_showwindow(void);
|
2020-02-02 10:00:42 +00:00
|
|
|
bool do_config(Conf *);
|
|
|
|
bool do_reconfig(HWND, Conf *, int);
|
2002-10-07 16:45:23 +00:00
|
|
|
void showeventlog(HWND);
|
|
|
|
void showabout(HWND);
|
|
|
|
void force_normal(HWND hwnd);
|
2003-03-06 12:41:39 +00:00
|
|
|
void modal_about_box(HWND hwnd);
|
|
|
|
void show_help(HWND hwnd);
|
2020-02-02 10:00:42 +00:00
|
|
|
HWND event_log_window(void);
|
2002-10-07 16:45:23 +00:00
|
|
|
|
2003-06-16 23:55:26 +00:00
|
|
|
/*
|
|
|
|
* Exports from winmisc.c.
|
|
|
|
*/
|
Remove remaining uses of the GLOBAL macro.
We now have no remaining things in header files that switch from being
a declaration to a definition depending on an awkward #define at the
point of including that header. There are still a few mutable
variables with external linkage, but at least now each one is defined
in a specific source file file appropriate to its purpose and context.
The remaining globals as of this commit were:
- 'logctx' and 'term', which never needed to be globals in the first
place, because they were never actually shared between source
files. Now 'term' is just a static in window.c, and 'logctx' is a
static in each of that and winplink.c.
- 'hinst', which still has external linkage, but is now defined
separately in each source file that sets it up (i.e. those with a
WinMain)
- osMajorVersion, osMinorVersion and osPlatformId, whose definitions
now live in winmisc.c alongside the code which sets them up.
(Actually they were defined there all along, it turns out, but
every toolchain I've built with has commoned them together with the
version defined by the GLOBAL in the header.)
- 'hwnd', which nothing was actually _using_ any more after previous
commits, so all this commit had to do was delete it.
2020-02-02 10:00:43 +00:00
|
|
|
extern DWORD osMajorVersion, osMinorVersion, osPlatformId;
|
2018-06-03 14:05:44 +00:00
|
|
|
void init_winver(void);
|
2016-07-18 19:02:32 +00:00
|
|
|
void dll_hijacking_protection(void);
|
2021-04-24 16:15:47 +00:00
|
|
|
const char *get_system_dir(void);
|
2010-09-13 08:29:45 +00:00
|
|
|
HMODULE load_system32_dll(const char *libname);
|
2013-07-22 07:11:39 +00:00
|
|
|
const char *win_strerror(int error);
|
2017-01-28 21:56:28 +00:00
|
|
|
void restrict_process_acl(void);
|
2020-02-02 10:00:42 +00:00
|
|
|
bool restricted_acl(void);
|
Rework mungestr() and unmungestr().
For a start, they now have different names on Windows and Unix,
reflecting their different roles: on Windows they apply escaping to
any string that's going to be used as a registry key (be it a session
name, or a host name for host key storage), whereas on Unix they're
for constructing saved-session file names in particular (and also
handle the special case of filling in "Default Settings" for NULL).
Also, they now produce output by writing to a strbuf, which simplifies
a lot of the call sites. In particular, the strbuf output idiom is
passed on to enum_settings_next, which is especially nice because its
only actual caller was doing an ad-hoc realloc loop that I can now get
rid of completely.
Thirdly, on Windows they're centralised into winmisc.c instead of
living in winstore.c, because that way Pageant can use the unescape
function too. (It was spotting the duplication there that made me
think of doing this in the first place, but once I'd started, I had to
keep unravelling the thread...)
2018-11-03 08:58:41 +00:00
|
|
|
void escape_registry_key(const char *in, strbuf *out);
|
|
|
|
void unescape_registry_key(const char *in, strbuf *out);
|
2003-08-21 19:48:45 +00:00
|
|
|
|
2019-02-20 06:54:51 +00:00
|
|
|
bool is_console_handle(HANDLE);
|
|
|
|
|
2017-04-03 19:30:18 +00:00
|
|
|
/* A few pieces of up-to-date Windows API definition needed for older
|
|
|
|
* compilers. */
|
|
|
|
#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
|
|
|
|
#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
|
|
|
|
#endif
|
|
|
|
#ifndef LOAD_LIBRARY_SEARCH_USER_DIRS
|
|
|
|
#define LOAD_LIBRARY_SEARCH_USER_DIRS 0x00000400
|
|
|
|
#endif
|
|
|
|
#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
|
|
|
|
#define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100
|
|
|
|
#endif
|
2017-05-24 19:34:38 +00:00
|
|
|
#ifndef DLL_DIRECTORY_COOKIE
|
2017-04-03 19:30:18 +00:00
|
|
|
typedef PVOID DLL_DIRECTORY_COOKIE;
|
2017-05-24 19:34:38 +00:00
|
|
|
DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory);
|
2017-04-03 19:30:18 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-07 16:45:23 +00:00
|
|
|
/*
|
|
|
|
* Exports from sizetip.c.
|
|
|
|
*/
|
|
|
|
void UpdateSizeTip(HWND src, int cx, int cy);
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
void EnableSizeTip(bool bEnable);
|
2002-10-07 16:45:23 +00:00
|
|
|
|
2003-01-01 22:25:25 +00:00
|
|
|
/*
|
|
|
|
* Exports from unicode.c.
|
|
|
|
*/
|
2003-01-15 16:16:36 +00:00
|
|
|
struct unicode_data;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
void init_ucs(Conf *, struct unicode_data *);
|
2003-01-01 22:25:25 +00:00
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
/*
|
|
|
|
* Exports from winhandl.c.
|
|
|
|
*/
|
2006-08-27 10:00:36 +00:00
|
|
|
#define HANDLE_FLAG_OVERLAPPED 1
|
|
|
|
#define HANDLE_FLAG_IGNOREEOF 2
|
2006-08-28 18:27:54 +00:00
|
|
|
#define HANDLE_FLAG_UNITBUFFER 4
|
2006-08-25 22:10:16 +00:00
|
|
|
struct handle;
|
2019-02-06 20:42:44 +00:00
|
|
|
typedef size_t (*handle_inputfn_t)(
|
|
|
|
struct handle *h, const void *data, size_t len, int err);
|
2019-02-06 20:36:11 +00:00
|
|
|
typedef void (*handle_outputfn_t)(
|
2019-02-06 20:42:44 +00:00
|
|
|
struct handle *h, size_t new_backlog, int err);
|
2006-08-26 07:41:15 +00:00
|
|
|
struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
|
2019-09-08 19:29:00 +00:00
|
|
|
void *privdata, int flags);
|
2006-08-26 07:41:15 +00:00
|
|
|
struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
|
2019-09-08 19:29:00 +00:00
|
|
|
void *privdata, int flags);
|
2019-02-06 20:42:44 +00:00
|
|
|
size_t handle_write(struct handle *h, const void *data, size_t len);
|
2011-09-13 11:44:03 +00:00
|
|
|
void handle_write_eof(struct handle *h);
|
2006-08-25 22:10:16 +00:00
|
|
|
void handle_free(struct handle *h);
|
2019-02-06 20:42:44 +00:00
|
|
|
void handle_unthrottle(struct handle *h, size_t backlog);
|
|
|
|
size_t handle_backlog(struct handle *h);
|
2006-08-26 07:41:15 +00:00
|
|
|
void *handle_get_privdata(struct handle *h);
|
2019-02-20 06:52:54 +00:00
|
|
|
/* Analogue of stdio_sink in marshal.h, for a Windows handle */
|
|
|
|
struct handle_sink {
|
|
|
|
struct handle *h;
|
|
|
|
BinarySink_IMPLEMENTATION;
|
|
|
|
};
|
|
|
|
void handle_sink_init(handle_sink *sink, struct handle *h);
|
2006-08-25 22:10:16 +00:00
|
|
|
|
Reorganise Windows HANDLE management.
Before commit 6e69223dc262755, Pageant would stop working after a
certain number of PuTTYs were active at the same time. (At most about
60, but maybe fewer - see below.)
This was because of two separate bugs. The easy one, fixed in
6e69223dc262755 itself, was that PuTTY left each named-pipe connection
to Pageant open for the rest of its lifetime. So the real problem was
that Pageant had too many active connections at once. (And since a
given PuTTY might make multiple connections during userauth - one to
list keys, and maybe another to actually make a signature - that was
why the number of _PuTTYs_ might vary.)
It was clearly a bug that PuTTY was leaving connections to Pageant
needlessly open. But it was _also_ a bug that Pageant couldn't handle
more than about 60 at once. In this commit, I fix that secondary bug.
The cause of the bug is that the WaitForMultipleObjects function
family in the Windows API have a limit on the number of HANDLE objects
they can select between. The limit is MAXIMUM_WAIT_OBJECTS, defined to
be 64. And handle-io.c was using a separate event object for each I/O
subthread to communicate back to the main thread, so as soon as all
those event objects (plus a handful of other HANDLEs) added up to more
than 64, we'd start passing an overlarge handle array to
WaitForMultipleObjects, and it would start not doing what we wanted.
To fix this, I've reorganised handle-io.c so that all its subthreads
share just _one_ event object to signal readiness back to the main
thread. There's now a linked list of 'struct handle' objects that are
ready to be processed, protected by a CRITICAL_SECTION. Each subthread
signals readiness by adding itself to the linked list, and setting the
event object to indicate that the list is now non-empty. When the main
thread receives the event, it iterates over the whole list processing
all the ready handles.
(Each 'struct handle' still has a separate event object for the main
thread to use to communicate _to_ the subthread. That's OK, because no
thread is ever waiting on all those events at once: each subthread
only waits on its own.)
The previous HT_FOREIGN system didn't really fit into this framework.
So I've moved it out into its own system. There's now a handle-wait.c
which deals with the relatively simple job of managing a list of
handles that need to be waited for, each with a callback function;
that's what communicates a list of HANDLEs to event loops, and
receives the notification when the event loop notices that one of them
has done something. And handle-io.c is now just one client of
handle-wait.c, providing a single HANDLE to the event loop, and
dealing internally with everything that needs to be done when that
handle fires.
The new top-level handle-wait.c system *still* can't deal with more
than MAXIMUM_WAIT_OBJECTS. At the moment, I'm reasonably convinced it
doesn't need to: the only kind of HANDLE that any of our tools could
previously have needed to wait on more than one of was the one in
handle-io.c that I've just removed. But I've left some assertions and
a TODO comment in there just in case we need to change that in future.
2021-05-24 12:06:10 +00:00
|
|
|
/*
|
|
|
|
* Exports from handle-wait.c.
|
|
|
|
*/
|
|
|
|
typedef struct HandleWait HandleWait;
|
|
|
|
typedef void (*handle_wait_callback_fn_t)(void *);
|
|
|
|
HandleWait *add_handle_wait(HANDLE h, handle_wait_callback_fn_t callback,
|
|
|
|
void *callback_ctx);
|
|
|
|
void delete_handle_wait(HandleWait *hw);
|
|
|
|
|
|
|
|
typedef struct HandleWaitList {
|
|
|
|
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
int nhandles;
|
|
|
|
} HandleWaitList;
|
|
|
|
HandleWaitList *get_handle_wait_list(void);
|
|
|
|
void handle_wait_activate(HandleWaitList *hwl, int index);
|
|
|
|
void handle_wait_list_free(HandleWaitList *hwl);
|
|
|
|
|
2020-01-01 15:55:06 +00:00
|
|
|
/*
|
|
|
|
* Exports from winpgntc.c.
|
|
|
|
*/
|
|
|
|
char *agent_named_pipe_name(void);
|
|
|
|
|
2006-08-28 10:35:12 +00:00
|
|
|
/*
|
|
|
|
* Exports from winser.c.
|
|
|
|
*/
|
2018-10-05 06:03:46 +00:00
|
|
|
extern const struct BackendVtable serial_backend;
|
2006-08-28 10:35:12 +00:00
|
|
|
|
2010-12-23 17:32:28 +00:00
|
|
|
/*
|
|
|
|
* Exports from winjump.c.
|
|
|
|
*/
|
|
|
|
#define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
|
|
|
|
void add_session_to_jumplist(const char * const sessionname);
|
|
|
|
void remove_session_from_jumplist(const char * const sessionname);
|
2010-12-26 20:00:45 +00:00
|
|
|
void clear_jumplist(void);
|
2018-11-03 08:28:35 +00:00
|
|
|
bool set_explicit_app_user_model_id(void);
|
2010-12-23 17:32:28 +00:00
|
|
|
|
2018-06-03 13:41:31 +00:00
|
|
|
/*
|
|
|
|
* Exports from winnoise.c.
|
|
|
|
*/
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 19:23:19 +00:00
|
|
|
bool win_read_random(void *buf, unsigned wanted); /* returns true on success */
|
2018-06-03 13:41:31 +00:00
|
|
|
|
2010-12-23 17:32:28 +00:00
|
|
|
/*
|
|
|
|
* Extra functions in winstore.c over and above the interface in
|
|
|
|
* storage.h.
|
|
|
|
*
|
|
|
|
* These functions manipulate the Registry section which mirrors the
|
|
|
|
* current Windows 7 jump list. (Because the real jump list storage is
|
|
|
|
* write-only, we need to keep another copy of whatever we put in it,
|
|
|
|
* so that we can put in a slightly modified version the next time.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Adds a saved session to the registry jump list mirror. 'item' is a
|
|
|
|
* string naming a saved session. */
|
|
|
|
int add_to_jumplist_registry(const char *item);
|
|
|
|
|
|
|
|
/* Removes an item from the registry jump list mirror. */
|
|
|
|
int remove_from_jumplist_registry(const char *item);
|
|
|
|
|
|
|
|
/* Returns the current jump list entries from the registry. Caller
|
|
|
|
* must free the returned pointer, which points to a contiguous
|
|
|
|
* sequence of NUL-terminated strings in memory, terminated with an
|
|
|
|
* empty one. */
|
|
|
|
char *get_jumplist_registry_entries(void);
|
|
|
|
|
2017-12-10 17:16:50 +00:00
|
|
|
/*
|
|
|
|
* Windows clipboard-UI wording.
|
|
|
|
*/
|
|
|
|
#define CLIPNAME_IMPLICIT "Last selected text"
|
|
|
|
#define CLIPNAME_EXPLICIT "System clipboard"
|
|
|
|
#define CLIPNAME_EXPLICIT_OBJECT "system clipboard"
|
|
|
|
/* These defaults are the ones PuTTY has historically had */
|
2018-10-29 19:50:29 +00:00
|
|
|
#define CLIPUI_DEFAULT_AUTOCOPY true
|
2017-12-10 17:16:50 +00:00
|
|
|
#define CLIPUI_DEFAULT_MOUSE CLIPUI_EXPLICIT
|
|
|
|
#define CLIPUI_DEFAULT_INS CLIPUI_EXPLICIT
|
|
|
|
|
2019-01-26 20:26:09 +00:00
|
|
|
/* In winmisc.c */
|
|
|
|
char *registry_get_string(HKEY root, const char *path, const char *leaf);
|
|
|
|
|
2020-02-07 19:15:13 +00:00
|
|
|
/* In wincliloop.c */
|
|
|
|
typedef bool (*cliloop_pre_t)(void *vctx, const HANDLE **extra_handles,
|
|
|
|
size_t *n_extra_handles);
|
|
|
|
typedef bool (*cliloop_post_t)(void *vctx, size_t extra_handle_index);
|
|
|
|
void cli_main_loop(cliloop_pre_t pre, cliloop_post_t post, void *ctx);
|
|
|
|
bool cliloop_null_pre(void *vctx, const HANDLE **, size_t *);
|
|
|
|
bool cliloop_null_post(void *vctx, size_t);
|
|
|
|
|
New application: a Windows version of 'pterm'!
This fulfills our long-standing Mayhem-difficulty wishlist item
'win-command-prompt': this is a Windows pterm in the sense that when
you run it you get a local cmd.exe running inside a PuTTY-style window.
Advantages of this: you get the same free choice of fonts as PuTTY has
(no restriction to a strange subset of the system's available fonts);
you get the same copy-paste gestures as PuTTY (no mental gear-shifting
when you have command prompts and SSH sessions open on the same
desktop); you get scrollback with the PuTTY semantics (scrolling to
the bottom gets you to where the action is, as opposed to the way you
could accidentally find yourself 500 lines past the end of the action
in a real console).
'win-command-prompt' was at Mayhem difficulty ('Probably impossible')
basically on the grounds that with Windows's old APIs for accessing
the contents of consoles, there was no way I could find to get this to
work sensibly. What was needed to make it feasible was a major piece
of re-engineering work inside Windows itself.
But, of course, that's exactly what happened! In 2019, the new ConPTY
API arrived, which lets you create an object that behaves like a
Windows console at one end, and round the back, emits a stream of
VT-style escape sequences as the screen contents evolve, and accepts a
VT-style input stream in return which it will parse function and arrow
keys out of in the usual way.
So now it's actually _easy_ to get this to basically work. The new
backend, in conpty.c, has to do a handful of magic Windows API calls
to set up the pseudo-console and its feeder pipes and start a
subprocess running in it, a further magic call every time the PuTTY
window is resized, and detect the end of the session by watching for
the subprocess terminating. But apart from that, all it has to do is
pass data back and forth unmodified between those pipes and the
backend's associated Seat!
That said, this is new and experimental, and there will undoubtedly be
issues. One that I already know about is that you can't copy and paste
a word that has wrapped between lines without getting an annoying
newline in the middle of it. As far as I can see this is a fundamental
limitation: the ConPTY system sends the _same_ escape sequence stream
for a line that wrapped as it would send for a line that had a logical
\n at what would have been the wrap point. Probably the best we can do
to mitigate this is to adopt a different heuristic for newline elision
that's right more often than it's wrong.
For the moment, that experimental-ness is indicated by the fact that
Buildscr will build, sign and deliver a copy of pterm.exe for each
flavour of Windows, but won't include it in the .zip file or in the
installer. (In fact, that puts it in exactly the same ad-hoc category
as PuTTYtel, although for completely different reasons.)
2021-05-08 16:24:13 +00:00
|
|
|
extern const struct BackendVtable conpty_backend;
|
|
|
|
|
|
|
|
/* Functions that parametrise window.c between PuTTY and pterm */
|
2021-05-08 16:20:50 +00:00
|
|
|
void gui_term_process_cmdline(Conf *conf, char *cmdline);
|
|
|
|
const struct BackendVtable *backend_vt_from_conf(Conf *conf);
|
|
|
|
const wchar_t *get_app_user_model_id(void);
|
|
|
|
/* And functions in window.c that those files call back to */
|
|
|
|
char *handle_restrict_acl_cmdline_prefix(char *cmdline);
|
|
|
|
bool handle_special_sessionname_cmdline(char *cmdline, Conf *conf);
|
|
|
|
bool handle_special_filemapping_cmdline(char *cmdline, Conf *conf);
|
|
|
|
|
2021-04-18 06:58:27 +00:00
|
|
|
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|