1
0
mirror of https://github.com/moparisthebest/curl synced 2025-02-28 09:21:50 -05:00

email: Moved server greeting responses into separate functions

Moved the server greeting response handling code from the statemach_act
functions to separate response functions. This makes the code simpler
to follow and provides consistency with the other responses that are
handled here.
This commit is contained in:
Steve Holme 2012-03-24 11:55:34 +00:00
parent 602a8a565c
commit 5c62a551c4
3 changed files with 96 additions and 45 deletions

View File

@ -343,6 +343,36 @@ static void imap_to_imaps(struct connectdata *conn)
#define imap_to_imaps(x) Curl_nop_stmt #define imap_to_imaps(x) Curl_nop_stmt
#endif #endif
/* for the initial server greeting */
static CURLcode imap_state_servergreet_resp(struct connectdata *conn,
int imapcode,
imapstate instate)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
(void)instate; /* no use for this yet */
if(imapcode != 'O') {
failf(data, "Got unexpected imap-server response");
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
to TLS connection now */
const char *str;
str = getcmdid(conn);
result = imapsendf(conn, str, "%s STARTTLS", str);
state(conn, IMAP_STARTTLS);
}
else
result = imap_state_login(conn);
return result;
}
/* for STARTTLS responses */ /* for STARTTLS responses */
static CURLcode imap_state_starttls_resp(struct connectdata *conn, static CURLcode imap_state_starttls_resp(struct connectdata *conn,
int imapcode, int imapcode,
@ -373,7 +403,9 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn,
} }
} }
} }
state(conn, IMAP_STOP); state(conn, IMAP_STOP);
return result; return result;
} }
@ -400,6 +432,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(imapcode != 'O') { if(imapcode != 'O') {
@ -408,6 +441,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
} }
state(conn, IMAP_STOP); state(conn, IMAP_STOP);
return result; return result;
} }
@ -422,6 +456,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn,
struct FTP *imap = data->state.proto.imap; struct FTP *imap = data->state.proto.imap;
struct pingpong *pp = &imapc->pp; struct pingpong *pp = &imapc->pp;
const char *ptr = data->state.buffer; const char *ptr = data->state.buffer;
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if('*' != imapcode) { if('*' != imapcode) {
@ -489,6 +524,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn,
result = CURLE_FTP_WEIRD_SERVER_REPLY; /* TODO: fix this code */ result = CURLE_FTP_WEIRD_SERVER_REPLY; /* TODO: fix this code */
state(conn, IMAP_STOP); state(conn, IMAP_STOP);
return result; return result;
} }
@ -558,7 +594,6 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
{ {
CURLcode result; CURLcode result;
curl_socket_t sock = conn->sock[FIRSTSOCKET]; curl_socket_t sock = conn->sock[FIRSTSOCKET];
struct SessionHandle *data=conn->data;
int imapcode; int imapcode;
struct imap_conn *imapc = &conn->proto.imapc; struct imap_conn *imapc = &conn->proto.imapc;
struct pingpong *pp = &imapc->pp; struct pingpong *pp = &imapc->pp;
@ -580,24 +615,7 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
/* we have now received a full IMAP server response */ /* we have now received a full IMAP server response */
switch(imapc->state) { switch(imapc->state) {
case IMAP_SERVERGREET: case IMAP_SERVERGREET:
if(imapcode != 'O') { result = imap_state_servergreet_resp(conn, imapcode, imapc->state);
failf(data, "Got unexpected imap-server response");
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
to TLS connection now */
const char *str;
str = getcmdid(conn);
result = imapsendf(conn, str, "%s STARTTLS", str);
state(conn, IMAP_STARTTLS);
}
else
result = imap_state_login(conn);
if(result)
return result;
break; break;
case IMAP_LOGIN: case IMAP_LOGIN:

View File

@ -287,6 +287,34 @@ static void pop3_to_pop3s(struct connectdata *conn)
#define pop3_to_pop3s(x) Curl_nop_stmt #define pop3_to_pop3s(x) Curl_nop_stmt
#endif #endif
/* for the initial server greeting */
static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct pop3_conn *pop3c = &conn->proto.pop3c;
(void)instate; /* no use for this yet */
if(pop3code != 'O') {
failf(data, "Got unexpected pop3-server response");
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
to TLS connection now */
result = Curl_pp_sendf(&pop3c->pp, "STLS");
state(conn, POP3_STARTTLS);
}
else
result = pop3_state_user(conn);
return result;
}
/* for STARTTLS responses */ /* for STARTTLS responses */
static CURLcode pop3_state_starttls_resp(struct connectdata *conn, static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
int pop3code, int pop3code,
@ -294,6 +322,7 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(pop3code != 'O') { if(pop3code != 'O') {
@ -316,6 +345,7 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
state(conn, POP3_STOP); state(conn, POP3_STOP);
} }
} }
return result; return result;
} }
@ -342,6 +372,7 @@ static CURLcode pop3_state_user_resp(struct connectdata *conn,
return result; return result;
state(conn, POP3_PASS); state(conn, POP3_PASS);
return result; return result;
} }
@ -360,6 +391,7 @@ static CURLcode pop3_state_pass_resp(struct connectdata *conn,
} }
state(conn, POP3_STOP); state(conn, POP3_STOP);
return result; return result;
} }
@ -518,7 +550,6 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
{ {
CURLcode result; CURLcode result;
curl_socket_t sock = conn->sock[FIRSTSOCKET]; curl_socket_t sock = conn->sock[FIRSTSOCKET];
struct SessionHandle *data=conn->data;
int pop3code; int pop3code;
struct pop3_conn *pop3c = &conn->proto.pop3c; struct pop3_conn *pop3c = &conn->proto.pop3c;
struct pingpong *pp = &pop3c->pp; struct pingpong *pp = &pop3c->pp;
@ -536,21 +567,7 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
/* we have now received a full POP3 server response */ /* we have now received a full POP3 server response */
switch(pop3c->state) { switch(pop3c->state) {
case POP3_SERVERGREET: case POP3_SERVERGREET:
if(pop3code != 'O') { result = pop3_state_servergreet_resp(conn, pop3code, pop3c->state);
failf(data, "Got unexpected pop3-server response");
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
to TLS connection now */
result = Curl_pp_sendf(&pop3c->pp, "STLS");
state(conn, POP3_STARTTLS);
}
else
result = pop3_state_user(conn);
if(result)
return result;
break; break;
case POP3_USER: case POP3_USER:
@ -585,6 +602,7 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
break; break;
} }
} }
return result; return result;
} }

