Commit 5c409d03 authored by Steve Holme's avatar Steve Holme Committed by Daniel Stenberg
Browse files

SMTP: Code policing and tidy up

parent a053560c
Loading
Loading
Loading
Loading
+14 −18
Original line number Original line Diff line number Diff line
@@ -427,7 +427,7 @@ static CURLcode smtp_authenticate(struct connectdata *conn)
#ifndef CURL_DISABLE_CRYPTO_AUTH
#ifndef CURL_DISABLE_CRYPTO_AUTH
  if(smtpc->authmechs & SMTP_AUTH_CRAM_MD5) {
  if(smtpc->authmechs & SMTP_AUTH_CRAM_MD5) {
    mech = "CRAM-MD5";
    mech = "CRAM-MD5";
    state1 = SMTP_AUTHCRAM;
    state1 = SMTP_AUTHCRAMMD5;
    smtpc->authused = SMTP_AUTH_CRAM_MD5;
    smtpc->authused = SMTP_AUTH_CRAM_MD5;
  }
  }
  else
  else
@@ -1146,7 +1146,7 @@ static CURLcode smtp_statemach_act(struct connectdata *conn)
      break;
      break;


#ifndef CURL_DISABLE_CRYPTO_AUTH
#ifndef CURL_DISABLE_CRYPTO_AUTH
    case SMTP_AUTHCRAM:
    case SMTP_AUTHCRAMMD5:
      result = smtp_state_authcram_resp(conn, smtpcode, smtpc->state);
      result = smtp_state_authcram_resp(conn, smtpcode, smtpc->state);
      break;
      break;
#endif
#endif
@@ -1339,13 +1339,12 @@ static CURLcode smtp_connect(struct connectdata *conn,
      path = "localhost";
      path = "localhost";
  }
  }


  /* url decode the path and use it as domain with EHLO */
  /* Url decode the path and use it as the domain in our EHLO */
  result = Curl_urldecode(conn->data, path, 0, &smtpc->domain, NULL, TRUE);
  result = Curl_urldecode(conn->data, path, 0, &smtpc->domain, NULL, TRUE);
  if(result)
  if(result)
    return result;
    return result;


  /* When we connect, we start in the state where we await the server greeting
  /* Set the state as we are waiting the server greeting */
   */
  state(conn, SMTP_SERVERGREET);
  state(conn, SMTP_SERVERGREET);


  if(data->state.used_interface == Curl_if_multi)
  if(data->state.used_interface == Curl_if_multi)
@@ -1430,7 +1429,6 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
 * This is the actual DO function for SMTP. Get a file/directory according to
 * This is the actual DO function for SMTP. Get a file/directory according to
 * the options previously setup.
 * the options previously setup.
 */
 */

static
static
CURLcode smtp_perform(struct connectdata *conn,
CURLcode smtp_perform(struct connectdata *conn,
                     bool *connected,  /* connect status after PASV / PORT */
                     bool *connected,  /* connect status after PASV / PORT */
@@ -1604,8 +1602,7 @@ static CURLcode smtp_doing(struct connectdata *conn,
 * Performs all commands done before a regular transfer between a local and a
 * Performs all commands done before a regular transfer between a local and a
 * remote host.
 * remote host.
 */
 */
static
static CURLcode smtp_regular_transfer(struct connectdata *conn,
CURLcode smtp_regular_transfer(struct connectdata *conn,
                                      bool *dophase_done)
                                      bool *dophase_done)
{
{
  CURLcode result = CURLE_OK;
  CURLcode result = CURLE_OK;
@@ -1654,8 +1651,8 @@ static CURLcode smtp_setup_connection(struct connectdata *conn)
      return CURLE_UNSUPPORTED_PROTOCOL;
      return CURLE_UNSUPPORTED_PROTOCOL;
#endif
#endif
    }
    }
    /*

     * We explicitly mark this connection as persistent here as we're doing
    /* We explicitly mark this connection as persistent here as we're doing
     * SMTP over HTTP and thus we accidentally avoid setting this value
     * SMTP over HTTP and thus we accidentally avoid setting this value
     * otherwise.
     * otherwise.
     */
     */
@@ -1688,10 +1685,10 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
    failf (data, "Failed to alloc scratch buffer!");
    failf (data, "Failed to alloc scratch buffer!");
    return CURLE_OUT_OF_MEMORY;
    return CURLE_OUT_OF_MEMORY;
  }
  }

  /* This loop can be improved by some kind of Boyer-Moore style of
  /* This loop can be improved by some kind of Boyer-Moore style of
     approach but that is saved for later... */
     approach but that is saved for later... */
  for(i = 0, si = 0; i < nread; i++) {
  for(i = 0, si = 0; i < nread; i++) {

    if(SMTP_EOB[smtpc->eob] == data->req.upload_fromhere[i])
    if(SMTP_EOB[smtpc->eob] == data->req.upload_fromhere[i])
      smtpc->eob++;
      smtpc->eob++;
    else if(smtpc->eob) {
    else if(smtpc->eob) {
@@ -1719,8 +1716,7 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
    }
    }
    else if(!smtpc->eob)
    else if(!smtpc->eob)
      data->state.scratch[si++] = data->req.upload_fromhere[i];
      data->state.scratch[si++] = data->req.upload_fromhere[i];

  }
  } /* for() */


  if(si != nread) {
  if(si != nread) {
    /* only use the new buffer if we replaced something */
    /* only use the new buffer if we replaced something */
+2 −2
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@
 *                            | (__| |_| |  _ <| |___
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *                             \___|\___/|_| \_\_____|
 *
 *
 * Copyright (C) 2009 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 2009 - 2012, 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
@@ -39,7 +39,7 @@ typedef enum {
  SMTP_AUTHPLAIN,
  SMTP_AUTHPLAIN,
  SMTP_AUTHLOGIN,
  SMTP_AUTHLOGIN,
  SMTP_AUTHPASSWD,
  SMTP_AUTHPASSWD,
  SMTP_AUTHCRAM,
  SMTP_AUTHCRAMMD5,
  SMTP_AUTHNTLM,
  SMTP_AUTHNTLM,
  SMTP_AUTHNTLM_TYPE2MSG,
  SMTP_AUTHNTLM_TYPE2MSG,
  SMTP_AUTH,
  SMTP_AUTH,