1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

pingpong: Optimised the endofresp() function

Reworked the pp->endofresp() function so that the conndata, line and
line length are passed down to it just as with Curl_client_write()
rather than each implementation of the function having to query
these values.

Additionally changed the int return type to bool as this is more
representative of the function's usage.
This commit is contained in:
Steve Holme 2013-02-12 18:08:48 +00:00
parent 586f5d3614
commit b56c9eb48e
6 changed files with 15 additions and 20 deletions

View File

@ -598,17 +598,17 @@ static CURLcode AllowServerConnect(struct connectdata *conn, bool *connected)
/* macro to check for the last line in an FTP server response */
#define LASTLINE(line) (STATUSCODE(line) && (' ' == line[3]))
static int ftp_endofresp(struct pingpong *pp,
int *code)
static bool ftp_endofresp(struct connectdata *conn, char *line, size_t len,
int *code)
{
char *line = pp->linestart_resp;
size_t len = pp->nread_resp;
(void)conn;
if((len > 3) && LASTLINE(line)) {
*code = curlx_sltosi(strtol(line, NULL, 10));
return 1;
return TRUE;
}
return 0;
return FALSE;
}
static CURLcode ftp_readresp(curl_socket_t sockfd,

View File

@ -327,11 +327,10 @@ static char* imap_atom(const char* str)
/* Function that checks for an ending IMAP status code at the start of the
given string but also detects various capabilities from the CAPABILITY
response including the supported authentication mechanisms. */
static int imap_endofresp(struct pingpong *pp, int *resp)
static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
int *resp)
{
char *line = pp->linestart_resp;
size_t len = pp->nread_resp;
struct imap_conn *imapc = &pp->conn->proto.imapc;
struct imap_conn *imapc = &conn->proto.imapc;
const char *id = imapc->resptag;
size_t id_len = strlen(id);
size_t wordlen;

View File

@ -395,7 +395,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
if(result)
return result;
if(pp->endofresp(pp, code)) {
if(pp->endofresp(conn, pp->linestart_resp, perline, code)) {
/* This is the end of the last line, copy the last line to the
start of the buffer and zero terminate, for old times sake (and
krb4)! */

View File

@ -64,7 +64,7 @@ struct pingpong {
CURLcode (*statemach_act)(struct connectdata *conn);
int (*endofresp)(struct pingpong *pp, int *code);
bool (*endofresp)(struct connectdata *conn, char *ptr, size_t len, int *code);
};
/*

View File

@ -220,11 +220,9 @@ static void pop3_to_pop3s(struct connectdata *conn)
given string, but also detects the APOP timestamp from the server greeting
as well as the supported authentication types and allowed SASL mechanisms
from the CAPA response. */
static int pop3_endofresp(struct pingpong *pp, int *resp)
static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
int *resp)
{
char *line = pp->linestart_resp;
size_t len = strlen(pp->linestart_resp);
struct connectdata *conn = pp->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
size_t wordlen;
size_t i;

View File

@ -216,11 +216,9 @@ static void smtp_to_smtps(struct connectdata *conn)
/* Function that checks for an ending SMTP status code at the start of the
given string, but also detects various capabilities from the EHLO response
including the supported authentication mechanisms. */
static int smtp_endofresp(struct pingpong *pp, int *resp)
static bool smtp_endofresp(struct connectdata *conn, char *line, size_t len,
int *resp)
{
char *line = pp->linestart_resp;
size_t len = strlen(pp->linestart_resp);
struct connectdata *conn = pp->conn;
struct smtp_conn *smtpc = &conn->proto.smtpc;
int result = FALSE;
size_t wordlen;