Commit b56c9eb4 authored by Steve Holme's avatar Steve Holme
Browse files

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.
parent 586f5d36
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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,
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,
+3 −4
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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)! */
+1 −1
Original line number Diff line number Diff line
@@ -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);
};

/*
+2 −4
Original line number Diff line number Diff line
@@ -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;
Loading