mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
In order to not encourage users to use incompatible function pointers, change the callback function definitions to use `char *` instead of `void *` for the first argument. Triggered by https://stackoverflow.com/questions/79921871/curl-c-c-library-based-application-produces-erronious-response-for-http-post-r#comment141032037_79921871 : "The code was mostly modified from [this example code](https://curl.se/libcurl/c/postinmemory.html), honestly I never knew this is wrong. Thanks for pointing it out." Signed-off-by: Ted Lyngmo <ted@lyncon.se> Closes #21265
88 lines
2.4 KiB
C
88 lines
2.4 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
/* <DESC>
|
|
* Extract lots of TLS certificate info.
|
|
* </DESC>
|
|
*/
|
|
#include <stdio.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream)
|
|
{
|
|
(void)stream;
|
|
(void)ptr;
|
|
return size * nmemb;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
CURL *curl;
|
|
CURLcode result;
|
|
|
|
result = curl_global_init(CURL_GLOBAL_ALL);
|
|
if(result != CURLE_OK)
|
|
return (int)result;
|
|
|
|
curl = curl_easy_init();
|
|
if(curl) {
|
|
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
|
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
|
|
|
|
result = curl_easy_perform(curl);
|
|
|
|
if(result == CURLE_OK) {
|
|
struct curl_certinfo *certinfo;
|
|
|
|
result = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);
|
|
|
|
if(!result && certinfo) {
|
|
int i;
|
|
|
|
printf("%d certs!\n", certinfo->num_of_certs);
|
|
|
|
for(i = 0; i < certinfo->num_of_certs; i++) {
|
|
struct curl_slist *slist;
|
|
|
|
for(slist = certinfo->certinfo[i]; slist; slist = slist->next)
|
|
printf("%s\n", slist->data);
|
|
}
|
|
}
|
|
}
|
|
|
|
curl_easy_cleanup(curl);
|
|
}
|
|
|
|
curl_global_cleanup();
|
|
|
|
return (int)result;
|
|
}
|