From 53476be643a799c119ec492b893c4a53c93f024e Mon Sep 17 00:00:00 2001 From: ygrek Date: Tue, 9 Jan 2018 17:02:48 -0500 Subject: [PATCH] + CURLOPT_POSTREDIR --- CHANGES.txt | 4 ++++ config.h.in | 4 ++++ configure | 13 +++++++++++++ configure.ac | 1 + curl-helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ curl.ml | 11 +++++++++++ curl.mli | 10 ++++++++++ 7 files changed, 87 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 7f0d951..6db8f2e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +0.8.1 - + + + CURLOPT_POSTREDIR + 0.8.0 - 28 Nov 2017 * fix build on Windows/msvc (Nicolas Ojeda Bar) diff --git a/config.h.in b/config.h.in index 467a1c3..1eee32a 100644 --- a/config.h.in +++ b/config.h.in @@ -875,6 +875,10 @@ you don't. */ #undef HAVE_DECL_CURLOPT_POSTQUOTE +/* Define to 1 if you have the declaration of `CURLOPT_POSTREDIR', and to 0 if + you don't. */ +#undef HAVE_DECL_CURLOPT_POSTREDIR + /* Define to 1 if you have the declaration of `CURLOPT_PREQUOTE', and to 0 if you don't. */ #undef HAVE_DECL_CURLOPT_PREQUOTE diff --git a/configure b/configure index c3e23e7..d7b5cee 100755 --- a/configure +++ b/configure @@ -6775,6 +6775,19 @@ fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_CURLOPT_CONNECT_TO $ac_have_decl _ACEOF +ac_fn_c_check_decl "$LINENO" "CURLOPT_POSTREDIR" "ac_cv_have_decl_CURLOPT_POSTREDIR" " +#include \"curl/curl.h\" + +" +if test "x$ac_cv_have_decl_CURLOPT_POSTREDIR" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_CURLOPT_POSTREDIR $ac_have_decl +_ACEOF ac_fn_c_check_decl "$LINENO" "CURLINFO_EFFECTIVE_URL" "ac_cv_have_decl_CURLINFO_EFFECTIVE_URL" " #include \"curl/curl.h\" diff --git a/configure.ac b/configure.ac index e640ea5..028445f 100644 --- a/configure.ac +++ b/configure.ac @@ -135,6 +135,7 @@ CURLOPT_PROXY_TRANSFER_MODE, CURLOPT_SEEKFUNCTION, CURLOPT_OPENSOCKETFUNCTION, CURLOPT_PROTOCOLS, CURLOPT_REDIR_PROTOCOLS, CURLOPT_RESOLVE, CURLOPT_DNS_SERVERS, CURLOPT_MAIL_FROM, CURLOPT_MAIL_RCPT, CURLOPT_PIPEWAIT, CURLOPT_CERTINFO, CURLOPT_USERNAME, CURLOPT_PASSWORD, CURLOPT_LOGIN_OPTIONS, CURLOPT_CONNECT_TO, +CURLOPT_POSTREDIR, CURLINFO_EFFECTIVE_URL, CURLINFO_RESPONSE_CODE, CURLINFO_TOTAL_TIME, CURLINFO_NAMELOOKUP_TIME, CURLINFO_CONNECT_TIME, CURLINFO_PRETRANSFER_TIME, diff --git a/curl-helper.c b/curl-helper.c index 2f1b0e8..fef756c 100644 --- a/curl-helper.c +++ b/curl-helper.c @@ -133,6 +133,7 @@ typedef enum OcamlValues Ocaml_PASSWORD, Ocaml_LOGIN_OPTIONS, Ocaml_CONNECT_TO, + Ocaml_POSTREDIR, /* Not used, last for size */ OcamlValuesSize @@ -2623,6 +2624,44 @@ SETOPT_STRING( LOGIN_OPTIONS) SETOPT_SLIST( CONNECT_TO) #endif +#if HAVE_DECL_CURLOPT_POSTREDIR + +static int curlPostRedir_table[] = { + CURL_REDIR_POST_ALL, +#if defined(CURL_REDIR_POST_301) + CURL_REDIR_POST_301, +#else + 0, +#endif +#if defined(CURL_REDIR_POST_302) + CURL_REDIR_POST_302, +#else + 0, +#endif +#if defined(CURL_REDIR_POST_303) + CURL_REDIR_POST_303, +#else + 0, +#endif +}; + +static void handle_POSTREDIR(Connection *conn, value option) +{ + CAMLparam1(option); + CURLcode result = CURLE_OK; + long bitmask = caml_convert_flag_list(option, curlPostRedir_table); + + result = curl_easy_setopt(conn->handle, + CURLOPT_POSTREDIR, + bitmask); + + if (result != CURLE_OK) + raiseError(conn, result); + + CAMLreturn0; +} +#endif + /** ** curl_easy_setopt helper function **/ @@ -3022,6 +3061,11 @@ CURLOptionMapping implementedOptionMap[] = #else MAP_NO(CONNECT_TO), #endif +#if HAVE_DECL_CURLOPT_POSTREDIR + MAP(POSTREDIR), +#else + MAP_NO(POSTREDIR), +#endif }; static Connection *duplicateConnection(Connection *original) diff --git a/curl.ml b/curl.ml index cc2843a..dc3617d 100644 --- a/curl.ml +++ b/curl.ml @@ -275,6 +275,13 @@ type curlProto = | CURLPROTO_RTMPTS | CURLPROTO_GOPHER +(* sync curlPostRedir_table *) +type curlPostRedir = +| REDIR_POST_ALL +| REDIR_POST_301 +| REDIR_POST_302 +| REDIR_POST_303 + type curlOption = | CURLOPT_WRITEFUNCTION of (string -> int) | CURLOPT_READFUNCTION of (int -> string) @@ -416,6 +423,7 @@ type curlOption = | CURLOPT_PASSWORD of string | CURLOPT_LOGIN_OPTIONS of string | CURLOPT_CONNECT_TO of string list + | CURLOPT_POSTREDIR of curlPostRedir list type initOption = | CURLINIT_GLOBALALL @@ -933,6 +941,9 @@ let set_login_options conn s = let set_connect_to conn l = setopt conn (CURLOPT_CONNECT_TO l) +let set_postredir conn l = + setopt conn (CURLOPT_POSTREDIR l) + let get_effectiveurl conn = match (getinfo conn CURLINFO_EFFECTIVE_URL) with | CURLINFO_String s -> s diff --git a/curl.mli b/curl.mli index 32a386b..1779271 100644 --- a/curl.mli +++ b/curl.mli @@ -283,6 +283,13 @@ type curlProto = | CURLPROTO_RTMPTS | CURLPROTO_GOPHER +(** if flag is not supported by libcurl - enabling it does nothing *) +type curlPostRedir = +| REDIR_POST_ALL +| REDIR_POST_301 +| REDIR_POST_302 +| REDIR_POST_303 (** added in libcurl 7.26.0 *) + type curlOption = | CURLOPT_WRITEFUNCTION of (string -> int) | CURLOPT_READFUNCTION of (int -> string) @@ -424,6 +431,7 @@ type curlOption = | CURLOPT_PASSWORD of string | CURLOPT_LOGIN_OPTIONS of string | CURLOPT_CONNECT_TO of string list + | CURLOPT_POSTREDIR of curlPostRedir list type initOption = | CURLINIT_GLOBALALL @@ -678,6 +686,8 @@ val set_login_options : t -> string -> unit (** @since 0.8.0 *) val set_connect_to : t -> string list -> unit (** @since 0.8.0 *) +val set_postredir : t -> curlPostRedir list -> unit +(** @since 0.8.1 *) (** {2 Get transfer properties} *) -- 2.11.4.GIT