From 4ad8e142da463ab208d5b5565e53291c8e5ef038 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 4 Aug 2013 19:34:16 +0200 Subject: urldata: clean up the use of the protocol specific structs 1 - always allocate the struct in protocol->setup_connection. Some protocol handlers had to get this function added. 2 - always free at the end of a request. This is also an attempt to keep less memory in the handle after it is completed. --- lib/imap.c | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'lib/imap.c') diff --git a/lib/imap.c b/lib/imap.c index 13e9784a4..c1dffb41d 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -163,7 +163,7 @@ const struct Curl_handler Curl_handler_imaps = { static const struct Curl_handler Curl_handler_imap_proxy = { "IMAP", /* scheme */ - ZERO_NULL, /* setup_connection */ + Curl_http_setup_conn, /* setup_connection */ Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ @@ -188,7 +188,7 @@ static const struct Curl_handler Curl_handler_imap_proxy = { static const struct Curl_handler Curl_handler_imaps_proxy = { "IMAPS", /* scheme */ - ZERO_NULL, /* setup_connection */ + Curl_http_setup_conn, /* setup_connection */ Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ @@ -1669,13 +1669,11 @@ static CURLcode imap_init(struct connectdata *conn) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; - struct IMAP *imap = data->state.proto.imap; + struct IMAP *imap; - if(!imap) { - imap = data->state.proto.imap = calloc(sizeof(struct IMAP), 1); - if(!imap) - result = CURLE_OUT_OF_MEMORY; - } + imap = data->state.proto.imap = calloc(sizeof(struct IMAP), 1); + if(!imap) + result = CURLE_OUT_OF_MEMORY; return result; } @@ -1705,15 +1703,6 @@ static CURLcode imap_connect(struct connectdata *conn, bool *done) *done = FALSE; /* default to not done yet */ - /* If there already is a protocol-specific struct allocated for this - sessionhandle, deal with it */ - Curl_reset_reqproto(conn); - - /* Initialise the IMAP layer */ - result = imap_init(conn); - if(result) - return result; - /* We always support persistent connections in IMAP */ conn->bits.close = FALSE; @@ -1891,15 +1880,6 @@ static CURLcode imap_do(struct connectdata *conn, bool *done) *done = FALSE; /* default to false */ - /* Since connections can be re-used between SessionHandles, there might be a - connection already existing but on a fresh SessionHandle struct. As such - we make sure we have a good IMAP struct to play with. For new connections - the IMAP struct is allocated and setup in the imap_connect() function. */ - Curl_reset_reqproto(conn); - result = imap_init(conn); - if(result) - return result; - /* Parse the URL path */ result = imap_parse_url_path(conn); if(result) @@ -2018,6 +1998,11 @@ static CURLcode imap_setup_connection(struct connectdata *conn) { struct SessionHandle *data = conn->data; + /* Initialise the IMAP layer */ + CURLcode result = imap_init(conn); + if(result) + return result; + if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) { /* Unless we have asked to tunnel IMAP operations through the proxy, we switch and use HTTP operations only */ @@ -2033,10 +2018,8 @@ static CURLcode imap_setup_connection(struct connectdata *conn) #endif } - /* We explicitly mark this connection as persistent here as we're doing - IMAP over HTTP and thus we accidentally avoid setting this value - otherwise */ - conn->bits.close = FALSE; + /* set it up as an HTTP connection instead */ + return conn->handler->setup_connection(conn); #else failf(data, "IMAP over http proxy requires HTTP support built-in!"); return CURLE_UNSUPPORTED_PROTOCOL; -- cgit v1.2.3