Пример #1
0
void
trigger_callback_end ()
{
    if (trigger_callback_hashtable_options_conditions)
        weechat_hashtable_free (trigger_callback_hashtable_options_conditions);
    if (trigger_callback_hashtable_options_regex)
        weechat_hashtable_free (trigger_callback_hashtable_options_regex);
}
Пример #2
0
int
weechat_aspell_speller_init ()
{
    weechat_aspell_spellers = weechat_hashtable_new (32,
                                                     WEECHAT_HASHTABLE_STRING,
                                                     WEECHAT_HASHTABLE_POINTER,
                                                     NULL, NULL);
    if (!weechat_aspell_spellers)
        return 0;
    weechat_hashtable_set_pointer (weechat_aspell_spellers,
                                   "callback_free_value",
                                   &weechat_aspell_speller_free_value_cb);

    weechat_aspell_speller_buffer = weechat_hashtable_new (32,
                                                           WEECHAT_HASHTABLE_POINTER,
                                                           WEECHAT_HASHTABLE_POINTER,
                                                           NULL, NULL);
    if (!weechat_aspell_speller_buffer)
    {
        weechat_hashtable_free (weechat_aspell_spellers);
        return 0;
    }
    weechat_hashtable_set_pointer (weechat_aspell_speller_buffer,
                                   "callback_free_value",
                                   &weechat_aspell_speller_buffer_free_value_cb);

    return 1;
}
Пример #3
0
void
relay_config_free ()
{
    weechat_config_free (relay_config_file);

    if (relay_config_regex_allowed_ips)
    {
        regfree (relay_config_regex_allowed_ips);
        free (relay_config_regex_allowed_ips);
        relay_config_regex_allowed_ips = NULL;
    }

    if (relay_config_regex_websocket_allowed_origins)
    {
        regfree (relay_config_regex_websocket_allowed_origins);
        free (relay_config_regex_websocket_allowed_origins);
        relay_config_regex_websocket_allowed_origins = NULL;
    }

    if (relay_config_hashtable_irc_backlog_tags)
    {
        weechat_hashtable_free (relay_config_hashtable_irc_backlog_tags);
        relay_config_hashtable_irc_backlog_tags = NULL;
    }
}
Пример #4
0
/**
 * Free the entire message queue for a profile.
 */
