Ejemplo n.º 1
0
int
exec_buffer_input_cb (const void *pointer, void *data,
                      struct t_gui_buffer *buffer,
                      const char *input_data)
{
    char **argv, **argv_eol;
    int argc;

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

    /* close buffer */
    if (strcmp (input_data, "q") == 0)
    {
        weechat_buffer_close (buffer);
        return WEECHAT_RC_OK;
    }

    argv = weechat_string_split (input_data, " ", 0, 0, &argc);
    argv_eol = weechat_string_split (input_data, " ", 1, 0, NULL);

    if (argv && argv_eol)
        exec_command_run (buffer, argc, argv, argv_eol, 0);

    if (argv)
        weechat_string_free_split (argv);
    if (argv_eol)
        weechat_string_free_split (argv_eol);

    return WEECHAT_RC_OK;
}
Ejemplo n.º 2
0
void
irc_notify_new_for_server (struct t_irc_server *server)
{
    const char *notify;
    char **items, *pos_params, **params;
    int i, j, num_items, num_params, check_away;

    irc_notify_free_all (server);

    notify = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_NOTIFY);
    if (!notify || !notify[0])
        return;

    items = weechat_string_split (notify, ",",
                                  WEECHAT_STRING_SPLIT_STRIP_LEFT
                                  | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                  | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                                  0, &num_items);
    if (items)
    {
        for (i = 0; i < num_items; i++)
        {
            check_away = 0;
            pos_params = strchr (items[i], ' ');
            if (pos_params)
            {
                pos_params[0] = '\0';
                pos_params++;
                while (pos_params[0] == ' ')
                {
                    pos_params++;
                }
                params = weechat_string_split (
                    pos_params,
                    "/",
                    WEECHAT_STRING_SPLIT_STRIP_LEFT
                    | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                    | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                    0,
                    &num_params);
                if (params)
                {
                    for (j = 0; j < num_params; j++)
                    {
                        if (weechat_strcasecmp (params[j], "away") == 0)
                            check_away = 1;
                    }
                    weechat_string_free_split (params);
                }
            }
            irc_notify_new (server, items[i], check_away);
        }
        weechat_string_free_split (items);
    }

    /* if we are using MONITOR, send it now with new nicks monitored */
    if (server->is_connected && (server->monitor > 0))
        irc_notify_send_monitor (server);
}
Ejemplo n.º 3
0
void
script_config_unhold (const char *name_with_extension)
{
    char **items, *hold;
    int num_items, i, length;

    length = strlen (weechat_config_string (script_config_scripts_hold)) + 1;
    hold = malloc (length);
    if (hold)
    {
        hold[0] = '\0';
        items = weechat_string_split (weechat_config_string (script_config_scripts_hold),
                                      ",", 0, 0, &num_items);
        if (items)
        {
            for (i = 0; i < num_items; i++)
            {
                if (strcmp (items[i], name_with_extension) != 0)
                {
                    if (hold[0])
                        strcat (hold, ",");
                    strcat (hold, items[i]);
                }
            }
            weechat_string_free_split (items);
        }

        weechat_config_option_set (script_config_scripts_hold, hold, 0);

        free (hold);
    }
}
Ejemplo n.º 4
0
void
rmodifier_hook_modifiers (struct t_rmodifier *rmodifier)
{
    char **argv, str_modifier[128];
    int argc, i;

    argv = weechat_string_split (rmodifier->modifiers, ",", 0, 0, &argc);

    if (argv)
    {
        rmodifier->hooks = malloc (sizeof (*rmodifier->hooks) * argc);
        if (rmodifier->hooks)
        {
            for (i = 0; i < argc; i++)
            {
                /*
                 * we use a high priority here, so that other modifiers
                 * (from other plugins) will be called after this one
                 */
                snprintf (str_modifier, sizeof (str_modifier) - 1,
                          "5000|%s", argv[i]);
                rmodifier->hooks[i] = weechat_hook_modifier (str_modifier,
                                                             &rmodifier_modifier_cb,
                                                             rmodifier);
            }
            rmodifier->hooks_count = argc;
        }
        weechat_string_free_split (argv);
    }
}
Ejemplo n.º 5
0
void
weechat_aspell_speller_check_dictionaries (const char *dict_list)
{
    char **argv;
    int argc, i;

    if (dict_list)
    {
        argv = weechat_string_split (dict_list, ",", 0, 0, &argc);
        if (argv)
        {
            for (i = 0; i < argc; i++)
            {
                if (!weechat_aspell_speller_dict_supported (argv[i]))
                {
                    weechat_printf (NULL,
                                    _("%s: warning: dictionary \"%s\" is not "
                                      "available on your system"),
                                    ASPELL_PLUGIN_NAME, argv[i]);
                }
            }
            weechat_string_free_split (argv);
        }
    }
}
Ejemplo n.º 6
0
void
weechat_aspell_create_spellers (struct t_gui_buffer *buffer)
{
    const char *dict_list;
    char **argv;
    int argc, i;

    if (buffer)
    {
        dict_list = weechat_aspell_get_dict (buffer);
        if (!weechat_aspell_spellers_already_ok (dict_list))
        {
            weechat_aspell_speller_free_all ();
            if (dict_list)
            {
                argv = weechat_string_split (dict_list, ",", 0, 0, &argc);
                if (argv)
                {
                    for (i = 0; i < argc; i++)
                    {
                        weechat_aspell_speller_new (argv[i]);
                    }
                    weechat_string_free_split (argv);
                }
            }
        }
    }
}
Ejemplo n.º 7
0
int
weechat_aspell_spellers_already_ok (const char *dict_list)
{
    char **argv;
    int argc, rc, i;
    struct t_aspell_speller *ptr_speller;

    if (!dict_list && !weechat_aspell_spellers)
        return 1;

    if (!dict_list || !weechat_aspell_spellers)
        return 0;

    rc = 0;

    argv = weechat_string_split (dict_list, ",", 0, 0, &argc);
    if (argv)
    {
        ptr_speller = weechat_aspell_spellers;
        for (i = 0; (i < argc) && ptr_speller; i++)
        {
            if (strcmp (ptr_speller->lang, argv[i]) == 0)
            {
                rc = 1;
                break;
            }
            ptr_speller = ptr_speller->next_speller;
        }
        weechat_string_free_split (argv);
    }

    return rc;
}
Ejemplo n.º 8
0
void
relay_config_change_irc_backlog_tags (void *data,
                                      struct t_config_option *option)
{
    char **items;
    int num_items, i;

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

    if (!relay_config_hashtable_irc_backlog_tags)
    {
        relay_config_hashtable_irc_backlog_tags = weechat_hashtable_new (32,
                                                                         WEECHAT_HASHTABLE_STRING,
                                                                         WEECHAT_HASHTABLE_STRING,
                                                                         NULL,
                                                                         NULL);
    }
    else
        weechat_hashtable_remove_all (relay_config_hashtable_irc_backlog_tags);

