Welcome to mirror list, hosted at ThFree Co, Russian Federation.

backend_socket_log.c « utils - github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 783cca3199b62c731a2baa72c3f78825ecd84788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <assert.h>
#include <string.h>

#include "putty.h"
#include "network.h"

void backend_socket_log(Seat *seat, LogContext *logctx,
                        PlugLogType type, SockAddr *addr, int port,
                        const char *error_msg, int error_code, Conf *conf,
                        bool session_started)
{
    char addrbuf[256], *msg;

    switch (type) {
      case PLUGLOG_CONNECT_TRYING:
        sk_getaddr(addr, addrbuf, lenof(addrbuf));
        if (sk_addr_needs_port(addr)) {
            msg = dupprintf("Connecting to %s port %d", addrbuf, port);
        } else {
            msg = dupprintf("Connecting to %s", addrbuf);
        }
        break;
      case PLUGLOG_CONNECT_FAILED:
        sk_getaddr(addr, addrbuf, lenof(addrbuf));
        msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
        break;
      case PLUGLOG_CONNECT_SUCCESS:
        if (addr)
            sk_getaddr(addr, addrbuf, lenof(addrbuf));
        else /* fallback if address unavailable */
            sprintf(addrbuf, "remote host");
        msg = dupprintf("Connected to %s", addrbuf);
        break;
      case PLUGLOG_PROXY_MSG: {
        /* Proxy-related log messages have their own identifying
         * prefix already, put on by our caller. */
        int len, log_to_term;

        /* Suffix \r\n temporarily, so we can log to the terminal. */
        msg = dupprintf("%s\r\n", error_msg);
        len = strlen(msg);
        assert(len >= 2);

        log_to_term = conf_get_int(conf, CONF_proxy_log_to_term);
        if (log_to_term == AUTO)
            log_to_term = session_started ? FORCE_OFF : FORCE_ON;
        if (log_to_term == FORCE_ON)
            seat_stderr(seat, msg, len);

        msg[len-2] = '\0';         /* remove the \r\n again */
        break;
      }
      default:
        msg = NULL;  /* shouldn't happen, but placate optimiser */
        break;
    }

    if (msg) {
        logevent(logctx, msg);
        sfree(msg);
    }
}