예제 #1
0
int
dogechat_js_signal_script_action_cb (void *data, const char *signal,
                                    const char *type_data,
                                    void *signal_data)
{
    /* make C++ compiler happy */
    (void) data;

    if (strcmp (type_data, DOGECHAT_HOOK_SIGNAL_STRING) == 0)
    {
        if (strcmp (signal, "javascript_script_install") == 0)
        {
            plugin_script_action_add (&js_action_install_list,
                                      (const char *)signal_data);
            dogechat_hook_timer (1, 0, 1,
                                &dogechat_js_timer_action_cb,
                                &js_action_install_list);
        }
        else if (strcmp (signal, "javascript_script_remove") == 0)
        {
            plugin_script_action_add (&js_action_remove_list,
                                      (const char *)signal_data);
            dogechat_hook_timer (1, 0, 1,
                                &dogechat_js_timer_action_cb,
                                &js_action_remove_list);
        }
        else if (strcmp (signal, "javascript_script_autoload") == 0)
        {
            plugin_script_action_add (&js_action_autoload_list,
                                      (const char *)signal_data);
            dogechat_hook_timer (1, 0, 1,
                                &dogechat_js_timer_action_cb,
                                &js_action_autoload_list);
        }
    }

    return DOGECHAT_RC_OK;
}
예제 #2
0
int
script_action_install_process_cb (void *data, const char *command,
                                  int return_code, const char *out,
                                  const char *err)
{
    char *pos, *filename, *filename2, str_signal[256];
    int quiet, length;
    struct t_script_repo *ptr_script;

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

    quiet = (data) ? 1 : 0;

    if (return_code >= 0)
    {
        pos = strrchr (command, '/');

        if (err && err[0])
        {
            dogechat_printf (NULL,
                            _("%s%s: error downloading script \"%s\": %s"),
                            dogechat_prefix ("error"),
                            SCRIPT_PLUGIN_NAME,
                            (pos) ? pos + 1 : "?",
                            err);
            return DOGECHAT_RC_OK;
        }

        if (pos)
        {
            ptr_script = script_repo_search_by_name_ext (pos + 1);
            if (ptr_script)
            {
                filename = script_config_get_script_download_filename (ptr_script,
                                                                       NULL);
                if (filename)
                {
                    length = 16 + strlen (filename) + 1;
                    filename2 = malloc (length);
                    if (filename2)
                    {
                        snprintf (filename2, length,
                                  "%s%s%s",
                                  (quiet && dogechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "",
                                  (dogechat_config_boolean (script_config_scripts_autoload)) ? "-a " : "",
                                  filename);
                        snprintf (str_signal, sizeof (str_signal),
                                  "%s_script_install",
                                  script_language[ptr_script->language]);
                        (void) dogechat_hook_signal_send (str_signal,
                                                         DOGECHAT_HOOK_SIGNAL_STRING,
                                                         filename2);
                        free (filename2);
                    }
                    free (filename);
                }

                /* schedule install of next script */
                dogechat_hook_timer (10, 0, 1,
                                    &script_action_installnext_timer_cb,
                                    (quiet) ? (void *)1 : (void *)0);
            }
        }
    }

    return DOGECHAT_RC_OK;
}
예제 #3
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;
}
예제 #4
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 = dogechat_hashtable_new (32,
                                           DOGECHAT_HASHTABLE_STRING,
                                           DOGECHAT_HASHTABLE_STRING,
                                           NULL,
                                           NULL);
        if (hashtable)
        {
            dogechat_hashtable_set (hashtable, "command", exec_cmd->command);
            snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number);
            dogechat_hashtable_set (hashtable, "number", str_number);
            dogechat_hashtable_set (hashtable, "name", exec_cmd->name);
            output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]);
            dogechat_hashtable_set (hashtable, "out", output);
            if (output)
                free (output);
            output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]);
            dogechat_hashtable_set (hashtable, "err", output);
            if (output)
                free (output);
            snprintf (str_number, sizeof (str_number), "%d", return_code);
            dogechat_hashtable_set (hashtable, "rc", str_number);
            dogechat_hook_hsignal_send (exec_cmd->hsignal, hashtable);
            dogechat_hashtable_free (hashtable);
        }
    }
    else
    {
        ptr_buffer = dogechat_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 = dogechat_buffer_get_integer (ptr_buffer, "type");
            if (return_code >= 0)
            {
                if (buffer_type == 1)
                {
                    dogechat_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
                {
                    dogechat_printf_tags (ptr_buffer, "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)
                {
                    dogechat_printf_y (ptr_buffer, -1,
                                      _("%s: unexpected end of command %d "
                                        "(\"%s\")"),
                                      EXEC_PLUGIN_NAME, exec_cmd->number,
                                      exec_cmd->command);
                }
                else
                {
                    dogechat_printf_tags (ptr_buffer, "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 (dogechat_config_integer (exec_config_command_purge_delay) >= 0)
    {
        dogechat_hook_timer (1 + (1000 * dogechat_config_integer (exec_config_command_purge_delay)),
                            0, 1,
                            &exec_timer_delete_cb, exec_cmd);
    }
}
예제 #5
0
int
xfer_network_connect (struct t_xfer *xfer)
{
    int flags;

    if (xfer->type == XFER_TYPE_CHAT_SEND)
        xfer->status = XFER_STATUS_WAITING;
    else
        xfer->status = XFER_STATUS_CONNECTING;

    if (XFER_IS_SEND(xfer->type))
    {
        /* create socket */
        if (xfer->sock < 0)
        {
            xfer->sock = socket (xfer->local_address->sa_family, SOCK_STREAM,
                                 0);
            if (xfer->sock < 0)
                return 0;
        }

        /* listen to socket */
        flags = fcntl (xfer->sock, F_GETFL);
        if (flags == -1)
            flags = 0;
        if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1)
            return 0;
        if (listen (xfer->sock, 1) == -1)
            return 0;
        if (fcntl (xfer->sock, F_SETFL, flags) == -1)
            return 0;

        xfer->hook_fd = dogechat_hook_fd (xfer->sock,
                                          1, 0, 0,
                                          &xfer_network_fd_cb,
                                          xfer);

        /* add timeout */
        if (dogechat_config_integer (xfer_config_network_timeout) > 0)
        {
            xfer->hook_timer = dogechat_hook_timer (dogechat_config_integer (xfer_config_network_timeout) * 1000,
                                                    0, 1,
                                                    &xfer_network_timer_cb,
                                                    xfer);
        }
    }

    /* for chat receiving, connect to listening host */
    if (xfer->type == XFER_TYPE_CHAT_RECV)
    {
        xfer->hook_connect = dogechat_hook_connect (xfer->proxy,
                             xfer->remote_address_str,
                             xfer->port, 1, 0, NULL, NULL,
                             0, "NONE", NULL,
                             &xfer_network_connect_chat_recv_cb,
                             xfer);
    }

    /* for file receiving, connection is made in child process (blocking) */

    return 1;
}