mirror of
https://github.com/moparisthebest/curl
synced 2024-11-16 22:45:03 -05:00
imap: make imap_send use dynbuf for the send buffer management
Reuses the buffer and thereby reduces number of mallocs over a transfer. Closes #6010
This commit is contained in:
parent
92a9b88ebf
commit
c4693adc62
@ -84,4 +84,5 @@ int Curl_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save);
|
|||||||
#define DYN_QLOG_NAME 1024
|
#define DYN_QLOG_NAME 1024
|
||||||
#define DYN_H1_TRAILER 4096
|
#define DYN_H1_TRAILER 4096
|
||||||
#define DYN_PINGPPONG_CMD (64*1024)
|
#define DYN_PINGPPONG_CMD (64*1024)
|
||||||
|
#define DYN_IMAP_CMD (64*1024)
|
||||||
#endif
|
#endif
|
||||||
|
27
lib/imap.c
27
lib/imap.c
@ -1429,6 +1429,7 @@ static CURLcode imap_connect(struct connectdata *conn, bool *done)
|
|||||||
imapc->preftype = IMAP_TYPE_ANY;
|
imapc->preftype = IMAP_TYPE_ANY;
|
||||||
Curl_sasl_init(&imapc->sasl, &saslimap);
|
Curl_sasl_init(&imapc->sasl, &saslimap);
|
||||||
|
|
||||||
|
Curl_dyn_init(&imapc->dyn, DYN_IMAP_CMD);
|
||||||
/* Initialise the pingpong layer */
|
/* Initialise the pingpong layer */
|
||||||
Curl_pp_setup(pp);
|
Curl_pp_setup(pp);
|
||||||
Curl_pp_init(pp);
|
Curl_pp_init(pp);
|
||||||
@ -1632,6 +1633,7 @@ static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
|
|||||||
|
|
||||||
/* Disconnect from the server */
|
/* Disconnect from the server */
|
||||||
Curl_pp_disconnect(&imapc->pp);
|
Curl_pp_disconnect(&imapc->pp);
|
||||||
|
Curl_dyn_free(&imapc->dyn);
|
||||||
|
|
||||||
/* Cleanup the SASL module */
|
/* Cleanup the SASL module */
|
||||||
Curl_sasl_cleanup(conn, imapc->sasl.authused);
|
Curl_sasl_cleanup(conn, imapc->sasl.authused);
|
||||||
@ -1733,30 +1735,25 @@ static CURLcode imap_sendf(struct connectdata *conn, const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct imap_conn *imapc = &conn->proto.imapc;
|
struct imap_conn *imapc = &conn->proto.imapc;
|
||||||
char *taggedfmt;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
DEBUGASSERT(fmt);
|
DEBUGASSERT(fmt);
|
||||||
|
|
||||||
/* Calculate the next command ID wrapping at 3 digits */
|
|
||||||
imapc->cmdid = (imapc->cmdid + 1) % 1000;
|
|
||||||
|
|
||||||
/* Calculate the tag based on the connection ID and command ID */
|
/* Calculate the tag based on the connection ID and command ID */
|
||||||
msnprintf(imapc->resptag, sizeof(imapc->resptag), "%c%03d",
|
msnprintf(imapc->resptag, sizeof(imapc->resptag), "%c%03d",
|
||||||
'A' + curlx_sltosi(conn->connection_id % 26), imapc->cmdid);
|
'A' + curlx_sltosi(conn->connection_id % 26),
|
||||||
|
(++imapc->cmdid)%1000);
|
||||||
|
|
||||||
/* Prefix the format with the tag */
|
/* start with a blank buffer */
|
||||||
taggedfmt = aprintf("%s %s", imapc->resptag, fmt);
|
Curl_dyn_reset(&imapc->dyn);
|
||||||
if(!taggedfmt)
|
|
||||||
return CURLE_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
/* Send the data with the tag */
|
/* append tag + space + fmt */
|
||||||
|
result = Curl_dyn_addf(&imapc->dyn, "%s %s", imapc->resptag, fmt);
|
||||||
|
if(!result) {
|
||||||
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
result = Curl_pp_vsendf(&imapc->pp, taggedfmt, ap);
|
result = Curl_pp_vsendf(&imapc->pp, Curl_dyn_ptr(&imapc->dyn), ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
}
|
||||||
free(taggedfmt);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 2009 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -75,13 +75,14 @@ struct imap_conn {
|
|||||||
bool preauth; /* Is this connection PREAUTH? */
|
bool preauth; /* Is this connection PREAUTH? */
|
||||||
struct SASL sasl; /* SASL-related parameters */
|
struct SASL sasl; /* SASL-related parameters */
|
||||||
unsigned int preftype; /* Preferred authentication type */
|
unsigned int preftype; /* Preferred authentication type */
|
||||||
int cmdid; /* Last used command ID */
|
unsigned int cmdid; /* Last used command ID */
|
||||||
char resptag[5]; /* Response tag to wait for */
|
char resptag[5]; /* Response tag to wait for */
|
||||||
bool tls_supported; /* StartTLS capability supported by server */
|
bool tls_supported; /* StartTLS capability supported by server */
|
||||||
bool login_disabled; /* LOGIN command disabled by server */
|
bool login_disabled; /* LOGIN command disabled by server */
|
||||||
bool ir_supported; /* Initial response supported by server */
|
bool ir_supported; /* Initial response supported by server */
|
||||||
char *mailbox; /* The last selected mailbox */
|
char *mailbox; /* The last selected mailbox */
|
||||||
char *mailbox_uidvalidity; /* UIDVALIDITY parsed from select response */
|
char *mailbox_uidvalidity; /* UIDVALIDITY parsed from select response */
|
||||||
|
struct dynbuf dyn; /* for the IMAP commands */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct Curl_handler Curl_handler_imap;
|
extern const struct Curl_handler Curl_handler_imap;
|
||||||
|
@ -166,7 +166,7 @@ my $SSHSRVMD5 = "[uninitialized]"; # MD5 of ssh server public key
|
|||||||
|
|
||||||
my $srcdir = $ENV{'srcdir'} || '.';
|
my $srcdir = $ENV{'srcdir'} || '.';
|
||||||
my $CURL="../src/curl".exe_ext('TOOL'); # what curl executable to run on the tests
|
my $CURL="../src/curl".exe_ext('TOOL'); # what curl executable to run on the tests
|
||||||
my $VCURL=$CURL; # what curl binary to use to verify the servers with
|
my $VCURL="curl"; # what curl binary to use to verify the servers with
|
||||||
# VCURL is handy to set to the system one when the one you
|
# VCURL is handy to set to the system one when the one you
|
||||||
# just built hangs or crashes and thus prevent verification
|
# just built hangs or crashes and thus prevent verification
|
||||||
my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
|
my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
|
||||||
|
Loading…
Reference in New Issue
Block a user