Example #1
0
const char *
irc_info_info_irc_nick_color_name_cb (void *data, const char *info_name,
                                      const char *arguments)
{
    /* make C compiler happy */
    (void) data;
    (void) info_name;

    return (arguments && arguments[0]) ?
        irc_nick_find_color_name (arguments) : NULL;
}
Example #2
0
const char *
irc_info_get_info_cb (void *data, const char *info_name,
                      const char *arguments)
{
    char *pos_comma, *pos_comma2, *server, *channel, *host;
    const char *nick, *pos_channel, *isupport_value;
    static char str_true[2] = "1";
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;

    /* make C compiler happy */
    (void) data;

    if (weechat_strcasecmp (info_name, "irc_is_channel") == 0)
    {
        ptr_server = NULL;
        pos_channel = arguments;
        pos_comma = strchr (arguments, ',');
        if (pos_comma)
        {
            pos_channel = pos_comma + 1;
            server = weechat_strndup (arguments, pos_comma - arguments);
            if (server)
            {
                ptr_server = irc_server_search (server);
                free (server);
            }
        }
        if (irc_channel_is_channel (ptr_server, pos_channel))
            return str_true;
        return NULL;
    }
    else if (weechat_strcasecmp (info_name, "irc_is_nick") == 0)
    {
        if (irc_nick_is_nick (arguments))
            return str_true;
        return NULL;
    }
    else if (weechat_strcasecmp (info_name, "irc_nick") == 0)
    {
        ptr_server = irc_server_search (arguments);
        if (ptr_server)
            return ptr_server->nick;
        return NULL;
    }
    else if (weechat_strcasecmp (info_name, "irc_nick_from_host") == 0)
    {
        return irc_message_get_nick_from_host (arguments);
    }
    else if (weechat_strcasecmp (info_name, "irc_nick_color") == 0)
    {
        return irc_nick_find_color (arguments);
    }
    else if (weechat_strcasecmp (info_name, "irc_nick_color_name") == 0)
    {
        return irc_nick_find_color_name (arguments);
    }
    else if (weechat_strcasecmp (info_name, "irc_buffer") == 0)
    {
        if (arguments && arguments[0])
        {
            server = NULL;
            channel = NULL;
            host = NULL;
            ptr_server = NULL;
            ptr_channel = NULL;

            pos_comma = strchr (arguments, ',');
            if (pos_comma)
            {
                server = weechat_strndup (arguments, pos_comma - arguments);
                pos_comma2 = strchr (pos_comma + 1, ',');
                if (pos_comma2)
                {
                    channel = weechat_strndup (pos_comma + 1,
                                               pos_comma2 - pos_comma - 1);
                    host = strdup (pos_comma2 + 1);
                }
                else
                    channel = strdup (pos_comma + 1);
            }
            else
            {
                if (irc_server_search (arguments))
                    server = strdup (arguments);
                else
                    channel = strdup (arguments);
            }
            if (server)
                ptr_server = irc_server_search (server);

            /*
             * replace channel by nick in host if channel is not a channel
             * (private ?)
             */
            if (channel && host)
            {
                if (!irc_channel_is_channel (ptr_server, channel))
                {
                    free (channel);
                    channel = NULL;
                    nick = irc_message_get_nick_from_host (host);
                    if (nick)
                        channel = strdup (nick);

                }
            }

            /* search for server or channel buffer */
            if (server && ptr_server && channel)
                ptr_channel = irc_channel_search (ptr_server, channel);

            if (server)
                free (server);
            if (channel)
                free (channel);
            if (host)
                free (host);

            if (ptr_channel)
            {
                irc_info_create_string_with_pointer (&ptr_channel->buffer_as_string,
                                                     ptr_channel->buffer);
                return ptr_channel->buffer_as_string;
            }
            if (ptr_server)
            {
                irc_info_create_string_with_pointer (&ptr_server->buffer_as_string,
                                                     ptr_server->buffer);
                return ptr_server->buffer_as_string;
            }
        }
    }
    else if (weechat_strcasecmp (info_name, "irc_server_isupport") == 0)
    {
        isupport_value = NULL;
        pos_comma = strchr (arguments, ',');
        if (pos_comma)
        {
            server = weechat_strndup (arguments, pos_comma - arguments);
            if (server)
            {
                ptr_server = irc_server_search (server);
                if (ptr_server)
                {
                    isupport_value = irc_server_get_isupport_value (ptr_server,
                                                                    pos_comma + 1);
                }
            }
        }
        if (isupport_value)
            return str_true;
        return NULL;
    }
    else if (weechat_strcasecmp (info_name, "irc_server_isupport_value") == 0)
    {
        isupport_value = NULL;
        pos_comma = strchr (arguments, ',');
        if (pos_comma)
        {
            server = weechat_strndup (arguments, pos_comma - arguments);
            if (server)
            {
                ptr_server = irc_server_search (server);
                if (ptr_server)
                {
                    isupport_value = irc_server_get_isupport_value (ptr_server,
                                                                    pos_comma + 1);
                }
            }
        }
        return isupport_value;
    }

    return NULL;
}