1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

smtp: Moved parsing of url path into separate function

This commit is contained in:
Steve Holme 2013-04-12 23:15:51 +01:00
parent c5ba0c2f54
commit 73cbd21b5e

View File

@ -99,6 +99,7 @@ static int smtp_getsock(struct connectdata *conn, curl_socket_t *socks,
int numsocks); int numsocks);
static CURLcode smtp_doing(struct connectdata *conn, bool *dophase_done); static CURLcode smtp_doing(struct connectdata *conn, bool *dophase_done);
static CURLcode smtp_setup_connection(struct connectdata *conn); static CURLcode smtp_setup_connection(struct connectdata *conn);
static CURLcode smtp_parse_url_path(struct connectdata *conn);
/* /*
* SMTP protocol handler. * SMTP protocol handler.
@ -1300,8 +1301,6 @@ static CURLcode smtp_connect(struct connectdata *conn, bool *done)
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct smtp_conn *smtpc = &conn->proto.smtpc; struct smtp_conn *smtpc = &conn->proto.smtpc;
struct pingpong *pp = &smtpc->pp; struct pingpong *pp = &smtpc->pp;
const char *path = conn->data->state.path;
char localhost[HOSTNAME_MAX + 1];
*done = FALSE; /* default to not done yet */ *done = FALSE; /* default to not done yet */
@ -1326,16 +1325,8 @@ static CURLcode smtp_connect(struct connectdata *conn, bool *done)
/* Initialise the pingpong layer */ /* Initialise the pingpong layer */
Curl_pp_init(pp); Curl_pp_init(pp);
/* Calculate the path if necessary */ /* Parse the URL path */
if(!*path) { result = smtp_parse_url_path(conn);
if(!Curl_gethostname(localhost, sizeof(localhost)))
path = localhost;
else
path = "localhost";
}
/* URL decode the path and use it as the domain in our EHLO */
result = Curl_urldecode(conn->data, path, 0, &smtpc->domain, NULL, TRUE);
if(result) if(result)
return result; return result;
@ -1640,6 +1631,33 @@ static CURLcode smtp_setup_connection(struct connectdata *conn)
return CURLE_OK; return CURLE_OK;
} }
/***********************************************************************
*
* smtp_parse_url_path()
*
* Parse the URL path into separate path components.
*/
static CURLcode smtp_parse_url_path(struct connectdata *conn)
{
/* The SMTP struct is already initialised in smtp_connect() */
struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->state.proto.smtp;
struct smtp_conn *smtpc = &conn->proto.smtpc;
const char *path = data->state.path;
char localhost[HOSTNAME_MAX + 1];
/* Calculate the path if necessary */
if(!*path) {
if(!Curl_gethostname(localhost, sizeof(localhost)))
path = localhost;
else
path = "localhost";
}
/* URL decode the path and use it as the domain in our EHLO */
return Curl_urldecode(conn->data, path, 0, &smtpc->domain, NULL, TRUE);
}
CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread) CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
{ {
/* When sending a SMTP payload we must detect CRLF. sequences making sure /* When sending a SMTP payload we must detect CRLF. sequences making sure