Commit Graph

302 Commits

Author SHA1 Message Date
Viktor Szakats
578ee6b79b
gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings
Extend `#pragma diagnostic push`/`pop` guards to the whole codebase
(from tests and examples only) to disable it for GCC <4.6. Rename guard
to `CURL_HAVE_DIAG` and make it include llvm/clang to be interchangeable
with `__GNUC__ || __clang__` in this context.

The above means no longer disabling certain warnings locally, so pair
this with disabling all picky warnings for GCC <4.6.

Also:
- drop global workarounds for misbehaving GCC <4.6 compiler warnings.
  Not needed with picky warnings disabled.

Reported-by: fds242 on github
Reported-by: Sergey Fedorov
Thanks-to: Orgad Shaneh
Follow-up to f07a98ae11 #20366
Fixes #20892
Fixes #20924
Closes #20902
Closes #20907
2026-03-18 11:33:37 +01:00
Viktor Szakats
9d104f566f
ldap: drop duplicate ldap_set_option() on Windows
Already set after `ldap_sslinit()`/`ldap_init()` and before
`ldap_ssl`-specific initialization.

Follow-up to 39d1976b7f #19830
Follow-up to b41e65a8e3
Follow-up to b91421b107

Closes #20930
2026-03-16 13:18:45 +01:00
Viktor Szakats
6b0a885611
ldap: fix to initialize cleartext connection on Windows
Regression since curl 8.18.0.

Reported-by: Yoshiro Yoneya
Fixes #20927
Follow-up to 39d1976b7f #19830

Closes #20928
2026-03-16 11:30:45 +01:00
Stefan Eissing
eb14705280
protocol source, all about protocols and uri schemes
Add protocol.h and protocol.c containing all about libcurl's
known URI schemes and their protocol handlers (so they exist).

Moves the scheme definitions from the various sources files into
protocol.c. Schemes are known and used, even of the protocol
handler is not build or just not implemented at all.

Closes #20906
2026-03-16 08:39:02 +01:00
Stefan Eissing
da7bfb89a1
connection_check, simplified
The protocol handler method `connection_check` allowed to variable
operations to trigger with variable result bits. Only the `CONNCHECK_ISDEAD`
and `CONNRESULT_DEAD` were in use. Transform the function into
`connection_is_dead` without extra parameter and a bool result.

- Remove defines for `CONNCHECK_*` and `CONNRESULT_*`
- Rename protocol function in handler comments
- Change RTSP implementation (only protocol that uses this)

Closes #20890
2026-03-11 23:28:50 +01:00
Viktor Szakats
7a08c5d820
ldap: silence clang-tidy v22 warning
Closes #20762
2026-02-27 15:57:48 +01:00
Viktor Szakats
8712fac111
clang-tidy: drop redundant casts
Found via `readability-redundant-casting`. Prone to false positives, not
enabled.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-casting.html

Closes #20630
2026-02-19 15:27:17 +01:00
Viktor Szakats
61df5f466c
tidy-up: miscellaneous
- curl_ntlm_core, smtp, schannel: fix comments.
- curl_setup.h: fix to undef before define.
- tool_doswin, server/sockfilt: reduce variables scopes.
- tool_doswin: drop an interim variable.
- windows: replace `SOCKET_ERROR` with `0` to align with rest of code.
- libssh2: rename variable to align with rest of code.
- gtls, unit1398: use `#if 0`.
- curl_trc.h, curlx/inet_ntop.h: add missing parentheses in macro
  expressions.
- ldap.c: set empty macro to `do {} while(0)`.
- examples/crawler: rename a non-CURLcode `result` variable.
- CURLINFO_TLS_SESSION: drop stray colon.
- add `const` to casts where missing.
- drop unnecessary parentheses.
- fix indent.
- quote style.
- comment style.
- whitespace, newlines, fold/unfold.

Closes #20554
2026-02-12 14:52:16 +01:00
Viktor Szakats
2a92c39a21
windows: tidy up wincrypt.h / BoringSSL/AWS-LC coexist workaround
- openssl: move and expand explanatory comment.

- openssl: drop duplicate workaround.

- schannel: drop workaround. Unnecessary, because OpenSSL headers are
  not included in or after schannel code.

- schannel: drop explicit `wincrypt.h` include. It's indirectly
  included by system `<schannel.h>`.

- ldap: drop explicit `wincrypt.h` include.
  It isn't used there, and also not required for the workaround.
  `winldap.h` keeps including it indirectly.

Tested with BoringSSL and AWS-LC (MultiSSL with Schannel), also LDAP
enabled, and H3, unity and non-unity, and all tested cases build fine.

