Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
#endif
}
data->state.path++; /* don't include the initial slash */
return CURLE_OK;
}
/* this is the 5-bytes End-Of-Body marker for POP3 */
#define POP3_EOB "\x0d\x0a\x2e\x0d\x0a"
#define POP3_EOB_LEN 5
/*
* This function scans the body after the end-of-body and writes everything
* until the end is found.
*/
CURLcode Curl_pop3_write(struct connectdata *conn,
char *str,
size_t nread)
{
/* This code could be made into a special function in the handler struct. */
CURLcode result;
struct SessionHandle *data = conn->data;
struct SingleRequest *k = &data->req;
/* Detect the end-of-body marker, which is 5 bytes:
0d 0a 2e 0d 0a. This marker can of course be spread out
over up to 5 different data chunks. Deal with it! */
struct pop3_conn *pop3c = &conn->proto.pop3c;
size_t checkmax = (nread >= POP3_EOB_LEN?POP3_EOB_LEN:nread);
size_t checkleft = POP3_EOB_LEN-pop3c->eob;
size_t check = (checkmax >= checkleft?checkleft:checkmax);
if(!memcmp(POP3_EOB, &str[nread - check], check)) {
/* substring match */
pop3c->eob += check;
if(pop3c->eob == POP3_EOB_LEN) {
/* full match, the transfer is done! */
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
nread -= check;
k->keepon &= ~KEEP_RECV;
pop3c->eob = 0;
}
}
else if(pop3c->eob) {
/* not a match, but we matched a piece before so we must now
send that part as body first, before we move on and send
this buffer */
result = Curl_client_write(conn, CLIENTWRITE_BODY,
(char *)POP3_EOB, pop3c->eob);
if(result)
return result;
pop3c->eob = 0;
}
result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);
return result;
}
#endif /* CURL_DISABLE_POP3 */