mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 14:56:39 +02:00
Add all server options for IRC commands /server and /connect
This commit is contained in:
@@ -536,9 +536,8 @@ int
|
||||
irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
int i, nb_connect, connect_ok, all_servers, no_join, port, ipv6, ssl;
|
||||
char *name, *error;
|
||||
long number;
|
||||
int i, nb_connect, connect_ok, all_servers, no_join;
|
||||
char *name;
|
||||
|
||||
IRC_GET_SERVER(buffer);
|
||||
|
||||
@@ -548,9 +547,6 @@ irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
|
||||
nb_connect = 0;
|
||||
connect_ok = 1;
|
||||
port = IRC_SERVER_DEFAULT_PORT;
|
||||
ipv6 = 0;
|
||||
ssl = 0;
|
||||
|
||||
all_servers = 0;
|
||||
no_join = 0;
|
||||
@@ -560,26 +556,6 @@ irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
all_servers = 1;
|
||||
if (weechat_strcasecmp (argv[i], "-nojoin") == 0)
|
||||
no_join = 1;
|
||||
if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
|
||||
ipv6 = 1;
|
||||
if (weechat_strcasecmp (argv[i], "-ssl") == 0)
|
||||
ssl = 1;
|
||||
if (weechat_strcasecmp (argv[i], "-port") == 0)
|
||||
{
|
||||
if (i == (argc - 1))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: missing argument for \"%s\" "
|
||||
"option"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME,
|
||||
"-port");
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
error = NULL;
|
||||
number = strtol (argv[++i], &error, 10);
|
||||
if (error && !error[0])
|
||||
port = number;
|
||||
}
|
||||
}
|
||||
|
||||
if (all_servers)
|
||||
@@ -625,16 +601,8 @@ irc_command_connect (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
IRC_COLOR_CHAT_SERVER,
|
||||
ptr_server->name,
|
||||
IRC_COLOR_CHAT);
|
||||
if (ipv6)
|
||||
{
|
||||
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_IPV6],
|
||||
"on", 1);
|
||||
}
|
||||
if (ssl)
|
||||
{
|
||||
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_SSL],
|
||||
"on", 1);
|
||||
}
|
||||
irc_server_apply_command_line_options (ptr_server,
|
||||
argc, argv);
|
||||
if (!irc_command_connect_one_server (ptr_server, 0))
|
||||
connect_ok = 0;
|
||||
}
|
||||
@@ -3011,34 +2979,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
|
||||
weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_ADDRESSES],
|
||||
argv[3], 1);
|
||||
|
||||
/* parse arguments */
|
||||
for (i = 4; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
if (weechat_strcasecmp (argv[i], "-auto") == 0)
|
||||
{
|
||||
weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_AUTOCONNECT],
|
||||
"on", 1);
|
||||
}
|
||||
if (weechat_strcasecmp (argv[i], "-noauto") == 0)
|
||||
{
|
||||
weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_AUTOCONNECT],
|
||||
"off", 1);
|
||||
}
|
||||
if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
|
||||
{
|
||||
weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_IPV6],
|
||||
"on", 1);
|
||||
}
|
||||
if (weechat_strcasecmp (argv[i], "-ssl") == 0)
|
||||
{
|
||||
weechat_config_option_set (new_server->options[IRC_SERVER_OPTION_SSL],
|
||||
"on", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
irc_server_apply_command_line_options (new_server, argc, argv);
|
||||
|
||||
weechat_printf (NULL,
|
||||
_("%s: server %s%s%s created"),
|
||||
@@ -3870,8 +3811,8 @@ irc_command_init ()
|
||||
weechat_hook_command ("connect",
|
||||
N_("connect to IRC server(s)"),
|
||||
N_("[-all [-nojoin] | servername [servername ...] "
|
||||
"[-nojoin] | hostname[/port] [-ipv6] "
|
||||
"[-ssl]]"),
|
||||
"[-nojoin] | hostname[/port] [-option[=value]] "
|
||||
"[-nooption]]"),
|
||||
N_(" -all: connect to all servers\n"
|
||||
"servername: internal server name to connect "
|
||||
"(server must have been created by /server add)\n"
|
||||
@@ -3879,8 +3820,16 @@ irc_command_init ()
|
||||
"autojoin is enabled on server)\n"
|
||||
" hostname: hostname (or IP) of a server\n"
|
||||
" port: port for server (6667 by default)\n"
|
||||
" ipv6: use IPv6 protocol\n"
|
||||
" ssl: use SSL protocol"),
|
||||
" option: set option for server (for boolean "
|
||||
"option, value can be omitted)\n"
|
||||
" nooption: set boolean option to 'off' (for "
|
||||
"example: -nossl)\n\n"
|
||||
"Examples:\n"
|
||||
" /connect freenode\n"
|
||||
" /connect irc.oftc.net/6667\n"
|
||||
" /connect irc6.oftc.net/6667 -ipv6\n"
|
||||
" /connect irc6.oftc.net/6697 -ipv6 -ssl\n"
|
||||
" /connect my.server.org/6697 -ssl -password=test"),
|
||||
"-all -nojoin"
|
||||
" || %(irc_servers)|%*",
|
||||
&irc_command_connect, NULL);
|
||||
@@ -4224,8 +4173,8 @@ irc_command_init ()
|
||||
weechat_hook_command ("server",
|
||||
N_("list, add or remove IRC servers"),
|
||||
N_("[list [servername]] | [listfull [servername]] | "
|
||||
"[add servername hostname[/port] "
|
||||
"[-auto | -noauto] [-ipv6] [-ssl]] | "
|
||||
"[add servername hostname[/port] [-temp] "
|
||||
"[-option[=value]] [-nooption]] | "
|
||||
"[copy servername newservername] | "
|
||||
"[rename servername newservername] | "
|
||||
"[keep servername] | [del servername] | "
|
||||
@@ -4239,12 +4188,11 @@ irc_command_init ()
|
||||
"display use\n"
|
||||
" hostname: name or IP address of server, with "
|
||||
"optional port (default: 6667)\n"
|
||||
" auto: automatically connect to server "
|
||||
"when WeeChat starts\n"
|
||||
" noauto: do not connect to server when "
|
||||
"WeeChat starts (default)\n"
|
||||
" ipv6: use IPv6 protocol\n"
|
||||
" ssl: use SSL protocol\n"
|
||||
" temp: create temporary server (not saved)\n"
|
||||
" option: set option for server (for boolean "
|
||||
"option, value can be omitted)\n"
|
||||
" nooption: set boolean option to 'off' (for "
|
||||
"example: -nossl)\n"
|
||||
" copy: duplicate a server\n"
|
||||
" rename: rename a server\n"
|
||||
" keep: keep server in config file (for "
|
||||
@@ -4257,7 +4205,7 @@ irc_command_init ()
|
||||
" raw: open buffer with raw IRC data\n\n"
|
||||
"Examples:\n"
|
||||
" /server listfull\n"
|
||||
" /server add oftc irc.oftc.net/6697 -ssl\n"
|
||||
" /server add oftc irc.oftc.net/6697 -ssl -autoconnect\n"
|
||||
" /server add oftc6 irc6.oftc.net/6697 -ipv6 -ssl\n"
|
||||
" /server add freenode2 chat.eu.freenode.net/6667,"
|
||||
"chat.us.freenode.net/6667\n"
|
||||
|
||||
@@ -516,6 +516,64 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
return (ptr_server) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_apply_command_line_options: apply options on command line to a
|
||||
* server
|
||||
* for example:
|
||||
* -ssl
|
||||
* -nossl
|
||||
* -password=test
|
||||
* -proxy=myproxy
|
||||
*/
|
||||
|
||||
void
|
||||
irc_server_apply_command_line_options (struct t_irc_server *server,
|
||||
int argc, char **argv)
|
||||
{
|
||||
int i, index_option;
|
||||
char *pos, *option_name, *ptr_value, *value_boolean[2] = { "off", "on" };
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
pos = strchr (argv[i], '=');
|
||||
ptr_value = value_boolean[0];
|
||||
if (pos)
|
||||
{
|
||||
option_name = weechat_strndup (argv[i] + 1, pos - argv[i] - 1);
|
||||
ptr_value = pos + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
option_name = strdup (argv[i] + 1);
|
||||
ptr_value = value_boolean[1];
|
||||
}
|
||||
if (option_name)
|
||||
{
|
||||
index_option = irc_server_search_option (option_name);
|
||||
if (index_option < 0)
|
||||
{
|
||||
/* look if option is negative, like "-noxxx" */
|
||||
if (weechat_strncasecmp (argv[i], "-no", 3) == 0)
|
||||
{
|
||||
free (option_name);
|
||||
option_name = strdup (argv[i] + 3);
|
||||
index_option = irc_server_search_option (option_name);
|
||||
ptr_value = value_boolean[0];
|
||||
}
|
||||
}
|
||||
if (index_option >= 0)
|
||||
{
|
||||
weechat_config_option_set (server->options[index_option],
|
||||
ptr_value, 1);
|
||||
}
|
||||
free (option_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_outqueue_add: add a message in out queue
|
||||
*/
|
||||
|
||||
@@ -173,6 +173,8 @@ extern void irc_server_set_nicks (struct t_irc_server *server, const char *nicks
|
||||
extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
|
||||
extern struct t_irc_server *irc_server_alloc (const char *name);
|
||||
extern int irc_server_alloc_with_url (const char *irc_url);
|
||||
extern void irc_server_apply_command_line_options (struct t_irc_server *server,
|
||||
int argc, char **argv);
|
||||
extern void irc_server_free_all ();
|
||||
extern struct t_irc_server *irc_server_copy (struct t_irc_server *server,
|
||||
const char *new_name);
|
||||
|
||||
Reference in New Issue
Block a user