summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/bot/botnet-connection.c8
-rw-r--r--src/irc/bot/botnet-users.c49
-rw-r--r--src/irc/bot/botnet.c22
-rw-r--r--src/irc/core/bans.c9
-rw-r--r--src/irc/core/channels-query.c4
-rw-r--r--src/irc/core/channels.c8
-rw-r--r--src/irc/core/irc-commands.c253
-rw-r--r--src/irc/core/irc-special-vars.c8
-rw-r--r--src/irc/core/ircnet-setup.c4
-rw-r--r--src/irc/core/modes.c11
-rw-r--r--src/irc/core/netsplit.c9
-rw-r--r--src/irc/dcc/dcc-chat.c28
-rw-r--r--src/irc/dcc/dcc-files.c40
-rw-r--r--src/irc/dcc/dcc.c28
-rw-r--r--src/irc/notifylist/notify-commands.c26
15 files changed, 319 insertions, 188 deletions
diff --git a/src/irc/bot/botnet-connection.c b/src/irc/bot/botnet-connection.c
index 387cce45..988a9b5c 100644
--- a/src/irc/bot/botnet-connection.c
+++ b/src/irc/bot/botnet-connection.c
@@ -480,14 +480,16 @@ static BOT_REC *bot_add(BOTNET_REC *botnet, const char *nick, const char *parent
static void botnet_event_botinfo(BOT_REC *bot, const char *data, const char *sender)
{
- char *params, *nick, *parent, *priority;
+ char *nick, *parent, *priority;
+ void *free_arg;
BOT_REC *rec;
/*str = g_strdup_printf("BOTINFO %s", data);
botnet_broadcast(bot->botnet, bot, sender, str);
g_free(str);*/
- params = cmd_get_params(data, 3, &nick, &parent, &priority);
+ if (!cmd_get_params(data, &free_arg, 3, &nick, &parent, &priority))
+ return;
if (*parent == '-' && parent[1] == '\0')
parent = NULL;
@@ -503,7 +505,7 @@ static void botnet_event_botinfo(BOT_REC *bot, const char *data, const char *sen
if (rec != NULL) {
rec->priority = atoi(priority);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_botquit(BOT_REC *bot, const char *data)
diff --git a/src/irc/bot/botnet-users.c b/src/irc/bot/botnet-users.c
index fda58723..3b366ac6 100644
--- a/src/irc/bot/botnet-users.c
+++ b/src/irc/bot/botnet-users.c
@@ -108,81 +108,94 @@ void botcmd_user_set_password(USER_REC *user, const char *password)
static void botnet_event_user_add(BOT_REC *bot, const char *data, const char *sender)
{
- char *params, *nick;
+ char *nick;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 1, &nick))
+ return;
- params = cmd_get_params(data, 1, &nick);
botuser_add(nick);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_user_flags(BOT_REC *bot, const char *data, const char *sender)
{
USER_REC *user;
- char *params, *nick, *flags;
+ char *nick, *flags;
+ void *free_arg;
- params = cmd_get_params(data, 2, &nick, &flags);
+ if (!cmd_get_params(data, &free_arg, 2, &nick, &flags))
+ return;
user = botuser_find(nick, NULL);
if (user == NULL) user = botuser_add(nick);
botuser_set_flags(user, botuser_flags2value(flags));
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_user_chan_flags(BOT_REC *bot, const char *data, const char *sender)
{
USER_REC *user;
- char *params, *nick, *channel, *flags;
+ char *nick, *channel, *flags;
+ void *free_arg;
- params = cmd_get_params(data, 3, &nick, &channel, &flags);
+ if (!cmd_get_params(data, &free_arg, 3, &nick, &channel, &flags))
+ return;
user = botuser_find(nick, NULL);
if (user == NULL) user = botuser_add(nick);
botuser_set_channel_flags(user, channel, botuser_flags2value(flags));
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_user_add_mask(BOT_REC *bot, const char *data, const char *sender)
{
USER_REC *user;
- char *params, *nick, *mask;
+ char *nick, *mask;
+ void *free_arg;
- params = cmd_get_params(data, 2, &nick, &mask);
+ if (!cmd_get_params(data, &free_arg, 2, &nick, &mask))
+ return;
user = botuser_find(nick, NULL);
if (user == NULL) user = botuser_add(nick);
botuser_add_mask(user, mask);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_user_mask_notflags(BOT_REC *bot, const char *data, const char *sender)
{
USER_REC *user;
- char *params, *nick, *mask, *not_flags;
+ char *nick, *mask, *not_flags;
+ void *free_arg;
- params = cmd_get_params(data, 3, &nick, &mask, &not_flags);
+ if (!cmd_get_params(data, &free_arg, 3, &nick, &mask, &not_flags))
+ return;
user = botuser_find(nick, NULL);
if (user == NULL) user = botuser_add(nick);
botuser_set_mask_notflags(user, mask, botuser_flags2value(not_flags));
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_user_pass(BOT_REC *bot, const char *data, const char *sender)
{
USER_REC *user;
- char *params, *nick, *pass;
+ char *nick, *pass;
+ void *free_arg;
- params = cmd_get_params(data, 2, &nick, &pass);
+ if (!cmd_get_params(data, &free_arg, 2, &nick, &pass))
+ return;
user = botuser_find(nick, NULL);
if (user == NULL) user = botuser_add(nick);
botuser_set_password(user, pass);
- g_free(params);
+ cmd_params_free(free_arg);
}
void botnet_users_init(void)
diff --git a/src/irc/bot/botnet.c b/src/irc/bot/botnet.c
index 4f74a867..190481d1 100644
--- a/src/irc/bot/botnet.c
+++ b/src/irc/bot/botnet.c
@@ -508,13 +508,15 @@ static void botnet_destroy(BOTNET_REC *botnet)
static void botnet_event(BOT_REC *bot, const char *data)
{
- char *params, *source, *target, *command, *args, *event;
+ char *source, *target, *command, *args, *event;
+ void *free_arg;
if (!bot->connected)
return;
- params = cmd_get_params(data, 4 | PARAM_FLAG_GETREST,
- &source, &target, &command, &args);
+ if (!cmd_get_params(data, &free_arg, 4 | PARAM_FLAG_GETREST,
+ &source, &target, &command, &args))
+ return;
if (*target == '-' && target[1] == '\0')
target = NULL;
@@ -524,23 +526,25 @@ static void botnet_event(BOT_REC *bot, const char *data)
signal_emit(event, 4, bot, args, source, target);
g_free(event);
- g_free(params);
+ cmd_params_free(free_arg);
}
/* broadcast the signal forward */
static void botnet_event_broadcast(BOT_REC *bot, const char *data)
{
- char *params, *source, *target, *command;
+ char *source, *target, *command;
+ void *free_arg;
if (!bot->connected)
return;
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST,
- &source, &target, &command);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
+ &source, &target, &command))
+ return;
if (g_strcasecmp(target, bot->botnet->nick) == 0) {
/* message was for us */
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -552,7 +556,7 @@ static void botnet_event_broadcast(BOT_REC *bot, const char *data)
botnet_send_cmd(bot->botnet, source, target, command);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void botnet_event_master(BOT_REC *bot, const char *data, const char *sender)
diff --git a/src/irc/core/bans.c b/src/irc/core/bans.c
index 774587cf..914fad65 100644
--- a/src/irc/core/bans.c
+++ b/src/irc/core/bans.c
@@ -167,14 +167,15 @@ void ban_remove(CHANNEL_REC *channel, const char *bans)
static void command_set_ban(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item, int set)
{
CHANNEL_REC *chanrec;
- char *params, *channel, *nicks;
+ char *channel, *nicks;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
- item, &channel, &nicks);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
+ item, &channel, &nicks)) return;
if (!ischannel(*channel)) cmd_param_error(CMDERR_NOT_JOINED);
if (*nicks == '\0') {
if (strcmp(data, "*") != 0)
@@ -192,7 +193,7 @@ static void command_set_ban(const char *data, IRC_SERVER_REC *server, WI_IRC_REC
else
ban_remove(chanrec, nicks);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_bantype(const char *data)
diff --git a/src/irc/core/channels-query.c b/src/irc/core/channels-query.c
index 0876f0bd..95ab9ecd 100644
--- a/src/irc/core/channels-query.c
+++ b/src/irc/core/channels-query.c
@@ -181,8 +181,8 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
chans = rec->queries[query];
- chanstr_commas = gslist_to_string(rec->queries[query], G_STRUCT_OFFSET(CHANNEL_REC, name), ",");
- chanstr_spaces = gslist_to_string(rec->queries[query], G_STRUCT_OFFSET(CHANNEL_REC, name), " ");
+ chanstr_commas = gslistptr_to_string(rec->queries[query], G_STRUCT_OFFSET(CHANNEL_REC, name), ",");
+ chanstr_spaces = gslistptr_to_string(rec->queries[query], G_STRUCT_OFFSET(CHANNEL_REC, name), " ");
chanstr = g_strconcat(chanstr_commas, " ", chanstr_spaces, NULL);
g_free(chanstr_spaces);
diff --git a/src/irc/core/channels.c b/src/irc/core/channels.c
index 6943952e..1048b202 100644
--- a/src/irc/core/channels.c
+++ b/src/irc/core/channels.c
@@ -162,15 +162,17 @@ void channels_join(IRC_SERVER_REC *server, const char *data, int automatic)
SETUP_CHANNEL_REC *schannel;
CHANNEL_REC *chanrec;
GString *outchans, *outkeys;
- char *params, *channels, *keys, *key;
+ char *channels, *keys, *key;
char **chanlist, **keylist, **tmp, **tmpkey, *channel;
+ void *free_arg;
int use_keys;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &channels, &keys);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &channels, &keys))
+ return;
if (*channels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanlist = g_strsplit(channels, ",", -1);
@@ -221,7 +223,7 @@ void channels_join(IRC_SERVER_REC *server, const char *data, int automatic)
g_strfreev(chanlist);
g_strfreev(keylist);
- g_free(params);
+ cmd_params_free(free_arg);
}
void channels_init(void)
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index a344931b..edc0dd7e 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -49,27 +49,34 @@ static IRC_SERVER_REC *connect_server(const char *data)
{
IRC_SERVER_CONNECT_REC *conn;
IRC_SERVER_REC *server;
- char *params, *args, *ircnet, *host, *addr, *portstr, *password, *nick;
+ GHashTable *optlist;
+ char *addr, *portstr, *password, *nick, *ircnet, *host;
+ void *free_arg;
g_return_val_if_fail(data != NULL, NULL);
- args = "ircnet host";
- params = cmd_get_params(data, 7 | PARAM_FLAG_MULTIARGS,
- &args, &ircnet, &host, &addr,
- &portstr, &password, &nick);
+ if (!cmd_get_params(data, &free_arg, 4 | PARAM_FLAG_OPTIONS,
+ "connect", &optlist, &addr, &portstr, &password, &nick))
+ return NULL;
if (*addr == '+') addr++;
- if (*addr == '\0') return NULL;
+ if (*addr == '\0') {
+ signal_emit("error command", 1, GINT_TO_POINTER(CMDERR_NOT_ENOUGH_PARAMS));
+ cmd_params_free(free_arg);
+ return NULL;
+ }
if (strcmp(password, "-") == 0)
*password = '\0';
/* connect to server */
conn = irc_server_create_conn(addr, atoi(portstr), password, nick);
- if (*ircnet != '\0') {
+ ircnet = g_hash_table_lookup(optlist, "ircnet");
+ if (ircnet != NULL && *ircnet != '\0') {
g_free_not_null(conn->ircnet);
conn->ircnet = g_strdup(ircnet);
}
- if (*host != '\0') {
+ host = g_hash_table_lookup(optlist, "host");
+ if (host != NULL && *host != '\0') {
IPADDR ip;
if (net_gethostbyname(host, &ip) == 0) {
@@ -80,7 +87,7 @@ static IRC_SERVER_REC *connect_server(const char *data)
}
server = irc_server_connect(conn);
- g_free(params);
+ cmd_params_free(free_arg);
return server;
}
@@ -93,14 +100,16 @@ static void cmd_connect(const char *data)
static void cmd_disconnect(const char *data, IRC_SERVER_REC *server)
{
IRC_SERVER_REC *ircserver;
- char *params, *tag, *msg;
+ char *tag, *msg;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (g_strncasecmp(data, "RECON-", 6) == 0)
return; /* remove reconnection, handle in server-reconnect.c */
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &tag, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
+ return;
if (*tag != '\0' && strcmp(tag, "*") != 0)
server = (IRC_SERVER_REC *) server_find_tag(tag);
@@ -120,22 +129,24 @@ static void cmd_disconnect(const char *data, IRC_SERVER_REC *server)
irc_send_cmdv(ircserver, "QUIT :%s", msg);
}
- g_free(params);
+ cmd_params_free(free_arg);
server_disconnect((SERVER_REC *) server);
}
static void cmd_server(const char *data, IRC_SERVER_REC *server)
{
- char *params, *args, *ircnetarg, *hostarg, *addr;
- char *channels, *away_reason, *usermode, *ircnet;
+ GHashTable *optlist;
+ char *addr, *channels, *away_reason, *usermode, *ircnet;
+ void *free_arg;
int no_old_server;
g_return_if_fail(data != NULL);
- args = "ircnet host";
- params = cmd_get_params(data, 4 | PARAM_FLAG_MULTIARGS,
- &args, &ircnetarg, &hostarg, &addr);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
+ "connect", &optlist, &addr))
+ return;
+
if (*addr == '\0' || strcmp(addr, "+") == 0)
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
@@ -167,7 +178,7 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server)
server->connrec->away_reason = away_reason;
}
g_free_not_null(ircnet);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_quit(const char *data)
@@ -195,12 +206,14 @@ static void cmd_quit(const char *data)
static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *target, *msg;
+ char *target, *msg;
+ void *free_arg;
int free_ret;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &msg))
+ return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (server == NULL || !server->connected || !irc_server_check(server))
@@ -219,35 +232,39 @@ static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
if (free_ret && target != NULL) g_free(target);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_notice(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *msg;
+ char *target, *msg;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &msg))
+ return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
g_string_sprintf(tmpstr, "NOTICE %s :%s", target, msg);
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *ctcpcmd, *ctcpdata;
+ char *target, *ctcpcmd, *ctcpdata;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata))
+ return;
if (*target == '\0' || *ctcpcmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
g_strup(ctcpcmd);
@@ -257,61 +274,79 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
g_string_sprintf(tmpstr, "PRIVMSG %s :\001%s %s\001", target, ctcpcmd, ctcpdata);
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_nctcp(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *ctcpcmd, *ctcpdata;
+ char *target, *ctcpcmd, *ctcpdata;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata))
+ return;
if (*target == '\0' || *ctcpcmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
g_strup(ctcpcmd);
g_string_sprintf(tmpstr, "NOTICE %s :\001%s %s\001", target, ctcpcmd, ctcpdata);
irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_join(const char *data, IRC_SERVER_REC *server)
{
- char *params, *args, *channels;
+ GHashTable *optlist;
+ GSList *list;
+ char *channels;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTARGS | PARAM_FLAG_GETREST, &args, &channels);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS |
+ PARAM_FLAG_GETREST, "join", &optlist, &channels))
+ return;
- if (stristr(args, "-invite")) {
+ if (g_hash_table_lookup(optlist, "-invite")) {
if (server->last_invite != NULL)
channels_join(server, server->last_invite, FALSE);
} else {
- if (*args != '\0') {
- server = (IRC_SERVER_REC *) server_find_tag(args+1);
- if (server == NULL) cmd_param_error(CMDERR_NOT_CONNECTED);
+ /* -<server tag> */
+ list = hashtable_get_keys(optlist);
+ if (list != NULL) {
+ server = (IRC_SERVER_REC *) server_find_tag(list->data);
+
+ if (server == NULL) {
+ /* unknown option (not server tag) */
+ signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), list->data);
+ signal_stop();
+ }
+ g_slist_free(list);
}
- channels_join(server, channels, FALSE);
+
+ if (server != NULL) channels_join(server, channels, FALSE);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_part(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *channame, *msg;
CHANNEL_REC *chanrec;
+ char *channame, *msg;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST, item, &channame, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST, item, &channame, &msg))
+ return;
if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanrec = channel_find(server, channame);
@@ -320,19 +355,21 @@ static void cmd_part(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
irc_send_cmdv(server, *msg == '\0' ? "PART %s" : "PART %s :%s",
channame, msg);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_kick(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *channame, *nicks, *reason;
+ char *channame, *nicks, *reason;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
- item, &channame, &nicks, &reason);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
+ item, &channame, &nicks, &reason))
+ return;
if (*channame == '\0' || *nicks == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (!ischannel(*channame)) cmd_param_error(CMDERR_NOT_JOINED);
@@ -340,36 +377,42 @@ static void cmd_kick(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
g_string_sprintf(tmpstr, "KICK %s %s :%s", channame, nicks, reason);
irc_send_cmd_split(server, tmpstr->str, 3, server->max_kicks_in_cmd);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_topic(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *args, *channame, *topic;
+ GHashTable *optlist;
+ char *channame, *topic;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_OPTCHAN |
- PARAM_FLAG_OPTARGS | PARAM_FLAG_GETREST,
- item, &args, &channame, &topic);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTCHAN |
+ PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
+ item, "topic", &optlist, &channame, &topic))
+ return;
- irc_send_cmdv(server, *topic == '\0' && strstr(args, "-d") == NULL ?
+ irc_send_cmdv(server, *topic == '\0' && g_hash_table_lookup(optlist, "-d") == NULL ?
"TOPIC %s" : "TOPIC %s :%s", channame, topic);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_invite(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *nick, *channame;
+ char *nick, *channame;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2, &nick, &channame);
+ if (!cmd_get_params(data, &free_arg, 2, &nick, &channame))
+ return;
+
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (*channame == '\0' || strcmp(channame, "*") == 0) {
if (!irc_item_channel(item))
@@ -379,24 +422,28 @@ static void cmd_invite(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *ite
}
irc_send_cmdv(server, "INVITE %s %s", nick, channame);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_list(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *args, *str;
+ GHashTable *optlist;
+ char *str;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTARGS | PARAM_FLAG_GETREST, &args, &str);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_GETREST, &optlist, &str))
+ return;
- if (*str == '\0' && stristr(args, "-yes") == NULL)
+ if (*str == '\0' && g_hash_table_lookup(optlist, "-yes") == NULL)
cmd_param_error(CMDERR_NOT_GOOD_IDEA);
irc_send_cmdv(server, "LIST %s", str);
- g_free(params);
+ cmd_params_free(free_arg);
/* add default redirection */
server_redirect_default((SERVER_REC *) server, "bogus command list");
@@ -404,13 +451,15 @@ static void cmd_list(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
static void cmd_who(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *channel, *args, *rest;
+ char *channel, *rest;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_OPTARGS | PARAM_FLAG_GETREST, &args, &channel, &rest);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &channel, &rest))
+ return;
if (strcmp(channel, "*") == 0 || *channel == '\0') {
if (!irc_item_channel(item))
@@ -425,7 +474,7 @@ static void cmd_who(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
irc_send_cmdv(server, *rest == '\0' ? "WHO %s" : "WHO %s %s",
channel, rest);
- g_free(params);
+ cmd_params_free(free_arg);
/* add default redirection */
server_redirect_default((SERVER_REC *) server, "bogus command who");
@@ -473,17 +522,20 @@ static char *get_redirect_nicklist(const char *nicks, int *free)
static void cmd_whois(const char *data, IRC_SERVER_REC *server)
{
- char *params, *qserver, *query;
+ char *qserver, *query;
+ void *free_arg;
int free_nick;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2, &qserver, &query);
+ if (!cmd_get_params(data, &free_arg, 2, &qserver, &query))
+ return;
+
if (*query == '\0') {
- g_free(params);
- params = cmd_get_params(data, 1, &query);
+ cmd_params_free(free_arg);
+ if (!cmd_get_params(data, &free_arg, 1, &query)) return;
qserver = "";
}
if (*query == '\0') query = server->nick;
@@ -505,7 +557,7 @@ static void cmd_whois(const char *data, IRC_SERVER_REC *server)
"event 311", "whois event", 1,
"event 401", "whois not found", 1, NULL);
if (free_nick) g_free(query);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void event_whois(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
@@ -539,14 +591,16 @@ static void event_whowas(const char *data, IRC_SERVER_REC *server, const char *n
static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
{
- char *params, *nicks, *count;
+ char *nicks, *count;
+ void *free_arg;
int free_nick;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2, &nicks, &count);
+ if (!cmd_get_params(data, &free_arg, 2, &nicks, &count))
+ return;
if (*nicks == '\0') nicks = server->nick;
server->whowas_found = FALSE;
@@ -558,7 +612,7 @@ static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
"event 369", "event 369", 1,
"event 314", "whowas event", 1, NULL);
if (free_nick) g_free(nicks);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
@@ -594,20 +648,23 @@ static void server_send_away(IRC_SERVER_REC *server, const char *reason)
static void cmd_away(const char *data, IRC_SERVER_REC *server)
{
- char *params, *args, *reason;
+ GHashTable *optlist;
+ char *reason;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTARGS | PARAM_FLAG_GETREST, &args, &reason);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_GETREST, "away", &optlist, &reason)) return;
- if (stristr(args, "-one"))
+ if (g_hash_table_lookup(optlist, "-one") != NULL)
server_send_away(server, reason);
else
g_slist_foreach(servers, (GFunc) server_send_away, reason);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_deop(const char *data, IRC_SERVER_REC *server)
@@ -646,7 +703,8 @@ static void cmd_wall_hash(gpointer key, NICK_REC *nick, GSList **nicks)
static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *channame, *msg, *args;
+ char *channame, *msg, *args;
+ void *free_arg;
CHANNEL_REC *chanrec;
GSList *tmp, *nicks;
@@ -654,7 +712,9 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST, item, &channame, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN |
+ PARAM_FLAG_GETREST, item, &channame, &msg))
+ return;
if (*msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanrec = channel_find(server, channame);
@@ -677,19 +737,21 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
g_free(msg);
g_slist_free(nicks);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_cycle(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *channame, *msg;
CHANNEL_REC *chanrec;
+ char *channame, *msg;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_OPTCHAN, item, &channame, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN, item, &channame, &msg))
+ return;
if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanrec = channel_find(server, channame);
@@ -700,21 +762,23 @@ static void cmd_cycle(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
irc_send_cmdv(server, chanrec->key == NULL ? "JOIN %s" : "JOIN %s %s",
channame, chanrec->key);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_kickban(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *nick;
+ char *nick;
+ void *free_arg;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 1, &nick);
+ if (!cmd_get_params(data, &free_arg, 1, &nick))
+ return;
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
signal_emit("command ban", 3, nick, server, item);
signal_emit("command kick", 3, data, server, item);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void knockout_destroy(IRC_SERVER_REC *server, KNOCKOUT_REC *rec)
@@ -760,7 +824,8 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
{
KNOCKOUT_REC *rec;
CHANNEL_REC *channel;
- char *params, *nick, *reason, *timeoutstr, *str;
+ char *nick, *reason, *timeoutstr, *str;
+ void *free_arg;
int timeleft;
g_return_if_fail(data != NULL);
@@ -771,11 +836,13 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
if (is_numeric(data, ' ')) {
/* first argument is the timeout */
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nick, &reason);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nick, &reason))
+ return;
timeleft = atoi(timeoutstr);
} else {
timeleft = 0;
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &nick, &reason);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &reason))
+ return;
}
if (timeleft == 0) timeleft = settings_get_int("knockout_time");
@@ -795,7 +862,7 @@ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
server->knockoutlist = g_slist_append(server->knockoutlist, rec);
- g_free(params);
+ cmd_params_free(free_arg);
}
/* destroy all knockouts in server */
@@ -845,16 +912,18 @@ static void command_1self(const char *data, IRC_SERVER_REC *server)
static void command_2self(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *text;
+ char *target, *text;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &text);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &text))
+ return;
if (*target == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
irc_send_cmdv(server, "%s %s :%s", current_command, target, text);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void sig_connected(IRC_SERVER_REC *server)
@@ -942,6 +1011,12 @@ void irc_commands_init(void)
signal_add("whois not found", (SIGNAL_FUNC) sig_whois_not_found);
signal_add("whois event", (SIGNAL_FUNC) event_whois);
signal_add("whowas event", (SIGNAL_FUNC) event_whowas);
+
+ command_set_options("connect", "+ircnet +host");
+ command_set_options("topic", "d");
+ command_set_options("list", "yes");
+ command_set_options("away", "one all");
+ command_set_options("join", "invite");
}
void irc_commands_deinit(void)
diff --git a/src/irc/core/irc-special-vars.c b/src/irc/core/irc-special-vars.c
index 09e0db11..92acd246 100644
--- a/src/irc/core/irc-special-vars.c
+++ b/src/irc/core/irc-special-vars.c
@@ -236,11 +236,13 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *
static void cmd_msg(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *msg;
+ char *target, *msg;
+ void *free_arg;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &msg))
+ return;
if (*target != '\0' && *msg != '\0' && !ischannel(*target) && isalpha(*target)) {
g_free_not_null(last_sent_msg);
g_free_not_null(last_sent_msg_body);
@@ -248,7 +250,7 @@ static void cmd_msg(const char *data, IRC_SERVER_REC *server)
last_sent_msg_body = g_strdup(msg);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void event_join(const char *data, IRC_SERVER_REC *server, const char *nick, const char *address)
diff --git a/src/irc/core/ircnet-setup.c b/src/irc/core/ircnet-setup.c
index 57cfab1a..b3946e6a 100644
--- a/src/irc/core/ircnet-setup.c
+++ b/src/irc/core/ircnet-setup.c
@@ -154,11 +154,11 @@ static void read_ircnets(void)
static void sig_connected(IRC_SERVER_REC *server)
{
IRCNET_REC *ircnet;
-
+
if (server->connrec->ircnet == NULL) return;
ircnet = ircnet_find(server->connrec->ircnet);
- if (ircnet->autosendcmd)
+ if (ircnet != NULL && ircnet->autosendcmd)
eval_special_string(ircnet->autosendcmd, "", server, NULL);
}
diff --git a/src/irc/core/modes.c b/src/irc/core/modes.c
index 715ad040..fcca2401 100644
--- a/src/irc/core/modes.c
+++ b/src/irc/core/modes.c
@@ -460,7 +460,8 @@ static void cmd_devoice(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *it
static void cmd_mode(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *target, *mode;
+ char *target, *mode;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
@@ -468,9 +469,11 @@ static void cmd_mode(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
if (*data == '+' || *data == '-') {
target = "*";
- params = mode = g_strdup(data); /* cmd_param_error() wants to free params.. */
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_GETREST, &mode))
+ return;
} else {
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &mode);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &mode))
+ return;
}
if (strcmp(target, "*") == 0) {
@@ -488,7 +491,7 @@ static void cmd_mode(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
else
irc_send_cmdv(server, "MODE %s %s", target, mode);
- g_free(params);
+ cmd_params_free(free_arg);
}
void modes_init(void)
diff --git a/src/irc/core/netsplit.c b/src/irc/core/netsplit.c
index bfa40c3c..0c394055 100644
--- a/src/irc/core/netsplit.c
+++ b/src/irc/core/netsplit.c
@@ -187,7 +187,8 @@ NICK_REC *netsplit_find_channel(IRC_SERVER_REC *server, const char *nick, const
int quitmsg_is_split(const char *msg)
{
- char *params, *host1, *host2, *p;
+ char *host1, *host2, *p;
+ void *free_arg;
int ok;
g_return_val_if_fail(msg != NULL, FALSE);
@@ -202,8 +203,10 @@ int quitmsg_is_split(const char *msg)
return FALSE;
/* get the two hosts */
+ if (!cmd_get_params(msg, &free_arg, 2 | PARAM_FLAG_NOQUOTES, &host1, &host2))
+ return FALSE;
+
ok = FALSE;
- params = cmd_get_params(msg, 2 | PARAM_FLAG_NOQUOTES, &host1, &host2);
if (g_strcasecmp(host1, host2) != 0) { /* hosts can't be same.. */
/* check that domain length is 2 or 3 */
p = strrchr(host1, '.');
@@ -215,7 +218,7 @@ int quitmsg_is_split(const char *msg)
}
}
}
- g_free(params);
+ cmd_params_free(free_arg);
return ok;
}
diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c
index 44968ce0..afdb9d5b 100644
--- a/src/irc/dcc/dcc-chat.c
+++ b/src/irc/dcc/dcc-chat.c
@@ -59,7 +59,8 @@ DCC_REC *item_get_dcc(void *item)
static void cmd_msg(const char *data)
{
DCC_REC *dcc;
- char *params, *text, *target;
+ char *text, *target;
+ void *free_arg;
g_return_if_fail(text != NULL);
@@ -68,12 +69,13 @@ static void cmd_msg(const char *data)
return;
}
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &text);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &text))
+ return;
dcc = dcc_find_item(DCC_TYPE_CHAT, ++target, NULL);
if (dcc != NULL) dcc_chat_send(dcc, text);
- g_free(params);
+ cmd_params_free(free_arg);
signal_stop();
}
@@ -96,9 +98,9 @@ static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
static void cmd_action(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *text;
DCC_REC *dcc;
- char *str;
+ char *target, *text, *str;
+ void *free_arg;
g_return_if_fail(data != NULL);
@@ -107,7 +109,8 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
return;
}
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &target, &text);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &text))
+ return;
if (*target == '\0' || *text == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
dcc = dcc_find_item(DCC_TYPE_CHAT, target+1, NULL);
@@ -117,25 +120,26 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
g_free(str);
}
- g_free(params);
+ cmd_params_free(free_arg);
signal_stop();
}
static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
{
- char *params, *target, *ctcpcmd, *ctcpdata;
DCC_REC *dcc;
- char *str;
+ char *target, *ctcpcmd, *ctcpdata, *str;
+ void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata))
+ return;
if (*target == '\0' || *ctcpcmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (*target != '=') {
/* handle only DCC CTCPs */
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -148,7 +152,7 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
g_free(str);
}
- g_free(params);
+ cmd_params_free(free_arg);
signal_stop();
}
diff --git a/src/irc/dcc/dcc-files.c b/src/irc/dcc/dcc-files.c
index e2dc732d..9a68813f 100644
--- a/src/irc/dcc/dcc-files.c
+++ b/src/irc/dcc/dcc-files.c
@@ -212,12 +212,14 @@ static void cmd_dcc_get(const char *data)
{
DCC_REC *dcc;
GSList *tmp, *next;
- char *params, *nick, *fname;
+ char *nick, *fname;
+ void *free_arg;
int found;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &nick, &fname);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &fname))
+ return;
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
dcc = NULL; found = FALSE;
@@ -235,7 +237,7 @@ static void cmd_dcc_get(const char *data)
if (!found)
signal_emit("dcc error get not found", 1, nick);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void dcc_resume_send(DCC_REC *dcc, int port)
@@ -264,7 +266,8 @@ static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server,
const char *sender, const char *sendaddr,
const char *target, DCC_REC *chat)
{
- char *params, *type, *arg, *portstr, *sizestr;
+ char *type, *arg, *portstr, *sizestr;
+ void *free_arg;
unsigned long size;
int port;
DCC_REC *dcc;
@@ -272,8 +275,9 @@ static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server,
g_return_if_fail(data != NULL);
g_return_if_fail(sender != NULL);
- params = cmd_get_params(data, 4 | PARAM_FLAG_NOQUOTES,
- &type, &arg, &portstr, &sizestr);
+ if (!cmd_get_params(data, &free_arg, 4 | PARAM_FLAG_NOQUOTES,
+ &type, &arg, &portstr, &sizestr))
+ return;
port = atoi(portstr);
size = atol(sizestr);
@@ -281,7 +285,7 @@ static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server,
dcc = dcc_find_by_port(sender, port);
if (dcc == NULL || !is_resume_type(type) ||
!is_resume_ok(type, dcc) || !is_accept_ok(type, dcc)) {
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -298,7 +302,7 @@ static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server,
dcc_get_connect(dcc);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void dcc_resume_rec(DCC_REC *dcc)
@@ -331,12 +335,14 @@ static void cmd_dcc_resume(const char *data)
{
DCC_REC *dcc;
GSList *tmp;
- char *params, *nick, *fname;
+ char *nick, *fname;
+ void *free_arg;
int found;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &nick, &fname);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &fname))
+ return;
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
dcc = NULL; found = FALSE;
@@ -353,7 +359,7 @@ static void cmd_dcc_resume(const char *data)
if (!found)
signal_emit("dcc error get not found", 1, nick);
- g_free(params);
+ cmd_params_free(free_arg);
}
/* input function: DCC SEND - we're ready to send more data */
@@ -483,7 +489,8 @@ static void dcc_send_init(DCC_REC *dcc)
/* command: DCC SEND */
static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
- char *params, *target, *fname, *str, *ptr;
+ char *target, *fname, *str, *ptr;
+ void *free_arg;
char host[MAX_IP_LEN];
int hfile, hlisten, port;
long fsize;
@@ -492,7 +499,8 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &fname);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &fname))
+ return;
if (*target == '\0' || *fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
/* if we're in dcc chat, send the request via it. */
@@ -506,7 +514,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
if (dcc_find_item(DCC_TYPE_SEND, target, fname)) {
signal_emit("dcc error send exists", 2, target, fname);
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -525,7 +533,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
if (hfile == -1) {
signal_emit("dcc error file not found", 2, target, fname);
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
fsize = lseek(hfile, 0, SEEK_END);
@@ -565,7 +573,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *i
g_free(str);
g_free(fname);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void read_settings(void)
diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c
index e514c934..75dc5459 100644
--- a/src/irc/dcc/dcc.c
+++ b/src/irc/dcc/dcc.c
@@ -278,7 +278,8 @@ static void dcc_get_address(const char *str, IPADDR *ip)
/* Handle incoming DCC CTCP messages */
static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr, char *target, DCC_REC *chat)
{
- char *params, *type, *arg, *addrstr, *portstr, *sizestr, *str;
+ char *type, *arg, *addrstr, *portstr, *sizestr, *str;
+ void *free_arg;
const char *cstr;
DCC_REC *dcc;
gulong size;
@@ -287,8 +288,9 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char
g_return_if_fail(data != NULL);
g_return_if_fail(sender != NULL);
- params = cmd_get_params(data, 5 | PARAM_FLAG_NOQUOTES,
- &type, &arg, &addrstr, &portstr, &sizestr);
+ if (!cmd_get_params(data, &free_arg, 5 | PARAM_FLAG_NOQUOTES,
+ &type, &arg, &addrstr, &portstr, &sizestr))
+ return;
if (sscanf(portstr, "%d", &port) != 1) port = 0;
if (sscanf(sizestr, "%lu", &size) != 1) size = 0;
@@ -349,20 +351,22 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char
break;
}
- g_free(params);
+ cmd_params_free(free_arg);
}
/* Handle incoming DCC CTCP replies */
static void dcc_ctcp_reply(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr)
{
- char *params, *cmd, *subcmd, *args;
+ char *cmd, *subcmd, *args;
+ void *free_arg;
int type;
DCC_REC *dcc;
g_return_if_fail(data != NULL);
g_return_if_fail(sender != NULL);
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &cmd, &subcmd, &args);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &cmd, &subcmd, &args))
+ return;
if (g_strcasecmp(cmd, "REJECT") == 0)
{
@@ -380,7 +384,7 @@ static void dcc_ctcp_reply(char *data, IRC_SERVER_REC *server, char *sender, cha
signal_emit("dcc unknown reply", 3, data, sender, sendaddr);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void dcc_reject(DCC_REC *dcc, IRC_SERVER_REC *server)
@@ -409,20 +413,22 @@ static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
{
DCC_REC *dcc;
GSList *tmp, *next;
- char *params, *type, *nick, *arg;
+ char *type, *nick, *arg;
+ void *free_arg;
gboolean found;
int itype;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 3, &type, &nick, &arg);
+ if (!cmd_get_params(data, &free_arg, 3, &type, &nick, &arg))
+ return;
g_strup(type);
itype = dcc_str2type(type);
if (itype == 0)
{
signal_emit("dcc error unknown type", 1, type);
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -442,7 +448,7 @@ static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
if (!found)
signal_emit("dcc error close not found", 3, type, nick, arg);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_dcc(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
diff --git a/src/irc/notifylist/notify-commands.c b/src/irc/notifylist/notify-commands.c
index af022dcd..0bef6d23 100644
--- a/src/irc/notifylist/notify-commands.c
+++ b/src/irc/notifylist/notify-commands.c
@@ -30,41 +30,47 @@
static void cmd_notify(gchar *data)
{
- char *params, *mask, *ircnets, *args, *idletime;
+ GHashTable *optlist;
+ char *mask, *ircnets, *idletime;
+ void *free_arg;
int away_check, idle_check_time;
g_return_if_fail(data != NULL);
- args = "@idle";
- params = cmd_get_params(data, 4 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST, &args, &idletime, &mask, &ircnets);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
+ "notify", &optlist, &mask, &ircnets))
+ return;
if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- if (stristr(args, "-idle") == NULL)
+ idletime = g_hash_table_lookup(optlist, "idle");
+ if (idletime == NULL)
idle_check_time = 0;
else {
idle_check_time = is_numeric(idletime, 0) ? (atoi(idletime)*60) :
(settings_get_int("notify_idle_time")*60);
}
- away_check = stristr(args, "-away") != NULL;
+ away_check = g_hash_table_lookup(optlist, "away") != NULL;
notifylist_remove(mask);
notifylist_add(mask, ircnets, away_check, idle_check_time);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_unnotify(const char *data)
{
- char *params, *mask;
+ char *mask;
+ void *free_arg;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 1, &mask);
+ if (!cmd_get_params(data, &free_arg, 1, &mask))
+ return;
if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
notifylist_remove(mask);
- g_free(params);
+ cmd_params_free(free_arg);
}
void notifylist_commands_init(void)
@@ -72,6 +78,8 @@ void notifylist_commands_init(void)
settings_add_int("misc", "notify_idle_time", DEFAULT_NOTIFY_IDLE_TIME);
command_bind("notify", NULL, (SIGNAL_FUNC) cmd_notify);
command_bind("unnotify", NULL, (SIGNAL_FUNC) cmd_unnotify);
+
+ command_set_options("notify", "@idle away");
}
void notifylist_commands_deinit(void)