    items = weechat_string_split (weechat_config_string (relay_config_irc_backlog_tags),
                                  ";", 0, 0, &num_items);
    if (items)
    {
        for (i = 0; i < num_items; i++)
        {
            weechat_hashtable_set (relay_config_hashtable_irc_backlog_tags,
                                   items[i],
                                   NULL);
        }
        weechat_string_free_split (items);
    }
}
Ejemplo n.º 9
0
int
relay_config_check_irc_backlog_tags (void *data,
                                     struct t_config_option *option,
                                     const char *value)
{
    char **tags;
    int num_tags, i, rc;

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

    rc = 1;

    /* "*" means all tags */
    if (strcmp (value, "*") == 0)
        return rc;

    /* split tags and check them */
    tags = weechat_string_split (value, ",", 0, 0, &num_tags);
    if (tags)
    {
        for (i = 0; i < num_tags; i++)
        {
            if (relay_irc_search_backlog_commands_tags (tags[i]) < 0)
            {
                rc = 0;
                break;
            }
        }
        weechat_string_free_split (tags);
    }

    return rc;
}
Ejemplo n.º 10
0
struct t_aspell_speller_buffer *
weechat_aspell_speller_buffer_new (struct t_gui_buffer *buffer)
{
    const char *buffer_dicts;
    char **dicts;
    int num_dicts, i;
    struct t_aspell_speller_buffer *new_speller_buffer;
    AspellSpeller *ptr_speller;

    if (!buffer)
        return NULL;

    weechat_hashtable_remove (weechat_aspell_speller_buffer, buffer);

    new_speller_buffer = malloc (sizeof (*new_speller_buffer));
    if (!new_speller_buffer)
        return NULL;

    new_speller_buffer->spellers = NULL;
    new_speller_buffer->modifier_string = NULL;
    new_speller_buffer->input_pos = -1;
    new_speller_buffer->modifier_result = NULL;

    buffer_dicts = weechat_aspell_get_dict (buffer);
    if (buffer_dicts)
    {
        dicts = weechat_string_split (buffer_dicts, ",", 0, 0, &num_dicts);
        if (dicts && (num_dicts > 0))
        {
            new_speller_buffer->spellers =
                malloc ((num_dicts + 1) * sizeof (AspellSpeller *));
            if (new_speller_buffer->spellers)
            {
                for (i = 0; i < num_dicts; i++)
                {
                    ptr_speller = weechat_hashtable_get (weechat_aspell_spellers,
                                                         dicts[i]);
                    if (!ptr_speller)
                        ptr_speller = weechat_aspell_speller_new (dicts[i]);
                    new_speller_buffer->spellers[i] = ptr_speller;
                }
                new_speller_buffer->spellers[num_dicts] = NULL;
            }
        }
        if (dicts)
            weechat_string_free_split (dicts);
    }

    weechat_hashtable_set (weechat_aspell_speller_buffer,
                           buffer,
                           new_speller_buffer);

    weechat_bar_item_update ("aspell_dict");

    return new_speller_buffer;
}
Ejemplo n.º 11
0
const char *
script_config_get_diff_command ()
{
    const char *diff_command;
    char *dir_separator;
    static char result[64];
    struct stat st;
    char *path, **paths, bin[4096];
    int num_paths, i, rc;

    diff_command = weechat_config_string (script_config_look_diff_command);
    if (!diff_command || !diff_command[0])
        return NULL;

    if (strcmp (diff_command, "auto") == 0)
    {
        dir_separator = weechat_info_get ("dir_separator", "");
        path = getenv ("PATH");
        result[0] = '\0';
        if (dir_separator && path)
        {
            paths = weechat_string_split (path, ":",
                                          WEECHAT_STRING_SPLIT_STRIP_LEFT
                                          | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                          | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                                          0, &num_paths);
            if (paths)
            {
                for (i = 0; i < num_paths; i++)
                {
                    snprintf (bin, sizeof (bin), "%s%s%s",
                              paths[i], dir_separator, "git");
                    rc = stat (bin, &st);
                    if ((rc == 0) && (S_ISREG(st.st_mode)))
                    {
                        snprintf (result, sizeof (result),
                                  "git diff --no-index");
                        break;
                    }
                }
                weechat_string_free_split (paths);
            }
        }
        if (dir_separator)
            free (dir_separator);
        if (!result[0])
            snprintf (result, sizeof (result), "diff");
        return result;
    }

    return diff_command;
}
Ejemplo n.º 12
0
void
relay_weechat_recv (struct t_relay_client *client, const char *data)
{
    char *new_partial, *pos, *tmp, **commands;
    int num_commands, i;

    if (relay_weechat_partial_message)
    {
        new_partial = realloc (relay_weechat_partial_message,
                               strlen (relay_weechat_partial_message) +
                               strlen (data) + 1);
        if (!new_partial)
            return;
        relay_weechat_partial_message = new_partial;
        strcat (relay_weechat_partial_message, data);
    }
    else
        relay_weechat_partial_message = strdup (data);

    pos = strrchr (relay_weechat_partial_message, '\n');
    if (pos)
    {
        pos[0] = '\0';
        commands = weechat_string_split (relay_weechat_partial_message, "\n",
                                         0, 0, &num_commands);
        if (commands)
        {
            for (i = 0; i < num_commands; i++)
            {
                relay_weechat_protocol_recv (client, commands[i]);
            }
            weechat_string_free_split (commands);
        }
        if (pos[1])
        {
            tmp = strdup (pos + 1);
            free (relay_weechat_partial_message);
            relay_weechat_partial_message = tmp;
        }
        else
        {
            free (relay_weechat_partial_message);
            relay_weechat_partial_message = NULL;
        }
    }
}
Ejemplo n.º 13
0
char *
weechat_python_get_python2_bin ()
{
    const char *dir_separator;
    char *py2_bin, *path, **paths, bin[4096];
    char *versions[] = { "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2", NULL };
    int num_paths, i, j, rc;
    struct stat stat_buf;

    py2_bin = NULL;

    dir_separator = weechat_info_get ("dir_separator", "");
    path = getenv ("PATH");

    if (dir_separator && path)
    {
        paths = weechat_string_split (path, ":", 0, 0, &num_paths);
        if (paths)
        {
            for (i = 0; i < num_paths; i++)
            {
                for (j = 0; versions[j]; j++)
                {
                    snprintf (bin, sizeof (bin), "%s%s%s%s",
                              paths[i], dir_separator, "python",
                              versions[j]);
                    rc = stat (bin, &stat_buf);
                    if ((rc == 0) && (S_ISREG(stat_buf.st_mode)))
                    {
                        py2_bin = strdup (bin);
                        break;
                    }
                }
                if (py2_bin)
                    break;
            }
            weechat_string_free_split (paths);
        }
    }

    if (!py2_bin)
        py2_bin = strdup ("python");

    return py2_bin;
}
Ejemplo n.º 14
0
void
script_config_hold (const char *name_with_extension)
{
    char **items, *hold;
    int num_items, i, length;

    length = strlen (weechat_config_string (script_config_scripts_hold)) +
        1 + strlen (name_with_extension) + 1;
    hold = malloc (length);
    if (hold)
    {
        hold[0] = '\0';
        items = weechat_string_split (
            weechat_config_string (script_config_scripts_hold),
            ",",
            WEECHAT_STRING_SPLIT_STRIP_LEFT
            | WEECHAT_STRING_SPLIT_STRIP_RIGHT
            | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
            0,
            &num_items);
        if (items)
        {
            for (i = 0; i < num_items; i++)
            {
                if (strcmp (items[i], name_with_extension) != 0)
                {
                    if (hold[0])
                        strcat (hold, ",");
                    strcat (hold, items[i]);
                }
            }
            weechat_string_free_split (items);
        }
        if (hold[0])
            strcat (hold, ",");
        strcat (hold, name_with_extension);

        weechat_config_option_set (script_config_scripts_hold, hold, 0);

        free (hold);
    }
}
Ejemplo n.º 15
0
void
weechat_aspell_speller_add_dicts_to_hash (struct t_hashtable *hashtable,
                                          const char *dict)
{
    char **dicts;
    int num_dicts, i;

    if (!dict || !dict[0])
        return;

    dicts = weechat_string_split (dict, ",", 0, 0, &num_dicts);
    if (dicts)
    {
        for (i = 0; i < num_dicts; i++)
        {
            weechat_hashtable_set (hashtable, dicts[i], NULL);
        }
        weechat_string_free_split (dicts);
    }
}
Ejemplo n.º 16
0
void
weechat_aspell_config_change_commands (const void *pointer, void *data,
                                       struct t_config_option *option)
{
    const char *value;
    int i;

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

    if (weechat_aspell_commands_to_check)
    {
        weechat_string_free_split (weechat_aspell_commands_to_check);
        weechat_aspell_commands_to_check = NULL;
        weechat_aspell_count_commands_to_check = 0;
    }

    if (weechat_aspell_length_commands_to_check)
    {
        free (weechat_aspell_length_commands_to_check);
        weechat_aspell_length_commands_to_check = NULL;
    }

    value = weechat_config_string (option);
    if (value && value[0])
    {
        weechat_aspell_commands_to_check = weechat_string_split (value,
                                                                 ",", 0, 0,
                                                                 &weechat_aspell_count_commands_to_check);
        if (weechat_aspell_count_commands_to_check > 0)
        {
            weechat_aspell_length_commands_to_check = malloc (weechat_aspell_count_commands_to_check *
                                                              sizeof (int));
            for (i = 0; i < weechat_aspell_count_commands_to_check; i++)
            {
                weechat_aspell_length_commands_to_check[i] = strlen (weechat_aspell_commands_to_check[i]);
            }
        }
    }
}
Ejemplo n.º 17
0
char *
irc_mode_get_arguments (const char *arguments)
{
    char **argv, **argv2, *new_arguments;
    int argc, i;

    if (!arguments || !arguments[0])
        return strdup ("");

    argv = weechat_string_split (arguments, " ",
                                 WEECHAT_STRING_SPLIT_STRIP_LEFT
                                 | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                 | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                                 0, &argc);
    if (!argv)
        return strdup ("");

    argv2 = malloc (sizeof (*argv) * (argc + 1));
    if (!argv2)
    {
        weechat_string_free_split (argv);
        return strdup ("");;
    }

    for (i = 0; i < argc; i++)
    {
        argv2[i] = (argv[i][0] == ':') ? argv[i] + 1 : argv[i];
    }
    argv2[argc] = NULL;

    new_arguments = weechat_string_build_with_split_string (
        (const char **)argv2, " ");

    weechat_string_free_split (argv);
    free (argv2);

    return new_arguments;
}
Ejemplo n.º 18
0
void
buflist_config_change_sort (const void *pointer, void *data,
                            struct t_config_option *option)
{
    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) option;

    if (buflist_config_sort_fields)
        weechat_string_free_split (buflist_config_sort_fields);

    buflist_config_sort_fields = weechat_string_split (
        weechat_config_string (buflist_config_look_sort),
        ",",
        WEECHAT_STRING_SPLIT_STRIP_LEFT
        | WEECHAT_STRING_SPLIT_STRIP_RIGHT
        | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
        0,
        &buflist_config_sort_fields_count);

    buflist_bar_item_update (0);
}
Ejemplo n.º 19
0
void
relay_weechat_protocol_recv (struct t_relay_client *client, const char *data)
{
    char *pos, *id, *command, **argv, **argv_eol;
    int i, argc, return_code;
    struct t_relay_weechat_protocol_cb protocol_cb[] =
        { { "init", &relay_weechat_protocol_cb_init },
          { "hdata", &relay_weechat_protocol_cb_hdata },
          { "info", &relay_weechat_protocol_cb_info },
          { "infolist", &relay_weechat_protocol_cb_infolist },
          { "nicklist", &relay_weechat_protocol_cb_nicklist },
          { "input", &relay_weechat_protocol_cb_input },
          { "sync", &relay_weechat_protocol_cb_sync },
          { "desync", &relay_weechat_protocol_cb_desync },
          { "test", &relay_weechat_protocol_cb_test },
          { "ping", &relay_weechat_protocol_cb_ping },
          { "quit", &relay_weechat_protocol_cb_quit },
          { NULL, NULL }
        };

    if (!data || !data[0] || RELAY_CLIENT_HAS_ENDED(client))
        return;

    /* display debug message */
    if (weechat_relay_plugin->debug >= 2)
    {
        weechat_printf (NULL, "%s: recv from client %s%s%s: \"%s\"",
                        RELAY_PLUGIN_NAME,
                        RELAY_COLOR_CHAT_CLIENT,
                        client->desc,
                        RELAY_COLOR_CHAT,
                        data);
    }

    /* extract id */
    id = NULL;
    if (data[0] == '(')
    {
        pos = strchr (data, ')');
        if (pos)
        {
            id = weechat_strndup (data + 1, pos - data - 1);
            data = pos + 1;
            while (data[0] == ' ')
            {
                data++;
            }
        }
    }

    /* search end of data */
    pos = strchr (data, ' ');
    if (pos)
        command = weechat_strndup (data, pos - data);
    else
        command = strdup (data);

    if (!command)
    {
        if (id)
            free (id);
        return;
    }

    argc = 0;
    argv = NULL;
    argv_eol = NULL;

    if (pos)
    {
        while (pos[0] == ' ')
        {
            pos++;
        }
        argv = weechat_string_split (pos, " ", 0, 0, &argc);
        argv_eol = weechat_string_split (pos, " ", 2, 0, NULL);
    }

    for (i = 0; protocol_cb[i].name; i++)
    {
        if (strcmp (protocol_cb[i].name, command) == 0)
        {
            if ((strcmp (protocol_cb[i].name, "init") != 0)
                && (!RELAY_WEECHAT_DATA(client, password_ok)))
            {
                /*
                 * command is not "init" and password is not set?
                 * then close connection!
                 */
                relay_client_set_status (client,
                                         RELAY_STATUS_AUTH_FAILED);
            }
            else
            {
                return_code = (int) (protocol_cb[i].cmd_function) (client,
                                                                   id,
                                                                   protocol_cb[i].name,
                                                                   argc,
                                                                   argv,
                                                                   argv_eol);
                if ((weechat_relay_plugin->debug >= 1)
                    && (return_code == WEECHAT_RC_ERROR))
                {
                    weechat_printf (NULL,
                                    _("%s%s: failed to execute command \"%s\" "
                                      "for client %s%s%s"),
                                    weechat_prefix ("error"),
                                    RELAY_PLUGIN_NAME,
                                    command,
                                    RELAY_COLOR_CHAT_CLIENT,
                                    client->desc,
                                    RELAY_COLOR_CHAT);
                }
            }
            break;
        }
    }

    if (id)
        free (id);
    free (command);
    if (argv)
        weechat_string_free_split (argv);
    if (argv_eol)
        weechat_string_free_split (argv_eol);
}
Ejemplo n.º 20
0
struct t_hashtable *
irc_message_split (struct t_irc_server *server, const char *message)
{
    struct t_hashtable *hashtable;
    char **argv, **argv_eol, *tags, *host, *command, *arguments, target[512];
    char *pos;
    int split_ok, argc, index_args, max_length_nick, max_length_host;

    split_ok = 0;
    tags = NULL;
    host = NULL;
    command = NULL;
    arguments = NULL;
    index_args = 0;
    argv = NULL;
    argv_eol = NULL;

    /* debug message */
    if (weechat_irc_plugin->debug >= 2)
        weechat_printf (NULL, "irc_message_split: message='%s'", message);

    hashtable = weechat_hashtable_new (32,
                                       WEECHAT_HASHTABLE_STRING,
                                       WEECHAT_HASHTABLE_STRING,
                                       NULL,
                                       NULL);
    if (!hashtable)
        return NULL;

    if (!message || !message[0])
        goto end;

    if (message[0] == '@')
    {
        pos = strchr (message, ' ');
        if (pos)
        {
            tags = weechat_strndup (message, pos - message + 1);
            message = pos + 1;
        }
    }

    argv = weechat_string_split (message, " ", 0, 0, &argc);
    argv_eol = weechat_string_split (message, " ", 2, 0, NULL);

    if (argc < 2)
        goto end;

    if (argv[0][0] == ':')
    {
        if (argc < 3)
            goto end;
        host = argv[0];
        command = argv[1];
        arguments = argv_eol[2];
        index_args = 2;
    }
    else
    {
        command = argv[0];
        arguments = argv_eol[1];
        index_args = 1;
    }

    max_length_nick = (server && (server->nick_max_length > 0)) ?
        server->nick_max_length : 16;
    max_length_host = 1 + /* ":"  */
        max_length_nick + /* nick */
        1 +               /* "!"  */
        63 +              /* host */
        1;                /* " "  */

    if ((weechat_strcasecmp (command, "ison") == 0)
        || (weechat_strcasecmp (command, "wallops") == 0))
    {
        split_ok = irc_message_split_string (hashtable, tags, host, command,
                                             NULL, ":",
                                             (argv_eol[index_args][0] == ':') ?
                                             argv_eol[index_args] + 1 : argv_eol[index_args],
                                             NULL, ' ', max_length_host);
    }
    else if (weechat_strcasecmp (command, "join") == 0)
    {
        /* split join (if it's more than 510 bytes) */
        if (strlen (message) > 510)
        {
            split_ok = irc_message_split_join (hashtable, tags, host,
                                               arguments);
        }
    }
    else if ((weechat_strcasecmp (command, "privmsg") == 0)
             || (weechat_strcasecmp (command, "notice") == 0))
    {
        /* split privmsg/notice */
        if (index_args + 1 <= argc - 1)
        {
            split_ok = irc_message_split_privmsg_notice (hashtable, tags, host,
                                                         command,
                                                         argv[index_args],
                                                         (argv_eol[index_args + 1][0] == ':') ?
                                                         argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1],
                                                         max_length_host);
        }
    }
    else if (weechat_strcasecmp (command, "005") == 0)
    {
        /* split 005 (isupport) */
        if (index_args + 1 <= argc - 1)
        {
            split_ok = irc_message_split_005 (hashtable, tags, host, command,
                                              argv[index_args],
                                              (argv_eol[index_args + 1][0] == ':') ?
                                              argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1]);
        }
    }
    else if (weechat_strcasecmp (command, "353") == 0)
    {
        /*
         * split 353 (list of users on channel):
         *   :server 353 mynick = #channel :mynick nick1 @nick2 +nick3
         */
        if (index_args + 2 <= argc - 1)
        {
            if (irc_channel_is_channel (server, argv[index_args + 1]))
            {
                snprintf (target, sizeof (target), "%s %s",
                          argv[index_args], argv[index_args + 1]);
                split_ok = irc_message_split_string (hashtable, tags, host,
                                                     command, target, ":",
                                                     (argv_eol[index_args + 2][0] == ':') ?
                                                     argv_eol[index_args + 2] + 1 : argv_eol[index_args + 2],
                                                     NULL, ' ', -1);
            }
            else
            {
                if (index_args + 3 <= argc - 1)
                {
                    snprintf (target, sizeof (target), "%s %s %s",
                              argv[index_args], argv[index_args + 1],
                              argv[index_args + 2]);
                    split_ok = irc_message_split_string (hashtable, tags, host,
                                                         command, target, ":",
                                                         (argv_eol[index_args + 3][0] == ':') ?
                                                         argv_eol[index_args + 3] + 1 : argv_eol[index_args + 3],
                                                         NULL, ' ', -1);
                }
            }
        }
    }

