1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-02 22:02:25 +03:00
Commit Graph

265 Commits

Author SHA1 Message Date
24503cb9e1 example: restore sys/time.h for AIX
In AIX, `time.h` header file doesn't have definitions like
`fd_set`, `struct timeval`, which are found in `sys/time.h`.

Add `sys/time.h` to files affected when available.

Regression from e53aae0e16 #1001.

Reported-by: shubhamhii on GitHub
Assisted-by: shubhamhii on GitHub
Fixes #1334
Fixes #1335
Closes #1340
2024-03-29 09:12:10 +00:00
c0f69548be session: add libssh2_session_callback_set2()
Add new `libssh2_session_callback_set2()` API that deprecates
`libssh2_session_callback_set()`.

The new implementation offers the same functionality, but accepts and
returns a generic function pointer (of type `libssh2_cb_generic *`), as
opposed to the old function that used data pointers (`void *`). The new
solution thus avoids data to function (and vice versa) pointer
conversions, which has undefined behaviour in standard C.

About the name: It seems the `*2` suffix was used in the past for
replacement functions for deprecated ones. Let's stick with that.
`*_ex` was preferred for new functions that extend existing ones with
new features.

Closes #1285
2023-12-18 15:02:17 +00:00
3ec53f3ea2 build: enable -pedantic-errors
According to the manual, this isn't the same as `-Werror -pedantic`.
Enable it together with `-Werror`.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-pedantic-errors-1

This option results in autotools feature detection going into crazies.
To avoid this, we add it to `CFLAGS` late. Idea copied from curl.

This option has an effect only with gcc 5.0 and newer as of this commit.
Let's enable it for clang and older versions too for simplicity. Ref:
d5c0351055
https://github.com/curl/curl/pull/2747

Closes #1286
2023-12-17 15:15:34 +00:00
94b6bad3c8 example, tests: call WSACleanup() for each WSAStartup()
On Windows.

Closes #1283
2023-12-13 01:28:14 +00:00
28dbf01667 add portable LIBSSH2_SOCKET_CLOSE() macro
Add `LIBSSH2_SOCKET_CLOSE()` to the public `libssh2.h` header, for user
code. It translates to `closesocket()` on Windows and `close()` on other
platforms.

Use it in example code.

It makes them more readable by reducing the number of `_WIN32` guards.

Closes #1278
2023-12-08 11:19:04 +00:00
3f60ccb76b example: use libssh2_socket_t in X11 example
Cherry-picked from #1277
2023-12-08 02:01:18 +00:00
2e5a8719d7 tidy-up: bump casts from int to long for large C99 types in printfs
Cast large integer types to avoid dealing with printf masks for
`size_t` and other C99 types. Some of existing code used `int`
for this, bump them to `long`.

Ref: afa6b86560 #1257

Closes #1264
2023-12-04 13:11:28 +00:00
afa6b86560 build: enable missing OpenSSF-recommended warnings, with fixes
Ref:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
(2023-11-29)

Enable new warnings:

- replace `-Wno-sign-conversion` with `-Wsign-conversion`.

  Fix them in example, tests and wincng. There remain about 360 of these
  warnings in `src`. Add a TODO item for those and disable `-Werror` for
  this particular warning.

- enable `-Wformat=2` for clang (in both cmake and autotools).

- enable `__attribute__((format))` for `_libssh2_debug()`,
  `_libssh2_snprintf()` and in tests for `run_command()`.

  `LIBSSH2_PRINTF()` copied from `CURL_TEMP_PRINTF()` in curl.

- enable `-Wimplicit-fallthrough`.

- enable `-Wtrampolines`.

Fix them:

- src: replace obsolete fall-through-comments with
  `__attribute__((fallthrough))`.

- wincng: fix `-Wsign-conversion` warnings.

- tests: fix `-Wsign-conversion` warnings.

- example: fix `-Wsign-conversion` warnings.

- src: fix `-Wformat` issues in trace calls.

  Also, where necessary fix `int` and `unsigned char` casts to
  `unsigned int` and adjust printf format strings. These were not
  causing compiler warnings.

  Cast large types to `long` to avoid dealing with printf masks for
  `size_t` and other C99 types. Existing code often used `int` for this.
  I'll update them to `long` in an upcoming commit.

- tests: fix `-Wformat` warning.