In lib in general, the point is to have the `#undef`s between the first
`wincrypt.h` include [1] and the first OpenSSL include [2], within a
single compilation unit. For non-unity builds the only such source is
`openssl.c`. For unity ones, depending on batch size, in theory we
should `#undef` after each `wincrypt.h` include. In practice this is
overkill and most cases are covered by `#undef`-fing _first_ in
`vtls/openssl.c`, and `#undef` in `ldap.c`. It's not impossible that we
need to add more undefs after further `wincrypt.h` includes to cover so
far undiscovered build cases [3]. Though I could not find more with the
current sources and source order.

It's also an option to include OpenSSL first, then `wincrypt.h`, as
done in libtests, but for lib and `vtls/openssl.c` it's more practical
to do the opposite.

[1] can be indirect, e.g. via `iphlpapi.h`, `schannel.h`, `winldap.h`.

[2] in
- BoringSSL/AWS-LC: any include (due to `openssl/base.h`).
  Original fix removed by BoringSSL in year
  [2014](ded93581f1 (diff-878093ea6426091505b4c49c59b78924f42859af0eb4ce39b8089bda9577e013)).
- OpenSSL: `openssl/ssl.h`, `openssl/x509v3.h`, and some more affected,
  and including `openssl/ossl_typ.h` does the `#undef` automatically.
  Since [3.1.0+](fbb9a1f997)
  each inclusion does the `#undef`, in 3.0.x (and earlier) only
  the first inclusion did. Initially fixed in
  [0.9.6d](1955b87423)
- LibreSSL [2.3.0+](0fa826d34f):
  not affected, though to suppress another warning 3.8.2+ and
  a [define](e7fe6caab2)
  is necessary.

[3] `lib/Makefile.inc` defines the order of unity sources.

For libtests, the case is simpler: There is always one compilation unit,
with a fixed order, and at the moment `cli_hx_download.c` is including
OpenSSL first, then wincrypt, and in this order they don't bother each
other. Also, at the moment `lib758.c` is the only other OpenSSL header
user, but it's compiled after `cli_hx_download.c` so the include is
skipped there. We may need to revisit this if either header gets
included before it.

All this said it'd be nice if BoringSSL/AWS-LC restored the built-in
workaround to behave like LibreSSL and OpenSSL and not require local
workarounds like these.

Ref: https://github.com/curl/curl/pull/20556#issuecomment-3888425644

Follow-up to 4c46c829f5 #9110
Follow-up to fbe07c6829 #5669 #5857

Closes #20567
2026-02-12 14:31:39 +01:00
Viktor Szakats
c220674ac4
windows: tidy up includes, macros, document dependencies
- define `SECURITY_WIN32` globally in `curl_setup.h`.
  To make sure it applies to all includes.

- document which Windows headers require `SECURITY_WIN32`.

- stop suppressing MSVC warning:
  `C4201 is: nonstandard extension used : nameless struct/union`
  The warning is no longer seen in supported build envs with the current
  codebase.
  Follow-up to 8beff43559 #8419

- document why `SCHANNEL_USE_BLACKLISTS` is needed.

- just define `SCHANNEL_USE_BLACKLISTS`, drop the unnecessary value `1`.

- stop defining unused `SCH_CRED_MAX_SUPPORTED*` fallback macros.
  Follow-up to 8beff43559 #8419

- document why `subauth.h` is included (where missing).

- move and de-dupe `subauth.h` include into `curl_setup.h`, limit to
  Schannel builds.

- stop include `schnlsp.h`. It is a 1-to-1 compatibility wrapper for
  `schannel.h`.

- curl_sspi.h: clarify comment about `SP_NAME_` macros.
  They are local macros, their SDK names are different and curl does not
  use them.

- curl_sspi.h: drop superfluous includes `security.h` and `rpc.h`.

Cherry-picked from #20556

Closes #20564
2026-02-11 16:15:11 +01:00
Viktor Szakats
9630593650
build: use more const
Mostly with `char *` types.

Also:
- mime, x509asn1, tool_operate, lib3207: drop redundant casts.
- examples/smooth-gtk-thread: add missing variable declaration.
- reduce variable scopes.
- tests/server: move `data_to_hex()` to its only user: `sws`.

Closes #20489
2026-02-02 12:32:49 +01:00
Daniel Stenberg
8edc0338f3
lib: separate scheme info from protocol implementation
This allows builds know about all schemes - but only have the protocol
implementations for those actually built-in.

