sourcemod/extensions/curl/curl-src/docs/examples/certinfo.c

63 lines
1.3 KiB
C
Raw Normal View History

2013-03-18 01:55:59 +01:00
/*****************************************************************************
*/
2009-01-09 00:31:00 +01:00
#include <stdio.h>
#include <curl/curl.h>
2013-03-18 01:55:59 +01:00
#include <curl/types.h>
#include <curl/easy.h>
2009-01-09 00:31:00 +01:00
static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
{
return size * nmemb;
}
2013-03-18 01:55:59 +01:00
int main(int argc, char **argv)
2009-01-09 00:31:00 +01:00
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
2013-03-18 01:55:59 +01:00
curl_easy_setopt(curl, CURLOPT_URL, "https://www.networking4all.com/");
2009-01-09 00:31:00 +01:00
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
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);
res = curl_easy_perform(curl);
if(!res) {
2013-03-18 01:55:59 +01:00
struct curl_certinfo *ci = NULL;
2009-01-09 00:31:00 +01:00
2013-03-18 01:55:59 +01:00
res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
2009-01-09 00:31:00 +01:00
2013-03-18 01:55:59 +01:00
if(!res && ci) {
2009-01-09 00:31:00 +01:00
int i;
2013-03-18 01:55:59 +01:00
printf("%d certs!\n", ci->num_of_certs);
2009-01-09 00:31:00 +01:00
2013-03-18 01:55:59 +01:00
for(i=0; i<ci->num_of_certs; i++) {
2009-01-09 00:31:00 +01:00
struct curl_slist *slist;
2013-03-18 01:55:59 +01:00
for(slist = ci->certinfo[i]; slist; slist = slist->next)
2009-01-09 00:31:00 +01:00
printf("%s\n", slist->data);
}
}
}
2013-03-18 01:55:59 +01:00
2009-01-09 00:31:00 +01:00
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}