ftp: Use 'CURLcode result' for curl result codes
This commit is contained in:
94
lib/tftp.c
94
lib/tftp.c
@@ -5,7 +5,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@@ -454,7 +454,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
char *filename;
|
char *filename;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
struct SessionHandle *data = state->conn->data;
|
struct SessionHandle *data = state->conn->data;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
|
|
||||||
/* Set ascii mode if -B flag was used */
|
/* Set ascii mode if -B flag was used */
|
||||||
if(data->set.prefer_ascii)
|
if(data->set.prefer_ascii)
|
||||||
@@ -469,7 +469,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
if(state->retries>state->retry_max) {
|
if(state->retries>state->retry_max) {
|
||||||
state->error = TFTP_ERR_NORESPONSE;
|
state->error = TFTP_ERR_NORESPONSE;
|
||||||
state->state = TFTP_STATE_FIN;
|
state->state = TFTP_STATE_FIN;
|
||||||
return res;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->set.upload) {
|
if(data->set.upload) {
|
||||||
@@ -539,19 +539,19 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
|
|
||||||
case TFTP_EVENT_OACK:
|
case TFTP_EVENT_OACK:
|
||||||
if(data->set.upload) {
|
if(data->set.upload) {
|
||||||
res = tftp_connect_for_tx(state, event);
|
result = tftp_connect_for_tx(state, event);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res = tftp_connect_for_rx(state, event);
|
result = tftp_connect_for_rx(state, event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TFTP_EVENT_ACK: /* Connected for transmit */
|
case TFTP_EVENT_ACK: /* Connected for transmit */
|
||||||
res = tftp_connect_for_tx(state, event);
|
result = tftp_connect_for_tx(state, event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TFTP_EVENT_DATA: /* Connected for receive */
|
case TFTP_EVENT_DATA: /* Connected for receive */
|
||||||
res = tftp_connect_for_rx(state, event);
|
result = tftp_connect_for_rx(state, event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TFTP_EVENT_ERROR:
|
case TFTP_EVENT_ERROR:
|
||||||
@@ -562,7 +562,8 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
failf(state->conn->data, "tftp_send_first: internal error");
|
failf(state->conn->data, "tftp_send_first: internal error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the next blocknum is x + 1 but it needs to wrap at an unsigned 16bit
|
/* the next blocknum is x + 1 but it needs to wrap at an unsigned 16bit
|
||||||
@@ -702,7 +703,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
struct SessionHandle *data = state->conn->data;
|
struct SessionHandle *data = state->conn->data;
|
||||||
ssize_t sbytes;
|
ssize_t sbytes;
|
||||||
int rblock;
|
int rblock;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SingleRequest *k = &data->req;
|
struct SingleRequest *k = &data->req;
|
||||||
|
|
||||||
switch(event) {
|
switch(event) {
|
||||||
@@ -728,7 +729,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
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;
|
result = CURLE_SEND_ERROR;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Re-send the data packet */
|
/* Re-send the data packet */
|
||||||
@@ -739,10 +740,11 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
/* Check all sbytes were sent */
|
/* Check all sbytes were sent */
|
||||||
if(sbytes<0) {
|
if(sbytes<0) {
|
||||||
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
|
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
|
||||||
res = CURLE_SEND_ERROR;
|
result = CURLE_SEND_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
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 */
|
block */
|
||||||
@@ -759,11 +761,13 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
state->state = TFTP_STATE_FIN;
|
state->state = TFTP_STATE_FIN;
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
res = Curl_fillreadbuffer(state->conn, state->blksize, &state->sbytes);
|
|
||||||
if(res)
|
result = Curl_fillreadbuffer(state->conn, state->blksize, &state->sbytes);
|
||||||
return res;
|
if(result)
|
||||||
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
|
return result;
|
||||||
4+state->sbytes, SEND_4TH_ARG,
|
|
||||||
|
sbytes = sendto(state->sockfd, (void *) state->spacket.data,
|
||||||
|
4 + state->sbytes, SEND_4TH_ARG,
|
||||||
(struct sockaddr *)&state->remote_addr,
|
(struct sockaddr *)&state->remote_addr,
|
||||||
state->remote_addrlen);
|
state->remote_addrlen);
|
||||||
/* Check all sbytes were sent */
|
/* Check all sbytes were sent */
|
||||||
@@ -819,7 +823,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
@@ -831,48 +835,47 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
|
|||||||
**********************************************************/
|
**********************************************************/
|
||||||
static CURLcode tftp_translate_code(tftp_error_t error)
|
static CURLcode tftp_translate_code(tftp_error_t error)
|
||||||
{
|
{
|
||||||
CURLcode code = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
|
|
||||||
if(error != TFTP_ERR_NONE) {
|
if(error != TFTP_ERR_NONE) {
|
||||||
switch(error) {
|
switch(error) {
|
||||||
case TFTP_ERR_NOTFOUND:
|
case TFTP_ERR_NOTFOUND:
|
||||||
code = CURLE_TFTP_NOTFOUND;
|
result = CURLE_TFTP_NOTFOUND;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_PERM:
|
case TFTP_ERR_PERM:
|
||||||
code = CURLE_TFTP_PERM;
|
result = CURLE_TFTP_PERM;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_DISKFULL:
|
case TFTP_ERR_DISKFULL:
|
||||||
code = CURLE_REMOTE_DISK_FULL;
|
result = CURLE_REMOTE_DISK_FULL;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_UNDEF:
|
case TFTP_ERR_UNDEF:
|
||||||
case TFTP_ERR_ILLEGAL:
|
case TFTP_ERR_ILLEGAL:
|
||||||
code = CURLE_TFTP_ILLEGAL;
|
result = CURLE_TFTP_ILLEGAL;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_UNKNOWNID:
|
case TFTP_ERR_UNKNOWNID:
|
||||||
code = CURLE_TFTP_UNKNOWNID;
|
result = CURLE_TFTP_UNKNOWNID;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_EXISTS:
|
case TFTP_ERR_EXISTS:
|
||||||
code = CURLE_REMOTE_FILE_EXISTS;
|
result = CURLE_REMOTE_FILE_EXISTS;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_NOSUCHUSER:
|
case TFTP_ERR_NOSUCHUSER:
|
||||||
code = CURLE_TFTP_NOSUCHUSER;
|
result = CURLE_TFTP_NOSUCHUSER;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_TIMEOUT:
|
case TFTP_ERR_TIMEOUT:
|
||||||
code = CURLE_OPERATION_TIMEDOUT;
|
result = CURLE_OPERATION_TIMEDOUT;
|
||||||
break;
|
break;
|
||||||
case TFTP_ERR_NORESPONSE:
|
case TFTP_ERR_NORESPONSE:
|
||||||
code = CURLE_COULDNT_CONNECT;
|
result = CURLE_COULDNT_CONNECT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
code= CURLE_ABORTED_BY_CALLBACK;
|
result = CURLE_ABORTED_BY_CALLBACK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
code = CURLE_OK;
|
result = CURLE_OK;
|
||||||
}
|
|
||||||
|
|
||||||
return(code);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
@@ -885,20 +888,21 @@ static CURLcode tftp_translate_code(tftp_error_t error)
|
|||||||
static CURLcode tftp_state_machine(tftp_state_data_t *state,
|
static CURLcode tftp_state_machine(tftp_state_data_t *state,
|
||||||
tftp_event_t event)
|
tftp_event_t event)
|
||||||
{
|
{
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = state->conn->data;
|
struct SessionHandle *data = state->conn->data;
|
||||||
|
|
||||||
switch(state->state) {
|
switch(state->state) {
|
||||||
case TFTP_STATE_START:
|
case TFTP_STATE_START:
|
||||||
DEBUGF(infof(data, "TFTP_STATE_START\n"));
|
DEBUGF(infof(data, "TFTP_STATE_START\n"));
|
||||||
res = tftp_send_first(state, event);
|
result = tftp_send_first(state, event);
|
||||||
break;
|
break;
|
||||||
case TFTP_STATE_RX:
|
case TFTP_STATE_RX:
|
||||||
DEBUGF(infof(data, "TFTP_STATE_RX\n"));
|
DEBUGF(infof(data, "TFTP_STATE_RX\n"));
|
||||||
res = tftp_rx(state, event);
|
result = tftp_rx(state, event);
|
||||||
break;
|
break;
|
||||||
case TFTP_STATE_TX:
|
case TFTP_STATE_TX:
|
||||||
DEBUGF(infof(data, "TFTP_STATE_TX\n"));
|
DEBUGF(infof(data, "TFTP_STATE_TX\n"));
|
||||||
res = tftp_tx(state, event);
|
result = tftp_tx(state, event);
|
||||||
break;
|
break;
|
||||||
case TFTP_STATE_FIN:
|
case TFTP_STATE_FIN:
|
||||||
infof(data, "%s\n", "TFTP finished");
|
infof(data, "%s\n", "TFTP finished");
|
||||||
@@ -906,10 +910,11 @@ static CURLcode tftp_state_machine(tftp_state_data_t *state,
|
|||||||
default:
|
default:
|
||||||
DEBUGF(infof(data, "STATE: %d\n", state->state));
|
DEBUGF(infof(data, "STATE: %d\n", state->state));
|
||||||
failf(data, "%s", "Internal state machine error");
|
failf(data, "%s", "Internal state machine error");
|
||||||
res = CURLE_TFTP_ILLEGAL;
|
result = CURLE_TFTP_ILLEGAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
@@ -943,7 +948,6 @@ static CURLcode tftp_disconnect(struct connectdata *conn, bool dead_connection)
|
|||||||
**********************************************************/
|
**********************************************************/
|
||||||
static CURLcode tftp_connect(struct connectdata *conn, bool *done)
|
static CURLcode tftp_connect(struct connectdata *conn, bool *done)
|
||||||
{
|
{
|
||||||
CURLcode code;
|
|
||||||
tftp_state_data_t *state;
|
tftp_state_data_t *state;
|
||||||
int blksize, rc;
|
int blksize, rc;
|
||||||
|
|
||||||
@@ -1017,8 +1021,8 @@ static CURLcode tftp_connect(struct connectdata *conn, bool *done)
|
|||||||
Curl_pgrsStartNow(conn->data);
|
Curl_pgrsStartNow(conn->data);
|
||||||
|
|
||||||
*done = TRUE;
|
*done = TRUE;
|
||||||
code = CURLE_OK;
|
|
||||||
return(code);
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
@@ -1031,7 +1035,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 result = 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;
|
||||||
|
|
||||||
(void)status; /* unused */
|
(void)status; /* unused */
|
||||||
@@ -1042,9 +1046,9 @@ static CURLcode tftp_done(struct connectdata *conn, CURLcode status,
|
|||||||
|
|
||||||
/* If we have encountered an error */
|
/* If we have encountered an error */
|
||||||
if(state)
|
if(state)
|
||||||
code = tftp_translate_code(state->error);
|
result = tftp_translate_code(state->error);
|
||||||
|
|
||||||
return code;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user