1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, 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 #include <curl/curl.h>
26 #define ENABLE_CURLX_PRINTF
27 /* use our own printf() functions */
30 #include "tool_cfgable.h"
31 #include "tool_easysrc.h"
32 #include "tool_setopt.h"
34 #include "memdebug.h" /* keep this as LAST include */
36 CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
37 const char *name, CURLoption tag, ...)
44 CURLcode ret = CURLE_OK;
48 if(tag < CURLOPTTYPE_OBJECTPOINT) {
49 long lval = va_arg(arg, long);
50 snprintf(value, sizeof(value), "%ldL", lval);
51 ret = curl_easy_setopt(curl, tag, lval);
55 else if(tag < CURLOPTTYPE_OFF_T) {
56 void *pval = va_arg(arg, void *);
57 unsigned char *ptr = (unsigned char *)pval;
59 /* function pointers are never printable */
60 if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
62 strcpy(value, "functionpointer"); /* 'value' fits 256 bytes */
70 snprintf(value, sizeof(value), "\"%s\"", (char *)ptr);
72 strcpy(value, "objectpointer"); /* 'value' fits 256 bytes */
78 ret = curl_easy_setopt(curl, tag, pval);
82 curl_off_t oval = va_arg(arg, curl_off_t);
83 snprintf(value, sizeof(value),
84 "(curl_off_t)%" CURL_FORMAT_CURL_OFF_T, oval);
85 ret = curl_easy_setopt(curl, tag, oval);
93 if(config->libcurl && !skip && !ret) {
94 /* we only use this for real if --libcurl was used */
97 bufp = curlx_maprintf("%s set to a %s", name, value);
99 bufp = curlx_maprintf("curl_easy_setopt(hnd, %s, %s);", name, value);
102 ret = CURLE_OUT_OF_MEMORY;
104 struct curl_slist *list =
105 curl_slist_append(remark?easysrc_remarks:easysrc, bufp);
110 curl_slist_free_all(easysrc_remarks);
111 curl_slist_free_all(easysrc);
112 easysrc_remarks = NULL;
114 ret = CURLE_OUT_OF_MEMORY;
117 easysrc_remarks = list;