Skip to content
Snippets Groups Projects
Commit 69322766 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add sftpc_get_err() function and make the sftp client struct hidden

This eliminates the hack of using ssh_mutex to protect members of
sftp_state (which has its own mutex).

This doesn't fix the problem of sftp_state itself though.
parent efc6e234
No related branches found
No related tags found
No related merge requests found
Pipeline #6090 passed
......@@ -171,22 +171,7 @@ enum sftp_handle_type {
typedef sftp_str_t sftp_filehandle_t;
typedef sftp_str_t sftp_dirhandle_t;
typedef struct sftp_client_state {
bool (*send_cb)(uint8_t *buf, size_t len, void *cb_data);
xpevent_t recv_event;
sftp_rx_pkt_t rxp;
sftp_tx_pkt_t txp;
void *cb_data;
sftp_str_t err_msg;
sftp_str_t err_lang;
pthread_mutex_t mtx;
uint32_t version;
uint32_t running;
uint32_t id;
uint32_t err_id;
uint32_t err_code;
bool terminating;
} *sftpc_state_t;
typedef struct sftp_client_state *sftpc_state_t;
typedef struct sftp_server_state {
bool (*send_cb)(uint8_t *buf, size_t len, void *cb_data);
......@@ -264,6 +249,7 @@ bool sftpc_close(sftpc_state_t state, sftp_filehandle_t *handle);
bool sftpc_read(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, uint32_t len, sftp_str_t *ret);
bool sftpc_write(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, sftp_str_t data);
bool sftpc_reclaim(sftpc_state_t state);
uint32_t sftpc_get_err(sftpc_state_t state);
/* sftp_attr.c */
sftp_file_attr_t sftp_fattr_alloc(void);
......
......@@ -5,6 +5,23 @@
#include "sftp.h"
typedef struct sftp_client_state {
bool (*send_cb)(uint8_t *buf, size_t len, void *cb_data);
xpevent_t recv_event;
sftp_rx_pkt_t rxp;
sftp_tx_pkt_t txp;
void *cb_data;
sftp_str_t err_msg;
sftp_str_t err_lang;
pthread_mutex_t mtx;
uint32_t version;
uint32_t running;
uint32_t id;
uint32_t err_id;
uint32_t err_code;
bool terminating;
} *sftpc_state_t;
#define SFTP_STATIC_TYPE sftpc_state_t
#include "sftp_static.h"
#undef SFTP_STATIC_TYPE
......@@ -367,3 +384,14 @@ sftpc_reclaim(sftpc_state_t state)
ret = sftp_rx_pkt_reclaim(&state->rxp) && ret;
return ret;
}
uint32_t
sftpc_get_err(sftpc_state_t state)
{
uint32_t ret = SSH_FX_FAILURE;
if (!enter_function(state))
return ret;
ret = state->err_code;
exit_function(state, true);
return ret;
}
......@@ -466,12 +466,8 @@ key_not_present(sftp_filehandle_t f, const char *priv)
}
if (!sftpc_read(sftp_state, f, off, (bufsz - bufpos > 1024) ? 1024 : bufsz - bufpos, &r)) {
free(buf);
pthread_mutex_lock(&ssh_mutex);
if (sftp_state->err_code == SSH_FX_EOF) {
pthread_mutex_unlock(&ssh_mutex);
if (sftpc_get_err(sftp_state) == SSH_FX_EOF)
return true;
}
pthread_mutex_unlock(&ssh_mutex);
return false;
}
memcpy(&buf[bufpos], r->c_str, r->len);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment