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

Do lprint() pointer instead of lprintf() pointer.

This doesn't make anything better or worse for the C API, but doing
variadic pointer things in C++ is fraught.
parent 96ec1645
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
......@@ -1320,11 +1320,9 @@ sftp_send(uint8_t *buf, size_t len, void *cb_data)
}
static void
sftp_lprintf(void *arg, uint32_t errcode, const char *fmt, ...)
sftp_lprint(void *arg, uint32_t errcode, const char *msg)
{
sbbs_t *sbbs = (sbbs_t *)arg;
va_list argptr;
char sbuf[1024];
int level = LOG_DEBUG;
switch (errcode) {
......@@ -1337,11 +1335,7 @@ sftp_lprintf(void *arg, uint32_t errcode, const char *fmt, ...)
break;
}
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
sbbs->lprintf(level, "SFTP error code %" PRIu32 " (%s) %s", errcode, sftp_get_errcode_name(errcode), sbuf);
sbbs->lprintf(level, "SFTP error code %" PRIu32 " (%s) %s", errcode, sftp_get_errcode_name(errcode), msg);
}
static void
......@@ -2153,7 +2147,7 @@ sbbs_t::init_sftp(int cid)
return true;
sftp_state = sftps_begin(sftp_send, this);
if (sftp_state != nullptr) {
sftp_state->lprintf = sftp_lprintf;
sftp_state->lprint = sftp_lprint;
sftp_state->cleanup_callback = sftp_cleanup_callback;
sftp_state->realpath = sftp_realpath;
sftp_state->open = sftp_open;
......
......@@ -193,7 +193,7 @@ typedef struct sftp_server_state {
sftp_rx_pkt_t rxp;
sftp_tx_pkt_t txp;
void *cb_data;
void (*lprintf)(void *cb_data, uint32_t errcode, const char *fmt, ...);
void (*lprint)(void *cb_data, uint32_t errcode, const char *msg);
void (*cleanup_callback)(void *cb_data);
bool (*open)(sftp_str_t filename, uint32_t flags, sftp_file_attr_t attributes, void *cb_data);
bool (*close)(sftp_str_t handle, void *cb_data);
......@@ -250,7 +250,7 @@ bool sftp_rx_pkt_reclaim(sftp_rx_pkt_t *pktp);
sftp_str_t sftp_alloc_str(uint32_t len);
sftp_str_t sftp_strdup(const char *str);
sftp_str_t sftp_asprintf(const char *format, ...);
sftp_str_t sftp_memdup(uint8_t *buf, uint32_t sz);
sftp_str_t sftp_memdup(const uint8_t *buf, uint32_t sz);
void free_sftp_str(sftp_str_t str);
/* sftp_client.c */
......
#include <assert.h>
#include <genwrap.h>
#include <stdarg.h>
#include <stdlib.h>
#include <threadwrap.h>
#include <str_list.h>
......@@ -326,11 +327,29 @@ sftps_send_packet(sftps_state_t state)
return true;
}
static void
lprintf(sftps_state_t state, uint32_t code, const char *fmt, ...)
{
char *msg;
va_list va;
int rc;
if (state->lprint == NULL)
return;
if (fmt == NULL)
return;
va_start(va, fmt);
rc = vasprintf(&msg, fmt, va);
va_end(va);
if (rc == -1)
return;
state->lprint(state->cb_data, code, msg);
}
bool
sftps_send_error(sftps_state_t state, uint32_t code, const char *msg)
{
if (state->lprintf)
state->lprintf(state->cb_data, code, "%s", msg);
lprintf(state, code, "%s", msg);
if (!appendheader(state, SSH_FXP_STATUS))
return false;
if (!append32(state, code))
......@@ -375,8 +394,7 @@ sftps_recv(sftps_state_t state, uint8_t *buf, uint32_t sz)
if (sftp_have_pkt_sz(state->rxp)) {
uint32_t psz = sftp_pkt_sz(state->rxp);
if (psz > SFTP_MAX_PACKET_SIZE) {
if (state->lprintf)
state->lprintf(state->cb_data, SSH_FX_FAILURE, "Packet too large (%" PRIu32 " bytes)", psz);
lprintf(state, SSH_FX_FAILURE, "Packet too large (%" PRIu32 " bytes)", psz);
return exit_function(state, false);
}
}
......@@ -528,8 +546,7 @@ sftps_recv(sftps_state_t state, uint8_t *buf, uint32_t sz)
break;
}
if (!handled) {
if (state->lprintf)
state->lprintf(state->cb_data, SSH_FX_FAILURE, "Unhandled request type: %s (%d)", sftp_get_type_name(state->rxp->type), state->rxp->type);
lprintf(state, SSH_FX_FAILURE, "Unhandled request type: %s (%d)", sftp_get_type_name(state->rxp->type), state->rxp->type);
state->id = get32(state);
if (!sftps_send_error(state, SSH_FX_OP_UNSUPPORTED, "Operation not implemented"))
return exit_function(state, false);
......@@ -568,22 +585,19 @@ sftps_send_name(sftps_state_t state, uint32_t count, str_list_t fnames, str_list
return false;
for (uint32_t idx = 0; idx < count; idx++) {
if (fnames[idx] == NULL) {
if (state->lprintf)
state->lprintf(state->cb_data, SSH_FX_FAILURE, "Reached fnames terminator at position %" PRIu32 " of " PRIu32, idx, count);
lprintf(state, SSH_FX_FAILURE, "Reached fnames terminator at position %" PRIu32 " of " PRIu32, idx, count);
return false;
}
if (!appendcstring(state, fnames[idx]))
return false;
if (lnames[idx] == NULL) {
if (state->lprintf)
state->lprintf(state->cb_data, SSH_FX_FAILURE, "Reached lnames terminator at position %" PRIu32 " of " PRIu32, idx, count);
lprintf(state, SSH_FX_FAILURE, "Reached lnames terminator at position %" PRIu32 " of " PRIu32, idx, count);
return false;
}
if (!appendcstring(state, lnames[idx]))
return false;
if (attrs[idx] == NULL) {
if (state->lprintf)
state->lprintf(state->cb_data, SSH_FX_FAILURE, "Reached attrs terminator at position %" PRIu32 " of " PRIu32, idx, count);
lprintf(state, SSH_FX_FAILURE, "Reached attrs terminator at position %" PRIu32 " of " PRIu32, idx, count);
return false;
}
if (!appendfattr(state, attrs[idx]))
......
......@@ -56,7 +56,7 @@ sftp_asprintf(const char *format, ...)
}
sftp_str_t
sftp_memdup(uint8_t *buf, uint32_t sz)
sftp_memdup(const uint8_t *buf, uint32_t sz)
{
sftp_str_t ret = sftp_alloc_str(sz);
if (ret == NULL)
......
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