From: Viktor Szakats Date: Tue, 7 Oct 2025 11:54:17 +0000 (+0200) Subject: examples: fix build issues in 'complicated' examples X-Git-Tag: rc-8_17_0-1~81 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6bb77140322565ca17f5a66aa5d8500d8d469cca;p=thirdparty%2Fcurl.git examples: fix build issues in 'complicated' examples - cacertinmem: build cleanly with BoringSSL/AWS-LC. - cacertinmem: silence `-Wcast-function-type-strict`. - multi-uv: fix callback prototypes. - multithread, threaded-ssl: do not pass const as thread arg. - sessioninfo: fix suppressing deprecated feature warning. - usercertinmem: sync formatting with cacertinmem. Follow-up to 4a6bdd5899005c25ce222dc21dcfd1a779544330 #18908 Cherry-picked from #18909 Closes #18914 --- diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index ec12df58bf..6a2649b29b 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -34,6 +34,17 @@ #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic ignored "-Woverlength-strings" #endif +/* Silence warning when calling sk_X509_INFO_pop_free() */ +#if defined(__clang__) && __clang_major__ >= 16 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-function-type-strict" +#endif + +#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) +typedef size_t ossl_valsize_t; +#else +typedef int ossl_valsize_t; +#endif static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) { @@ -68,8 +79,8 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) "-----END CERTIFICATE-----\n"; BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem)); - X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx); - int i; + X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx); + ossl_valsize_t i; STACK_OF(X509_INFO) *inf; (void)curl; diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index ee0ac0e1b3..07774c93eb 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -167,9 +167,9 @@ static void on_uv_timeout(uv_timer_t *req) } /* callback from libcurl to update the timeout expiry */ -static int cb_timeout(CURLM *multi, long timeout_ms, - struct datauv *uv) +static int cb_timeout(CURLM *multi, long timeout_ms, void *userp) { + struct datauv *uv = (struct datauv *)userp; (void)multi; if(timeout_ms < 0) uv_timer_stop(&uv->timeout); @@ -185,9 +185,9 @@ static int cb_timeout(CURLM *multi, long timeout_ms, /* callback from libcurl to update socket activity to wait for */ static int cb_socket(CURL *easy, curl_socket_t s, int action, - struct datauv *uv, - void *socketp) + void *userp, void *socketp) { + struct datauv *uv = (struct datauv *)userp; struct curl_context *curl_context; int events = 0; (void)easy; diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index ceee94022a..4cdb74fbe4 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -48,12 +48,13 @@ static const char * const urls[NUMT]= { "www.example" }; -static void *pull_one_url(void *url) +static void *pull_one_url(void *pindex) { + int i = *(int *)pindex; CURL *curl; curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_URL, urls[i]); curl_easy_perform(curl); /* ignores error */ curl_easy_cleanup(curl); @@ -79,7 +80,7 @@ int main(void) int error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, - (void *)urls[i]); + (void *)&i); if(error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else diff --git a/docs/examples/sessioninfo.c b/docs/examples/sessioninfo.c index 225b1ae5a5..5fbc1cc4df 100644 --- a/docs/examples/sessioninfo.c +++ b/docs/examples/sessioninfo.c @@ -29,6 +29,10 @@ /* Note that this example currently requires curl to be linked against GnuTLS (and this program must also be linked against -lgnutls). */ +#ifndef CURL_DISABLE_DEPRECATION +#define CURL_DISABLE_DEPRECATION +#endif + #include #include @@ -47,8 +51,7 @@ static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) (void)stream; (void)ptr; - res = CURL_IGNORE_DEPRECATION( - curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &info)); + res = curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &info); if(!res) { switch(info->backend) { diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 161182eec1..6590e8b202 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -52,12 +52,13 @@ static const char * const urls[]= { "https://www4.example.com/", }; -static void *pull_one_url(void *url) +static void *pull_one_url(void *pindex) { + int i = *(int *)pindex; CURL *curl; curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_URL, urls[i]); /* this example does not verify the server's certificate, which means we might be downloading stuff from an impostor */ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); @@ -82,7 +83,7 @@ int main(int argc, char **argv) int error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, - (void *)urls[i]); + (void *)&i); if(error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else diff --git a/docs/examples/usercertinmem.c b/docs/examples/usercertinmem.c index 50537ae25f..899895592e 100644 --- a/docs/examples/usercertinmem.c +++ b/docs/examples/usercertinmem.c @@ -22,7 +22,7 @@ * ***************************************************************************/ /* - * Use an in-memory user certificate and RSA key and retrieve an https page. + * Use an in-memory user certificate and RSA key and retrieve an HTTPS page. * */ /* Written by Ishan SinghLevett, based on Theo Borm's cacertinmem.c. @@ -47,7 +47,7 @@ static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) { - fwrite(ptr, size, nmemb, stream); + fwrite(ptr, size, nmemb, (FILE *)stream); return nmemb * size; } @@ -179,12 +179,10 @@ int main(void) /* first try: retrieve page without user certificate and key -> fails */ rv = curl_easy_perform(ch); - if(rv == CURLE_OK) { + if(rv == CURLE_OK) printf("*** transfer succeeded ***\n"); - } - else { + else printf("*** transfer failed ***\n"); - } /* second try: retrieve page using user certificate and key -> succeeds * load the certificate and key by installing a function doing the necessary @@ -192,12 +190,10 @@ int main(void) */ curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, sslctx_function); rv = curl_easy_perform(ch); - if(rv == CURLE_OK) { + if(rv == CURLE_OK) printf("*** transfer succeeded ***\n"); - } - else { + else printf("*** transfer failed ***\n"); - } curl_easy_cleanup(ch); curl_global_cleanup();