From aaa0f73eac88316978c65fb0f0c8b5d23d1dc100 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Tue, 24 Jun 2014 23:45:35 -0700 Subject: [PATCH] Make proxy messages include more detail and add status command --- src/irc/proxy/listen.c | 15 +++++++++------ src/irc/proxy/proxy.c | 34 ++++++++++++++++++++++++++++++++++ src/irc/proxy/proxy.h | 1 + 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 8f8ebe99..df0d7479 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -45,8 +45,8 @@ static void remove_client(CLIENT_REC *rec) rec->listen->clients = g_slist_remove(rec->listen->clients, rec); signal_emit("proxy client disconnected", 1, rec); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client disconnected from %s", rec->host); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s:%d disconnected", rec->host, rec->port); g_free(rec->proxy_address); net_sendbuffer_destroy(rec->handle, TRUE); @@ -127,8 +127,9 @@ static void handle_client_connect_cmd(CLIENT_REC *client, remove_client(client); } else { signal_emit("proxy client connected", 1, client); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client finished connecting from %s", client->host); + printtext(client->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s:%d connected", + client->host, client->port); client->connected = TRUE; proxy_dump_data(client); } @@ -350,6 +351,7 @@ static void sig_listen(LISTEN_REC *listen) rec->listen = listen; rec->handle = sendbuf; rec->host = g_strdup(host); + rec->port = port; if (strcmp(listen->ircnet, "*") == 0) { rec->proxy_address = g_strdup("irc.proxy"); rec->server = servers == NULL ? NULL : IRC_SERVER(servers->data); @@ -365,8 +367,9 @@ static void sig_listen(LISTEN_REC *listen) rec->listen->clients = g_slist_prepend(rec->listen->clients, rec); signal_emit("proxy client connecting", 1, rec); - printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - "Proxy: Client connecting from %s", rec->host); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: New client %s:%d on port %d (%s)", + rec->host, rec->port, listen->port, listen->ircnet); } static void sig_incoming(IRC_SERVER_REC *server, const char *line) diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index c8f47bdf..75da112c 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -23,6 +23,37 @@ #include "settings.h" #include "levels.h" +#include "fe-common/core/printtext.h" + +static void cmd_proxy_status(const char *data, IRC_SERVER_REC *server) +{ + GSList *tmp; + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Currently connected clients: %d", + g_slist_length(proxy_clients)); + + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + " %s:%d connect%s to %d (%s)", + rec->host, rec->port, + rec->connected ? "ed" : "ing", + rec->listen->port, rec->listen->ircnet); + } +} + +static void cmd_proxy(const char *data, IRC_SERVER_REC *server, void *item) +{ + if (*data == '\0') { + cmd_proxy_status(data, server); + return; + } + + command_runsub("proxy", data, server, item); +} + void irc_proxy_init(void) { settings_add_str("irssiproxy", "irssiproxy_ports", ""); @@ -43,6 +74,9 @@ void irc_proxy_init(void) "... to set them."); } + command_bind("proxy", NULL, (SIGNAL_FUNC) cmd_proxy); + command_bind("proxy status", NULL, (SIGNAL_FUNC) cmd_proxy_status); + proxy_listen_init(); settings_check(); module_register("proxy", "irc"); diff --git a/src/irc/proxy/proxy.h b/src/irc/proxy/proxy.h index 4ddc9da9..158b0675 100644 --- a/src/irc/proxy/proxy.h +++ b/src/irc/proxy/proxy.h @@ -19,6 +19,7 @@ typedef struct { typedef struct { char *nick, *host; + int port; NET_SENDBUF_REC *handle; int recv_tag; char *proxy_address;