View File

@ -499,6 +499,26 @@ static void smtp_to_smtps(struct connectdata *conn)
#define smtp_to_smtps(x) Curl_nop_stmt #define smtp_to_smtps(x) Curl_nop_stmt
#endif #endif
/* for the initial server greeting */
static CURLcode smtp_state_servergreet_resp(struct connectdata *conn,
int smtpcode,
smtpstate instate)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
(void)instate; /* no use for this yet */
if(smtpcode/100 != 2) {
failf(data, "Got unexpected smtp-server response: %d", smtpcode);
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
result = smtp_state_ehlo(conn);
return result;
}
/* for STARTTLS responses */ /* for STARTTLS responses */
static CURLcode smtp_state_starttls_resp(struct connectdata *conn, static CURLcode smtp_state_starttls_resp(struct connectdata *conn,
int smtpcode, int smtpcode,
@ -506,6 +526,7 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn,
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(smtpcode != 220) { if(smtpcode != 220) {
@ -1066,14 +1087,15 @@ static CURLcode smtp_state_data_resp(struct connectdata *conn,
FIRSTSOCKET, smtp->bytecountp); FIRSTSOCKET, smtp->bytecountp);
state(conn, SMTP_STOP); state(conn, SMTP_STOP);
return CURLE_OK; return CURLE_OK;
} }
/* for the POSTDATA response, which is received after the entire DATA /* for the POSTDATA response, which is received after the entire DATA
part has been sent off to the server */ part has been sent off to the server */
static CURLcode smtp_state_postdata_resp(struct connectdata *conn, static CURLcode smtp_state_postdata_resp(struct connectdata *conn,
int smtpcode, int smtpcode,
smtpstate instate) smtpstate instate)
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
@ -1117,14 +1139,7 @@ static CURLcode smtp_statemach_act(struct connectdata *conn)
/* we have now received a full SMTP server response */ /* we have now received a full SMTP server response */
switch(smtpc->state) { switch(smtpc->state) {
case SMTP_SERVERGREET: case SMTP_SERVERGREET:
if(smtpcode/100 != 2) { result = smtp_state_servergreet_resp(conn, smtpcode, smtpc->state);
failf(data, "Got unexpected smtp-server response: %d", smtpcode);
return CURLE_FTP_WEIRD_SERVER_REPLY;
}
result = smtp_state_ehlo(conn);
if(result)
return result;
break; break;
case SMTP_EHLO: case SMTP_EHLO: