Skip to content

Commit e79535b

Browse files
committed
SessionHandle: the protocol specific pointer is now a void *
All protocol handler structs are now opaque (void *) in the SessionHandle struct and moved in the request-specific sub-struct 'SingleRequest'. The intension is to keep the protocol specific knowledge in their own dedicated source files [protocol].c etc. There's some "leakage" where this policy is violated, to be addressed at a later point in time.
1 parent 4ad8e14 commit e79535b

File tree

16 files changed

+140
-143
lines changed

16 files changed

+140
-143
lines changed

lib/easy.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ void Curl_easy_addmulti(struct SessionHandle *data,
602602

603603
void Curl_easy_initHandleData(struct SessionHandle *data)
604604
{
605-
memset(&data->req, 0, sizeof(struct SingleRequest));
606-
data->req.maxdownload = -1;
605+
(void)data;
607606
}
608607

609608
/*
@@ -737,7 +736,7 @@ void curl_easy_reset(CURL *curl)
737736

738737
data->state.path = NULL;
739738

740-
Curl_safefree(data->state.proto.generic);
739+
Curl_free_request_state(data);
741740

742741
/* zero out UserDefined data: */
743742
Curl_freeset(data);

lib/file.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ static CURLcode file_done(struct connectdata *conn,
9090
static CURLcode file_connect(struct connectdata *conn, bool *done);
9191
static CURLcode file_disconnect(struct connectdata *conn,
9292
bool dead_connection);
93-
93+
static CURLcode file_setup_connection(struct connectdata *conn);
9494

9595
/*
9696
* FILE scheme handler.
9797
*/
9898

9999
const struct Curl_handler Curl_handler_file = {
100100
"FILE", /* scheme */
101-
ZERO_NULL, /* setup_connection */
101+
file_setup_connection, /* setup_connection */
102102
file_do, /* do_it */
103103
file_done, /* done */
104104
ZERO_NULL, /* do_more */
@@ -117,6 +117,16 @@ const struct Curl_handler Curl_handler_file = {
117117
};
118118

119119

120+
static CURLcode file_setup_connection(struct connectdata *conn)
121+
{
122+
/* allocate the FILE specific struct */
123+
conn->data->req.protop = calloc(1, sizeof(struct FILEPROTO));
124+
if(!conn->data->req.protop)
125+
return CURLE_OUT_OF_MEMORY;
126+
127+
return CURLE_OK;
128+
}
129+
120130
/*
121131
Check if this is a range download, and if so, set the internal variables
122132
properly. This code is copied from the FTP implementation and might as
@@ -179,7 +189,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
179189
{
180190
struct SessionHandle *data = conn->data;
181191
char *real_path;
182-
struct FILEPROTO *file;
192+
struct FILEPROTO *file = data->req.protop;
183193
int fd;
184194
#ifdef DOS_FILESYSTEM
185195
int i;
@@ -190,13 +200,6 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
190200
if(!real_path)
191201
return CURLE_OUT_OF_MEMORY;
192202

193-
file = calloc(1, sizeof(struct FILEPROTO));
194-
if(!file) {
195-
free(real_path);
196-
return CURLE_OUT_OF_MEMORY;
197-
}
198-
data->state.proto.file = file;
199-
200203
#ifdef DOS_FILESYSTEM
201204
/* If the first character is a slash, and there's
202205
something that looks like a drive at the beginning of
@@ -247,7 +250,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
247250
static CURLcode file_done(struct connectdata *conn,
248251
CURLcode status, bool premature)
249252
{
250-
struct FILEPROTO *file = conn->data->state.proto.file;
253+
struct FILEPROTO *file = conn->data->req.protop;
251254
(void)status; /* not used */
252255
(void)premature; /* not used */
253256

@@ -265,7 +268,7 @@ static CURLcode file_done(struct connectdata *conn,
265268
static CURLcode file_disconnect(struct connectdata *conn,
266269
bool dead_connection)
267270
{
268-
struct FILEPROTO *file = conn->data->state.proto.file;
271+
struct FILEPROTO *file = conn->data->req.protop;
269272
(void)dead_connection; /* not used */
270273

271274
if(file) {
@@ -287,7 +290,7 @@ static CURLcode file_disconnect(struct connectdata *conn,
287290

288291
static CURLcode file_upload(struct connectdata *conn)
289292
{
290-
struct FILEPROTO *file = conn->data->state.proto.file;
293+
struct FILEPROTO *file = conn->data->req.protop;
291294
const char *dir = strchr(file->path, DIRSEP);
292295
int fd;
293296
int mode;
@@ -425,6 +428,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
425428
curl_off_t bytecount = 0;
426429
int fd;
427430
struct timeval now = Curl_tvnow();
431+
struct FILEPROTO *file;
428432

429433
*done = TRUE; /* unconditionally */
430434

@@ -434,8 +438,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
434438
if(data->set.upload)
435439
return file_upload(conn);
436440

441+
file = conn->data->req.protop;
442+
437443
/* get the fd from the connection phase */
438-
fd = data->state.proto.file->fd;
444+
fd = file->fd;
439445

440446
/* VMS: This only works reliable for STREAMLF files */
441447
if(-1 != fstat(fd, &statbuf)) {

lib/ftp.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static CURLcode ReceivedServerConnect(struct connectdata *conn, bool *received)
493493
static CURLcode InitiateTransfer(struct connectdata *conn)
494494
{
495495
struct SessionHandle *data = conn->data;
496-
struct FTP *ftp = data->state.proto.ftp;
496+
struct FTP *ftp = data->req.protop;
497497
CURLcode result = CURLE_OK;
498498

499499
if(conn->ssl[SECONDARYSOCKET].use) {
@@ -835,7 +835,7 @@ static void _state(struct connectdata *conn,
835835
static CURLcode ftp_state_user(struct connectdata *conn)
836836
{
837837
CURLcode result;
838-
struct FTP *ftp = conn->data->state.proto.ftp;
838+
struct FTP *ftp = conn->data->req.protop;
839839
/* send USER */
840840
PPSENDF(&conn->proto.ftpc.pp, "USER %s", ftp->user?ftp->user:"");
841841

@@ -1382,7 +1382,7 @@ static CURLcode ftp_state_use_pasv(struct connectdata *conn)
13821382
static CURLcode ftp_state_prepare_transfer(struct connectdata *conn)
13831383
{
13841384
CURLcode result = CURLE_OK;
1385-
struct FTP *ftp = conn->data->state.proto.ftp;
1385+
struct FTP *ftp = conn->data->req.protop;
13861386
struct SessionHandle *data = conn->data;
13871387

13881388
if(ftp->transfer != FTPTRANSFER_BODY) {
@@ -1425,7 +1425,7 @@ static CURLcode ftp_state_prepare_transfer(struct connectdata *conn)
14251425
static CURLcode ftp_state_rest(struct connectdata *conn)
14261426
{
14271427
CURLcode result = CURLE_OK;
1428-
struct FTP *ftp = conn->data->state.proto.ftp;
1428+
struct FTP *ftp = conn->data->req.protop;
14291429
struct ftp_conn *ftpc = &conn->proto.ftpc;
14301430

14311431
if((ftp->transfer != FTPTRANSFER_BODY) && ftpc->file) {
@@ -1446,7 +1446,7 @@ static CURLcode ftp_state_rest(struct connectdata *conn)
14461446
static CURLcode ftp_state_size(struct connectdata *conn)
14471447
{
14481448
CURLcode result = CURLE_OK;
1449-
struct FTP *ftp = conn->data->state.proto.ftp;
1449+
struct FTP *ftp = conn->data->req.protop;
14501450
struct ftp_conn *ftpc = &conn->proto.ftpc;
14511451

14521452
if((ftp->transfer == FTPTRANSFER_INFO) && ftpc->file) {
@@ -1557,7 +1557,7 @@ static CURLcode ftp_state_stor_prequote(struct connectdata *conn)
15571557
static CURLcode ftp_state_type(struct connectdata *conn)
15581558
{
15591559
CURLcode result = CURLE_OK;
1560-
struct FTP *ftp = conn->data->state.proto.ftp;
1560+
struct FTP *ftp = conn->data->req.protop;
15611561
struct SessionHandle *data = conn->data;
15621562
struct ftp_conn *ftpc = &conn->proto.ftpc;
15631563

@@ -1614,7 +1614,7 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
16141614
bool sizechecked)
16151615
{
16161616
CURLcode result = CURLE_OK;
1617-
struct FTP *ftp = conn->data->state.proto.ftp;
1617+
struct FTP *ftp = conn->data->req.protop;
16181618
struct SessionHandle *data = conn->data;
16191619
struct ftp_conn *ftpc = &conn->proto.ftpc;
16201620
int seekerr = CURL_SEEKFUNC_OK;
@@ -1712,7 +1712,7 @@ static CURLcode ftp_state_quote(struct connectdata *conn,
17121712
{
17131713
CURLcode result = CURLE_OK;
17141714
struct SessionHandle *data = conn->data;
1715-
struct FTP *ftp = data->state.proto.ftp;
1715+
struct FTP *ftp = data->req.protop;
17161716
struct ftp_conn *ftpc = &conn->proto.ftpc;
17171717
bool quote=FALSE;
17181718
struct curl_slist *item;
@@ -2058,13 +2058,13 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
20582058
* FTP pointer
20592059
*/
20602060
struct HTTP http_proxy;
2061-
struct FTP *ftp_save = data->state.proto.ftp;
2061+
struct FTP *ftp_save = data->req.protop;
20622062
memset(&http_proxy, 0, sizeof(http_proxy));
2063-
data->state.proto.http = &http_proxy;
2063+
data->req.protop = &http_proxy;
20642064

20652065
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport);
20662066

2067-
data->state.proto.ftp = ftp_save;
2067+
data->req.protop = ftp_save;
20682068

20692069
if(result)
20702070
return result;
@@ -2124,7 +2124,7 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
21242124
{
21252125
CURLcode result = CURLE_OK;
21262126
struct SessionHandle *data=conn->data;
2127-
struct FTP *ftp = data->state.proto.ftp;
2127+
struct FTP *ftp = data->req.protop;
21282128
struct ftp_conn *ftpc = &conn->proto.ftpc;
21292129

21302130
switch(ftpcode) {
@@ -2258,7 +2258,7 @@ static CURLcode ftp_state_retr(struct connectdata *conn,
22582258
{
22592259
CURLcode result = CURLE_OK;
22602260
struct SessionHandle *data=conn->data;
2261-
struct FTP *ftp = data->state.proto.ftp;
2261+
struct FTP *ftp = data->req.protop;
22622262
struct ftp_conn *ftpc = &conn->proto.ftpc;
22632263

22642264
if(data->set.max_filesize && (filesize > data->set.max_filesize)) {
@@ -2450,7 +2450,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
24502450
{
24512451
CURLcode result = CURLE_OK;
24522452
struct SessionHandle *data = conn->data;
2453-
struct FTP *ftp = data->state.proto.ftp;
2453+
struct FTP *ftp = data->req.protop;
24542454
char *buf = data->state.buffer;
24552455

24562456
if((ftpcode == 150) || (ftpcode == 125)) {
@@ -2618,7 +2618,7 @@ static CURLcode ftp_state_user_resp(struct connectdata *conn,
26182618
{
26192619
CURLcode result = CURLE_OK;
26202620
struct SessionHandle *data = conn->data;
2621-
struct FTP *ftp = data->state.proto.ftp;
2621+
struct FTP *ftp = data->req.protop;
26222622
struct ftp_conn *ftpc = &conn->proto.ftpc;
26232623
(void)instate; /* no use for this yet */
26242624

@@ -3214,7 +3214,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
32143214
bool premature)
32153215
{
32163216
struct SessionHandle *data = conn->data;
3217-
struct FTP *ftp = data->state.proto.ftp;
3217+
struct FTP *ftp = data->req.protop;
32183218
struct ftp_conn *ftpc = &conn->proto.ftpc;
32193219
struct pingpong *pp = &ftpc->pp;
32203220
ssize_t nread;
@@ -3631,7 +3631,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
36313631
bool complete = FALSE;
36323632

36333633
/* the ftp struct is inited in ftp_connect() */
3634-
struct FTP *ftp = data->state.proto.ftp;
3634+
struct FTP *ftp = data->req.protop;
36353635

36363636
/* if the second connection isn't done yet, wait for it */
36373637
if(!conn->bits.tcpconnect[SECONDARYSOCKET]) {
@@ -3779,7 +3779,7 @@ CURLcode ftp_perform(struct connectdata *conn,
37793779

37803780
if(conn->data->set.opt_no_body) {
37813781
/* requested no body means no transfer... */
3782-
struct FTP *ftp = conn->data->state.proto.ftp;
3782+
struct FTP *ftp = conn->data->req.protop;
37833783
ftp->transfer = FTPTRANSFER_INFO;
37843784
}
37853785

@@ -4218,7 +4218,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
42184218
{
42194219
struct SessionHandle *data = conn->data;
42204220
/* the ftp struct is already inited in ftp_connect() */
4221-
struct FTP *ftp = data->state.proto.ftp;
4221+
struct FTP *ftp = data->req.protop;
42224222
struct ftp_conn *ftpc = &conn->proto.ftpc;
42234223
const char *slash_pos; /* position of the first '/' char in curpos */
42244224
const char *path_to_use = data->state.path;
@@ -4408,7 +4408,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
44084408
static CURLcode ftp_dophase_done(struct connectdata *conn,
44094409
bool connected)
44104410
{
4411-
struct FTP *ftp = conn->data->state.proto.ftp;
4411+
struct FTP *ftp = conn->data->req.protop;
44124412
struct ftp_conn *ftpc = &conn->proto.ftpc;
44134413

44144414
if(connected) {
@@ -4532,7 +4532,7 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
45324532
#endif
45334533
}
45344534

4535-
conn->data->state.proto.ftp = ftp = malloc(sizeof(struct FTP));
4535+
conn->data->req.protop = ftp = malloc(sizeof(struct FTP));
45364536
if(NULL == ftp)
45374537
return CURLE_OUT_OF_MEMORY;
45384538

lib/http.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ CURLcode Curl_http_setup_conn(struct connectdata *conn)
153153
{
154154
/* allocate the HTTP-specific struct for the SessionHandle, only to survive
155155
during this request */
156-
struct HTTP *http;
157-
158-
DEBUGASSERT(conn->data->state.proto.http == NULL);
156+
DEBUGASSERT(conn->data->req.protop == NULL);
159157

160-
conn->data->state.proto.http = http = calloc(1, sizeof(struct HTTP));
161-
if(!http)
158+
conn->data->req.protop = calloc(1, sizeof(struct HTTP));
159+
if(!conn->data->req.protop)
162160
return CURLE_OUT_OF_MEMORY;
163161

164162
return CURLE_OK;
@@ -345,7 +343,7 @@ static bool pickoneauth(struct auth *pick)
345343
static CURLcode http_perhapsrewind(struct connectdata *conn)
346344
{
347345
struct SessionHandle *data = conn->data;
348-
struct HTTP *http = data->state.proto.http;
346+
struct HTTP *http = data->req.protop;
349347
curl_off_t bytessent;
350348
curl_off_t expectsend = -1; /* default is unknown */
351349

@@ -963,7 +961,7 @@ static size_t readmoredata(char *buffer,
963961
void *userp)
964962
{
965963
struct connectdata *conn = (struct connectdata *)userp;
966-
struct HTTP *http = conn->data->state.proto.http;
964+
struct HTTP *http = conn->data->req.protop;
967965
size_t fullsize = size * nitems;
968966

969967
if(0 == http->postsize)
@@ -1034,7 +1032,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
10341032
CURLcode res;
10351033
char *ptr;
10361034
size_t size;
1037-
struct HTTP *http = conn->data->state.proto.http;
1035+
struct HTTP *http = conn->data->req.protop;
10381036
size_t sendsize;
10391037
curl_socket_t sockfd;
10401038
size_t headersize;
@@ -1417,7 +1415,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
14171415
CURLcode status, bool premature)
14181416
{
14191417
struct SessionHandle *data = conn->data;
1420-
struct HTTP *http =data->state.proto.http;
1418+
struct HTTP *http =data->req.protop;
14211419

14221420
Curl_unencode_cleanup(conn);
14231421

@@ -1671,7 +1669,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
16711669
the rest of the request in the PERFORM phase. */
16721670
*done = TRUE;
16731671

1674-
http = data->state.proto.http;
1672+
http = data->req.protop;
16751673

16761674
if(!data->state.this_is_a_follow) {
16771675
/* this is not a followed location, get the original host name */

lib/http_proxy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ CURLcode Curl_proxy_connect(struct connectdata *conn)
6666
* This function might be called several times in the multi interface case
6767
* if the proxy's CONNTECT response is not instant.
6868
*/
69-
prot_save = conn->data->state.proto.generic;
69+
prot_save = conn->data->req.protop;
7070
memset(&http_proxy, 0, sizeof(http_proxy));
71-
conn->data->state.proto.http = &http_proxy;
71+
conn->data->req.protop = &http_proxy;
7272
conn->bits.close = FALSE;
7373
result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
7474
conn->host.name, conn->remote_port);
75-
conn->data->state.proto.generic = prot_save;
75+
conn->data->req.protop = prot_save;
7676
if(CURLE_OK != result)
7777
return result;
7878
#else

0 commit comments

Comments
 (0)