end:
    if (!split_ok
        || (weechat_hashtable_get_integer (hashtable, "items_count") == 0))
    {
        irc_message_split_add (hashtable, 1, tags, message, arguments);
    }

    if (tags)
        free (tags);
    if (argv)
        weechat_string_free_split (argv);
    if (argv_eol)
        weechat_string_free_split (argv_eol);

    return hashtable;
}
Ejemplo n.º 21
0
int
irc_message_split_join (struct t_hashtable *hashtable,
                        const char *tags, const char *host,
                        const char *arguments)
{
    int number, channels_count, keys_count, length, length_no_channel;
    int length_to_add, index_channel;
    char **channels, **keys, *pos, *str;
    char msg_to_send[2048], keys_to_add[2048];

    number = 1;

    channels = NULL;
    channels_count = 0;
    keys = NULL;
    keys_count = 0;

    pos = strchr (arguments, ' ');
    if (pos)
    {
        str = weechat_strndup (arguments, pos - arguments);
        if (!str)
            return 0;
        channels = weechat_string_split (str, ",", 0, 0, &channels_count);
        free (str);
        while (pos[0] == ' ')
        {
            pos++;
        }
        if (pos[0])
            keys = weechat_string_split (pos, ",", 0, 0, &keys_count);
    }
    else
    {
        channels = weechat_string_split (arguments, ",", 0, 0, &channels_count);
    }

    snprintf (msg_to_send, sizeof (msg_to_send), "%s%sJOIN",
              (host) ? host : "",
              (host) ? " " : "");
    length = strlen (msg_to_send);
    length_no_channel = length;
    keys_to_add[0] = '\0';
    index_channel = 0;
    while (index_channel < channels_count)
    {
        length_to_add = 1 + strlen (channels[index_channel]);
        if (index_channel < keys_count)
            length_to_add += 1 + strlen (keys[index_channel]);
        if ((length + length_to_add < 510) || (length == length_no_channel))
        {
            if (length + length_to_add < (int)sizeof (msg_to_send))
            {
                strcat (msg_to_send, (length == length_no_channel) ? " " : ",");
                strcat (msg_to_send, channels[index_channel]);
            }
            if (index_channel < keys_count)
            {
                if (strlen (keys_to_add) + 1 +
                    strlen (keys[index_channel]) < (int)sizeof (keys_to_add))
                {
                    strcat (keys_to_add, (keys_to_add[0]) ? "," : " ");
                    strcat (keys_to_add, keys[index_channel]);
                }
            }
            length += length_to_add;
            index_channel++;
        }
        else
        {
            strcat (msg_to_send, keys_to_add);
            irc_message_split_add (hashtable, number,
                                   tags,
                                   msg_to_send,
                                   msg_to_send + length_no_channel + 1);
            number++;
            snprintf (msg_to_send, sizeof (msg_to_send), "%s%sJOIN",
                      (host) ? host : "",
                      (host) ? " " : "");
            length = strlen (msg_to_send);
            keys_to_add[0] = '\0';
        }
    }

    if (length > length_no_channel)
    {
        strcat (msg_to_send, keys_to_add);
        irc_message_split_add (hashtable, number,
                               tags,
                               msg_to_send,
                               msg_to_send + length_no_channel + 1);
    }

    if (channels)
        weechat_string_free_split (channels);
    if (keys)
        weechat_string_free_split (keys);

    return 1;
}
Ejemplo n.º 22
0
void
trigger_hook (struct t_trigger *trigger)
{
    char **argv, **argv_eol, *tags, *message, *error1, *error2, *error3;
    int i, argc, strip_colors;
    long interval, align_second, max_calls;

    trigger_unhook (trigger);

    argv = weechat_string_split (weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]),
                                 ";", 0, 0, &argc);
    argv_eol = weechat_string_split (weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]),
                                     ";", 1, 0, NULL);

    switch (weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK]))
    {
        case TRIGGER_HOOK_SIGNAL:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_signal (
                            argv[i],
                            &trigger_callback_signal_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_HSIGNAL:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_hsignal (
                            argv[i],
                            &trigger_callback_hsignal_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_MODIFIER:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_modifier (
                            argv[i],
                            &trigger_callback_modifier_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_PRINT:
            tags = NULL;
            message = NULL;
            strip_colors = 0;
            if (argv && (argc >= 1))
            {
                if (strcmp (argv[0], "*") != 0)
                    trigger->hook_print_buffers = strdup (argv[0]);
                if ((argc >= 2) && (strcmp (argv[1], "*") != 0))
                    tags = argv[1];
                if ((argc >= 3) && (strcmp (argv[2], "*") != 0))
                    message = argv[2];
                if (argc >= 4)
                    strip_colors = (strcmp (argv[3], "0") != 0) ? 1 : 0;
            }
            trigger->hooks = malloc (sizeof (trigger->hooks[0]));
            if (trigger->hooks)
            {
                trigger->hooks_count = 1;
                trigger->hooks[0] = weechat_hook_print (
                    NULL,
                    tags,
                    message,
                    strip_colors,
                    &trigger_callback_print_cb,
                    trigger);
            }
            break;
        case TRIGGER_HOOK_COMMAND:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = 1;
                    trigger->hooks[0] = weechat_hook_command (
                        argv[0],  /* command */
                        (argc > 1) ? argv[1] : "",  /* description */
                        (argc > 2) ? argv[2] : "",  /* arguments */
                        (argc > 3) ? argv[3] : "",  /* description of args */
                        (argc > 4) ? argv[4] : "",  /* completion */
                        &trigger_callback_command_cb,
                        trigger);
                }
            }
            break;
        case TRIGGER_HOOK_COMMAND_RUN:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_command_run (
                            argv[i],
                            &trigger_callback_command_run_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_TIMER:
            if (argv && (argc >= 1))
            {
                error1 = NULL;
                error2 = NULL;
                error3 = NULL;
                interval = strtol (argv[0], &error1, 10);
                align_second = strtol ((argc >= 2) ? argv[1] : "0", &error2, 10);
                max_calls = strtol ((argc >= 3) ? argv[2] : "0", &error3, 10);
                if (error1 && !error1[0]
                    && error2 && !error2[0]
                    && error3 && !error3[0]
                    && (interval > 0)
                    && (align_second >= 0)
                    && (max_calls >= 0))
                {
                    trigger->hooks = malloc (sizeof (trigger->hooks[0]));
                    if (trigger->hooks)
                    {
                        trigger->hooks_count = 1;
                        trigger->hooks[0] = weechat_hook_timer (
                            interval,
                            (int)align_second,
                            (int)max_calls,
                            &trigger_callback_timer_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_CONFIG:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_config (
                            argv[i],
                            &trigger_callback_config_cb,
                            trigger);
                    }
                }
            }
            break;
        case TRIGGER_HOOK_FOCUS:
            if (argv && (argc >= 1))
            {
                trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
                if (trigger->hooks)
                {
                    trigger->hooks_count = argc;
                    for (i = 0; i < argc; i++)
                    {
                        trigger->hooks[i] = weechat_hook_focus (
                            argv[i],
                            &trigger_callback_focus_cb,
                            trigger);
                    }
                }
            }
            break;
    }

    if (!trigger->hooks)
    {
        weechat_printf (NULL,
                        _("%s%s: unable to create hook for trigger \"%s\" "
                          "(bad arguments)"),
                        weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                        trigger->name);
    }

    if (argv)
        weechat_string_free_split (argv);
    if (argv_eol)
        weechat_string_free_split (argv_eol);
}
Ejemplo n.º 23
0
int
irc_mode_channel_set (struct t_irc_server *server,
                      struct t_irc_channel *channel,
                      const char *modes)
{
    char *pos_args, *str_modes, set_flag, **argv, *pos, *ptr_arg, chanmode_type;
    int argc, current_arg, update_channel_modes, channel_modes_updated;
    int smart_filter;
    struct t_irc_nick *ptr_nick;

    if (!server || !channel || !modes)
        return 0;

    channel_modes_updated = 0;
    argc = 0;
    argv = NULL;
    pos_args = strchr (modes, ' ');
    if (pos_args)
    {
        str_modes = weechat_strndup (modes, pos_args - modes);
        if (!str_modes)
            return 0;
        pos_args++;
        while (pos_args[0] == ' ')
            pos_args++;
        argv = weechat_string_split (pos_args, " ", 0, 0, &argc);
    }
    else
    {
        str_modes = strdup (modes);
        if (!str_modes)
            return 0;
    }

    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;

    if (str_modes && str_modes[0])
    {
        set_flag = '+';
        pos = str_modes;
        while (pos && pos[0])
        {
            switch (pos[0])
            {
                case ':':
                case ' ':
                    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)
                        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]);
                                if (smart_filter
                                    && irc_channel_nick_speaking_time_search (server,
                                                                              channel,
                                                                              ptr_nick->name,
                                                                              1))
                                {
                                    smart_filter = 0;
                                }
                            }
                        }
                    }
                    if (update_channel_modes)
                    {
                        irc_mode_channel_update (server, channel, set_flag,
                                                 pos[0], ptr_arg);
                        channel_modes_updated = 1;
                    }
                    break;
            }
            pos++;
        }
    }

    if (str_modes)
        free (str_modes);
    if (argv)
        weechat_string_free_split (argv);

    if (channel_modes_updated)
        weechat_bar_item_update ("buffer_modes");

    return smart_filter;
}
Ejemplo n.º 24
0
void
relay_weechat_msg_add_infolist (struct t_relay_weechat_msg *msg,
                                const char *name,
                                void *pointer,
                                const char *arguments)
{
    struct t_infolist *ptr_infolist;
    const char *fields;
    char **list_fields;
    void *buf_ptr;
    int num_fields, i, buf_size;
    int pos_count_items, count_items, pos_count_vars, count_vars;
    uint32_t count32;

    ptr_infolist = weechat_infolist_get (name, pointer, arguments);
    if (!ptr_infolist)
        return;

    /* start infolist in message */
    relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INFOLIST);
    relay_weechat_msg_add_string (msg, name);

    /* count of items will be set later, with number of items in infolist */
    pos_count_items = msg->data_size;
    count_items = 0;
    relay_weechat_msg_add_int (msg, 0);

    while (weechat_infolist_next (ptr_infolist))
    {
        fields = weechat_infolist_fields (ptr_infolist);
        if (fields)
        {
            list_fields = weechat_string_split (fields, ",", 0, 0, &num_fields);
            if (list_fields)
            {
                count_items++;
                pos_count_vars = msg->data_size;
                count_vars = 0;
                relay_weechat_msg_add_int (msg, 0);
                for (i = 0; i < num_fields; i++)
                {
                    if (strlen (list_fields[i]) > 2)
                    {
                        count_vars++;
                        relay_weechat_msg_add_string (msg, list_fields[i] + 2);
                        switch (list_fields[i][0])
                        {
                            case 'i':
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
                                relay_weechat_msg_add_int (msg,
                                                           weechat_infolist_integer (ptr_infolist,
                                                                                     list_fields[i] + 2));
                                break;
                            case 's':
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
                                relay_weechat_msg_add_string (msg,
                                                              weechat_infolist_string (ptr_infolist,
                                                                                       list_fields[i] + 2));
                                break;
                            case 'p':
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
                                relay_weechat_msg_add_pointer (msg,
                                                               weechat_infolist_pointer (ptr_infolist,
                                                                                         list_fields[i] + 2));
                                break;
                            case 'b':
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_BUFFER);
                                buf_ptr = weechat_infolist_buffer (ptr_infolist,
                                                                   list_fields[i] + 2,
                                                                   &buf_size);
                                relay_weechat_msg_add_buffer (msg, buf_ptr, buf_size);
                                break;
                            case 't':
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
                                relay_weechat_msg_add_time (msg,
                                                            weechat_infolist_time (ptr_infolist,
                                                                                   list_fields[i] + 2));
                                break;
                        }
                    }
                }

                /* set count of variables in item */
                count32 = htonl ((uint32_t)count_vars);
                relay_weechat_msg_set_bytes (msg, pos_count_vars, &count32, 4);

                weechat_string_free_split (list_fields);
            }
        }
    }

    /* set count of items */
    count32 = htonl ((uint32_t)count_items);
    relay_weechat_msg_set_bytes (msg, pos_count_items, &count32, 4);

    weechat_infolist_free (ptr_infolist);
}
Ejemplo n.º 25
0
int
trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
                         char **argv, char **argv_eol)
{
    struct t_trigger *ptr_trigger, *ptr_trigger2;
    struct t_trigger_regex *regex;
    char *value, **sargv, **items, input[1024], str_pos[16];
    int rc, i, type, count, index_option, enable, sargc, num_items, add_rc;
    int regex_count, regex_rc;

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

    rc = WEECHAT_RC_OK;
    sargv = NULL;

    /* list all triggers */
    if ((argc == 1)
        || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0)))
    {
        trigger_command_list (_("List of triggers:"), 0);
        goto end;
    }

    /* full list of all triggers */
    if ((argc == 2) && (weechat_strcasecmp (argv[1], "listfull") == 0))
    {
        trigger_command_list (_("List of triggers:"), 1);
        goto end;
    }

    /* list of default triggers */
    if ((argc == 2) && (weechat_strcasecmp (argv[1], "listdefault") == 0))
    {
        trigger_command_list_default (1);
        goto end;
    }

    /* add a trigger */
    if ((weechat_strcasecmp (argv[1], "add") == 0)
        || (weechat_strcasecmp (argv[1], "addoff") == 0)
        || (weechat_strcasecmp (argv[1], "addreplace") == 0))
    {
        sargv = weechat_string_split_shell (argv_eol[2], &sargc);
        if (!sargv || (sargc < 2))
            goto error;
        if (!trigger_name_valid (sargv[0]))
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: invalid name for trigger"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
            goto end;
        }
        type = trigger_search_hook_type (sargv[1]);
        if (type < 0)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: invalid hook type \"%s\""),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 sargv[1]);
            goto end;
        }
        if ((sargc > 4) && sargv[4][0])
        {
            regex_count = 0;
            regex = NULL;
            regex_rc = trigger_regex_split (sargv[4], &regex_count, &regex);
            trigger_regex_free (&regex_count, &regex);
            switch (regex_rc)
            {
                case 0: /* OK */
                    break;
                case -1: /* format error */
                    weechat_printf (NULL,
                                    _("%s%s: invalid format for regular "
                                      "expression"),
                                    weechat_prefix ("error"),
                                    TRIGGER_PLUGIN_NAME);
                    goto end;
                    break;
                case -2: /* regex compilation error */
                    weechat_printf (NULL,
                                    _("%s%s: invalid regular expression "
                                      "(compilation failed)"),
                                    weechat_prefix ("error"),
                                    TRIGGER_PLUGIN_NAME);
                    goto end;
                    break;
                case -3: /* memory error */
                    weechat_printf (NULL,
                                    _("%s%s: not enough memory"),
                                    weechat_prefix ("error"),
                                    TRIGGER_PLUGIN_NAME);
                    goto end;
                    break;
            }
        }
        if ((sargc > 6) && sargv[6][0]
            && (trigger_search_return_code (sargv[6]) < 0))
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: invalid return code \"%s\""),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 sargv[6]);
            goto end;
        }
        ptr_trigger = trigger_search (sargv[0]);
        if (ptr_trigger)
        {
            if (weechat_strcasecmp (argv[1], "addreplace") == 0)
            {
                if (ptr_trigger)
                    trigger_free (ptr_trigger);
            }
            else
            {
                weechat_printf_tags (NULL, "no_trigger",
                                     _("%s%s: trigger \"%s\" already exists "
                                       "(choose another name or use option "
                                       "\"addreplace\" to overwrite it)"),
                                     weechat_prefix ("error"),
                                     TRIGGER_PLUGIN_NAME, sargv[0]);
                goto end;
            }
        }
        ptr_trigger = trigger_alloc (sargv[0]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: failed to create trigger \"%s\""),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 sargv[0]);
            goto end;
        }
        ptr_trigger = trigger_new (
            sargv[0],                      /* name */
            (weechat_strcasecmp (argv[1], "addoff") == 0) ? "off" : "on",
            sargv[1],                      /* hook */
            (sargc > 2) ? sargv[2] : "",   /* arguments */
            (sargc > 3) ? sargv[3] : "",   /* conditions */
            (sargc > 4) ? sargv[4] : "",   /* regex */
            (sargc > 5) ? sargv[5] : "",   /* command */
            (sargc > 6) ? sargv[6] : "");  /* return code */
        if (ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("Trigger \"%s\" created"), sargv[0]);
        }
        else
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: failed to create trigger \"%s\""),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 sargv[0]);
        }
        goto end;
    }

    /* add trigger command in input (to help trigger creation) */
    if (weechat_strcasecmp (argv[1], "addinput") == 0)
    {
        type = TRIGGER_HOOK_SIGNAL;
        if (argc >= 3)
        {
            type = trigger_search_hook_type (argv[2]);
            if (type < 0)
            {
                weechat_printf_tags (NULL, "no_trigger",
                                     _("%s%s: invalid hook type \"%s\""),
                                     weechat_prefix ("error"),
                                     TRIGGER_PLUGIN_NAME, argv[2]);
                goto end;
            }
        }
        items = weechat_string_split (trigger_hook_default_rc[type], ",", 0, 0,
                                      &num_items);
        snprintf (input, sizeof (input),
                  "/trigger add name %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s",
                  trigger_hook_type_string[type],
                  trigger_hook_default_arguments[type],
                  TRIGGER_HOOK_DEFAULT_CONDITIONS,
                  TRIGGER_HOOK_DEFAULT_REGEX,
                  TRIGGER_HOOK_DEFAULT_COMMAND,
                  (items && (num_items > 0)) ? " \"" : "",
                  (items && (num_items > 0)) ? items[0] : "",
                  (items && (num_items > 0)) ? "\"" : "");
        weechat_buffer_set (buffer, "input", input);
        weechat_buffer_set (buffer, "input_pos", "13");
        goto end;
    }

    /*
     * get command to create a trigger, and according to option:
     * - input: put the command in input
     * - output: send the command to the buffer
     * - recreate: same as input, but the trigger is first deleted
     */
    if ((weechat_strcasecmp (argv[1], "input") == 0)
        || (weechat_strcasecmp (argv[1], "output") == 0)
        || (weechat_strcasecmp (argv[1], "recreate") == 0))
    {
        if (argc < 3)
            goto error;
        ptr_trigger = trigger_search (argv[2]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" not found"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[2]);
            goto end;
        }
        add_rc = trigger_hook_default_rc[weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_HOOK])][0];
        snprintf (input, sizeof (input),
                  "//trigger %s %s %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s",
                  (weechat_strcasecmp (argv[1], "recreate") == 0) ? "addreplace" : "add",
                  ptr_trigger->name,
                  weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_HOOK]),
                  weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_ARGUMENTS]),
                  weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_CONDITIONS]),
                  weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_REGEX]),
                  weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_COMMAND]),
                  (add_rc) ? " \"" : "",
                  (add_rc) ? weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]) : "",
                  (add_rc) ? "\"" : "");
        if (weechat_strcasecmp (argv[1], "output") == 0)
        {
            weechat_command (buffer, input);
        }
        else
        {
            weechat_buffer_set (buffer, "input", input + 1);
            snprintf (str_pos, sizeof (str_pos),
                      "%d", weechat_utf8_strlen (input + 1));
            weechat_buffer_set (buffer, "input_pos", str_pos);
        }
        goto end;
    }

    /* set option in a trigger */
    if (weechat_strcasecmp (argv[1], "set") == 0)
    {
        if (argc < 5)
            goto error;
        ptr_trigger = trigger_search (argv[2]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" not found"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[2]);
            goto end;
        }
        if (weechat_strcasecmp (argv[3], "name") == 0)
        {
            trigger_command_rename (ptr_trigger, argv[4]);
            goto end;
        }
        value = weechat_string_remove_quotes (argv_eol[4], "'\"");
        if (value)
        {
            index_option = trigger_search_option (argv[3]);
            if (index_option >= 0)
            {
                weechat_config_option_set (ptr_trigger->options[index_option],
                                           value, 1);
                weechat_printf_tags (NULL, "no_trigger",
                                     _("Trigger \"%s\" updated"),
                                     ptr_trigger->name);
            }
            else
            {
                weechat_printf_tags (NULL, "no_trigger",
                                     _("%s%s: trigger option \"%s\" not "
                                       "found"),
                                     weechat_prefix ("error"),
                                     TRIGGER_PLUGIN_NAME, argv[3]);
            }
            free (value);
        }
        goto end;
    }

    /* rename a trigger */
    if (weechat_strcasecmp (argv[1], "rename") == 0)
    {
        if (argc < 4)
            goto error;
        ptr_trigger = trigger_search (argv[2]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" not found"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[2]);
            goto end;
        }
        trigger_command_rename (ptr_trigger, argv[3]);
        goto end;
    }

    /* copy a trigger */
    if (weechat_strcasecmp (argv[1], "copy") == 0)
    {
        if (argc < 4)
            goto error;
        ptr_trigger = trigger_search (argv[2]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" not found"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[2]);
            goto end;
        }
        /* check that new name is valid */
        if (!trigger_name_valid (argv[3]))
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: invalid name for trigger"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
            goto end;
        }
        /* check that no trigger already exists with the new name */
        if (trigger_search (argv[3]))
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" already "
                                   "exists"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[3]);
            goto end;
        }
        /* copy the trigger */
        ptr_trigger2 = trigger_copy (ptr_trigger, argv[3]);
        if (ptr_trigger2)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("Trigger \"%s\" copied to \"%s\""),
                                 ptr_trigger->name, ptr_trigger2->name);
        }
        else
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: failed to copy trigger "
                                   "\"%s\""),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 ptr_trigger->name);
        }
        goto end;
    }

    /* enable/disable/toggle/restart trigger(s) */
    if ((weechat_strcasecmp (argv[1], "enable") == 0)
        || (weechat_strcasecmp (argv[1], "disable") == 0)
        || (weechat_strcasecmp (argv[1], "toggle") == 0)
        || (weechat_strcasecmp (argv[1], "restart") == 0))
    {
        if (argc < 3)
        {
            if (weechat_strcasecmp (argv[1], "restart") == 0)
                goto error;
            if (weechat_strcasecmp (argv[1], "enable") == 0)
                weechat_config_option_set (trigger_config_look_enabled, "1", 1);
            else if (weechat_strcasecmp (argv[1], "disable") == 0)
                weechat_config_option_set (trigger_config_look_enabled, "0", 1);
            else if (weechat_strcasecmp (argv[1], "toggle") == 0)
            {
                weechat_config_option_set (trigger_config_look_enabled,
                                           (trigger_enabled) ? "0" : "1",
                                           1);
            }
            trigger_command_display_status ();
            goto end;
        }
        enable = -1;
        if (weechat_strcasecmp (argv[1], "enable") == 0)
            enable = 1;
        else if (weechat_strcasecmp (argv[1], "disable") == 0)
            enable = 0;
        else if (weechat_strcasecmp (argv[1], "restart") == 0)
            enable = 2;
        if (weechat_strcasecmp (argv[2], "-all") == 0)
        {
            for (ptr_trigger = triggers; ptr_trigger;
                 ptr_trigger = ptr_trigger->next_trigger)
            {
                trigger_command_set_enabled (ptr_trigger, enable, 0);
            }
        }
        else
        {
            for (i = 2; i < argc; i++)
            {
                ptr_trigger = trigger_search (argv[i]);
                if (ptr_trigger)
                    trigger_command_set_enabled (ptr_trigger, enable, 1);
                else
                {
                    weechat_printf_tags (NULL, "no_trigger",
                                         _("%sTrigger \"%s\" not found"),
                                         weechat_prefix ("error"), argv[i]);
                }
            }
        }
        goto end;
    }

    /* delete trigger(s) */
    if (weechat_strcasecmp (argv[1], "del") == 0)
    {
        if (argc < 3)
            goto error;
        if (weechat_strcasecmp (argv[2], "-all") == 0)
        {
            count = triggers_count;
            trigger_free_all ();
            if (count > 0)
                weechat_printf_tags (NULL, "no_trigger",
                                     _("%d triggers removed"), count);
        }
        else
        {
            for (i = 2; i < argc; i++)
            {
                ptr_trigger = trigger_search (argv[i]);
                if (ptr_trigger)
                {
                    trigger_free (ptr_trigger);
                    weechat_printf_tags (NULL, "no_trigger",
                                         _("Trigger \"%s\" removed"), argv[i]);
                }
                else
                {
                    weechat_printf_tags (NULL, "no_trigger",
                                         _("%sTrigger \"%s\" not found"),
                                         weechat_prefix ("error"), argv[i]);
                }
            }
        }
        goto end;
    }

    /* show detailed info on a trigger */
    if (weechat_strcasecmp (argv[1], "show") == 0)
    {
        if (argc < 3)
            goto error;
        ptr_trigger = trigger_search (argv[2]);
        if (!ptr_trigger)
        {
            weechat_printf_tags (NULL, "no_trigger",
                                 _("%s%s: trigger \"%s\" not found"),
                                 weechat_prefix ("error"), TRIGGER_PLUGIN_NAME,
                                 argv[2]);
            goto end;
        }
        weechat_printf_tags (NULL, "no_trigger", "");
        weechat_printf_tags (NULL, "no_trigger", _("Trigger:"));
        trigger_command_display_trigger (ptr_trigger, 2);
        goto end;
    }

    /* restore default triggers */
    if (weechat_strcasecmp (argv[1], "default") == 0)
    {
        if ((argc >= 3) && (weechat_strcasecmp (argv[2], "-yes") == 0))
        {
            trigger_free_all ();
            trigger_create_default ();
            trigger_command_list (_("Default triggers restored:"), 0);
        }
        else
        {
            weechat_printf (NULL,
                            _("%s%s: \"-yes\" argument is required for "
                              "restoring default triggers (security reason)"),
                            weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
        }
        goto end;
    }

    /* open the trigger monitor buffer */
    if (weechat_strcasecmp (argv[1], "monitor") == 0)
    {
        trigger_buffer_open ((argc > 2) ? argv_eol[2] : NULL, 1);
        goto end;
    }

error:
    rc = WEECHAT_RC_ERROR;

end:
    if (sargv)
        weechat_string_free_split (sargv);

    return rc;
}
Ejemplo n.º 26
0
void
relay_weechat_msg_add_hdata (struct t_relay_weechat_msg *msg,
                             const char *path, const char *keys)
{
    struct t_hdata *ptr_hdata_head, *ptr_hdata;
    char *hdata_head, *pos, **list_keys, *keys_types, **list_path;
    char *path_returned;
    const char *hdata_name, *array_size;
    void *pointer, **path_pointers;
    long unsigned int value;
    int num_keys, num_path, i, type, pos_count, count, rc;
    uint32_t count32;

    hdata_head = NULL;
    list_keys = NULL;
    num_keys = 0;
    keys_types = NULL;
    list_path = NULL;
    num_path = 0;
    path_returned = NULL;

    /* extract hdata name (head) from path */
    pos = strchr (path, ':');
    if (!pos)
        goto end;
    hdata_head = weechat_strndup (path, pos - path);
    if (!hdata_head)
        goto end;
    ptr_hdata_head = weechat_hdata_get (hdata_head);
    if (!ptr_hdata_head)
        goto end;

    /* split path */
    list_path = weechat_string_split (pos + 1, "/", 0, 0, &num_path);
    if (!list_path)
        goto end;

    /* extract pointer from first path (direct pointer or list name) */
    pointer = NULL;
    pos = strchr (list_path[0], '(');
    if (pos)
        pos[0] = '\0';
    if (strncmp (list_path[0], "0x", 2) == 0)
    {
        rc = sscanf (list_path[0], "%lx", &value);
        if ((rc != EOF) && (rc != 0))
            pointer = (void *)value;
    }
    else
        pointer = weechat_hdata_get_list (ptr_hdata_head, list_path[0]);
    if (pos)
        pos[0] = '(';
    if (!pointer)
        goto end;

    /*
     * build string with path where:
     * - counters are removed
     * - variable names are replaced by hdata name
     */
    path_returned = malloc (strlen (path) * 2);
    if (!path_returned)
        goto end;
    ptr_hdata = ptr_hdata_head;
    strcpy (path_returned, hdata_head);
    hdata_name = hdata_head;
    for (i = 1; i < num_path; i++)
    {
        pos = strchr (list_path[i], '(');
        if (pos)
            pos[0] = '\0';
        hdata_name = weechat_hdata_get_var_hdata (ptr_hdata, list_path[i]);
        if (!hdata_name)
            goto end;
        ptr_hdata = weechat_hdata_get (hdata_name);
        if (!ptr_hdata)
            goto end;
        strcat (path_returned, "/");
        strcat (path_returned, hdata_name);
        if (pos)
            pos[0] = '(';
    }

    /* split keys */
    if (!keys)
        keys = weechat_hdata_get_string (ptr_hdata, "var_keys");
    list_keys = weechat_string_split (keys, ",", 0, 0, &num_keys);
    if (!list_keys)
        goto end;

    /* build string with list of keys with types: "key1:type1,key2:type2,..." */
    keys_types = malloc (strlen (keys) + (num_keys * 8) + 1);
    if (!keys_types)
        goto end;
    keys_types[0] = '\0';
    for (i = 0; i < num_keys; i++)
    {
        type = weechat_hdata_get_var_type (ptr_hdata, list_keys[i]);
        if ((type >= 0) && (type != WEECHAT_HDATA_OTHER))
        {
            if (keys_types[0])
                strcat (keys_types, ",");
            strcat (keys_types, list_keys[i]);
            strcat (keys_types, ":");
            array_size = weechat_hdata_get_var_array_size_string (ptr_hdata,
                                                                  NULL,
                                                                  list_keys[i]);
            if (array_size)
                strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_ARRAY);
            else
            {
                switch (type)
                {
                    case WEECHAT_HDATA_CHAR:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_CHAR);
                        break;
                    case WEECHAT_HDATA_INTEGER:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_INT);
                        break;
                    case WEECHAT_HDATA_LONG:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_LONG);
                        break;
                    case WEECHAT_HDATA_STRING:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_STRING);
                        break;
                    case WEECHAT_HDATA_POINTER:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_POINTER);
                        break;
                    case WEECHAT_HDATA_TIME:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_TIME);
                        break;
                    case WEECHAT_HDATA_HASHTABLE:
                        strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_HASHTABLE);
                        break;
                }
            }
        }
    }
    if (!keys_types[0])
        goto end;

    /* start hdata in message */
    relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_HDATA);
    relay_weechat_msg_add_string (msg, path_returned);
    relay_weechat_msg_add_string (msg, keys_types);

    /* "count" will be set later, with number of objects in hdata */
    pos_count = msg->data_size;
    count = 0;
    relay_weechat_msg_add_int (msg, 0);
    path_pointers = malloc (sizeof (*path_pointers) * num_path);
    if (path_pointers)
    {
        count = relay_weechat_msg_add_hdata_path (msg,
                                                  list_path,
                                                  0,
                                                  path_pointers,
                                                  ptr_hdata_head,
                                                  pointer,
                                                  list_keys);
        free (path_pointers);
    }
    count32 = htonl ((uint32_t)count);
    relay_weechat_msg_set_bytes (msg, pos_count, &count32, 4);

