aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/tftp.c
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-10-04 17:24:16 +0300
committerGitHub <noreply@github.com>2024-10-04 17:24:16 +0300
commita1e4766748b5924d3879ab6a0259b28ec3c5d535 (patch)
tree4480150864228623d6c9101a4ba8c049bda9aa90 /contrib/libs/curl/lib/tftp.c
parent6536467764bed7822214815ce92ed4dcd5bf409b (diff)
parenta46fe128b9c9c84438fc2aac337aeefdaecb99df (diff)
downloadydb-a1e4766748b5924d3879ab6a0259b28ec3c5d535.tar.gz
Merge pull request #10090 from ydb-platform/mergelibs-241004-1110
Library import 241004-1110
Diffstat (limited to 'contrib/libs/curl/lib/tftp.c')
-rw-r--r--contrib/libs/curl/lib/tftp.c97
1 files changed, 49 insertions, 48 deletions
diff --git a/contrib/libs/curl/lib/tftp.c b/contrib/libs/curl/lib/tftp.c
index 663015502d..dbae202d52 100644
--- a/contrib/libs/curl/lib/tftp.c
+++ b/contrib/libs/curl/lib/tftp.c
@@ -168,7 +168,7 @@ static CURLcode tftp_translate_code(tftp_error_t error);
*/
const struct Curl_handler Curl_handler_tftp = {
- "TFTP", /* scheme */
+ "tftp", /* scheme */
tftp_setup_connection, /* setup_connection */
tftp_do, /* do_it */
tftp_done, /* done */
@@ -181,7 +181,8 @@ const struct Curl_handler Curl_handler_tftp = {
ZERO_NULL, /* domore_getsock */
ZERO_NULL, /* perform_getsock */
tftp_disconnect, /* disconnect */
- ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* write_resp */
+ ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
PORT_TFTP, /* defport */
@@ -239,12 +240,11 @@ static CURLcode tftp_set_timeouts(struct tftp_state_data *state)
state->retry_time = 1;
infof(state->data,
- "set timeouts for state %d; Total % " CURL_FORMAT_CURL_OFF_T
- ", retry %d maxtry %d",
+ "set timeouts for state %d; Total % " FMT_OFF_T ", retry %d maxtry %d",
(int)state->state, timeout_ms, state->retry_time, state->retry_max);
/* init RX time */
- time(&state->rx_time);
+ state->rx_time = time(NULL);
return CURLE_OK;
}
@@ -314,7 +314,7 @@ static CURLcode tftp_parse_option_ack(struct tftp_state_data *state,
const char *tmp = ptr;
struct Curl_easy *data = state->data;
- /* if OACK doesn't contain blksize option, the default (512) must be used */
+ /* if OACK does not contain blksize option, the default (512) must be used */
state->blksize = TFTP_BLKSIZE_DEFAULT;
while(tmp < ptr + len) {
@@ -348,7 +348,7 @@ static CURLcode tftp_parse_option_ack(struct tftp_state_data *state,
return CURLE_TFTP_ILLEGAL;
}
else if(blksize > state->requested_blksize) {
- /* could realloc pkt buffers here, but the spec doesn't call out
+ /* could realloc pkt buffers here, but the spec does not call out
* support for the server requesting a bigger blksize than the client
* requests */
failf(data, "%s (%ld)",
@@ -433,7 +433,7 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
struct Curl_easy *data = state->data;
CURLcode result = CURLE_OK;
- /* Set ascii mode if -B flag was used */
+ /* Set ASCII mode if -B flag was used */
if(data->state.prefer_ascii)
mode = "netascii";
@@ -452,8 +452,6 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
if(data->state.upload) {
/* If we are uploading, send an WRQ */
setpacketevent(&state->spacket, TFTP_EVENT_WRQ);
- state->data->req.upload_fromhere =
- (char *)state->spacket.data + 4;
if(data->state.infilesize != -1)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
@@ -462,7 +460,7 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
setpacketevent(&state->spacket, TFTP_EVENT_RRQ);
}
/* As RFC3617 describes the separator slash is not actually part of the
- file name so we skip the always-present first letter of the path
+ filename so we skip the always-present first letter of the path
string. */
result = Curl_urldecode(&state->data->state.up.path[1], 0,
&filename, NULL, REJECT_ZERO);
@@ -470,9 +468,9 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
return result;
if(strlen(filename) > (state->blksize - strlen(mode) - 4)) {
- failf(data, "TFTP file name too long");
+ failf(data, "TFTP filename too long");
free(filename);
- return CURLE_TFTP_ILLEGAL; /* too long file name field */
+ return CURLE_TFTP_ILLEGAL; /* too long filename field */
}
msnprintf((char *)state->spacket.data + 2,
@@ -485,7 +483,7 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
char buf[64];
/* add tsize option */
if(data->state.upload && (data->state.infilesize != -1))
- msnprintf(buf, sizeof(buf), "%" CURL_FORMAT_CURL_OFF_T,
+ msnprintf(buf, sizeof(buf), "%" FMT_OFF_T,
data->state.infilesize);
else
strcpy(buf, "0"); /* the destination is large enough */
@@ -529,7 +527,7 @@ static CURLcode tftp_send_first(struct tftp_state_data *state,
senddata = sendto(state->sockfd, (void *)state->spacket.data,
(SEND_TYPE_ARG3)sbytes, 0,
&data->conn->remote_addr->sa_addr,
- data->conn->remote_addr->addrlen);
+ (curl_socklen_t)data->conn->remote_addr->addrlen);
if(senddata != (ssize_t)sbytes) {
char buffer[STRERROR_LEN];
failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
@@ -591,7 +589,7 @@ static CURLcode tftp_rx(struct tftp_state_data *state,
/* Is this the block we expect? */
rblock = getrpacketblock(&state->rpacket);
if(NEXT_BLOCKNUM(state->block) == rblock) {
- /* This is the expected block. Reset counters and ACK it. */
+ /* This is the expected block. Reset counters and ACK it. */
state->retries = 0;
}
else if(state->block == rblock) {
@@ -627,7 +625,7 @@ static CURLcode tftp_rx(struct tftp_state_data *state,
else {
state->state = TFTP_STATE_RX;
}
- time(&state->rx_time);
+ state->rx_time = time(NULL);
break;
case TFTP_EVENT_OACK:
@@ -645,16 +643,16 @@ static CURLcode tftp_rx(struct tftp_state_data *state,
return CURLE_SEND_ERROR;
}
- /* we're ready to RX data */
+ /* we are ready to RX data */
state->state = TFTP_STATE_RX;
- time(&state->rx_time);
+ state->rx_time = time(NULL);
break;
case TFTP_EVENT_TIMEOUT:
/* Increment the retry count and fail if over the limit */
state->retries++;
infof(data,
- "Timeout waiting for block %d ACK. Retries = %d",
+ "Timeout waiting for block %d ACK. Retries = %d",
NEXT_BLOCKNUM(state->block), state->retries);
if(state->retries > state->retry_max) {
state->error = TFTP_ERR_TIMEOUT;
@@ -680,8 +678,8 @@ static CURLcode tftp_rx(struct tftp_state_data *state,
4, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
- /* don't bother with the return code, but if the socket is still up we
- * should be a good TFTP client and let the server know we're done */
+ /* do not bother with the return code, but if the socket is still up we
+ * should be a good TFTP client and let the server know we are done */
state->state = TFTP_STATE_FIN;
break;
@@ -708,6 +706,8 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
struct SingleRequest *k = &data->req;
size_t cb; /* Bytes currently read */
char buffer[STRERROR_LEN];
+ char *bufptr;
+ bool eos;
switch(event) {
@@ -718,13 +718,13 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
int rblock = getrpacketblock(&state->rpacket);
if(rblock != state->block &&
- /* 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
+ /* There is 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 are expecting
* 0, also accept 65535. See
* https://www.syslinux.org/archives/2010-September/015612.html
* */
!(state->block == 0 && rblock == 65535)) {
- /* This isn't the expected block. Log it and up the retry counter */
+ /* This is not the expected block. Log it and up the retry counter */
infof(data, "Received ACK for block %d, expecting %d",
rblock, state->block);
state->retries++;
@@ -737,7 +737,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
else {
/* Re-send the data packet */
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
- 4 + state->sbytes, SEND_4TH_ARG,
+ 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
/* Check all sbytes were sent */
@@ -750,9 +750,9 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
return result;
}
- /* This is the expected packet. Reset the counters and send the next
+ /* This is the expected packet. Reset the counters and send the next
block */
- time(&state->rx_time);
+ state->rx_time = time(NULL);
state->block++;
}
else
@@ -771,17 +771,18 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
* data block.
* */
state->sbytes = 0;
- state->data->req.upload_fromhere = (char *)state->spacket.data + 4;
+ bufptr = (char *)state->spacket.data + 4;
do {
- result = Curl_fillreadbuffer(data, state->blksize - state->sbytes, &cb);
+ result = Curl_client_read(data, bufptr, state->blksize - state->sbytes,
+ &cb, &eos);
if(result)
return result;
state->sbytes += (int)cb;
- state->data->req.upload_fromhere += cb;
+ bufptr += cb;
} while(state->sbytes < state->blksize && cb);
sbytes = sendto(state->sockfd, (void *) state->spacket.data,
- 4 + state->sbytes, SEND_4TH_ARG,
+ 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
/* Check all sbytes were sent */
@@ -799,7 +800,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
state->retries++;
infof(data, "Timeout waiting for block %d ACK. "
" Retries = %d", NEXT_BLOCKNUM(state->block), state->retries);
- /* Decide if we've had enough */
+ /* Decide if we have had enough */
if(state->retries > state->retry_max) {
state->error = TFTP_ERR_TIMEOUT;
state->state = TFTP_STATE_FIN;
@@ -807,7 +808,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
else {
/* Re-send the data packet */
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
- 4 + state->sbytes, SEND_4TH_ARG,
+ 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
/* Check all sbytes were sent */
@@ -827,8 +828,8 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event)
(void)sendto(state->sockfd, (void *)state->spacket.data, 4, SEND_4TH_ARG,
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
- /* don't bother with the return code, but if the socket is still up we
- * should be a good TFTP client and let the server know we're done */
+ /* do not bother with the return code, but if the socket is still up we
+ * should be a good TFTP client and let the server know we are done */
state->state = TFTP_STATE_FIN;
break;
@@ -999,7 +1000,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done)
return CURLE_OUT_OF_MEMORY;
}
- /* we don't keep TFTP connections up basically because there's none or very
+ /* we do not keep TFTP connections up basically because there is none or very
* little gain for UDP */
connclose(conn, "TFTP");
@@ -1030,7 +1031,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done)
* IPv4 and IPv6...
*/
int rc = bind(state->sockfd, (struct sockaddr *)&state->local_addr,
- conn->remote_addr->addrlen);
+ (curl_socklen_t)conn->remote_addr->addrlen);
if(rc) {
char buffer[STRERROR_LEN];
failf(data, "bind() failed; %s",
@@ -1108,7 +1109,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data)
fromlen = sizeof(fromaddr);
state->rbytes = (int)recvfrom(state->sockfd,
(void *)state->rpacket.data,
- state->blksize + 4,
+ (RECV_TYPE_ARG3)state->blksize + 4,
0,
(struct sockaddr *)&fromaddr,
&fromlen);
@@ -1130,7 +1131,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data)
switch(state->event) {
case TFTP_EVENT_DATA:
- /* Don't pass to the client empty or retransmitted packets */
+ /* Do not pass to the client empty or retransmitted packets */
if(state->rbytes > 4 &&
(NEXT_BLOCKNUM(state->block) == getrpacketblock(&state->rpacket))) {
result = Curl_client_write(data, CLIENTWRITE_BODY,
@@ -1202,11 +1203,11 @@ static timediff_t tftp_state_timeout(struct Curl_easy *data,
state->state = TFTP_STATE_FIN;
return 0;
}
- time(&current);
+ current = time(NULL);
if(current > state->rx_time + state->retry_time) {
if(event)
*event = TFTP_EVENT_TIMEOUT;
- time(&state->rx_time); /* update even though we received nothing */
+ state->rx_time = time(NULL); /* update even though we received nothing */
}
return timeout_ms;
@@ -1239,8 +1240,8 @@ static CURLcode tftp_multi_statemach(struct Curl_easy *data, bool *done)
return result;
*done = (state->state == TFTP_STATE_FIN) ? TRUE : FALSE;
if(*done)
- /* Tell curl we're done */
- Curl_setup_transfer(data, -1, -1, FALSE, -1);
+ /* Tell curl we are done */
+ Curl_xfer_setup_nop(data);
}
else {
/* no timeouts to handle, check our socket */
@@ -1262,8 +1263,8 @@ static CURLcode tftp_multi_statemach(struct Curl_easy *data, bool *done)
return result;
*done = (state->state == TFTP_STATE_FIN) ? TRUE : FALSE;
if(*done)
- /* Tell curl we're done */
- Curl_setup_transfer(data, -1, -1, FALSE, -1);
+ /* Tell curl we are done */
+ Curl_xfer_setup_nop(data);
}
/* if rc == 0, then select() timed out */
}
@@ -1287,7 +1288,7 @@ static CURLcode tftp_doing(struct Curl_easy *data, bool *dophase_done)
DEBUGF(infof(data, "DO phase is complete"));
}
else if(!result) {
- /* The multi code doesn't have this logic for the DOING state so we
+ /* The multi code does not have this logic for the DOING state so we
provide it for TFTP since it may do the entire transfer in this
state. */
if(Curl_pgrsUpdate(data))
@@ -1374,7 +1375,7 @@ static CURLcode tftp_setup_connection(struct Curl_easy *data,
conn->transport = TRNSPRT_UDP;
/* TFTP URLs support an extension like ";mode=<typecode>" that
- * we'll try to get now! */
+ * we will try to get now! */
type = strstr(data->state.up.path, ";mode=");
if(!type)