It further allows multiple protocols to reuse the same protocol setup
and functions for both TLS and non-TLS implementations instead of
needing two (or more) structs.

The scheme information is now in 'struct Curl_scheme' and all the
function pointers for each scheme/protocol implementation are in struct
Curl_protocol.

The URL API now always work with all known protocols.

Closes #20351
2026-01-19 23:15:13 +01:00
Viktor Szakats
ea94afe318
ldap: silence potential unused variable warning (OS400)
Also:
- add `endif` comment.
- unfold a line.

Follow-up to 64350280d3 #20197

Closes #20302
2026-01-14 00:55:04 +01:00
Viktor Szakats
7d2c65e6ee
lib: reorder protocol functions to avoid forward declarations (misc cont.)
For protocols: ldap, openldap, rtmp, rtsp, telnet

Move protocol handler table to the end of sources, rearrange static
functions in reverse dependency order as necessary.

Closes #20289
2026-01-13 17:43:34 +01:00
Andrew
64350280d3
ldap: fix LDAP version display on IBMi
Fixes #20196
Closes #20197
2026-01-06 12:08:16 +01:00
Andrew
0343951cb5
ldap: fix Curl_ldap_version() for IBMi/OS400
- `LDAP_OPT_SUCCESS` (== 0) is missing from some LDAP implementations
  and documented to use `LDAP_SUCCESS` (== 0) instead. Use literal zero
  to avoid macro name differences.

- fix freeing `LDAP_OPT_API_INFO` buffers:
  - docs suggest `ldapai_vendor_name` on IBMi is `const char *`.
    Nothing in docs says it need to be freed.
  - `ldapai_extensions` need to be freed, according to docs.
    However, on IBMi there is `ldap_value_free()` function for it.
  Ref: https://www.ibm.com/docs/en/svd/10.0.3?topic=settings-ldap-opt-api-info

Fixing, on OS400 (V7R4M0):
```
CZM1003:  LDAP__819.c, 1028.56: CZM0045(30) Undeclared identifier LDAP_OPT_SUCCESS.
CZM1003:  LDAP__819.c, 1036.21: CZM0280(30) Function argument assignment between types "char*" and "const char*" is not allowed.
CZM1001:  LDAP__819.c, 1037.5: CZM0304(10) No function prototype given for "ber_memvfree".
...
CZS0601:  Module LDAP is not created because statement errors occurred.
```

Follow-up to 859ce48de1 #19832
Fixes #20188
Closes #20189
2026-01-05 23:10:47 +01:00
Viktor Szakats
7032982896
tidy-up: miscellaneous
- asyn-thrdd.c: scope an include.
- apply more clang-format suggestions.
- tidy-up PP guard comments.
- delete empty line from the top of headers.
- add empty line after `curl_setup.h` include where missing.
- fix indent.
- CODE_STYLE.md: add `strcpy`.
  Follow-up to 8636ad55df #20088
- lib1901.c: drop unnecessary line.
  Follow-up to 436e67f65b #20076

Closes #20070
2025-12-26 22:06:09 +01:00
Viktor Szakats
e8415a8296
lib: drop, or replace sendf.h with curl_trc.h where possible
- replace `sendf.h` with `curl_trc.h` where it was included just for it.
- drop unused `curl_trc.h` includes.
- easy: delete obsolete comment about `send.h` include reason.

Also:
- move out `curl_trc.h` include from `sendf.h` and include it directly
  in users, where not done already. To flatten the include tree and
  to less rely on indirect includes.
- stop including `sendf.h` from other headers, replace it with forward
  declaration of `Curl_easy`, as done already elsewhere.

Verified with an all non-unity CI run.

Closes #20061
2025-12-21 12:39:25 +01:00
Viktor Szakats
d11b8593a2
build: drop duplicate include curl/curl.h and others
- curl_range: replace `sendf.h` with direct header dependency
  `curl_trc.h`.
- drop `curl/curl.h` includes from internal sourcees in favor of the
  include made from `curl_setup.h`. Replace it with the latter where
  it's the only include.
- include `curl_setup.h` before using macros, where missing.
- drop redundant `stdlib.h`, `string.h` includes, in favor of
  `curl_setup_once.h` including them.
- drop redundant `limits.h` in favor of `curl_setup.h` including it.
- fake_addrinfo.h: fix typo in comment.
- curl_setup_once.h: drop `stdio.h` in favor of earlier include in
  `curl_setup.h`.
- drop stray, unused, `stddef.h` includes.
- memdebug.h: add missing `stddef.h` include. (relying on accidental
  includes via other headers before this patch.)
