mirror of https://github.com/moparisthebest/curl
pop3: Moved APOP detection into pop3_state_servergreet_resp()
In an effort to reduce what pop3_endofresp() does and bring the POP3 source back inline with the IMAP and SMTP protocols, moved the APOP detection into pop3_state_servergreet_resp().
This commit is contained in:
parent
fae7db8a31
commit
1cfb436a2f
54
lib/pop3.c
54
lib/pop3.c
|
@ -237,7 +237,6 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
|
||||||
{
|
{
|
||||||
struct pop3_conn *pop3c = &conn->proto.pop3c;
|
struct pop3_conn *pop3c = &conn->proto.pop3c;
|
||||||
size_t wordlen;
|
size_t wordlen;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
/* Do we have an error response? */
|
/* Do we have an error response? */
|
||||||
if(len >= 4 && !memcmp("-ERR", line, 4)) {
|
if(len >= 4 && !memcmp("-ERR", line, 4)) {
|
||||||
|
@ -246,31 +245,8 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Are we processing servergreet responses? */
|
|
||||||
if(pop3c->state == POP3_SERVERGREET) {
|
|
||||||
/* Look for the APOP timestamp */
|
|
||||||
if(len >= 3 && line[len - 3] == '>') {
|
|
||||||
for(i = 0; i < len - 3; ++i) {
|
|
||||||
if(line[i] == '<') {
|
|
||||||
/* Calculate the length of the timestamp */
|
|
||||||
size_t timestamplen = len - 2 - i;
|
|
||||||
|
|
||||||
/* Allocate some memory for the timestamp */
|
|
||||||
pop3c->apoptimestamp = (char *)calloc(1, timestamplen + 1);
|
|
||||||
|
|
||||||
if(!pop3c->apoptimestamp)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Copy the timestamp */
|
|
||||||
memcpy(pop3c->apoptimestamp, line + i, timestamplen);
|
|
||||||
pop3c->apoptimestamp[timestamplen] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Are we processing CAPA command responses? */
|
/* Are we processing CAPA command responses? */
|
||||||
else if(pop3c->state == POP3_CAPA) {
|
if(pop3c->state == POP3_CAPA) {
|
||||||
/* Do we have the terminating line? */
|
/* Do we have the terminating line? */
|
||||||
if(len >= 1 && !memcmp(line, ".", 1)) {
|
if(len >= 1 && !memcmp(line, ".", 1)) {
|
||||||
*resp = '+';
|
*resp = '+';
|
||||||
|
@ -733,6 +709,10 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
|
||||||
{
|
{
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
|
struct pop3_conn *pop3c = &conn->proto.pop3c;
|
||||||
|
const char *line = data->state.buffer;
|
||||||
|
size_t len = strlen(line);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
|
@ -740,8 +720,30 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
|
||||||
failf(data, "Got unexpected pop3-server response");
|
failf(data, "Got unexpected pop3-server response");
|
||||||
result = CURLE_FTP_WEIRD_SERVER_REPLY;
|
result = CURLE_FTP_WEIRD_SERVER_REPLY;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
/* Look for the APOP timestamp */
|
||||||
|
if(len >= 3 && line[len - 3] == '>') {
|
||||||
|
for(i = 0; i < len - 3; ++i) {
|
||||||
|
if(line[i] == '<') {
|
||||||
|
/* Calculate the length of the timestamp */
|
||||||
|
size_t timestamplen = len - 2 - i;
|
||||||
|
|
||||||
|
/* Allocate some memory for the timestamp */
|
||||||
|
pop3c->apoptimestamp = (char *)calloc(1, timestamplen + 1);
|
||||||
|
|
||||||
|
if(!pop3c->apoptimestamp)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Copy the timestamp */
|
||||||
|
memcpy(pop3c->apoptimestamp, line + i, timestamplen);
|
||||||
|
pop3c->apoptimestamp[timestamplen] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = pop3_perform_capa(conn);
|
result = pop3_perform_capa(conn);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue