mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 04:13:32 +02:00
Proxy plugin fixes and cleanups. Supports now multiple servers, doesn't
let clients see CTCP requests and if one client writes message, other clients will see it as well. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@810 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
2fc8c5b83f
commit
a8c139d5e2
6 changed files with 648 additions and 524 deletions
|
|
@ -18,119 +18,34 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#include "module.h"
|
||||
#include "settings.h"
|
||||
#include "levels.h"
|
||||
#include "fe-common/core/printtext.h"
|
||||
#include "servers.h"
|
||||
#include "net-sendbuffer.h"
|
||||
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
PLUGIN_DATA *proxy_data;
|
||||
MODULE_REC *plug;
|
||||
|
||||
|
||||
|
||||
gchar *plugin_description(void)
|
||||
void proxy_deinit(void)
|
||||
{
|
||||
return "IRC proxy plugin";
|
||||
plugin_proxy_listen_deinit();
|
||||
}
|
||||
|
||||
/*gint plugin_version(void)
|
||||
void proxy_init(void)
|
||||
{
|
||||
return PLUGIN_LAYER_VERSION;
|
||||
}
|
||||
*/
|
||||
settings_add_str("irssiproxy", "irssiproxy_ports", "");
|
||||
settings_add_str("irssiproxy", "irssiproxy_password", "");
|
||||
|
||||
void proxy_settings_init(void)
|
||||
{
|
||||
settings_add_str("proxy", "proxy_listen_addr", "localhost");
|
||||
settings_add_int("proxy", "proxy_listen_port", 2777);
|
||||
settings_add_str("proxy", "proxy_listen_password", "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* If we call plugin_deinit() in this code, it doesn't necessarily point to
|
||||
_THIS_ module's plugin_deinit() but instead some other module's.. So,
|
||||
we create static deinit() function which should be used.. */
|
||||
static void deinit(/*MODULE_REC *plugin*/)
|
||||
{
|
||||
plugin_proxy_listen_deinit(proxy_data);
|
||||
}
|
||||
|
||||
|
||||
void proxy_deinit(/*MODULE_REC *plugin*/)
|
||||
{
|
||||
deinit(/*plugin*/);
|
||||
}
|
||||
|
||||
gboolean proxy_init(void)
|
||||
{
|
||||
|
||||
gchar ipaddr[MAX_IP_LEN];
|
||||
|
||||
const char *password;
|
||||
const char *addr;
|
||||
int port;
|
||||
|
||||
proxy_settings_init();
|
||||
|
||||
proxy_data = g_new0(PLUGIN_DATA, 1);
|
||||
password = settings_get_str("proxy_listen_password");
|
||||
addr = settings_get_str("proxy_listen_addr");
|
||||
port = settings_get_int("proxy_listen_port");
|
||||
|
||||
plug = module_find("proxy");
|
||||
proxy_data->plugin = plug;
|
||||
|
||||
if (*password != '\0')
|
||||
{
|
||||
/* args = password */
|
||||
proxy_data->password = g_strdup(password);
|
||||
}
|
||||
if (*addr != '\0')
|
||||
{
|
||||
/* specify ip address to listen */
|
||||
net_host2ip(addr, &proxy_data->ip);
|
||||
}
|
||||
if (port != 0)
|
||||
{
|
||||
/* specify port to use */
|
||||
proxy_data->port = port;
|
||||
}
|
||||
|
||||
if (proxy_data->password == NULL)
|
||||
{
|
||||
/* no password - bad idea! */
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Warning!! Password not specified, everyone can use this proxy! Use /set proxy_listen_password <password> to set it");
|
||||
}
|
||||
|
||||
if (servers == NULL)
|
||||
{
|
||||
/* FIXME: not good */
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "You need to specify IP address to listen with /set proxy_listen_addr <address>");
|
||||
deinit();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
SERVER_REC *server;
|
||||
|
||||
server = servers->data;
|
||||
if (net_getsockname(net_sendbuffer_handle(server->handle), &proxy_data->ip, NULL))
|
||||
{
|
||||
deinit();
|
||||
return FALSE;
|
||||
if (*settings_get_str("irssiproxy_password") == '\0') {
|
||||
/* no password - bad idea! */
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
"Warning!! Password not specified, everyone can "
|
||||
"use this proxy! Use /set irssiproxy_password "
|
||||
"<password> to set it");
|
||||
}
|
||||
if (*settings_get_str("irssiproxy_ports") == '\0') {
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
"No proxy ports specified. Use /SET "
|
||||
"irssiproxy_ports <ircnet>=<port> <ircnet2>=<port2> "
|
||||
"... to set them.");
|
||||
}
|
||||
}
|
||||
|
||||
net_ip2host(&proxy_data->ip, ipaddr);
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Proxy plugin loaded - listening in interface %s port %d", ipaddr, proxy_data->port);
|
||||
|
||||
plugin_proxy_listen_init(proxy_data);
|
||||
|
||||
proxy_data->loaded = TRUE;
|
||||
return TRUE;
|
||||
plugin_proxy_listen_init();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue