mirror of
https://github.com/curl/curl.git
synced 2025-09-20 19:12:40 +03:00
David McCreedy added CURLOPT_SOCKOPTFUNCTION and CURLOPT_SOCKOPTDATA to
allow applications to set their own socket options.
This commit is contained in:
parent
2ff609dd43
commit
5acadc9cd7
4
CHANGES
4
CHANGES
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
Daniel (29 August 2006)
|
||||||
|
- David McCreedy added CURLOPT_SOCKOPTFUNCTION and CURLOPT_SOCKOPTDATA to
|
||||||
|
allow applications to set their own socket options.
|
||||||
|
|
||||||
Daniel (25 August 2006)
|
Daniel (25 August 2006)
|
||||||
- Armel Asselin reported that the 'running_handles' counter wasn't updated
|
- Armel Asselin reported that the 'running_handles' counter wasn't updated
|
||||||
properly if you removed a "live" handle from a multi handle with
|
properly if you removed a "live" handle from a multi handle with
|
||||||
|
|
|
@ -3,7 +3,7 @@ Curl and libcurl 7.15.6
|
||||||
Public curl release number: 96
|
Public curl release number: 96
|
||||||
Releases counted from the very beginning: 123
|
Releases counted from the very beginning: 123
|
||||||
Available command line options: 114
|
Available command line options: 114
|
||||||
Available curl_easy_setopt() options: 133
|
Available curl_easy_setopt() options: 135
|
||||||
Number of public functions in libcurl: 54
|
Number of public functions in libcurl: 54
|
||||||
Amount of public web site mirrors: 33
|
Amount of public web site mirrors: 33
|
||||||
Number of known libcurl bindings: 32
|
Number of known libcurl bindings: 32
|
||||||
|
@ -11,12 +11,13 @@ Curl and libcurl 7.15.6
|
||||||
|
|
||||||
This release includes the following changes:
|
This release includes the following changes:
|
||||||
|
|
||||||
|
o CURLOPT_SOCKOPTFUNCTION and CURLOPT_SOCKOPTDATA were added
|
||||||
o (FTP) libcurl avoids sending TYPE if the desired type was already set
|
o (FTP) libcurl avoids sending TYPE if the desired type was already set
|
||||||
o (FTP) CURLOPT_PREQUOTE works even when CURLOPT_NOBODY is set true
|
o (FTP) CURLOPT_PREQUOTE works even when CURLOPT_NOBODY is set true
|
||||||
|
|
||||||
This release includes the following bugfixes:
|
This release includes the following bugfixes:
|
||||||
|
|
||||||
o running_handles' counter wasn't always updated properly when
|
o the 'running_handles' counter wasn't always updated properly when
|
||||||
curl_multi_remove_handle() was used
|
curl_multi_remove_handle() was used
|
||||||
o (FTP) EPRT transfers with IPv6 didn't work properly
|
o (FTP) EPRT transfers with IPv6 didn't work properly
|
||||||
o (FTP) SINGLECWD mode and using files in the root dir
|
o (FTP) SINGLECWD mode and using files in the root dir
|
||||||
|
|
|
@ -160,12 +160,28 @@ found in \fI<curl/curl.h>\fP. This function gets called by libcurl when
|
||||||
something special I/O-related needs to be done that the library can't do by
|
something special I/O-related needs to be done that the library can't do by
|
||||||
itself. For now, rewinding the read data stream is the only action it can
|
itself. For now, rewinding the read data stream is the only action it can
|
||||||
request. The rewinding of the read data stream may be necessary when doing a
|
request. The rewinding of the read data stream may be necessary when doing a
|
||||||
HTTP PUT or POST with a multi-pass authentication method. (Opion added in
|
HTTP PUT or POST with a multi-pass authentication method. (Option added in
|
||||||
7.12.3)
|
7.12.3)
|
||||||
.IP CURLOPT_IOCTLDATA
|
.IP CURLOPT_IOCTLDATA
|
||||||
Pass a pointer that will be untouched by libcurl and passed as the 3rd
|
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
|
argument in the ioctl callback set with \fICURLOPT_IOCTLFUNCTION\fP. (Option
|
||||||
added in 7.12.3)
|
added in 7.12.3)
|
||||||
|
.IP CURLOPT_SOCKOPTFUNCTION
|
||||||
|
Function pointer that should match the \fIcurl_sockopt_callback\fP prototype
|
||||||
|
found in \fI<curl/curl.h>\fP. This function gets called by libcurl after the
|
||||||
|
socket() call but before the connect() call. The callback's \fIpurpose\fP
|
||||||
|
argument identifies the exact purpose for this particular socket, and
|
||||||
|
currently only one value is supported: \fICURLSOCKTYPE_IPCXN\fP for the
|
||||||
|
primary connection (meaning the control connection in the FTP case). Future
|
||||||
|
versions of libcurl may support more purposes. 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_SOCKOPTDATA
|
||||||
|
Pass a pointer that will be untouched by libcurl and passed as the first
|
||||||
|
argument in the sockopt callback set with \fICURLOPT_SOCKOPTFUNCTION\fP.
|
||||||
|
(Option added in 7.15.6.)
|
||||||
.IP CURLOPT_PROGRESSFUNCTION
|
.IP CURLOPT_PROGRESSFUNCTION
|
||||||
Function pointer that should match the \fIcurl_progress_callback\fP prototype
|
Function pointer that should match the \fIcurl_progress_callback\fP prototype
|
||||||
found in \fI<curl/curl.h>\fP. This function gets called by libcurl instead of
|
found in \fI<curl/curl.h>\fP. This function gets called by libcurl instead of
|
||||||
|
|
|
@ -133,6 +133,47 @@ extern "C" {
|
||||||
#undef FILESIZEBITS
|
#undef FILESIZEBITS
|
||||||
#endif
|
#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 <winsock2.h>
|
||||||
|
#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 <sys/select.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32_WCE
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#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 {
|
||||||
struct curl_httppost *next; /* next entry in the list */
|
struct curl_httppost *next; /* next entry in the list */
|
||||||
char *name; /* pointer to allocated name */
|
char *name; /* pointer to allocated name */
|
||||||
|
@ -184,6 +225,14 @@ typedef size_t (*curl_read_callback)(char *buffer,
|
||||||
size_t nitems,
|
size_t nitems,
|
||||||
void *instream);
|
void *instream);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */
|
||||||
|
CURLSOCKTYPE_LAST /* never use */
|
||||||
|
} curlsocktype;
|
||||||
|
|
||||||
|
typedef int (*curl_sockopt_callback)(void *clientp,
|
||||||
|
curl_socket_t curlfd,
|
||||||
|
curlsocktype purpose);
|
||||||
|
|
||||||
#ifndef CURL_NO_OLDIES
|
#ifndef CURL_NO_OLDIES
|
||||||
/* not used since 7.10.8, will be removed in a future release */
|
/* not used since 7.10.8, will be removed in a future release */
|
||||||
|
@ -982,6 +1031,10 @@ typedef enum {
|
||||||
/* Pointer to command string to send if USER/PASS fails. */
|
/* Pointer to command string to send if USER/PASS fails. */
|
||||||
CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147),
|
CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147),
|
||||||
|
|
||||||
|
/* callback function for setting socket options */
|
||||||
|
CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148),
|
||||||
|
CINIT(SOCKOPTDATA, OBJECTPOINT, 149),
|
||||||
|
|
||||||
CURLOPT_LASTENTRY /* the last unused */
|
CURLOPT_LASTENTRY /* the last unused */
|
||||||
} CURLoption;
|
} CURLoption;
|
||||||
|
|
||||||
|
|
|
@ -37,34 +37,6 @@
|
||||||
file descriptors simultaneous easily.
|
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 <winsock2.h>
|
|
||||||
#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 <sys/select.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This header file should not really need to include "curl.h" since curl.h
|
* This header file should not really need to include "curl.h" since curl.h
|
||||||
|
@ -83,18 +55,6 @@ extern "C" {
|
||||||
|
|
||||||
typedef void CURLM;
|
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 {
|
typedef enum {
|
||||||
CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
|
CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
|
||||||
curl_multi_socket*() soon */
|
curl_multi_socket*() soon */
|
||||||
|
|
|
@ -702,6 +702,17 @@ singleipconnect(struct connectdata *conn,
|
||||||
|
|
||||||
nosigpipe(conn, sockfd);
|
nosigpipe(conn, sockfd);
|
||||||
|
|
||||||
|
if(data->set.fsockopt) {
|
||||||
|
/* activate callback for setting socket options */
|
||||||
|
error = data->set.fsockopt(data->set.sockopt_client,
|
||||||
|
sockfd,
|
||||||
|
CURLSOCKTYPE_IPCXN);
|
||||||
|
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 */
|
/* possibly bind the local end to an IP, interface or port */
|
||||||
res = bindlocal(conn, sockfd);
|
res = bindlocal(conn, sockfd);
|
||||||
if(res) {
|
if(res) {
|
||||||
|
|
13
lib/setup.h
13
lib/setup.h
|
@ -278,19 +278,6 @@ int fileno( FILE *stream);
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#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) && \
|
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \
|
||||||
!defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */
|
!defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
|
|
14
lib/url.c
14
lib/url.c
|
@ -1551,6 +1551,20 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||||
data->set.ftp_alternative_to_user = va_arg(param, char *);
|
data->set.ftp_alternative_to_user = va_arg(param, char *);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CURLOPT_SOCKOPTFUNCTION:
|
||||||
|
/*
|
||||||
|
* socket callback function: called after socket() but before connect()
|
||||||
|
*/
|
||||||
|
data->set.fsockopt = va_arg(param, curl_sockopt_callback);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CURLOPT_SOCKOPTDATA:
|
||||||
|
/*
|
||||||
|
* socket callback data pointer. Might be NULL.
|
||||||
|
*/
|
||||||
|
data->set.sockopt_client = va_arg(param, void *);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* unknown tag and its companion, just ignore: */
|
/* unknown tag and its companion, just ignore: */
|
||||||
result = CURLE_FAILED_INIT; /* correct this */
|
result = CURLE_FAILED_INIT; /* correct this */
|
||||||
|
|
|
@ -1029,6 +1029,8 @@ struct UserDefined {
|
||||||
curl_progress_callback fprogress; /* function for progress information */
|
curl_progress_callback fprogress; /* function for progress information */
|
||||||
curl_debug_callback fdebug; /* function that write informational data */
|
curl_debug_callback fdebug; /* function that write informational data */
|
||||||
curl_ioctl_callback ioctl; /* function for I/O control */
|
curl_ioctl_callback ioctl; /* function for I/O control */
|
||||||
|
curl_sockopt_callback fsockopt; /* function for setting socket options */
|
||||||
|
void *sockopt_client; /* pointer to pass to the socket options callback */
|
||||||
|
|
||||||
/* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
|
/* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
|
||||||
/* function to convert from the network encoding: */
|
/* function to convert from the network encoding: */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user