diff options
author | Steve Holme <steve_holme@hotmail.com> | 2012-03-24 12:28:11 +0000 |
---|---|---|
committer | Steve Holme <steve_holme@hotmail.com> | 2012-03-24 12:28:11 +0000 |
commit | 2da89708ecea44b15c2ed9642b391e33f5188e91 (patch) | |
tree | 1e4cda93fa98a625468b20f85c3ef61f1e324406 /lib | |
parent | 5c62a551c431e05ab7a80cf48985870ee54c1a68 (diff) |
pop3.c: Code policing and tidy up
Corrected character and line spacing and re-ordered list and retr
functions based on the order of their state machines.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pop3.c | 130 |
1 files changed, 66 insertions, 64 deletions
diff --git a/lib/pop3.c b/lib/pop3.c index 6b7e01a60..e3f31c893 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -127,7 +127,6 @@ const struct Curl_handler Curl_handler_pop3 = { PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ }; - #ifdef USE_SSL /* * POP3S protocol handler. @@ -180,7 +179,6 @@ static const struct Curl_handler Curl_handler_pop3_proxy = { PROTOPT_NONE /* flags */ }; - #ifdef USE_SSL /* * HTTP-proxyed POP3S protocol handler. @@ -208,7 +206,6 @@ static const struct Curl_handler Curl_handler_pop3s_proxy = { #endif #endif - /* function that checks for a pop3 status code at the start of the given string */ static int pop3_endofresp(struct pingpong *pp, @@ -219,7 +216,7 @@ static int pop3_endofresp(struct pingpong *pp, if(((len >= 3) && !memcmp("+OK", line, 3)) || ((len >= 4) && !memcmp("-ERR", line, 4))) { - *resp=line[1]; /* O or E */ + *resp = line[1]; /* O or E */ return TRUE; } @@ -383,6 +380,7 @@ static CURLcode pop3_state_pass_resp(struct connectdata *conn, { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; + (void)instate; /* no use for this yet */ if(pop3code != 'O') { @@ -395,8 +393,8 @@ static CURLcode pop3_state_pass_resp(struct connectdata *conn, return result; } -/* for the retr response */ -static CURLcode pop3_state_retr_resp(struct connectdata *conn, +/* for the list response */ +static CURLcode pop3_state_list_resp(struct connectdata *conn, int pop3code, pop3state instate) { @@ -413,14 +411,23 @@ static CURLcode pop3_state_retr_resp(struct connectdata *conn, return CURLE_RECV_ERROR; } + /* This 'OK' line ends with a CR LF pair which is the two first bytes of the + EOB string so count this is two matching bytes. This is necessary to make + the code detect the EOB if the only data than comes now is %2e CR LF like + when there is no body to return. */ + pop3c->eob = 2; + + /* But since this initial CR LF pair is not part of the actual body, we set + the strip counter here so that these bytes won't be delivered. */ + pop3c->strip = 2; + /* POP3 download */ Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp, -1, NULL); /* no upload here */ if(pp->cache) { - /* The header "cache" contains a bunch of data that is actually body - content so send it as such. Note that there may even be additional - "headers" after the body */ + /* The header "cache" contains a bunch of data that is actually list data + so send it as such */ if(!data->set.opt_no_body) { result = Curl_pop3_write(conn, pp->cache, pp->cache_size); @@ -440,8 +447,28 @@ static CURLcode pop3_state_retr_resp(struct connectdata *conn, return result; } -/* for the list response */ -static CURLcode pop3_state_list_resp(struct connectdata *conn, +/* for LIST response with a given message */ +static CURLcode pop3_state_list_single_resp(struct connectdata *conn, + int pop3code, + pop3state instate) +{ + CURLcode result = CURLE_OK; + struct SessionHandle *data = conn->data; + + (void)instate; /* no use for this yet */ + + if(pop3code != 'O') { + failf(data, "Invalid message. %c", pop3code); + result = CURLE_REMOTE_FILE_NOT_FOUND; + } + + state(conn, POP3_STOP); + + return result; +} + +/* for the retr response */ +static CURLcode pop3_state_retr_resp(struct connectdata *conn, int pop3code, pop3state instate) { @@ -458,23 +485,14 @@ static CURLcode pop3_state_list_resp(struct connectdata *conn, return CURLE_RECV_ERROR; } - /* This 'OK' line ends with a CR LF pair which is the two first bytes of the - EOB string so count this is two matching bytes. This is necessary to make - the code detect the EOB if the only data than comes now is %2e CR LF like - when there is no body to return. */ - pop3c->eob = 2; - - /* But since this initial CR LF pair is not part of the actual body, we set - the strip counter here so that these bytes won't be delivered. */ - pop3c->strip = 2; - /* POP3 download */ Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp, -1, NULL); /* no upload here */ if(pp->cache) { - /* The header "cache" contains a bunch of data that is actually list data - so send it as such */ + /* The header "cache" contains a bunch of data that is actually body + content so send it as such. Note that there may even be additional + "headers" after the body */ if(!data->set.opt_no_body) { result = Curl_pop3_write(conn, pp->cache, pp->cache_size); @@ -494,21 +512,24 @@ static CURLcode pop3_state_list_resp(struct connectdata *conn, return result; } -/* for LIST response with a given message */ -static CURLcode pop3_state_list_single_resp(struct connectdata *conn, - int pop3code, - pop3state instate) +/* start the DO phase for LIST */ +static CURLcode pop3_list(struct connectdata *conn) { CURLcode result = CURLE_OK; - struct SessionHandle *data = conn->data; - (void)instate; /* no use for this yet */ + struct pop3_conn *pop3c = &conn->proto.pop3c; - if(pop3code != 'O') { - failf(data, "Invalid message. %c", pop3code); - result = CURLE_REMOTE_FILE_NOT_FOUND; - } + if(pop3c->mailbox[0] != '\0') + result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST %s", pop3c->mailbox); + else + result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST"); + if(result) + return result; + + if(pop3c->mailbox[0] != '\0') + state(conn, POP3_LIST_SINGLE); + else + state(conn, POP3_LIST); - state(conn, POP3_STOP); return result; } @@ -523,26 +544,7 @@ static CURLcode pop3_retr(struct connectdata *conn) return result; state(conn, POP3_RETR); - return result; -} - -/* start the DO phase for LIST */ -static CURLcode pop3_list(struct connectdata *conn) -{ - CURLcode result = CURLE_OK; - struct pop3_conn *pop3c = &conn->proto.pop3c; - if(pop3c->mailbox[0] != '\0') - result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST %s", pop3c->mailbox); - else - result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST"); - if(result) - return result; - - if(pop3c->mailbox[0] != '\0') - state(conn, POP3_LIST_SINGLE); - else - state(conn, POP3_LIST); return result; } @@ -582,10 +584,6 @@ static CURLcode pop3_statemach_act(struct connectdata *conn) result = pop3_state_starttls_resp(conn, pop3code, pop3c->state); break; - case POP3_RETR: - result = pop3_state_retr_resp(conn, pop3code, pop3c->state); - break; - case POP3_LIST: result = pop3_state_list_resp(conn, pop3code, pop3c->state); break; @@ -594,6 +592,10 @@ static CURLcode pop3_statemach_act(struct connectdata *conn) result = pop3_state_list_single_resp(conn, pop3code, pop3c->state); break; + case POP3_RETR: + result = pop3_state_retr_resp(conn, pop3code, pop3c->state); + break; + case POP3_QUIT: /* fallthrough, just stop! */ default: @@ -668,7 +670,7 @@ static CURLcode pop3_init(struct connectdata *conn) * a part of the easy interface, it will always be TRUE. */ static CURLcode pop3_connect(struct connectdata *conn, - bool *done) /* see description above */ + bool *done) /* see description above */ { CURLcode result; struct pop3_conn *pop3c = &conn->proto.pop3c; @@ -732,7 +734,8 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status, struct SessionHandle *data = conn->data; struct FTP *pop3 = data->state.proto.pop3; struct pop3_conn *pop3c = &conn->proto.pop3c; - CURLcode result=CURLE_OK; + CURLcode result = CURLE_OK; + (void)premature; if(!pop3) @@ -749,7 +752,6 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status, } Curl_safefree(pop3c->mailbox); - pop3c->mailbox = NULL; /* Clear the transfer mode for the next connection */ pop3->transfer = FTPTRANSFER_BODY; @@ -861,6 +863,7 @@ static CURLcode pop3_quit(struct connectdata *conn) result = Curl_pp_sendf(&conn->proto.pop3c.pp, "QUIT", NULL); if(result) return result; + state(conn, POP3_QUIT); result = pop3_easy_statemach(conn); @@ -889,7 +892,6 @@ static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection) if(!dead_connection && pop3c->pp.conn) (void)pop3_quit(conn); /* ignore errors on the LOGOUT */ - Curl_pp_disconnect(&pop3c->pp); return CURLE_OK; @@ -939,6 +941,7 @@ static CURLcode pop3_doing(struct connectdata *conn, DEBUGF(infof(conn->data, "DO phase is complete\n")); } + return result; } @@ -952,9 +955,8 @@ static CURLcode pop3_doing(struct connectdata *conn, * remote host. * */ -static -CURLcode pop3_regular_transfer(struct connectdata *conn, - bool *dophase_done) +static CURLcode pop3_regular_transfer(struct connectdata *conn, + bool *dophase_done) { CURLcode result=CURLE_OK; bool connected=FALSE; |