From be73b2b4947015f23323ec168ba462e94a8c3fba Mon Sep 17 00:00:00 2001 From: bgraf Date: Sun, 28 Sep 2014 19:34:39 +0200 Subject: [PATCH] + CURLOPT_MAIL_FROM CURLOPT_MAIL_RCPT --- config.h.in | 8 +++++ configure | 26 ++++++++++++++++ configure.in | 1 + curl-helper.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curl.ml | 8 +++++ curl.mli | 4 +++ 6 files changed, 144 insertions(+) diff --git a/config.h.in b/config.h.in index 909db76..7ea8468 100644 --- a/config.h.in +++ b/config.h.in @@ -731,6 +731,14 @@ 0 if you don't. */ #undef HAVE_DECL_CURLOPT_LOW_SPEED_TIME +/* Define to 1 if you have the declaration of `CURLOPT_MAIL_FROM', and to 0 if + you don't. */ +#undef HAVE_DECL_CURLOPT_MAIL_FROM + +/* Define to 1 if you have the declaration of `CURLOPT_MAIL_RCPT', and to 0 if + you don't. */ +#undef HAVE_DECL_CURLOPT_MAIL_RCPT + /* Define to 1 if you have the declaration of `CURLOPT_MAXCONNECTS', and to 0 if you don't. */ #undef HAVE_DECL_CURLOPT_MAXCONNECTS diff --git a/configure b/configure index 8af4888..1953711 100755 --- a/configure +++ b/configure @@ -6486,6 +6486,32 @@ fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_CURLOPT_DNS_SERVERS $ac_have_decl _ACEOF +ac_fn_c_check_decl "$LINENO" "CURLOPT_MAIL_FROM" "ac_cv_have_decl_CURLOPT_MAIL_FROM" " +#include \"curl/curl.h\" + +" +if test "x$ac_cv_have_decl_CURLOPT_MAIL_FROM" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_CURLOPT_MAIL_FROM $ac_have_decl +_ACEOF +ac_fn_c_check_decl "$LINENO" "CURLOPT_MAIL_RCPT" "ac_cv_have_decl_CURLOPT_MAIL_RCPT" " +#include \"curl/curl.h\" + +" +if test "x$ac_cv_have_decl_CURLOPT_MAIL_RCPT" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_CURLOPT_MAIL_RCPT $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.in b/configure.in index 6c3106f..20cfe90 100644 --- a/configure.in +++ b/configure.in @@ -86,6 +86,7 @@ CURLOPT_NEW_FILE_PERMS, CURLOPT_NEW_DIRECTORY_PERMS, CURLOPT_POST301, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, CURLOPT_COPYPOSTFIELDS, CURLOPT_PROXY_TRANSFER_MODE, CURLOPT_SEEKFUNCTION, CURLOPT_OPENSOCKETFUNCTION, CURLOPT_PROTOCOLS, CURLOPT_REDIR_PROTOCOLS, CURLOPT_RESOLVE, CURLOPT_DNS_SERVERS, +CURLOPT_MAIL_FROM, CURLOPT_MAIL_RCPT, 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 b86d7f5..c85fa95 100644 --- a/curl-helper.c +++ b/curl-helper.c @@ -116,6 +116,9 @@ enum OcamlValues OcamlDNSServers, + OcamlMailFrom, + OcamlMailRcpt, + /* Not used, last for size */ OcamlValuesSize }; @@ -176,6 +179,8 @@ struct Connection char *sshHostPublicKeyMD5; char *copyPostFields; char *dns_servers; + char *mailFrom; + struct curl_slist *mailRcpt; }; struct ConnectionList @@ -747,6 +752,8 @@ static void handleProtocols(Connection *, value); static void handleRedirProtocols(Connection *, value); static void handleResolve(Connection *, value); static void handleDnsServers(Connection *, value); +static void handleMailFrom(Connection *, value); +static void handleMailRcpt(Connection *, value); CURLOptionMapping implementedOptionMap[] = { @@ -1102,6 +1109,16 @@ CURLOptionMapping implementedOptionMap[] = #else {handleDnsServers, "CURLOPT_DNS_SERVERS", 0}, #endif +#if HAVE_DECL_CURLOPT_MAIL_FROM + {handleMailFrom, "CURLOPT_MAIL_FROM", CURLOPT_MAIL_FROM}, +#else + {handleMailFrom, "CURLOPT_MAIL_FROM", 0}, +#endif +#if HAVE_DECL_CURLOPT_MAIL_RCPT + {handleMailRcpt, "CURLOPT_MAIL_RCPT", CURLOPT_MAIL_RCPT}, +#else + {handleMailRcpt, "CURLOPT_MAIL_RCPT", 0}, +#endif }; static char *findOption(CURLOptionMapping optionMap[], @@ -1237,6 +1254,8 @@ static Connection* allocConnection(CURL* h) connection->copyPostFields = NULL; connection->resolve = NULL; connection->dns_servers = NULL; + connection->mailFrom = NULL; + connection->mailRcpt = NULL; return connection; } @@ -1418,6 +1437,14 @@ static Connection *duplicateConnection(Connection *original) handleDnsServers(connection, Field(original->ocamlValues, OcamlDNSServers)); + if (Field(original->ocamlValues, OcamlMailFrom) != Val_unit) + handleMailFrom(connection, + Field(original->ocamlValues, + OcamlMailFrom)); + if (Field(original->ocamlValues, OcamlMailRcpt) != Val_unit) + handleMailRcpt(connection, + Field(original->ocamlValues, + OcamlMailRcpt)); return connection; } @@ -1508,6 +1535,8 @@ static void removeConnection(Connection *connection, int finalization) free_if(connection->sshPrivateKeyFile); free_if(connection->copyPostFields); free_if(connection->dns_servers); + free_if(connection->mailFrom); + free_curl_slist(connection->mailRcpt); } #if 1 @@ -5525,6 +5554,74 @@ static void handleDnsServers(Connection *conn, value option) } #endif +#if HAVE_DECL_CURLOPT_MAIL_FROM +static void handleMailFrom(Connection *conn, value option) +{ + CAMLparam1(option); + CURLcode result = CURLE_OK; + + Store_field(conn->ocamlValues, OcamlMailFrom, option); + + if (conn->mailFrom != NULL) + free(conn->mailFrom); + + conn->mailFrom = strdup(String_val(option)); + + result = curl_easy_setopt(conn->connection, + CURLOPT_MAIL_FROM, + conn->mailFrom); + + if (result != CURLE_OK) + raiseError(conn, result); + + CAMLreturn0; +} +#else +#pragma message("libcurl does not implement CURLOPT_MAIL_FROM") +static void handleMailFrom(Connection *conn, value option) +{ + failwith("libcurl does not implement CURLOPT_MAIL_FROM"); +} +#endif + +#if HAVE_DECL_CURLOPT_MAIL_RCPT +static void handleMailRcpt(Connection *conn, value option) +{ + CAMLparam1(option); + CAMLlocal1(listIter); + CURLcode result = CURLE_OK; + + Store_field(conn->ocamlValues, OcamlMailRcpt, option); + + free_curl_slist(conn->mailRcpt); + conn->mailRcpt = NULL; + + listIter = option; + + while (Val_emptylist != listIter) + { + conn->mailRcpt = curl_slist_append(conn->mailRcpt, String_val(Field(listIter, 0))); + + listIter = Field(listIter, 1); + } + + result = curl_easy_setopt(conn->connection, + CURLOPT_MAIL_RCPT, + conn->mailRcpt); + + if (result != CURLE_OK) + raiseError(conn, result); + + CAMLreturn0; +} +#else +#pragma message("libcurl does not implement CURLOPT_MAIL_RCPT") +static void handleMailRcpt(Connection *conn, value option) +{ + failwith("libcurl does not implement CURLOPT_MAIL_RCPT"); +} +#endif + /** ** curl_easy_setopt helper function **/ diff --git a/curl.ml b/curl.ml index 026a80a..2f322b4 100644 --- a/curl.ml +++ b/curl.ml @@ -395,6 +395,8 @@ type curlOption = | CURLOPT_REDIR_PROTOCOLS of curlProto list | CURLOPT_RESOLVE of string list | CURLOPT_DNS_SERVERS of string + | CURLOPT_MAIL_FROM of string + | CURLOPT_MAIL_RCPT of string list type initOption = | CURLINIT_GLOBALALL @@ -919,6 +921,12 @@ let set_resolve conn l_add l_del = let set_dns_servers conn l = setopt conn (CURLOPT_DNS_SERVERS (String.concat "," l)) +let set_mailfrom conn l = + setopt conn (CURLOPT_MAIL_FROM l) + +let set_mailrcpt conn l = + setopt conn (CURLOPT_MAIL_RCPT 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 62839a2..4240c46 100644 --- a/curl.mli +++ b/curl.mli @@ -399,6 +399,8 @@ type curlOption = | CURLOPT_REDIR_PROTOCOLS of curlProto list | CURLOPT_RESOLVE of string list | CURLOPT_DNS_SERVERS of string + | CURLOPT_MAIL_FROM of string + | CURLOPT_MAIL_RCPT of string list type initOption = | CURLINIT_GLOBALALL @@ -638,6 +640,8 @@ val set_redirprotocols : t -> curlProto list -> unit *) val set_resolve : t -> (string * int * string) list -> (string * int) list -> unit val set_dns_servers : t -> string list -> unit +val set_mailfrom : t -> string -> unit +val set_mailrcpt : t -> string list -> unit (** {2 Get transfer properties} *) -- 2.11.4.GIT