Beispiel #1
0
struct t_gui_buffer *
irc_msgbuffer_get_target_buffer (struct t_irc_server *server, const char *nick,
                                 const char *message, const char *alias,
                                 struct t_gui_buffer *default_buffer)
{
    struct t_config_option *ptr_option;
    int target;
    struct t_gui_buffer *ptr_buffer;
    struct t_irc_channel *ptr_channel;
    struct t_weechat_plugin *buffer_plugin;

    ptr_option = NULL;

    if (message && message[0])
        ptr_option = irc_msgbuffer_get_option (server, message);
    if (!ptr_option && alias && alias[0])
        ptr_option = irc_msgbuffer_get_option (server, alias);

    if (!ptr_option)
    {
        if (default_buffer)
            return default_buffer;
        return (server) ? server->buffer : NULL;
    }

    target = weechat_config_integer (ptr_option);
    switch (target)
    {
        case IRC_MSGBUFFER_TARGET_WEECHAT:
            return NULL;
            break;
        case IRC_MSGBUFFER_TARGET_SERVER:
            return (server) ? server->buffer : NULL;
            break;
        case IRC_MSGBUFFER_TARGET_CURRENT:
            break;
        case IRC_MSGBUFFER_TARGET_PRIVATE:
            ptr_channel = irc_channel_search (server, nick);
            if (ptr_channel)
                return ptr_channel->buffer;
            if (weechat_config_integer (irc_config_look_msgbuffer_fallback) ==
                IRC_CONFIG_LOOK_MSGBUFFER_FALLBACK_SERVER)
            {
                return (server) ? server->buffer : NULL;
            }
            break;
        default:
            return (server) ? server->buffer : NULL;
            break;
    }

    ptr_buffer = weechat_current_buffer ();
    buffer_plugin = weechat_buffer_get_pointer (ptr_buffer, "plugin");
    if (buffer_plugin == weechat_irc_plugin)
        return ptr_buffer;

