cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

log.c (2329B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include <guacamole/client.h>
     21#include <winpr/wlog.h>
     22#include <winpr/wtypes.h>
     23
     24#include <stddef.h>
     25
     26/**
     27 * The guac_client that should be used within this process for FreeRDP log
     28 * messages. As all Guacamole connections are isolated at the process level,
     29 * this will only ever be set to the guac_client of the current process'
     30 * connection.
     31 */
     32static guac_client* current_client = NULL;
     33
     34/**
     35 * Logs the text data within the given message to the logging facilities of the
     36 * guac_client currently stored under current_client (the guac_client of the
     37 * current process).
     38 *
     39 * @param message
     40 *     The message to log.
     41 *
     42 * @return
     43 *     TRUE if the message was successfully logged, FALSE otherwise.
     44 */
     45static BOOL guac_rdp_wlog_text_message(const wLogMessage* message) {
     46
     47    /* Fail if log not yet redirected */
     48    if (current_client == NULL)
     49        return FALSE;
     50
     51    /* Log all received messages at the debug level */
     52    guac_client_log(current_client, GUAC_LOG_DEBUG, "%s", message->TextString);
     53    return TRUE;
     54
     55}
     56
     57void guac_rdp_redirect_wlog(guac_client* client) {
     58
     59    wLogCallbacks callbacks = {
     60        .message = guac_rdp_wlog_text_message
     61    };
     62
     63    current_client = client;
     64
     65    /* Reconfigure root logger to use callback appender */
     66    wLog* root = WLog_GetRoot();
     67    WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);
     68
     69    /* Set appender callbacks to our own */
     70    wLogAppender* appender = WLog_GetLogAppender(root);
     71    WLog_ConfigureAppender(appender, "callbacks", &callbacks);
     72
     73}
     74