1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 #ifndef CURL_DISABLE_LIBCURL_OPTION
26 #include <curl/curl.h>
28 #define ENABLE_CURLX_PRINTF
29 /* use our own printf() functions */
32 #include "tool_cfgable.h"
33 #include "tool_easysrc.h"
34 #include "tool_setopt.h"
36 #include "memdebug.h" /* keep this as LAST include */
38 CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
39 const char *name, CURLoption tag, ...)
46 CURLcode ret = CURLE_OK;
50 if(tag < CURLOPTTYPE_OBJECTPOINT) {
51 long lval = va_arg(arg, long);
52 snprintf(value, sizeof(value), "%ldL", lval);
53 ret = curl_easy_setopt(curl, tag, lval);
57 else if(tag < CURLOPTTYPE_OFF_T) {
58 void *pval = va_arg(arg, void *);
59 unsigned char *ptr = (unsigned char *)pval;
61 /* function pointers are never printable */
62 if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
64 strcpy(value, "functionpointer"); /* 'value' fits 256 bytes */
72 snprintf(value, sizeof(value), "\"%s\"", (char *)ptr);
74 strcpy(value, "objectpointer"); /* 'value' fits 256 bytes */
80 ret = curl_easy_setopt(curl, tag, pval);
84 curl_off_t oval = va_arg(arg, curl_off_t);
85 snprintf(value, sizeof(value),
86 "(curl_off_t)%" CURL_FORMAT_CURL_OFF_T, oval);
87 ret = curl_easy_setopt(curl, tag, oval);
95 if(config->libcurl && !skip && !ret) {
96 /* we only use this for real if --libcurl was used */
99 bufp = curlx_maprintf("%s set to a %s", name, value);
101 bufp = curlx_maprintf("curl_easy_setopt(hnd, %s, %s);", name, value);
104 ret = CURLE_OUT_OF_MEMORY;
106 struct curl_slist *list =
107 curl_slist_append(remark?easysrc_remarks:easysrc, bufp);
112 curl_slist_free_all(easysrc_remarks);
113 curl_slist_free_all(easysrc);
114 easysrc_remarks = NULL;
116 ret = CURLE_OUT_OF_MEMORY;
119 easysrc_remarks = list;
128 #endif /* CURL_DISABLE_LIBCURL_OPTION */