void
twc_message_queue_free_profile(struct t_twc_profile *profile)
{
    weechat_hashtable_map(profile->message_queues,
                          twc_message_queue_free_map_callback, NULL);
    weechat_hashtable_free(profile->message_queues);
}
Пример #5
0
void
irc_ctcp_reply_to_nick (struct t_irc_server *server,
                        const char *command,
                        struct t_irc_channel *channel,
                        const char *nick, const char *ctcp,
                        const char *arguments)
{
    struct t_hashtable *hashtable;
    int number;
    char hash_key[32];
    const char *str_args;

    hashtable = irc_server_sendf (server,
                                  IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE,
                                  NULL,
                                  "NOTICE %s :\01%s%s%s\01",
                                  nick, ctcp,
                                  (arguments) ? " " : "",
                                  (arguments) ? arguments : "");

    if (hashtable)
    {
        if (weechat_config_boolean (irc_config_look_display_ctcp_reply))
        {
            number = 1;
            while (1)
            {
                snprintf (hash_key, sizeof (hash_key), "args%d", number);
                str_args = weechat_hashtable_get (hashtable, hash_key);
                if (!str_args)
                    break;
                weechat_printf_tags (irc_msgbuffer_get_target_buffer (server,
                                                                      nick,
                                                                      NULL,
                                                                      "ctcp",
                                                                      (channel) ? channel->buffer : NULL),
                                     irc_protocol_tags (command,
                                                        "irc_ctcp,irc_ctcp_reply,"
                                                        "notify_none,no_highlight",
                                                        NULL),
                                     _("%sCTCP reply to %s%s%s: %s%s%s%s%s"),
                                     weechat_prefix ("network"),
                                     irc_nick_color_for_message (server, NULL,
                                                                 nick),
                                     nick,
                                     IRC_COLOR_RESET,
                                     IRC_COLOR_CHAT_CHANNEL,
                                     ctcp,
                                     (str_args[0]) ? IRC_COLOR_RESET : "",
                                     (str_args[0]) ? " " : "",
                                     str_args);
                number++;
            }
        }
        weechat_hashtable_free (hashtable);
    }
}
Пример #6
0
void
relay_weechat_free (struct t_relay_client *client)
{
    if (client->protocol_data)
    {
        if (RELAY_WEECHAT_DATA(client, buffers_sync))
            weechat_hashtable_free (RELAY_WEECHAT_DATA(client, buffers_sync));
        if (RELAY_WEECHAT_DATA(client, hook_signal_buffer))
            weechat_unhook (RELAY_WEECHAT_DATA(client, hook_signal_buffer));
        if (RELAY_WEECHAT_DATA(client, hook_signal_nicklist))
            weechat_unhook (RELAY_WEECHAT_DATA(client, hook_signal_nicklist));
        if (RELAY_WEECHAT_DATA(client, buffers_nicklist))
            weechat_hashtable_free (RELAY_WEECHAT_DATA(client, buffers_nicklist));

        free (client->protocol_data);

        client->protocol_data = NULL;
    }
}
Пример #7
0
void
irc_redirect_stop (struct t_irc_redirect *redirect, const char *error)
{
    struct t_hashtable *hashtable;
    char signal_name[1024], str_int[64];

    redirect->current_count++;

    if (error || (redirect->current_count > redirect->count))
    {
        /*
         * error or max count reached, then we run callback and remove
         * redirect
         */
        hashtable = weechat_hashtable_new (32,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL,
                                           NULL);
        if (hashtable)
        {
            /* set error and output (main fields) */
            weechat_hashtable_set (hashtable, "error",
                                   (error) ? (char *)error : "");
            weechat_hashtable_set (hashtable, "output",
                                   (redirect->output) ? redirect->output : "");
            snprintf (str_int, sizeof (str_int), "%d", redirect->output_size);
            weechat_hashtable_set (hashtable, "output_size", str_int);

            /* set some other fields with values from redirect */
            weechat_hashtable_set (hashtable, "server", redirect->server->name);
            weechat_hashtable_set (hashtable, "pattern", redirect->pattern);
            weechat_hashtable_set (hashtable, "signal", redirect->signal);
            weechat_hashtable_set (hashtable, "command", redirect->command);
        }

        snprintf (signal_name, sizeof (signal_name), "irc_redirection_%s_%s",
                  redirect->signal, redirect->pattern);
        (void) weechat_hook_hsignal_send (signal_name, hashtable);

        if (hashtable)
            weechat_hashtable_free (hashtable);

        irc_redirect_free (redirect);
    }
    else
    {
        /*
         * max count not yet reached, then we prepare redirect to continue
         * redirection
         */
        redirect->cmd_start_received = 0;
        redirect->cmd_stop_received = 0;
    }
}
Пример #8
0
int
irc_notify_timer_ison_cb (const void *pointer, void *data, int remaining_calls)
{
    char *message, hash_key[32];
    const char *str_message;
    int num_nicks, number;
    struct t_irc_server *ptr_server;
    struct t_hashtable *hashtable;

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

    for (ptr_server = irc_servers; ptr_server;
         ptr_server = ptr_server->next_server)
    {
        if (ptr_server->is_connected
            && ptr_server->notify_list
            && (ptr_server->monitor == 0))
        {
            message = irc_notify_build_message_with_nicks (ptr_server,
                                                           "ISON :",
                                                           " ",
                                                           &num_nicks);
            if (message && (num_nicks > 0))
            {
                hashtable = irc_message_split (ptr_server, message);
                if (hashtable)
                {
                    number = 1;
                    while (1)
                    {
                        snprintf (hash_key, sizeof (hash_key), "msg%d", number);
                        str_message = weechat_hashtable_get (hashtable,
                                                             hash_key);
                        if (!str_message)
                            break;
                        irc_redirect_new (ptr_server, "ison", "notify", 1,
                                          NULL, 0, NULL);
                        irc_server_sendf (ptr_server,
                                          IRC_SERVER_SEND_OUTQ_PRIO_LOW,
                                          NULL, "%s", str_message);
                        number++;
                    }
                    weechat_hashtable_free (hashtable);
                }
            }
            if (message)
                free (message);
        }
    }

    return WEECHAT_RC_OK;
}
void
weechat_aspell_speller_remove_unused ()
{
    struct t_hashtable *used_spellers;
    struct t_infolist *infolist;

    if (weechat_aspell_plugin->debug)
    {
        weechat_printf (NULL,
                        "%s: removing unused spellers",
                        ASPELL_PLUGIN_NAME);
    }

    /* create a hashtable that will contain all used spellers */
    used_spellers = weechat_hashtable_new (32,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL,
                                           NULL);
    if (!used_spellers)
        return;

    /* collect used spellers and store them in hashtable "used_spellers" */
    weechat_aspell_speller_add_dicts_to_hash (used_spellers,
                                              weechat_config_string (weechat_aspell_config_check_default_dict));
    infolist = weechat_infolist_get ("option", NULL, "aspell.dict.*");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            weechat_aspell_speller_add_dicts_to_hash (used_spellers,
                                                      weechat_infolist_string (infolist, "value"));
        }
        weechat_infolist_free (infolist);
    }

    /*
     * look at current spellers, and remove spellers that are not in hashtable
     * "used_spellers"
     */
    weechat_hashtable_map (weechat_aspell_spellers,
                           &weechat_aspell_speller_remove_unused_cb,
                           used_spellers);

    weechat_hashtable_free (used_spellers);
}
Пример #10
0
void
irc_input_send_user_message (struct t_gui_buffer *buffer, int flags,
                             const char *tags, char *message)
{
    int number, action;
    char hash_key[32], *str_args;
    struct t_hashtable *hashtable;

    IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

    if (!ptr_server || !ptr_channel || !message || !message[0])
        return;

    if (!ptr_server->is_connected)
    {
        weechat_printf (buffer,
                        _("%s%s: you are not connected to server"),
                        weechat_prefix ("error"), IRC_PLUGIN_NAME);
        return;
    }
    hashtable = irc_server_sendf (ptr_server,
                                  flags | IRC_SERVER_SEND_RETURN_HASHTABLE,
                                  tags,
                                  "PRIVMSG %s :%s",
                                  ptr_channel->name, message);
    if (hashtable)
    {
        action = (strncmp (message, "\01ACTION ", 8) == 0);
        number = 1;
        while (1)
        {
            snprintf (hash_key, sizeof (hash_key), "args%d", number);
            str_args = weechat_hashtable_get (hashtable, hash_key);
            if (!str_args)
                break;
            irc_input_user_message_display (buffer, action, str_args);
            number++;
        }
        weechat_hashtable_free (hashtable);
    }
}
Пример #11
0
struct t_hashtable *
trigger_callback_irc_message_parse (const char *irc_message,
                                    const char *irc_server)
{
    struct t_hashtable *hashtable_in, *hashtable_out;

    hashtable_out = NULL;

    hashtable_in = weechat_hashtable_new (32,
                                          WEECHAT_HASHTABLE_STRING,
                                          WEECHAT_HASHTABLE_STRING,
                                          NULL,
                                          NULL);
    if (hashtable_in)
    {
        weechat_hashtable_set (hashtable_in, "message", irc_message);
        weechat_hashtable_set (hashtable_in, "server", irc_server);
        hashtable_out = weechat_info_get_hashtable ("irc_message_parse",
                                                    hashtable_in);
        weechat_hashtable_free (hashtable_in);
    }

    return hashtable_out;
}
Пример #12
0
void
irc_notify_send_monitor (struct t_irc_server *server)
{
    struct t_hashtable *hashtable;
    char *message, hash_key[32];
    const char *str_message;
    int num_nicks, number;

    message = irc_notify_build_message_with_nicks (server,
                                                   "MONITOR + ",
                                                   ",",
                                                   &num_nicks);
    if (message && (num_nicks > 0))
    {
        hashtable = irc_message_split (server, message);
        if (hashtable)
        {
            number = 1;
            while (1)
            {
                snprintf (hash_key, sizeof (hash_key), "msg%d", number);
                str_message = weechat_hashtable_get (hashtable,
                                                     hash_key);
                if (!str_message)
                    break;
                irc_server_sendf (server,
                                  IRC_SERVER_SEND_OUTQ_PRIO_LOW,
                                  NULL, "%s", str_message);
                number++;
            }
            weechat_hashtable_free (hashtable);
        }
    }
    if (message)
        free (message);
}
Пример #13
0
void
irc_redirect_free (struct t_irc_redirect *redirect)
{
    struct t_irc_server *server;
    struct t_irc_redirect *new_redirects;
    int priority;
    struct t_irc_outqueue *ptr_outqueue;

    if (!redirect)
        return;

    server = redirect->server;

    /* remove redirect */
    if (server->last_redirect == redirect)
        server->last_redirect = redirect->prev_redirect;
    if (redirect->prev_redirect)
    {
        (redirect->prev_redirect)->next_redirect = redirect->next_redirect;
        new_redirects = server->redirects;
    }
    else
        new_redirects = redirect->next_redirect;

    if (redirect->next_redirect)
        (redirect->next_redirect)->prev_redirect = redirect->prev_redirect;

    /* remove any pointer to this redirect */
    for (priority = 0; priority < IRC_SERVER_NUM_OUTQUEUES_PRIO; priority++)
    {
        for (ptr_outqueue = server->outqueue[priority]; ptr_outqueue;
             ptr_outqueue = ptr_outqueue->next_outqueue)
        {
            if (ptr_outqueue->redirect == redirect)
                ptr_outqueue->redirect = NULL;
        }
    }

    /* free data */
    if (redirect->pattern)
        free (redirect->pattern);
    if (redirect->signal)
        free (redirect->signal);
    if (redirect->string)
        free (redirect->string);
    if (redirect->command)
        free (redirect->command);
    if (redirect->cmd_start)
        weechat_hashtable_free (redirect->cmd_start);
    if (redirect->cmd_stop)
        weechat_hashtable_free (redirect->cmd_stop);
    if (redirect->cmd_extra)
        weechat_hashtable_free (redirect->cmd_extra);
    if (redirect->cmd_filter)
        weechat_hashtable_free (redirect->cmd_filter);
    if (redirect->output)
        free (redirect->output);

    free (redirect);

    server->redirects = new_redirects;
}
Пример #14
0
int
exec_command_run (struct t_gui_buffer *buffer,
                  int argc, char **argv, char **argv_eol, int start_arg)
{
    char str_buffer[512];
    struct t_exec_cmd *new_exec_cmd;
    struct t_exec_cmd_options cmd_options;
    struct t_hashtable *process_options;
    struct t_infolist *ptr_infolist;
    struct t_gui_buffer *ptr_new_buffer;

    /* parse command options */
    cmd_options.command_index = -1;
    cmd_options.use_shell = 0;
    cmd_options.detached = 0;
    cmd_options.pipe_stdin = 0;
    cmd_options.timeout = 0;
    cmd_options.ptr_buffer_name = NULL;
    cmd_options.ptr_buffer = buffer;
    cmd_options.output_to_buffer = 0;
    cmd_options.new_buffer = 0;
    cmd_options.new_buffer_clear = 0;
    cmd_options.switch_to_buffer = 1;
    cmd_options.line_numbers = -1;
    cmd_options.flush = 1;
    cmd_options.color = EXEC_COLOR_AUTO;
    cmd_options.display_rc = 1;
    cmd_options.ptr_command_name = NULL;
    cmd_options.pipe_command = NULL;
    cmd_options.hsignal = NULL;

    /* parse default options */
    if (!exec_command_parse_options (&cmd_options,
                                     exec_config_cmd_num_options,
                                     exec_config_cmd_options,
                                     0, 0))
    {
        weechat_printf (NULL,
                        _("%s%s: invalid options in option "
                          "exec.command.default_options"),
                        weechat_prefix ("error"), EXEC_PLUGIN_NAME);
        return WEECHAT_RC_ERROR;
    }
    if (!exec_command_parse_options (&cmd_options, argc, argv, start_arg, 1))
        return WEECHAT_RC_ERROR;

    /* options "-bg" and "-o"/"-n" are incompatible */
    if (cmd_options.detached
        && (cmd_options.output_to_buffer || cmd_options.new_buffer))
        return WEECHAT_RC_ERROR;

    /* options "-pipe" and "-bg"/"-o"/"-n" are incompatible */
    if (cmd_options.pipe_command
        && (cmd_options.detached || cmd_options.output_to_buffer
            || cmd_options.new_buffer))
        return WEECHAT_RC_ERROR;

    /* command not found? */
    if (cmd_options.command_index < 0)
        return WEECHAT_RC_ERROR;

    new_exec_cmd = exec_add ();
    if (!new_exec_cmd)
        return WEECHAT_RC_ERROR;

    /* create hashtable for weechat_hook_process_hashtable() */
    process_options = weechat_hashtable_new (32,
                                             WEECHAT_HASHTABLE_STRING,
                                             WEECHAT_HASHTABLE_STRING,
                                             NULL,
                                             NULL);
    if (!process_options)
    {
        exec_free (new_exec_cmd);
        return WEECHAT_RC_ERROR;
    }
    /* automatically disable shell if we are downloading an URL */
    if (strncmp (argv_eol[cmd_options.command_index], "url:", 4) == 0)
        cmd_options.use_shell = 0;
    if (cmd_options.use_shell)
    {
        /* command will be: sh -c "command arguments..." */
        weechat_hashtable_set (process_options, "arg1", "-c");
        weechat_hashtable_set (process_options, "arg2",
                               argv_eol[cmd_options.command_index]);
    }
    if (cmd_options.pipe_stdin)
        weechat_hashtable_set (process_options, "stdin", "1");
    if (cmd_options.detached)
        weechat_hashtable_set (process_options, "detached", "1");
    if (cmd_options.flush)
        weechat_hashtable_set (process_options, "buffer_flush", "1");

    /* set variables in new command (before running the command) */
    new_exec_cmd->name = (cmd_options.ptr_command_name) ?
        strdup (cmd_options.ptr_command_name) : NULL;
    new_exec_cmd->command = strdup (argv_eol[cmd_options.command_index]);
    new_exec_cmd->detached = cmd_options.detached;

    if (!cmd_options.detached && !cmd_options.pipe_command
        && !cmd_options.hsignal)
    {
        if (cmd_options.ptr_buffer_name && !cmd_options.ptr_buffer)
        {
            /* output in a new buffer using given name */
            new_exec_cmd->output_to_buffer = 0;
            snprintf (str_buffer, sizeof (str_buffer),
                      "exec.%s", cmd_options.ptr_buffer_name);
            ptr_new_buffer = exec_buffer_new (str_buffer,
                                              (cmd_options.new_buffer == 2),
                                              cmd_options.new_buffer_clear,
                                              cmd_options.switch_to_buffer);
            if (ptr_new_buffer)
            {
                new_exec_cmd->buffer_full_name =
                    strdup (weechat_buffer_get_string (ptr_new_buffer,
                                                       "full_name"));
            }
        }
        else if (cmd_options.new_buffer)
        {
            /* output in a new buffer using automatic name */
            if (new_exec_cmd->name)
            {
                snprintf (str_buffer, sizeof (str_buffer),
                          "exec.%s", new_exec_cmd->name);
            }
            else
            {
                snprintf (str_buffer, sizeof (str_buffer),
                          "exec.%d", new_exec_cmd->number);
            }
            ptr_new_buffer = exec_buffer_new (str_buffer,
                                              (cmd_options.new_buffer == 2),
                                              cmd_options.new_buffer_clear,
                                              cmd_options.switch_to_buffer);
            if (ptr_new_buffer)
            {
                new_exec_cmd->buffer_full_name =
                    strdup (weechat_buffer_get_string (ptr_new_buffer,
                                                       "full_name"));
            }
        }
        else if (cmd_options.ptr_buffer)
        {
            new_exec_cmd->buffer_full_name =
                strdup (weechat_buffer_get_string (cmd_options.ptr_buffer,
                                                   "full_name"));
            if (cmd_options.switch_to_buffer)
                weechat_buffer_set (cmd_options.ptr_buffer, "display", "1");
        }
        if (cmd_options.ptr_buffer
            && (strcmp (weechat_buffer_get_string (cmd_options.ptr_buffer, "plugin"),
                        EXEC_PLUGIN_NAME) == 0))
        {
            cmd_options.output_to_buffer = 0;
            cmd_options.new_buffer = 1;
        }
    }
    new_exec_cmd->output_to_buffer = cmd_options.output_to_buffer;
    new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ?
        cmd_options.new_buffer : cmd_options.line_numbers;
    new_exec_cmd->color = cmd_options.color;
    new_exec_cmd->display_rc = cmd_options.display_rc;
    new_exec_cmd->pipe_command = cmd_options.pipe_command;
    new_exec_cmd->hsignal = cmd_options.hsignal;

    /* execute the command */
    if (weechat_exec_plugin->debug >= 1)
    {
        weechat_printf (NULL, "%s: executing command: \"%s%s%s\"",
                        EXEC_PLUGIN_NAME,
                        (cmd_options.use_shell) ? "" : "sh -c '",
                        argv_eol[cmd_options.command_index],
                        (cmd_options.use_shell) ? "" : "'");
    }
    new_exec_cmd->hook = weechat_hook_process_hashtable (
        (cmd_options.use_shell) ? "sh" : argv_eol[cmd_options.command_index],
        process_options,
        cmd_options.timeout * 1000,
        &exec_process_cb,
        new_exec_cmd);

    if (new_exec_cmd->hook)
    {
        /* get PID of command */
        ptr_infolist = weechat_infolist_get ("hook", new_exec_cmd->hook, NULL);
        if (ptr_infolist)
        {
            if (weechat_infolist_next (ptr_infolist))
            {
                new_exec_cmd->pid = weechat_infolist_integer (ptr_infolist,
                                                              "child_pid");
            }
            weechat_infolist_free (ptr_infolist);
        }
    }
    else
    {
        exec_free (new_exec_cmd);
        weechat_printf (NULL,
                        _("%s%s: failed to run command \"%s\""),
                        weechat_prefix ("error"), EXEC_PLUGIN_NAME,
                        argv_eol[cmd_options.command_index]);
    }

    weechat_hashtable_free (process_options);

    return WEECHAT_RC_OK;
}
Пример #15
0
void
exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
{
    struct t_gui_buffer *ptr_buffer;
    struct t_hashtable *hashtable;
    char str_number[32], *output;
    int i, buffer_type;

    if (exec_cmd->hsignal)
    {
        hashtable = weechat_hashtable_new (32,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL, NULL);
        if (hashtable)
        {
            weechat_hashtable_set (hashtable, "command", exec_cmd->command);
            snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number);
            weechat_hashtable_set (hashtable, "number", str_number);
            weechat_hashtable_set (hashtable, "name", exec_cmd->name);
            output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]);
            weechat_hashtable_set (hashtable, "out", output);
            if (output)
                free (output);
            output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]);
            weechat_hashtable_set (hashtable, "err", output);
            if (output)
                free (output);
            snprintf (str_number, sizeof (str_number), "%d", return_code);
            weechat_hashtable_set (hashtable, "rc", str_number);
            weechat_hook_hsignal_send (exec_cmd->hsignal, hashtable);
            weechat_hashtable_free (hashtable);
        }
    }
    else
    {
        ptr_buffer = weechat_buffer_search ("==", exec_cmd->buffer_full_name);

        /* display the last line of output (if not ending with '\n') */
        exec_display_line (exec_cmd, ptr_buffer, EXEC_STDOUT,
                           exec_cmd->output[EXEC_STDOUT]);
        exec_display_line (exec_cmd, ptr_buffer, EXEC_STDERR,
                           exec_cmd->output[EXEC_STDERR]);

        /*
         * display return code (only if command is not detached, if output is
         * NOT sent to buffer, and if command is not piped)
         */
        if (exec_cmd->display_rc
            && !exec_cmd->detached && !exec_cmd->output_to_buffer
            && !exec_cmd->pipe_command)
        {
            buffer_type = weechat_buffer_get_integer (ptr_buffer, "type");
            if (return_code >= 0)
            {
                if (buffer_type == 1)
                {
                    weechat_printf_y (ptr_buffer, -1,
                                      ("%s: end of command %d (\"%s\"), "
                                       "return code: %d"),
                                      EXEC_PLUGIN_NAME, exec_cmd->number,
                                      exec_cmd->command, return_code);
                }
                else
                {
                    weechat_printf_date_tags (
                        ptr_buffer, 0, "exec_rc",
                        _("%s: end of command %d (\"%s\"), "
                          "return code: %d"),
                        EXEC_PLUGIN_NAME, exec_cmd->number,
                        exec_cmd->command, return_code);
                }
            }
            else
            {
                if (buffer_type == 1)
                {
                    weechat_printf_y (ptr_buffer, -1,
                                      _("%s: unexpected end of command %d "
                                        "(\"%s\")"),
                                      EXEC_PLUGIN_NAME, exec_cmd->number,
                                      exec_cmd->command);
                }
                else
                {
                    weechat_printf_date_tags (
                        ptr_buffer, 0, "exec_rc",
                        _("%s: unexpected end of command %d "
                          "(\"%s\")"),
                        EXEC_PLUGIN_NAME, exec_cmd->number,
                        exec_cmd->command);
                }
            }
        }
    }

    /* (re)set some variables after the end of command */
    exec_cmd->hook = NULL;
    exec_cmd->pid = 0;
    exec_cmd->end_time = time (NULL);
    exec_cmd->return_code = return_code;
    for (i = 0; i < 2; i++)
    {
        if (exec_cmd->output[i])
        {
            free (exec_cmd->output[i]);
            exec_cmd->output[i] = NULL;
        }
        exec_cmd->output_size[i] = 0;
    }

    /* schedule a timer to remove the executed command */
    if (weechat_config_integer (exec_config_command_purge_delay) >= 0)
    {
        weechat_hook_timer (1 + (1000 * weechat_config_integer (exec_config_command_purge_delay)),
                            0, 1,
                            &exec_timer_delete_cb, exec_cmd, NULL);
    }
}
Пример #16
0
void
weechat_aspell_speller_end ()
{
    weechat_hashtable_free (weechat_aspell_spellers);
    weechat_hashtable_free (weechat_aspell_speller_buffer);
}
Пример #17
0
void
trigger_callback_replace_regex (struct t_trigger *trigger,
                                struct t_hashtable *pointers,
                                struct t_hashtable *extra_vars,
                                int display_monitor)
{
    char *value;
    const char *ptr_key, *ptr_value;
    int i, pointers_allocated;

    pointers_allocated = 0;

    if (trigger->regex_count == 0)
        return;

    if (!pointers)
    {
        pointers = weechat_hashtable_new (32,
                                          WEECHAT_HASHTABLE_STRING,
                                          WEECHAT_HASHTABLE_POINTER,
                                          NULL,
                                          NULL);
        if (!pointers)
            return;
        pointers_allocated = 1;
    }

    for (i = 0; i < trigger->regex_count; i++)
    {
        /* if regex is not set (invalid), skip it */
        if (!trigger->regex[i].regex)
            continue;

        ptr_key = (trigger->regex[i].variable) ?
            trigger->regex[i].variable :
            trigger_hook_regex_default_var[weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK])];
        if (!ptr_key || !ptr_key[0])
        {
            if (trigger_buffer && display_monitor)
            {
                weechat_printf_tags (trigger_buffer, "no_trigger",
                                     "\t  regex %d: %s",
                                     i + 1, _("no variable"));
            }
            continue;
        }

        ptr_value = weechat_hashtable_get (extra_vars, ptr_key);
        if (!ptr_value)
        {
            if (trigger_buffer && display_monitor)
            {
                weechat_printf_tags (trigger_buffer, "no_trigger",
                                     "\t  regex %d (%s): %s",
                                     i + 1, ptr_key, _("empty variable"));
            }
            continue;
        }

        weechat_hashtable_set (pointers, "regex", trigger->regex[i].regex);
        weechat_hashtable_set (trigger_callback_hashtable_options_regex,
                               "regex_replace",
                               trigger->regex[i].replace_escaped);

        value = weechat_string_eval_expression (
            ptr_value,
            pointers,
            extra_vars,
            trigger_callback_hashtable_options_regex);

        if (value)
        {
            /* display debug info on trigger buffer */
            if (trigger_buffer && display_monitor)
            {
                weechat_printf_tags (trigger_buffer, "no_trigger",
                                     "\t  regex %d %s(%s%s%s)%s: "
                                     "%s\"%s%s%s\"",
                                     i + 1,
                                     weechat_color ("chat_delimiters"),
                                     weechat_color ("reset"),
                                     ptr_key,
                                     weechat_color ("chat_delimiters"),
                                     weechat_color ("reset"),
                                     weechat_color ("chat_delimiters"),
                                     weechat_color ("reset"),
                                     value,
                                     weechat_color ("chat_delimiters"));
            }
            weechat_hashtable_set (extra_vars, ptr_key, value);
            free (value);
        }
    }

    if (pointers_allocated)
        weechat_hashtable_free (pointers);
    else
        weechat_hashtable_remove (pointers, "regex");
}
Пример #18
0
void
trigger_callback_end ()
{
    if (trigger_callback_hashtable_options)
        weechat_hashtable_free (trigger_callback_hashtable_options);
}