end:
    if (list_keys)
        weechat_string_free_split (list_keys);
    if (keys_types)
        free (keys_types);
    if (list_path)
        weechat_string_free_split (list_path);
    if (path_returned)
        free (path_returned);
    if (hdata_head)
        free (hdata_head);
}
Ejemplo n.º 27
0
char *
trigger_callback_modifier_cb (void *data, const char *modifier,
                              const char *modifier_data, const char *string)
{
    struct t_gui_buffer *buffer;
    const char *ptr_string;
    char *string_modified, *pos, *pos2, *plugin_name, *buffer_name;
    char *buffer_full_name, *str_tags, **tags, *prefix, *string_no_color;
    int length, num_tags;

    TRIGGER_CALLBACK_CB_INIT(NULL);

    buffer = NULL;
    tags = NULL;
    num_tags = 0;
    string_no_color = NULL;

    /* split IRC message (if string is an IRC message) */
    if ((strncmp (modifier, "irc_in_", 7) == 0)
        || (strncmp (modifier, "irc_in2_", 8) == 0)
        || (strncmp (modifier, "irc_out1_", 9) == 0)
        || (strncmp (modifier, "irc_out_", 8) == 0))
    {
        extra_vars = trigger_callback_irc_message_parse (string,
                                                         modifier_data);
        if (extra_vars)
            weechat_hashtable_set (extra_vars, "server", modifier_data);
    }

    TRIGGER_CALLBACK_CB_NEW_POINTERS;
    if (!extra_vars)
    {
        TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
    }

    /* add data in hashtable used for conditions/replace/command */
    weechat_hashtable_set (extra_vars, "tg_modifier", modifier);
    weechat_hashtable_set (extra_vars, "tg_modifier_data", modifier_data);
    weechat_hashtable_set (extra_vars, "tg_string", string);
    string_no_color = weechat_string_remove_color (string, NULL);
    if (string_no_color)
    {
        weechat_hashtable_set (extra_vars,
                               "tg_string_nocolor", string_no_color);
    }

    /* add special variables for a WeeChat message */
    if (strcmp (modifier, "weechat_print") == 0)
    {
        /* set "tg_prefix" and "tg_message" */
        pos = strchr (string, '\t');
        if (pos)
        {
            if (pos > string)
            {
                prefix = weechat_strndup (string, pos - string);
                if (prefix)
                {
                    weechat_hashtable_set (extra_vars, "tg_prefix", prefix);
                    free (prefix);
                }
            }
            pos++;
            if (pos[0] == '\t')
                pos++;
            weechat_hashtable_set (extra_vars, "tg_message", pos);
        }
        else
            weechat_hashtable_set (extra_vars, "tg_message", string);

        /* set "tg_prefix_nocolor" and "tg_message_nocolor" */
        if (string_no_color)
        {
            pos = strchr (string_no_color, '\t');
            if (pos)
            {
                if (pos > string_no_color)
                {
                    prefix = weechat_strndup (string_no_color,
                                              pos - string_no_color);
                    if (prefix)
                    {
                        weechat_hashtable_set (extra_vars,
                                               "tg_prefix_nocolor", prefix);
                        free (prefix);
                    }
                }
                pos++;
                if (pos[0] == '\t')
                    pos++;
                weechat_hashtable_set (extra_vars, "tg_message_nocolor", pos);
            }
            else
            {
                weechat_hashtable_set (extra_vars,
                                       "tg_message_nocolor", string_no_color);
            }
        }

        /*
         * extract buffer/tags from modifier data
         * (format: "plugin;buffer_name;tags")
         */
        pos = strchr (modifier_data, ';');
        if (pos)
        {
            plugin_name = weechat_strndup (modifier_data, pos - modifier_data);
            if (plugin_name)
            {
                weechat_hashtable_set (extra_vars, "tg_plugin", plugin_name);
                pos++;
                pos2 = strchr (pos, ';');
                if (pos2)
                {
                    buffer_name = weechat_strndup (pos, pos2 - pos);
                    if (buffer_name)
                    {
                        buffer = weechat_buffer_search (plugin_name,
                                                        buffer_name);
                        length = strlen (plugin_name) + 1 + strlen (buffer_name) + 1;
                        buffer_full_name = malloc (length);
                        if (buffer_full_name)
                        {
                            snprintf (buffer_full_name, length,
                                      "%s.%s", plugin_name, buffer_name);
                            weechat_hashtable_set (extra_vars, "tg_buffer",
                                                   buffer_full_name);
                            free (buffer_full_name);
                        }
                        free (buffer_name);
                    }
                    pos2++;
                    if (pos2[0])
                    {
                        tags = weechat_string_split (pos2, ",", 0, 0, &num_tags);
                        length = 1 + strlen (pos2) + 1 + 1;
                        str_tags = malloc (length);
                        if (str_tags)
                        {
                            snprintf (str_tags, length, ",%s,", pos2);
                            weechat_hashtable_set (extra_vars, "tg_tags",
                                                   str_tags);
                            free (str_tags);
                        }
                    }
                }
                free (plugin_name);
            }
        }
        weechat_hashtable_set (pointers, "buffer", buffer);
    }

    if (tags)
    {
        if (!trigger_callback_set_tags (buffer, (const char **)tags, num_tags,
                                        extra_vars))
        {
            goto end;
        }
    }

    /* execute the trigger (conditions, regex, command) */
    trigger_callback_execute (trigger, buffer, pointers, extra_vars);

end:
    ptr_string = weechat_hashtable_get (extra_vars, "tg_string");
    string_modified = (ptr_string && (strcmp (ptr_string, string) != 0)) ?
        strdup (ptr_string) : NULL;

    if (tags)
        weechat_string_free_split (tags);
    if (string_no_color)
        free (string_no_color);

    TRIGGER_CALLBACK_CB_END(string_modified);
}
Ejemplo n.º 28
0
void
irc_mode_channel_update (struct t_irc_server *server,
                         struct t_irc_channel *channel,
                         char set_flag,
                         char chanmode,
                         const char *argument)
{
    char *pos_args, *str_modes, **argv, *pos, *ptr_arg;
    char *new_modes, *new_args, str_mode[2], *str_temp;
    int argc, current_arg, chanmode_found, length;

    if (!channel->modes)
        channel->modes = strdup ("+");
    if (!channel->modes)
        return;

    argc = 0;
    argv = NULL;
    pos_args = strchr (channel->modes, ' ');
    if (pos_args)
    {
        str_modes = weechat_strndup (channel->modes, pos_args - channel->modes);
        if (!str_modes)
            return;
        pos_args++;
        while (pos_args[0] == ' ')
            pos_args++;
        argv = weechat_string_split (pos_args, " ",
                                     WEECHAT_STRING_SPLIT_STRIP_LEFT
                                     | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                                     | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                                     0, &argc);
    }
    else
    {
        str_modes = strdup (channel->modes);
        if (!str_modes)
            return;
    }

    new_modes = malloc (strlen (channel->modes) + 1 + 1);
    new_args = malloc (((pos_args) ? strlen (pos_args) : 0)
                       + ((argument) ? 1 + strlen (argument) : 0) + 1);
    if (new_modes && new_args)
    {
        new_modes[0] = '\0';
        new_args[0] = '\0';

        /* loop on current modes and build "new_modes" + "new_args" */
        current_arg = 0;
        chanmode_found = 0;
        pos = str_modes;
        while (pos && pos[0])
        {
            if ((pos[0] == '+') || (pos[0] == '-'))
            {
                str_mode[0] = pos[0];
                str_mode[1] = '\0';
                strcat (new_modes, str_mode);
            }
            else
            {
                ptr_arg = NULL;
                switch (irc_mode_get_chanmode_type (server, pos[0]))
                {
                    case 'A': /* always argument */
                    case 'B': /* always argument */
                    case 'C': /* argument if set */
                        ptr_arg = (current_arg < argc) ?
                            argv[current_arg] : NULL;
                        break;
                    case 'D': /* no argument */
                        break;
                }
                if (ptr_arg)
                    current_arg++;
                if (pos[0] == chanmode)
                {
                    chanmode_found = 1;
                    if (set_flag == '+')
                    {
                        str_mode[0] = pos[0];
                        str_mode[1] = '\0';
                        strcat (new_modes, str_mode);
                        if (argument)
                        {
                            if (new_args[0])
                                strcat (new_args, " ");
                            strcat (new_args, argument);
                        }
                    }
                }
                else
                {
                    str_mode[0] = pos[0];
                    str_mode[1] = '\0';
                    strcat (new_modes, str_mode);
                    if (ptr_arg)
                    {
                        if (new_args[0])
                            strcat (new_args, " ");
                        strcat (new_args, ptr_arg);
                    }
                }
            }
            pos++;
        }
        if (!chanmode_found)
        {
            /*
             * chanmode was not in channel modes: if set_flag is '+', add
             * it to channel modes
             */
            if (set_flag == '+')
            {
                if (argument)
                {
                    /* add mode with argument at the end of modes */
                    str_mode[0] = chanmode;
                    str_mode[1] = '\0';
                    strcat (new_modes, str_mode);
                    if (new_args[0])
                        strcat (new_args, " ");
                    strcat (new_args, argument);
                }
                else
                {
                    /* add mode without argument at the beginning of modes */
                    pos = new_modes;
                    while (pos[0] == '+')
                        pos++;
                    memmove (pos + 1, pos, strlen (pos) + 1);
                    pos[0] = chanmode;
                }
            }
        }
        if (new_args[0])
        {
            length = strlen (new_modes) + 1 + strlen (new_args) + 1;
            str_temp = malloc (length);
            if (str_temp)
            {
                snprintf (str_temp, length, "%s %s", new_modes, new_args);
                if (channel->modes)
                    free (channel->modes);
                channel->modes = str_temp;
            }
        }
        else
        {
            if (channel->modes)
                free (channel->modes);
            channel->modes = strdup (new_modes);
        }
    }

    if (new_modes)
        free (new_modes);
    if (new_args)
        free (new_args);
    if (str_modes)
        free (str_modes);
    if (argv)
        weechat_string_free_split (argv);
}
Ejemplo n.º 29
0
int
irc_upgrade_read_cb (void *data,
                     struct t_upgrade_file *upgrade_file,
                     int object_id,
                     struct t_infolist *infolist)
{
    int flags, sock, size, i, index, nicks_count, num_items;
    long number;
    time_t join_time;
    char *buf, option_name[64], **nicks, *nick_join, *pos, *error;
    char **items;
    const char *buffer_name, *str, *nick;
    struct t_irc_nick *ptr_nick;
    struct t_irc_redirect *ptr_redirect;
    struct t_irc_notify *ptr_notify;
    struct t_gui_buffer *ptr_buffer;

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

