Skip to content

Commit

Permalink
docs: fix some CURLINFO examples
Browse files Browse the repository at this point in the history
- improve getinfo result check for example sections:
  CURLINFO_ACTIVESOCKET, CURLINFO_LASTSOCKET, CURLINFO_SSL_VERIFYRESULT,
  CURLINFO_PROXY_SSL_VERIFYRESULT

- fix getinfo result check for example sections:
  CURLINFO_NUM_CONNECTS, CURLINFO_OS_ERRNO

- fix verify result check for example sections:
  CURLINFO_PROXY_SSL_VERIFYRESULT

Bug: #13557 (comment)
Reported-by: farazrbx@users.noreply.github.com

Closes #13559
  • Loading branch information
jay committed May 10, 2024
1 parent 3b4b6bd commit edc5b35
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
13 changes: 9 additions & 4 deletions docs/libcurl/opts/CURLINFO_ACTIVESOCKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ int main(void)
/* Do not do the transfer - only connect to host */
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl);
/* Extract the socket from the curl handle */
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
if(res != CURLE_OK) {
printf("Error: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
return 1;
}
/* Extract the socket from the curl handle */
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
if(!res && sockfd != CURL_SOCKET_BAD) {
/* operate on sockfd */
}
curl_easy_cleanup(curl);
}
}
~~~
Expand Down
13 changes: 9 additions & 4 deletions docs/libcurl/opts/CURLINFO_LASTSOCKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ int main(void)
/* Do not do the transfer - only connect to host */
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl);
/* Extract the socket from the curl handle */
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
if(res != CURLE_OK) {
printf("Error: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
return 1;
}
/* Extract the socket from the curl handle */
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
if(!res && sockfd != -1) {
/* operate on sockfd */
}
curl_easy_cleanup(curl);
}
}
~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/libcurl/opts/CURLINFO_NUM_CONNECTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(void)
if(res == CURLE_OK) {
long connects;
res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connects);
if(res)
if(!res)
printf("It needed %ld connects\n", connects);
}
curl_easy_cleanup(curl);
Expand Down
2 changes: 1 addition & 1 deletion docs/libcurl/opts/CURLINFO_OS_ERRNO.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(void)
if(res != CURLE_OK) {
long error;
res = curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &error);
if(res && error) {
if(!res && error) {
printf("Errno: %ld\n", error);
}
}
Expand Down
19 changes: 15 additions & 4 deletions docs/libcurl/opts/CURLINFO_PROXY_SSL_VERIFYRESULT.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Pass a pointer to a long to receive the result of the certificate verification
that was requested (using the CURLOPT_PROXY_SSL_VERIFYPEER(3)
option. This is only used for HTTPS proxies.
0 is a positive result. Non-zero is an error.
# EXAMPLE
~~~c
Expand All @@ -43,14 +45,23 @@ int main(void)
if(curl) {
CURLcode res;
long verifyresult;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
res = curl_easy_perform(curl);
if(res)
if(res) {
printf("error: %s\n", curl_easy_strerror(res));
curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT, &verifyresult);
printf("The peer verification said %s\n", verifyresult?
"fine" : "bad");
curl_easy_cleanup(curl);
return 1;
}
res = curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT,
&verifyresult);
if(!res) {
printf("The peer verification said %s\n",
(verifyresult ? "bad" : "fine"));
}
curl_easy_cleanup(curl);
}
}
Expand Down
17 changes: 13 additions & 4 deletions docs/libcurl/opts/CURLINFO_SSL_VERIFYRESULT.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ int main(void)
if(curl) {
CURLcode res;
long verifyresult;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
res = curl_easy_perform(curl);
if(res)
if(res) {
printf("error: %s\n", curl_easy_strerror(res));
curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, &verifyresult);
printf("The peer verification said %s\n", verifyresult?
"BAAAD":"fine");
curl_easy_cleanup(curl);
return 1;
}
res = curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
&verifyresult);
if(!res) {
printf("The peer verification said %s\n",
(verifyresult ? "bad" : "fine"));
}
curl_easy_cleanup(curl);
}
}
Expand Down

0 comments on commit edc5b35

Please sign in to comment.