- silence `-Wformat-nonliteral` warnings.

- mbedtls: silence `-Wsign-conversion`/`-Warith-conversion`
  in external header.

Closes #1257
2023-12-03 01:32:20 +00:00
744e059f31 example, tests: fix/silence -Wformat-truncation=2 gcc warnings
Then sync this warning option with curl.

Seems like a false positive and/or couldn't figure how to fix it, so silence:
```
example/ssh2.c:227:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                      ^~
example/ssh2.c:227:34: note: assuming directive output of 1 byte
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                  ^~~~~~~
example/ssh2.c:227:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example/ssh2.c:228:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                      ^~
example/ssh2.c:228:34: note: assuming directive output of 1 byte
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                  ^~~~~~~
example/ssh2.c:228:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205970397#step:10:98

Fix:
```
tests/openssh_fixture.c:116:38: error: ' 2>&1' directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Werror=format-truncation=]
tests/openssh_fixture.c:116:11: note: 'snprintf' output between 6 and 1029 bytes into a destination of size 1024
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205969221#step:10:51

Tested via #1257
2023-12-01 13:31:47 +00:00
2e57dcb9d2 example: fix indentation follow-up
Fix long line and fix more indentations.

Follow-up to 9e896e1b80
2023-12-01 13:02:11 +00:00
9e896e1b80 example: fix indentation
Tested via #1257
2023-12-01 12:18:01 +00:00
8d69e63db9 example: replace remaining libssh2_scp_recv with libssh2_scp_recv2 in output messages (#1258)
libssh2_scp_recv is deprecated and has been replaced by libssh2_scp_recv2
in prior commit.

Follow-up to 6c84a426be
2023-12-01 04:52:12 +01:00
0c9a8e3590 ci: add OpenBSD (v7.4) job + fix build error in example
- Use CMake, LibreSSL and clang from the base install.

- This uncovered a build error in `example/subsystem_netconf.c`, caused
  by using the `%n` printf mask. This is a security risk and some
  systems (notably OpenBSD) disable this feature.

  Fix it by applying this patch from OpenBSD ports (from 2021-09-11):
  https://cvsweb.openbsd.org/ports/security/libssh2/patches/patch-example_subsystem_netconf_c?rev=1.1&content-type=text/x-cvsweb-markup
  2c5b2f3e94
  "The old code is also broken, as it passes a pointer to a variable
  of a different size (on LP64).  There is no check for truncation,
  but buf[] is 1MB in size."
  Patch-by: naddy

  ```
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:252:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:270:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  2 errors generated.
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/6991449778/job/19022024280#step:3:420

Also made tests with arm64, but it takes consistently almost 14m to
finish the job, vs. 2-3m for the native amd64:
https://github.com/libssh2/libssh2/actions/runs/6991648984/job/19022440525
https://github.com/libssh2/libssh2/actions/runs/6991551220/job/19022233651

Cherry-picked from #1250
Closes #1250
2023-11-26 10:16:56 +00:00
c6589b8823 stop using leading underscores in macro names
Underscored macros are reserved for the compiler / standard lib / etc.
Stop using them in user code.

We used them as header guards in `src` and in `__FILESIZE` in `example`.

Closes #1248
2023-11-25 13:09:27 +00:00
6fbc9505d8 windows: use built-in _WIN32 macro to detect Windows
Instead of `WIN32`.

The compiler defines `_WIN32`. Windows SDK headers or build env defines
`WIN32`, or we have to take care of it. The agreement seems to be that
`_WIN32` is the preferred practice here.

Minor downside is that CMake uses `WIN32` and we also adopted it in
`Makefile.mk`.

In public libssh2 headers we stick with accepting either `_WIN32` or
`WIN32` and define our own namespaced `LIBSSH2_WIN32` based on them.

grepping for `WIN32` remains useful to detect Windows-specific code.

Closes #1195
2023-09-29 19:15:08 +00:00
4a64ca1430 cmake: tidy-up foreach() syntax
Use `IN LISTS` and `IN ITEMS`. This appears to be the preferred way
within CMake's own source code and possibly improves readability.

Fixup a side-effect of `IN LISTS`, where it retains empty values at
the end of the list, as opposed to the syntax used before, which
dropped it. In our case this happened with lines read from a text
file via `file(READ)`.

https://cmake.org/cmake/help/v3.7/command/foreach.html

Closes #1180
2023-08-28 22:57:02 +00:00
3fa5282d62 cmake: style tidy up
- quote text literals to improve readability.
  (exceptions: `FILES` items, `add_subdirectory` names, `find_package`
  names, literal target names, version numbers, 0/1, built-in CMake
  values and CMake keywords, list items in `cmake/max_warnings.cmake`)
- quote standalone variables that could break syntax on empty values.
- replace `libssh2_SOURCE_DIR` with `PROJECT_SOURCE_DIR`.
- add missing mode to `message()` call.
- `TRUE`/`FALSE` → `ON`/`OFF`.
- add missing default value `OFF` to `option()` for clarity.
- unfold some lines.
- `INSTALL_CMAKE.md` fixes and updates. Show defaults.

Closes #1166
2023-08-15 15:08:30 +00:00
2fdc10ba04 cmake: formatting [ci skip] 2023-07-25 08:38:54 +00:00
279a2e57e5 example: fix regression in ssh2_exec.c
Regression from b13936bd6a #861 #846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes #1105
Closes #1106
2023-06-25 16:48:49 +00:00
f6aa31f48f provide SPDX identifiers
- All files have prominent copyright and SPDX identifier
- If not embedded in the file, in the .reuse/dep5 file
- All used licenses are in LICENSES/ (not shipped in tarballs)
- A new REUSE CI job verify that all files are OK

Assisted-by: Viktor Szakats

Closes #1084
2023-06-07 08:18:55 +02:00
187d89bb07 copyright: remove years from copyright headers
Also:
- uppercase `(C)`.
- add missing 'All rights reserved.' lines.
- drop duplicate 'Author' lines.
- add copyright headers where missing.
- enable copyright header check in checksrc.

Reasons for deleting years (copied as-is from curl):
- they are mostly pointless in all major jurisdictions
- many big corporations and projects already don't use them
- saves us from pointless churn
- git keeps history for us
- the year range is kept in COPYING

Closes #1082
2023-06-04 19:19:16 +00:00
003fb454c3 tidy-up: avoid exclamations, prefer single quotes, in outputs
Closes #1079
2023-06-03 12:51:56 +00:00
e7a542da6a add copyright/credits
Closes #1050
2023-05-29 17:07:11 +00:00
7129ea9ca8 cmake: add and test "unity" builds
"Unity" (aka "jumbo", aka "amalgamation" builds concatenate source files
before compiling. It has these benefits for example: faster builds,
improved code optimization, cleaner code. Let's support and test this.

- enable unity builds for some existing CI builds to test this build
  scenario.
- tune `UNITY_BUILD_BATCH_SIZE` size.
- disable unity build for example and test programs (they use one source
  each already).

You can enable it by passing `-DCMAKE_UNITY_BUILD=ON` to cmake.
Supported by CMake 3.16 and newer.

Ref: https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html

Closes #1034
2023-05-07 10:03:20 +00:00
fc003d4dc3 tidy-up: formatting nits
Whitespace and redundant parenthesis in `return`s.

Closes #1029
2023-05-04 20:16:28 +00:00
8270633eeb example, tests: fix ssh2 to correctly return failure
Before this patch ssh2 and test_ssh2 returned success even if the session
failed at `libssh2_session_handshake()` or after.

This patch depends on cda41f7cb8, that fixed
running test_ssh2 on Windows via sshd_fixture.

Cherry-picked from #1017
2023-05-03 13:07:13 +00:00
612ca85aaa cmake: use shared libs again in example and tests
Re-sync with autotools and v1.10.0 behavior.

This improves build times. It also allows to stop building our special
shared test target to test shared builds.

Follow-up to 4e2580628d

Cherry-picked from #1017
Closes #1022
2023-05-03 12:30:43 +00:00
d70919fb00 example, test_ssh2: shutdown socket before close
Syncing them with `tests/session_fixture.c`.

Cherry-picked from #1017
2023-05-03 12:26:28 +00:00
a683133dfe tidy-up: C header use
- drop unused or duplicate C headers.
- add missing ones (that worked by chance).
  (`string.h`, `stdlib.h`)
- mention the functions that need certain headers.
- move some headers from crypto header to crypto C source.
- reorder headers in some places.
- simplify the #if tree for `sys/select.h` in `libssh2_priv.h`.
- move scp-specific macros next to their header to `scp.c`
  Follow-up to 5db836b2a8

Closes #999
2023-04-27 14:27:17 +00:00
d67aaaffc4 tidy-up: text nits, English contractions [ci skip]
In input/output text and docs mostly.
2023-04-27 14:19:03 +00:00
e53aae0e16 tidy-up: gettimeofday() fallback and use
Simplify the way we handle `gettimeofday()` fallback for platforms
without native support or without any support. Make it similar to
how we handle `snprintf()`.

In case of no native `gettimeofday()` support and a non-Windows
platform, our local fallback returns zero in `tv_usec` and `tv_sec`,
ending up with a zero `timeout_remaining` in `session.c`, same as
before this patch.

Also:
- drop unused `sys/time.h` headers.
- fix our fallback code to compile with any Windows compilers
  (not just MSVC)
- delete unnecessary casts.

Closes #1001
2023-04-26 00:52:19 +00:00
17801d2064 tidy-up: fix more nits
- fix indentation errors.
- reformat `cmake/FindmbedTLS.cmake`
- replace a macro with a variable in `example/sftp_RW_nonblock.c`.
- delete macOS macro `_DARWIN_USE_64_BIT_INODE` from the
  OS/400 config header, `os400/libssh2_config.h`.
- fix other minor nits.

Closes #983
2023-04-18 08:41:20 +00:00
803f19f004 cmake: dedupe setting -DHAVE_CONFIG_H
Move `libssh2_config.h` generation and setting `-DHAVE_CONFIG_H` to
the root `CMakeFile.txt`.

Also move symbol hiding setup there. It needs to be done before
generating the config file for `LIBSSH2_API` value to be set in it.

After this change the `HIDE_SYMBOLS` setting is accepted without an
annoying CMake warning when not actually building a shared libssh2 lib.

Closes #981
2023-04-18 08:20:05 +00:00
9ecb22daab tests: build improvements and more
- rename tests to have more succint names and a more useful natural
  order.

- rename `simple` and `ssh2` in tests to have the `test_` prefix.

  This avoids a name collisions with `ssh2` in examples.

- cmake: drop the `example-` prefix for generated examples.

  Bringing their names in sync with other build tools, like autotools.

- move common auth test code into the fixture and simplify tests by
  using that.

- move feature guards from CMake to preprocessor for auth tests.

  Now it works with all build tools and it's easier to keep it in sync
  with the lib itself.

  For this we need to include `libssh2_priv.h` in tests, which in turn
  needs tweaking on the trick we use to suppress extra MSVS warnings
  when building tests and examples.

- move mbedTLS blocklist for crypto tests from CMake to the test
  fixture.

- add ed25519 hostkey tests to `test_hostkey` and `test_hostkey_hash`.

- add shell script to regenerate all test keys used for our tests.

- alpha-sort tests.

- rename `signed_*` keys to begin with `key` like the rest of the keys
  do.

- whitespace fixes.

Closes #969
2023-04-16 22:50:01 +00:00
1b0c93b755 checksrc: fix NOTEQUALSZERO warnings
Closes #963
2023-04-14 19:16:27 +00:00
2efdb6747a tidy-up: example, tests continued
- fix skip auth if `userauthlist` is NULL.
  Closes #836 (Reported-by: @sudipm-mukherjee on github)
- fix most silenced `checksrc` warnings.
- sync examples/tests code between each other.
  (output messages, error handling, declaration order, comments)
- stop including unnecessary headers.
- always deinitialize in case of error.
- drop some redundant variables.
- add error handling where missing.
- show more error codes.
- switch `perror()` to `fprintf()`.
- fix some `printf()`s to be `fprintf()`.
- formatting.

Closes #960
2023-04-14 11:07:53 +00:00
f4f5841dd5 example/ssh2_exec: drop conditional code for deprecated API 2023-04-13 15:55:26 +02:00
ec0feae792 build: speed up and extend picky compiler options
Implement picky warnings with clang in autotools. Extend picky gcc
warnings, sync them between build tools and compilers and greatly
speed up detection in CMake.

- autotools: enable clang compiler warnings with `--enable-debug`.

- autotools: enable more gcc compiler warnings with `--enable-debug`.

- autotools/cmake: sync compiler warning options between gcc and clang.

- sync compiler warning options between autotools and cmake.

- cmake: reduce option-checks to speed up the detection phase.
  Bring them down to 3 (from 35). Leaving some checks to keep the
  CMake logic alive and for an easy way to add new options.

  clang 3.0 (2011-11-29) and gcc 2.95 (1999-07-31) now required.

- autotools logic copied from curl, with these differences:

  - delete `-Wimplicit-fallthrough=4` due to a false positive.

  - reduce `-Wformat-truncation=2` to `1` due to a false positive.

  - simplify MinGW detection for `-Wno-pedantic-ms-format`.

- cmake: show enabled picky compiler options (like autotools).

- cmake: do compile `tests/simple.c` and `tests/ssh2.c`.

- fix new compiler warnings.

- `tests/CMakeLists.txt`: fix indentation.

Original source of autotools logic:
- a8fbdb461c/acinclude.m4
- a8fbdb461c/m4/curl-compilers.m4

Notice that the autotools implementation considers Apple clang as
legacy clang 3.7. CMake detection works more accurately, at the same
time more error-prone and difficult to update due to the sparsely
documented nature of Apple clang option evolution.

Closes #952
2023-04-13 11:12:22 +00:00
4f0f4bff5a build: unify source lists
- introduce `src/crypto.c` as an umbrella source that does nothing else
  than include the selected crypto backend source. Moving this job from
  the built-tool to the C preprocessor.

- this allows dropping the various techniques to pick the correct crypto
  backend sources in autotools, CMake and other build method. Including
  the per-backend `Makefile.<crypto-backend>.inc` makefiles.

- copy a trick from curl and instead of maintaining duplicate source
  lists for CMake, convert the GNU Makefile kept for autotools
  automatically. Do this in `docs`, `examples` and `src`.

  Ref: dfabe8bca2/CMakeLists.txt (L1399-L1413)

  Also fixes missing `libssh2_setup.h` from `src/CMakeFiles.txt` after
  59666e03f0.

- move `Makefile.inc` from root to `src`.

- reformat `src/Makefile.inc` to list each source in separate lines,
  re-align the continuation character and sort the lists alphabetically.

- update `docs/HACKING-CRYPTO` accordingly.

- autotools: update the way we add crypto-backends to `LIBS`.

- delete old CSV headers, indent, and merge two lines in
  `docs/Makefile.am` and `src/Makefile.am`.

- add `libssh2.pc` to `.gitignore`, while there.

Closes #941
2023-04-10 09:20:13 +00:00
fb9f888308 tidy-up: example, tests
- drop unnecessary `WIN32`-specific branches.

- add `static`.

- sync header inclusion order.

- sync some common code between examples/tests.

- fix formatting/indentation.

- fix some `checksrc` errors not caught by `checksrc`.

Closes #936
2023-04-08 22:26:10 +00:00
dfb086bfe2 tidy-up: indentation in guarded #includes [ci skip] 2023-04-08 10:56:14 +00:00
59666e03f0 build: hand-crafted config rework & header tidy-up
- 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
2023-04-07 23:44:43 +00:00
4048d0ba26 example/x11: Add null-termination (#749) 2023-04-05 16:23:54 +02:00
202a4f3f7a build: MSVS warning suppression option tidy-up
- 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
2023-04-04 00:03:33 +00:00
2e3e0be816 ci: add MSVS 2008/2010 build tests and fix warnings
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/08t5ktvkcgdghp7r

Closes #925
2023-04-03 12:08:50 +00:00
cab599120c delete redundant HAVE_STDLIB_H
libssh2 used this standard C89 header unconditionally before this patch.

Delete the feature checks and all unnecessary header guards.

Closes #913
2023-04-01 23:41:07 +00:00
eb236329c4 delete redundant HAVE_WINSOCK2_H
`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.
2023-04-01 19:32:08 +02:00
d245c66cc0 example: make x11 exclusion build-tool-agnostic
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
2023-04-01 01:36:54 +00:00
91af53851d .gitignore updates [ci skip] 2023-03-31 23:45:36 +00:00
9aa1964dfb tidy-up: whitespace, sorting, comment and naming fixups 2023-03-31 23:46:06 +02:00