diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2018-09-30 09:57:48 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2018-09-30 09:59:45 +0200 |
commit | e28cb001061745576918e7db46a4c8f3652abb70 (patch) | |
tree | e43aecabc71bbbff272b7edb7f083842ea25bf95 /src/plugins | |
parent | 0f782166e22d01a2f268fbf4430486dc66856fb3 (diff) | |
download | weechat-e28cb001061745576918e7db46a4c8f3652abb70.zip |
relay: add real IP in client description (closes #1256)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/relay/relay-client.c | 18 | ||||
-rw-r--r-- | src/plugins/relay/relay-client.h | 1 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c index 7878f595c..ab830a824 100644 --- a/src/plugins/relay/relay-client.c +++ b/src/plugins/relay/relay-client.c @@ -214,13 +214,16 @@ relay_client_set_desc (struct t_relay_client *client) free (client->desc); snprintf (desc, sizeof (desc), - "%d/%s%s%s%s/%s", + "%d/%s%s%s%s/%s%s%s%s", client->id, (client->ssl) ? "ssl." : "", relay_protocol_string[client->protocol], (client->protocol_args) ? "." : "", (client->protocol_args) ? client->protocol_args : "", - client->address); + client->address, + (client->real_ip) ? "(" : "", + (client->real_ip) ? client->real_ip : "", + (client->real_ip) ? ")" : ""); client->desc = strdup (desc); } @@ -422,6 +425,10 @@ relay_client_recv_text (struct t_relay_client *client, const char *data) client->http_headers, "x-real-ip"); if (ptr_real_ip) { + if (client->real_ip) + free (client->real_ip); + client->real_ip = strdup (ptr_real_ip); + relay_client_set_desc (client); weechat_printf_date_tags ( NULL, 0, "relay_client", _("%s: websocket client %s%s%s has real IP " @@ -1214,6 +1221,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server) new_client->websocket = 0; new_client->http_headers = NULL; new_client->address = strdup ((address) ? address : "?"); + new_client->real_ip = NULL; new_client->status = RELAY_STATUS_CONNECTED; new_client->protocol = server->protocol; new_client->protocol_string = (server->protocol_string) ? strdup (server->protocol_string) : NULL; @@ -1384,6 +1392,7 @@ relay_client_new_with_infolist (struct t_infolist *infolist) new_client->websocket = weechat_infolist_integer (infolist, "websocket"); new_client->http_headers = NULL; new_client->address = strdup (weechat_infolist_string (infolist, "address")); + new_client->real_ip = strdup (weechat_infolist_string (infolist, "real_ip")); new_client->status = weechat_infolist_integer (infolist, "status"); new_client->protocol = weechat_infolist_integer (infolist, "protocol"); str = weechat_infolist_string (infolist, "protocol_string"); @@ -1571,6 +1580,8 @@ relay_client_free (struct t_relay_client *client) free (client->desc); if (client->address) free (client->address); + if (client->real_ip) + free (client->real_ip); if (client->protocol_string) free (client->protocol_string); if (client->protocol_args) @@ -1697,6 +1708,8 @@ relay_client_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_string (ptr_item, "address", client->address)) return 0; + if (!weechat_infolist_new_var_string (ptr_item, "real_ip", client->real_ip)) + return 0; if (!weechat_infolist_new_var_integer (ptr_item, "status", client->status)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "status_string", relay_client_status_string[client->status])) @@ -1776,6 +1789,7 @@ relay_client_print_log () ptr_client->http_headers, weechat_hashtable_get_string (ptr_client->http_headers, "keys_values")); weechat_log_printf (" address . . . . . . . : '%s'", ptr_client->address); + weechat_log_printf (" real_ip . . . . . . . : '%s'", ptr_client->real_ip); weechat_log_printf (" status. . . . . . . . : %d (%s)", ptr_client->status, relay_client_status_string[ptr_client->status]); diff --git a/src/plugins/relay/relay-client.h b/src/plugins/relay/relay-client.h index e9c52ddf9..91d61c664 100644 --- a/src/plugins/relay/relay-client.h +++ b/src/plugins/relay/relay-client.h @@ -99,6 +99,7 @@ struct t_relay_client int websocket; /* 0=not a ws, 1=init ws, 2=ws ready */ struct t_hashtable *http_headers; /* HTTP headers for websocket */ char *address; /* string with IP address */ + char *real_ip; /* real IP (X-Real-IP HTTP header) */ enum t_relay_status status; /* status (connecting, active,..) */ enum t_relay_protocol protocol; /* protocol (irc,..) */ char *protocol_string; /* example: "ipv6.ssl.irc.freenode" */ |