GUACAMOLE-249: Redirect FreeRDP log messages to debug level of guac_client_log().

This commit is contained in:
Michael Jumper 2019-12-29 18:44:41 -08:00
parent 9ad3bc9a49
commit 0926864ecb
4 changed files with 113 additions and 0 deletions

View File

@ -66,6 +66,7 @@ libguac_client_rdp_la_SOURCES = \
keyboard/decompose.c \ keyboard/decompose.c \
keyboard/keyboard.c \ keyboard/keyboard.c \
keyboard/keymap.c \ keyboard/keymap.c \
log.c \
ls.c \ ls.c \
plugins/channels.c \ plugins/channels.c \
plugins/ptr-string.c \ plugins/ptr-string.c \
@ -107,6 +108,7 @@ noinst_HEADERS = \
keyboard/decompose.h \ keyboard/decompose.h \
keyboard/keyboard.h \ keyboard/keyboard.h \
keyboard/keymap.h \ keyboard/keymap.h \
log.h \
ls.h \ ls.h \
plugins/channels.h \ plugins/channels.h \
plugins/guacai/guacai-messages.h \ plugins/guacai/guacai-messages.h \

View File

@ -23,6 +23,7 @@
#include "client.h" #include "client.h"
#include "common/recording.h" #include "common/recording.h"
#include "fs.h" #include "fs.h"
#include "log.h"
#include "rdp.h" #include "rdp.h"
#include "user.h" #include "user.h"
@ -40,6 +41,7 @@
#include <guacamole/audio.h> #include <guacamole/audio.h>
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/socket.h> #include <guacamole/socket.h>
#include <winpr/wlog.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
@ -60,6 +62,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
/* Init display update module */ /* Init display update module */
rdp_client->disp = guac_rdp_disp_alloc(); rdp_client->disp = guac_rdp_disp_alloc();
/* Redirect FreeRDP log messages to guac_client_log() */
guac_rdp_redirect_wlog(client);
/* Recursive attribute for locks */ /* Recursive attribute for locks */
pthread_mutexattr_init(&(rdp_client->attributes)); pthread_mutexattr_init(&(rdp_client->attributes));
pthread_mutexattr_settype(&(rdp_client->attributes), pthread_mutexattr_settype(&(rdp_client->attributes),

71
src/protocols/rdp/log.c Normal file
View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <guacamole/client.h>
#include <winpr/wlog.h>
/**
* The guac_client that should be used within this process for FreeRDP log
* messages. As all Guacamole connections are isolated at the process level,
* this will only ever be set to the guac_client of the current process'
* connection.
*/
static guac_client* current_client = NULL;
/**
* Logs the text data within the given message to the logging facilities of the
* guac_client currently stored under current_client (the guac_client of the
* current process).
*
* @param message
* The message to log.
*
* @return
* TRUE if the message was successfully logged, FALSE otherwise.
*/
static BOOL guac_rdp_wlog_text_message(const wLogMessage* message) {
/* Fail if log not yet redirected */
if (current_client == NULL)
return FALSE;
/* Log all received messages at the debug level */
guac_client_log(current_client, GUAC_LOG_DEBUG, "%s", message->TextString);
return TRUE;
}
void guac_rdp_redirect_wlog(guac_client* client) {
wLogCallbacks callbacks = {
.message = guac_rdp_wlog_text_message
};
current_client = client;
/* Reconfigure root logger to use callback appender */
wLog* root = WLog_GetRoot();
WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);
/* Set appender callbacks to our own */
wLogAppender* appender = WLog_GetLogAppender(root);
WLog_ConfigureAppender(appender, "callbacks", &callbacks);
}

35
src/protocols/rdp/log.h Normal file
View File

@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef GUAC_RDP_LOG_H
#define GUAC_RDP_LOG_H
#include <guacamole/client.h>
/**
* Redirects the core FreeRDP logging facility, wLog, such that it logs all
* messages at the debug level using guac_client_log().
*
* @param client
* The guac_client that should receive all log messages.
*/
void guac_rdp_redirect_wlog(guac_client* client);
#endif