Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modify to /channel, /server and /network #498

Merged
merged 9 commits into from Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/help/in/channel.in
Expand Up @@ -7,6 +7,7 @@

LIST: Displays the list of configured channels.
ADD: Adds a channel to your configuration.
MODIFY: Modifies a channel in your configuration.
REMOVE: Removes a channel from your configuration.

-auto: Automatically join the channel.
Expand Down Expand Up @@ -36,6 +37,7 @@
/CHANNEL ADD -auto #basementcat Quakenet secret_lair
/CHANNEL ADD -auto -bots '*!@*.irssi.org *!bot@irssi.org' -botcmd 'msg $0 op WzerTrzq' #hideout Freenode
/CHANNEL ADD -auto -bots 'Q!TheQBot@CServe.quakenet.org' -botcmd '^MSG Q op #irssi' #irssi Quakenet
/CHANNEL MODIFY -noauto #irssi Freenode
/CHANNEL REMOVE #hideout Freenode

%9Special Example:%9
Expand Down
2 changes: 2 additions & 0 deletions docs/help/in/network.in
Expand Up @@ -7,6 +7,7 @@

LIST: Displays the list of configured networks.
ADD: Adds a network to your configuration.
MODIFY: Modifies a network in your configuration.
REMOVE: Removes a network from your configuration.

-nick: Specifies the nickname to use.
Expand Down Expand Up @@ -59,6 +60,7 @@
/NETWORK ADD -usermode +iw -nick mike -realname 'The one and only mike!' -host staff.irssi.org Freenode
/NETWORK ADD -autosendcmd '^MSG NickServ identify WzerT8zq' Freenode
/NETWORK ADD -autosendcmd '^MSG Q@CServe.quakenet.org AUTH mike WzerT8zq; WAIT 2000; OPER mike WzerT8zq; WAIT 2000; MODE mike +kXP' Quakenet
/NETWORK MODIFY -usermode +gi EFnet
/NETWORK REMOVE Freenode

%9See also:%9 CHANNEL, CONNECT, SERVER
Expand Down
2 changes: 2 additions & 0 deletions docs/help/in/server.in
Expand Up @@ -8,6 +8,7 @@
LIST: Displays the list of servers you are connected to.
CONNECT: Connects to the given server.
ADD: Adds a server to your configuration.
MODIFY: Modifies a server in your configuration.
REMOVE: Removes a server from your configuration.
PURGE: Purges the commands queued to be sent to the server.

Expand Down Expand Up @@ -62,6 +63,7 @@
/SERVER CONNECT +chat.freenode.net
/SERVER ADD -network Freenode -noautosendcmd orwell.freenode.net
/SERVER ADD -! -auto -host staff.irssi.org -port 6667 -4 -network Freenode -noproxy orwell.freenode.net
/SERVER MODIFY -network Freenode -noauto orwell.freenode.net
/SERVER REMOVE orwell.freenode.net 6667 Freenode
/SERVER PURGE
/SERVER PURGE orwell.freenode.net
Expand Down
37 changes: 30 additions & 7 deletions src/fe-common/core/fe-channels.c
Expand Up @@ -246,9 +246,7 @@ static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
}
}

/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
<channel> <network> [<password>] */
static void cmd_channel_add(const char *data)
static void cmd_channel_add_modify(const char *data, gboolean add)
{
GHashTable *optlist;
CHATNET_REC *chatnetrec;
Expand All @@ -257,25 +255,33 @@ static void cmd_channel_add(const char *data)
void *free_arg;

if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
"channel add", &optlist, &channel, &chatnet, &password))
"channel add", &optlist, &channel, &chatnet, &password))
return;

if (*chatnet == '\0' || *channel == '\0')
if (*chatnet == '\0' || *channel == '\0') {
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
}

chatnetrec = chatnet_find(chatnet);
if (chatnetrec == NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_UNKNOWN_CHATNET, chatnet);
TXT_UNKNOWN_CHATNET, chatnet);
cmd_params_free(free_arg);
return;
return;
}

botarg = g_hash_table_lookup(optlist, "bots");
botcmdarg = g_hash_table_lookup(optlist, "botcmd");

rec = channel_setup_find(channel, chatnet);
if (rec == NULL) {
if (!add) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== FALSE

cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
return;
}

rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
rec->name = g_strdup(channel);
rec->chatnet = g_strdup(chatnet);
Expand All @@ -299,6 +305,20 @@ static void cmd_channel_add(const char *data)
cmd_params_free(free_arg);
}

