Commit e79535bc authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

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.
parent 4ad8e142
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -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);
+20 −14
Original line number Diff line number Diff line
@@ -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)) {
+21 −21
Original line number Diff line number Diff line
@@ -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;

+8 −10
Original line number Diff line number Diff line
@@ -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->state.proto.http == NULL);
  DEBUGASSERT(conn->data->req.protop == 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 */
+3 −3
Original line number Diff line number Diff line
@@ -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
Loading