mirror of
https://github.com/irssi/irssi.git
synced 2026-08-22 18:12:12 +02:00
refactored shared code
This commit is contained in:
parent
a7353b6b3a
commit
6a75df0b40
3 changed files with 120 additions and 179 deletions
|
|
@ -246,6 +246,23 @@ static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
|||
}
|
||||
}
|
||||
|
||||
static CHANNEL_SETUP_REC *channel_setup_fill_rec(CHANNEL_SETUP_REC *rec, GHashTable *optlist)
|
||||
{
|
||||
char *botarg, *botcmdarg;
|
||||
|
||||
g_return_if_fail(rec != NULL);
|
||||
|
||||
botarg = g_hash_table_lookup(optlist, "bots");
|
||||
botcmdarg = g_hash_table_lookup(optlist, "botcmd");
|
||||
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
|
||||
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
|
||||
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
|
||||
<channel> <network> [<password>] */
|
||||
static void cmd_channel_add(const char *data)
|
||||
|
|
@ -253,7 +270,7 @@ static void cmd_channel_add(const char *data)
|
|||
GHashTable *optlist;
|
||||
CHATNET_REC *chatnetrec;
|
||||
CHANNEL_SETUP_REC *rec;
|
||||
char *botarg, *botcmdarg, *chatnet, *channel, *password;
|
||||
char *chatnet, *channel, *password;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
|
|
@ -271,9 +288,6 @@ static void cmd_channel_add(const char *data)
|
|||
return;
|
||||
}
|
||||
|
||||
botarg = g_hash_table_lookup(optlist, "bots");
|
||||
botcmdarg = g_hash_table_lookup(optlist, "botcmd");
|
||||
|
||||
rec = channel_setup_find(channel, chatnet);
|
||||
if (rec == NULL) {
|
||||
rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
|
||||
|
|
@ -284,12 +298,11 @@ static void cmd_channel_add(const char *data)
|
|||
if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
|
||||
if (*password != '\0') g_free_and_null(rec->password);
|
||||
}
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
|
||||
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
|
||||
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
|
||||
|
||||
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
|
||||
|
||||
rec = channel_setup_fill_rec(rec, optlist);
|
||||
|
||||
channel_setup_create(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_CHANSETUP_ADDED, channel, chatnet);
|
||||
|
|
@ -304,7 +317,7 @@ static void cmd_channel_modify(const char *data)
|
|||
GHashTable *optlist;
|
||||
CHATNET_REC *chatnetrec;
|
||||
CHANNEL_SETUP_REC *rec;
|
||||
char *botarg, *botcmdarg, *chatnet, *channel, *password;
|
||||
char *chatnet, *channel, *password;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
|
|
@ -322,9 +335,6 @@ static void cmd_channel_modify(const char *data)
|
|||
return;
|
||||
}
|
||||
|
||||
botarg = g_hash_table_lookup(optlist, "bots");
|
||||
botcmdarg = g_hash_table_lookup(optlist, "botcmd");
|
||||
|
||||
rec = channel_setup_find(channel, chatnet);
|
||||
if (rec == NULL) {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
|
||||
|
|
@ -332,12 +342,10 @@ static void cmd_channel_modify(const char *data)
|
|||
if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
|
||||
if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
|
||||
if (*password != '\0') g_free_and_null(rec->password);
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
|
||||
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
|
||||
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
|
||||
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
|
||||
|
||||
rec = channel_setup_fill_rec(rec, optlist);
|
||||
|
||||
channel_setup_create(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_CHANSETUP_MODIFIED, channel, chatnet);
|
||||
|
|
|
|||
|
|
@ -104,43 +104,11 @@ static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
|
|||
return server;
|
||||
}
|
||||
|
||||
static void cmd_server_add(const char *data)
|
||||
|
||||
static SERVER_SETUP_REC *server_setup_fill_rec(SERVER_SETUP_REC *rec, GHashTable *optlist)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
SERVER_SETUP_REC *rec;
|
||||
char *addr, *portstr, *password, *value, *chatnet;
|
||||
void *free_arg;
|
||||
int port;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
"server add", &optlist, &addr, &portstr, &password))
|
||||
return;
|
||||
|
||||
if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
port = *portstr == '\0' ? DEFAULT_SERVER_ADD_PORT : atoi(portstr);
|
||||
|
||||
chatnet = g_hash_table_lookup(optlist, "network");
|
||||
|
||||
rec = server_setup_find(addr, port, chatnet);
|
||||
|
||||
if (rec == NULL) {
|
||||
rec = create_server_setup(optlist);
|
||||
if (rec == NULL) {
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
rec->address = g_strdup(addr);
|
||||
rec->port = port;
|
||||
} else {
|
||||
value = g_hash_table_lookup(optlist, "port");
|
||||
if (value != NULL && *value != '\0') rec->port = atoi(value);
|
||||
|
||||
if (*password != '\0') g_free_and_null(rec->password);
|
||||
if (g_hash_table_lookup(optlist, "host")) {
|
||||
g_free_and_null(rec->own_host);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
}
|
||||
g_return_if_fail(rec != NULL);
|
||||
char *value;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "6"))
|
||||
rec->family = AF_INET6;
|
||||
|
|
@ -189,13 +157,57 @@ static void cmd_server_add(const char *data)
|
|||
if (g_hash_table_lookup(optlist, "proxy")) rec->no_proxy = FALSE;
|
||||
if (g_hash_table_lookup(optlist, "noproxy")) rec->no_proxy = TRUE;
|
||||
|
||||
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
|
||||
value = g_hash_table_lookup(optlist, "host");
|
||||
if (value != NULL && *value != '\0') {
|
||||
rec->own_host = g_strdup(value);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
static void cmd_server_add(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
SERVER_SETUP_REC *rec;
|
||||
char *addr, *portstr, *password, *value, *chatnet;
|
||||
void *free_arg;
|
||||
int port;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
"server add", &optlist, &addr, &portstr, &password))
|
||||
return;
|
||||
|
||||
if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
port = *portstr == '\0' ? DEFAULT_SERVER_ADD_PORT : atoi(portstr);
|
||||
|
||||
chatnet = g_hash_table_lookup(optlist, "network");
|
||||
|
||||
rec = server_setup_find(addr, port, chatnet);
|
||||
|
||||
if (rec == NULL) {
|
||||
rec = create_server_setup(optlist);
|
||||
if (rec == NULL) {
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
rec->address = g_strdup(addr);
|
||||
rec->port = port;
|
||||
} else {
|
||||
value = g_hash_table_lookup(optlist, "port");
|
||||
if (value != NULL && *value != '\0') rec->port = atoi(value);
|
||||
|
||||
if (*password != '\0') g_free_and_null(rec->password);
|
||||
if (g_hash_table_lookup(optlist, "host")) {
|
||||
g_free_and_null(rec->own_host);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
|
||||
|
||||
rec = server_setup_fill_rec(rec, optlist);
|
||||
|
||||
signal_emit("server add fill", 2, rec, optlist);
|
||||
|
||||
server_setup_add(rec);
|
||||
|
|
@ -236,59 +248,9 @@ static void cmd_server_modify(const char *data)
|
|||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "6"))
|
||||
rec->family = AF_INET6;
|
||||
else if (g_hash_table_lookup(optlist, "4"))
|
||||
rec->family = AF_INET;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "ssl"))
|
||||
rec->use_ssl = TRUE;
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_cert");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_cert = g_strdup(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_pkey");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_pkey = g_strdup(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_pass");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_pass = g_strdup(value);
|
||||
|
||||
if (g_hash_table_lookup(optlist, "ssl_verify"))
|
||||
rec->ssl_verify = TRUE;
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_cafile");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_cafile = g_strdup(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_capath");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_capath = g_strdup(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "ssl_ciphers");
|
||||
if (value != NULL && *value != '\0')
|
||||
rec->ssl_ciphers = g_strdup(value);
|
||||
|
||||
if ((rec->ssl_cafile != NULL && rec->ssl_cafile[0] != '\0')
|
||||
|| (rec->ssl_capath != NULL && rec->ssl_capath[0] != '\0'))
|
||||
rec->ssl_verify = TRUE;
|
||||
|
||||
if ((rec->ssl_cert != NULL && rec->ssl_cert[0] != '\0') || rec->ssl_verify == TRUE)
|
||||
rec->use_ssl = TRUE;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autoconnect = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autoconnect = FALSE;
|
||||
if (g_hash_table_lookup(optlist, "proxy")) rec->no_proxy = FALSE;
|
||||
if (g_hash_table_lookup(optlist, "noproxy")) rec->no_proxy = TRUE;
|
||||
|
||||
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
|
||||
value = g_hash_table_lookup(optlist, "host");
|
||||
if (value != NULL && *value != '\0') {
|
||||
rec->own_host = g_strdup(value);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
|
||||
rec = server_setup_fill_rec(rec, optlist);
|
||||
|
||||
signal_emit("server modify fill", 2, rec, optlist);
|
||||
|
||||
|
|
|
|||
|
|
@ -88,43 +88,11 @@ 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 IRC_CHATNET_REC *network_setup_fill_rec(IRC_CHATNET_REC *rec, GHashTable *optlist)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *name, *value;
|
||||
void *free_arg;
|
||||
IRC_CHATNET_REC *rec;
|
||||
char *value;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
|
||||
"network add", &optlist, &name))
|
||||
return;
|
||||
if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
rec = ircnet_find(name);
|
||||
if (rec == NULL) {
|
||||
rec = g_new0(IRC_CHATNET_REC, 1);
|
||||
rec->name = g_strdup(name);
|
||||
} else {
|
||||
if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
|
||||
if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
|
||||
if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
|
||||
if (g_hash_table_lookup(optlist, "host")) {
|
||||
g_free_and_null(rec->own_host);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
if (g_hash_table_lookup(optlist, "usermode")) g_free_and_null(rec->usermode);
|
||||
if (g_hash_table_lookup(optlist, "autosendcmd")) g_free_and_null(rec->autosendcmd);
|
||||
if (g_hash_table_lookup(optlist, "sasl_mechanism")) g_free_and_null(rec->sasl_mechanism);
|
||||
if (g_hash_table_lookup(optlist, "sasl_username")) g_free_and_null(rec->sasl_username);
|
||||
if (g_hash_table_lookup(optlist, "sasl_password")) g_free_and_null(rec->sasl_password);
|
||||
}
|
||||
g_return_if_fail(rec != NULL);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "kicks");
|
||||
if (value != NULL) rec->max_kicks = atoi(value);
|
||||
|
|
@ -168,6 +136,49 @@ static void cmd_network_add(const char *data)
|
|||
value = g_hash_table_lookup(optlist, "sasl_password");
|
||||
if (value != NULL && *value != '\0') rec->sasl_password = g_strdup(value);
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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))
|
||||
return;
|
||||
if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
rec = ircnet_find(name);
|
||||
if (rec == NULL) {
|
||||
rec = g_new0(IRC_CHATNET_REC, 1);
|
||||
rec->name = g_strdup(name);
|
||||
} else {
|
||||
if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
|
||||
if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
|
||||
if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
|
||||
if (g_hash_table_lookup(optlist, "host")) {
|
||||
g_free_and_null(rec->own_host);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
if (g_hash_table_lookup(optlist, "usermode")) g_free_and_null(rec->usermode);
|
||||
if (g_hash_table_lookup(optlist, "autosendcmd")) g_free_and_null(rec->autosendcmd);
|
||||
if (g_hash_table_lookup(optlist, "sasl_mechanism")) g_free_and_null(rec->sasl_mechanism);
|
||||
if (g_hash_table_lookup(optlist, "sasl_username")) g_free_and_null(rec->sasl_username);
|
||||
if (g_hash_table_lookup(optlist, "sasl_password")) g_free_and_null(rec->sasl_password);
|
||||
}
|
||||
|
||||
rec = network_setup_fill_rec(rec, optlist);
|
||||
|
||||
ircnet_create(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NETWORK_ADDED, name);
|
||||
|
||||
|
|
@ -210,47 +221,7 @@ static void cmd_network_modify(const char *data)
|
|||
if (g_hash_table_lookup(optlist, "sasl_username")) g_free_and_null(rec->sasl_username);
|
||||
if (g_hash_table_lookup(optlist, "sasl_password")) g_free_and_null(rec->sasl_password);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "kicks");
|
||||
if (value != NULL) rec->max_kicks = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "msgs");
|
||||
if (value != NULL) rec->max_msgs = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "modes");
|
||||
if (value != NULL) rec->max_modes = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "whois");
|
||||
if (value != NULL) rec->max_whois = atoi(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "cmdspeed");
|
||||
if (value != NULL) rec->cmd_queue_speed = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "cmdmax");
|
||||
if (value != NULL) rec->max_cmds_at_once = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "querychans");
|
||||
if (value != NULL) rec->max_query_chans = atoi(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "nick");
|
||||
if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
|
||||
value = g_hash_table_lookup(optlist, "user");
|
||||
if (value != NULL && *value != '\0') rec->username = g_strdup(value);
|
||||
value = g_hash_table_lookup(optlist, "realname");
|
||||
if (value != NULL && *value != '\0') rec->realname = g_strdup(value);
|
||||
|
||||
value = g_hash_table_lookup(optlist, "host");
|
||||
if (value != NULL && *value != '\0') {
|
||||
rec->own_host = g_strdup(value);
|
||||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup(optlist, "usermode");
|
||||
if (value != NULL && *value != '\0') rec->usermode = g_strdup(value);
|
||||
value = g_hash_table_lookup(optlist, "autosendcmd");
|
||||
if (value != NULL && *value != '\0') rec->autosendcmd = g_strdup(value);
|
||||
|
||||
/* the validity of the parameters is checked in sig_server_setup_fill_chatnet */
|
||||
value = g_hash_table_lookup(optlist, "sasl_mechanism");
|
||||
if (value != NULL && *value != '\0') rec->sasl_mechanism = g_strdup(value);
|
||||
value = g_hash_table_lookup(optlist, "sasl_username");
|
||||
if (value != NULL && *value != '\0') rec->sasl_username = g_strdup(value);
|
||||
value = g_hash_table_lookup(optlist, "sasl_password");
|
||||
if (value != NULL && *value != '\0') rec->sasl_password = g_strdup(value);
|
||||
rec = network_setup_fill_rec(rec, optlist);
|
||||
|
||||
ircnet_create(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NETWORK_MODIFIED, name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue