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.
This commit is contained in:
Daniel Stenberg 2013-08-05 10:32:08 +02:00
parent 4ad8e142da
commit e79535bc5e
16 changed files with 140 additions and 143 deletions

View File

@ -602,8 +602,7 @@ void Curl_easy_addmulti(struct SessionHandle *data,
void Curl_easy_initHandleData(struct SessionHandle *data)
{
memset(&data->req, 0, sizeof(struct SingleRequest));
data->req.maxdownload = -1;
(void)data;
}
/*
@ -737,7 +736,7 @@ void curl_easy_reset(CURL *curl)
data->state.path = NULL;
Curl_safefree(data->state.proto.generic);
Curl_free_request_state(data);
/* zero out UserDefined data: */
Curl_freeset(data);

View File

@ -90,7 +90,7 @@ static CURLcode file_done(struct connectdata *conn,
static CURLcode file_connect(struct connectdata *conn, bool *done);
static CURLcode file_disconnect(struct connectdata *conn,
bool dead_connection);
static CURLcode file_setup_connection(struct connectdata *conn);
/*
* FILE scheme handler.
@ -98,7 +98,7 @@ static CURLcode file_disconnect(struct connectdata *conn,
const struct Curl_handler Curl_handler_file = {
"FILE", /* scheme */
ZERO_NULL, /* setup_connection */
file_setup_connection, /* setup_connection */
file_do, /* do_it */
file_done, /* done */
ZERO_NULL, /* do_more */
@ -117,6 +117,16 @@ const struct Curl_handler Curl_handler_file = {
};
static CURLcode file_setup_connection(struct connectdata *conn)
{
/* allocate the FILE specific struct */
conn->data->req.protop = calloc(1, sizeof(struct FILEPROTO));
if(!conn->data->req.protop)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
/*
Check if this is a range download, and if so, set the internal variables
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)
{
struct SessionHandle *data = conn->data;
char *real_path;
struct FILEPROTO *file;
struct FILEPROTO *file = data->req.protop;
int fd;
#ifdef DOS_FILESYSTEM
int i;
@ -190,13 +200,6 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
if(!real_path)
return CURLE_OUT_OF_MEMORY;
file = calloc(1, sizeof(struct FILEPROTO));
if(!file) {
free(real_path);
return CURLE_OUT_OF_MEMORY;
}
data->state.proto.file = file;
#ifdef DOS_FILESYSTEM
/* If the first character is a slash, and there's
something that looks like a drive at the beginning of
@ -247,7 +250,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
static CURLcode file_done(struct connectdata *conn,
CURLcode status, bool premature)
{
struct FILEPROTO *file = conn->data->state.proto.file;
struct FILEPROTO *file = conn->data->req.protop;
(void)status; /* not used */
(void)premature; /* not used */
@ -265,7 +268,7 @@ static CURLcode file_done(struct connectdata *conn,
static CURLcode file_disconnect(struct connectdata *conn,
bool dead_connection)
{
struct FILEPROTO *file = conn->data->state.proto.file;
struct FILEPROTO *file = conn->data->req.protop;
(void)dead_connection; /* not used */
if(file) {
@ -287,7 +290,7 @@ static CURLcode file_disconnect(struct connectdata *conn,
static CURLcode file_upload(struct connectdata *conn)
{
struct FILEPROTO *file = conn->data->state.proto.file;
struct FILEPROTO *file = conn->data->req.protop;
const char *dir = strchr(file->path, DIRSEP);
int fd;
int mode;
@ -425,6 +428,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
curl_off_t bytecount = 0;
int fd;
struct timeval now = Curl_tvnow();
struct FILEPROTO *file;
*done = TRUE; /* unconditionally */
@ -434,8 +438,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
if(data->set.upload)
return file_upload(conn);
file = conn->data->req.protop;
/* get the fd from the connection phase */
fd = data->state.proto.file->fd;
fd = file->fd;
/* VMS: This only works reliable for STREAMLF files */
if(-1 != fstat(fd, &statbuf)) {

View File

@ -493,7 +493,7 @@ static CURLcode ReceivedServerConnect(struct connectdata *conn, bool *received)
static CURLcode InitiateTransfer(struct connectdata *conn)
{
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
CURLcode result = CURLE_OK;
if(conn->ssl[SECONDARYSOCKET].use) {
@ -835,7 +835,7 @@ static void _state(struct connectdata *conn,
static CURLcode ftp_state_user(struct connectdata *conn)
{
CURLcode result;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
/* send USER */
PPSENDF(&conn->proto.ftpc.pp, "USER %s", ftp->user?ftp->user:"");
@ -1382,7 +1382,7 @@ static CURLcode ftp_state_use_pasv(struct connectdata *conn)
static CURLcode ftp_state_prepare_transfer(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct SessionHandle *data = conn->data;
if(ftp->transfer != FTPTRANSFER_BODY) {
@ -1425,7 +1425,7 @@ static CURLcode ftp_state_prepare_transfer(struct connectdata *conn)
static CURLcode ftp_state_rest(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
if((ftp->transfer != FTPTRANSFER_BODY) && ftpc->file) {
@ -1446,7 +1446,7 @@ static CURLcode ftp_state_rest(struct connectdata *conn)
static CURLcode ftp_state_size(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
if((ftp->transfer == FTPTRANSFER_INFO) && ftpc->file) {
@ -1557,7 +1557,7 @@ static CURLcode ftp_state_stor_prequote(struct connectdata *conn)
static CURLcode ftp_state_type(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct SessionHandle *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
@ -1614,7 +1614,7 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
bool sizechecked)
{
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct SessionHandle *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
int seekerr = CURL_SEEKFUNC_OK;
@ -1712,7 +1712,7 @@ static CURLcode ftp_state_quote(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
bool quote=FALSE;
struct curl_slist *item;
@ -2058,13 +2058,13 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
* FTP pointer
*/
struct HTTP http_proxy;
struct FTP *ftp_save = data->state.proto.ftp;
struct FTP *ftp_save = data->req.protop;
memset(&http_proxy, 0, sizeof(http_proxy));
data->state.proto.http = &http_proxy;
data->req.protop = &http_proxy;
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport);
data->state.proto.ftp = ftp_save;
data->req.protop = ftp_save;
if(result)
return result;
@ -2124,7 +2124,7 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data=conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
switch(ftpcode) {
@ -2258,7 +2258,7 @@ static CURLcode ftp_state_retr(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data=conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
if(data->set.max_filesize && (filesize > data->set.max_filesize)) {
@ -2450,7 +2450,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
char *buf = data->state.buffer;
if((ftpcode == 150) || (ftpcode == 125)) {
@ -2618,7 +2618,7 @@ static CURLcode ftp_state_user_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
(void)instate; /* no use for this yet */
@ -3214,7 +3214,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
bool premature)
{
struct SessionHandle *data = conn->data;
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
ssize_t nread;
@ -3631,7 +3631,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
bool complete = FALSE;
/* the ftp struct is inited in ftp_connect() */
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
/* if the second connection isn't done yet, wait for it */
if(!conn->bits.tcpconnect[SECONDARYSOCKET]) {
@ -3779,7 +3779,7 @@ CURLcode ftp_perform(struct connectdata *conn,
if(conn->data->set.opt_no_body) {
/* requested no body means no transfer... */
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
ftp->transfer = FTPTRANSFER_INFO;
}
@ -4218,7 +4218,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
{
struct SessionHandle *data = conn->data;
/* the ftp struct is already inited in ftp_connect() */
struct FTP *ftp = data->state.proto.ftp;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
const char *slash_pos; /* position of the first '/' char in curpos */
const char *path_to_use = data->state.path;
@ -4408,7 +4408,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
static CURLcode ftp_dophase_done(struct connectdata *conn,
bool connected)
{
struct FTP *ftp = conn->data->state.proto.ftp;
struct FTP *ftp = conn->data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
if(connected) {
@ -4532,7 +4532,7 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
#endif
}
conn->data->state.proto.ftp = ftp = malloc(sizeof(struct FTP));
conn->data->req.protop = ftp = malloc(sizeof(struct FTP));
if(NULL == ftp)
return CURLE_OUT_OF_MEMORY;

View File

@ -153,12 +153,10 @@ CURLcode Curl_http_setup_conn(struct connectdata *conn)
{
/* allocate the HTTP-specific struct for the SessionHandle, only to survive
during this request */
struct HTTP *http;
DEBUGASSERT(conn->data->req.protop == NULL);
DEBUGASSERT(conn->data->state.proto.http == NULL);
conn->data->state.proto.http = http = calloc(1, sizeof(struct HTTP));
if(!http)
conn->data->req.protop = calloc(1, sizeof(struct HTTP));
if(!conn->data->req.protop)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
@ -345,7 +343,7 @@ static bool pickoneauth(struct auth *pick)
static CURLcode http_perhapsrewind(struct connectdata *conn)
{
struct SessionHandle *data = conn->data;
struct HTTP *http = data->state.proto.http;
struct HTTP *http = data->req.protop;
curl_off_t bytessent;
curl_off_t expectsend = -1; /* default is unknown */
@ -963,7 +961,7 @@ static size_t readmoredata(char *buffer,
void *userp)
{
struct connectdata *conn = (struct connectdata *)userp;
struct HTTP *http = conn->data->state.proto.http;
struct HTTP *http = conn->data->req.protop;
size_t fullsize = size * nitems;
if(0 == http->postsize)
@ -1034,7 +1032,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
CURLcode res;
char *ptr;
size_t size;
struct HTTP *http = conn->data->state.proto.http;
struct HTTP *http = conn->data->req.protop;
size_t sendsize;
curl_socket_t sockfd;
size_t headersize;
@ -1417,7 +1415,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
CURLcode status, bool premature)
{
struct SessionHandle *data = conn->data;
struct HTTP *http =data->state.proto.http;
struct HTTP *http =data->req.protop;
Curl_unencode_cleanup(conn);
@ -1671,7 +1669,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
the rest of the request in the PERFORM phase. */
*done = TRUE;
http = data->state.proto.http;
http = data->req.protop;
if(!data->state.this_is_a_follow) {
/* this is not a followed location, get the original host name */

View File

@ -66,13 +66,13 @@ CURLcode Curl_proxy_connect(struct connectdata *conn)
* This function might be called several times in the multi interface case
* if the proxy's CONNTECT response is not instant.
*/
prot_save = conn->data->state.proto.generic;
prot_save = conn->data->req.protop;
memset(&http_proxy, 0, sizeof(http_proxy));
conn->data->state.proto.http = &http_proxy;
conn->data->req.protop = &http_proxy;
conn->bits.close = FALSE;
result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
conn->host.name, conn->remote_port);
conn->data->state.proto.generic = prot_save;
conn->data->req.protop = prot_save;
if(CURLE_OK != result)
return result;
#else

View File

@ -268,7 +268,7 @@ static bool imap_matchresp(const char *line, size_t len, const char *cmd)
static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
int *resp)
{
struct IMAP *imap = conn->data->state.proto.imap;
struct IMAP *imap = conn->data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
const char *id = imapc->resptag;
size_t id_len = strlen(id);
@ -638,7 +638,7 @@ static CURLcode imap_perform_list(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
char *mailbox;
if(imap->custom)
@ -673,7 +673,7 @@ static CURLcode imap_perform_select(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
char *mailbox;
@ -712,7 +712,7 @@ static CURLcode imap_perform_select(struct connectdata *conn)
static CURLcode imap_perform_fetch(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct IMAP *imap = conn->data->state.proto.imap;
struct IMAP *imap = conn->data->req.protop;
/* Check we have a UID */
if(!imap->uid) {
@ -740,7 +740,7 @@ static CURLcode imap_perform_fetch(struct connectdata *conn)
static CURLcode imap_perform_append(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct IMAP *imap = conn->data->state.proto.imap;
struct IMAP *imap = conn->data->req.protop;
char *mailbox;
/* Check we have a mailbox */
@ -1316,7 +1316,7 @@ static CURLcode imap_state_select_resp(struct connectdata *conn, int imapcode,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = conn->data->state.proto.imap;
struct IMAP *imap = conn->data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
const char *line = data->state.buffer;
char tmp[20];
@ -1671,7 +1671,7 @@ static CURLcode imap_init(struct connectdata *conn)
struct SessionHandle *data = conn->data;
struct IMAP *imap;
imap = data->state.proto.imap = calloc(sizeof(struct IMAP), 1);
imap = data->req.protop = calloc(sizeof(struct IMAP), 1);
if(!imap)
result = CURLE_OUT_OF_MEMORY;
@ -1748,7 +1748,7 @@ static CURLcode imap_done(struct connectdata *conn, CURLcode status,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
(void)premature;
@ -1813,7 +1813,7 @@ static CURLcode imap_perform(struct connectdata *conn, bool *connected,
/* This is IMAP and no proxy */
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
bool selected = FALSE;
@ -1932,7 +1932,7 @@ static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
/* Call this when the DO phase has completed */
static CURLcode imap_dophase_done(struct connectdata *conn, bool connected)
{
struct IMAP *imap = conn->data->state.proto.imap;
struct IMAP *imap = conn->data->req.protop;
(void)connected;
@ -2242,7 +2242,7 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
/* The imap struct is already initialised in imap_connect() */
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
const char *begin = data->state.path;
const char *ptr = begin;
@ -2350,7 +2350,7 @@ static CURLcode imap_parse_custom_request(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct IMAP *imap = data->state.proto.imap;
struct IMAP *imap = data->req.protop;
const char *custom = data->set.str[STRING_CUSTOMREQUEST];
if(custom) {

View File

@ -378,7 +378,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
if(!lr)
return CURLE_OUT_OF_MEMORY;
lr->msgid = msgid;
data->state.proto.generic = lr;
data->req.protop = lr;
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL);
*done = TRUE;
return CURLE_OK;
@ -387,7 +387,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
static CURLcode ldap_done(struct connectdata *conn, CURLcode res,
bool premature)
{
ldapreqinfo *lr = conn->data->state.proto.generic;
ldapreqinfo *lr = conn->data->req.protop;
(void)res;
(void)premature;
@ -398,7 +398,7 @@ static CURLcode ldap_done(struct connectdata *conn, CURLcode res,
ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
lr->msgid = 0;
}
conn->data->state.proto.generic = NULL;
conn->data->req.protop = NULL;
free(lr);
}
return CURLE_OK;
@ -409,7 +409,7 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
{
ldapconninfo *li = conn->proto.generic;
struct SessionHandle *data=conn->data;
ldapreqinfo *lr = data->state.proto.generic;
ldapreqinfo *lr = data->req.protop;
int rc, ret;
LDAPMessage *result = NULL;
LDAPMessage *ent;

View File

@ -673,7 +673,7 @@ static CURLcode pop3_perform_command(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct POP3 *pop3 = data->state.proto.pop3;
struct POP3 *pop3 = data->req.protop;
const char *command = NULL;
/* Calculate the default command */
@ -1203,7 +1203,7 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct POP3 *pop3 = data->state.proto.pop3;
struct POP3 *pop3 = data->req.protop;
struct pop3_conn *pop3c = &conn->proto.pop3c;
struct pingpong *pp = &pop3c->pp;
@ -1397,7 +1397,7 @@ static CURLcode pop3_init(struct connectdata *conn)
struct SessionHandle *data = conn->data;
struct POP3 *pop3;
pop3 = data->state.proto.pop3 = calloc(sizeof(struct POP3), 1);
pop3 = data->req.protop = calloc(sizeof(struct POP3), 1);
if(!pop3)
result = CURLE_OUT_OF_MEMORY;
@ -1472,7 +1472,7 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct POP3 *pop3 = data->state.proto.pop3;
struct POP3 *pop3 = data->req.protop;
(void)premature;
@ -1515,7 +1515,7 @@ static CURLcode pop3_perform(struct connectdata *conn, bool *connected,
if(conn->data->set.opt_no_body) {
/* Requested no body means no transfer */
struct POP3 *pop3 = conn->data->state.proto.pop3;
struct POP3 *pop3 = conn->data->req.protop;
pop3->transfer = FTPTRANSFER_INFO;
}
@ -1774,7 +1774,7 @@ static CURLcode pop3_parse_url_path(struct connectdata *conn)
{
/* The POP3 struct is already initialised in pop3_connect() */
struct SessionHandle *data = conn->data;
struct POP3 *pop3 = data->state.proto.pop3;
struct POP3 *pop3 = data->req.protop;
const char *path = data->state.path;
/* URL decode the path for the message ID */
@ -1791,7 +1791,7 @@ static CURLcode pop3_parse_custom_request(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct POP3 *pop3 = data->state.proto.pop3;
struct POP3 *pop3 = data->req.protop;
const char *custom = data->set.str[STRING_CUSTOMREQUEST];
/* URL decode the custom request */

View File

@ -129,7 +129,7 @@ static CURLcode rtsp_setup_connection(struct connectdata *conn)
{
struct RTSP *rtsp;
conn->data->state.proto.rtsp = rtsp = calloc(1, sizeof(struct RTSP));
conn->data->req.protop = rtsp = calloc(1, sizeof(struct RTSP));
if(!rtsp)
return CURLE_OUT_OF_MEMORY;
@ -200,7 +200,7 @@ static CURLcode rtsp_done(struct connectdata *conn,
CURLcode status, bool premature)
{
struct SessionHandle *data = conn->data;
struct RTSP *rtsp = data->state.proto.rtsp;
struct RTSP *rtsp = data->req.protop;
CURLcode httpStatus;
long CSeq_sent;
long CSeq_recv;
@ -236,7 +236,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
struct SessionHandle *data = conn->data;
CURLcode result=CURLE_OK;
Curl_RtspReq rtspreq = data->set.rtspreq;
struct RTSP *rtsp = data->state.proto.rtsp;
struct RTSP *rtsp = data->req.protop;
struct HTTP *http;
Curl_send_buffer *req_buffer;
curl_off_t postsize = 0; /* for ANNOUNCE and SET_PARAMETER */
@ -750,7 +750,8 @@ CURLcode Curl_rtsp_parseheader(struct connectdata *conn,
/* Store the received CSeq. Match is verified in rtsp_done */
int nc = sscanf(&header[4], ": %ld", &CSeq);
if(nc == 1) {
data->state.proto.rtsp->CSeq_recv = CSeq; /* mark the request */
struct RTSP *rtsp = data->req.protop;
rtsp->CSeq_recv = CSeq; /* mark the request */
data->state.rtsp_CSeq_recv = CSeq; /* update the handle */
}
else {

View File

@ -636,7 +636,7 @@ static CURLcode smtp_perform_rcpt_to(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct SMTP *smtp = data->req.protop;
/* Send the RCPT TO command */
if(smtp->rcpt) {
@ -1115,7 +1115,7 @@ static CURLcode smtp_state_mail_resp(struct connectdata *conn, int smtpcode,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct SMTP *smtp = data->req.protop;
(void)instate; /* no use for this yet */
@ -1139,7 +1139,7 @@ static CURLcode smtp_state_rcpt_resp(struct connectdata *conn, int smtpcode,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct SMTP *smtp = data->req.protop;
(void)instate; /* no use for this yet */
@ -1363,7 +1363,7 @@ static CURLcode smtp_init(struct connectdata *conn)
struct SessionHandle *data = conn->data;
struct SMTP *smtp;
smtp = data->state.proto.smtp = calloc(sizeof(struct SMTP), 1);
smtp = data->req.protop = calloc(sizeof(struct SMTP), 1);
if(!smtp)
result = CURLE_OUT_OF_MEMORY;
@ -1442,7 +1442,7 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct SMTP *smtp = data->req.protop;
struct pingpong *pp = &conn->proto.smtpc.pp;
const char *eob;
ssize_t len;
@ -1523,7 +1523,7 @@ static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
if(conn->data->set.opt_no_body) {
/* Requested no body means no transfer */
struct SMTP *smtp = conn->data->state.proto.smtp;
struct SMTP *smtp = conn->data->req.protop;
smtp->transfer = FTPTRANSFER_INFO;
}
@ -1602,7 +1602,7 @@ static CURLcode smtp_disconnect(struct connectdata *conn,
/* Call this when the DO phase has completed */
static CURLcode smtp_dophase_done(struct connectdata *conn, bool connected)
{
struct SMTP *smtp = conn->data->state.proto.smtp;
struct SMTP *smtp = conn->data->req.protop;
(void)connected;
@ -1785,7 +1785,7 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
ssize_t i;
ssize_t si;
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct SMTP *smtp = data->req.protop;
/* Do we need to allocate the scatch buffer? */
if(!data->state.scratch) {

View File

@ -688,7 +688,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct SSHPROTO *sftp_scp = data->state.proto.ssh;
struct SSHPROTO *sftp_scp = data->req.protop;
struct ssh_conn *sshc = &conn->proto.sshc;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
char *new_readdir_line;
@ -2694,7 +2694,7 @@ static CURLcode ssh_setup_connection(struct connectdata *conn)
{
struct SSHPROTO *ssh;
conn->data->state.proto.ssh = ssh = calloc(1, sizeof(struct SSHPROTO));
conn->data->req.protop = ssh = calloc(1, sizeof(struct SSHPROTO));
if(!ssh)
return CURLE_OUT_OF_MEMORY;
@ -2870,7 +2870,7 @@ static CURLcode scp_disconnect(struct connectdata *conn, bool dead_connection)
struct ssh_conn *ssh = &conn->proto.sshc;
(void) dead_connection;
Curl_safefree(conn->data->state.proto.ssh);
Curl_safefree(conn->data->req.protop);
if(ssh->ssh_session) {
/* only if there's a session still around to use! */
@ -2888,7 +2888,7 @@ static CURLcode scp_disconnect(struct connectdata *conn, bool dead_connection)
static CURLcode ssh_done(struct connectdata *conn, CURLcode status)
{
CURLcode result = CURLE_OK;
struct SSHPROTO *sftp_scp = conn->data->state.proto.ssh;
struct SSHPROTO *sftp_scp = conn->data->req.protop;
if(status == CURLE_OK) {
/* run the state-machine
@ -3035,7 +3035,7 @@ static CURLcode sftp_disconnect(struct connectdata *conn, bool dead_connection)
DEBUGF(infof(conn->data, "SSH DISCONNECT starts now\n"));
Curl_safefree(conn->data->state.proto.ssh);
Curl_safefree(conn->data->req.protop);
if(conn->proto.sshc.ssh_session) {
/* only if there's a session still around to use! */

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -247,7 +247,7 @@ CURLcode init_telnet(struct connectdata *conn)
if(!tn)
return CURLE_OUT_OF_MEMORY;
conn->data->state.proto.telnet = (void *)tn; /* make us known */
conn->data->req.protop = tn; /* make us known */
tn->telrcv_state = CURL_TS_DATA;
@ -292,7 +292,7 @@ CURLcode init_telnet(struct connectdata *conn)
static void negotiate(struct connectdata *conn)
{
int i;
struct TELNET *tn = (struct TELNET *) conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *) conn->data->req.protop;
for(i = 0;i < CURL_NTELOPTS;i++) {
if(i==CURL_TELOPT_ECHO)
@ -366,7 +366,7 @@ static void send_negotiation(struct connectdata *conn, int cmd, int option)
static
void set_remote_option(struct connectdata *conn, int option, int newstate)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
if(newstate == CURL_YES) {
switch(tn->him[option]) {
case CURL_NO:
@ -440,7 +440,7 @@ void set_remote_option(struct connectdata *conn, int option, int newstate)
static
void rec_will(struct connectdata *conn, int option)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
switch(tn->him[option]) {
case CURL_NO:
if(tn->him_preferred[option] == CURL_YES) {
@ -488,7 +488,7 @@ void rec_will(struct connectdata *conn, int option)
static
void rec_wont(struct connectdata *conn, int option)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
switch(tn->him[option]) {
case CURL_NO:
/* Already disabled */
@ -530,7 +530,7 @@ void rec_wont(struct connectdata *conn, int option)
static void
set_local_option(struct connectdata *conn, int option, int newstate)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
if(newstate == CURL_YES) {
switch(tn->us[option]) {
case CURL_NO:
@ -604,7 +604,7 @@ set_local_option(struct connectdata *conn, int option, int newstate)
static
void rec_do(struct connectdata *conn, int option)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
switch(tn->us[option]) {
case CURL_NO:
if(tn->us_preferred[option] == CURL_YES) {
@ -664,7 +664,7 @@ void rec_do(struct connectdata *conn, int option)
static
void rec_dont(struct connectdata *conn, int option)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
switch(tn->us[option]) {
case CURL_NO:
/* Already disabled */
@ -825,7 +825,7 @@ static CURLcode check_telnet_options(struct connectdata *conn)
char option_keyword[128];
char option_arg[256];
struct SessionHandle *data = conn->data;
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
CURLcode result = CURLE_OK;
int binary_option;
@ -935,7 +935,7 @@ static void suboption(struct connectdata *conn)
char varname[128];
char varval[128];
struct SessionHandle *data = conn->data;
struct TELNET *tn = (struct TELNET *)data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)data->req.protop;
printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn)+2);
switch (CURL_SB_GET(tn)) {
@ -1009,7 +1009,7 @@ static void sendsuboption(struct connectdata *conn, int option)
unsigned char*uc1, *uc2;
struct SessionHandle *data = conn->data;
struct TELNET *tn = (struct TELNET *)data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)data->req.protop;
switch (option) {
case CURL_TELOPT_NAWS:
@ -1067,7 +1067,7 @@ CURLcode telrcv(struct connectdata *conn,
int in = 0;
int startwrite=-1;
struct SessionHandle *data = conn->data;
struct TELNET *tn = (struct TELNET *)data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)data->req.protop;
#define startskipping() \
if(startwrite >= 0) { \
@ -1264,7 +1264,7 @@ static CURLcode send_telnet_data(struct connectdata *conn,
static CURLcode telnet_done(struct connectdata *conn,
CURLcode status, bool premature)
{
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
struct TELNET *tn = (struct TELNET *)conn->data->req.protop;
(void)status; /* unused */
(void)premature; /* not used */
@ -1274,7 +1274,7 @@ static CURLcode telnet_done(struct connectdata *conn,
curl_slist_free_all(tn->telnet_vars);
tn->telnet_vars = NULL;
Curl_safefree(conn->data->state.proto.telnet);
Curl_safefree(conn->data->req.protop);
return CURLE_OK;
}
@ -1318,7 +1318,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
if(code)
return code;
tn = (struct TELNET *)data->state.proto.telnet;
tn = (struct TELNET *)data->req.protop;
code = check_telnet_options(conn);
if(code)

View File

@ -810,9 +810,10 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
/* HTTP pollution, this should be written nicer to become more
protocol agnostic. */
int fillcount;
struct HTTP *http = data->req.protop;
if((k->exp100 == EXP100_SENDING_REQUEST) &&
(data->state.proto.http->sending == HTTPSEND_BODY)) {
(http->sending == HTTPSEND_BODY)) {
/* If this call is to send body data, we must take some action:
We have sent off the full HTTP 1.1 request, and we shall now
go into the Expect: 100 state and await such a header */
@ -827,7 +828,7 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
}
if(conn->handler->protocol&(CURLPROTO_HTTP|CURLPROTO_RTSP)) {
if(data->state.proto.http->sending == HTTPSEND_REQUEST)
if(http->sending == HTTPSEND_REQUEST)
/* We're sending the HTTP request headers, not the data.
Remember that so we don't change the line endings. */
sending_http_headers = TRUE;
@ -1852,7 +1853,7 @@ CURLcode Curl_retry_request(struct connectdata *conn,
data->req.headerbytecount == 0) &&
conn->bits.reuse &&
!data->set.opt_no_body &&
data->set.rtspreq != RTSPREQ_RECEIVE)) {
data->set.rtspreq != RTSPREQ_RECEIVE)) {
/* We got no data, we attempted to re-use a connection and yet we want a
"body". This might happen if the connection was left alive when we were
done using it before, but that was closed when we wanted to read from
@ -1870,9 +1871,11 @@ CURLcode Curl_retry_request(struct connectdata *conn,
transferred! */
if((conn->handler->protocol&CURLPROTO_HTTP) &&
data->state.proto.http->writebytecount)
return Curl_readrewind(conn);
if(conn->handler->protocol&CURLPROTO_HTTP) {
struct HTTP *http = data->req.protop;
if(http->writebytecount)
return Curl_readrewind(conn);
}
}
return CURLE_OK;
}
@ -1930,6 +1933,7 @@ Curl_setup_transfer(
k->keepon |= KEEP_RECV;
if(conn->writesockfd != CURL_SOCKET_BAD) {
struct HTTP *http = data->req.protop;
/* HTTP 1.1 magic:
Even if we require a 100-return code before uploading data, we might
@ -1940,7 +1944,8 @@ Curl_setup_transfer(
state info where we wait for the 100-return code
*/
if((data->state.expect100header) &&
(data->state.proto.http->sending == HTTPSEND_BODY)) {
(conn->handler->protocol&CURLPROTO_HTTP) &&
(http->sending == HTTPSEND_BODY)) {
/* wait with write until we either got 100-continue or a timeout */
k->exp100 = EXP100_AWAITING_CONTINUE;
k->start100 = Curl_tvnow();

View File

@ -148,7 +148,6 @@ static CURLcode parse_url_login(struct SessionHandle *data,
static CURLcode parse_login_details(const char *login, const size_t len,
char **userptr, char **passwdptr,
char **optionsptr);
static void free_connection_internals(struct SessionHandle *data);
/*
* Protocol table.
*/
@ -419,7 +418,7 @@ CURLcode Curl_close(struct SessionHandle *data)
data->state.path = NULL;
/* freed here just in case DONE wasn't called */
free_connection_internals(data);
Curl_free_request_state(data);
/* Close down all open SSL info and sessions */
Curl_ssl_close_all(data);
@ -4037,7 +4036,10 @@ static CURLcode setup_connection_internals(struct connectdata *conn)
without doing a DISCONNECT or DONE in between (since the connection is
yet in place) and therefore this function needs to first make sure
there's no lingering previous data allocated. */
free_connection_internals(conn->data);
Curl_free_request_state(conn->data);
memset(&conn->data->req, 0, sizeof(struct SingleRequest));
conn->data->req.maxdownload = -1;
conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
@ -4066,9 +4068,14 @@ static CURLcode setup_connection_internals(struct connectdata *conn)
return CURLE_OK;
}
static void free_connection_internals(struct SessionHandle *data)
/*
* Curl_free_request_state() should free temp data that was allocated in the
* SessionHandle for this single request.
*/
void Curl_free_request_state(struct SessionHandle *data)
{
Curl_safefree(data->state.proto.generic);
Curl_safefree(data->req.protop);
}
@ -5751,7 +5758,7 @@ CURLcode Curl_done(struct connectdata **connp,
this was either closed or handed over to the connection
cache here, and therefore cannot be used from this point on
*/
free_connection_internals(data);
Curl_free_request_state(data);
return result;
}

View File

@ -45,6 +45,7 @@ CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done);
CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done);
CURLcode Curl_setup_conn(struct connectdata *conn,
bool *protocol_done);
void Curl_free_request_state(struct SessionHandle *data);
int Curl_protocol_getsock(struct connectdata *conn,
curl_socket_t *socks,

View File

@ -692,6 +692,9 @@ struct SingleRequest {
bool forbidchunk; /* used only to explicitly forbid chunk-upload for
specific upload buffers. See readmoredata() in
http.c for details. */
void *protop; /* Allocated protocol-specific data. Each protocol
handler makes sure this points to data it needs. */
};
/*
@ -1274,29 +1277,6 @@ struct UrlState {
long rtsp_next_server_CSeq; /* the session's next server CSeq */
long rtsp_CSeq_recv; /* most recent CSeq received */
/* Protocol specific data.
*
*************************************************************************
* Note that this data will be freed after each request is DONE, so anything
* that should be kept/stored on a per-connection basis and thus live for
* the next request on the same connection MUST be put in the connectdata
* struct!
*************************************************************************/
union {
struct HTTP *http;
struct HTTP *https; /* alias, just for the sake of being more readable */
struct RTSP *rtsp;
struct FTP *ftp;
/* void *tftp; not used */
struct FILEPROTO *file;
void *telnet; /* private for telnet.c-eyes only */
void *generic;
struct SSHPROTO *ssh;
struct IMAP *imap;
struct POP3 *pop3;
struct SMTP *smtp;
} proto;
/* if true, force SSL connection retry (workaround for certain servers) */
bool ssl_connect_retry;
};