- stddef.h: document why it's included.
- strerr: drop `curl/mprintf.h` in favor of `curl/curl.h` including it
  via `curl_setup.h`.

Closes #20027
2025-12-19 10:58:11 +01:00
Viktor Szakats
fe8393d7db
tidy-up: miscellaneous
- drop stray duplicate empty lines in docs, scripts, test data, include,
  examples, tests.
- drop duplicate PP parenthesis.
- curl-functions.m4: move literals to the right side in if expressions,
  to match rest of the source code.
- FAQ.md: delete language designator from an URL.
- packages: apply clang-format (OS400, VMS).
- scripts/schemetable.c: apply clang-format.
- data320: delete duplicate empty line that doesn't change the outcome.
- spacecheck: extend to check for duplicate empty lines
  (with exceptions.)
- fix whitespace nits

Closes #19936
2025-12-12 04:18:48 +01:00
Viktor Szakats
0295c9401d
ldap: drop PP logic for old, unsupported, Windows SDKs
`LDAP_VENDOR_NAME` and `winber.h` are available in all supported
MS SDK and mingw-w64 versions. Stop checking for them.

Also drop redundant parenthesis in PP expression.

Closes #19918
2025-12-10 16:02:55 +01:00
Viktor Szakats
4e051ff550
curlx: limit use of system allocators to the minimum possible
Clone a multibye conversion function into curlx/fopen, and use that
local copy from curlx/fopen functions. Adjust allocators in curlx/fopen
to use curl's in normal builds, and system allocators in TrackMemory
builds to avoid recursion.

This allows to switch curlx/multibyte functions to curl allocators in
all configurations, as they are no longer called by curlx/fopen, and
a recursive call can no longer happen.

After this patch the system allocator is only used in TrackMemory
Windows builds, within curlx `fopen`, `freopen`, `stat` and `open`
functions.

Also:
- test 1, 440, 767: raise allocation limitsto fit the extra allocations
  in Windows Unicode builds.
- replace all uses of `curlx_unicodefree()` macro with `curlx_free()`
  across the codebase.
- curlx/multibyte: delete `curlx_unicodefree()`.
- ldap: join Windows and non-Windows codepaths that became
  identical after moving from `curlx_unicodefree()` to `curlx_free()`.
- vauth: drop a strdup from standard to curl allocator since
  the original allocation is now already done by curl's.
- tool_doswin: drop now superfluous strdup from `FindWin32CACert()`.
- memanalyzer.pm: sync weirdo `calloc` log message with `malloc`'s.

Fixes #19748
Closes #19845
2025-12-05 15:32:59 +01:00
Viktor Szakats
2d6ade19fc
ldap: improve detection of Apple LDAP
When detecting the Apple fork of "legacy" LDAP, replace the `__APPLE__`
macro (which can be present also when using an old mainline OpenLDAP
while building for an Apple platform) with `LDAP_OPT_X_TLS_PASSPHRASE`
which is an Apple-specific macro, merged by Apple in 2007, later adding
the comment 'Apple Specific code'. This macro hasn't been retrofitted
to OpenLDAP since then, and unlikely to happen in the future.

Refs:
c4d990a6cf (diff-0f7a5f85bae4de860b70aabf34aa12b0ecc37e748cd96e203e2d8ddb30a207c3R145)
49ac28a486 (diff-0f7a5f85bae4de860b70aabf34aa12b0ecc37e748cd96e203e2d8ddb30a207c3R166)

Follow-up to 859ce48de1 #19832
Closes #19849
2025-12-05 13:16:07 +01:00
Viktor Szakats
859ce48de1
ldap: detect version of "legacy" LDAP
Legacy LDAP means an OpenLDAP-compatible implementation
without the private API `ldap_init_fd()` introduced in OpenLDAP
2.4.6+ (2007-10-31), and not WinLDAP.

One known example is Apple's LDAP build, which is based on
OpenLDAP 2.4.28 (2011-11-25), without providing this private API.

The version query API was introduced around 1998-1999, before
the minimum (2.0 2000-08-01) required by curl.

Follow-up to 3e2a946926 #19808
Closes #19832
2025-12-04 23:14:01 +01:00
Viktor Szakats
0476e4fc65
tidy-up: one more round of formatting nits
Closes #19835
2025-12-04 19:30:59 +01:00
Patrick Monnerat
36542b7349
lib: turn state.url into a struct bufref
Closes #19827
2025-12-04 16:17:31 +01:00
Daniel Stenberg
39d1976b7f
ldap: call ldap_init() before setting the options
Closes #19830
2025-12-04 16:14:48 +01:00
Viktor Szakats
c3b030b860
lib: fix formatting nits (part 3)
From `lib/h` to `lib/w`.

