Skip to content

Commit 584dbff

Browse files
committed
moved the dynamicly set pointers to the connectdata struct
1 parent 1c6f6f6 commit 584dbff

File tree

4 files changed

+78
-82
lines changed

4 files changed

+78
-82
lines changed

lib/ftp.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ CURLcode Curl_ftp_done(struct connectdata *conn)
493493
}
494494
else {
495495
if((-1 != conn->size) && (conn->size != *ftp->bytecountp) &&
496-
(data->maxdownload != *ftp->bytecountp)) {
496+
(conn->maxdownload != *ftp->bytecountp)) {
497497
failf(data, "Received only partial file");
498498
return CURLE_PARTIAL_FILE;
499499
}
@@ -1393,16 +1393,16 @@ again:;
13931393
else if(from < 0) {
13941394
/* -Y */
13951395
totalsize = -from;
1396-
data->maxdownload = -from;
1396+
conn->maxdownload = -from;
13971397
data->resume_from = from;
13981398
infof(data, "FTP RANGE the last %d bytes\n", totalsize);
13991399
}
14001400
else {
14011401
/* X-Y */
14021402
totalsize = to-from;
1403-
data->maxdownload = totalsize+1; /* include the last mentioned byte */
1403+
conn->maxdownload = totalsize+1; /* include the last mentioned byte */
14041404
data->resume_from = from;
1405-
infof(data, "FTP RANGE from %d getting %d bytes\n", from, data->maxdownload);
1405+
infof(data, "FTP RANGE from %d getting %d bytes\n", from, conn->maxdownload);
14061406
}
14071407
infof(data, "range-download from %d to %d, totally %d bytes\n",
14081408
from, to, totalsize);

lib/http.c

+29-28
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
282282
"%s"
283283
"\r\n",
284284
hostname, remote_port,
285-
(data->bits.proxy_user_passwd)?data->ptr_proxyuserpwd:"",
286-
(data->useragent?data->ptr_uagent:"")
285+
(data->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"",
286+
(data->useragent?conn->allocptr.uagent:"")
287287
);
288288

289289
/* wait for the proxy to send us a HTTP/1.0 200 OK header */
@@ -405,9 +405,9 @@ CURLcode Curl_http(struct connectdata *conn)
405405
have been used in the proxy connect, but if we have got a header with
406406
the user-agent string specified, we erase the previously made string
407407
here. */
408-
if(checkheaders(data, "User-Agent:") && data->ptr_uagent) {
409-
free(data->ptr_uagent);
410-
data->ptr_uagent=NULL;
408+
if(checkheaders(data, "User-Agent:") && conn->allocptr.uagent) {
409+
free(conn->allocptr.uagent);
410+
conn->allocptr.uagent=NULL;
411411
}
412412

413413
if((data->bits.user_passwd) && !checkheaders(data, "Authorization:")) {
@@ -421,23 +421,23 @@ CURLcode Curl_http(struct connectdata *conn)
421421
sprintf(data->buffer, "%s:%s", data->user, data->passwd);
422422
if(Curl_base64_encode(data->buffer, strlen(data->buffer),
423423
&authorization) >= 0) {
424-
if(data->ptr_userpwd)
425-
free(data->ptr_userpwd);
426-
data->ptr_userpwd = aprintf( "Authorization: Basic %s\015\012",
424+
if(conn->allocptr.userpwd)
425+
free(conn->allocptr.userpwd);
426+
conn->allocptr.userpwd = aprintf( "Authorization: Basic %s\015\012",
427427
authorization);
428428
free(authorization);
429429
}
430430
}
431431
}
432432
if((data->bits.http_set_referer) && !checkheaders(data, "Referer:")) {
433-
if(data->ptr_ref)
434-
free(data->ptr_ref);
435-
data->ptr_ref = aprintf("Referer: %s\015\012", data->referer);
433+
if(conn->allocptr.ref)
434+
free(conn->allocptr.ref);
435+
conn->allocptr.ref = aprintf("Referer: %s\015\012", data->referer);
436436
}
437437
if(data->cookie && !checkheaders(data, "Cookie:")) {
438-
if(data->ptr_cookie)
439-
free(data->ptr_cookie);
440-
data->ptr_cookie = aprintf("Cookie: %s\015\012", data->cookie);
438+
if(conn->allocptr.cookie)
439+
free(conn->allocptr.cookie);
440+
conn->allocptr.cookie = aprintf("Cookie: %s\015\012", data->cookie);
441441
}
442442

443443
if(data->cookies) {
@@ -457,17 +457,18 @@ CURLcode Curl_http(struct connectdata *conn)
457457
}
458458

459459
if(!checkheaders(data, "Host:") &&
460-
!data->ptr_host) {
460+
!conn->allocptr.host) {
461461
/* if ptr_host is already set, it is OK since we only re-use connections
462462
to the very same host and port */
463463

464464
if(((conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTPS)) ||
465465
(!(conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTP)) )
466466
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
467467
the port number in the host string */
468-
data->ptr_host = aprintf("Host: %s\r\n", host);
468+
conn->allocptr.host = aprintf("Host: %s\r\n", host);
469469
else
470-
data->ptr_host = aprintf("Host: %s:%d\r\n", host, data->remote_port);
470+
conn->allocptr.host = aprintf("Host: %s:%d\r\n", host,
471+
data->remote_port);
471472
}
472473

473474
if(!checkheaders(data, "Pragma:"))
@@ -541,22 +542,22 @@ CURLcode Curl_http(struct connectdata *conn)
541542
*/
542543
if((data->httpreq == HTTPREQ_GET) &&
543544
!checkheaders(data, "Range:")) {
544-
data->ptr_rangeline = aprintf("Range: bytes=%s\r\n", data->range);
545+
conn->allocptr.rangeline = aprintf("Range: bytes=%s\r\n", data->range);
545546
}
546547
else if((data->httpreq != HTTPREQ_GET) &&
547548
!checkheaders(data, "Content-Range:")) {
548549

549550
if(data->resume_from) {
550551
/* This is because "resume" was selected */
551552
long total_expected_size= data->resume_from + data->infilesize;
552-
data->ptr_rangeline = aprintf("Content-Range: bytes %s%ld/%ld\r\n",
553+
conn->allocptr.rangeline = aprintf("Content-Range: bytes %s%ld/%ld\r\n",
553554
data->range, total_expected_size-1,
554555
total_expected_size);
555556
}
556557
else {
557558
/* Range was selected and then we just pass the incoming range and
558559
append total size */
559-
data->ptr_rangeline = aprintf("Content-Range: bytes %s/%d\r\n",
560+
conn->allocptr.rangeline = aprintf("Content-Range: bytes %s/%d\r\n",
560561
data->range, data->infilesize);
561562
}
562563
}
@@ -572,7 +573,7 @@ CURLcode Curl_http(struct connectdata *conn)
572573
/* add the main request stuff */
573574
add_bufferf(req_buffer,
574575
"%s " /* GET/HEAD/POST/PUT */
575-
"%s HTTP/1.0\r\n" /* path */
576+
"%s HTTP/1.1\r\n" /* path */
576577
"%s" /* proxyuserpwd */
577578
"%s" /* userpwd */
578579
"%s" /* range */
@@ -588,15 +589,15 @@ CURLcode Curl_http(struct connectdata *conn)
588589
(data->bits.http_post || data->bits.http_formpost)?"POST":
589590
(data->bits.http_put)?"PUT":"GET"),
590591
ppath,
591-
(data->bits.proxy_user_passwd && data->ptr_proxyuserpwd)?data->ptr_proxyuserpwd:"",
592-
(data->bits.user_passwd && data->ptr_userpwd)?data->ptr_userpwd:"",
593-
(data->bits.set_range && data->ptr_rangeline)?data->ptr_rangeline:"",
594-
(data->useragent && *data->useragent && data->ptr_uagent)?data->ptr_uagent:"",
595-
(data->ptr_cookie?data->ptr_cookie:""), /* Cookie: <data> */
596-
(data->ptr_host?data->ptr_host:""), /* Host: host */
592+
(data->bits.proxy_user_passwd && conn->allocptr.proxyuserpwd)?conn->allocptr.proxyuserpwd:"",
593+
(data->bits.user_passwd && conn->allocptr.userpwd)?conn->allocptr.userpwd:"",
594+
(data->bits.set_range && conn->allocptr.rangeline)?conn->allocptr.rangeline:"",
595+
(data->useragent && *data->useragent && conn->allocptr.uagent)?conn->allocptr.uagent:"",
596+
(conn->allocptr.cookie?conn->allocptr.cookie:""), /* Cookie: <data> */
597+
(conn->allocptr.host?conn->allocptr.host:""), /* Host: host */
597598
http->p_pragma?http->p_pragma:"",
598599
http->p_accept?http->p_accept:"",
599-
(data->bits.http_set_referer && data->ptr_ref)?data->ptr_ref:"" /* Referer: <data> <CRLF> */
600+
(data->bits.http_set_referer && conn->allocptr.ref)?conn->allocptr.ref:"" /* Referer: <data> <CRLF> */
600601
);
601602

602603
if(co) {

lib/url.c

+26-37
Original file line numberDiff line numberDiff line change
@@ -158,35 +158,6 @@ CURLcode curl_close(CURL *curl)
158158
data->bits.rangestringalloc=0; /* free now */
159159
}
160160

161-
if(data->ptr_proxyuserpwd) {
162-
free(data->ptr_proxyuserpwd);
163-
data->ptr_proxyuserpwd=NULL;
164-
}
165-
if(data->ptr_uagent) {
166-
free(data->ptr_uagent);
167-
data->ptr_uagent=NULL;
168-
}
169-
if(data->ptr_userpwd) {
170-
free(data->ptr_userpwd);
171-
data->ptr_userpwd=NULL;
172-
}
173-
if(data->ptr_rangeline) {
174-
free(data->ptr_rangeline);
175-
data->ptr_rangeline=NULL;
176-
}
177-
if(data->ptr_ref) {
178-
free(data->ptr_ref);
179-
data->ptr_ref=NULL;
180-
}
181-
if(data->ptr_cookie) {
182-
free(data->ptr_cookie);
183-
data->ptr_cookie=NULL;
184-
}
185-
if(data->ptr_host) {
186-
free(data->ptr_host);
187-
data->ptr_host=NULL;
188-
}
189-
190161
/* check for allocated [URL] memory to free: */
191162
if(data->freethis)
192163
free(data->freethis);
@@ -577,13 +548,26 @@ CURLcode curl_disconnect(CURLconnect *c_connect)
577548
/* close possibly still open sockets */
578549
if(-1 != conn->secondarysocket) {
579550
sclose(conn->secondarysocket);
580-
conn->secondarysocket = -1;
581551
}
582552
if(-1 != conn->firstsocket) {
583553
sclose(conn->firstsocket);
584-
conn->firstsocket=-1;
585554
}
586555

556+
if(conn->allocptr.proxyuserpwd)
557+
free(conn->allocptr.proxyuserpwd);
558+
if(conn->allocptr.uagent)
559+
free(conn->allocptr.uagent);
560+
if(conn->allocptr.userpwd)
561+
free(conn->allocptr.userpwd);
562+
if(conn->allocptr.rangeline)
563+
free(conn->allocptr.rangeline);
564+
if(conn->allocptr.ref)
565+
free(conn->allocptr.ref);
566+
if(conn->allocptr.cookie)
567+
free(conn->allocptr.cookie);
568+
if(conn->allocptr.host)
569+
free(conn->allocptr.host);
570+
587571
free(conn); /* free all the connection oriented data */
588572

589573
return CURLE_OK;
@@ -1544,6 +1528,11 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
15441528
free(conn->path); /* free the previous path pointer */
15451529
conn->path = path; /* use this one */
15461530
conn->ppath = path; /* set this too */
1531+
1532+
/* re-use init */
1533+
conn->maxdownload = 0; /* might have been used previously! */
1534+
1535+
infof(data, "Re-using existing connection! (#%d)\n", conn->connectindex);
15471536
}
15481537
else {
15491538
/*
@@ -1653,9 +1642,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
16531642
data->proxyuser, data->proxypasswd);
16541643
if(Curl_base64_encode(data->buffer, strlen(data->buffer),
16551644
&authorization) >= 0) {
1656-
if(data->ptr_proxyuserpwd)
1657-
free(data->ptr_proxyuserpwd);
1658-
data->ptr_proxyuserpwd =
1645+
if(conn->allocptr.proxyuserpwd)
1646+
free(conn->allocptr.proxyuserpwd);
1647+
conn->allocptr.proxyuserpwd =
16591648
aprintf("Proxy-authorization: Basic %s\015\012", authorization);
16601649
free(authorization);
16611650
}
@@ -1667,9 +1656,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
16671656
*************************************************************/
16681657
if((conn->protocol&PROT_HTTP) || data->bits.httpproxy) {
16691658
if(data->useragent) {
1670-
if(data->ptr_uagent)
1671-
free(data->ptr_uagent);
1672-
data->ptr_uagent =
1659+
if(conn->allocptr.uagent)
1660+
free(conn->allocptr.uagent);
1661+
conn->allocptr.uagent =
16731662
aprintf("User-Agent: %s\015\012", data->useragent);
16741663
}
16751664
}

lib/urldata.h

+19-13
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ struct connectdata {
242242
long upload_bufsize; /* adjust as you see fit, never bigger than BUFSIZE
243243
never smaller than UPLOAD_BUFSIZE */
244244

245+
long maxdownload; /* in bytes, the maximum amount of data to fetch, 0
246+
means unlimited */
247+
245248
struct ssl_connect_data ssl; /* this is for ssl-stuff */
246249

247250
struct ConnectBits bits; /* various state-flags for this connection */
@@ -274,6 +277,17 @@ struct connectdata {
274277
the same we read from. -1 disables */
275278
long *writebytecountp; /* return number of bytes written or NULL */
276279

280+
/** Dynamicly allocated strings, may need to be freed before this **/
281+
/** struct is killed. **/
282+
struct dynamically_allocated_data {
283+
char *proxyuserpwd; /* free later if not NULL! */
284+
char *uagent; /* free later if not NULL! */
285+
char *userpwd; /* free later if not NULL! */
286+
char *rangeline; /* free later if not NULL! */
287+
char *ref; /* free later if not NULL! */
288+
char *cookie; /* free later if not NULL! */
289+
char *host; /* free later if not NULL */
290+
} allocptr;
277291

278292
#ifdef KRB4
279293

@@ -411,11 +425,15 @@ typedef enum {
411425
*
412426
* (Request)
413427
* 3 - Request-specific. Variables that are of interest for this particular
414-
* transfer being made right now.
428+
* transfer being made right now. THIS IS WRONG STRUCT FOR THOSE.
415429
*
416430
* In Febrary 2001, this is being done stricter. The 'connectdata' struct
417431
* MUST have all the connection oriented stuff as we may now have several
418432
* simultaneous connections and connection structs in memory.
433+
*
434+
* From now on, the 'UrlData' must only contain data that is set once to go
435+
* for many (perhaps) independent connections. Values that are generated or
436+
* calculated internally MUST NOT be a part of this struct.
419437
*/
420438

421439
struct UrlData {
@@ -488,9 +506,6 @@ struct UrlData {
488506
long timeout; /* in seconds, 0 means no timeout */
489507
long infilesize; /* size of file to upload, -1 means unknown */
490508

491-
long maxdownload; /* in bytes, the maximum amount of data to fetch, 0
492-
means unlimited */
493-
494509
char buffer[BUFSIZE+1]; /* buffer with size BUFSIZE */
495510

496511
double current_speed; /* the ProgressShow() funcion sets this */
@@ -546,15 +561,6 @@ struct UrlData {
546561
char proxyuser[MAX_CURL_USER_LENGTH];
547562
char proxypasswd[MAX_CURL_PASSWORD_LENGTH];
548563

549-
/**** Dynamicly allocated strings, may need to be freed on return ****/
550-
char *ptr_proxyuserpwd; /* free later if not NULL! */
551-
char *ptr_uagent; /* free later if not NULL! */
552-
char *ptr_userpwd; /* free later if not NULL! */
553-
char *ptr_rangeline; /* free later if not NULL! */
554-
char *ptr_ref; /* free later if not NULL! */
555-
char *ptr_cookie; /* free later if not NULL! */
556-
char *ptr_host; /* free later if not NULL */
557-
558564
char *krb4_level; /* what security level */
559565
#ifdef KRB4
560566
FILE *cmdchannel;

0 commit comments

Comments
 (0)