Exemplo n.º 1
0
int
dogechat_plugin_init (struct t_dogechat_plugin *plugin, int argc, char *argv[])
{
    int i, upgrading;

    dogechat_plugin = plugin;

    exec_command_init ();

    if (!exec_config_init ())
        return DOGECHAT_RC_ERROR;

    exec_config_read ();

    /* hook some signals */
    dogechat_hook_signal ("debug_dump", &exec_debug_dump_cb, NULL);

    /* hook completions */
    exec_completion_init ();

    /* look at arguments */
    upgrading = 0;
    for (i = 0; i < argc; i++)
    {
        if (dogechat_strcasecmp (argv[i], "--upgrade") == 0)
        {
            upgrading = 1;
        }
    }

    if (upgrading)
        exec_buffer_set_callbacks ();

    return DOGECHAT_RC_OK;
}
Exemplo n.º 2
0
int
exec_debug_dump_cb (void *data, const char *signal, const char *type_data,
                    void *signal_data)
{
    /* make C compiler happy */
    (void) data;
    (void) signal;
    (void) type_data;

    if (!signal_data
        || (dogechat_strcasecmp ((char *)signal_data, EXEC_PLUGIN_NAME) == 0))
    {
        dogechat_log_printf ("");
        dogechat_log_printf ("***** \"%s\" plugin dump *****",
                            dogechat_plugin->name);

        exec_print_log ();

        dogechat_log_printf ("");
        dogechat_log_printf ("***** End of \"%s\" plugin dump *****",
                            dogechat_plugin->name);
    }

    return DOGECHAT_RC_OK;
}
Exemplo n.º 3
0
int
xfer_command_xfer (void *data, struct t_gui_buffer *buffer, int argc,
                   char **argv, char **argv_eol)
{
    /* make C compiler happy */
    (void) data;
    (void) buffer;
    (void) argv_eol;

    if ((argc > 1) && (dogechat_strcasecmp (argv[1], "list") == 0))
    {
        xfer_command_xfer_list (0);
        return DOGECHAT_RC_OK;
    }

    if ((argc > 1) && (dogechat_strcasecmp (argv[1], "listfull") == 0))
    {
        xfer_command_xfer_list (1);
        return DOGECHAT_RC_OK;
    }

    if (!xfer_buffer)
        xfer_buffer_open ();

    if (xfer_buffer)
    {
        dogechat_buffer_set (xfer_buffer, "display", "1");

        if (argc > 1)
        {
            if (strcmp (argv[1], "up") == 0)
            {
                if (xfer_buffer_selected_line > 0)
                    xfer_buffer_selected_line--;
            }
            else if (strcmp (argv[1], "down") == 0)
            {
                if (xfer_buffer_selected_line < xfer_count - 1)
                    xfer_buffer_selected_line++;
            }
        }
    }

    xfer_buffer_refresh (NULL);

    return DOGECHAT_RC_OK;
}
Exemplo n.º 4
0
int
irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags)
{
    const char *ptr_data;
    char *data_with_colors, *msg;

    IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

    if (buffer == irc_raw_buffer)
    {
        if (dogechat_strcasecmp (input_data, "q") == 0)
            dogechat_buffer_close (buffer);
    }
    else
    {
        /*
         * if send unknown commands is enabled and that input data is a
         * command, then send this command to IRC server
         */
        if (dogechat_config_boolean (irc_config_network_send_unknown_commands)
            && !dogechat_string_input_for_buffer (input_data))
        {
            if (ptr_server)
            {
                irc_server_sendf (ptr_server, flags, NULL,
                                  "%s", dogechat_utf8_next_char (input_data));
            }
            return DOGECHAT_RC_OK;
        }

        if (ptr_channel)
        {
            ptr_data = dogechat_string_input_for_buffer (input_data);
            if (!ptr_data)
                ptr_data = input_data;
            data_with_colors = irc_color_encode (
                ptr_data,
                dogechat_config_boolean (irc_config_network_colors_send));

            msg = strdup ((data_with_colors) ? data_with_colors : ptr_data);
            if (msg)
            {
                irc_input_send_user_message (buffer, flags, NULL, msg);
                free (msg);
            }

            if (data_with_colors)
                free (data_with_colors);
        }
        else
        {
            dogechat_printf (buffer,
                            _("%s%s: this buffer is not a channel!"),
                            dogechat_prefix ("error"), IRC_PLUGIN_NAME);
        }
    }

    return DOGECHAT_RC_OK;
}
Exemplo n.º 5
0
struct t_alias *
alias_search (const char *alias_name)
{
    struct t_alias *ptr_alias;

    for (ptr_alias = alias_list; ptr_alias;
         ptr_alias = ptr_alias->next_alias)
    {
        if (dogechat_strcasecmp (alias_name, ptr_alias->name) == 0)
            return ptr_alias;
    }
    return NULL;
}
Exemplo n.º 6
0
struct t_alias *
alias_find_pos (const char *name)
{
    struct t_alias *ptr_alias;

    for (ptr_alias = alias_list; ptr_alias; ptr_alias = ptr_alias->next_alias)
    {
        if (dogechat_strcasecmp (name, ptr_alias->name) < 0)
            return ptr_alias;
    }

    /* position not found (we will add to the end of list) */
    return NULL;
}
Exemplo n.º 7
0
int
dogechat_js_signal_debug_dump_cb (void *data, const char *signal,
                                 const char *type_data, void *signal_data)
{
    /* make C++ compiler happy */
    (void) data;
    (void) signal;
    (void) type_data;

    if (!signal_data
        || (dogechat_strcasecmp ((char *)signal_data, JS_PLUGIN_NAME) == 0))
    {
        plugin_script_print_log (dogechat_js_plugin, js_scripts);
    }

    return DOGECHAT_RC_OK;
}
Exemplo n.º 8
0
int
exec_search_color (const char *color)
{
    int i;

    if (!color)
        return -1;

    for (i = 0; i < EXEC_NUM_COLORS; i++)
    {
        if (dogechat_strcasecmp (exec_color_string[i], color) == 0)
            return i;
    }

    /* color not found */
    return -1;
}
Exemplo n.º 9
0
struct t_infolist *
dogechat_js_infolist_cb (void *data, const char *infolist_name,
                        void *pointer, const char *arguments)
{
    /* make C++ compiler happy */
    (void) data;

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

    if (dogechat_strcasecmp (infolist_name, "javascript_script") == 0)
    {
        return plugin_script_infolist_list_scripts (dogechat_js_plugin,
                                                    js_scripts, pointer,
                                                    arguments);
    }

    return NULL;
}
Exemplo n.º 10
0
int
fifo_config_cb (void *data, const char *option, const char *value)
{
    /* make C compiler happy */
    (void) data;
    (void) option;

    if (dogechat_strcasecmp (value, "on") == 0)
    {
        if (fifo_fd < 0)
            fifo_create ();
    }
    else
    {
        if (fifo_fd >= 0)
            fifo_remove ();
    }

    return DOGECHAT_RC_OK;
}
Exemplo n.º 11
0
int
script_action_run ()
{
    char **actions, **argv, **argv_eol, *ptr_action;
    int num_actions, argc, i, j, quiet, script_found;
    struct t_script_repo *ptr_script;

    if (!script_actions)
        return 0;

    script_get_loaded_plugins ();

    actions = dogechat_string_split (script_actions, "\n", 0, 0, &num_actions);
    if (actions)
    {
        for (i = 0; i < num_actions; i++)
        {
            quiet = 0;
            ptr_action = actions[i];
            if (ptr_action[0] == '-')
            {
                /*
                 * if action starts with options (like "-q"),
                 * read and skip them
                 */
                ptr_action++;
                while (ptr_action[0] && (ptr_action[0] != ' '))
                {
                    switch (ptr_action[0])
                    {
                        case 'q': /* quiet */
                            quiet = 1;
                            break;
                    }
                    ptr_action++;
                }
                while (ptr_action[0] == ' ')
                {
                    ptr_action++;
                }
            }
            argv = dogechat_string_split (ptr_action, " ", 0, 0, &argc);
            argv_eol = dogechat_string_split (ptr_action, " ", 1, 0, &argc);
            if (argv && argv_eol)
            {
                if (dogechat_strcasecmp (argv[0], "buffer") == 0)
                {
                    /* open buffer with list of scripts */
                    if (!script_buffer)
                    {
                        script_buffer_open ();
                        script_buffer_refresh (1);
                    }
                    dogechat_buffer_set (script_buffer, "display", "1");
                }
                else if (dogechat_strcasecmp (argv[0], "list") == 0)
                {
                    if (argc > 1)
                    {
                        if (dogechat_strcasecmp (argv[1], "-i") == 0)
                            script_action_list_input (0);
                        else if (dogechat_strcasecmp (argv[1], "-o") == 0)
                            script_action_list_input (1);
                        else
                            script_action_list ();
                    }
                    else
                        script_action_list ();
                }
                else if (dogechat_strcasecmp (argv[0], "load") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_load (argv[j], quiet);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "unload") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_unload (argv[j], quiet);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "reload") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_reload (argv[j], quiet);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "autoload") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_autoload (argv[j], quiet, 1);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "noautoload") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_autoload (argv[j], quiet, 0);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "toggleautoload") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_autoload (argv[j], quiet, -1);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "install") == 0)
                {
                    script_found = 0;
                    for (j = 1; j < argc; j++)
                    {
                        ptr_script = script_repo_search_by_name_ext (argv[j]);
                        if (ptr_script)
                        {
                            if (ptr_script->status & SCRIPT_STATUS_HELD)
                            {
                                dogechat_printf (NULL,
                                                _("%s: script \"%s\" is held"),
                                                SCRIPT_PLUGIN_NAME, argv[j]);
                            }
                            else if ((ptr_script->status & SCRIPT_STATUS_INSTALLED)
                                     && !(ptr_script->status & SCRIPT_STATUS_NEW_VERSION))
                            {
                                dogechat_printf (NULL,
                                                _("%s: script \"%s\" is already "
                                                  "installed and up-to-date"),
                                                SCRIPT_PLUGIN_NAME, argv[j]);
                            }
                            else
                            {
                                script_found++;
                                ptr_script->install_order = script_found;
                            }
                        }
                        else
                        {
                            dogechat_printf (NULL,
                                            _("%s: script \"%s\" not found"),
                                            SCRIPT_PLUGIN_NAME, argv[j]);
                        }
                    }
                    if (script_found)
                        script_action_install (quiet);
                }
                else if (dogechat_strcasecmp (argv[0], "remove") == 0)
                {
                    for (j = 1; j < argc; j++)
                    {
                        script_action_remove (argv[j], quiet);
                    }
                }
                else if (dogechat_strcasecmp (argv[0], "installremove") == 0)
                {
                    script_found = 0;
                    for (j = 1; j < argc; j++)
                    {
                        ptr_script = script_repo_search_by_name_ext (argv[j]);
                        if (ptr_script)
                        {
                            if (ptr_script->status & SCRIPT_STATUS_HELD)
                            {
                                dogechat_printf (NULL,
                                                _("%s: script \"%s\" is held"),
                                                SCRIPT_PLUGIN_NAME, argv[j]);
                            }
                            else if (ptr_script->status & SCRIPT_STATUS_INSTALLED)
                            {
                                script_action_remove (argv[j], quiet);
                            }
                            else
                            {
                                script_found++;
                                ptr_script->install_order = script_found;
                            }
                        }
                        else
                        {
                            dogechat_printf (NULL,
                                            _("%s: script \"%s\" not found"),
                                            SCRIPT_PLUGIN_NAME, argv[j]);
                        }
                    }
                    if (script_found)
                        script_action_install (quiet);
                }
                else if (dogechat_strcasecmp (argv[0], "hold") == 0)
                {
                    script_found = 0;
                    for (j = 1; j < argc; j++)
                    {
                        if (script_action_hold (argv[j], quiet))
                            script_found = 1;
                    }
                    if (script_found)
                        script_buffer_refresh (0);
                }
                else if (dogechat_strcasecmp (argv[0], "show") == 0)
                {
                    if (!script_buffer)
                        script_buffer_open ();
                    script_action_show ((argc >= 2) ? argv[1] : NULL,
                                        quiet);
                    dogechat_buffer_set (script_buffer, "display", "1");
                }
                else if (dogechat_strcasecmp (argv[0], "showdiff") == 0)
                {
                    script_action_showdiff ();
                }
                else if (dogechat_strcasecmp (argv[0], "upgrade") == 0)
                {
                    script_found = 0;
                    for (ptr_script = scripts_repo; ptr_script;
                         ptr_script = ptr_script->next_script)
                    {
                        /*
                         * if script is installed, with new version available,
                         * and not held, then upgrade it
                         */
                        if ((ptr_script->status & SCRIPT_STATUS_INSTALLED)
                            && (ptr_script->status & SCRIPT_STATUS_NEW_VERSION)
                            && !(ptr_script->status & SCRIPT_STATUS_HELD))
                        {
                            script_found++;
                            ptr_script->install_order = script_found;
                        }
                    }
                    if (script_found)
                        script_action_install (quiet);
                    else
                    {
                        dogechat_printf (NULL,
                                        _("%s: all scripts are up-to-date"),
                                        SCRIPT_PLUGIN_NAME);
                    }
                }
            }
            if (argv)
                dogechat_string_free_split (argv);
            if (argv_eol)
                dogechat_string_free_split (argv_eol);
        }
        dogechat_string_free_split (actions);
    }

    free (script_actions);
    script_actions = NULL;

    return 1;
}
Exemplo n.º 12
0
void
fifo_create ()
{
    int filename_length;
    const char *fifo_option, *dogechat_home;

    fifo_option = dogechat_config_get_plugin ("fifo");
    if (!fifo_option)
    {
        dogechat_config_set_plugin ("fifo", "on");
        fifo_option = dogechat_config_get_plugin ("fifo");
    }

    dogechat_home = dogechat_info_get ("dogechat_dir", "");

    if (fifo_option && dogechat_home)
    {
        fifo_remove_old_pipes ();

        if (dogechat_strcasecmp (fifo_option, "on") == 0)
        {
            /*
             * build FIFO filename:
             *   "<dogechat_home>/dogechat_fifo_" + process PID
             */
            if (!fifo_filename)
            {
                filename_length = strlen (dogechat_home) + 64;
                fifo_filename = malloc (filename_length);
                snprintf (fifo_filename, filename_length,
                          "%s/%s%d",
                          dogechat_home, FIFO_FILENAME_PREFIX, (int) getpid());
            }

            fifo_fd = -1;

            /* create FIFO pipe, writable for user only */
            if (mkfifo (fifo_filename, 0600) == 0)
            {
                /* open FIFO pipe in read-only, non-blocking mode */
                if ((fifo_fd = open (fifo_filename,
                                     O_RDONLY | O_NONBLOCK)) != -1)
                {
                    if ((dogechat_fifo_plugin->debug >= 1) || !fifo_quiet)
                    {
                        dogechat_printf (NULL,
                                        _("%s: pipe opened (file: %s)"),
                                        FIFO_PLUGIN_NAME,
                                        fifo_filename);
                    }
                    fifo_fd_hook = dogechat_hook_fd (fifo_fd, 1, 0, 0,
                                                    &fifo_read, NULL);
                }
                else
                    dogechat_printf (NULL,
                                    _("%s%s: unable to open pipe (%s) for "
                                      "reading"),
                                    dogechat_prefix ("error"), FIFO_PLUGIN_NAME,
                                    fifo_filename);
            }
            else
            {
                dogechat_printf (NULL,
                                _("%s%s: unable to create pipe for remote "
                                  "control (%s): error %d %s"),
                                dogechat_prefix ("error"), FIFO_PLUGIN_NAME,
                                fifo_filename, errno, strerror (errno));
            }
        }
    }
}
Exemplo n.º 13
0
int
dogechat_plugin_init (struct t_dogechat_plugin *plugin, int argc, char *argv[])
{
    int i, auto_connect, upgrading;

    dogechat_plugin = plugin;

    if (!irc_config_init ())
        return DOGECHAT_RC_ERROR;

    irc_config_read ();

    irc_command_init ();

    irc_info_init ();

    irc_redirect_init ();

    irc_notify_init ();

    /* hook some signals */
    irc_debug_init ();
    dogechat_hook_signal ("quit", &irc_signal_quit_cb, NULL);
    dogechat_hook_signal ("upgrade", &irc_signal_upgrade_cb, NULL);
    dogechat_hook_signal ("xfer_send_ready", &irc_server_xfer_send_ready_cb, NULL);
    dogechat_hook_signal ("xfer_resume_ready", &irc_server_xfer_resume_ready_cb, NULL);
    dogechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL);
    dogechat_hook_signal ("irc_input_send", &irc_input_send_cb, NULL);

    /* hook hsignals for redirection */
    dogechat_hook_hsignal ("irc_redirect_pattern", &irc_redirect_pattern_hsignal_cb, NULL);
    dogechat_hook_hsignal ("irc_redirect_command", &irc_redirect_command_hsignal_cb, NULL);

    /* modifiers */
    dogechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL);
    dogechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL);
    dogechat_hook_modifier ("irc_color_decode_ansi", &irc_color_modifier_cb, NULL);

    /* hook completions */
    irc_completion_init ();

    irc_bar_item_init ();

    /* look at arguments */
    auto_connect = 1;
    upgrading = 0;
    for (i = 0; i < argc; i++)
    {
        if ((dogechat_strcasecmp (argv[i], "-a") == 0)
            || (dogechat_strcasecmp (argv[i], "--no-connect") == 0))
        {
            auto_connect = 0;
        }
        else if ((dogechat_strncasecmp (argv[i], IRC_PLUGIN_NAME, 3) == 0))
        {
            if (!irc_server_alloc_with_url (argv[i]))
            {
                dogechat_printf (
                    NULL,
                    _("%s%s: unable to add temporary server \"%s\" (check "
                      "if there is already a server with this name)"),
                    dogechat_prefix ("error"), IRC_PLUGIN_NAME, argv[i]);
            }
        }
        else if (dogechat_strcasecmp (argv[i], "--upgrade") == 0)
        {
            upgrading = 1;
        }
    }

    if (upgrading)
    {
        if (!irc_upgrade_load ())
        {
            dogechat_printf (
                NULL,
                _("%s%s: WARNING: some network connections may still be "
                  "opened and not visible, you should restart DogeChat now "
                  "(with /quit)."),
                dogechat_prefix ("error"), IRC_PLUGIN_NAME);
        }
    }
    else
    {
        irc_server_auto_connect (auto_connect);
    }

    irc_hook_timer = dogechat_hook_timer (1 * 1000, 0, 0,
                                         &irc_server_timer_cb, NULL);

    return DOGECHAT_RC_OK;
}
Exemplo n.º 14
0
int
exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
                   char **argv, char **argv_eol)
{
    int i, length, count;
    char *text;
    struct t_exec_cmd *ptr_exec_cmd, *ptr_next_exec_cmd;

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

    /* list running commands */
    if ((argc == 1)
        || ((argc == 2) && (dogechat_strcasecmp (argv[1], "-list") == 0)))
    {
        exec_command_list ();
        return DOGECHAT_RC_OK;
    }

    /* send text to a running process */
    if (dogechat_strcasecmp (argv[1], "-in") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(4, "-in");
        ptr_exec_cmd = exec_command_search_running_id (argv[2]);
        if (ptr_exec_cmd && ptr_exec_cmd->hook)
        {
            length = strlen (argv_eol[3]) + 1 + 1;
            text = malloc (length);
            if (text)
            {
                snprintf (text, length, "%s\n", argv_eol[3]);
                dogechat_hook_set (ptr_exec_cmd->hook, "stdin", text);
                free (text);
            }
        }
        return DOGECHAT_RC_OK;
    }

    /* send text to a running process (if given), then close stdin */
    if (dogechat_strcasecmp (argv[1], "-inclose") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(3, "-inclose");
        ptr_exec_cmd = exec_command_search_running_id (argv[2]);
        if (ptr_exec_cmd && ptr_exec_cmd->hook)
        {
            if (argc > 3)
            {
                length = strlen (argv_eol[3]) + 1 + 1;
                text = malloc (length);
                if (text)
                {
                    snprintf (text, length, "%s\n", argv_eol[3]);
                    dogechat_hook_set (ptr_exec_cmd->hook, "stdin", text);
                    free (text);
                }
            }
            dogechat_hook_set (ptr_exec_cmd->hook, "stdin_close", "1");
        }
        return DOGECHAT_RC_OK;
    }

    /* send a signal to a running process */
    if (dogechat_strcasecmp (argv[1], "-signal") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(4, "-signal");
        ptr_exec_cmd = exec_command_search_running_id (argv[2]);
        if (ptr_exec_cmd)
            dogechat_hook_set (ptr_exec_cmd->hook, "signal", argv[3]);
        return DOGECHAT_RC_OK;
    }

    /* send a KILL signal to a running process */
    if (dogechat_strcasecmp (argv[1], "-kill") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(3, "-kill");
        ptr_exec_cmd = exec_command_search_running_id (argv[2]);
        if (ptr_exec_cmd)
            dogechat_hook_set (ptr_exec_cmd->hook, "signal", "kill");
        return DOGECHAT_RC_OK;
    }

    /* send a KILL signal to all running processes */
    if (dogechat_strcasecmp (argv[1], "-killall") == 0)
    {
        for (ptr_exec_cmd = exec_cmds; ptr_exec_cmd;
             ptr_exec_cmd = ptr_exec_cmd->next_cmd)
        {
            if (ptr_exec_cmd->hook)
            {
                dogechat_hook_set (ptr_exec_cmd->hook, "signal", "kill");
            }
        }
        return DOGECHAT_RC_OK;
    }

    /* set a hook property */
    if (dogechat_strcasecmp (argv[1], "-set") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(5, "-set");
        ptr_exec_cmd = exec_command_search_running_id (argv[2]);
        if (ptr_exec_cmd)
            dogechat_hook_set (ptr_exec_cmd->hook, argv[3], argv_eol[4]);
        return DOGECHAT_RC_OK;
    }

    /* delete terminated command(s) */
    if (dogechat_strcasecmp (argv[1], "-del") == 0)
    {
        DOGECHAT_COMMAND_MIN_ARGS(3, "-del");
        if (dogechat_strcasecmp (argv[2], "-all") == 0)
        {
            count = 0;
            ptr_exec_cmd = exec_cmds;
            while (ptr_exec_cmd)
            {
                ptr_next_exec_cmd = ptr_exec_cmd->next_cmd;
                if (!ptr_exec_cmd->hook)
                {
                    exec_free (ptr_exec_cmd);
                    count++;
                }
                ptr_exec_cmd = ptr_next_exec_cmd;
            }
            dogechat_printf (NULL, _("%d commands removed"), count);
        }
        else
        {
            for (i = 2; i < argc; i++)
            {
                ptr_exec_cmd = exec_search_by_id (argv[i]);
                if (ptr_exec_cmd)
                {
                    if (ptr_exec_cmd->hook)
                    {
                        dogechat_printf (NULL,
                                        _("%s%s: command with id \"%s\" is still "
                                          "running"),
                                        dogechat_prefix ("error"), EXEC_PLUGIN_NAME,
                                        argv[i]);
                    }
                    else
                    {
                        exec_free (ptr_exec_cmd);
                        dogechat_printf (NULL,
                                        _("Command \"%s\" removed"), argv[i]);
                    }
                }
                else
                {
                    dogechat_printf (NULL,
                                    _("%s%s: command id \"%s\" not found"),
                                    dogechat_prefix ("error"), EXEC_PLUGIN_NAME,
                                    argv[i]);
                }
            }
        }
        return DOGECHAT_RC_OK;
    }

    return exec_command_run (buffer, argc, argv, argv_eol, 1);
}
Exemplo n.º 15
0
int
exec_command_parse_options (struct t_exec_cmd_options *cmd_options,
                            int argc, char **argv, int start_arg,
                            int set_command_index)
{
    int i, j, end, length, length_total;
    char *error;

    for (i = start_arg; i < argc; i++)
    {
        if (dogechat_strcasecmp (argv[i], "-sh") == 0)
        {
            cmd_options->use_shell = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nosh") == 0)
        {
            cmd_options->use_shell = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-bg") == 0)
        {
            cmd_options->detached = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nobg") == 0)
        {
            cmd_options->detached = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-stdin") == 0)
        {
            cmd_options->pipe_stdin = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nostdin") == 0)
        {
            cmd_options->pipe_stdin = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-buffer") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            cmd_options->ptr_buffer_name = argv[i];
            cmd_options->ptr_buffer = dogechat_buffer_search ("==", argv[i]);
            if (cmd_options->ptr_buffer
                && (dogechat_buffer_get_integer (cmd_options->ptr_buffer, "type") != 0))
            {
                /* only a buffer with formatted content is allowed */
                return 0;
            }
            if (!cmd_options->ptr_buffer)
                cmd_options->new_buffer = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-l") == 0)
        {
            cmd_options->output_to_buffer = 0;
            cmd_options->new_buffer = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-o") == 0)
        {
            cmd_options->output_to_buffer = 1;
            cmd_options->new_buffer = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-n") == 0)
        {
            cmd_options->output_to_buffer = 0;
            cmd_options->new_buffer = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nf") == 0)
        {
            cmd_options->output_to_buffer = 0;
            cmd_options->new_buffer = 2;
        }
        else if (dogechat_strcasecmp (argv[i], "-cl") == 0)
        {
            cmd_options->new_buffer_clear = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nocl") == 0)
        {
            cmd_options->new_buffer_clear = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-sw") == 0)
        {
            cmd_options->switch_to_buffer = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-nosw") == 0)
        {
            cmd_options->switch_to_buffer = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-ln") == 0)
        {
            cmd_options->line_numbers = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-noln") == 0)
        {
            cmd_options->line_numbers = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-flush") == 0)
        {
            cmd_options->flush = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-noflush") == 0)
        {
            cmd_options->flush = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-color") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            cmd_options->color = exec_search_color (argv[i]);
            if (cmd_options->color < 0)
                return 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-rc") == 0)
        {
            cmd_options->display_rc = 1;
        }
        else if (dogechat_strcasecmp (argv[i], "-norc") == 0)
        {
            cmd_options->display_rc = 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-timeout") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            error = NULL;
            cmd_options->timeout = strtol (argv[i], &error, 10);
            if (!error || error[0])
                return 0;
        }
        else if (dogechat_strcasecmp (argv[i], "-name") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            cmd_options->ptr_command_name = argv[i];
        }
        else if (dogechat_strcasecmp (argv[i], "-pipe") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            if (cmd_options->pipe_command)
            {
                free (cmd_options->pipe_command);
                cmd_options->pipe_command = NULL;
            }
            if (argv[i][0] == '"')
            {
                /* search the ending double quote */
                length_total = 1;
                end = i;
                while (end < argc)
                {
                    length = strlen (argv[end]);
                    length_total += length + 1;
                    if ((length > 0) && (argv[end][length - 1] == '"'))
                        break;
                    end++;
                }
                if (end == argc)
                    return 0;
                cmd_options->pipe_command = malloc (length_total);
                if (!cmd_options->pipe_command)
                    return 0;
                cmd_options->pipe_command[0] = '\0';
                for (j = i; j <= end; j++)
                {
                    if (cmd_options->pipe_command[0])
                        strcat (cmd_options->pipe_command, " ");
                    strcat (cmd_options->pipe_command,
                            (j == i) ? argv[j] + 1 : argv[j]);
                }
                length = strlen (cmd_options->pipe_command);
                if (length > 0)
                    cmd_options->pipe_command[length - 1] = '\0';
                i = end;
            }
            else
                cmd_options->pipe_command = strdup (argv[i]);
        }
        else if (dogechat_strcasecmp (argv[i], "-hsignal") == 0)
        {
            if (i + 1 >= argc)
                return 0;
            i++;
            if (cmd_options->hsignal)
            {
                free (cmd_options->hsignal);
                cmd_options->hsignal = NULL;
            }
            cmd_options->hsignal = strdup (argv[i]);
        }
        else
        {
            if (set_command_index)
            {
                cmd_options->command_index = i;
                break;
            }
            else
                return 0;
        }
    }

    return 1;
}
Exemplo n.º 16
0
int
dogechat_js_command_cb (void *data, struct t_gui_buffer *buffer,
                       int argc, char **argv, char **argv_eol)
{
    char *ptr_name, *path_script;

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

    if (argc == 1)
    {
        plugin_script_display_list (dogechat_js_plugin, js_scripts,
                                    NULL, 0);
    }
    else if (argc == 2)
    {
        if (dogechat_strcasecmp (argv[1], "list") == 0)
        {
            plugin_script_display_list (dogechat_js_plugin, js_scripts,
                                        NULL, 0);
        }
        else if (dogechat_strcasecmp (argv[1], "listfull") == 0)
        {
            plugin_script_display_list (dogechat_js_plugin, js_scripts,
                                        NULL, 1);
        }
        else if (dogechat_strcasecmp (argv[1], "autoload") == 0)
        {
            plugin_script_auto_load (dogechat_js_plugin, &dogechat_js_load_cb);
        }
        else if (dogechat_strcasecmp (argv[1], "reload") == 0)
        {
            dogechat_js_unload_all ();
            plugin_script_auto_load (dogechat_js_plugin, &dogechat_js_load_cb);
        }
        else if (dogechat_strcasecmp(argv[1], "unload"))
        {
            dogechat_js_unload_all ();
        }
    }
    else
    {
        if (dogechat_strcasecmp (argv[1], "list") == 0)
        {
            plugin_script_display_list (dogechat_js_plugin, js_scripts,
                                        argv_eol[2], 0);
        }
        else if (dogechat_strcasecmp (argv[1], "listfull") == 0)
        {
            plugin_script_display_list (dogechat_js_plugin, js_scripts,
                                        argv_eol[2], 1);
        }
        else if ((dogechat_strcasecmp (argv[1], "load") == 0)
                 || (dogechat_strcasecmp (argv[1], "reload") == 0)
                 || (dogechat_strcasecmp (argv[1], "unload") == 0))
        {
            ptr_name = argv_eol[2];
            if (strncmp (ptr_name, "-q ", 3) == 0)
            {
                js_quiet = 1;
                ptr_name += 3;
                while (ptr_name[0] == ' ')
                {
                    ptr_name++;
                }
            }
            if (dogechat_strcasecmp (argv[1], "load") == 0)
            {
                /* load javascript script */
                path_script = plugin_script_search_path (dogechat_js_plugin,
                                                         ptr_name);
                dogechat_js_load ((path_script) ? path_script : ptr_name);
                if (path_script)
                    free (path_script);
            }
            else if (dogechat_strcasecmp (argv[1], "reload") == 0)
            {
                /* reload one javascript script */
                dogechat_js_reload_name (ptr_name);
            }
            else if (dogechat_strcasecmp (argv[1], "unload") == 0)
            {
                /* unload javascript script */
                dogechat_js_unload_name (ptr_name);
            }
            js_quiet = 0;
        }
        else
            DOGECHAT_COMMAND_ERROR;
    }

    return DOGECHAT_RC_OK;
}