part 1: 47a1ab2ebe #19764
part 2: 86b346443b #19800

Closes #19811
2025-12-03 14:50:16 +01:00
Daniel Stenberg
3e2a946926
ldap: provide version for "legacy" ldap as well
It displays in version output as WinLDAP and LDAP/1, compared to
OpenLDAP/[version] for the OpenLDAP backend code.

Closes #19808
2025-12-02 16:27:16 +01:00
Viktor Szakats
193cb00ce9
build: stop overriding standard memory allocation functions
Before this patch curl used the C preprocessor to override standard
memory allocation symbols: malloc, calloc, strdup, realloc, free.
The goal of these is to replace them with curl's debug wrappers in
`CURLDEBUG` builds, another was to replace them with the wrappers
calling user-defined allocators in libcurl. This solution needed a bunch
of workarounds to avoid breaking external headers: it relied on include
order to do the overriding last. For "unity" builds it needed to reset
overrides before external includes. Also in test apps, which are always
built as single source files. It also needed the `(symbol)` trick
to avoid overrides in some places. This would still not fix cases where
the standard symbols were macros. It was also fragile and difficult
to figure out which was the actual function behind an alloc or free call
in a specific piece of code. This in turn caused bugs where the wrong
allocator was accidentally called.

To avoid these problems, this patch replaces this solution with
`curlx_`-prefixed allocator macros, and mapping them _once_ to either
the libcurl wrappers, the debug wrappers or the standard ones, matching
the rest of the code in libtests.

This concludes the long journey to avoid redefining standard functions
in the curl codebase.

Note: I did not update `packages/OS400/*.c` sources. They did not
`#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning
the overrides were never applied to them. This may or may not have been
correct. For now I suppressed the direct use of standard allocators
via a local `.checksrc`. Probably they (except for `curlcl.c`) should be
updated to include `curl_setup.h` and use the `curlx_` macros.

This patch changes mappings in two places:
- `lib/curl_threads.c` in libtests: Before this patch it mapped to
  libcurl allocators. After, it maps to standard allocators, like
  the rest of libtests code.
- `units`: before this patch it mapped to standard allocators. After, it
  maps to libcurl allocators.

Also:
- drop all position-dependent `curl_memory.h` and `memdebug.h` includes,
  and delete the now unnecessary headers.
- rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other
  allocators.
- map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`).
  To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`.
- multibyte: map `curlx_convert_*()` to `_strdup()` on Windows
  (was: `strdup()`).
- src: do not reuse the `strdup` name for the local replacement.
- lib509: call `_strdup()` on Windows (was: `strdup()`).
- test1132: delete test obsoleted by this patch.
- CHECKSRC.md: update text for `SNPRINTF`.
- checksrc: ban standard allocator symbols.

Follow-up to b12da22db1 #18866
Follow-up to db98daab05 #18844
Follow-up to 4deea9396b #18814
Follow-up to 9678ff5b1b #18776
Follow-up to 10bac43b87 #18774
Follow-up to 20142f5d06 #18634
Follow-up to bf7375ecc5 #18503
Follow-up to 9863599d69 #18502
Follow-up to 3bb5e58c10 #17827

Closes #19626
2025-11-28 10:44:26 +01:00
Stefan Eissing
bbb929112b
curlx_base64_encode: use uint8_t* for input
Change `inputbuff` parameter from `const char *` to `const uint8_t *` to
reflect the binary nature of the input bytes. Half the code was casting
unsigned char to signed already in calling.

Closes #19722
2025-11-27 14:35:01 +01:00
Stefan Eissing
24b36fdd15
ratelimit: redesign
Description of how this works in `docs/internal/RATELIMITS.ms`.

Notable implementation changes:
- KEEP_SEND_PAUSE/KEEP_SEND_HOLD and KEEP_RECV_PAUSE/KEEP_RECV_HOLD
  no longer exist. Pausing is down via blocked the new rlimits.
- KEEP_SEND_TIMED no longer exists. Pausing "100-continue" transfers
  is done in the new `Curl_http_perform_pollset()` method.
- HTTP/2 rate limiting implemented via window updates. When
  transfer initiaiting connection has a ratelimit, adjust the
  initial window size
- HTTP/3 ngtcp2 rate limitin implemnented via ack updates
- HTTP/3 quiche does not seem to support this via its API
- the default progress-meter has been improved for accuracy
  in "current speed" results.

pytest speed tests have been improved.

Closes #19384
2025-11-24 23:34:05 +01:00
Daniel Stenberg
a97f9d41cc
openldap/ldap; check for binary attribute case insensitively
This bug was found with ZeroPath

Fixes #19240
Reported-by: Joshua Rogers
Closes #19273
2025-10-29 10:03:35 +01:00
Viktor Szakats
71d1eec675
tidy-up: miscellaneous
- cmake/Find*: make double quotes consistent.
- drop redundant parenthesis.
- GHA/checksrc: sync a step name with others.
- whitespace.

Closes #19233
2025-10-25 00:19:00 +02:00
Joshua Rogers
9021e42c02
ldap: do not pass a \n to failf()
Discovered by ZeroPath
Closes #19122
2025-10-18 22:16:33 +02:00
Stefan Eissing
6e35eb4879
lib: SSL connection reuse
Protocol handlers not flagging PROTOPT_SSL that allow reuse of existing
SSL connections now need to carry the flag PROTOPT_SSL_REUSE.

Add PROTOPT_SSL_REUSE to imap, ldap, pop3, smtp and ftp.

Add tests the http: urls do not reuse https: connections and vice versa.

Reported-by: Sakthi SK
Fixes #19006
Closes #19007
2025-10-12 15:30:12 +02:00
Daniel Stenberg
69efbcaa03
ldap: avoid null ptr deref on failure
ldap_get_dn() can return NULL on error

Reported-by: Joshua Rogers
Closes #18988
2025-10-10 08:24:45 +02:00
Viktor Szakats
b12da22db1
lib: stop overriding system printf symbols
After this patch, the codebase no longer overrides system printf
functions. Instead it explicitly calls either the curl printf functions
`curl_m*printf()` or the system ones using their original names.

Also:
- drop unused `curl_printf.h` includes.
- checksrc: ban system printf functions, allow where necessary.

Follow-up to db98daab05 #18844
Follow-up to 4deea9396b #18814

Closes #18866
2025-10-06 20:57:59 +02:00
Viktor Szakats
ef1794e50e
ldap: tidy-up types, fix error code confusion
- fix `CURLcode` vs. LDAP result code confusion.
  Return `LDAP_NO_MEMORY` when `Curl_create_sspi_identity()` fails,
  since it can only return `CURLE_OUT_OF_MEMORY` as error.
- use `ULONG` for result code on Windows. Drop casts.
- use portable `curl_ldap_num_t`. Drop casts.
- replace magic number 0 with `LDAP_SUCCESS`.
- compare with `LDAP_SUCCESS` instead of assuming non-zero.
  (where necessary.)
- add/fix `#endif` comments.
- fix indentation.

