Esempio n. 1
0
int
xfer_command_me (void *data, struct t_gui_buffer *buffer, int argc,
                 char **argv, char **argv_eol)
{
    struct t_xfer *ptr_xfer;

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

    ptr_xfer = xfer_search_by_buffer (buffer);

    if (!ptr_xfer)
    {
        dogechat_printf (NULL,
                        _("%s%s: can't find xfer for buffer \"%s\""),
                        dogechat_prefix ("error"), XFER_PLUGIN_NAME,
                        dogechat_buffer_get_string (buffer, "name"));
        return DOGECHAT_RC_OK;
    }

    if (!XFER_HAS_ENDED(ptr_xfer->status))
    {
        xfer_chat_sendf (ptr_xfer, "\01ACTION %s\01\r\n",
                         (argv_eol[1]) ? argv_eol[1] : "");
        dogechat_printf_tags (buffer,
                             "no_highlight",
                             "%s%s%s %s%s",
                             dogechat_prefix ("action"),
                             dogechat_color ("chat_nick_self"),
                             ptr_xfer->local_nick,
                             dogechat_color ("chat"),
                             (argv_eol[1]) ? argv_eol[1] : "");
    }

    return DOGECHAT_RC_OK;
}
Esempio n. 2
0
void
script_action_list ()
{
    int i, scripts_loaded;
    char hdata_name[128];
    const char *ptr_name;
    struct t_hdata *hdata;
    void *ptr_script;

    dogechat_printf (NULL, "");
    dogechat_printf (NULL, _("Scripts loaded:"));

    scripts_loaded = 0;

    for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
    {
        snprintf (hdata_name, sizeof (hdata_name),
                  "%s_script", script_language[i]);
        hdata = dogechat_hdata_get (hdata_name);
        ptr_script = dogechat_hdata_get_list (hdata, "scripts");
        while (ptr_script)
        {
            ptr_name = dogechat_hdata_string (hdata, ptr_script, "name");
            dogechat_printf (NULL, " %s %s%s%s.%s %s%s %s(%s%s%s)",
                            script_repo_get_status_for_display (script_repo_search_by_name (ptr_name),
                                                                "*?iaHN", 0),
                            dogechat_color (dogechat_config_string (script_config_color_text_name)),
                            ptr_name,
                            dogechat_color (dogechat_config_string (script_config_color_text_extension)),
                            script_extension[i],
                            dogechat_color (dogechat_config_string (script_config_color_text_version)),
                            dogechat_hdata_string (hdata, ptr_script, "version"),
                            dogechat_color ("chat_delimiters"),
                            dogechat_color (dogechat_config_string (script_config_color_text_description)),
                            dogechat_hdata_string (hdata, ptr_script, "description"),
                            dogechat_color ("chat_delimiters"));
            scripts_loaded++;
            ptr_script = dogechat_hdata_move (hdata, ptr_script, 1);
        }
    }

    if (scripts_loaded == 0)
    {
        dogechat_printf (NULL, _("  (none)"));
    }
}
Esempio n. 3
0
int
script_action_show_source_process_cb (void *data, const char *command,
                                      int return_code, const char *out,
                                      const char *err)
{
    char *pos, *filename, *filename_loaded, line[4096], *ptr_line;
    char *diff_command;
    const char *ptr_diff_command;
    struct t_script_repo *ptr_script;
    FILE *file;
    int length, diff_made;

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

    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,
                                                                       ".repository");
                if (filename)
                {
                    /*
                     * read file and display content on script buffer
                     * (only if script buffer is still displaying detail of
                     * this script)
                     */
                    if (script_buffer && script_buffer_detail_script
                        && (script_buffer_detail_script == ptr_script))
                    {
                        file = fopen (filename, "r");
                        if (file)
                        {
                            while (!feof (file))
                            {
                                ptr_line = fgets (line, sizeof (line) - 1, file);
                                if (ptr_line)
                                {
                                    dogechat_printf_y (script_buffer,
                                                      script_buffer_detail_script_last_line++,
                                                      "%s", ptr_line);
                                }
                            }
                            fclose (file);
                        }
                        else
                        {
                            dogechat_printf_y (script_buffer,
                                              script_buffer_detail_script_last_line++,
                                              _("Error: file not found"));
                        }
                        dogechat_printf_y (script_buffer,
                                          script_buffer_detail_script_last_line++,
                                          "%s----------------------------------------"
                                          "----------------------------------------",
                                          dogechat_color ("lightcyan"));
                    }
                    diff_made = 0;
                    ptr_diff_command = script_config_get_diff_command ();
                    if (ptr_diff_command && ptr_diff_command[0]
                        && (ptr_script->status & SCRIPT_STATUS_NEW_VERSION))
                    {
                        /*
                         * diff command set => get the diff with a new process,
                         * file will be deleted later (in callback of this new
                         * process)
                         */
                        filename_loaded = script_repo_get_filename_loaded (ptr_script);
                        if (filename_loaded)
                        {
                            length = strlen (ptr_diff_command) + 1
                                + strlen (filename_loaded) + 1
                                + strlen (filename) + 1;
                            diff_command = malloc (length);
                            if (diff_command)
                            {
                                snprintf (diff_command, length,
                                          "%s %s %s",
                                          ptr_diff_command,
                                          filename_loaded,
                                          filename);
                                script_buffer_detail_script_last_line++;
                                script_buffer_detail_script_line_diff = script_buffer_detail_script_last_line;
                                dogechat_printf_y (script_buffer,
                                                  script_buffer_detail_script_last_line++,
                                                  "%s", diff_command);
                                dogechat_printf_y (script_buffer,
                                                  script_buffer_detail_script_last_line++,
                                                  "%s----------------------------------------"
                                                  "----------------------------------------",
                                                  dogechat_color ("magenta"));
                                dogechat_hook_process (diff_command, 10000,
                                                      &script_action_show_diff_process_cb,
                                                      filename);
                                diff_made = 1;
                                free (diff_command);
                            }
                            free (filename_loaded);
                        }
                    }
                    if (!diff_made)
                    {
                        /* no diff made: delete temporary file now */
                        unlink (filename);
                        free (filename);
                    }
                }
            }
        }
    }

    return DOGECHAT_RC_OK;
}
Esempio n. 4
0
int
script_action_show_diff_process_cb (void *data, const char *command,
                                    int return_code, const char *out,
                                    const char *err)
{
    char **lines, *filename;
    const char *color;
    int num_lines, i, diff_color;

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

    if (script_buffer && script_buffer_detail_script
        && ((return_code == DOGECHAT_HOOK_PROCESS_RUNNING) || (return_code >= 0)))
    {
        if (out)
        {
            lines = dogechat_string_split (out, "\n", 0, 0, &num_lines);
            if (lines)
            {
                diff_color = dogechat_config_boolean (script_config_look_diff_color);
                for (i = 0; i < num_lines; i++)
                {
                    color = NULL;
                    if (diff_color)
                    {
                        switch (lines[i][0])
                        {
                            case '-':
                            case '<':
                                color = dogechat_color ("red");
                                break;
                            case '+':
                            case '>':
                                color = dogechat_color ("green");
                                break;
                            case '@':
                                color = dogechat_color ("cyan");
                                break;
                        }
                    }
                    dogechat_printf_y (script_buffer,
                                      script_buffer_detail_script_last_line++,
                                      "%s%s",
                                      (color) ? color : "",
                                      lines[i]);
                }
                dogechat_string_free_split (lines);
            }
        }
        else if (err)
        {
            lines = dogechat_string_split (err, "\n", 0, 0, &num_lines);
            if (lines)
            {
                for (i = 0; i < num_lines; i++)
                {
                    dogechat_printf_y (script_buffer,
                                      script_buffer_detail_script_last_line++,
                                      "%s",
                                      lines[i]);
                }
                dogechat_string_free_split (lines);
            }
        }
        if (return_code >= 0)
        {
            dogechat_printf_y (script_buffer,
                              script_buffer_detail_script_last_line++,
                              "%s----------------------------------------"
                              "----------------------------------------",
                              dogechat_color ("magenta"));
        }
    }

    if ((return_code == DOGECHAT_HOOK_PROCESS_ERROR) || (return_code >= 0))
    {
        /* last call to this callback: delete temporary file */
        filename = (char *)data;
        unlink (filename);
        free (filename);
    }

    return DOGECHAT_RC_OK;
}
Esempio n. 5
0
void
script_action_show (const char *name, int quiet)
{
    struct t_script_repo *ptr_script;
    char *filename, *url;
    struct t_hashtable *options;

    if (name)
    {
        ptr_script = script_repo_search_by_name_ext (name);
        if (ptr_script)
        {
            script_buffer_show_detail_script (ptr_script);
            if (dogechat_config_boolean (script_config_look_display_source))
            {
                dogechat_printf_y (script_buffer,
                                  script_buffer_detail_script_last_line++,
                                  _("Source code:"));
                dogechat_printf_y (script_buffer,
                                  script_buffer_detail_script_last_line++,
                                  "%s----------------------------------------"
                                  "----------------------------------------",
                                  dogechat_color ("lightcyan"));
                dogechat_printf_y (script_buffer,
                                  script_buffer_detail_script_last_line,
                                  _("Downloading script..."));
                dogechat_printf_y (script_buffer,
                                  script_buffer_detail_script_last_line + 1,
                                  "%s----------------------------------------"
                                  "----------------------------------------",
                                  dogechat_color ("lightcyan"));
                filename = script_config_get_script_download_filename (ptr_script,
                                                                       ".repository");
                if (filename)
                {
                    options = dogechat_hashtable_new (32,
                                                     DOGECHAT_HASHTABLE_STRING,
                                                     DOGECHAT_HASHTABLE_STRING,
                                                     NULL,
                                                     NULL);
                    if (options)
                    {
                        url = script_build_download_url (ptr_script->url);
                        if (url)
                        {
                            dogechat_hashtable_set (options, "file_out", filename);
                            dogechat_hook_process_hashtable (
                                url,
                                options,
                                dogechat_config_integer (script_config_scripts_download_timeout) * 1000,
                                &script_action_show_source_process_cb,
                                NULL);
                            free (url);
                        }
                        dogechat_hashtable_free (options);
                    }
                    free (filename);
                }
            }
        }
        else
        {
            if (!quiet)
            {
                dogechat_printf (NULL,
                                _("%s: script \"%s\" not found"),
                                SCRIPT_PLUGIN_NAME, name);
            }
        }
    }
    else
        script_buffer_show_detail_script (NULL);
}
Esempio n. 6
0
void
xfer_command_xfer_list (int full)
{
    struct t_xfer *ptr_xfer;
    int i;
    char date[128];
    unsigned long long pct_complete;
    struct tm *date_tmp;

    if (xfer_list)
    {
        dogechat_printf (NULL, "");
        dogechat_printf (NULL, _("Xfer list:"));
        i = 1;
        for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
        {
            /* xfer info */
            if (XFER_IS_FILE(ptr_xfer->type))
            {
                if (ptr_xfer->size == 0)
                {
                    if (ptr_xfer->status == XFER_STATUS_DONE)
                        pct_complete = 100;
                    else
                        pct_complete = 0;
                }
                else
                    pct_complete = (unsigned long long)(((float)(ptr_xfer->pos)/(float)(ptr_xfer->size)) * 100);

                dogechat_printf (NULL,
                                _("%3d. %s (%s), file: \"%s\" (local: "
                                  "\"%s\"), %s %s, status: %s%s%s "
                                  "(%llu %%)"),
                                i,
                                xfer_type_string[ptr_xfer->type],
                                xfer_protocol_string[ptr_xfer->protocol],
                                ptr_xfer->filename,
                                ptr_xfer->local_filename,
                                (XFER_IS_SEND(ptr_xfer->type)) ?
                                _("sent to") : _("received from"),
                                ptr_xfer->remote_nick,
                                dogechat_color (
                                    dogechat_config_string (
                                        xfer_config_color_status[ptr_xfer->status])),
                                _(xfer_status_string[ptr_xfer->status]),
                                dogechat_color ("chat"),
                                pct_complete);
            }
            else
            {
                date[0] = '\0';
                date_tmp = localtime (&(ptr_xfer->start_time));
                if (date_tmp)
                {
                    strftime (date, sizeof (date),
                              "%a, %d %b %Y %H:%M:%S", date_tmp);
                }
                dogechat_printf (NULL,
                                /* TRANSLATORS: "%s" after "started on" is a date */
                                _("%3d. %s, chat with %s (local nick: %s), "
                                  "started on %s, status: %s%s"),
                                i,
                                xfer_type_string[ptr_xfer->type],
                                ptr_xfer->remote_nick,
                                ptr_xfer->local_nick,
                                date,
                                dogechat_color(
                                    dogechat_config_string(
                                        xfer_config_color_status[ptr_xfer->status])),
                                _(xfer_status_string[ptr_xfer->status]));
            }

            if (full)
            {
                /* second line of xfer info */
                if (XFER_IS_FILE(ptr_xfer->type))
                {
                    dogechat_printf (NULL,
                                    _("     plugin: %s (id: %s), file: %llu "
                                      "bytes (position: %llu), address: "
                                      "%s (port %d)"),
                                    ptr_xfer->plugin_name,
                                    ptr_xfer->plugin_id,
                                    ptr_xfer->size,
                                    ptr_xfer->pos,
                                    ptr_xfer->remote_address_str,
                                    ptr_xfer->port);
                    date[0] = '\0';
                    date_tmp = localtime (&(ptr_xfer->start_transfer));
                    if (date_tmp)
                    {
                        strftime (date, sizeof (date),
                                  "%a, %d %b %Y %H:%M:%S", date_tmp);
                    }
                    dogechat_printf (NULL,
                                    /* TRANSLATORS: "%s" after "started on" is a date */
                                    _("     fast_send: %s, blocksize: %d, "
                                      "started on %s"),
                                    (ptr_xfer->fast_send) ? _("yes") : _("no"),
                                    ptr_xfer->blocksize,
                                    date);
                }
            }
            i++;
        }
    }
    else
        dogechat_printf (NULL, _("No xfer"));
}
Esempio n. 7
0
void
exec_command_list ()
{
    struct t_exec_cmd *ptr_exec_cmd;
    char str_elapsed[32], str_time1[256], str_time2[256];
    time_t elapsed_time;
    struct tm *local_time;

    dogechat_printf (NULL, "");

    if (!exec_cmds)
    {
        dogechat_printf (NULL, _("No command is running"));
        return;
    }

    dogechat_printf (NULL, _("Commands:"));

    for (ptr_exec_cmd = exec_cmds; ptr_exec_cmd;
         ptr_exec_cmd = ptr_exec_cmd->next_cmd)
    {
        elapsed_time = (ptr_exec_cmd->end_time == 0) ?
            time (NULL) - ptr_exec_cmd->start_time :
            ptr_exec_cmd->end_time - ptr_exec_cmd->start_time;
        if (elapsed_time >= 3600)
        {
            snprintf (str_elapsed, sizeof (str_elapsed),
                      /* TRANSLATORS: format: hours + minutes, for example: 3h59 */
                      _("%dh%02d"),
                      elapsed_time / 3600,
                      elapsed_time % 3600);
        }
        else if (elapsed_time >= 60)
        {
            snprintf (str_elapsed, sizeof (str_elapsed),
                      /* TRANSLATORS: format: minutes + seconds, for example: 3m59 */
                      _("%dm%02d"),
                      elapsed_time / 60,
                      elapsed_time % 60);
        }
        else
        {
            snprintf (str_elapsed, sizeof (str_elapsed),
                      /* TRANSLATORS: format: seconds, for example: 59s */
                      _("%ds"),
                      elapsed_time);
        }
        if (ptr_exec_cmd->end_time == 0)
        {
            /* running command */
            dogechat_printf (NULL,
                            /* TRANSLATORS: %s before "ago" is elapsed time, for example: "3m59" */
                            _("  %s%s%s %d%s%s%s: %s\"%s%s%s\"%s (pid: %d, "
                              "started %s ago)"),
                            dogechat_color (dogechat_config_string (exec_config_color_flag_running)),
                            ">>",
                            dogechat_color ("reset"),
                            ptr_exec_cmd->number,
                            (ptr_exec_cmd->name) ? " (" : "",
                            (ptr_exec_cmd->name) ? ptr_exec_cmd->name : "",
                            (ptr_exec_cmd->name) ? ")" : "",
                            dogechat_color ("chat_delimiters"),
                            dogechat_color ("reset"),
                            ptr_exec_cmd->command,
                            dogechat_color ("chat_delimiters"),
                            dogechat_color ("reset"),
                            ptr_exec_cmd->pid,
                            str_elapsed);
        }
        else
        {
            /* process has ended */
            local_time = localtime (&ptr_exec_cmd->start_time);
            strftime (str_time1, sizeof (str_time1),
                      "%Y-%m-%d %H:%M:%S", local_time);
            local_time = localtime (&ptr_exec_cmd->end_time);
            strftime (str_time2, sizeof (str_time2),
                      "%Y-%m-%d %H:%M:%S", local_time);
            dogechat_printf (NULL,
                            "  %s%s%s %d%s%s%s: %s\"%s%s%s\"%s (%s -> %s, %s)",
                            dogechat_color (dogechat_config_string (exec_config_color_flag_finished)),
                            "[]",
                            dogechat_color ("reset"),
                            ptr_exec_cmd->number,
                            (ptr_exec_cmd->name) ? " (" : "",
                            (ptr_exec_cmd->name) ? ptr_exec_cmd->name : "",
                            (ptr_exec_cmd->name) ? ")" : "",
                            dogechat_color ("chat_delimiters"),
                            dogechat_color ("reset"),
                            ptr_exec_cmd->command,
                            dogechat_color ("chat_delimiters"),
                            dogechat_color ("reset"),
                            str_time1,
                            str_time2,
                            str_elapsed);
        }
    }
}