tool_setopt.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef HEADER_CURL_TOOL_SETOPT_H
  2. #define HEADER_CURL_TOOL_SETOPT_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "tool_setup.h"
  25. #include "tool_formparse.h"
  26. /*
  27. * Macros used in operate()
  28. */
  29. #define SETOPT_CHECK(v,opt) do { \
  30. if(!tool_setopt_skip(opt)) { \
  31. result = (v); \
  32. if(result) \
  33. break; \
  34. } \
  35. } while(0)
  36. /* allow removed features to simulate success: */
  37. bool tool_setopt_skip(CURLoption tag);
  38. #ifndef CURL_DISABLE_LIBCURL_OPTION
  39. /* Associate symbolic names with option values */
  40. struct NameValue {
  41. const char *name;
  42. long value;
  43. };
  44. struct NameValueUnsigned {
  45. const char *name;
  46. unsigned long value;
  47. };
  48. extern const struct NameValue setopt_nv_CURLPROXY[];
  49. extern const struct NameValue setopt_nv_CURL_SOCKS_PROXY[];
  50. extern const struct NameValue setopt_nv_CURL_HTTP_VERSION[];
  51. extern const struct NameValue setopt_nv_CURL_SSLVERSION[];
  52. extern const struct NameValue setopt_nv_CURL_TIMECOND[];
  53. extern const struct NameValue setopt_nv_CURLFTPSSL_CCC[];
  54. extern const struct NameValue setopt_nv_CURLUSESSL[];
  55. extern const struct NameValueUnsigned setopt_nv_CURLSSLOPT[];
  56. extern const struct NameValue setopt_nv_CURL_NETRC[];
  57. extern const struct NameValue setopt_nv_CURLPROTO[];
  58. extern const struct NameValueUnsigned setopt_nv_CURLAUTH[];
  59. extern const struct NameValueUnsigned setopt_nv_CURLHSTS[];
  60. /* Map options to NameValue sets */
  61. #define setopt_nv_CURLOPT_HSTS_CTRL setopt_nv_CURLHSTS
  62. #define setopt_nv_CURLOPT_HTTP_VERSION setopt_nv_CURL_HTTP_VERSION
  63. #define setopt_nv_CURLOPT_HTTPAUTH setopt_nv_CURLAUTH
  64. #define setopt_nv_CURLOPT_SSLVERSION setopt_nv_CURL_SSLVERSION
  65. #define setopt_nv_CURLOPT_PROXY_SSLVERSION setopt_nv_CURL_SSLVERSION
  66. #define setopt_nv_CURLOPT_TIMECONDITION setopt_nv_CURL_TIMECOND
  67. #define setopt_nv_CURLOPT_FTP_SSL_CCC setopt_nv_CURLFTPSSL_CCC
  68. #define setopt_nv_CURLOPT_USE_SSL setopt_nv_CURLUSESSL
  69. #define setopt_nv_CURLOPT_SSL_OPTIONS setopt_nv_CURLSSLOPT
  70. #define setopt_nv_CURLOPT_PROXY_SSL_OPTIONS setopt_nv_CURLSSLOPT
  71. #define setopt_nv_CURLOPT_NETRC setopt_nv_CURL_NETRC
  72. #define setopt_nv_CURLOPT_PROTOCOLS setopt_nv_CURLPROTO
  73. #define setopt_nv_CURLOPT_REDIR_PROTOCOLS setopt_nv_CURLPROTO
  74. #define setopt_nv_CURLOPT_PROXYTYPE setopt_nv_CURLPROXY
  75. #define setopt_nv_CURLOPT_PROXYAUTH setopt_nv_CURLAUTH
  76. #define setopt_nv_CURLOPT_SOCKS5_AUTH setopt_nv_CURLAUTH
  77. /* Intercept setopt calls for --libcurl */
  78. CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
  79. const char *name, CURLoption tag,
  80. const struct NameValue *nv, long lval);
  81. CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
  82. const char *name, CURLoption tag,
  83. const struct NameValue *nv, long lval);
  84. CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
  85. const char *name, CURLoption tag,
  86. const struct NameValueUnsigned *nv, long lval);
  87. CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
  88. const char *name, CURLoption tag,
  89. curl_mime *mimepost);
  90. CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
  91. const char *name, CURLoption tag,
  92. struct curl_slist *list);
  93. CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
  94. struct OperationConfig *config,
  95. const char *name, CURLoption tag, ...);
  96. #define my_setopt(x,y,z) \
  97. SETOPT_CHECK(tool_setopt(x, FALSE, global, config, #y, y, z), y)
  98. #define my_setopt_str(x,y,z) \
  99. SETOPT_CHECK(tool_setopt(x, TRUE, global, config, #y, y, z), y)
  100. #define my_setopt_enum(x,y,z) \
  101. SETOPT_CHECK(tool_setopt_enum(x, global, #y, y, setopt_nv_ ## y, z), y)
  102. #define my_setopt_flags(x,y,z) \
  103. SETOPT_CHECK(tool_setopt_flags(x, global, #y, y, setopt_nv_ ## y, z), y)
  104. #define my_setopt_bitmask(x,y,z) \
  105. SETOPT_CHECK(tool_setopt_bitmask(x, global, #y, y, setopt_nv_ ## y, z), y)
  106. #define my_setopt_mimepost(x,y,z) \
  107. SETOPT_CHECK(tool_setopt_mimepost(x, global, #y, y, z), y)
  108. #define my_setopt_slist(x,y,z) \
  109. SETOPT_CHECK(tool_setopt_slist(x, global, #y, y, z), y)
  110. #define res_setopt(x,y,z) tool_setopt(x, FALSE, global, config, #y, y, z)
  111. #define res_setopt_str(x,y,z) tool_setopt(x, TRUE, global, config, #y, y, z)
  112. #else /* CURL_DISABLE_LIBCURL_OPTION */
  113. /* No --libcurl, so pass options directly to library */
  114. #define my_setopt(x,y,z) \
  115. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  116. #define my_setopt_str(x,y,z) \
  117. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  118. #define my_setopt_enum(x,y,z) \
  119. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  120. #define my_setopt_flags(x,y,z) \
  121. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  122. #define my_setopt_bitmask(x,y,z) \
  123. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  124. #define my_setopt_mimepost(x,y,z) \
  125. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  126. #define my_setopt_slist(x,y,z) \
  127. SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
  128. #define res_setopt(x,y,z) curl_easy_setopt(x,y,z)
  129. #define res_setopt_str(x,y,z) curl_easy_setopt(x,y,z)
  130. #endif /* CURL_DISABLE_LIBCURL_OPTION */
  131. #endif /* HEADER_CURL_TOOL_SETOPT_H */