Closes #18888
2025-10-06 19:31:13 +02:00
Viktor Szakats
92f215fea1
build: address some -Weverything warnings, update picky warnings
`-Weverything` is not enabled by curl, and not recommended by LLVM,
because it may enable experimental options, and will result in new
fallouts after toolchain upgrades. This patch aims to fix/silence as much
as possible as found with llvm/clang 21.1.0. It also permanently enables
warnings that were fixed in source and deemed manageable in the future.
`-Wformat` warnings are addressed separately via #18343.

Fix/silence warnings in the source:
- typecheck-gcc.h: fix `-Wreserved-identifier`.
- lib: silence `-Wcast-function-type-strict`.
  For llvm 16+ or Apple clang 16+.
- asyn-ares: limit `HAPPY_EYEBALLS_DNS_TIMEOUT` to old c-ares versions.
- curl_trc: fix `-Wc++-hidden-decl`.
- doh: fix `-Wc++-keyword`.
- ftp: fix `-Wreserved-identifier`.
- ldap: fix `-Wreserved-identifier`.
- mqtt: comment unused macro to avoid warning.
- multi_ev: drop unused macros to avoid warnings.
- setopt: fix useless `break;` after `return;`.
- gtls, mbedtls, rustls: silence `-Wconditional-uninitialized`.
- socks_sspi, schannel, x509asn1: fix `-Wimplicit-int-enum-cast`.
- x509asn1: fix `-Wc++-keyword`.
- openssl: scope `OSSL_UI_METHOD_CAST` to avoid unused macro warning.
- libssh2, wolfssl: drop unused macros.
- curl_ngtcp2, curl_quiche, httpsrr, urlapi: drop/limit unused macros.
- tool_getparam: fix useless `break;` after `return;` or `break;`.
  Not normally enabled because it doesn't work with unity.
  https://github.com/llvm/llvm-project/issues/71046