/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
<channel> <network> [<password>] */
static void cmd_channel_add(const char *data)
{
cmd_channel_add_modify(data, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a TRUE/FALSE instead of 1/0 when the argument is a gboolean

}

/* SYNTAX: CHANNEL MODIFY [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
<channel> <network> [<password>] */
static void cmd_channel_modify(const char *data)
{
cmd_channel_add_modify(data, 0);
}

/* SYNTAX: CHANNEL REMOVE <channel> <network> */
static void cmd_channel_remove(const char *data)
{
Expand Down Expand Up @@ -622,12 +642,14 @@ void fe_channels_init(void)
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
command_bind("channel modify", NULL, (SIGNAL_FUNC) cmd_channel_modify);
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
command_bind("names", NULL, (SIGNAL_FUNC) cmd_names);
command_bind("cycle", NULL, (SIGNAL_FUNC) cmd_cycle);

command_set_options("channel add", "auto noauto -bots -botcmd");
command_set_options("channel modify", "auto noauto -bots -botcmd");
command_set_options("names", "count ops halfops voices normal");
command_set_options("join", "invite window");
}
Expand All @@ -643,6 +665,7 @@ void fe_channels_deinit(void)
command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
command_unbind("channel modify", (SIGNAL_FUNC) cmd_channel_modify);
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list);
command_unbind("names", (SIGNAL_FUNC) cmd_names);
Expand Down
24 changes: 22 additions & 2 deletions src/fe-common/core/fe-server.c
Expand Up @@ -104,7 +104,7 @@ static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
return server;
}

static void cmd_server_add(const char *data)
static void cmd_server_add_modify(const char *data, gboolean add)
{
GHashTable *optlist;
SERVER_SETUP_REC *rec;
Expand All @@ -113,7 +113,7 @@ static void cmd_server_add(const char *data)
int port;

if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
"server add", &optlist, &addr, &portstr, &password))
"server add", &optlist, &addr, &portstr, &password))
return;

if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
Expand All @@ -124,6 +124,13 @@ static void cmd_server_add(const char *data)
rec = server_setup_find(addr, port, chatnet);

if (rec == NULL) {
if (!add) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_SETUPSERVER_NOT_FOUND, addr, port);
return;
}

rec = create_server_setup(optlist);
if (rec == NULL) {
cmd_params_free(free_arg);
Expand Down Expand Up @@ -205,6 +212,16 @@ static void cmd_server_add(const char *data)
cmd_params_free(free_arg);
}

static void cmd_server_add(const char *data)
{
cmd_server_add_modify(data, 1);
}

static void cmd_server_modify(const char *data)
{
cmd_server_add_modify(data, 0);
}

/* SYNTAX: SERVER REMOVE <address> [<port>] [<network>] */
static void cmd_server_remove(const char *data)
{
Expand Down Expand Up @@ -388,10 +405,12 @@ void fe_server_init(void)
command_bind("server", NULL, (SIGNAL_FUNC) cmd_server);
command_bind("server connect", NULL, (SIGNAL_FUNC) cmd_server_connect);
command_bind("server add", NULL, (SIGNAL_FUNC) cmd_server_add);
command_bind("server modify", NULL, (SIGNAL_FUNC) cmd_server_modify);
command_bind("server remove", NULL, (SIGNAL_FUNC) cmd_server_remove);
command_bind_first("server", NULL, (SIGNAL_FUNC) server_command);
command_bind_first("disconnect", NULL, (SIGNAL_FUNC) server_command);
command_set_options("server add", "4 6 !! ssl +ssl_cert +ssl_pkey +ssl_pass ssl_verify +ssl_cafile +ssl_capath +ssl_ciphers auto noauto proxy noproxy -host -port noautosendcmd");
command_set_options("server modify", "4 6 !! ssl +ssl_cert +ssl_pkey +ssl_pass ssl_verify +ssl_cafile +ssl_capath +ssl_ciphers auto noauto proxy noproxy -host -port noautosendcmd");

signal_add("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_add("server connecting", (SIGNAL_FUNC) sig_server_connecting);
Expand All @@ -412,6 +431,7 @@ void fe_server_deinit(void)
command_unbind("server", (SIGNAL_FUNC) cmd_server);
command_unbind("server connect", (SIGNAL_FUNC) cmd_server_connect);
command_unbind("server add", (SIGNAL_FUNC) cmd_server_add);
command_unbind("server modify", (SIGNAL_FUNC) cmd_server_modify);
command_unbind("server remove", (SIGNAL_FUNC) cmd_server_remove);
command_unbind("server", (SIGNAL_FUNC) server_command);
command_unbind("disconnect", (SIGNAL_FUNC) server_command);
Expand Down
7 changes: 7 additions & 0 deletions src/fe-common/irc/fe-irc-server.c
Expand Up @@ -50,12 +50,19 @@ const char *get_visible_target(IRC_SERVER_REC *server, const char *target)

return target;
}

/* SYNTAX: SERVER ADD [-4 | -6] [-ssl] [-ssl_cert <cert>] [-ssl_pkey <pkey>] [-ssl_pass <password>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just recycle the existing comment block, the options that are accepted are the same for ADD and MODIFY, and that way we don't have to keep in-sync so many different versions of the same text.

[-ssl_verify] [-ssl_cafile <cafile>] [-ssl_capath <capath>]
[-ssl_ciphers <list>]
[-auto | -noauto] [-network <network>] [-host <hostname>]
[-cmdspeed <ms>] [-cmdmax <count>] [-port <port>]
<address> [<port> [<password>]] */
/* SYNTAX: SERVER MODIFY [-4 | -6] [-ssl] [-ssl_cert <cert>] [-ssl_pkey <pkey>] [-ssl_pass <password>]
[-ssl_verify] [-ssl_cafile <cafile>] [-ssl_capath <capath>]
[-ssl_ciphers <list>]
[-auto | -noauto] [-network <network>] [-host <hostname>]
[-cmdspeed <ms>] [-cmdmax <count>] [-port <port>]
<address> [<port> [<password>]] */
/* NOTE: -network replaces the old -ircnet flag. */
static void sig_server_add_fill(IRC_SERVER_SETUP_REC *rec,
GHashTable *optlist)
Expand Down
47 changes: 38 additions & 9 deletions src/fe-common/irc/fe-ircnet.c
Expand Up @@ -88,27 +88,28 @@ static void cmd_network_list(void)
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_NETWORK_FOOTER);
}