    return (server) ? server->buffer : NULL;
}
Beispiel #2
0
int
irc_input_send_cb (const void *pointer, void *data,
                   const char *signal,
                   const char *type_data, void *signal_data)
{
    const char *ptr_string, *ptr_message;
    char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4;
    char *server, *channel, *options, *tags, *data_with_colors, **list_options;
    int i, num_options, flags, force_user_message;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;
    struct t_gui_buffer *ptr_buffer;

    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) signal;
    (void) type_data;

    ptr_string = (const char *)signal_data;

    server = NULL;
    channel = NULL;
    options = NULL;
    flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
    force_user_message = 0;
    tags = NULL;
    ptr_message = NULL;
    ptr_server = NULL;
    ptr_channel = NULL;

    pos_semicol1 = strchr (ptr_string, ';');
    if (pos_semicol1)
    {
        if (pos_semicol1 > ptr_string + 1)
        {
            server = weechat_strndup (ptr_string, pos_semicol1 - ptr_string);
        }
        pos_semicol2 = strchr (pos_semicol1 + 1, ';');
        if (pos_semicol2)
        {
            if (pos_semicol2 > pos_semicol1 + 1)
            {
                channel = weechat_strndup (pos_semicol1 + 1,
                                           pos_semicol2 - pos_semicol1 - 1);
            }
            pos_semicol3 = strchr (pos_semicol2 + 1, ';');
            if (pos_semicol3)
            {
                if (pos_semicol3 > pos_semicol2 + 1)
                {
                    options = weechat_strndup (pos_semicol2 + 1,
                                               pos_semicol3 - pos_semicol2 - 1);
                }
                pos_semicol4 = strchr (pos_semicol3 + 1, ';');
                if (pos_semicol4)
                {
                    if (pos_semicol4 > pos_semicol3 + 1)
                    {
                        tags = weechat_strndup (pos_semicol3 + 1,
                                                pos_semicol4 - pos_semicol3 - 1);
                    }
                    ptr_message = pos_semicol4 + 1;
                }
            }
        }
    }

    if (options && options[0])
    {
        list_options = weechat_string_split (options, ",", 0, 0, &num_options);
        if (list_options)
        {
            for (i = 0; i < num_options; i++)
            {
                if (strcmp (list_options[i], "priority_high") == 0)
                    flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
                else if (strcmp (list_options[i], "priority_low") == 0)
                    flags = IRC_SERVER_SEND_OUTQ_PRIO_LOW;
                else if (strcmp (list_options[i], "user_message") == 0)
                    force_user_message = 1;
            }
            weechat_string_free_split (list_options);
        }
    }

    if (server && ptr_message)
    {
        ptr_server = irc_server_search (server);
        if (ptr_server)
        {
            ptr_buffer = ptr_server->buffer;
            if (channel)
            {
                ptr_channel = irc_channel_search (ptr_server, channel);
                if (ptr_channel)
                    ptr_buffer = ptr_channel->buffer;
            }

            /* set tags to use by default */
            irc_server_set_send_default_tags (tags);

            /* send text to buffer, or execute command */
            if (force_user_message
                || weechat_string_input_for_buffer (ptr_message))
            {
                /* text as input */
                irc_input_data (ptr_buffer, ptr_message, flags, 1);
            }
            else
            {
                /* command */
                data_with_colors = irc_color_encode (
                    ptr_message,
                    weechat_config_boolean (irc_config_network_colors_send));
                weechat_command (
                    ptr_buffer,
                    (data_with_colors) ? data_with_colors : ptr_message);
                if (data_with_colors)
                    free (data_with_colors);
            }

            /* reset tags to use by default */
            irc_server_set_send_default_tags (NULL);
        }
    }

    if (server)
        free (server);
    if (channel)
        free (channel);
    if (options)
        free (options);
    if (tags)
        free (tags);

    return WEECHAT_RC_OK;
}
Beispiel #3
0
int
irc_input_send_cb (void *data, const char *signal,
                   const char *type_data, void *signal_data)
{
    const char *ptr_string, *ptr_message;
    char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4, *error;
    char *server, *channel, *flags, *tags;
    long flags_value;
    char *data_with_colors;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;
    struct t_gui_buffer *ptr_buffer;

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

    ptr_string = (const char *)signal_data;

    server = NULL;
    channel = NULL;
    flags = NULL;
    tags = NULL;
    ptr_message = NULL;
    ptr_server = NULL;
    ptr_channel = NULL;

    pos_semicol1 = strchr (ptr_string, ';');
    if (pos_semicol1)
    {
        if (pos_semicol1 > ptr_string + 1)
        {
            server = weechat_strndup (ptr_string, pos_semicol1 - ptr_string);
        }
        pos_semicol2 = strchr (pos_semicol1 + 1, ';');
        if (pos_semicol2)
        {
            if (pos_semicol2 > pos_semicol1 + 1)
            {
                channel = weechat_strndup (pos_semicol1 + 1,
                                           pos_semicol2 - pos_semicol1 - 1);
            }
            pos_semicol3 = strchr (pos_semicol2 + 1, ';');
            if (pos_semicol3)
            {
                if (pos_semicol3 > pos_semicol2 + 1)
                {
                    flags = weechat_strndup (pos_semicol2 + 1,
                                             pos_semicol3 - pos_semicol2 - 1);
                }
                pos_semicol4 = strchr (pos_semicol3 + 1, ';');
                if (pos_semicol4)
                {
                    if (pos_semicol4 > pos_semicol3 + 1)
                    {
                        tags = weechat_strndup (pos_semicol3 + 1,
                                                pos_semicol4 - pos_semicol3 - 1);
                    }
                    ptr_message = pos_semicol4 + 1;
                }
            }
        }
    }

    flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
    if (flags)
    {
        error = NULL;
        flags_value = strtol (flags, &error, 10);
        if (flags_value < 0)
            flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
    }

    if (server && ptr_message)
    {
        ptr_server = irc_server_search (server);
        if (ptr_server)
        {
            ptr_buffer = ptr_server->buffer;
            if (channel)
            {
                ptr_channel = irc_channel_search (ptr_server, channel);
                if (ptr_channel)
                    ptr_buffer = ptr_channel->buffer;
            }

            /* set tags to use by default */
            irc_server_set_send_default_tags (tags);

            /* send text to buffer, or execute command */
            if (weechat_string_input_for_buffer (ptr_message))
            {
                /* text as input */
                irc_input_data (ptr_buffer, ptr_message, flags_value);
            }
            else
            {
                /* command */
                data_with_colors = irc_color_encode (ptr_message,
                                                     weechat_config_boolean (irc_config_network_colors_send));
                weechat_command (ptr_buffer,
                                 (data_with_colors) ? data_with_colors : ptr_message);
                if (data_with_colors)
                    free (data_with_colors);
            }

            /* reset tags to use by default */
            irc_server_set_send_default_tags (NULL);
        }
    }

    if (server)
        free (server);
    if (channel)
        free (channel);
    if (flags)
        free (flags);
    if (tags)
        free (tags);

    return WEECHAT_RC_OK;
}
Beispiel #4
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;
    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)
    {
        if (irc_channel_is_channel (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_protocol_get_nick_from_host (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_channel_is_channel (arguments))
                    channel = strdup (arguments);
                else
                    server = strdup (arguments);
            }
            
            /* replace channel by nick in host if channel is not a channel
               (private ?) */
            if (channel && host)
            {
                if (!irc_channel_is_channel (channel))
                {
                    free (channel);
                    channel = NULL;
                    nick = irc_protocol_get_nick_from_host (host);
                    if (nick)
                        channel = strdup (nick);
                    
                }
            }
            
            /* search for server or channel buffer */
            if (server)
            {
                ptr_server = irc_server_search (server);
                if (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;
            }
        }
    }
    
    return NULL;
}
Beispiel #5
0
struct t_infolist *
irc_info_get_infolist_cb (void *data, const char *infolist_name,
                          void *pointer, const char *arguments)
{
    struct t_infolist *ptr_infolist;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;
    struct t_irc_nick *ptr_nick;
    struct t_irc_ignore *ptr_ignore;
    char **argv;
    int argc;
    
    /* make C compiler happy */
    (void) data;
    
    if (!infolist_name || !infolist_name[0])
        return NULL;
    
    if (weechat_strcasecmp (infolist_name, "irc_server") == 0)
    {
        if (pointer && !irc_server_valid (pointer))
            return NULL;
        
        ptr_infolist = weechat_infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one server */
                if (!irc_server_add_to_infolist (ptr_infolist, pointer))
                {
                    weechat_infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all servers matching arguments */
                for (ptr_server = irc_servers; ptr_server;
                     ptr_server = ptr_server->next_server)
                {
                    if (!arguments || !arguments[0]
                        || weechat_string_match (ptr_server->name, arguments, 0))
                    {
                        if (!irc_server_add_to_infolist (ptr_infolist, ptr_server))
                        {
                            weechat_infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (weechat_strcasecmp (infolist_name, "irc_channel") == 0)
    {
        if (arguments && arguments[0])
        {
            ptr_server = irc_server_search (arguments);
            if (ptr_server)
            {
                if (pointer && !irc_channel_valid (ptr_server, pointer))
                    return NULL;
                
                ptr_infolist = weechat_infolist_new ();
                if (ptr_infolist)
                {
                    if (pointer)
                    {
                        /* build list with only one channel */
                        if (!irc_channel_add_to_infolist (ptr_infolist, pointer))
                        {
                            weechat_infolist_free (ptr_infolist);
                            return NULL;
                        }
                        return ptr_infolist;
                    }
                    else
                    {
                        /* build list with all channels of server */
                        for (ptr_channel = ptr_server->channels; ptr_channel;
                             ptr_channel = ptr_channel->next_channel)
                        {
                            if (!irc_channel_add_to_infolist (ptr_infolist,
                                                              ptr_channel))
                            {
                                weechat_infolist_free (ptr_infolist);
                                return NULL;
                            }
                        }
                        return ptr_infolist;
                    }
                }
            }
        }
    }
    else if (weechat_strcasecmp (infolist_name, "irc_nick") == 0)
    {
        if (arguments && arguments[0])
        {
            ptr_server = NULL;
            ptr_channel = NULL;
            argv = weechat_string_split (arguments, ",", 0, 0, &argc);
            if (argv)
            {
                if (argc >= 2)
                {
                    ptr_server = irc_server_search (argv[0]);
                    if (!ptr_server)
                    {
                        weechat_string_free_split (argv);
                        return NULL;
                    }
                    ptr_channel = irc_channel_search (ptr_server, argv[1]);
                    if (!ptr_channel)
                    {
                        weechat_string_free_split (argv);
                        return NULL;
                    }
                    if (!pointer && (argc >= 3))
                    {
                        pointer = irc_nick_search (ptr_channel, argv[2]);
                        if (!pointer)
                        {
                            weechat_string_free_split (argv);
                            return NULL;
                        }
                    }
                }
                weechat_string_free_split (argv);
                if (ptr_server && ptr_channel)
                {
                    if (pointer && !irc_nick_valid (ptr_channel, pointer))
                        return NULL;
                    
                    ptr_infolist = weechat_infolist_new ();
                    if (ptr_infolist)
                    {
                        if (pointer)
                        {
                            /* build list with only one nick */
                            if (!irc_nick_add_to_infolist (ptr_infolist, pointer))
                            {
                                weechat_infolist_free (ptr_infolist);
                                return NULL;
                            }
                            return ptr_infolist;
                        }
                        else
                        {
                            /* build list with all nicks of channel */
                            for (ptr_nick = ptr_channel->nicks; ptr_nick;
                                 ptr_nick = ptr_nick->next_nick)
                            {
                                if (!irc_nick_add_to_infolist (ptr_infolist,
                                                               ptr_nick))
                                {
                                    weechat_infolist_free (ptr_infolist);
                                    return NULL;
                                }
                            }
                            return ptr_infolist;
                        }
                    }
                }
            }
        }
    }
    else if (weechat_strcasecmp (infolist_name, "irc_ignore") == 0)
    {
        if (pointer && !irc_ignore_valid (pointer))
            return NULL;
        
        ptr_infolist = weechat_infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one ignore */
                if (!irc_ignore_add_to_infolist (ptr_infolist, pointer))
                {
                    weechat_infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all ignore */
                for (ptr_ignore = irc_ignore_list; ptr_ignore;
                     ptr_ignore = ptr_ignore->next_ignore)
                {
                    if (!irc_ignore_add_to_infolist (ptr_infolist, ptr_ignore))
                    {
                        weechat_infolist_free (ptr_infolist);
                        return NULL;
                    }
                }
                return ptr_infolist;
            }
        }
    }
    
    return NULL;
}
Beispiel #6
0
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;
    }
}
Beispiel #7
0
struct t_infolist *
irc_info_infolist_irc_nick_cb (void *data, const char *infolist_name,
                               void *pointer, const char *arguments)
{
    struct t_infolist *ptr_infolist;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;
    struct t_irc_nick *ptr_nick;
    char **argv;
    int argc;

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

    if (!arguments || !arguments[0])
        return NULL;

    ptr_server = NULL;
    ptr_channel = NULL;
    argv = dogechat_string_split (arguments, ",", 0, 0, &argc);
    if (!argv)
        return NULL;

    if (argc >= 2)
    {
        ptr_server = irc_server_search (argv[0]);
        if (!ptr_server)
        {
            dogechat_string_free_split (argv);
            return NULL;
        }
        ptr_channel = irc_channel_search (ptr_server, argv[1]);
        if (!ptr_channel)
        {
            dogechat_string_free_split (argv);
            return NULL;
        }
        if (!pointer && (argc >= 3))
        {
            pointer = irc_nick_search (ptr_server, ptr_channel,
                                       argv[2]);
            if (!pointer)
            {
                dogechat_string_free_split (argv);
                return NULL;
            }
        }
    }
    dogechat_string_free_split (argv);

    if (!ptr_server || !ptr_channel)
        return NULL;

    if (pointer && !irc_nick_valid (ptr_channel, pointer))
        return NULL;

    ptr_infolist = dogechat_infolist_new ();
    if (!ptr_infolist)
        return NULL;

    if (pointer)
    {
        /* build list with only one nick */
        if (!irc_nick_add_to_infolist (ptr_infolist,
                                       pointer))
        {
            dogechat_infolist_free (ptr_infolist);
            return NULL;
        }
        return ptr_infolist;
    }
    else
    {
        /* build list with all nicks of channel */
        for (ptr_nick = ptr_channel->nicks; ptr_nick;
             ptr_nick = ptr_nick->next_nick)
        {
            if (!irc_nick_add_to_infolist (ptr_infolist,
                                           ptr_nick))
            {
                dogechat_infolist_free (ptr_infolist);
                return NULL;
            }
        }
        return ptr_infolist;
    }

    return NULL;
}
Beispiel #8
0
const char *
irc_info_info_irc_buffer_cb (void *data, const char *info_name,
                             const char *arguments)
{
    char *pos_comma, *pos_comma2, *server, *channel, *host;
    const char *nick;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;

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

    if (!arguments || !arguments[0])
        return NULL;

    server = NULL;
    channel = NULL;
    host = NULL;
    ptr_server = NULL;
    ptr_channel = NULL;

    pos_comma = strchr (arguments, ',');
    if (pos_comma)
    {
        server = dogechat_strndup (arguments, pos_comma - arguments);
        pos_comma2 = strchr (pos_comma + 1, ',');
        if (pos_comma2)
        {
            channel = dogechat_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;
    }
    return NULL;
}