mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-10 06:23:01 +03:00
Fixes the ssh_log issue on ssh_bind handles.
This commit is contained in:
64
src/log.c
64
src/log.c
@@ -37,6 +37,33 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @internal
|
||||
* @brief do the actual work of logging an event
|
||||
*/
|
||||
|
||||
static void do_ssh_log(struct ssh_common_struct *common, int verbosity,
|
||||
const char *buffer){
|
||||
char indent[256];
|
||||
int min;
|
||||
if (common->callbacks && common->callbacks->log_function) {
|
||||
common->callbacks->log_function((ssh_session)common, verbosity, buffer,
|
||||
common->callbacks->userdata);
|
||||
} else if (verbosity == SSH_LOG_FUNCTIONS) {
|
||||
if (common->log_indent > 255) {
|
||||
min = 255;
|
||||
} else {
|
||||
min = common->log_indent;
|
||||
}
|
||||
|
||||
memset(indent, ' ', min);
|
||||
indent[min] = '\0';
|
||||
|
||||
fprintf(stderr, "[func] %s%s\n", indent, buffer);
|
||||
} else {
|
||||
fprintf(stderr, "[%d] %s\n", verbosity, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Log a SSH event.
|
||||
*
|
||||
@@ -48,32 +75,31 @@
|
||||
*/
|
||||
void ssh_log(ssh_session session, int verbosity, const char *format, ...) {
|
||||
char buffer[1024];
|
||||
char indent[256];
|
||||
int min;
|
||||
va_list va;
|
||||
|
||||
if (verbosity <= session->log_verbosity) {
|
||||
if (verbosity <= session->common.log_verbosity) {
|
||||
va_start(va, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, va);
|
||||
va_end(va);
|
||||
do_ssh_log(&session->common, verbosity, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (session->callbacks && session->callbacks->log_function) {
|
||||
session->callbacks->log_function(session, verbosity, buffer,
|
||||
session->callbacks->userdata);
|
||||
} else if (verbosity == SSH_LOG_FUNCTIONS) {
|
||||
if (session->log_indent > 255) {
|
||||
min = 255;
|
||||
} else {
|
||||
min = session->log_indent;
|
||||
}
|
||||
/** @internal
|
||||
* @brief log a SSH event with a common pointer
|
||||
* @param common The SSH/bind session.
|
||||
* @param verbosity The verbosity of the event.
|
||||
* @param format The format string of the log entry.
|
||||
*/
|
||||
void ssh_log_common(struct ssh_common_struct *common, int verbosity, const char *format, ...){
|
||||
char buffer[1024];
|
||||
va_list va;
|
||||
|
||||
memset(indent, ' ', min);
|
||||
indent[min] = '\0';
|
||||
|
||||
fprintf(stderr, "[func] %s%s\n", indent, buffer);
|
||||
} else {
|
||||
fprintf(stderr, "[%d] %s\n", verbosity, buffer);
|
||||
}
|
||||
if (verbosity <= common->log_verbosity) {
|
||||
va_start(va, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, va);
|
||||
va_end(va);
|
||||
do_ssh_log(common, verbosity, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user