mirror of
https://github.com/curl/curl.git
synced 2026-04-14 22:41:40 +03:00
examples: consistent variable naming across examples
- 'CURL *' handles are called 'curl' - 'CURLM *' handles are called 'multi' - write callbacks are called 'write_cb' - read callbacs are called 'read_cb' - CURLcode variables are called 'res' It makes the examples look and feel more consistent. It allows for easier copy and pasting between examples. Closes #19299
This commit is contained in:
parent
0313223853
commit
928363f28c
59 changed files with 715 additions and 725 deletions
|
|
@ -48,7 +48,7 @@ typedef size_t ossl_valsize_t;
|
|||
typedef int ossl_valsize_t;
|
||||
#endif
|
||||
|
||||
static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
fwrite(ptr, size, nmemb, (FILE *)stream);
|
||||
return nmemb * size;
|
||||
|
|
@ -115,37 +115,37 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
CURL *ch;
|
||||
CURL *curl;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
ch = curl_easy_init();
|
||||
if(ch) {
|
||||
curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L);
|
||||
curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
|
||||
curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L);
|
||||
curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L);
|
||||
curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writefunction);
|
||||
curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout);
|
||||
curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, writefunction);
|
||||
curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr);
|
||||
curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");
|
||||
curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/");
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, stderr);
|
||||
curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
||||
|
||||
/* Turn off the default CA locations, otherwise libcurl loads CA
|
||||
* certificates from the locations that were detected/specified at
|
||||
* build-time
|
||||
*/
|
||||
curl_easy_setopt(ch, CURLOPT_CAINFO, NULL);
|
||||
curl_easy_setopt(ch, CURLOPT_CAPATH, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_CAPATH, NULL);
|
||||
|
||||
/* first try: retrieve page without ca certificates -> should fail
|
||||
* unless libcurl was built --with-ca-fallback enabled at build-time
|
||||
*/
|
||||
res = curl_easy_perform(ch);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res == CURLE_OK)
|
||||
printf("*** transfer succeeded ***\n");
|
||||
else
|
||||
|
|
@ -155,24 +155,24 @@ int main(void)
|
|||
* performance of multiple transfers but it is necessary order to
|
||||
* demonstrate this example. recall that the ssl ctx callback is only
|
||||
* called _before_ an SSL connection is established, therefore it does not
|
||||
* affect existing verified SSL connections already in the connection cache
|
||||
* associated with this handle. normally you would set the ssl ctx function
|
||||
* before making any transfers, and not use this option.
|
||||
* affect existing verified SSL connections already in the connection
|
||||
* cache associated with this handle. normally you would set the ssl ctx
|
||||
* function before making any transfers, and not use this option.
|
||||
*/
|
||||
curl_easy_setopt(ch, CURLOPT_FRESH_CONNECT, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
|
||||
|
||||
/* second try: retrieve page using cacerts' certificate -> succeeds to load
|
||||
* the certificate by installing a function doing the necessary
|
||||
/* second try: retrieve page using cacerts' certificate -> succeeds to
|
||||
* load the certificate by installing a function doing the necessary
|
||||
* "modifications" to the SSL CONTEXT just before link init
|
||||
*/
|
||||
curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);
|
||||
res = curl_easy_perform(ch);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res == CURLE_OK)
|
||||
printf("*** transfer succeeded ***\n");
|
||||
else
|
||||
printf("*** transfer failed ***\n");
|
||||
|
||||
curl_easy_cleanup(ch);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue