- introduce the concept of a project level setup header
`src/libssh2_setup.h`, that is used by `src`, `example` and `tests`
alike. Move there all common platform/compiler configuration from
`src/libssh2_priv.h`, individual sources and `CMakeFiles.txt` files.
Also move there our hand-crafted (= not auto-generated by CMake or
autotools) configuration `win32/libssh2-config.h`.
- `win32` directory is empty now, delete it.
- `Makefile.mk`: adapt to the above. Build-directory is the target
triplet, or any custom name set via `BLD_DIR`.
- sync header path order between build systems:
build/src -> source/src -> source/include
- delete redundant references to `windows.h`, `winsock2.h`,
`ws2tcpip.h`.
- delete unnecessary #includes, update order (`libssh2_setup.h` first,
`winsock2.h` first), simplify where possible.
This makes the code warning-free without `WIN32_LEAN_AND_MEAN`.
At the same time this patch applies this macro globally, to avoid
header bloat.
- example: add missing *nix header guards.
- example: fix misindented `HAVE_UNISTD_H` `#ifdef`s.
- set `WIN32` with all build-tools.
- set `HAVE_SYS_PARAM_H` in the hand-crafted config for MinGW.
To match auto-detection.
- move a source-specific macro to `misc.c` from `libssh2_priv.h`.
See the PR's individual commits for step-by-step updates.
Closes#932
- use `example` target for building examples (was: `test`).
- add support for building tests via the `test` target.
- accept lib-only options in a new `LIBSSH2_CPPFLAGS_LIB` variable.
Useful to pass `-DLIBSSH2_EXPORTS` for correct `dllexport` in
`libssh2.dll`.
- fix to put dynamic library in lib directory for non-Windows builds
- fix to not delete lib objects on `testclean`
Instead of overriding `main()`. To align with the other tests.
Overriding `main()` can cause duplicate symbols without using a lib for
the `runner` code.
Follow-up to 40ac6b230aCloses#934
This set of changes provides a mechanism to runtime-configure the
previously #define'd timeout for reading packets from a session. The
intention here is to also extend libcurl to be able to use this
interface so that when fetching from sftp servers which are very slow
to return directory listings, connections do not time-out so much.
* Add new field to session to hold configurable read timeout
* Updated `_libssh2_packet_require()`, `_libssh2_packet_requirev()`,
and `sftp_packet_requirev()` to use new field in session structure
* Updated docs for API functions to set/get read timeout field in
session structure
* Updated `libssh2.h` to declare the get/set read timeout functions
Co-authored-by: Jon Axtell <jon.axtell@codethink.co.uk>
Credit: Daniel Silverstone
Move the GNU Make file formerly known as `win32/GNUmakefile` to the
root directory from `win32`. It now supports any platform with a
GCC-like toolchain, while also keeping support for win32.
For non-Windows platforms it's necessary to provide a hand-crafted
`libssh2_config.h` header for now.
Usage: `make -f Makefile.mk`
- in `win32/libssh2_config.h` replace `_CRT_SECURE_NO_DEPRECATE` with
`_CRT_SECURE_NO_WARNINGS`, to use the official macro for this, like
in CMake.
Also, it's now safe to move it back under `_MSC_VER`.
Suppressing:
`warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.`
`warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.`
- move `_CRT_NONSTDC_NO_DEPRECATE` to `example` and `tests`.
Not needed for `src`.
Suppressing:
`warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.`
`warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _write.`
- move `_WINSOCK_DEPRECATED_NO_WARNINGS` from source files to
CMake files, in `example` and `tests`. Also limit this to MSVC.
Suppressing:
`warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead`
TODO: try fixing these instead of suppressing.
Closes#929
- add `BLD_DIR` to customize the output directory (where libs, .zip,
obj subdir will go). This directory must exist.
It remains `./win32` for Windows builds.
- add `CONFIG_H_DIR` option to customize `libssh2_config.h` location.
It remains `./win32` for Windows builds.
- include `.def` in distro zip for Windows.
- ready to move to the root directory.
Replace incorrect `MD5_DIGEST_LENGTH` with `SHA_DIGEST_LENGTH` for these
hostkey algos:
- `ssh-rsa` and `ssh-dss`
Ref: 7a5ffc8cee (2004-12-07 Initial)
- `ssh-rsa-cert-v01@openssh.com`
Ref: 4b21e49d9d (2022-07-28)
Ref: #710
Also delete local fall-back definition of `MD5_DIGEST_LENGTH` (added
in 9af7eb48dc). Macro is no longer used.
Reported-by: Markus-Schmidt on github
Fixes#919Closes#926
Also:
- fix newly surfaced (bogus) warnings in examples with MSVS 2010:
```
..\..\example\direct_tcpip.c(262): warning C4127: conditional expression is constant
```
Happens for every `FD_SET()` macro reference.
Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46677835/job/ni4hs97bh18c14ap
- silence MSVS 2010 predefined Windows macro warnings:
```
..\..\src\wincng.c(867): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
..\..\src\wincng.c(897): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
..\..\src\wincng.c(1132): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
```
Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46678071/job/08t5ktvkcgdghp7rCloses#925
Rename `RANDOM_PADDING` macro used internally to enable some code.
Committed in the initial version of `transport.c` in
9d55db6501 (2007-02-02). libssh2 code
never defined it.
The name happens to collide with a Windows macro in `wincrypt.h`.
`transport.c` doesn't include this header, but it includes `winsock2.h`,
and it turns out it can also define this macro in some cases, e.g.
when `WIN32_LEAN_AND_MEAN` is not set.
To be on the safe side, prefix the name with `LIBSSH2_` to avoid
enabling it by accident.
Q: Maybe it'd be best to delete it with the guarded code?
Reported-by: Markus-Schmidt on github
Fixes#921Closes#924
The `DLL_EXPORT` macro is automatically set by autotools when building
the libssh2 DLL. Certain toolchains might require this to correctly
export symbols, so make sure to respect it in `libssh2.h` to enable
`declspec(dllexport)`.
With this patch we have a manual macro for that (`LIBSSH2_EXPORT`),
this autotools one, the CMake one, and `_WINDLL` (added in
c355d31ff9), possibly defined by Visual
Studio.
Closes#917
libssh2 uses `wincrypt.h` aka the `crypt32` Windows system library
for the function `CryptDecodeObjectEx()` [1]. This function has been
available for Win32 (and UWP/WinRT apps) for a long while. Even old
MinGW supports it, and also Watcom 1.9, of the rare/old compilers
I checked.
CMake had it permanently enabled, while it also did an extra check
for the header to add the lib to the lib list. Autotools did the
detection proper. Other builds had it permanently enabled.
It seems safe to assume this function/header/lib is available in all
environments we support.
In this patch we simplify by deleting these detections and feature
flags from all build tools.
Keep the feature flag internal to `wincng.h`, and for extra safety add
the new macro `LIBSSH2_WINCNG_DISABLE_WINCRYPT` do disable it via
custom `CPPFLAGS`.
WinCNG's other requirement is `bcrypt`. That also has been universally
available for a long time. Here the only known outlier is old/legacy
MinGW, which is missing support.
[1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptdecodeobjectexCloses#916
Instead of maintaining a second copy of `libssh2.pc.in` in `src` just
for CMake, teach CMake to use the existing template in the root dir,
that we already use with autotools.
Closes#914
`libssh2.h` required `winsock2.h` for `_WIN32` since
81d53de4dc (2011-06-04).
Apply that to the whole codebase. This makes it unnecessary to detect
`HAVE_WINSOCK2_H` and allows to drop all its uses.
Completes TODO from b66d7317ca
TODO: Straighten out the use a mixture of `HAVE_WINDOWS_H`,
`WIN32`, `_WIN32` to detect Windows.
- replace `OPENSSLINC` and `OPENSSLLIB` with `OPENSSL_PATH`.
Assume `include` and `lib` subdirs for headers and libs.
- replace `WITH_ZLIB`, `ZLIBINC` and `ZLIBLIB` with `ZLIB_PATH`.
Assume `include` and `lib` subdirs for header and lib.
- make WinCNG the default if `WITH_OPENSSL` is not set.
With 20-ish extra lines, make this Makefile support all GCC-like
toolchains.
The temporary directory becomes `<triplet>-{release|debug}` from
the former `{release|debug}`.
Also change the lib directory name in the `dist` package from
`win32` to `lib`, to match other packages and build tools.
It was used once in `src/libssh2_priv.h`, but without any effect.
The header included `ws2tcpip.h` twice, once guarded by
`HAVE_WS2TCPIP_H` and another time by `HAVE_WINSOCK2_H`.
Dedupe these to not use `HAVE_WS2TCPIP_H`. Then delete detection
of this feature from all build methods.
TODO: Replace `HAVE_WINSOCK2_H` with `_WIN32`/`WIN32`.
- enable `HAVE_LONGLONG` for MinGW and MSVC versions supporting it.
Necessary for `GNUmakefile`/`NMakefile` builds to create the same
binaries as CMake/autotools ones do.
- enable `HAVE_STDLIB_H`. It has been universally available on
Windows for a long time.
Fixes these clang-cl warnings:
```
src\wincng.c(444,5) : warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
free(buf);
^
src\wincng.c(491,20) : warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long long)' [-Wimplicit-function-declaration]
pbHashObject = malloc(dwHashObject);
^
src\wincng.c(491,20) : note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
src\wincng.c(2106,14) : warning: implicitly declaring library function 'realloc' with type 'void *(void *, unsigned long long)' [-Wimplicit-function-declaration]
bignum = realloc(bn->bignum, length);
^
src\wincng.c(2106,14) : note: include the header <stdlib.h> or explicitly provide a declaration for 'realloc'
3 warnings generated.
```
Whether to build the `x11` example or not was decided by each build
tool. CMake didn't build it even on supported platforms. GNUMakefile
used a specific blocklist for it, while autotools enabled it based on
feature-detection.
Migrate the enabler logic to an #ifdef in source and build `x11`
unconditionally with all build tools.
On unsupported platforms (=Windows) this program now displays a short
message stating that fact.
Also:
- fix `x11.c` warnings uncovered after CMake started building it.
- use `libssh2_socket_t` type for portability in `x11.c` too.
- use detected header guards in `x11.c`.
- delete a duplicate reference to `-lws2_32` from `win32/GNUmakefile`
while there.
Closes#909