mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 08:43:13 +02:00
relay: fix code style
This commit is contained in:
@@ -145,7 +145,7 @@ relay_command_server_list ()
|
||||
NULL,
|
||||
_(" %s %s%s%s, relay: %s%s%s, %s (not started)"),
|
||||
RELAY_COLOR_CHAT_BUFFER,
|
||||
ptr_server->unix_socket ? _("path") : _("port"),
|
||||
(ptr_server->unix_socket) ? _("path") : _("port"),
|
||||
ptr_server->path,
|
||||
RELAY_COLOR_CHAT,
|
||||
RELAY_COLOR_CHAT_BUFFER,
|
||||
@@ -166,7 +166,7 @@ relay_command_server_list ()
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_(" %s %s%s%s, relay: %s%s%s, %s, started on: %s"),
|
||||
ptr_server->unix_socket ? _("path") : _("port"),
|
||||
(ptr_server->unix_socket) ? _("path") : _("port"),
|
||||
RELAY_COLOR_CHAT_BUFFER,
|
||||
ptr_server->path,
|
||||
RELAY_COLOR_CHAT,
|
||||
@@ -174,7 +174,7 @@ relay_command_server_list ()
|
||||
ptr_server->protocol_string,
|
||||
RELAY_COLOR_CHAT,
|
||||
((ptr_server->ipv4 && ptr_server->ipv6) ? "IPv4+6" : ((ptr_server->ipv6) ? "IPv6" : ((ptr_server->ipv4) ? "IPv4" : "UNIX"))),
|
||||
date_start);
|
||||
date_start);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -226,9 +226,8 @@ relay_command_relay (const void *pointer, void *data,
|
||||
{
|
||||
WEECHAT_COMMAND_MIN_ARGS(4, "add");
|
||||
/* check if we're expecting a path or a port */
|
||||
port_path_section = strncmp (argv[2], "unix.", 5) ?
|
||||
relay_config_section_port :
|
||||
relay_config_section_path;
|
||||
port_path_section = (strncmp (argv[2], "unix.", 5) == 0) ?
|
||||
relay_config_section_path : relay_config_section_port;
|
||||
if (relay_config_create_option_port (
|
||||
NULL, NULL,
|
||||
relay_config_file,
|
||||
@@ -252,17 +251,17 @@ relay_command_relay (const void *pointer, void *data,
|
||||
{
|
||||
path = strdup (ptr_server->path);
|
||||
relay_server_free (ptr_server);
|
||||
ptr_option = weechat_config_search_option (relay_config_file,
|
||||
ptr_server->unix_socket ?
|
||||
relay_config_section_path :
|
||||
relay_config_section_port,
|
||||
argv_eol[2]);
|
||||
ptr_option = weechat_config_search_option (
|
||||
relay_config_file,
|
||||
(ptr_server->unix_socket) ? relay_config_section_path : relay_config_section_port,
|
||||
argv_eol[2]);
|
||||
if (ptr_option)
|
||||
weechat_config_option_free (ptr_option);
|
||||
weechat_printf (NULL,
|
||||
_("%s: relay \"%s\" (%s %s) removed"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
argv[2], ptr_server->unix_socket ? _("path") : _("port"),
|
||||
argv[2],
|
||||
(ptr_server->unix_socket) ? _("path") : _("port"),
|
||||
path);
|
||||
free (path);
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ relay_config_create_option_port (const void *pointer, void *data,
|
||||
const char *option_name,
|
||||
const char *value)
|
||||
{
|
||||
int rc, protocol_number, ipv4, ipv6, ssl, un;
|
||||
int rc, protocol_number, ipv4, ipv6, ssl, unix_socket;
|
||||
char *error, *protocol, *protocol_args;
|
||||
long port;
|
||||
struct t_relay_server *ptr_server;
|
||||
@@ -646,8 +646,8 @@ relay_config_create_option_port (const void *pointer, void *data,
|
||||
protocol_number = -1;
|
||||
port = -1;
|
||||
|
||||
relay_server_get_protocol_args (option_name, &ipv4, &ipv6, &ssl, &un,
|
||||
&protocol, &protocol_args);
|
||||
relay_server_get_protocol_args (option_name, &ipv4, &ipv6, &ssl,
|
||||
&unix_socket, &protocol, &protocol_args);
|
||||
|
||||
#ifndef HAVE_GNUTLS
|
||||
if (ssl)
|
||||
@@ -696,7 +696,7 @@ relay_config_create_option_port (const void *pointer, void *data,
|
||||
|
||||
if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR)
|
||||
{
|
||||
if (un)
|
||||
if (unix_socket)
|
||||
{
|
||||
ptr_server = relay_server_search_path (value);
|
||||
}
|
||||
@@ -711,7 +711,7 @@ relay_config_create_option_port (const void *pointer, void *data,
|
||||
weechat_printf (NULL, _("%s%s: error: %s \"%s\" is already used"),
|
||||
weechat_prefix ("error"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
un ? _("path") : _("port"),
|
||||
(unix_socket) ? _("path") : _("port"),
|
||||
value);
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
}
|
||||
@@ -720,28 +720,28 @@ relay_config_create_option_port (const void *pointer, void *data,
|
||||
if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR)
|
||||
{
|
||||
if (relay_server_new (option_name, protocol_number, protocol_args,
|
||||
port, value, ipv4, ipv6, ssl, un))
|
||||
port, value, ipv4, ipv6, ssl, unix_socket))
|
||||
{
|
||||
/* create configuration option */
|
||||
if (un)
|
||||
if (unix_socket)
|
||||
{
|
||||
weechat_config_new_option (
|
||||
config_file, section,
|
||||
option_name, "string", NULL,
|
||||
NULL, 0, 0, "", value, 0,
|
||||
&relay_config_check_path_cb, NULL, NULL,
|
||||
&relay_config_change_port_cb, NULL, NULL,
|
||||
&relay_config_delete_port_cb, NULL, NULL);
|
||||
config_file, section,
|
||||
option_name, "string", NULL,
|
||||
NULL, 0, 0, "", value, 0,
|
||||
&relay_config_check_path_cb, NULL, NULL,
|
||||
&relay_config_change_port_cb, NULL, NULL,
|
||||
&relay_config_delete_port_cb, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_config_new_option (
|
||||
config_file, section,
|
||||
option_name, "integer", NULL,
|
||||
NULL, 0, 65535, "", value, 0,
|
||||
&relay_config_check_port_cb, NULL, NULL,
|
||||
&relay_config_change_port_cb, NULL, NULL,
|
||||
&relay_config_delete_port_cb, NULL, NULL);
|
||||
config_file, section,
|
||||
option_name, "integer", NULL,
|
||||
NULL, 0, 65535, "", value, 0,
|
||||
&relay_config_check_port_cb, NULL, NULL,
|
||||
&relay_config_change_port_cb, NULL, NULL,
|
||||
&relay_config_delete_port_cb, NULL, NULL);
|
||||
}
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
|
||||
}
|
||||
@@ -1177,6 +1177,7 @@ relay_config_init ()
|
||||
}
|
||||
|
||||
relay_config_section_path = ptr_section;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,16 +68,17 @@ struct t_relay_server *last_relay_server = NULL;
|
||||
|
||||
void
|
||||
relay_server_get_protocol_args (const char *protocol_and_args,
|
||||
int *ipv4, int *ipv6, int *ssl, int *un,
|
||||
int *ipv4, int *ipv6, int *ssl,
|
||||
int *unix_socket,
|
||||
char **protocol, char **protocol_args)
|
||||
{
|
||||
int opt_ipv4, opt_ipv6, opt_ssl, opt_un;
|
||||
int opt_ipv4, opt_ipv6, opt_ssl, opt_unix_socket;
|
||||
char *pos;
|
||||
|
||||
opt_ipv4 = -1;
|
||||
opt_ipv6 = -1;
|
||||
opt_ssl = 0;
|
||||
opt_un = -1;
|
||||
opt_unix_socket = -1;
|
||||
while (1)
|
||||
{
|
||||
if (strncmp (protocol_and_args, "ipv4.", 5) == 0)
|
||||
@@ -97,13 +98,13 @@ relay_server_get_protocol_args (const char *protocol_and_args,
|
||||
}
|
||||
else if (strncmp (protocol_and_args, "unix.", 5) == 0)
|
||||
{
|
||||
opt_un = 1;
|
||||
opt_unix_socket = 1;
|
||||
protocol_and_args += 5;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if ((opt_ipv4 == -1) && (opt_ipv6 == -1) && (opt_un == -1))
|
||||
if ((opt_ipv4 == -1) && (opt_ipv6 == -1) && (opt_unix_socket == -1))
|
||||
{
|
||||
/*
|
||||
* no IPv4/IPv6/UNIX specified, then use defaults:
|
||||
@@ -112,7 +113,7 @@ relay_server_get_protocol_args (const char *protocol_and_args,
|
||||
*/
|
||||
opt_ipv4 = 1;
|
||||
opt_ipv6 = weechat_config_boolean (relay_config_network_ipv6);
|
||||
opt_un = 0;
|
||||
opt_unix_socket = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -120,10 +121,10 @@ relay_server_get_protocol_args (const char *protocol_and_args,
|
||||
opt_ipv4 = 0;
|
||||
if (opt_ipv6 == -1)
|
||||
opt_ipv6 = 0;
|
||||
if (opt_un == -1)
|
||||
opt_un = 0;
|
||||
if (opt_unix_socket == -1)
|
||||
opt_unix_socket = 0;
|
||||
}
|
||||
if (!opt_ipv4 && !opt_ipv6 && !opt_un)
|
||||
if (!opt_ipv4 && !opt_ipv6 && !opt_unix_socket)
|
||||
{
|
||||
/* IPv4/IPv6/UNIX disabled (should never occur!) */
|
||||
opt_ipv4 = 1;
|
||||
@@ -134,8 +135,8 @@ relay_server_get_protocol_args (const char *protocol_and_args,
|
||||
*ipv6 = opt_ipv6;
|
||||
if (ssl)
|
||||
*ssl = opt_ssl;
|
||||
if (un)
|
||||
*un = opt_un;
|
||||
if (unix_socket)
|
||||
*unix_socket = opt_unix_socket;
|
||||
|
||||
pos = strchr (protocol_and_args, '.');
|
||||
if (pos)
|
||||
@@ -215,7 +216,7 @@ relay_server_search_path (const char *path)
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
/* only include UNIX socket relays, to allow for numerical paths */
|
||||
if (!strcmp (path, ptr_server->path) && ptr_server->unix_socket)
|
||||
if (ptr_server->unix_socket && (strcmp (path, ptr_server->path) == 0))
|
||||
return ptr_server;
|
||||
}
|
||||
|
||||
@@ -239,15 +240,13 @@ relay_server_close_socket (struct t_relay_server *server)
|
||||
close (server->sock);
|
||||
server->sock = -1;
|
||||
if (server->unix_socket)
|
||||
{
|
||||
unlink (server->path);
|
||||
}
|
||||
if (!relay_signal_upgrade_received)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: socket closed for %s (%s %s)"),
|
||||
RELAY_PLUGIN_NAME, server->protocol_string,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path);
|
||||
}
|
||||
}
|
||||
@@ -263,13 +262,13 @@ relay_server_sock_cb (const void *pointer, void *data, int fd)
|
||||
struct t_relay_server *server;
|
||||
struct sockaddr_in client_addr;
|
||||
struct sockaddr_in6 client_addr6;
|
||||
struct sockaddr_un client_addr_un;
|
||||
struct sockaddr_un client_addr_unix;
|
||||
|
||||
socklen_t client_addr_size;
|
||||
void *ptr_addr;
|
||||
int client_fd, flags, set, max_clients, num_clients_on_port;
|
||||
char ipv4_address[INET_ADDRSTRLEN + 1], ipv6_address[INET6_ADDRSTRLEN + 1];
|
||||
char un_address[sizeof (client_addr_un.sun_path)];
|
||||
char unix_address[sizeof (client_addr_unix.sun_path)];
|
||||
char *ptr_ip_address, *relay_password, *relay_totp_secret;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -294,7 +293,7 @@ relay_server_sock_cb (const void *pointer, void *data, int fd)
|
||||
}
|
||||
else if (server->unix_socket)
|
||||
{
|
||||
ptr_addr = &client_addr_un;
|
||||
ptr_addr = &client_addr_unix;
|
||||
client_addr_size = sizeof (struct sockaddr_un);
|
||||
}
|
||||
|
||||
@@ -307,7 +306,7 @@ relay_server_sock_cb (const void *pointer, void *data, int fd)
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: cannot accept client on %s %s (%s): error %d %s"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path, server->protocol_string,
|
||||
errno, strerror (errno));
|
||||
goto error;
|
||||
@@ -405,8 +404,9 @@ relay_server_sock_cb (const void *pointer, void *data, int fd)
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy (un_address, client_addr_un.sun_path, sizeof (un_address));
|
||||
ptr_ip_address = un_address;
|
||||
strncpy (unix_address, client_addr_unix.sun_path,
|
||||
sizeof (unix_address));
|
||||
ptr_ip_address = unix_address;
|
||||
}
|
||||
|
||||
/* check if IP is allowed, if not, just close socket */
|
||||
@@ -475,7 +475,7 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
int domain, set, max_clients, addr_size;
|
||||
struct sockaddr_in server_addr;
|
||||
struct sockaddr_in6 server_addr6;
|
||||
struct sockaddr_un server_addr_un;
|
||||
struct sockaddr_un server_addr_unix;
|
||||
const char *bind_address;
|
||||
void *ptr_addr;
|
||||
|
||||
@@ -528,11 +528,11 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
else
|
||||
{
|
||||
domain = AF_UNIX;
|
||||
memset (&server_addr_un, 0, sizeof (struct sockaddr_un));
|
||||
server_addr_un.sun_family = domain;
|
||||
strncpy (server_addr_un.sun_path, server->path,
|
||||
sizeof (server_addr_un.sun_path));
|
||||
ptr_addr = &server_addr_un;
|
||||
memset (&server_addr_unix, 0, sizeof (struct sockaddr_un));
|
||||
server_addr_unix.sun_family = domain;
|
||||
strncpy (server_addr_unix.sun_path, server->path,
|
||||
sizeof (server_addr_unix.sun_path));
|
||||
ptr_addr = &server_addr_unix;
|
||||
addr_size = sizeof (struct sockaddr_un);
|
||||
if (!relay_config_check_path_len (server->path))
|
||||
return 0;
|
||||
@@ -614,7 +614,7 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: cannot \"bind\" on %s %s (%s): error %d %s"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path, server->protocol_string,
|
||||
errno, strerror (errno));
|
||||
close (server->sock);
|
||||
@@ -631,7 +631,7 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: cannot \"listen\" on %s %s (%s): error %d %s"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path, server->protocol_string,
|
||||
errno, strerror (errno));
|
||||
close (server->sock);
|
||||
@@ -648,7 +648,7 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
"%s: listening on %s %s (relay: %s, %s, max %d clients)",
|
||||
max_clients),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path,
|
||||
server->protocol_string,
|
||||
((server->ipv4 && server->ipv6) ? "IPv4+6" : ((server->ipv6) ? "IPv6" : ((server->ipv4) ? "IPv4" : "UNIX"))),
|
||||
@@ -660,7 +660,7 @@ relay_server_create_socket (struct t_relay_server *server)
|
||||
NULL,
|
||||
_("%s: listening on %s %s (relay: %s, %s)"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->unix_socket ? _("path") : _("port"),
|
||||
(server->unix_socket) ? _("path") : _("port"),
|
||||
server->path,
|
||||
server->protocol_string,
|
||||
((server->ipv4 && server->ipv6) ? "IPv4+6" : ((server->ipv6) ? "IPv6" : ((server->ipv4) ? "IPv4" : "UNIX"))));
|
||||
@@ -692,12 +692,12 @@ relay_server_new (const char *protocol_string, enum t_relay_protocol protocol,
|
||||
return NULL;
|
||||
|
||||
/* look for duplicate ports/paths */
|
||||
dup_server = unix_socket ?
|
||||
dup_server = (unix_socket) ?
|
||||
relay_server_search_path (path) : relay_server_search_port (port);
|
||||
if (dup_server)
|
||||
{
|
||||
weechat_printf (NULL, _("%s%s: error: %s \"%s\" is already used"),
|
||||
unix_socket ? _("path") : _("port"),
|
||||
(unix_socket) ? _("path") : _("port"),
|
||||
weechat_prefix ("error"),
|
||||
RELAY_PLUGIN_NAME, port);
|
||||
return NULL;
|
||||
@@ -788,6 +788,7 @@ relay_server_free (struct t_relay_server *server)
|
||||
if (server->protocol_args)
|
||||
free (server->protocol_args);
|
||||
free (server->path);
|
||||
|
||||
free (server);
|
||||
|
||||
relay_servers = new_relay_servers;
|
||||
|
||||
@@ -53,7 +53,7 @@ extern struct t_relay_server *last_relay_server;
|
||||
|
||||
extern void relay_server_get_protocol_args (const char *protocol_and_string,
|
||||
int *ipv4, int *ipv6,
|
||||
int *ssl, int *un,
|
||||
int *ssl, int *unix_socket,
|
||||
char **protocol,
|
||||
char **protocol_args);
|
||||
extern struct t_relay_server *relay_server_search (const char *protocol_and_args);
|
||||
@@ -66,7 +66,7 @@ extern struct t_relay_server *relay_server_new (const char *protocol_string,
|
||||
const char *protocol_args,
|
||||
int port, const char *path,
|
||||
int ipv4, int ipv6,
|
||||
int ssl, int un);
|
||||
int ssl, int unix_socket);
|
||||
extern void relay_server_update_port (struct t_relay_server *server, int port);
|
||||
extern void relay_server_free (struct t_relay_server *server);
|
||||
extern void relay_server_free_all ();
|
||||
|
||||
Reference in New Issue
Block a user