Skip to content

Commit

Permalink
Merge 6488715 into e551910
Browse files Browse the repository at this point in the history
  • Loading branch information
zagor committed Feb 13, 2018
2 parents e551910 + 6488715 commit 6e555d7
Show file tree
Hide file tree
Showing 27 changed files with 312 additions and 22 deletions.
4 changes: 4 additions & 0 deletions docs/libcurl/libcurl-errors.3
Expand Up @@ -252,6 +252,8 @@ Failed to match the pinned key specified with \fICURLOPT_PINNEDPUBLICKEY(3)\fP.
Status returned failure when asked with \fICURLOPT_SSL_VERIFYSTATUS(3)\fP.
.IP "CURLE_HTTP2_STREAM (92)"
Stream error in the HTTP/2 framing layer.
.IP "CURLE_RECURSIVE_API_CALL (93)"
An API function was called from inside a callback.
.IP "CURLE_OBSOLETE*"
These error codes will never be returned. They were used in an old libcurl
version and are currently unused.
Expand Down Expand Up @@ -285,6 +287,8 @@ curl_multi_setopt() with unsupported option
.IP "CURLM_ADDED_ALREADY (7)"
An easy handle already added to a multi handle was attempted to get added a
second time. (Added in 7.32.1)
.IP "CURLM_RECURSIVE_API_CALL (8)"
An API function was called from inside a callback.
.SH "CURLSHcode"
The "share" interface will return a CURLSHcode to indicate when an error has
occurred. Also consider \fIcurl_share_strerror(3)\fP.
Expand Down
2 changes: 2 additions & 0 deletions docs/libcurl/symbols-in-versions
Expand Up @@ -101,6 +101,7 @@ CURLE_QUOTE_ERROR 7.17.0
CURLE_RANGE_ERROR 7.17.0
CURLE_READ_ERROR 7.1
CURLE_RECV_ERROR 7.10
CURLE_RECURSIVE_API_CALL 7.59.0
CURLE_REMOTE_ACCESS_DENIED 7.17.0
CURLE_REMOTE_DISK_FULL 7.17.0
CURLE_REMOTE_FILE_EXISTS 7.17.0
Expand Down Expand Up @@ -323,6 +324,7 @@ CURLM_CALL_MULTI_SOCKET 7.15.5
CURLM_INTERNAL_ERROR 7.9.6
CURLM_OK 7.9.6
CURLM_OUT_OF_MEMORY 7.9.6
CURLM_RECURSIVE_API_CALL 7.59.0
CURLM_UNKNOWN_OPTION 7.15.4
CURLOPTTYPE_FUNCTIONPOINT 7.1
CURLOPTTYPE_LONG 7.1
Expand Down
2 changes: 2 additions & 0 deletions include/curl/curl.h
Expand Up @@ -577,6 +577,8 @@ typedef enum {
CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */
CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer
*/
CURLE_RECURSIVE_API_CALL, /* 93 - an api function was called from
inside a callback */
CURL_LAST /* never use! */
} CURLcode;

Expand Down
2 changes: 2 additions & 0 deletions include/curl/multi.h
Expand Up @@ -70,6 +70,8 @@ typedef enum {
CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
attempted to get added - again */
CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
callback */
CURLM_LAST
} CURLMcode;