    weechat_infolist_reset_item_cursor (infolist);
    while (weechat_infolist_next (infolist))
    {
        switch (object_id)
        {
            case IRC_UPGRADE_TYPE_SERVER:
                irc_upgrade_current_server = irc_server_search (weechat_infolist_string (infolist, "name"));
                if (irc_upgrade_current_server)
                {
                    irc_upgrade_current_server->temp_server =
                        weechat_infolist_integer (infolist, "temp_server");
                    irc_upgrade_current_server->buffer = NULL;
                    buffer_name = weechat_infolist_string (infolist, "buffer_name");
                    if (buffer_name && buffer_name[0])
                    {
                        ptr_buffer = weechat_buffer_search (IRC_PLUGIN_NAME,
                                                            buffer_name);
                        if (ptr_buffer)
                            irc_upgrade_current_server->buffer = ptr_buffer;
                    }
                    irc_upgrade_current_server->index_current_address =
                        weechat_infolist_integer (infolist, "index_current_address");
                    str = weechat_infolist_string (infolist, "current_address");
                    if (str)
                    {
                        irc_upgrade_current_server->current_address = strdup (str);
                        irc_upgrade_current_server->current_port = weechat_infolist_integer (infolist, "current_port");
                    }
                    else
                    {
                        if (irc_upgrade_current_server->index_current_address < irc_upgrade_current_server->addresses_count)
                        {
                            irc_upgrade_current_server->current_address =
                                strdup (irc_upgrade_current_server->addresses_array[irc_upgrade_current_server->index_current_address]);
                            irc_upgrade_current_server->current_port =
                                irc_upgrade_current_server->ports_array[irc_upgrade_current_server->index_current_address];
                        }
                    }
                    str = weechat_infolist_string (infolist, "current_ip");
                    if (str)
                        irc_upgrade_current_server->current_ip = strdup (str);
                    sock = weechat_infolist_integer (infolist, "sock");
                    if (sock >= 0)
                    {
                        irc_upgrade_current_server->sock = sock;
                        irc_upgrade_current_server->hook_fd = weechat_hook_fd (irc_upgrade_current_server->sock,
                                                                               1, 0, 0,
                                                                               &irc_server_recv_cb,
                                                                               irc_upgrade_current_server);
                    }
                    irc_upgrade_current_server->is_connected = weechat_infolist_integer (infolist, "is_connected");
                    irc_upgrade_current_server->ssl_connected = weechat_infolist_integer (infolist, "ssl_connected");
                    irc_upgrade_current_server->disconnected = weechat_infolist_integer (infolist, "disconnected");
                    str = weechat_infolist_string (infolist, "unterminated_message");
                    if (str)
                        irc_upgrade_current_server->unterminated_message = strdup (str);
                    str = weechat_infolist_string (infolist, "nick");
                    if (str)
                        irc_server_set_nick (irc_upgrade_current_server, str);
                    str = weechat_infolist_string (infolist, "nick_modes");
                    if (str)
                        irc_upgrade_current_server->nick_modes = strdup (str);
                    str = weechat_infolist_string (infolist, "isupport");
                    if (str)
                        irc_upgrade_current_server->isupport = strdup (str);
                    /*
                     * "prefix" is not any more in this infolist (since
                     * WeeChat 0.3.4), but we read it to keep compatibility
                     * with old WeeChat versions, on /upgrade)
                     */
                    str = weechat_infolist_string (infolist, "prefix");
                    if (str)
                        irc_server_set_prefix_modes_chars (irc_upgrade_current_server, str);
                    /* "prefix_modes" is new in WeeChat 0.3.4 */
                    str = weechat_infolist_string (infolist, "prefix_modes");
                    if (str)
                    {
                        if (irc_upgrade_current_server->prefix_modes)
                            free (irc_upgrade_current_server->prefix_modes);
                        irc_upgrade_current_server->prefix_modes = strdup (str);
                    }
                    /* "prefix_chars" is new in WeeChat 0.3.4 */
                    str = weechat_infolist_string (infolist, "prefix_chars");
                    if (str)
                    {
                        if (irc_upgrade_current_server->prefix_chars)
                            free (irc_upgrade_current_server->prefix_chars);
                        irc_upgrade_current_server->prefix_chars = strdup (str);
                    }
                    irc_upgrade_current_server->nick_max_length = weechat_infolist_integer (infolist, "nick_max_length");
                    irc_upgrade_current_server->casemapping = weechat_infolist_integer (infolist, "casemapping");
                    str = weechat_infolist_string (infolist, "chantypes");
                    if (str)
                        irc_upgrade_current_server->chantypes = strdup (str);
                    str = weechat_infolist_string (infolist, "chanmodes");
                    if (str)
                        irc_upgrade_current_server->chanmodes = strdup (str);
                    else
                    {
                        str = irc_server_get_isupport_value (irc_upgrade_current_server,
                                                             "CHANMODES");
                        if (str)
                            irc_upgrade_current_server->chanmodes = strdup (str);
                    }
                    /* "monitor" is new in WeeChat 0.4.3 */
                    if (weechat_infolist_search_var (infolist, "monitor"))
                    {
                        irc_upgrade_current_server->monitor = weechat_infolist_integer (infolist, "monitor");
                    }
                    else
                    {
                        /* WeeChat <= 0.4.2 */
                        str = irc_server_get_isupport_value (irc_upgrade_current_server,
                                                             "MONITOR");
                        if (str)
                        {
                            error = NULL;
                            number = strtol (str, &error, 10);
                            if (error && !error[0])
                                irc_upgrade_current_server->monitor = (int)number;
                        }
                    }
                    irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay");
                    irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start");
                    irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time");
                    irc_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join");
                    irc_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin");
                    irc_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away");
                    str = weechat_infolist_string (infolist, "away_message");
                    if (str)
                        irc_upgrade_current_server->away_message = strdup (str);
                    irc_upgrade_current_server->away_time = weechat_infolist_time (infolist, "away_time");
                    irc_upgrade_current_server->lag = weechat_infolist_integer (infolist, "lag");
                    buf = weechat_infolist_buffer (infolist, "lag_check_time", &size);
                    if (buf)
                        memcpy (&(irc_upgrade_current_server->lag_check_time), buf, size);
                    irc_upgrade_current_server->lag_next_check = weechat_infolist_time (infolist, "lag_next_check");
                    irc_upgrade_current_server->lag_last_refresh = weechat_infolist_time (infolist, "lag_last_refresh");
                    irc_upgrade_current_server->last_user_message = weechat_infolist_time (infolist, "last_user_message");
                    irc_upgrade_current_server->last_away_check = weechat_infolist_time (infolist, "last_away_check");
                    irc_upgrade_current_server->last_data_purge = weechat_infolist_time (infolist, "last_data_purge");
                }
                break;
            case IRC_UPGRADE_TYPE_CHANNEL:
                if (irc_upgrade_current_server)
                {
                    irc_upgrade_current_channel = irc_channel_new (irc_upgrade_current_server,
                                                                   weechat_infolist_integer (infolist, "type"),
                                                                   weechat_infolist_string (infolist, "name"),
                                                                   0, 0);
                    if (irc_upgrade_current_channel)
                    {
                        str = weechat_infolist_string (infolist, "topic");
                        if (str)
                            irc_channel_set_topic (irc_upgrade_current_channel, str);
                        str = weechat_infolist_string (infolist, "modes");
                        if (str)
                            irc_upgrade_current_channel->modes = strdup (str);
                        irc_upgrade_current_channel->limit = weechat_infolist_integer (infolist, "limit");
                        str = weechat_infolist_string (infolist, "key");
                        if (str)
                            irc_upgrade_current_channel->key = strdup (str);
                        str = weechat_infolist_string (infolist, "join_msg_received");
                        if (str)
                        {
                            items = weechat_string_split (str, ",", 0, 0,
                                                          &num_items);
                            if (items)
                            {
                                for (i = 0; i < num_items; i++)
                                {
                                    weechat_hashtable_set (irc_upgrade_current_channel->join_msg_received,
                                                           items[i], "1");
                                }
                                weechat_string_free_split (items);
                            }
                        }
                        irc_upgrade_current_channel->checking_away = weechat_infolist_integer (infolist, "checking_away");
                        str = weechat_infolist_string (infolist, "away_message");
                        if (str)
                            irc_upgrade_current_channel->away_message = strdup (str);
                        irc_upgrade_current_channel->has_quit_server = weechat_infolist_integer (infolist, "has_quit_server");
                        irc_upgrade_current_channel->cycle = weechat_infolist_integer (infolist, "cycle");
                        irc_upgrade_current_channel->part = weechat_infolist_integer (infolist, "part");
                        irc_upgrade_current_channel->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset");
                        for (i = 0; i < 2; i++)
                        {
                            index = 0;
                            while (1)
                            {
                                snprintf (option_name, sizeof (option_name),
                                          "nick_speaking%d_%05d", i, index);
                                nick = weechat_infolist_string (infolist, option_name);
                                if (!nick)
                                    break;
                                irc_channel_nick_speaking_add (irc_upgrade_current_channel,
                                                               nick,
                                                               i);
                                index++;
                            }
                        }
                        index = 0;
                        while (1)
                        {
                            snprintf (option_name, sizeof (option_name),
                                      "nick_speaking_time_nick_%05d", index);
                            nick = weechat_infolist_string (infolist, option_name);
                            if (!nick)
                                break;
                            snprintf (option_name, sizeof (option_name),
                                      "nick_speaking_time_time_%05d", index);
                            irc_channel_nick_speaking_time_add (irc_upgrade_current_server,
                                                                irc_upgrade_current_channel,
                                                                nick,
                                                                weechat_infolist_time (infolist,
                                                                                       option_name));
                            index++;
                        }
                        str = weechat_infolist_string (infolist, "join_smart_filtered");
                        if (str)
                        {
                            nicks = weechat_string_split (str, ",", 0, 0,
                                                          &nicks_count);
                            if (nicks)
                            {
                                for (i = 0; i < nicks_count; i++)
                                {
                                    pos = strchr (nicks[i], ':');
                                    if (pos)
                                    {
                                        nick_join = weechat_strndup (nicks[i],
                                                                     pos - nicks[i]);
                                        if (nick_join)
                                        {
                                            error = NULL;
                                            number = strtol (pos + 1, &error, 10);
                                            if (error && !error[0])
                                            {
                                                join_time = (time_t)number;
                                                irc_channel_join_smart_filtered_add (irc_upgrade_current_channel,
                                                                                     nick_join,
                                                                                     join_time);
                                            }
                                            free (nick_join);
                                        }
                                    }
                                }
                                weechat_string_free_split (nicks);
                            }
                        }
                    }
                }
                break;
            case IRC_UPGRADE_TYPE_NICK:
                if (irc_upgrade_current_server && irc_upgrade_current_channel)
                {
                    ptr_nick = irc_nick_new (irc_upgrade_current_server,
                                             irc_upgrade_current_channel,
                                             weechat_infolist_string (infolist, "name"),
                                             weechat_infolist_string (infolist, "host"),
                                             weechat_infolist_string (infolist, "prefixes"),
                                             weechat_infolist_integer (infolist, "away"));
                    if (ptr_nick)
                    {
                        /*
                         * "flags" is not any more in this infolist (since
                         * WeeChat 0.3.4), but we read it to keep compatibility
                         * with old WeeChat versions, on /upgrade)
                         * We try to restore prefixes with old flags, but
                         * this is approximation, it's not sure we will
                         * restore good prefixes here (a /names on channel
                         * will fix problem if prefixes are wrong).
                         * Flags were defined in irc-nick.h:
                         *   #define IRC_NICK_CHANOWNER  1
                         *   #define IRC_NICK_CHANADMIN  2
                         *   #define IRC_NICK_CHANADMIN2 4
                         *   #define IRC_NICK_OP         8
                         *   #define IRC_NICK_HALFOP     16
                         *   #define IRC_NICK_VOICE      32
                         *   #define IRC_NICK_AWAY       64
                         *   #define IRC_NICK_CHANUSER   128
                         */
                        flags = weechat_infolist_integer (infolist, "flags");
                        if (flags > 0)
                        {
                            /* channel owner */
                            if (flags & 1)
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'q');
                            }
                            /* channel admin */
                            if ((flags & 2) || (flags & 4))
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'a');
                            }
                            /* op */
                            if (flags & 8)
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'o');
                            }
                            /* half-op */
                            if (flags & 16)
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'h');
                            }
                            /* voice */
                            if (flags & 32)
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'v');
                            }
                            /* away */
                            if (flags & 64)
                            {
                                irc_nick_set_away (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1);
                            }
                            /* channel user */
                            if (flags & 128)
                            {
                                irc_nick_set_mode (irc_upgrade_current_server,
                                                   irc_upgrade_current_channel,
                                                   ptr_nick, 1, 'u');
                            }
                        }
                    }
                }
                break;
            case IRC_UPGRADE_TYPE_REDIRECT:
                if (irc_upgrade_current_server)
                {
                    ptr_redirect = irc_redirect_new_with_commands (
                        irc_upgrade_current_server,
                        weechat_infolist_string (infolist, "pattern"),
                        weechat_infolist_string (infolist, "signal"),
                        weechat_infolist_integer (infolist, "count"),
                        weechat_infolist_string (infolist, "string"),
                        weechat_infolist_integer (infolist, "timeout"),
                        weechat_infolist_string (infolist, "cmd_start"),
                        weechat_infolist_string (infolist, "cmd_stop"),
                        weechat_infolist_string (infolist, "cmd_extra"),
                        weechat_infolist_string (infolist, "cmd_filter"));
                    if (ptr_redirect)
                    {
                        ptr_redirect->current_count = weechat_infolist_integer (infolist, "current_count");
                        str = weechat_infolist_string (infolist, "command");
                        if (str)
                            ptr_redirect->command = strdup (str);
                        ptr_redirect->assigned_to_command = weechat_infolist_integer (infolist, "assigned_to_command");
                        ptr_redirect->start_time = weechat_infolist_time (infolist, "start_time");
                        ptr_redirect->cmd_start_received = weechat_infolist_integer (infolist, "cmd_start_received");
                        ptr_redirect->cmd_stop_received = weechat_infolist_integer (infolist, "cmd_stop_received");
                        str = weechat_infolist_string (infolist, "output");
                        if (str)
                            ptr_redirect->output = strdup (str);
                        ptr_redirect->output_size = weechat_infolist_integer (infolist, "output_size");
                    }
                }
                break;
            case IRC_UPGRADE_TYPE_REDIRECT_PATTERN:
                irc_redirect_pattern_new (
                    weechat_infolist_string (infolist, "name"),
                    weechat_infolist_integer (infolist, "temp_pattern"),
                    weechat_infolist_integer (infolist, "timeout"),
                    weechat_infolist_string (infolist, "cmd_start"),
                    weechat_infolist_string (infolist, "cmd_stop"),
                    weechat_infolist_string (infolist, "cmd_extra"));
                break;
            case IRC_UPGRADE_TYPE_NOTIFY:
                if (irc_upgrade_current_server)
                {
                    ptr_notify = irc_notify_search (irc_upgrade_current_server,
                                                    weechat_infolist_string (infolist, "nick"));
                    if (ptr_notify)
                    {
                        ptr_notify->is_on_server = weechat_infolist_integer (infolist, "is_on_server");
                        str = weechat_infolist_string (infolist, "away_message");
                        if (str)
                            ptr_notify->away_message = strdup (str);
                    }
                }
                break;
            case IRC_UPGRADE_TYPE_RAW_MESSAGE:
                irc_raw_message_add_to_list (weechat_infolist_time (infolist, "date"),
                                             weechat_infolist_string (infolist, "prefix"),
                                             weechat_infolist_string (infolist, "message"));
                break;
        }
    }

    return WEECHAT_RC_OK;
}
Ejemplo n.º 30
0
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;
}