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 <s...@cmpwn.com>
---
v2 drops RFC and adds a man page.

 docs/libcurl/curl_easy_vsetopt.3 | 42 ++++++++++++++++++++++++++++++++
 include/curl/easy.h              |  3 +++
 lib/setopt.c                     | 14 ++++-------
 lib/setopt.h                     |  1 -
 packages/OS400/ccsidcurl.c       |  2 +-
 5 files changed, 51 insertions(+), 11 deletions(-)
 create mode 100644 docs/libcurl/curl_easy_vsetopt.3

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
@@ -0,0 +1,42 @@
+.\" **************************************************************************
+.\" *                                  _   _ ____  _
+.\" *  Project                     ___| | | |  _ \| |
+.\" *                             / __| | | | |_) | |
+.\" *                            | (__| |_| |  _ <| |___
+.\" *                             \___|\___/|_| \_\_____|
+.\" *
+.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <dan...@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
@@ -21,6 +21,8 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include <stdarg.h>
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -38,6 +40,7 @@ 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
@@ -146,11 +146,7 @@ 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;
@@ -160,6 +156,9 @@ 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);
@@ -3044,12 +3043,9 @@ 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
@@ -25,6 +25,5 @@
 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/packages/OS400/ccsidcurl.c b/packages/OS400/ccsidcurl.c
index 4b30683ea..3f9a3a9ee 100644
--- a/packages/OS400/ccsidcurl.c
+++ b/packages/OS400/ccsidcurl.c
@@ -1264,7 +1264,7 @@ curl_easy_setopt_ccsid(CURL *curl, CURLoption tag, ...)
 
   case CURLOPT_ERRORBUFFER:                     /* This is an output buffer. */
   default:
-    result = Curl_vsetopt(curl, tag, arg);
+    result = curl_easy_vsetopt(curl, tag, arg);
     break;
   }
 
-- 
2.35.1

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to