1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -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 */ /* macro to check for the last line in an FTP server response */
#define LASTLINE(line) (STATUSCODE(line) && (' ' == line[3])) #define LASTLINE(line) (STATUSCODE(line) && (' ' == line[3]))
static int ftp_endofresp(struct pingpong *pp, static bool ftp_endofresp(struct connectdata *conn, char *line, size_t len,
int *code) int *code)
{ {
char *line = pp->linestart_resp; (void)conn;
size_t len = pp->nread_resp;
if((len > 3) && LASTLINE(line)) { if((len > 3) && LASTLINE(line)) {
*code = curlx_sltosi(strtol(line, NULL, 10)); *code = curlx_sltosi(strtol(line, NULL, 10));
return 1; return TRUE;
} }
return 0;
return FALSE;
} }
static CURLcode ftp_readresp(curl_socket_t sockfd, 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 /* Function that checks for an ending IMAP status code at the start of the
given string but also detects various capabilities from the CAPABILITY given string but also detects various capabilities from the CAPABILITY
response including the supported authentication mechanisms. */ 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; struct imap_conn *imapc = &conn->proto.imapc;
size_t len = pp->nread_resp;
struct imap_conn *imapc = &pp->conn->proto.imapc;
const char *id = imapc->resptag; const char *id = imapc->resptag;
size_t id_len = strlen(id); size_t id_len = strlen(id);
size_t wordlen; size_t wordlen;

View File

@ -395,7 +395,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
if(result) if(result)
return 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 /* 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 start of the buffer and zero terminate, for old times sake (and
krb4)! */ krb4)! */

View File

@ -64,7 +64,7 @@ struct pingpong {
CURLcode (*statemach_act)(struct connectdata *conn); 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 given string, but also detects the APOP timestamp from the server greeting
as well as the supported authentication types and allowed SASL mechanisms as well as the supported authentication types and allowed SASL mechanisms
from the CAPA response. */ 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; struct pop3_conn *pop3c = &conn->proto.pop3c;
size_t wordlen; size_t wordlen;
size_t i; 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 /* 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 given string, but also detects various capabilities from the EHLO response
including the supported authentication mechanisms. */ 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; struct smtp_conn *smtpc = &conn->proto.smtpc;
int result = FALSE; int result = FALSE;
size_t wordlen; size_t wordlen;