mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
Add support for more than one proxy, with proxy selection for each IRC server (task #6859)
This commit is contained in:
@@ -620,6 +620,7 @@ irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
server_tmp.autoconnect,
|
||||
server_tmp.autoreconnect,
|
||||
server_tmp.autoreconnect_delay,
|
||||
server_tmp.proxy,
|
||||
server_tmp.addresses,
|
||||
server_tmp.ipv6,
|
||||
server_tmp.ssl,
|
||||
@@ -2945,6 +2946,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
server_tmp.autoconnect,
|
||||
server_tmp.autoreconnect,
|
||||
server_tmp.autoreconnect_delay,
|
||||
server_tmp.proxy,
|
||||
server_tmp.addresses,
|
||||
server_tmp.ipv6,
|
||||
server_tmp.ssl,
|
||||
|
||||
@@ -36,12 +36,12 @@
|
||||
|
||||
|
||||
char *irc_config_server_option_string[IRC_CONFIG_NUM_SERVER_OPTIONS] =
|
||||
{ "autoconnect", "autoreconnect", "autoreconnect_delay", "addresses", "ipv6",
|
||||
"ssl", "password", "nicks", "username", "realname", "local_hostname",
|
||||
{ "autoconnect", "autoreconnect", "autoreconnect_delay", "proxy", "addresses",
|
||||
"ipv6", "ssl", "password", "nicks", "username", "realname", "local_hostname",
|
||||
"command", "command_delay", "autojoin", "autorejoin"
|
||||
};
|
||||
char *irc_config_server_option_default[IRC_CONFIG_NUM_SERVER_OPTIONS] =
|
||||
{ "off", "on", "30", "", "off", "off", "", "", "", "", "", "", "0", "",
|
||||
{ "off", "on", "30", "", "", "off", "off", "", "", "", "", "", "", "0", "",
|
||||
"off", ""
|
||||
};
|
||||
|
||||
@@ -710,6 +710,17 @@ irc_config_server_new_option (struct t_config_file *config_file,
|
||||
callback_change, callback_change_data,
|
||||
callback_delete, callback_delete_data);
|
||||
break;
|
||||
case IRC_CONFIG_SERVER_PROXY:
|
||||
new_option = weechat_config_new_option (
|
||||
config_file, section,
|
||||
option_name, "string",
|
||||
N_("proxy used for this server (optional)"),
|
||||
NULL, 0, 0,
|
||||
irc_config_server_option_default[index_option], value,
|
||||
NULL, NULL,
|
||||
callback_change, callback_change_data,
|
||||
callback_delete, callback_delete_data);
|
||||
break;
|
||||
case IRC_CONFIG_SERVER_ADDRESSES:
|
||||
new_option = weechat_config_new_option (
|
||||
config_file, section,
|
||||
|
||||
@@ -31,6 +31,7 @@ enum t_irc_config_server_option
|
||||
IRC_CONFIG_SERVER_AUTOCONNECT = 0,
|
||||
IRC_CONFIG_SERVER_AUTORECONNECT,
|
||||
IRC_CONFIG_SERVER_AUTORECONNECT_DELAY,
|
||||
IRC_CONFIG_SERVER_PROXY,
|
||||
IRC_CONFIG_SERVER_ADDRESSES,
|
||||
IRC_CONFIG_SERVER_IPV6,
|
||||
IRC_CONFIG_SERVER_SSL,
|
||||
|
||||
@@ -1573,6 +1573,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command,
|
||||
weechat_infolist_new_var_string (item, "local_nick", server->nick);
|
||||
weechat_infolist_new_var_string (item, "filename", pos_file);
|
||||
weechat_infolist_new_var_string (item, "size", pos_size);
|
||||
weechat_infolist_new_var_string (item, "proxy", server->proxy);
|
||||
weechat_infolist_new_var_string (item, "address", pos_addr);
|
||||
weechat_infolist_new_var_integer (item, "port", atoi (pos_port));
|
||||
weechat_hook_signal_send ("xfer_add",
|
||||
@@ -1905,6 +1906,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command,
|
||||
weechat_infolist_new_var_string (item, "type", "chat_recv");
|
||||
weechat_infolist_new_var_string (item, "remote_nick", nick);
|
||||
weechat_infolist_new_var_string (item, "local_nick", server->nick);
|
||||
weechat_infolist_new_var_string (item, "proxy", server->proxy);
|
||||
weechat_infolist_new_var_string (item, "address", pos_addr);
|
||||
weechat_infolist_new_var_integer (item, "port", atoi (pos_port));
|
||||
weechat_hook_signal_send ("xfer_add",
|
||||
|
||||
+121
-57
@@ -240,6 +240,11 @@ irc_server_set_with_option (struct t_irc_server *server,
|
||||
case IRC_CONFIG_SERVER_AUTORECONNECT_DELAY:
|
||||
server->autoreconnect_delay = weechat_config_integer (option);
|
||||
break;
|
||||
case IRC_CONFIG_SERVER_PROXY:
|
||||
if (server->proxy)
|
||||
free (server->proxy);
|
||||
server->proxy = strdup (weechat_config_string (option));
|
||||
break;
|
||||
case IRC_CONFIG_SERVER_ADDRESSES:
|
||||
irc_server_set_addresses (server, weechat_config_string (option));
|
||||
break;
|
||||
@@ -333,6 +338,7 @@ irc_server_init (struct t_irc_server *server)
|
||||
server->autoconnect = IRC_CONFIG_SERVER_DEFAULT_AUTOCONNECT;
|
||||
server->autoreconnect = IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT;
|
||||
server->autoreconnect_delay = IRC_CONFIG_SERVER_DEFAULT_AUTORECONNECT_DELAY;
|
||||
server->proxy = NULL;
|
||||
server->addresses = NULL;
|
||||
server->ipv6 = IRC_CONFIG_SERVER_DEFAULT_IPV6;
|
||||
server->ssl = IRC_CONFIG_SERVER_DEFAULT_SSL;
|
||||
@@ -722,6 +728,8 @@ irc_server_free_data (struct t_irc_server *server)
|
||||
/* free data */
|
||||
if (server->name)
|
||||
free (server->name);
|
||||
if (server->proxy)
|
||||
free (server->proxy);
|
||||
if (server->addresses)
|
||||
free (server->addresses);
|
||||
if (server->addresses_array)
|
||||
@@ -817,8 +825,9 @@ irc_server_free_all ()
|
||||
|
||||
struct t_irc_server *
|
||||
irc_server_new (const char *name, int autoconnect, int autoreconnect,
|
||||
int autoreconnect_delay, const char *addresses, int ipv6,
|
||||
int ssl, const char *password, const char *nicks,
|
||||
int autoreconnect_delay, const char *proxy,
|
||||
const char *addresses, int ipv6, int ssl,
|
||||
const char *password, const char *nicks,
|
||||
const char *username, const char *realname,
|
||||
const char *local_hostname, const char *command,
|
||||
int command_delay, const char *autojoin, int autorejoin)
|
||||
@@ -830,11 +839,11 @@ irc_server_new (const char *name, int autoconnect, int autoreconnect,
|
||||
|
||||
if (weechat_irc_plugin->debug)
|
||||
{
|
||||
weechat_log_printf ("Creating new server (name:%s, addresses:%s, "
|
||||
"pwd:%s, nicks:%s, username:%s, realname:%s, "
|
||||
"local_hostname: %s, command:%s, autojoin:%s, "
|
||||
"autorejoin:%s)",
|
||||
name, addresses, (password) ? password : "",
|
||||
weechat_log_printf ("Creating new server (name:%s, proxy:%s, "
|
||||
"addresses:%s, pwd:%s, nicks:%s, username:%s, "
|
||||
"realname:%s, local_hostname: %s, command:%s, "
|
||||
"autojoin:%s, autorejoin:%s)",
|
||||
name, proxy, addresses, (password) ? password : "",
|
||||
(nicks) ? nicks : "", (username) ? username : "",
|
||||
(realname) ? realname : "",
|
||||
(local_hostname) ? local_hostname : "",
|
||||
@@ -849,6 +858,7 @@ irc_server_new (const char *name, int autoconnect, int autoreconnect,
|
||||
new_server->autoconnect = autoconnect;
|
||||
new_server->autoreconnect = autoreconnect;
|
||||
new_server->autoreconnect_delay = autoreconnect_delay;
|
||||
new_server->proxy = (proxy) ? strdup (proxy) : NULL;
|
||||
irc_server_set_addresses (new_server, addresses);
|
||||
new_server->ipv6 = ipv6;
|
||||
new_server->ssl = ssl;
|
||||
@@ -898,6 +908,7 @@ irc_server_duplicate (struct t_irc_server *server, const char *new_server_name)
|
||||
server->autoconnect,
|
||||
server->autoreconnect,
|
||||
server->autoreconnect_delay,
|
||||
server->proxy,
|
||||
server->addresses,
|
||||
server->ipv6,
|
||||
server->ssl,
|
||||
@@ -1993,15 +2004,11 @@ int
|
||||
irc_server_connect_cb (void *arg_server, int status, const char *ip_address)
|
||||
{
|
||||
struct t_irc_server *server;
|
||||
int config_proxy_use;
|
||||
|
||||
server = (struct t_irc_server *)arg_server;
|
||||
|
||||
server->hook_connect = NULL;
|
||||
|
||||
config_proxy_use = weechat_config_boolean (
|
||||
weechat_config_get ("weechat.proxy.use"));
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case WEECHAT_HOOK_CONNECT_OK:
|
||||
@@ -2020,7 +2027,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address)
|
||||
break;
|
||||
case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND:
|
||||
weechat_printf (server->buffer,
|
||||
(config_proxy_use) ?
|
||||
(server->proxy && server->proxy[0]) ?
|
||||
_("%s%s: proxy address \"%s\" not found") :
|
||||
_("%s%s: address \"%s\" not found"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
@@ -2031,7 +2038,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address)
|
||||
break;
|
||||
case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND:
|
||||
weechat_printf (server->buffer,
|
||||
(config_proxy_use) ?
|
||||
(server->proxy && server->proxy[0]) ?
|
||||
_("%s%s: proxy IP address not found") :
|
||||
_("%s%s: IP address not found"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
@@ -2041,7 +2048,7 @@ irc_server_connect_cb (void *arg_server, int status, const char *ip_address)
|
||||
break;
|
||||
case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED:
|
||||
weechat_printf (server->buffer,
|
||||
(config_proxy_use) ?
|
||||
(server->proxy && server->proxy[0]) ?
|
||||
_("%s%s: proxy connection refused") :
|
||||
_("%s%s: connection refused"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
@@ -2158,40 +2165,17 @@ irc_server_create_buffer (struct t_irc_server *server, int all_servers)
|
||||
int
|
||||
irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
{
|
||||
int set;
|
||||
const char *config_proxy_type, *config_proxy_address;
|
||||
int config_proxy_use, config_proxy_ipv6, config_proxy_port;
|
||||
|
||||
if (!server->addresses || !server->addresses[0])
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: addresses not defined for server \"%s\", "
|
||||
"cannot connect"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->name);
|
||||
return 0;
|
||||
}
|
||||
int set, length;
|
||||
char *option_name;
|
||||
struct t_config_option *proxy_type, *proxy_ipv6, *proxy_address, *proxy_port;
|
||||
const char *str_proxy_type, *str_proxy_address;
|
||||
|
||||
if (!server->nicks || !server->nicks[0])
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: nicks not defined for server \"%s\", "
|
||||
"cannot connect"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
config_proxy_use = weechat_config_boolean (
|
||||
weechat_config_get ("weechat.proxy.use"));
|
||||
config_proxy_ipv6 = weechat_config_boolean (
|
||||
weechat_config_get ("weechat.proxy.ipv6"));
|
||||
config_proxy_type = weechat_config_string (
|
||||
weechat_config_get ("weechat.proxy.type"));
|
||||
config_proxy_address = weechat_config_string (
|
||||
weechat_config_get ("weechat.proxy.address"));
|
||||
config_proxy_port = weechat_config_integer (
|
||||
weechat_config_get ("weechat.proxy.port"));
|
||||
proxy_type = NULL;
|
||||
proxy_ipv6 = NULL;
|
||||
proxy_address = NULL;
|
||||
proxy_port = NULL;
|
||||
str_proxy_type = NULL;
|
||||
str_proxy_address = NULL;
|
||||
|
||||
if (!server->buffer)
|
||||
{
|
||||
@@ -2222,6 +2206,74 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
"/command irc /server switch");
|
||||
}
|
||||
|
||||
if (server->proxy && server->proxy[0])
|
||||
{
|
||||
length = 32 + strlen (server->proxy) + 1;
|
||||
option_name = malloc (length);
|
||||
if (!option_name)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: not enough memory"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME);
|
||||
return 0;
|
||||
}
|
||||
snprintf (option_name, length, "weechat.proxy.%s.type",
|
||||
server->proxy);
|
||||
proxy_type = weechat_config_get (option_name);
|
||||
snprintf (option_name, length, "weechat.proxy.%s.ipv6",
|
||||
server->proxy);
|
||||
proxy_ipv6 = weechat_config_get (option_name);
|
||||
snprintf (option_name, length, "weechat.proxy.%s.address",
|
||||
server->proxy);
|
||||
proxy_address = weechat_config_get (option_name);
|
||||
snprintf (option_name, length, "weechat.proxy.%s.port",
|
||||
server->proxy);
|
||||
proxy_port = weechat_config_get (option_name);
|
||||
free (option_name);
|
||||
if (!proxy_type || !proxy_address)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: proxy \"%s\" not found for server "
|
||||
"\"%s\", cannot connect"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->proxy, server->name);
|
||||
return 0;
|
||||
}
|
||||
str_proxy_type = weechat_config_string (proxy_type);
|
||||
str_proxy_address = weechat_config_string (proxy_address);
|
||||
if (!str_proxy_type[0] || !proxy_ipv6 || !str_proxy_address[0]
|
||||
|| !proxy_port)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: missing proxy settings, check options "
|
||||
"for proxy \"%s\""),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->proxy);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!server->addresses || !server->addresses[0])
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: addresses not defined for server \"%s\", "
|
||||
"cannot connect"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!server->nicks || !server->nicks[0])
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: nicks not defined for server \"%s\", "
|
||||
"cannot connect"),
|
||||
irc_buffer_get_server_prefix (server, "error"),
|
||||
IRC_PLUGIN_NAME, server->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_GNUTLS
|
||||
if (server->ssl)
|
||||
{
|
||||
@@ -2233,7 +2285,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (config_proxy_use)
|
||||
if (proxy_type)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: connecting to server %s/%d%s%s via %s "
|
||||
@@ -2244,18 +2296,20 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
server->ports_array[server->current_address],
|
||||
(server->ipv6) ? " (IPv6)" : "",
|
||||
(server->ssl) ? " (SSL)" : "",
|
||||
config_proxy_type,
|
||||
config_proxy_address, config_proxy_port,
|
||||
(config_proxy_ipv6) ? " (IPv6)" : "");
|
||||
str_proxy_type,
|
||||
str_proxy_address,
|
||||
weechat_config_integer (proxy_port),
|
||||
(weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : "");
|
||||
weechat_log_printf (_("Connecting to server %s/%d%s%s via %s proxy "
|
||||
"%s/%d%s..."),
|
||||
server->addresses_array[server->current_address],
|
||||
server->ports_array[server->current_address],
|
||||
(server->ipv6) ? " (IPv6)" : "",
|
||||
(server->ssl) ? " (SSL)" : "",
|
||||
config_proxy_type,
|
||||
config_proxy_address, config_proxy_port,
|
||||
(config_proxy_ipv6) ? " (IPv6)" : "");
|
||||
str_proxy_type,
|
||||
str_proxy_address,
|
||||
weechat_config_integer (proxy_port),
|
||||
(weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : "");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2280,10 +2334,16 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
irc_server_close_connection (server);
|
||||
|
||||
/* create socket and set options */
|
||||
if (config_proxy_use)
|
||||
server->sock = socket ((config_proxy_ipv6) ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
|
||||
if (proxy_type)
|
||||
{
|
||||
server->sock = socket ((weechat_config_integer (proxy_ipv6)) ?
|
||||
AF_INET6 : AF_INET,
|
||||
SOCK_STREAM, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
server->sock = socket ((server->ipv6) ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
|
||||
}
|
||||
if (server->sock == -1)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
@@ -2326,7 +2386,8 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin)
|
||||
|
||||
server->disable_autojoin = disable_autojoin;
|
||||
|
||||
server->hook_connect = weechat_hook_connect (server->addresses_array[server->current_address],
|
||||
server->hook_connect = weechat_hook_connect (server->proxy,
|
||||
server->addresses_array[server->current_address],
|
||||
server->ports_array[server->current_address],
|
||||
server->sock,
|
||||
server->ipv6,
|
||||
@@ -2901,6 +2962,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", server->autoreconnect_delay))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "proxy", server->proxy))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "addresses", server->addresses))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", server->ipv6))
|
||||
@@ -2988,6 +3051,7 @@ irc_server_print_log ()
|
||||
weechat_log_printf (" autoconnect . . . . : %d", ptr_server->autoconnect);
|
||||
weechat_log_printf (" autoreconnect . . . : %d", ptr_server->autoreconnect);
|
||||
weechat_log_printf (" autoreconnect_delay : %d", ptr_server->autoreconnect_delay);
|
||||
weechat_log_printf (" proxy . . . . . . . : '%s'", ptr_server->proxy);
|
||||
weechat_log_printf (" addresses . . . . . : '%s'", ptr_server->addresses);
|
||||
weechat_log_printf (" ipv6. . . . . . . . : %d", ptr_server->ipv6);
|
||||
weechat_log_printf (" ssl . . . . . . . . : %d", ptr_server->ssl);
|
||||
|
||||
@@ -63,6 +63,7 @@ struct t_irc_server
|
||||
int autoconnect; /* = 1 if auto connect at startup */
|
||||
int autoreconnect; /* = 1 if auto reco when disconnected */
|
||||
int autoreconnect_delay; /* delay before trying again reconnect */
|
||||
char *proxy; /* proxy used for this server (optional) */
|
||||
char *addresses; /* server addresses (IP/name with port) */
|
||||
int ipv6; /* use IPv6 protocol */
|
||||
int ssl; /* SSL protocol */
|
||||
@@ -157,6 +158,7 @@ extern void irc_server_free_all ();
|
||||
extern struct t_irc_server *irc_server_new (const char *name, int autoconnect,
|
||||
int autoreconnect,
|
||||
int autoreconnect_delay,
|
||||
const char *proxy,
|
||||
const char *addresses,
|
||||
int ipv6,
|
||||
int ssl,
|
||||
|
||||
@@ -2752,7 +2752,7 @@ weechat_lua_api_hook_connect_cb (void *data, int status, const char *ip_address)
|
||||
static int
|
||||
weechat_lua_api_hook_connect (lua_State *L)
|
||||
{
|
||||
const char *address, *local_hostname, *function;
|
||||
const char *proxy, *address, *local_hostname, *function;
|
||||
int n, port, sock, ipv6;
|
||||
char *result;
|
||||
|
||||
@@ -2764,7 +2764,8 @@ weechat_lua_api_hook_connect (lua_State *L)
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_connect");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
proxy = NULL;
|
||||
address = NULL;
|
||||
port = 0;
|
||||
sock = 0;
|
||||
@@ -2773,13 +2774,14 @@ weechat_lua_api_hook_connect (lua_State *L)
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 6)
|
||||
|
||||
if (n < 7)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
proxy = lua_tostring (lua_current_interpreter, -7);
|
||||
address = lua_tostring (lua_current_interpreter, -6);
|
||||
port = lua_tonumber (lua_current_interpreter, -5);
|
||||
sock = lua_tonumber (lua_current_interpreter, -4);
|
||||
@@ -2789,6 +2791,7 @@ weechat_lua_api_hook_connect (lua_State *L)
|
||||
|
||||
result = script_ptr2str (script_api_hook_connect (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
proxy,
|
||||
address,
|
||||
port,
|
||||
sock,
|
||||
|
||||
@@ -2299,7 +2299,7 @@ weechat_perl_api_hook_connect_cb (void *data, int status,
|
||||
|
||||
static XS (XS_weechat_api_hook_connect)
|
||||
{
|
||||
char *address, *local_hostname, *result;
|
||||
char *proxy, *address, *local_hostname, *result;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2311,25 +2311,27 @@ static XS (XS_weechat_api_hook_connect)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 6)
|
||||
if (items < 7)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
address = SvPV (ST (0), PL_na);
|
||||
local_hostname = SvPV (ST (4), PL_na);
|
||||
proxy = SvPV (ST (0), PL_na);
|
||||
address = SvPV (ST (1), PL_na);
|
||||
local_hostname = SvPV (ST (5), PL_na);
|
||||
|
||||
result = script_ptr2str (script_api_hook_connect (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
proxy,
|
||||
address,
|
||||
SvIV (ST (1)), /* port */
|
||||
SvIV (ST (2)), /* sock */
|
||||
SvIV (ST (3)), /* ipv6 */
|
||||
SvIV (ST (2)), /* port */
|
||||
SvIV (ST (3)), /* sock */
|
||||
SvIV (ST (4)), /* ipv6 */
|
||||
NULL, /* gnutls session */
|
||||
local_hostname,
|
||||
&weechat_perl_api_hook_connect_cb,
|
||||
SvPV (ST (5), PL_na))); /* perl function */
|
||||
SvPV (ST (6), PL_na))); /* perl function */
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -2453,7 +2453,7 @@ weechat_python_api_hook_connect_cb (void *data, int status,
|
||||
static PyObject *
|
||||
weechat_python_api_hook_connect (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *address, *local_hostname, *function, *result;
|
||||
char *proxy, *address, *local_hostname, *function, *result;
|
||||
int port, sock, ipv6;
|
||||
PyObject *object;
|
||||
|
||||
@@ -2465,7 +2465,8 @@ weechat_python_api_hook_connect (PyObject *self, PyObject *args)
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_connect");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
proxy = NULL;
|
||||
address = NULL;
|
||||
port = 0;
|
||||
sock = 0;
|
||||
@@ -2473,8 +2474,8 @@ weechat_python_api_hook_connect (PyObject *self, PyObject *args)
|
||||
local_hostname = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "siiiss", &address, &port, &sock, &ipv6,
|
||||
&local_hostname, &function))
|
||||
if (!PyArg_ParseTuple (args, "ssiiiss", &proxy, &address, &port, &sock,
|
||||
&ipv6, &local_hostname, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -2482,6 +2483,7 @@ weechat_python_api_hook_connect (PyObject *self, PyObject *args)
|
||||
|
||||
result = script_ptr2str (script_api_hook_connect (weechat_python_plugin,
|
||||
python_current_script,
|
||||
proxy,
|
||||
address,
|
||||
port,
|
||||
sock,
|
||||
|
||||
@@ -2816,11 +2816,11 @@ weechat_ruby_api_hook_connect_cb (void *data, int status,
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_connect (VALUE class, VALUE address, VALUE port,
|
||||
VALUE sock, VALUE ipv6, VALUE local_hostname,
|
||||
VALUE function)
|
||||
weechat_ruby_api_hook_connect (VALUE class, VALUE proxy, VALUE address,
|
||||
VALUE port, VALUE sock, VALUE ipv6,
|
||||
VALUE local_hostname, VALUE function)
|
||||
{
|
||||
char *c_address, *c_local_hostname, *c_function, *result;
|
||||
char *c_proxy, *c_address, *c_local_hostname, *c_function, *result;
|
||||
int c_port, c_sock, c_ipv6;
|
||||
VALUE return_value;
|
||||
|
||||
@@ -2832,7 +2832,8 @@ weechat_ruby_api_hook_connect (VALUE class, VALUE address, VALUE port,
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_connect");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
c_proxy = NULL;
|
||||
c_address = NULL;
|
||||
c_port = 0;
|
||||
c_sock = 0;
|
||||
@@ -2840,20 +2841,22 @@ weechat_ruby_api_hook_connect (VALUE class, VALUE address, VALUE port,
|
||||
c_local_hostname = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (address) || NIL_P (port) || NIL_P (sock) || NIL_P (ipv6)
|
||||
|| NIL_P (local_hostname) || NIL_P (function))
|
||||
if (NIL_P (proxy) || NIL_P (address) || NIL_P (port) || NIL_P (sock)
|
||||
|| NIL_P (ipv6) || NIL_P (local_hostname) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
Check_Type (proxy, T_STRING);
|
||||
Check_Type (address, T_STRING);
|
||||
Check_Type (port, T_FIXNUM);
|
||||
Check_Type (sock, T_FIXNUM);
|
||||
Check_Type (ipv6, T_FIXNUM);
|
||||
Check_Type (local_hostname, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
|
||||
c_proxy = STR2CSTR (proxy);
|
||||
c_address = STR2CSTR (address);
|
||||
c_port = FIX2INT (port);
|
||||
c_sock = FIX2INT (sock);
|
||||
@@ -2863,6 +2866,7 @@ weechat_ruby_api_hook_connect (VALUE class, VALUE address, VALUE port,
|
||||
|
||||
result = script_ptr2str (script_api_hook_connect (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_proxy,
|
||||
c_address,
|
||||
c_port,
|
||||
c_sock,
|
||||
@@ -5633,7 +5637,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "hook_command", &weechat_ruby_api_hook_command, 6);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_timer", &weechat_ruby_api_hook_timer, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_fd", &weechat_ruby_api_hook_fd, 5);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_connect", &weechat_ruby_api_hook_connect, 6);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_connect", &weechat_ruby_api_hook_connect, 7);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_print", &weechat_ruby_api_hook_print, 5);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_signal", &weechat_ruby_api_hook_signal, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
|
||||
|
||||
@@ -744,8 +744,9 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_hook *
|
||||
script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *address, int port, int sock, int ipv6,
|
||||
void *gnutls_sess, const char *local_hostname,
|
||||
const char *proxy, const char *address, int port,
|
||||
int sock, int ipv6, void *gnutls_sess,
|
||||
const char *local_hostname,
|
||||
int (*callback)(void *data, int status, const char *ip_address),
|
||||
const char *function)
|
||||
{
|
||||
@@ -756,8 +757,8 @@ script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = weechat_hook_connect (address, port, sock, ipv6, gnutls_sess,
|
||||
local_hostname, callback,
|
||||
new_hook = weechat_hook_connect (proxy, address, port, sock, ipv6,
|
||||
gnutls_sess, local_hostname, callback,
|
||||
new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
|
||||
@@ -121,6 +121,7 @@ extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugi
|
||||
const char *function);
|
||||
extern struct t_hook *script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *proxy,
|
||||
const char *address,
|
||||
int port,
|
||||
int sock,
|
||||
|
||||
@@ -2663,7 +2663,7 @@ weechat_tcl_api_hook_connect (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *address, *local_hostname, *result;
|
||||
char *proxy, *address, *local_hostname, *result;
|
||||
int i, port, sock, ipv6;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2675,25 +2675,27 @@ weechat_tcl_api_hook_connect (ClientData clientData, Tcl_Interp *interp,
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 6)
|
||||
if (objc < 7)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if ((Tcl_GetIntFromObj (interp, objv[2], &port) != TCL_OK)
|
||||
|| (Tcl_GetIntFromObj (interp, objv[3], &sock) != TCL_OK)
|
||||
|| (Tcl_GetIntFromObj (interp, objv[4], &ipv6) != TCL_OK))
|
||||
if ((Tcl_GetIntFromObj (interp, objv[3], &port) != TCL_OK)
|
||||
|| (Tcl_GetIntFromObj (interp, objv[4], &sock) != TCL_OK)
|
||||
|| (Tcl_GetIntFromObj (interp, objv[5], &ipv6) != TCL_OK))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_connect");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
address = Tcl_GetStringFromObj (objv[1], &i);
|
||||
local_hostname = Tcl_GetStringFromObj (objv[5], &i);
|
||||
proxy = Tcl_GetStringFromObj (objv[1], &i);
|
||||
address = Tcl_GetStringFromObj (objv[2], &i);
|
||||
local_hostname = Tcl_GetStringFromObj (objv[6], &i);
|
||||
|
||||
result = script_ptr2str (script_api_hook_connect (weechat_tcl_plugin,
|
||||
tcl_current_script,
|
||||
proxy,
|
||||
address,
|
||||
port,
|
||||
sock,
|
||||
@@ -2701,7 +2703,7 @@ weechat_tcl_api_hook_connect (ClientData clientData, Tcl_Interp *interp,
|
||||
NULL, /* gnutls session */
|
||||
local_hostname,
|
||||
&weechat_tcl_api_hook_connect_cb,
|
||||
Tcl_GetStringFromObj (objv[6], &i))); /* tcl function */
|
||||
Tcl_GetStringFromObj (objv[7], &i))); /* tcl function */
|
||||
|
||||
TCL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -342,6 +342,7 @@ struct t_weechat_plugin
|
||||
int (*callback)(void *data),
|
||||
void *callback_data);
|
||||
struct t_hook *(*hook_connect) (struct t_weechat_plugin *plugin,
|
||||
const char *proxy,
|
||||
const char *address,
|
||||
int port,
|
||||
int sock,
|
||||
@@ -518,8 +519,10 @@ struct t_weechat_plugin
|
||||
struct t_gui_buffer *buffer, const char *command);
|
||||
|
||||
/* network */
|
||||
int (*network_pass_proxy) (int sock, const char *address, int port);
|
||||
int (*network_connect_to) (int sock, unsigned long address, int port);
|
||||
int (*network_pass_proxy) (const char *proxy, int sock,
|
||||
const char *address, int port);
|
||||
int (*network_connect_to) (const char *proxy, int sock,
|
||||
unsigned long address, int port);
|
||||
|
||||
/* infos */
|
||||
const char *(*info_get) (struct t_weechat_plugin *plugin,
|
||||
@@ -870,11 +873,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->hook_fd(weechat_plugin, __fd, __flag_read, \
|
||||
__flag_write, __flag_exception, __callback, \
|
||||
__data)
|
||||
#define weechat_hook_connect(__address, __port, __sock, __ipv6, \
|
||||
__gnutls_sess, __local_hostname, \
|
||||
#define weechat_hook_connect(__proxy, __address, __port, __sock, \
|
||||
__ipv6, __gnutls_sess, __local_hostname, \
|
||||
__callback, __data) \
|
||||
weechat_plugin->hook_connect(weechat_plugin, __address, __port, \
|
||||
__sock, __ipv6, __gnutls_sess, \
|
||||
weechat_plugin->hook_connect(weechat_plugin, __proxy, __address, \
|
||||
__port, __sock, __ipv6, __gnutls_sess, \
|
||||
__local_hostname, __callback, __data)
|
||||
#define weechat_hook_print(__buffer, __tags, __msg, __strip__colors, \
|
||||
__callback, __data) \
|
||||
@@ -1014,10 +1017,12 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->command(weechat_plugin, __buffer, __command)
|
||||
|
||||
/* network */
|
||||
#define weechat_network_pass_proxy(__sock, __address, __port) \
|
||||
weechat_plugin->network_pass_proxy(__sock, __address, __port)
|
||||
#define weechat_network_connect_to(__sock, __address, __port) \
|
||||
weechat_plugin->network_connect_to(__sock, __address, __port)
|
||||
#define weechat_network_pass_proxy(__proxy, __sock, __address, __port) \
|
||||
weechat_plugin->network_pass_proxy(__proxy, __sock, __address, \
|
||||
__port)
|
||||
#define weechat_network_connect_to(__proxy, __sock, __address, __port) \
|
||||
weechat_plugin->network_connect_to(__proxy, __sock, __address, \
|
||||
__port)
|
||||
|
||||
/* infos */
|
||||
#define weechat_info_get(__info_name, __arguments) \
|
||||
|
||||
@@ -167,7 +167,8 @@ xfer_dcc_recv_file_child (struct t_xfer *xfer)
|
||||
time_t last_sent, new_time;
|
||||
|
||||
/* first connect to sender (blocking) */
|
||||
if (!weechat_network_connect_to (xfer->sock, xfer->address, xfer->port))
|
||||
if (!weechat_network_connect_to (xfer->proxy, xfer->sock,
|
||||
xfer->address, xfer->port))
|
||||
{
|
||||
xfer_network_write_pipe (xfer, XFER_STATUS_FAILED,
|
||||
XFER_ERROR_CONNECT_SENDER);
|
||||
|
||||
@@ -492,7 +492,8 @@ xfer_network_connect (struct t_xfer *xfer)
|
||||
{
|
||||
if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1)
|
||||
return 0;
|
||||
weechat_network_connect_to (xfer->sock, xfer->address, xfer->port);
|
||||
weechat_network_connect_to (xfer->proxy, xfer->sock, xfer->address,
|
||||
xfer->port);
|
||||
|
||||
xfer->hook_fd = weechat_hook_fd (xfer->sock,
|
||||
1, 0, 0,
|
||||
|
||||
+15
-9
@@ -457,10 +457,10 @@ xfer_alloc ()
|
||||
|
||||
struct t_xfer *
|
||||
xfer_new (const char *plugin_name, const char *plugin_id, enum t_xfer_type type,
|
||||
enum t_xfer_protocol protocol, const char *remote_nick, const char *local_nick,
|
||||
const char *filename,
|
||||
unsigned long size, unsigned long address, int port, int sock,
|
||||
const char *local_filename)
|
||||
enum t_xfer_protocol protocol, const char *remote_nick,
|
||||
const char *local_nick, const char *filename,
|
||||
unsigned long size, const char *proxy, unsigned long address,
|
||||
int port, int sock, const char *local_filename)
|
||||
{
|
||||
struct t_xfer *new_xfer;
|
||||
|
||||
@@ -491,6 +491,7 @@ xfer_new (const char *plugin_name, const char *plugin_id, enum t_xfer_type type,
|
||||
else
|
||||
new_xfer->filename = strdup (_("xfer chat"));
|
||||
new_xfer->size = size;
|
||||
new_xfer->proxy = (proxy) ? strdup (proxy) : NULL;
|
||||
new_xfer->address = address;
|
||||
new_xfer->port = port;
|
||||
|
||||
@@ -657,7 +658,7 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
|
||||
{
|
||||
struct t_infolist *infolist;
|
||||
const char *plugin_name, *plugin_id, *str_type, *str_protocol;
|
||||
const char *remote_nick, *local_nick, *filename;
|
||||
const char *remote_nick, *local_nick, *filename, *proxy;
|
||||
int type, protocol;
|
||||
const char *weechat_dir;
|
||||
char *dir1, *dir2, *filename2, *short_filename, *pos;
|
||||
@@ -708,6 +709,7 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
|
||||
remote_nick = weechat_infolist_string (infolist, "remote_nick");
|
||||
local_nick = weechat_infolist_string (infolist, "local_nick");
|
||||
filename = weechat_infolist_string (infolist, "filename");
|
||||
proxy = weechat_infolist_string (infolist, "proxy");
|
||||
protocol = XFER_NO_PROTOCOL;
|
||||
|
||||
if (!plugin_name || !plugin_id || !str_type || !remote_nick || !local_nick)
|
||||
@@ -835,7 +837,7 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
|
||||
/* get local IP address */
|
||||
sscanf (weechat_infolist_string (infolist, "address"), "%lu", &local_addr);
|
||||
|
||||
/* look up the IP address from dcc_own_ip, if set */
|
||||
/* look up the IP address from network_own_ip, if set */
|
||||
if (weechat_config_string(xfer_config_network_own_ip)
|
||||
&& weechat_config_string(xfer_config_network_own_ip)[0])
|
||||
{
|
||||
@@ -970,11 +972,12 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
|
||||
if (XFER_IS_FILE(type))
|
||||
ptr_xfer = xfer_new (plugin_name, plugin_id, type, protocol,
|
||||
remote_nick, local_nick, short_filename,
|
||||
file_size, local_addr, port, sock, filename2);
|
||||
file_size, proxy, local_addr, port, sock,
|
||||
filename2);
|
||||
else
|
||||
ptr_xfer = xfer_new (plugin_name, plugin_id, type, protocol,
|
||||
remote_nick, local_nick, NULL, 0, local_addr,
|
||||
port, sock, NULL);
|
||||
remote_nick, local_nick, NULL, 0, proxy,
|
||||
local_addr, port, sock, NULL);
|
||||
|
||||
if (!ptr_xfer)
|
||||
{
|
||||
@@ -1207,6 +1210,8 @@ xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer)
|
||||
snprintf (value, sizeof (value), "%lu", xfer->size);
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "size", value))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "proxy", xfer->proxy))
|
||||
return 0;
|
||||
snprintf (value, sizeof (value), "%lu", xfer->address);
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "address", value))
|
||||
return 0;
|
||||
@@ -1295,6 +1300,7 @@ xfer_print_log ()
|
||||
weechat_log_printf (" local_nick. . . . . : '%s'", ptr_xfer->local_nick);
|
||||
weechat_log_printf (" filename. . . . . . : '%s'", ptr_xfer->filename);
|
||||
weechat_log_printf (" size. . . . . . . . : %lu", ptr_xfer->size);
|
||||
weechat_log_printf (" proxy . . . . . . . : '%s'", ptr_xfer->proxy);
|
||||
weechat_log_printf (" address . . . . . . : %lu", ptr_xfer->address);
|
||||
weechat_log_printf (" port. . . . . . . . : %d", ptr_xfer->port);
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ struct t_xfer
|
||||
char *local_nick; /* local nick */
|
||||
char *filename; /* filename */
|
||||
unsigned long size; /* file size */
|
||||
char *proxy; /* proxy to use (optional) */
|
||||
unsigned long address; /* local or remote IP address */
|
||||
int port; /* remote port */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user