cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] Add configuration option disable --libcurl output

From: Colin Hogben <curl_at_pythontech.co.uk>
Date: Sun, 5 Feb 2012 17:44:22 +0000

---
 configure.ac        |   71 +++++++++++++++++++++++++++++++++------------------
 src/tool_easysrc.c  |    3 ++
 src/tool_easysrc.h  |    3 ++
 src/tool_getparam.c |    6 ++++
 src/tool_help.c     |    2 +
 src/tool_operate.c  |    8 ++++++
 src/tool_setopt.c   |    3 ++
 src/tool_setopt.h   |   41 +++++++++++++++++++++--------
 8 files changed, 101 insertions(+), 36 deletions(-)
diff --git a/configure.ac b/configure.ac
index 8920280..1e67dda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,6 +155,7 @@ curl_tls_srp_msg="no      (--enable-tls-srp)"
    curl_ipv6_msg="no      (--enable-ipv6)"
     curl_idn_msg="no      (--with-libidn)"
  curl_manual_msg="no      (--enable-manual)"
+curl_libcurl_msg="enabled (--disable-libcurl-option)"
 curl_verbose_msg="enabled (--disable-verbose)"
    curl_sspi_msg="no      (--enable-sspi)"
    curl_ldap_msg="no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)"
@@ -651,6 +652,25 @@ AC_HELP_STRING([--disable-manual],[Disable built-in manual]),
 dnl The actual use of the USE_MANUAL variable is done much later in this
 dnl script to allow other actions to disable it as well.
 
+dnl ************************************************************
+dnl disable C code generation support
+dnl
+AC_MSG_CHECKING([whether to enable generation of C code])
+AC_ARG_ENABLE(libcurl_option,
+AC_HELP_STRING([--enable-libcurl-option],[Enable --libcurl C code generation support])
+AC_HELP_STRING([--disable-libcurl-option],[Disable --libcurl C code generation support]),
+[ case "$enableval" in
+  no)
+       AC_MSG_RESULT(no)
+       AC_DEFINE(CURL_DISABLE_LIBCURL_OPTION, 1, [to disable --libcurl C code generation option])
+       curl_libcurl_msg="no"
+       ;;
+  *)   AC_MSG_RESULT(yes)
+       ;;
+  esac ],
+       AC_MSG_RESULT(yes)
+)
+
 dnl **********************************************************************
 dnl Checks for libraries.
 dnl **********************************************************************
@@ -3301,31 +3321,32 @@ CURL_GENERATE_CONFIGUREHELP_PM
 
 AC_MSG_NOTICE([Configured to build curl/libcurl:
 
-  curl version:    ${CURLVERSION}
-  Host setup:      ${host}
-  Install prefix:  ${prefix}
-  Compiler:        ${CC}
-  SSL support:     ${curl_ssl_msg}
-  SSH support:     ${curl_ssh_msg}
-  zlib support:    ${curl_zlib_msg}
-  krb4 support:    ${curl_krb4_msg}
-  GSSAPI support:  ${curl_gss_msg}
-  SPNEGO support:  ${curl_spnego_msg}
-  TLS-SRP support: ${curl_tls_srp_msg}
-  resolver:        ${curl_res_msg}
-  ipv6 support:    ${curl_ipv6_msg}
-  IDN support:     ${curl_idn_msg}
-  Build libcurl:   Shared=${enable_shared}, Static=${enable_static}
-  Built-in manual: ${curl_manual_msg}
-  Verbose errors:  ${curl_verbose_msg}
-  SSPI support:    ${curl_sspi_msg}
-  ca cert bundle:  ${ca}
-  ca cert path:    ${capath}
-  LDAP support:    ${curl_ldap_msg}
-  LDAPS support:   ${curl_ldaps_msg}
-  RTSP support:    ${curl_rtsp_msg}
-  RTMP support:    ${curl_rtmp_msg}
-  Protocols:       ${SUPPORT_PROTOCOLS}
+  curl version:     ${CURLVERSION}
+  Host setup:       ${host}
+  Install prefix:   ${prefix}
+  Compiler:         ${CC}
+  SSL support:      ${curl_ssl_msg}
+  SSH support:      ${curl_ssh_msg}
+  zlib support:     ${curl_zlib_msg}
+  krb4 support:     ${curl_krb4_msg}
+  GSSAPI support:   ${curl_gss_msg}
+  SPNEGO support:   ${curl_spnego_msg}
+  TLS-SRP support:  ${curl_tls_srp_msg}
+  resolver:         ${curl_res_msg}
+  ipv6 support:     ${curl_ipv6_msg}
+  IDN support:      ${curl_idn_msg}
+  Build libcurl:    Shared=${enable_shared}, Static=${enable_static}
+  Built-in manual:  ${curl_manual_msg}
+  --libcurl option: ${curl_libcurl_msg} 
+  Verbose errors:   ${curl_verbose_msg}
+  SSPI support:     ${curl_sspi_msg}
+  ca cert bundle:   ${ca}
+  ca cert path:     ${capath}
+  LDAP support:     ${curl_ldap_msg}
+  LDAPS support:    ${curl_ldaps_msg}
+  RTSP support:     ${curl_rtsp_msg}
+  RTMP support:     ${curl_rtmp_msg}
+  Protocols:        ${SUPPORT_PROTOCOLS}
 ])
 
 if test "x$soname_bump" = "xyes"; then
diff --git a/src/tool_easysrc.c b/src/tool_easysrc.c
index 5c42e80..019e235 100644
--- a/src/tool_easysrc.c
+++ b/src/tool_easysrc.c
@@ -23,6 +23,8 @@
 
 #include <curl/curl.h>
 
+#ifndef CURL_DISABLE_LIBCURL_OPTION
+
 #define ENABLE_CURLX_PRINTF
 /* use our own printf() functions */
 #include "curlx.h"
@@ -110,3 +112,4 @@ void dumpeasysrc(struct Configurable *config)
   easysrc = NULL;
 }
 
+#endif /* CURL_DISABLE_LIBCURL_OPTION */
diff --git a/src/tool_easysrc.h b/src/tool_easysrc.h
index 21b5674..f0c8c3e 100644
--- a/src/tool_easysrc.h
+++ b/src/tool_easysrc.h
@@ -22,6 +22,7 @@
  *
  ***************************************************************************/
 #include "setup.h"
+#ifndef CURL_DISABLE_LIBCURL_OPTION
 
 /* global variable declarations, for easy-interface source code generation */
 
@@ -30,5 +31,7 @@ extern struct curl_slist *easysrc_remarks;
 
 void dumpeasysrc(struct Configurable *config);
 
+#endif /* CURL_DISABLE_LIBCIRL_CMD */
+
 #endif /* HEADER_CURL_TOOL_EASYSRC_H */
 
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index bd7375f..d181666 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -738,8 +738,14 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
         config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
         break;
       case 'z': /* --libcurl */
+#ifdef CURL_DISABLE_LIBCURL_OPTION
+        warnf(config,
+              "--libcurl option was disabled at build-time!\n");
+        return PARAM_OPTION_UNKNOWN;
+#else
         GetStr(&config->libcurl, nextarg);
         break;
+#endif
       case '#': /* --raw */
         config->raw = toggle;
         break;
diff --git a/src/tool_help.c b/src/tool_help.c
index 7c7d8d3..2aff92e 100644
--- a/src/tool_help.c
+++ b/src/tool_help.c
@@ -110,7 +110,9 @@ static const char *const helptext[] = {
   "     --key KEY       Private key file name (SSL/SSH)",
   "     --key-type TYPE Private key file type (DER/PEM/ENG) (SSL)",
   "     --krb LEVEL     Enable Kerberos with specified security level (F)",
+#ifndef CURL_DISABLE_LIBCURL_OPTION
   "     --libcurl FILE  Dump libcurl equivalent code of this command line",
+#endif
   "     --limit-rate RATE  Limit transfer speed to this rate",
   " -l, --list-only     List only names of an FTP directory (F)",
   "     --local-port RANGE  Force use of these local port numbers",
diff --git a/src/tool_operate.c b/src/tool_operate.c
index a6f6f0b..547f949 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -333,6 +333,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
     }
   }
 
+#ifndef CURL_DISABLE_LIBCURL_OPTION
   /* This is the first entry added to easysrc and it initializes the slist */
   easysrc = curl_slist_append(easysrc, "CURL *hnd = curl_easy_init();");
   if(!easysrc) {
@@ -340,6 +341,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
     res = CURLE_OUT_OF_MEMORY;
     goto quit_curl;
   }
