struct t_hashtable * irc_message_parse_to_hashtable (struct t_irc_server *server, const char *message) { char *tags,*message_without_tags, *nick, *host, *command, *channel; char *arguments, *text, str_pos_text[32]; char empty_str[1] = { '\0' }; int pos_text; struct t_hashtable *hashtable; irc_message_parse (server, message, &tags, &message_without_tags, &nick, &host, &command, &channel, &arguments, &text, &pos_text); hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!hashtable) return NULL; weechat_hashtable_set (hashtable, "tags", (tags) ? tags : empty_str); weechat_hashtable_set (hashtable, "message_without_tags", (message_without_tags) ? message_without_tags : empty_str); weechat_hashtable_set (hashtable, "nick", (nick) ? nick : empty_str); weechat_hashtable_set (hashtable, "host", (host) ? host : empty_str); weechat_hashtable_set (hashtable, "command", (command) ? command : empty_str); weechat_hashtable_set (hashtable, "channel", (channel) ? channel : empty_str); weechat_hashtable_set (hashtable, "arguments", (arguments) ? arguments : empty_str); weechat_hashtable_set (hashtable, "text", (text) ? text : empty_str); snprintf (str_pos_text, sizeof (str_pos_text), "%d", pos_text); weechat_hashtable_set (hashtable, "pos_text", str_pos_text); if (tags) free (tags); if (message_without_tags) free (message_without_tags); if (nick) free (nick); if (host) free (host); if (command) free (command); if (channel) free (channel); if (arguments) free (arguments); if (text) free (text); return hashtable; }
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; }