/* SYNTAX: NETWORK ADD [-nick <nick>] [-user <user>] [-realname <name>]
[-host <host>] [-usermode <mode>] [-autosendcmd <cmd>]
[-querychans <count>] [-whois <count>] [-msgs <count>]
[-kicks <count>] [-modes <count>] [-cmdspeed <ms>]
[-cmdmax <count>] [-sasl_mechanism <mechanism>]
[-sasl_username <username>] [-sasl_password <password>]
<name> */
static void cmd_network_add(const char *data)
static void cmd_network_add_modify(const char *data, gboolean add)
{
GHashTable *optlist;
char *name, *value;
void *free_arg;
IRC_CHATNET_REC *rec;

if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
"network add", &optlist, &name))
"network add", &optlist, &name))
return;

if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

rec = ircnet_find(name);
if (rec == NULL) {
if (!add) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
IRCTXT_NETWORK_NOT_FOUND, name);
return;
}

rec = g_new0(IRC_CHATNET_REC, 1);
rec->name = g_strdup(name);
} else {
Expand Down Expand Up @@ -174,6 +175,30 @@ static void cmd_network_add(const char *data)
cmd_params_free(free_arg);
}

/* SYNTAX: NETWORK ADD [-nick <nick>] [-user <user>] [-realname <name>]
[-host <host>] [-usermode <mode>] [-autosendcmd <cmd>]
[-querychans <count>] [-whois <count>] [-msgs <count>]
[-kicks <count>] [-modes <count>] [-cmdspeed <ms>]
[-cmdmax <count>] [-sasl_mechanism <mechanism>]
[-sasl_username <username>] [-sasl_password <password>]
<name> */
static void cmd_network_add(const char *data)
{
cmd_network_add_modify(data, 1);
}

/* SYNTAX: NETWORK MODIFY [-nick <nick>] [-user <user>] [-realname <name>]
[-host <host>] [-usermode <mode>] [-autosendcmd <cmd>]
[-querychans <count>] [-whois <count>] [-msgs <count>]
[-kicks <count>] [-modes <count>] [-cmdspeed <ms>]
[-cmdmax <count>] [-sasl_mechanism <mechanism>]
[-sasl_username <username>] [-sasl_password <password>]
<name> */
static void cmd_network_modify(const char *data)
{
cmd_network_add_modify(data, 0);
}

/* SYNTAX: NETWORK REMOVE <network> */
static void cmd_network_remove(const char *data)
{
Expand Down Expand Up @@ -206,10 +231,13 @@ void fe_ircnet_init(void)
command_bind("network", NULL, (SIGNAL_FUNC) cmd_network);
command_bind("network list", NULL, (SIGNAL_FUNC) cmd_network_list);
command_bind("network add", NULL, (SIGNAL_FUNC) cmd_network_add);
command_bind("network modify", NULL, (SIGNAL_FUNC) cmd_network_modify);
command_bind("network remove", NULL, (SIGNAL_FUNC) cmd_network_remove);

command_set_options("network add", "-kicks -msgs -modes -whois -cmdspeed "
"-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
command_set_options("network modify", "-kicks -msgs -modes -whois -cmdspeed "
"-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
}

void fe_ircnet_deinit(void)
Expand All @@ -218,5 +246,6 @@ void fe_ircnet_deinit(void)
command_unbind("network", (SIGNAL_FUNC) cmd_network);
command_unbind("network list", (SIGNAL_FUNC) cmd_network_list);
command_unbind("network add", (SIGNAL_FUNC) cmd_network_add);
command_unbind("network modify", (SIGNAL_FUNC) cmd_network_modify);
command_unbind("network remove", (SIGNAL_FUNC) cmd_network_remove);
}