+#endif
 
   if(config->list_engines) {
     struct curl_slist *engines = NULL;
@@ -1212,10 +1214,12 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         retry_sleep = retry_sleep_default; /* ms */
         retrystart = tvnow();
 
+#ifndef CURL_DISABLE_LIBCURL_OPTION
         if(!curl_slist_append(easysrc, "ret = curl_easy_perform(hnd);")) {
           res = CURLE_OUT_OF_MEMORY;
           goto show_error;
         }
+#endif
 
         for(;;) {
           res = curl_easy_perform(curl);
@@ -1538,8 +1542,10 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
     curl_easy_cleanup(curl);
     config->easy = curl = NULL;
   }
+#ifndef CURL_DISABLE_LIBCURL_OPTION
   if(easysrc)
     curl_slist_append(easysrc, "curl_easy_cleanup(hnd);");
+#endif
 
   /* Close function-local opened file descriptors */
 
@@ -1551,10 +1557,12 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
   if(config->trace_fopened && config->trace_stream)
     fclose(config->trace_stream);
 
+#ifndef CURL_DISABLE_LIBCURL_OPTION
   /* Dump the libcurl code if previously enabled.
      NOTE: that this function relies on config->errors amongst other things
      so not everything can be closed and cleaned before this is called */
   dumpeasysrc(config);
+#endif
 
   if(config->errors_fopened && config->errors)
     fclose(config->errors);
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index b636aab..8613aa1 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -21,6 +21,8 @@
  ***************************************************************************/
 #include "setup.h"
 
+#ifndef CURL_DISABLE_LIBCURL_OPTION
+
 #include <curl/curl.h>
 
 #define ENABLE_CURLX_PRINTF
@@ -123,3 +125,4 @@ CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
   return ret;
 }
 
+#endif /* CURL_DISABLE_LIBCURL_OPTION */
diff --git a/src/tool_setopt.h b/src/tool_setopt.h
index d01c9eb..a2a1ff2 100644
--- a/src/tool_setopt.h
+++ b/src/tool_setopt.h
@@ -23,28 +23,47 @@
  ***************************************************************************/
 #include "setup.h"
 
-CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
-                     const char *name, CURLoption tag, ...);
-
 /*
  * Macros used in operate()
  */
 
-#define my_setopt(x,y,z)  do { \
-  res = tool_setopt(x, FALSE, config, #y, y, z); \
+#define SETOPT_CHECK(v) do { \
+  res = (v); \
   if(res) \
     goto show_error; \
 } WHILE_FALSE
 
-#define my_setopt_str(x,y,z)  do { \
-  res = tool_setopt(x, TRUE, config, #y, y, z); \
-  if(res) \
-    goto show_error; \
-} WHILE_FALSE
+#ifndef CURL_DISABLE_LIBCURL_OPTION
+
+/* Intercept setopt calls for --libcurl */
+
+CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config,
+                     const char *name, CURLoption tag, ...);
+
+#define my_setopt(x,y,z) \
+  SETOPT_CHECK(tool_setopt(x, FALSE, config, #y, y, z))
+
+#define my_setopt_str(x,y,z) \
+  SETOPT_CHECK(tool_setopt(x, TRUE, config, #y, y, z))
 
 #define res_setopt(x,y,z) tool_setopt(x, FALSE, config, #y, y, z)
 
 #define res_setopt_str(x,y,z) tool_setopt(x, TRUE, config, #y, y, z)
 
-#endif /* HEADER_CURL_TOOL_SETOPT_H */
+#else
+
+/* No --libcurl, so pass options directly to library */
+
+#define my_setopt(x,y,z) \
+  SETOPT_CHECK(curl_easy_setopt(x, y, z))
 
+#define my_setopt_str(x,y,z) \
+  SETOPT_CHECK(curl_easy_setopt(x, y, z))
+
+#define res_setopt(x,y,z) curl_easy_setopt(x,y,z)
+
+#define res_setopt_str(x,y,z) curl_easy_setopt(x,y,z)
+
+#endif /* CURL_DISABLE_LIBCURL_OPTION */
+
+#endif /* HEADER_CURL_TOOL_SETOPT_H */
-- 
1.6.5.6
--------------020809080108070900000903
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
--------------020809080108070900000903--
Received on 2001-09-17