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

imap: use defined names for response codes

When working on this code I found the previous setup a bit weird while
using proper defines increases readability.

Closes #1824
This commit is contained in:
Daniel Stenberg 2017-08-24 13:39:07 +02:00
parent 4a7673c8ca
commit dff069fdf5
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -162,11 +162,15 @@ const struct Curl_handler Curl_handler_imaps = {
}; };
#endif #endif
#define IMAP_RESP_OK 1
#define IMAP_RESP_NOT_OK 2
#define IMAP_RESP_PREAUTH 3
/* SASL parameters for the imap protocol */ /* SASL parameters for the imap protocol */
static const struct SASLproto saslimap = { static const struct SASLproto saslimap = {
"imap", /* The service name */ "imap", /* The service name */
'+', /* Code received when continuation is expected */ '+', /* Code received when continuation is expected */
'O', /* Code to receive upon authentication success */ IMAP_RESP_OK, /* Code to receive upon authentication success */
0, /* Maximum initial response length (no max) */ 0, /* Maximum initial response length (no max) */
imap_perform_authenticate, /* Send authentication command */ imap_perform_authenticate, /* Send authentication command */
imap_continue_authenticate, /* Send authentication continuation */ imap_continue_authenticate, /* Send authentication continuation */
@ -249,17 +253,11 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
len -= id_len + 1; len -= id_len + 1;
if(len >= 2 && !memcmp(line, "OK", 2)) if(len >= 2 && !memcmp(line, "OK", 2))
*resp = 'O'; *resp = IMAP_RESP_OK;
else if(len >= 2 && !memcmp(line, "NO", 2))
*resp = 'N';
else if(len >= 3 && !memcmp(line, "BAD", 3))
*resp = 'B';
else if(len >= 7 && !memcmp(line, "PREAUTH", 7)) else if(len >= 7 && !memcmp(line, "PREAUTH", 7))
*resp = 'P'; *resp = IMAP_RESP_PREAUTH;
else { else
failf(conn->data, "Bad tagged response"); *resp = IMAP_RESP_NOT_OK;
*resp = -1;
}
return TRUE; return TRUE;
} }
@ -795,13 +793,13 @@ static CURLcode imap_state_servergreet_resp(struct connectdata *conn,
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(imapcode == 'P') { if(imapcode == IMAP_RESP_PREAUTH) {
/* PREAUTH */ /* PREAUTH */
struct imap_conn *imapc = &conn->proto.imapc; struct imap_conn *imapc = &conn->proto.imapc;
imapc->preauth = TRUE; imapc->preauth = TRUE;
infof(data, "PREAUTH connection, already authenticated!\n"); infof(data, "PREAUTH connection, already authenticated!\n");
} }
else if(imapcode != 'O') { else if(imapcode != IMAP_RESP_OK) {
failf(data, "Got unexpected imap-server response"); failf(data, "Got unexpected imap-server response");
return CURLE_WEIRD_SERVER_REPLY; return CURLE_WEIRD_SERVER_REPLY;
} }
@ -873,7 +871,7 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn,
line += wordlen; line += wordlen;
} }
} }
else if(imapcode == 'O') { else if(imapcode == IMAP_RESP_OK) {
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested */ /* We don't have a SSL/TLS connection yet, but SSL is requested */
if(imapc->tls_supported) if(imapc->tls_supported)
@ -906,7 +904,7 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn,
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(imapcode != 'O') { if(imapcode != IMAP_RESP_OK) {
if(data->set.use_ssl != CURLUSESSL_TRY) { if(data->set.use_ssl != CURLUSESSL_TRY) {
failf(data, "STARTTLS denied"); failf(data, "STARTTLS denied");
result = CURLE_USE_SSL_FAILED; result = CURLE_USE_SSL_FAILED;
@ -964,7 +962,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
(void)instate; /* no use for this yet */ (void)instate; /* no use for this yet */
if(imapcode != 'O') { if(imapcode != IMAP_RESP_OK) {
failf(data, "Access denied. %c", imapcode); failf(data, "Access denied. %c", imapcode);
result = CURLE_LOGIN_DENIED; result = CURLE_LOGIN_DENIED;
} }
@ -992,7 +990,7 @@ static CURLcode imap_state_listsearch_resp(struct connectdata *conn,
result = Curl_client_write(conn, CLIENTWRITE_BODY, line, len + 1); result = Curl_client_write(conn, CLIENTWRITE_BODY, line, len + 1);
line[len] = '\0'; line[len] = '\0';
} }
else if(imapcode != 'O') else if(imapcode != IMAP_RESP_OK)
result = CURLE_QUOTE_ERROR; /* TODO: Fix error code */ result = CURLE_QUOTE_ERROR; /* TODO: Fix error code */
else else
/* End of DO phase */ /* End of DO phase */
@ -1021,7 +1019,7 @@ static CURLcode imap_state_select_resp(struct connectdata *conn, int imapcode,
imapc->mailbox_uidvalidity = strdup(tmp); imapc->mailbox_uidvalidity = strdup(tmp);
} }
} }
else if(imapcode == 'O') { else if(imapcode == IMAP_RESP_OK) {
/* Check if the UIDVALIDITY has been specified and matches */ /* Check if the UIDVALIDITY has been specified and matches */
if(imap->uidvalidity && imapc->mailbox_uidvalidity && if(imap->uidvalidity && imapc->mailbox_uidvalidity &&
strcmp(imap->uidvalidity, imapc->mailbox_uidvalidity)) { strcmp(imap->uidvalidity, imapc->mailbox_uidvalidity)) {
@ -1153,7 +1151,7 @@ static CURLcode imap_state_fetch_final_resp(struct connectdata *conn,
(void)instate; /* No use for this yet */ (void)instate; /* No use for this yet */
if(imapcode != 'O') if(imapcode != IMAP_RESP_OK)
result = CURLE_WEIRD_SERVER_REPLY; result = CURLE_WEIRD_SERVER_REPLY;
else else
/* End of DONE phase */ /* End of DONE phase */
@ -1197,7 +1195,7 @@ static CURLcode imap_state_append_final_resp(struct connectdata *conn,
(void)instate; /* No use for this yet */ (void)instate; /* No use for this yet */
if(imapcode != 'O') if(imapcode != IMAP_RESP_OK)
result = CURLE_UPLOAD_FAILED; result = CURLE_UPLOAD_FAILED;
else else
/* End of DONE phase */ /* End of DONE phase */