diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am index 19c81c2e..3d9d5a50 100644 --- a/src/protocols/rdp/Makefile.am +++ b/src/protocols/rdp/Makefile.am @@ -66,6 +66,7 @@ libguac_client_rdp_la_SOURCES = \ keyboard/decompose.c \ keyboard/keyboard.c \ keyboard/keymap.c \ + log.c \ ls.c \ plugins/channels.c \ plugins/ptr-string.c \ @@ -107,6 +108,7 @@ noinst_HEADERS = \ keyboard/decompose.h \ keyboard/keyboard.h \ keyboard/keymap.h \ + log.h \ ls.h \ plugins/channels.h \ plugins/guacai/guacai-messages.h \ diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 123e1339..c8150acb 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -23,6 +23,7 @@ #include "client.h" #include "common/recording.h" #include "fs.h" +#include "log.h" #include "rdp.h" #include "user.h" @@ -40,6 +41,7 @@ #include #include #include +#include #include #include @@ -60,6 +62,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /* Init display update module */ rdp_client->disp = guac_rdp_disp_alloc(); + /* Redirect FreeRDP log messages to guac_client_log() */ + guac_rdp_redirect_wlog(client); + /* Recursive attribute for locks */ pthread_mutexattr_init(&(rdp_client->attributes)); pthread_mutexattr_settype(&(rdp_client->attributes), diff --git a/src/protocols/rdp/log.c b/src/protocols/rdp/log.c new file mode 100644 index 00000000..fa0a074f --- /dev/null +++ b/src/protocols/rdp/log.c @@ -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 +#include + +/** + * 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); + +} + diff --git a/src/protocols/rdp/log.h b/src/protocols/rdp/log.h new file mode 100644 index 00000000..3b40aeef --- /dev/null +++ b/src/protocols/rdp/log.h @@ -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 + +/** + * 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 +