int irc_buffer_nickcmp_cb (void *data, struct t_gui_buffer *buffer, const char *nick1, const char *nick2) { IRC_BUFFER_GET_SERVER(buffer); /* make C compiler happy */ (void) data; return irc_server_strcasecmp (ptr_server, nick1, nick2); }
struct t_irc_notify * irc_notify_search (struct t_irc_server *server, const char *nick) { struct t_irc_notify *ptr_notify; if (!server || !nick) return NULL; for (ptr_notify = server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { if (irc_server_strcasecmp (server, ptr_notify->nick, nick) == 0) return ptr_notify; } /* notify not found */ return NULL; }
int irc_buffer_nickcmp_cb (void *data, struct t_gui_buffer *buffer, const char *nick1, const char *nick2) { struct t_irc_server *server; if (data) server = (struct t_irc_server *)data; else irc_buffer_get_server_and_channel (buffer, &server, NULL); if (server) { return irc_server_strcasecmp (server, nick1, nick2); } else { /* default is RFC 1459 casemapping comparison */ return dogechat_strcasecmp_range (nick1, nick2, 29); } }
int irc_mode_channel_set (struct t_irc_server *server, struct t_irc_channel *channel, const char *host, const char *modes, const char *modes_arguments) { const char *pos, *ptr_arg; char set_flag, **argv, chanmode_type; int argc, current_arg, update_channel_modes, channel_modes_updated; int smart_filter, end_modes; struct t_irc_nick *ptr_nick; struct t_irc_modelist *ptr_modelist; struct t_irc_modelist_item *ptr_item; if (!server || !channel || !modes) return 0; channel_modes_updated = 0; argc = 0; argv = NULL; if (modes_arguments) { argv = weechat_string_split (modes_arguments, " ", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &argc); } current_arg = 0; smart_filter = (weechat_config_boolean (irc_config_look_smart_filter) && weechat_config_string (irc_config_look_smart_filter_mode) && weechat_config_string (irc_config_look_smart_filter_mode)[0]) ? 1 : 0; end_modes = 0; set_flag = '+'; pos = modes; while (pos[0]) { switch (pos[0]) { case ':': break; case ' ': end_modes = 1; break; case '+': set_flag = '+'; break; case '-': set_flag = '-'; break; default: update_channel_modes = 1; chanmode_type = irc_mode_get_chanmode_type (server, pos[0]); ptr_arg = NULL; switch (chanmode_type) { case 'A': /* always argument */ update_channel_modes = 0; ptr_arg = (current_arg < argc) ? argv[current_arg] : NULL; break; case 'B': /* always argument */ ptr_arg = (current_arg < argc) ? argv[current_arg] : NULL; break; case 'C': /* argument if set */ ptr_arg = ((set_flag == '+') && (current_arg < argc)) ? argv[current_arg] : NULL; break; case 'D': /* no argument */ break; } if (ptr_arg) { if (ptr_arg[0] == ':') ptr_arg++; current_arg++; } if (smart_filter && !irc_mode_smart_filtered (server, pos[0])) { smart_filter = 0; } if (pos[0] == 'k') { /* channel key */ if (set_flag == '-') { if (channel->key) { free (channel->key); channel->key = NULL; } } else if ((set_flag == '+') && ptr_arg && (strcmp (ptr_arg, "*") != 0)) { /* replace key for +k, but ignore "*" as new key */ if (channel->key) free (channel->key); channel->key = strdup (ptr_arg); } } else if (pos[0] == 'l') { /* channel limit */ if (set_flag == '-') channel->limit = 0; if ((set_flag == '+') && ptr_arg) { channel->limit = atoi (ptr_arg); } } else if ((chanmode_type != 'A') && (irc_server_get_prefix_mode_index (server, pos[0]) >= 0)) { /* mode for nick */ update_channel_modes = 0; if (ptr_arg) { ptr_nick = irc_nick_search (server, channel, ptr_arg); if (ptr_nick) { irc_nick_set_mode (server, channel, ptr_nick, (set_flag == '+'), pos[0]); /* * disable smart filtering if mode is sent * to me, or based on the nick speaking time */ if (smart_filter && ((irc_server_strcasecmp (server, ptr_nick->name, server->nick) == 0) || irc_channel_nick_speaking_time_search (server, channel, ptr_nick->name, 1))) { smart_filter = 0; } } } } else if (chanmode_type == 'A') { /* modelist modes */ if (ptr_arg) { ptr_modelist = irc_modelist_search (channel, pos[0]); if (ptr_modelist) { if (set_flag == '+') { irc_modelist_item_new (ptr_modelist, ptr_arg, host, time (NULL)); } else if (set_flag == '-') { ptr_item = irc_modelist_item_search_mask ( ptr_modelist, ptr_arg); if (ptr_item) irc_modelist_item_free (ptr_modelist, ptr_item); } } } } if (update_channel_modes) { irc_mode_channel_update (server, channel, set_flag, pos[0], ptr_arg); channel_modes_updated = 1; } break; } if (end_modes) break; pos++; } if (argv) weechat_string_free_split (argv); if (channel_modes_updated) weechat_bar_item_update ("buffer_modes"); return smart_filter; }
void irc_ctcp_recv (struct t_irc_server *server, const char *command, struct t_irc_channel *channel, const char *address, const char *nick, const char *remote_nick, char *arguments, char *message) { char *pos_end, *pos_space, *pos_args; const char *reply; char *decoded_reply; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; int nick_is_me; while (arguments && arguments[0]) { pos_end = strrchr (arguments + 1, '\01'); if (pos_end) pos_end[0] = '\0'; pos_args = NULL; pos_space = strchr (arguments + 1, ' '); if (pos_space) { pos_space[0] = '\0'; pos_args = pos_space + 1; while (pos_args[0] == ' ') { pos_args++; } } /* CTCP ACTION */ if (strcmp (arguments + 1, "ACTION") == 0) { nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0); if (channel) { ptr_nick = irc_nick_search (server, channel, nick); irc_channel_nick_speaking_add (channel, nick, (pos_args) ? weechat_string_has_highlight (pos_args, server->nick) : 0); irc_channel_nick_speaking_time_remove_old (channel); irc_channel_nick_speaking_time_add (server, channel, nick, time (NULL)); weechat_printf_tags (channel->buffer, irc_protocol_tags (command, (nick_is_me) ? "irc_action,notify_none,no_highlight" : "irc_action,notify_message", nick), "%s%s%s%s%s%s", weechat_prefix ("action"), (ptr_nick) ? ptr_nick->color : ((nick) ? irc_nick_find_color (nick) : IRC_COLOR_CHAT_NICK), nick, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); } else { ptr_channel = irc_channel_search (server, remote_nick); if (!ptr_channel) { ptr_channel = irc_channel_new (server, IRC_CHANNEL_TYPE_PRIVATE, remote_nick, 0, 0); if (!ptr_channel) { weechat_printf (server->buffer, _("%s%s: cannot create new " "private buffer \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, remote_nick); } } if (ptr_channel) { if (!ptr_channel->topic) irc_channel_set_topic (ptr_channel, address); weechat_printf_tags (ptr_channel->buffer, irc_protocol_tags (command, (nick_is_me) ? "irc_action,notify_none,no_highlight" : "irc_action,notify_private", nick), "%s%s%s%s%s%s", weechat_prefix ("action"), (nick_is_me) ? IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick), nick, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); weechat_hook_signal_send ("irc_pv", WEECHAT_HOOK_SIGNAL_STRING, message); } } } /* CTCP PING */ else if (strcmp (arguments + 1, "PING") == 0) { reply = irc_ctcp_get_reply (server, arguments + 1); irc_ctcp_display_request (server, command, channel, nick, arguments + 1, pos_args, reply); if (!reply || reply[0]) { irc_ctcp_reply_to_nick (server, command, channel, nick, arguments + 1, pos_args); } } /* CTCP DCC */ else if (strcmp (arguments + 1, "DCC") == 0) { irc_ctcp_recv_dcc (server, nick, pos_args, message); } /* other CTCP */ else { reply = irc_ctcp_get_reply (server, arguments + 1); if (reply) { irc_ctcp_display_request (server, command, channel, nick, arguments + 1, pos_args, reply); if (reply[0]) { decoded_reply = irc_ctcp_replace_variables (server, reply); if (decoded_reply) { irc_ctcp_reply_to_nick (server, command, channel, nick, arguments + 1, decoded_reply); free (decoded_reply); } } } else { if (weechat_config_boolean (irc_config_look_display_ctcp_unknown)) { weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, nick, NULL, "ctcp", (channel) ? channel->buffer : NULL), irc_protocol_tags (command, "irc_ctcp", NULL), _("%sUnknown CTCP requested by %s%s%s: " "%s%s%s%s%s"), weechat_prefix ("network"), IRC_COLOR_CHAT_NICK, nick, IRC_COLOR_RESET, IRC_COLOR_CHAT_CHANNEL, arguments + 1, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", (pos_args) ? pos_args : ""); } } } weechat_hook_signal_send ("irc_ctcp", WEECHAT_HOOK_SIGNAL_STRING, message); if (pos_space) pos_space[0] = ' '; if (pos_end) pos_end[0] = '\01'; arguments = (pos_end) ? pos_end + 1 : NULL; } }
int irc_ignore_check (struct t_irc_server *server, const char *channel, const char *nick, const char *host) { struct t_irc_ignore *ptr_ignore; int server_match, channel_match; char *pos; if (!server) return 0; /* * if nick is the same as server, then we will not ignore * (it is possible when connected to an irc proxy) */ if (nick && server->nick && (irc_server_strcasecmp (server, server->nick, nick) == 0)) { return 0; } for (ptr_ignore = irc_ignore_list; ptr_ignore; ptr_ignore = ptr_ignore->next_ignore) { if (strcmp (ptr_ignore->server, "*") == 0) server_match = 1; else server_match = (weechat_strcasecmp (ptr_ignore->server, server->name) == 0); channel_match = 0; if (!channel || (strcmp (ptr_ignore->channel, "*") == 0)) channel_match = 1; else { if (irc_channel_is_channel (server, channel)) { channel_match = (weechat_strcasecmp (ptr_ignore->channel, channel) == 0); } else if (nick) { channel_match = (weechat_strcasecmp (ptr_ignore->channel, nick) == 0); } } if (server_match && channel_match) { if (nick && (regexec (ptr_ignore->regex_mask, nick, 0, NULL, 0) == 0)) return 1; if (host) { if (regexec (ptr_ignore->regex_mask, host, 0, NULL, 0) == 0) return 1; if (!strchr (ptr_ignore->mask, '!')) { pos = strchr (host, '!'); if (pos && (regexec (ptr_ignore->regex_mask, pos + 1, 0, NULL, 0) == 0)) { return 1; } } } } } return 0; }
int irc_notify_hsignal_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { const char *error, *server, *pattern, *command, *output; char **messages, **nicks_sent, **nicks_recv, *irc_cmd, *arguments; char *ptr_args, *pos; int i, j, num_messages, num_nicks_sent, num_nicks_recv, nick_was_sent; int away_message_updated, no_such_nick; struct t_irc_server *ptr_server; struct t_irc_notify *ptr_notify; /* make C compiler happy */ (void) pointer; (void) data; (void) signal; error = weechat_hashtable_get (hashtable, "error"); server = weechat_hashtable_get (hashtable, "server"); pattern = weechat_hashtable_get (hashtable, "pattern"); command = weechat_hashtable_get (hashtable, "command"); output = weechat_hashtable_get (hashtable, "output"); /* if there is an error on redirection, just ignore result */ if (error && error[0]) return WEECHAT_RC_OK; /* missing things in redirection */ if (!server || !pattern || !command || !output) return WEECHAT_RC_OK; /* search server */ ptr_server = irc_server_search (server); if (!ptr_server) return WEECHAT_RC_OK; /* search for start of arguments in command sent to server */ ptr_args = strchr (command, ' '); if (!ptr_args) return WEECHAT_RC_OK; ptr_args++; while ((ptr_args[0] == ' ') || (ptr_args[0] == ':')) { ptr_args++; } if (!ptr_args[0]) return WEECHAT_RC_OK; /* read output of command */ if (strcmp (pattern, "ison") == 0) { /* redirection of command "ison" */ messages = weechat_string_split ( output, "\n", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_messages); if (messages) { nicks_sent = weechat_string_split ( ptr_args, " ", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_nicks_sent); if (!nicks_sent) return WEECHAT_RC_OK; for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { ptr_notify->ison_received = 0; } for (i = 0; i < num_messages; i++) { irc_message_parse (ptr_server, messages[i], NULL, NULL, NULL, NULL, NULL, NULL, &arguments, NULL, NULL, NULL, NULL, NULL); if (arguments) { pos = strchr (arguments, ' '); if (pos) { pos++; while ((pos[0] == ' ') || (pos[0] == ':')) { pos++; } if (pos[0]) { nicks_recv = weechat_string_split ( pos, " ", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_nicks_recv); if (nicks_recv) { for (j = 0; j < num_nicks_recv; j++) { for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { if (irc_server_strcasecmp (ptr_server, ptr_notify->nick, nicks_recv[j]) == 0) { irc_notify_set_is_on_server (ptr_notify, NULL, 1); ptr_notify->ison_received = 1; } } } weechat_string_free_split (nicks_recv); } } } free (arguments); } } for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { if (!ptr_notify->ison_received) { nick_was_sent = 0; for (j = 0; j < num_nicks_sent; j++) { if (irc_server_strcasecmp (ptr_server, nicks_sent[j], ptr_notify->nick) == 0) { nick_was_sent = 1; break; } } if (nick_was_sent) { irc_notify_set_is_on_server (ptr_notify, NULL, 0); } } } weechat_string_free_split (messages); } } else if (strcmp (pattern, "whois") == 0) { /* redirection of command "whois" */ ptr_notify = irc_notify_search (ptr_server, ptr_args); if (ptr_notify) { away_message_updated = 0; no_such_nick = 0; messages = weechat_string_split ( output, "\n", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_messages); if (messages) { for (i = 0; i < num_messages; i++) { irc_message_parse (ptr_server, messages[i], NULL, NULL, NULL, NULL, &irc_cmd, NULL, &arguments, NULL, NULL, NULL, NULL, NULL); if (irc_cmd && arguments) { if (strcmp (irc_cmd, "401") == 0) { /* no such nick/channel */ no_such_nick = 1; } else if (strcmp (irc_cmd, "301") == 0) { /* away message */ pos = strchr (arguments, ':'); if (pos) { pos++; /* nick is away */ irc_notify_set_away_message (ptr_notify, pos); away_message_updated = 1; } } } if (irc_cmd) free (irc_cmd); if (arguments) free (arguments); } } if (!away_message_updated && !no_such_nick) { /* nick is back */ irc_notify_set_away_message (ptr_notify, NULL); } } } return WEECHAT_RC_OK; }