mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 10:43:13 +02:00
Return IPv4/IPv6 address to connect hook callback when connection is ok (used by IRC plugin to display IP of IRC server)
This commit is contained in:
@@ -6,7 +6,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2008-09-17 16:19+0200\n"
|
||||
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
@@ -3795,6 +3795,10 @@ msgstr "%s: Navazuji nové spojení se serverem za %d sekund\n"
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s IP adresa nenalezena\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s nepřipojen k serveru \"%s\"!\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s adresa proxy \"%s\" nenalezena\n"
|
||||
|
||||
@@ -9,7 +9,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2007-09-06 12:44+0200\n"
|
||||
"Last-Translator: Thomas Schuetz <i18n@internet-villa.de>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
@@ -3705,6 +3705,10 @@ msgstr "%s: Neuverbinden in %d Sekunden\n"
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s IP-Adresse nicht gefunden\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s keine Verbindung zum Server \"%s\"!\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s Proxyadresse \"%s\" nicht gefunden\n"
|
||||
|
||||
@@ -6,7 +6,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2007-09-19 12:09+0200\n"
|
||||
"Last-Translator: Roberto González Cardenete <robert.glez@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
@@ -3704,6 +3704,10 @@ msgstr "%s: Reconexión al servidor en %d segundos\n"
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s Dirección IP no encontrada\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s ¡no conectado al servidor \"%s\"!\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s dirección proxy \"%s\" no encontrada\n"
|
||||
|
||||
@@ -6,8 +6,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"PO-Revision-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2008-09-22 16:27+0200\n"
|
||||
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -3731,6 +3731,10 @@ msgstr "%s: reconnexion au serveur dans %d %s"
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s: bascule vers l'adresse %s/%d"
|
||||
|
||||
#, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s: connecté à %s (%s)"
|
||||
|
||||
#, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s%s: adresse du proxy \"%s\" non trouvée"
|
||||
|
||||
@@ -12,7 +12,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2007-10-10 18:07+0200\n"
|
||||
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
@@ -3728,6 +3728,10 @@ msgstr "%s: Újracsatlakozás a szerverhez %d másodperc múlva\n"
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s IP-cím nem található\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s nincs csatlakozva a \"%s\" szerverhez!\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s proxy cím \"%s\" nem található\n"
|
||||
|
||||
@@ -6,7 +6,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WeeChat 0.2.7-dev\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: 2007-09-06 12:44+0200\n"
|
||||
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
|
||||
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
|
||||
@@ -3720,6 +3720,10 @@ msgstr "%s: Повторное подключение к серверу чере
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr "%s IP адрес не найден\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr "%s не подключен к серверу \"%s\"!\n"
|
||||
|
||||
#, fuzzy, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr "%s proxy \"%s\" не найден\n"
|
||||
|
||||
+5
-1
@@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
|
||||
"POT-Creation-Date: 2008-09-21 21:30+0200\n"
|
||||
"POT-Creation-Date: 2008-09-22 16:26+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -3180,6 +3180,10 @@ msgstr ""
|
||||
msgid "%s: switching address to %s/%d"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%s: connected to %s (%s)"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%s%s: proxy address \"%s\" not found"
|
||||
msgstr ""
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ struct t_hook_fd
|
||||
int flags; /* fd flags (read,write,..) */
|
||||
};
|
||||
|
||||
typedef int (t_hook_callback_connect)(void *data, int status);
|
||||
typedef int (t_hook_callback_connect)(void *data, int status, char *ip_address);
|
||||
|
||||
struct t_hook_connect
|
||||
{
|
||||
|
||||
+96
-9
@@ -511,8 +511,10 @@ void
|
||||
network_connect_child (struct t_hook *hook_connect)
|
||||
{
|
||||
struct addrinfo hints, *res, *res_local;
|
||||
char status_str[2];
|
||||
int rc;
|
||||
char status_str[2], *ptr_address, *status_ok_with_address;
|
||||
char ipv4_address[INET_ADDRSTRLEN + 1], ipv6_address[INET6_ADDRSTRLEN + 1];
|
||||
char status_ok_without_address[1 + 5 + 1];
|
||||
int rc, length;
|
||||
|
||||
res = NULL;
|
||||
res_local = NULL;
|
||||
@@ -663,7 +665,55 @@ network_connect_child (struct t_hook *hook_connect)
|
||||
|
||||
/* connection ok */
|
||||
status_str[0] = '0' + WEECHAT_HOOK_CONNECT_OK;
|
||||
write (HOOK_CONNECT(hook_connect, child_write), status_str, 1);
|
||||
|
||||
status_ok_with_address = NULL;
|
||||
ptr_address = NULL;
|
||||
if (HOOK_CONNECT(hook_connect, ipv6))
|
||||
{
|
||||
if (inet_ntop (AF_INET6,
|
||||
&((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr,
|
||||
ipv6_address,
|
||||
INET6_ADDRSTRLEN))
|
||||
{
|
||||
ptr_address = ipv6_address;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//ip = inet_ntoa (((struct sockaddr_in *)(res->ai_addr))->sin_addr);
|
||||
if (inet_ntop (AF_INET,
|
||||
&((struct sockaddr_in *)(res->ai_addr))->sin_addr,
|
||||
ipv4_address,
|
||||
INET_ADDRSTRLEN))
|
||||
{
|
||||
ptr_address = ipv4_address;
|
||||
}
|
||||
}
|
||||
if (ptr_address)
|
||||
{
|
||||
length = strlen (status_str) + 5 + strlen (ptr_address) + 1;
|
||||
status_ok_with_address = malloc (length);
|
||||
if (status_ok_with_address)
|
||||
{
|
||||
snprintf (status_ok_with_address, length, "%s%05d%s",
|
||||
status_str, strlen (ptr_address), ptr_address);
|
||||
}
|
||||
}
|
||||
|
||||
if (status_ok_with_address)
|
||||
{
|
||||
write (HOOK_CONNECT(hook_connect, child_write),
|
||||
status_ok_with_address, strlen (status_ok_with_address));
|
||||
free (status_ok_with_address);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (status_ok_without_address, sizeof (status_ok_without_address),
|
||||
"%s%05d", status_str, 0);
|
||||
write (HOOK_CONNECT(hook_connect, child_write),
|
||||
status_ok_without_address, strlen (status_ok_without_address));
|
||||
}
|
||||
|
||||
if (res)
|
||||
freeaddrinfo (res);
|
||||
if (res_local)
|
||||
@@ -678,20 +728,47 @@ int
|
||||
network_connect_child_read_cb (void *arg_hook_connect)
|
||||
{
|
||||
struct t_hook *hook_connect;
|
||||
char buffer[1];
|
||||
char buffer[1], buf_size_ip[6], *ip_address, *error;
|
||||
int num_read;
|
||||
long size_ip;
|
||||
#ifdef HAVE_GNUTLS
|
||||
int rc;
|
||||
#endif
|
||||
|
||||
hook_connect = (struct t_hook *)arg_hook_connect;
|
||||
|
||||
ip_address = NULL;
|
||||
|
||||
num_read = read (HOOK_CONNECT(hook_connect, child_read),
|
||||
buffer, sizeof (buffer));
|
||||
if (num_read > 0)
|
||||
{
|
||||
if (buffer[0] - '0' == WEECHAT_HOOK_CONNECT_OK)
|
||||
{
|
||||
buf_size_ip[5] = '\0';
|
||||
num_read = read (HOOK_CONNECT(hook_connect, child_read),
|
||||
buf_size_ip, 5);
|
||||
if (num_read == 5)
|
||||
{
|
||||
error = NULL;
|
||||
size_ip = strtol (buf_size_ip, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
ip_address = malloc (size_ip + 1);
|
||||
if (ip_address)
|
||||
{
|
||||
num_read = read (HOOK_CONNECT(hook_connect, child_read),
|
||||
ip_address, size_ip);
|
||||
if (num_read == size_ip)
|
||||
ip_address[size_ip] = '\0';
|
||||
else
|
||||
{
|
||||
free (ip_address);
|
||||
ip_address = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (HOOK_CONNECT(hook_connect, gnutls_sess))
|
||||
{
|
||||
@@ -708,18 +785,25 @@ network_connect_child_read_cb (void *arg_hook_connect)
|
||||
if (rc != GNUTLS_E_SUCCESS)
|
||||
{
|
||||
(void) (HOOK_CONNECT(hook_connect, callback))
|
||||
(hook_connect->callback_data, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR);
|
||||
(hook_connect->callback_data,
|
||||
WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR,
|
||||
ip_address);
|
||||
unhook (hook_connect);
|
||||
if (ip_address)
|
||||
free (ip_address);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
(void) (HOOK_CONNECT(hook_connect, callback))
|
||||
(hook_connect->callback_data, buffer[0] - '0');
|
||||
(hook_connect->callback_data, buffer[0] - '0', ip_address);
|
||||
unhook (hook_connect);
|
||||
}
|
||||
|
||||
if (ip_address)
|
||||
free (ip_address);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -743,7 +827,8 @@ network_connect_with_fork (struct t_hook *hook_connect)
|
||||
{
|
||||
(void) (HOOK_CONNECT(hook_connect, callback))
|
||||
(hook_connect->callback_data,
|
||||
'0' + WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR);
|
||||
'0' + WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR,
|
||||
NULL);
|
||||
unhook (hook_connect);
|
||||
return;
|
||||
}
|
||||
@@ -765,7 +850,8 @@ network_connect_with_fork (struct t_hook *hook_connect)
|
||||
{
|
||||
(void) (HOOK_CONNECT(hook_connect, callback))
|
||||
(hook_connect->callback_data,
|
||||
'0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR);
|
||||
'0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR,
|
||||
NULL);
|
||||
unhook (hook_connect);
|
||||
return;
|
||||
}
|
||||
@@ -786,7 +872,8 @@ network_connect_with_fork (struct t_hook *hook_connect)
|
||||
case -1:
|
||||
(void) (HOOK_CONNECT(hook_connect, callback))
|
||||
(hook_connect->callback_data,
|
||||
'0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR);
|
||||
'0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR,
|
||||
NULL);
|
||||
unhook (hook_connect);
|
||||
return;
|
||||
/* child process */
|
||||
|
||||
@@ -1956,7 +1956,7 @@ irc_server_switch_address (struct t_irc_server *server)
|
||||
*/
|
||||
|
||||
int
|
||||
irc_server_connect_cb (void *arg_server, int status)
|
||||
irc_server_connect_cb (void *arg_server, int status, char *ip_address)
|
||||
{
|
||||
struct t_irc_server *server;
|
||||
int config_proxy_use;
|
||||
@@ -1972,6 +1972,11 @@ irc_server_connect_cb (void *arg_server, int status)
|
||||
{
|
||||
case WEECHAT_HOOK_CONNECT_OK:
|
||||
/* login to server */
|
||||
weechat_printf (server->buffer,
|
||||
_("%s: connected to %s (%s)"),
|
||||
IRC_PLUGIN_NAME,
|
||||
server->addresses_array[server->current_address],
|
||||
(ip_address) ? ip_address : "?");
|
||||
irc_server_login (server);
|
||||
server->hook_fd = weechat_hook_fd (server->sock,
|
||||
1, 0, 0,
|
||||
|
||||
@@ -326,7 +326,9 @@ struct t_weechat_plugin
|
||||
const char *address, int port,
|
||||
int sock, int ipv6, void *gnutls_sess,
|
||||
const char *local_hostname,
|
||||
int (*callback)(void *data, int status),
|
||||
int (*callback)(void *data,
|
||||
int status,
|
||||
char *ip_address),
|
||||
void *callback_data);
|
||||
struct t_hook *(*hook_print) (struct t_weechat_plugin *plugin,
|
||||
struct t_gui_buffer *buffer,
|
||||
|
||||
Reference in New Issue
Block a user