]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
docs: fix some CURLINFO examples
authorJay Satiro <raysatiro@yahoo.com>
Wed, 8 May 2024 07:37:12 +0000 (03:37 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Fri, 10 May 2024 05:12:36 +0000 (01:12 -0400)
- 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: https://github.com/curl/curl/discussions/13557#discussion-6625507
Reported-by: farazrbx@users.noreply.github.com
Closes https://github.com/curl/curl/pull/13559

docs/libcurl/opts/CURLINFO_ACTIVESOCKET.md
docs/libcurl/opts/CURLINFO_LASTSOCKET.md
docs/libcurl/opts/CURLINFO_NUM_CONNECTS.md
docs/libcurl/opts/CURLINFO_OS_ERRNO.md
docs/libcurl/opts/CURLINFO_PROXY_SSL_VERIFYRESULT.md
docs/libcurl/opts/CURLINFO_SSL_VERIFYRESULT.md

index 92567e627d934f971851789e75f7326337ed2778..1a799e1e53d7753e510aa49e04c1b66277cfb303 100644 (file)
@@ -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);
   }
 }
 ~~~
index 8e98df90e2a801ec5765e9b578161d57cd884ec8..318fe71512b77ed84bf3396f6173a543957de24c 100644 (file)
@@ -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);
   }
 }
 ~~~
index 5488fcc42683bbe5850af6c9c4516616af2f68d9..56383de3958ba97c0ee1153d0d93a9862bacaafd 100644 (file)
@@ -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);
index 85084778a8e4441f9a1bb78c34956ef36a1cb43a..8f6853ef4471121d34288aace46693f15abedd1c 100644 (file)
@@ -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);
       }
     }
index 073de0aa5358ec5e3b21aac14d9f0936b1e41edb..9ccf831f991c4a6f0333a110b81a2a795402d119 100644 (file)
@@ -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
@@ -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);
   }
 }
index 27cbfde71ab6a71fcd3e2e5db167f9b13dec4a85..0e4fedf58fb2363300c58d6b13deb88fed0a6c28 100644 (file)
@@ -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);
   }
 }