- tool_operate: fix `-Wc++-keyword`.
- curlinfo: fix a `-Wunsafe-buffer-usage`.
- tests: silence `-Wformat-non-iso`.
- lib557: fix `-Wreserved-identifier`.
- lib1565: silence `-Wconditional-uninitialized`.

Enable the above clang warnings permanently in picky mode:
- `-Wc++-hidden-decl`
- `-Wc++-keyword` (except for Windows, where it collides with `wchar_t`)
- `-Wcast-function-type-strict`
- `-Wcast-function-type`
- `-Wconditional-uninitialized`
- `-Wformat-non-iso` (except for clang-cl)
- `-Wreserved-identifier`
- `-Wtentative-definition-compat`

Silence problematic `-Weverything` warnings globally (in picky mode):
- `-Wused-but-marked-unused` (88000+ hits) and
  `-Wdisabled-macro-expansion` (2600+ hits).
  Triggered by `typecheck-gcc.h` when building with clang 14+.
  Maybe there exists a way to fix within that header?
  Ref: https://discourse.llvm.org/t/removing-wused-but-marked-unused/55310
- `-Wunsafe-buffer-usage`. clang 16+. 7000+ hits.
  May be useful in theory, but such high volume of hits makes it
  impractical to review and possibly address. Meant for C++.
  Ref: https://clang.llvm.org/docs/SafeBuffers.html
  Ref: https://stackoverflow.com/questions/77017567/how-to-fix-code-to-avoid-warning-wunsafe-buffer-usage
  Ref: https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734
  Ref: https://github.com/llvm/llvm-project/pull/111624
- `-Wimplicit-void-ptr-cast`. clang 21+. 1700+ hits.
  C++ warning, deemed pure noise.
  Ref: https://github.com/curl/curl/issues/18470#issuecomment-3253506266
- `-Wswitch-default` (180+ hits), `-Wswitch-enum` (190+ hits),
  `-Wcovered-switch-default` (20+ hits).
  Next to impossible to fix cleanly, esp. when the covered `case`
  branches depend on compile-time options.
- `-Wdocumentation-unknown-command` (8+ hits).
  Triggered in a few sources. Seems arbitrary and bogus.
- `-Wpadded` (550+ hits).
- `-Wc++-keyword` on Windows, where it collides with `wchar_t`.
  (100+ hits)
  Ref: https://github.com/llvm/llvm-project/issues/155988
- `-Wreserved-macro-identifier`. clang 13+. 5+ hits.
  Sometimes it's necessary to set external macros that use
  the reserved namespace. E.g. `_CRT_NONSTDC_NO_DEPRECATE`,
  `__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__`, `__NO_NET_API`,
  possibly `_REENTRANT`, and more.
  It's not worth trying to silence them individually.
- `-Wnonportable-system-include-path` with `clang-cl`.
  It'd be broken by doing what the warning suggests.
- `-Wformat-non-iso` for clang-cl.

CMake `PICKY_COMPILER=ON` (the default) or `./configure`
`--enable-warnings` (not the default) is required to enable these
silencing rules.

Also:
- autotools, cmake: fix Apple clang and mainline llvm version translations.
  Ref: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
- autotools, cmake: enable `-Warray-compare` for clang 20+.
  Follow-up to 4b7accda5a #17196
- cmake: fix to enable `-Wmissing-variable-declarations` at an earlier
  clang version.
- cmake: update internal logic to handle warning options with `+` in
  them.
- cmake: fix internal logic to match the whole option when looking
  into `CMAKE_C_FLAGS` for custom-disabled warnings.

Follow-up to b85cb8cb4e #18485

Closes #18477
2025-09-20 10:16:15 +02:00
Daniel Stenberg
44a586472b
ldap: do not base64 encode zero length string
Reported-by: Joshua Rogers
Closes #18602
2025-09-18 17:15:30 +02:00
Stefan Eissing
5b80b4c012
lib: replace getsock() logic with pollsets
`getsock()` calls operated on a global limit that could
not be configure beyond 16 sockets. This is no longer adequate
with the new happy eyeballing strategy.

Instead, do the following:
- make `struct easy_pollset` dynamic. Starting with
  a minimal room for two sockets, the very common case,
  allow it to grow on demand.
- replace all protocol handler getsock() calls with pollsets
  and a CURLcode to return failures
- add CURLcode return for all connection filter `adjust_pollset()`
  callbacks, since they too can now fail.
- use appropriately in multi.c and multi_ev.c
- fix unit2600 to trigger pollset growth

