mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 12:23:37 +02:00
commit
2b13e793c4
7 changed files with 139 additions and 12 deletions
|
|
@ -37,6 +37,8 @@ GSList *proxy_clients;
|
|||
static GString *next_line;
|
||||
static int ignore_next;
|
||||
|
||||
static int enabled = FALSE;
|
||||
|
||||
static void remove_client(CLIENT_REC *rec)
|
||||
{
|
||||
g_return_if_fail(rec != NULL);
|
||||
|
|
@ -45,8 +47,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);
|
||||
|
|
@ -126,6 +128,10 @@ static void handle_client_connect_cmd(CLIENT_REC *client,
|
|||
/* client didn't send us PASS, kill it */
|
||||
remove_client(client);
|
||||
} else {
|
||||
signal_emit("proxy client connected", 1, client);
|
||||
printtext(client->server, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
"Proxy: Client %s:%d connected",
|
||||
client->host, client->port);
|
||||
client->connected = TRUE;
|
||||
proxy_dump_data(client);
|
||||
}
|
||||
|
|
@ -347,6 +353,7 @@ static void sig_listen(LISTEN_REC *listen)
|
|||
rec->listen = listen;
|
||||
rec->handle = sendbuf;
|
||||
rec->host = g_strdup(host);
|
||||
rec->port = port;
|
||||
if (g_strcmp0(listen->ircnet, "*") == 0) {
|
||||
rec->proxy_address = g_strdup("irc.proxy");
|
||||
rec->server = servers == NULL ? NULL : IRC_SERVER(servers->data);
|
||||
|
|
@ -361,9 +368,10 @@ static void sig_listen(LISTEN_REC *listen)
|
|||
proxy_clients = g_slist_prepend(proxy_clients, rec);
|
||||
rec->listen->clients = g_slist_prepend(rec->listen->clients, rec);
|
||||
|
||||
signal_emit("proxy client connected", 1, rec);
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
"Proxy: Client connected from %s", rec->host);
|
||||
signal_emit("proxy client connecting", 1, rec);
|
||||
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)
|
||||
|
|
@ -634,7 +642,8 @@ static void remove_listen(LISTEN_REC *rec)
|
|||
static void read_settings(void)
|
||||
{
|
||||
LISTEN_REC *rec;
|
||||
GSList *remove_listens;
|
||||
GSList *remove_listens = NULL;
|
||||
GSList *add_listens = NULL;
|
||||
char **ports, **tmp, *ircnet, *port;
|
||||
int portnum;
|
||||
|
||||
|
|
@ -653,17 +662,30 @@ static void read_settings(void)
|
|||
continue;
|
||||
|
||||
rec = find_listen(ircnet, portnum);
|
||||
if (rec == NULL)
|
||||
add_listen(ircnet, portnum);
|
||||
else
|
||||
if (rec == NULL) {
|
||||
rec = g_new0(LISTEN_REC, 1);
|
||||
rec->ircnet = ircnet; /* borrow */
|
||||
rec->port = portnum;
|
||||
add_listens = g_slist_prepend(add_listens, rec);
|
||||
} else {
|
||||
/* remove from the list of listens to remove == keep it */
|
||||
remove_listens = g_slist_remove(remove_listens, rec);
|
||||
}
|
||||
}
|
||||
g_strfreev(ports);
|
||||
|
||||
while (remove_listens != NULL) {
|
||||
remove_listen(remove_listens->data);
|
||||
remove_listen(remove_listens->data);
|
||||
remove_listens = g_slist_remove(remove_listens, remove_listens->data);
|
||||
}
|
||||
|
||||
while (add_listens != NULL) {
|
||||
rec = add_listens->data;
|
||||
add_listen(rec->ircnet, rec->port);
|
||||
g_free(rec);
|
||||
add_listens = g_slist_remove(add_listens, add_listens->data);
|
||||
}
|
||||
|
||||
g_strfreev(ports);
|
||||
}
|
||||
|
||||
static void sig_dump(CLIENT_REC *client, const char *data)
|
||||
|
|
@ -676,6 +698,11 @@ static void sig_dump(CLIENT_REC *client, const char *data)
|
|||
|
||||
void proxy_listen_init(void)
|
||||
{
|
||||
if (enabled) {
|
||||
return;
|
||||
}
|
||||
enabled = TRUE;
|
||||
|
||||
next_line = g_string_new(NULL);
|
||||
|
||||
proxy_clients = NULL;
|
||||
|
|
@ -697,6 +724,11 @@ void proxy_listen_init(void)
|
|||
|
||||
void proxy_listen_deinit(void)
|
||||
{
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
enabled = FALSE;
|
||||
|
||||
while (proxy_listens != NULL)
|
||||
remove_listen(proxy_listens->data);
|
||||
g_string_free(next_line, TRUE);
|
||||
|
|
|
|||
|
|
@ -23,11 +23,60 @@
|
|||
#include "settings.h"
|
||||
#include "levels.h"
|
||||
|
||||
#include "fe-common/core/printtext.h"
|
||||
|
||||
/* SYNTAX: IRSSIPROXY STATUS */
|
||||
static void cmd_irssiproxy_status(const char *data, IRC_SERVER_REC *server)
|
||||
{
|
||||
if (!settings_get_bool("irssiproxy")) {
|
||||
printtext(server, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
"Proxy is currently disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: IRSSIPROXY */
|
||||
static void cmd_irssiproxy(const char *data, IRC_SERVER_REC *server, void *item)
|
||||
{
|
||||
if (*data == '\0') {
|
||||
cmd_irssiproxy_status(data, server);
|
||||
return;
|
||||
}
|
||||
|
||||
command_runsub("irssiproxy", data, server, item);
|
||||
}
|
||||
|
||||
static void irc_proxy_setup_changed(void)
|
||||
{
|
||||
if (settings_get_bool("irssiproxy")) {
|
||||
proxy_listen_init();
|
||||
} else {
|
||||
proxy_listen_deinit();
|
||||
}
|
||||
}
|
||||
|
||||
void irc_proxy_init(void)
|
||||
{
|
||||
settings_add_str("irssiproxy", "irssiproxy_ports", "");
|
||||
settings_add_str("irssiproxy", "irssiproxy_password", "");
|
||||
settings_add_str("irssiproxy", "irssiproxy_bind", "");
|
||||
settings_add_bool("irssiproxy", "irssiproxy", TRUE);
|
||||
|
||||
if (*settings_get_str("irssiproxy_password") == '\0') {
|
||||
/* no password - bad idea! */
|
||||
|
|
@ -43,7 +92,14 @@ void irc_proxy_init(void)
|
|||
"... to set them.");
|
||||
}
|
||||
|
||||
proxy_listen_init();
|
||||
command_bind("irssiproxy", NULL, (SIGNAL_FUNC) cmd_irssiproxy);
|
||||
command_bind("irssiproxy status", NULL, (SIGNAL_FUNC) cmd_irssiproxy_status);
|
||||
|
||||
signal_add_first("setup changed", (SIGNAL_FUNC) irc_proxy_setup_changed);
|
||||
|
||||
if (settings_get_bool("irssiproxy")) {
|
||||
proxy_listen_init();
|
||||
}
|
||||
settings_check();
|
||||
module_register("proxy", "irc");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char *nick, *host;
|
||||
int port;
|
||||
NET_SENDBUF_REC *handle;
|
||||
int recv_tag;
|
||||
char *proxy_address;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue