curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

[PATCH v3] setopt: make curl_easy_vsetopt public

From: Drew DeVault via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 23 Mar 2022 16:09:19 +0100

This moves the internal Curl_vsetopt function into the public API so
that users can set options with a va_list.

Signed-off-by: Drew DeVault <sir_at_cmpwn.com>
---
 docs/libcurl/curl_easy_vsetopt.3 | 42 +++++++++++++++++++++
 include/curl/easy.h              |  3 ++
 lib/setopt.c                     | 14 +++----
 lib/setopt.h                     |  1 -
 tests/libtest/Makefile.inc       |  6 ++-
 tests/libtest/lib3026.c          | 64 ++++++++++++++++++++++++++++++++
 6 files changed, 119 insertions(+), 11 deletions(-)
 create mode 100644 docs/libcurl/curl_easy_vsetopt.3
 create mode 100644 tests/libtest/lib3026.c
diff --git a/docs/libcurl/curl_easy_vsetopt.3 b/docs/libcurl/curl_easy_vsetopt.3
new file mode 100644
index 000000000..809376ff8
--- /dev/null
+++ b/docs/libcurl/curl_easy_vsetopt.3
_at__at_ -0,0 +1,42 _at__at_
+.\" **************************************************************************
+.\" *                                  _   _ ____  _
+.\" *  Project                     ___| | | |  _ \| |
+.\" *                             / __| | | | |_) | |
+.\" *                            | (__| |_| |  _ <| |___
+.\" *                             \___|\___/|_| \_\_____|
+.\" *
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel_at_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.
+.\" *
+.\" **************************************************************************
+.\"
+.TH curl_easy_vsetopt 3 "22 Mar 2022" "libcurl 7.38.0" "libcurl Manual"
+.SH NAME
+curl_easy_vsetopt \- set options for a curl easy handle from a va_list
+.SH SYNOPSIS
+.nf
+#include <stdarg.h>
+#include <curl/curl.h>
+
+CURLcode curl_easy_vsetopt(CURL *handle, CURLoption option, va_list ap);
+.fi
+.SH DESCRIPTION
+\fIcurl_easy_vsetopt(3)\fP is used to set options for a curl easy handle from a
+variadic argument list specified by the ap parameter. In all other respects it
+is identical to \fIcurl_easy_setopt(3)\fP.
+.SH AVAILABILITY
+Always
+.SH RETURN VALUE
+See \fIcurl_easy_setopt(3)\fP.
+.SH "SEE ALSO"
+.BR curl_easy_setopt "(3)"
diff --git a/include/curl/easy.h b/include/curl/easy.h
index 2dbfb26b5..ce6a77c8f 100644
--- a/include/curl/easy.h
+++ b/include/curl/easy.h
_at__at_ -21,6 +21,8 _at__at_
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include <stdarg.h>
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
_at__at_ -38,6 +40,7 _at__at_ struct curl_blob {
 
 CURL_EXTERN CURL *curl_easy_init(void);
 CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
+CURL_EXTERN CURLcode curl_easy_vsetopt(CURL *curl, CURLoption option, va_list param);
 CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
 CURL_EXTERN void curl_easy_cleanup(CURL *curl);
 
diff --git a/lib/setopt.c b/lib/setopt.c
index 8e1bf1279..247234c63 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
_at__at_ -146,11 +146,7 _at__at_ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
 #define C_SSLVERSION_VALUE(x) (x & 0xffff)
 #define C_SSLVERSION_MAX_VALUE(x) (x & 0xffff0000)
 
-/*
- * Do not make Curl_vsetopt() static: it is called from
- * packages/OS400/ccsidcurl.c.
- */
-CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
+CURLcode curl_easy_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
 {
   char *argptr;
   CURLcode result = CURLE_OK;
_at__at_ -160,6 +156,9 _at__at_ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
 #endif
   curl_off_t bigsize;
 
+  if(!data)
+    return CURLE_BAD_FUNCTION_ARGUMENT;
+
   switch(option) {
   case CURLOPT_DNS_CACHE_TIMEOUT:
     arg = va_arg(param, long);
_at__at_ -3044,12 +3043,9 _at__at_ CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
   va_list arg;
   CURLcode result;
 
-  if(!data)
-    return CURLE_BAD_FUNCTION_ARGUMENT;
-
   va_start(arg, tag);
 
-  result = Curl_vsetopt(data, tag, arg);
+  result = curl_easy_vsetopt(data, tag, arg);
 
   va_end(arg);
   return result;
diff --git a/lib/setopt.h b/lib/setopt.h
index affbfd996..2d7a37995 100644
--- a/lib/setopt.h
+++ b/lib/setopt.h
_at__at_ -25,6 +25,5 _at__at_
 CURLcode Curl_setstropt(char **charp, const char *s);
 CURLcode Curl_setblobopt(struct curl_blob **blobp,
                          const struct curl_blob *blob);
-CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list arg);
 
 #endif /* HEADER_CURL_SETOPT_H */
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index a87390733..aab9865fd 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
_at__at_ -62,7 +62,7 _at__at_ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
          lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \
          lib1915 lib1916 lib1917 lib1918 lib1933 lib1934 lib1935 lib1936 \
  lib1937 lib1938 lib1939 lib1940 lib1945 lib1946 \
- lib3010 lib3025
+ lib3010 lib3025 lib3026
 
 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
  ../../lib/curl_ctype.c  ../../lib/dynbuf.c ../../lib/strdup.c
_at__at_ -743,3 +743,7 _at__at_ lib3010_CPPFLAGS = $(AM_CPPFLAGS)
 lib3025_SOURCES = lib3025.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib3025_LDADD = $(TESTUTIL_LIBS)
 lib3025_CPPFLAGS = $(AM_CPPFLAGS)
+
+lib3026_SOURCES = lib3026.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib3026_LDADD = $(TESTUTIL_LIBS)
+lib3026_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/libtest/lib3026.c b/tests/libtest/lib3026.c
new file mode 100644
index 000000000..e70e95018
--- /dev/null
+++ b/tests/libtest/lib3026.c
_at__at_ -0,0 +1,64 _at__at_
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel_at_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.
+ *
+ ***************************************************************************/
+#include "test.h"
+#include "memdebug.h"
+
+#include <stdarg.h>
+
+CURLcode test_vsetopt(CURL *curl, CURLoption opt, ...)
+{
+  va_list ap;
+  va_start(ap, opt);
+  curl_easy_vsetopt(curl, opt, ap);
+  va_end(ap);
+}
+
+int test(char *URL)
+{
+  CURLcode res;
+  CURL *curl;
+
+  if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  curl = curl_easy_init();
+  if(!curl) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  test_vsetopt(curl, CURLOPT_VERBOSE, 1L);
+  test_vsetopt(curl, CURLOPT_HEADER, 1L);
+  test_vsetopt(curl, CURLOPT_URL, URL);
+
+  res = curl_easy_perform(curl);
+
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return (int)res;
+}
-- 
2.35.1
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-03-23