Expand Down
13 changes: 11 additions & 2 deletions lib/connect.c
Expand Up @@ -1033,9 +1033,11 @@ static CURLcode singleipconnect(struct connectdata *conn,

if(data->set.fsockopt) {
/* activate callback for setting socket options */
Curl_set_in_callback(data, true);
error = data->set.fsockopt(data->set.sockopt_client,
sockfd,
CURLSOCKTYPE_IPCXN);
Curl_set_in_callback(data, false);

if(error == CURL_SOCKOPT_ALREADY_CONNECTED)
isconnected = TRUE;
Expand Down Expand Up @@ -1311,8 +1313,12 @@ int Curl_closesocket(struct connectdata *conn,
status */
conn->sock_accepted[SECONDARYSOCKET] = FALSE;
else {
int rc;
Curl_multi_closed(conn, sock);
return conn->fclosesocket(conn->closesocket_client, sock);
Curl_set_in_callback(conn->data, true);
rc = conn->fclosesocket(conn->closesocket_client, sock);
Curl_set_in_callback(conn->data, false);
return rc;
}
}

Expand Down Expand Up @@ -1363,7 +1369,7 @@ CURLcode Curl_socket(struct connectdata *conn,
addr->addrlen = sizeof(struct Curl_sockaddr_storage);
memcpy(&addr->sa_addr, ai->ai_addr, addr->addrlen);

if(data->set.fopensocket)
if(data->set.fopensocket) {
/*
* If the opensocket callback is set, all the destination address
* information is passed to the callback. Depending on this information the
Expand All @@ -1373,9 +1379,12 @@ CURLcode Curl_socket(struct connectdata *conn,
* might have been changed and this 'new' address will actually be used
* here to connect.
*/
Curl_set_in_callback(data, true);
*sockfd = data->set.fopensocket(data->set.opensocket_client,
CURLSOCKTYPE_IPCXN,
(struct curl_sockaddr *)addr);
Curl_set_in_callback(data, false);
}
else
/* opensocket callback not set, so simply create the socket now */
*sockfd = socket(addr->family, addr->socktype, addr->protocol);
Expand Down
13 changes: 13 additions & 0 deletions lib/easy.c
Expand Up @@ -61,6 +61,7 @@
#include "strdup.h"
#include "progress.h"
#include "easyif.h"
#include "multiif.h"
#include "select.h"
#include "sendf.h" /* for failf function prototype */
#include "connect.h" /* for Curl_getconnectinfo */
Expand Down Expand Up @@ -761,6 +762,9 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
data->multi_easy = multi;
}

if(multi->in_callback)
return CURLE_RECURSIVE_API_CALL;

/* Copy the MAXCONNECTS option to the multi handle */
curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, data->set.maxconnects);

Expand Down Expand Up @@ -1030,6 +1034,9 @@ void curl_easy_reset(struct Curl_easy *data)
* the pausing, you may get your write callback called at this point.
*
* Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
*
* NOTE: This is one of few API functions that are allowed to be called from
* within a callback.
*/
CURLcode curl_easy_pause(struct Curl_easy *data, int action)
{
Expand Down Expand Up @@ -1134,6 +1141,9 @@ CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
ssize_t n1;
struct connectdata *c;

if(Curl_is_in_callback(data))
return CURLE_RECURSIVE_API_CALL;

result = easy_connection(data, &sfd, &c);
if(result)
return result;
Expand Down Expand Up @@ -1161,6 +1171,9 @@ CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
ssize_t n1;
struct connectdata *c = NULL;

if(Curl_is_in_callback(data))
return CURLE_RECURSIVE_API_CALL;

result = easy_connection(data, &sfd, &c);
if(result)
return result;
Expand Down
16 changes: 14 additions & 2 deletions lib/ftp.c
Expand Up @@ -311,9 +311,11 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
int error = 0;

/* activate callback for setting socket options */
Curl_set_in_callback(data, true);
error = data->set.fsockopt(data->set.sockopt_client,
s,
CURLSOCKTYPE_ACCEPT);
Curl_set_in_callback(data, false);

if(error) {
close_secondarysocket(conn);
Expand Down Expand Up @@ -1616,8 +1618,10 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,

/* Let's read off the proper amount of bytes from the input. */
if(conn->seek_func) {
Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
SEEK_SET);
Curl_set_in_callback(data, true);
}

if(seekerr != CURL_SEEKFUNC_OK) {
Expand Down Expand Up @@ -3181,7 +3185,9 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,

if(data->state.wildcardmatch) {
if(data->set.chunk_end && ftpc->file) {
Curl_set_in_callback(data, true);
data->set.chunk_end(data->wildcard.customptr);
Curl_set_in_callback(data, false);
}
ftpc->known_filesize = -1;
}
Expand Down Expand Up @@ -3834,8 +3840,11 @@ static CURLcode wc_statemach(struct connectdata *conn)

infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename);
if(conn->data->set.chunk_bgn) {
long userresponse = conn->data->set.chunk_bgn(
long userresponse;
Curl_set_in_callback(conn->data, true);
userresponse = conn->data->set.chunk_bgn(
finfo, wildcard->customptr, (int)wildcard->filelist.size);
Curl_set_in_callback(conn->data, false);
switch(userresponse) {
case CURL_CHUNK_BGN_FUNC_SKIP:
infof(conn->data, "Wildcard - \"%s\" skipped by user\n",
Expand Down Expand Up @@ -3871,8 +3880,11 @@ static CURLcode wc_statemach(struct connectdata *conn)
} break;

case CURLWC_SKIP: {
if(conn->data->set.chunk_end)
if(conn->data->set.chunk_end) {
Curl_set_in_callback(conn->data, true);
conn->data->set.chunk_end(conn->data->wildcard.customptr);
Curl_set_in_callback(conn->data, false);
}
Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL);
wildcard->state = (wildcard->filelist.size == 0) ?
CURLWC_CLEAN : CURLWC_DOWNLOADING;
Expand Down
3 changes: 3 additions & 0 deletions lib/ftplistparser.c
Expand Up @@ -49,6 +49,7 @@
#include "ftplistparser.h"
#include "curl_fnmatch.h"
#include "curl_memory.h"
#include "multiif.h"
/* The last #include file should be: */
#include "memdebug.h"

Expand Down Expand Up @@ -294,6 +295,7 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
compare = Curl_fnmatch;

/* filter pattern-corresponding filenames */
Curl_set_in_callback(conn->data, true);
if(compare(conn->data->set.fnmatch_data, wc->pattern,
finfo->filename) == 0) {
/* discard symlink which is containing multiple " -> " */
Expand All @@ -305,6 +307,7 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
else {
add = FALSE;
}
Curl_set_in_callback(conn->data, false);

if(add) {
Curl_llist_insert_next(llist, llist->tail, finfo, &infop->list);
Expand Down
2 changes: 2 additions & 0 deletions lib/http.c
Expand Up @@ -2191,8 +2191,10 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* Now, let's read off the proper amount of bytes from the
input. */
if(conn->seek_func) {
Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
SEEK_SET);
Curl_set_in_callback(data, false);
}

if(seekerr != CURL_SEEKFUNC_OK) {
Expand Down
2 changes: 2 additions & 0 deletions lib/http2.c
Expand Up @@ -464,9 +464,11 @@ static int push_promise(struct Curl_easy *data,
goto fail;
}

Curl_set_in_callback(data, true);
rv = data->multi->push_cb(data, newhandle,
stream->push_headers_used, &heads,
data->multi->push_userp);
Curl_set_in_callback(data, false);

/* free the headers again */
for(i = 0; i<stream->push_headers_used; i++)
Expand Down

0 comments on commit 6e555d7

Please sign in to comment.