diff -urx version.c curl-7.15.6-20060814/docs/libcurl/curl_easy_setopt.3 curlinux/docs/libcurl/curl_easy_setopt.3 --- curl-7.15.6-20060814/docs/libcurl/curl_easy_setopt.3 2006-08-09 22:00:17.000000000 -0400 +++ curlinux/docs/libcurl/curl_easy_setopt.3 2006-08-14 15:49:51.952328000 -0400 @@ -166,6 +166,15 @@ Pass a pointer that will be untouched by libcurl and passed as the 3rd argument in the ioctl callback set with \fICURLOPT_IOCTLFUNCTION\fP. (Option added in 7.12.3) +.IP CURLOPT_SOCKOPTFUNCTION +Function pointer that should match the following prototype: +\fBint function(curl_socket_t curlfd);\fP +This function gets called by libcurl after the socket() call but before the +connect() call. It passes the newly created socket descriptor so additional +setsockopt() calls can be done at the user's discretion. A non-zero return +code from the callback function will signal an unrecoverable error to the +library and it will close the socket and return \fICURLE_COULDNT_CONNECT\fP. +(Option added in 7.15.6.) .IP CURLOPT_PROGRESSFUNCTION Function pointer that should match the \fIcurl_progress_callback\fP prototype found in \fI\fP. This function gets called by libcurl instead of diff -urx version.c curl-7.15.6-20060814/include/curl/curl.h curlinux/include/curl/curl.h --- curl-7.15.6-20060814/include/curl/curl.h 2006-08-04 22:00:23.000000000 -0400 +++ curlinux/include/curl/curl.h 2006-08-14 15:49:51.792328000 -0400 @@ -133,6 +133,47 @@ #undef FILESIZEBITS #endif +#if defined(_WIN32) && !defined(WIN32) +/* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we + make this adjustment to catch this. */ +#define WIN32 1 +#endif + +#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) && \ + !defined(__CYGWIN__) || defined(__MINGW32__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include +#endif +#else + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on system that are known to + require it! */ +#if defined(_AIX) || defined(NETWARE) || defined(__NetBSD__) || defined(__minix) +#include +#endif + +#ifndef _WIN32_WCE +#include +#endif +#include +#include +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#ifdef WIN32 +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + struct curl_httppost { struct curl_httppost *next; /* next entry in the list */ char *name; /* pointer to allocated name */ @@ -184,6 +225,7 @@ size_t nitems, void *instream); +typedef int (*curl_sockopt_callback)(curl_socket_t curlfd); #ifndef CURL_NO_OLDIES /* not used since 7.10.8, will be removed in a future release */ @@ -982,6 +1024,9 @@ /* Pointer to command string to send if USER/PASS fails. */ CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147), + /* callback function for setting socket options */ + CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), + CURLOPT_LASTENTRY /* the last unused */ } CURLoption; diff -urx version.c curl-7.15.6-20060814/include/curl/multi.h curlinux/include/curl/multi.h --- curl-7.15.6-20060814/include/curl/multi.h 2006-08-11 22:00:18.000000000 -0400 +++ curlinux/include/curl/multi.h 2006-08-14 15:49:51.802328000 -0400 @@ -37,34 +37,6 @@ file descriptors simultaneous easily. */ -#if defined(_WIN32) && !defined(WIN32) -/* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we - make this adjustment to catch this. */ -#define WIN32 1 -#endif - -#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) && \ - !defined(__CYGWIN__) || defined(__MINGW32__) -#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H)) -/* The check above prevents the winsock2 inclusion if winsock.h already was - included, since they can't co-exist without problems */ -#include -#endif -#else - -/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish - libc5-based Linux systems. Only include it on system that are known to - require it! */ -#if defined(_AIX) || defined(NETWARE) || defined(__NetBSD__) || defined(__minix) -#include -#endif - -#ifndef _WIN32_WCE -#include -#endif -#include -#include -#endif /* * This header file should not really need to include "curl.h" since curl.h @@ -83,18 +55,6 @@ typedef void CURLM; -#ifndef curl_socket_typedef -/* Public socket typedef */ -#ifdef WIN32 -typedef SOCKET curl_socket_t; -#define CURL_SOCKET_BAD INVALID_SOCKET -#else -typedef int curl_socket_t; -#define CURL_SOCKET_BAD -1 -#endif -#define curl_socket_typedef -#endif /* curl_socket_typedef */ - typedef enum { CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or curl_multi_socket*() soon */ diff -urx version.c curl-7.15.6-20060814/lib/connect.c curlinux/lib/connect.c --- curl-7.15.6-20060814/lib/connect.c 2006-07-21 22:00:29.000000000 -0400 +++ curlinux/lib/connect.c 2006-08-14 15:49:51.142328000 -0400 @@ -702,6 +702,15 @@ nosigpipe(conn, sockfd); + if(data->set.fsockopt) { + /* activate callback for setting socket options */ + error = data->set.fsockopt(sockfd); + if (error) { + sclose(sockfd); /* close the socket and bail out */ + return CURL_SOCKET_BAD; + } + } + /* possibly bind the local end to an IP, interface or port */ res = bindlocal(conn, sockfd); if(res) { diff -urx version.c curl-7.15.6-20060814/lib/easy.c curlinux/lib/easy.c --- curl-7.15.6-20060814/lib/easy.c 2006-07-25 22:00:42.000000000 -0400 +++ curlinux/lib/easy.c 2006-08-14 15:49:51.142328000 -0400 @@ -635,6 +635,9 @@ /* zero out Progress data: */ memset(&data->progress, 0, sizeof(struct Progress)); + /* remove any CURLOPT_SOCKOPTFUNCTION callback function */ + data->set.fsockopt = (curl_sockopt_callback)0; + /* The remainder of these calls have been taken from Curl_open() */ data->set.out = stdout; /* default output to stdout */ diff -urx version.c curl-7.15.6-20060814/lib/setup.h curlinux/lib/setup.h --- curl-7.15.6-20060814/lib/setup.h 2006-08-03 22:00:18.000000000 -0400 +++ curlinux/lib/setup.h 2006-08-14 15:49:51.152328000 -0400 @@ -278,19 +278,6 @@ #endif /* WIN32 */ -#ifndef curl_socket_typedef -/* now typedef our socket type */ -#ifdef WIN32 -typedef SOCKET curl_socket_t; -#define CURL_SOCKET_BAD INVALID_SOCKET -#else -typedef int curl_socket_t; -#define CURL_SOCKET_BAD -1 -#endif -#define curl_socket_typedef -#endif /* curl_socket_typedef */ - - #if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \ !defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */ #ifdef ENABLE_IPV6 diff -urx version.c curl-7.15.6-20060814/lib/url.c curlinux/lib/url.c --- curl-7.15.6-20060814/lib/url.c 2006-07-31 22:00:18.000000000 -0400 +++ curlinux/lib/url.c 2006-08-14 15:49:51.132328000 -0400 @@ -1551,6 +1551,13 @@ data->set.ftp_alternative_to_user = va_arg(param, char *); break; + case CURLOPT_SOCKOPTFUNCTION: + /* + * socket callback function: called after socket() but before connect() + */ + data->set.fsockopt = va_arg(param, curl_sockopt_callback); + break; + default: /* unknown tag and its companion, just ignore: */ result = CURLE_FAILED_INIT; /* correct this */ diff -urx version.c curl-7.15.6-20060814/lib/urldata.h curlinux/lib/urldata.h --- curl-7.15.6-20060814/lib/urldata.h 2006-08-08 22:00:18.000000000 -0400 +++ curlinux/lib/urldata.h 2006-08-14 15:49:51.152328000 -0400 @@ -1027,6 +1027,7 @@ curl_progress_callback fprogress; /* function for progress information */ curl_debug_callback fdebug; /* function that write informational data */ curl_ioctl_callback ioctl; /* function for I/O control */ + curl_sockopt_callback fsockopt; /* function for setting socket options */ /* the 3 curl_conv_callback functions below are used on non-ASCII hosts */ /* function to convert from the network encoding: */