diff options
Diffstat (limited to 'src/irc/bot')
-rw-r--r-- | src/irc/bot/botnet-connection.c | 8 | ||||
-rw-r--r-- | src/irc/bot/botnet-users.c | 49 | ||||
-rw-r--r-- | src/irc/bot/botnet.c | 22 |
3 files changed, 49 insertions, 30 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, ¬_flags); + if (!cmd_get_params(data, &free_arg, 3, &nick, &mask, ¬_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) |