1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

TFTP: re-indented the source code

Just made sure that the good old curl indentation style is used all over
this file.
This commit is contained in:
Daniel Stenberg 2010-09-26 23:38:00 +02:00
parent 6bf2014745
commit 33c3bb057b

View File

@ -169,7 +169,7 @@ static CURLcode tftp_connect(struct connectdata *conn, bool *done);
static CURLcode tftp_disconnect(struct connectdata *conn); static CURLcode tftp_disconnect(struct connectdata *conn);
static CURLcode tftp_do(struct connectdata *conn, bool *done); static CURLcode tftp_do(struct connectdata *conn, bool *done);
static CURLcode tftp_done(struct connectdata *conn, static CURLcode tftp_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
static CURLcode tftp_setup_connection(struct connectdata * conn); static CURLcode tftp_setup_connection(struct connectdata * conn);
static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done); static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done);
static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done); static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done);
@ -374,12 +374,12 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
} }
else if(blksize > TFTP_BLKSIZE_MAX) { else if(blksize > TFTP_BLKSIZE_MAX) {
failf(data, "%s (%d)", "blksize is larger than max supported", failf(data, "%s (%d)", "blksize is larger than max supported",
TFTP_BLKSIZE_MAX); TFTP_BLKSIZE_MAX);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
} }
else if(blksize < TFTP_BLKSIZE_MIN) { else if(blksize < TFTP_BLKSIZE_MIN) {
failf(data, "%s (%d)", "blksize is smaller than min supported", failf(data, "%s (%d)", "blksize is smaller than min supported",
TFTP_BLKSIZE_MIN); TFTP_BLKSIZE_MIN);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
} }
else if (blksize > state->requested_blksize) { else if (blksize > state->requested_blksize) {
@ -387,13 +387,13 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
* support for the server requesting a bigger blksize than the client * support for the server requesting a bigger blksize than the client
* requests */ * requests */
failf(data, "%s (%ld)", failf(data, "%s (%ld)",
"server requested blksize larger than allocated", blksize); "server requested blksize larger than allocated", blksize);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
} }
state->blksize = (int)blksize; state->blksize = (int)blksize;
infof(data, "%s (%d) %s (%d)\n", "blksize parsed from OACK", infof(data, "%s (%d) %s (%d)\n", "blksize parsed from OACK",
state->blksize, "requested", state->requested_blksize); state->blksize, "requested", state->requested_blksize);
} }
else if(checkprefix(option, TFTP_OPTION_TSIZE)) { else if(checkprefix(option, TFTP_OPTION_TSIZE)) {
long tsize = 0; long tsize = 0;
@ -716,48 +716,48 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
case TFTP_EVENT_ACK: case TFTP_EVENT_ACK:
case TFTP_EVENT_OACK: case TFTP_EVENT_OACK:
if (event == TFTP_EVENT_ACK) { if (event == TFTP_EVENT_ACK) {
/* Ack the packet */ /* Ack the packet */
rblock = getrpacketblock(&state->rpacket); rblock = getrpacketblock(&state->rpacket);
if(rblock != state->block && if(rblock != state->block &&
/* There's a bug in tftpd-hpa that causes it to send us an ack for /* There's a bug in tftpd-hpa that causes it to send us an ack for
* 65535 when the block number wraps to 0. So when we're expecting * 65535 when the block number wraps to 0. So when we're expecting
* 0, also accept 65535. See * 0, also accept 65535. See
* http://syslinux.zytor.com/archives/2010-September/015253.html * http://syslinux.zytor.com/archives/2010-September/015253.html
* */ * */
!(state->block == 0 && rblock == 65535)) { !(state->block == 0 && rblock == 65535)) {
/* This isn't the expected block. Log it and up the retry counter */ /* This isn't the expected block. Log it and up the retry counter */
infof(data, "Received ACK for block %d, expecting %d\n", infof(data, "Received ACK for block %d, expecting %d\n",
rblock, state->block); rblock, state->block);
state->retries++; state->retries++;
/* Bail out if over the maximum */ /* Bail out if over the maximum */
if(state->retries>state->retry_max) { if(state->retries>state->retry_max) {
failf(data, "tftp_tx: giving up waiting for block %d ack", failf(data, "tftp_tx: giving up waiting for block %d ack",
state->block); state->block);
res = CURLE_SEND_ERROR; res = CURLE_SEND_ERROR;
}
else {
/* Re-send the data packet */
sbytes = sendto(state->sockfd, (void *)&state->spacket,
4+state->sbytes, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
res = CURLE_SEND_ERROR;
} }
else { }
/* Re-send the data packet */ return res;
sbytes = sendto(state->sockfd, (void *)&state->spacket, }
4+state->sbytes, SEND_4TH_ARG, /* This is the expected packet. Reset the counters and send the next
(struct sockaddr *)&state->remote_addr, block */
state->remote_addrlen); time(&state->rx_time);
/* Check all sbytes were sent */ state->block++;
if(sbytes<0) {
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
res = CURLE_SEND_ERROR;
}
}
return res;
}
/* This is the expected packet. Reset the counters and send the next
block */
time(&state->rx_time);
state->block++;
}
else {
state->block = 1; /* first data block is 1 when using OACK */
} }
else
state->block = 1; /* first data block is 1 when using OACK */
state->retries = 0; state->retries = 0;
setpacketevent(&state->spacket, TFTP_EVENT_DATA); setpacketevent(&state->spacket, TFTP_EVENT_DATA);
setpacketblock(&state->spacket, state->block); setpacketblock(&state->spacket, state->block);
@ -1038,7 +1038,7 @@ static CURLcode tftp_connect(struct connectdata *conn, bool *done)
* *
**********************************************************/ **********************************************************/
static CURLcode tftp_done(struct connectdata *conn, CURLcode status, static CURLcode tftp_done(struct connectdata *conn, CURLcode status,
bool premature) bool premature)
{ {
CURLcode code = CURLE_OK; CURLcode code = CURLE_OK;
tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc; tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc;
@ -1062,7 +1062,7 @@ static CURLcode tftp_done(struct connectdata *conn, CURLcode status,
* *
**********************************************************/ **********************************************************/
static int tftp_getsock(struct connectdata *conn, curl_socket_t *socks, static int tftp_getsock(struct connectdata *conn, curl_socket_t *socks,
int numsocks) int numsocks)
{ {
if(!numsocks) if(!numsocks)
return GETSOCK_BLANK; return GETSOCK_BLANK;
@ -1091,11 +1091,11 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
/* Receive the packet */ /* Receive the packet */
fromlen = sizeof(fromaddr); fromlen = sizeof(fromaddr);
state->rbytes = (int)recvfrom(state->sockfd, state->rbytes = (int)recvfrom(state->sockfd,
(void *)state->rpacket.data, (void *)state->rpacket.data,
state->blksize+4, state->blksize+4,
0, 0,
(struct sockaddr *)&fromaddr, (struct sockaddr *)&fromaddr,
&fromlen); &fromlen);
if(state->remote_addrlen==0) { if(state->remote_addrlen==0) {
memcpy(&state->remote_addr, &fromaddr, fromlen); memcpy(&state->remote_addr, &fromaddr, fromlen);
state->remote_addrlen = fromlen; state->remote_addrlen = fromlen;
@ -1135,8 +1135,8 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
break; break;
case TFTP_EVENT_OACK: case TFTP_EVENT_OACK:
result = tftp_parse_option_ack(state, result = tftp_parse_option_ack(state,
(const char *)state->rpacket.data+2, (const char *)state->rpacket.data+2,
state->rbytes-2); state->rbytes-2);
if(result) if(result)
return result; return result;
break; break;
@ -1258,11 +1258,11 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
/* Force a progress callback if it's been too long */ /* Force a progress callback if it's been too long */
if (Curl_tvdiff(k->now, k->start) >= data->set.timeout) { if (Curl_tvdiff(k->now, k->start) >= data->set.timeout) {
if(Curl_pgrsUpdate(conn)) { if(Curl_pgrsUpdate(conn)) {
tftp_state_machine(state, TFTP_EVENT_ERROR); tftp_state_machine(state, TFTP_EVENT_ERROR);
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
} }
k->start = k->now; k->start = k->now;
} }
if(rc == -1) { if(rc == -1) {
@ -1289,7 +1289,7 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
else { else {
result = tftp_receive_packet(conn); result = tftp_receive_packet(conn);
if (result == CURLE_OK) if (result == CURLE_OK)
transaction_start = Curl_tvnow(); transaction_start = Curl_tvnow();
if(k->bytecountp) if(k->bytecountp)
*k->bytecountp = k->bytecount; /* read count */ *k->bytecountp = k->bytecount; /* read count */
@ -1461,7 +1461,7 @@ static CURLcode tftp_do(struct connectdata *conn, bool *done)
/* If tftp_perform() returned an error, use that for return code. If it /* If tftp_perform() returned an error, use that for return code. If it
was OK, see if tftp_translate_code() has an error. */ was OK, see if tftp_translate_code() has an error. */
if (code == CURLE_OK) if (code == CURLE_OK)
/* If we have encountered an internal tftp error, translate it. */ /* If we have encountered an internal tftp error, translate it. */
code = tftp_translate_code(state->error); code = tftp_translate_code(state->error);