Closes #18164
2025-08-04 23:43:13 +02:00
Stefan Eissing
83da4d9d3b
connectdata: remove primary+secondary ip_quadruple
Since the content varies during connection setup and while doing it
(eyeballing), remove these strcut from `connectdata` and replace use
with querying the connection filters. Those keep that information
already.

Change the info logging of established connections to also give the
local address and port.

Closes #17960
2025-07-30 10:56:19 +02:00
Viktor Szakats
89771d19d5
tidy-up: prefer ifdef/ifndef for single checks
Closes #18018
2025-07-27 22:35:17 +02:00
Viktor Szakats
a3787f98ac
lib: drop two interim macros in favor of native libcurl API calls
Drop `strcasecompare` and `strncasecompare` in favor of libcurl API
calls `curl_strequal` and `curl_strnequal` respectively.

Also drop unnecessary `strcase.h` includes. Include `curl/curl.h`
instead where it wasn't included before.

Closes #17772
2025-06-30 18:38:56 +02:00
Daniel Stenberg
2d528898f7
lib: move multibyte.[ch] to curlx/
This file provides functions in the curlx set.

Closes #17285
2025-05-08 10:19:19 +02:00
Daniel Stenberg
255aac56f9
curlx: move into to curlx/
Move curlx_ functions into its own subdir.

The idea is to use the curlx_ prefix proper on these functions, and use
these same function names both in tool, lib and test suite source code.
Stop the previous special #define setup for curlx_ names.

The printf defines are now done for the library alone. Tests no longer
use the printf defines. The tool code sets its own defines. The printf
functions are not curlx, they are publicly available.

The strcase defines are not curlx_ functions and should not be used by
tool or server code.

dynbuf, warnless, base64, strparse, timeval, timediff are now proper
curlx functions.

When libcurl is built statically, the functions from the library can be
used as-is. The key is then that the functions must work as-is, without
having to be recompiled for use in tool/tests. This avoids symbol
collisions - when libcurl is built statically, we use those functions
directly when building the tool/tests. When libcurl is shared, we
build/link them separately for the tool/tests.

Assisted-by: Jay Satiro

Closes #17253
2025-05-07 11:01:15 +02:00
Viktor Szakats
f4e23950c7
build: enable -Wcast-qual, fix or silence compiler warnings
The issues found fell into these categories, with the applied fixes:

- const was accidentally stripped.
  Adjust code to not cast or cast with const.

- const/volatile missing from arguments, local variables.
  Constify arguments or variables, adjust/delete casts. Small code
  changes in a few places.

- const must be stripped because an API dependency requires it.
  Strip `const` with `CURL_UNCONST()` macro to silence the warning out
  of our control. These happen at API boundaries. Sometimes they depend
  on dependency version, which this patch handles as necessary. Also
  enable const support for the zlib API, using `ZLIB_CONST`. Supported
  by zlib 1.2.5.2 and newer.

- const must be stripped because a curl API requires it.
  Strip `const` with `CURL_UNCONST()` macro to silence the warning out
  of our immediate control. For example we promise to send a non-const
  argument to a callback, though the data is const internally.

- other cases where we may avoid const stripping by code changes.
  Also silenced with `CURL_UNCONST()`.

- there are 3 places where `CURL_UNCONST()` is cast again to const.
  To silence this type of warning:
  ```
  lib/vquic/curl_osslq.c:1015:29: error: to be safe all intermediate
    pointers in cast from 'unsigned char **' to 'const unsigned char **'
    must be 'const' qualified [-Werror=cast-qual]
  lib/cf-socket.c:734:32: error: to be safe all intermediate pointers in
    cast from 'char **' to 'const char **' must be 'const' qualified
    [-Werror=cast-qual]
  ```
  There may be a better solution, but I couldn't find it.

These cases are handled in separate subcommits, but without further
markup.

If you see a `-Wcast-qual` warning in curl, we appreciate your report
about it.

Closes #16142
2025-03-10 22:30:15 +01:00
Daniel Stenberg
676de7f580
lib: use Curl_str_* instead of strtok_r()
Helps avoid extra mallocs. Gets rid of the private strtok_r
implementation.

Closes #16360
2025-02-17 13:18:28 +01:00
Daniel Stenberg
b4538ec522
strparse: switch to curl_off_t as base data type
- add hex and octal parsers to the Curl_str_* family
- make curlx_strtoofft use these parsers
- remove all use of strtol() and strtoul() in library code
- generally use Curl_str_* more than strtoofft, for stricter parsing
- supports 64-bit universally, instead of 'long' which differs in size
  between platforms

Extended the unit test 1664 to verify hex and octal parsing.

Closes #16336
2025-02-15 21:58:48 +01:00