コード例 #1
0
char *
irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
{
    const char *dogechat_dir;
    char *key_path1, *key_path2, *content;

    if (!sasl_key)
        return NULL;

    content = NULL;

    dogechat_dir = dogechat_info_get ("dogechat_dir", "");
    key_path1 = dogechat_string_replace (sasl_key, "%h", dogechat_dir);
    key_path2 = (key_path1) ?
        dogechat_string_expand_home (key_path1) : NULL;

    if (key_path2)
        content = dogechat_file_get_content (key_path2);

    if (!content)
    {
        dogechat_printf (
            server->buffer,
            _("%s%s: unable to read private key in file \"%s\""),
            dogechat_prefix ("error"),
            IRC_PLUGIN_NAME,
            (key_path2) ? key_path2 : ((key_path1) ? key_path1 : sasl_key));
    }

    if (key_path1)
        free (key_path1);
    if (key_path2)
        free (key_path2);

    return content;
}
コード例 #2
0
void
exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer,
                   int out, const char *line)
{
    char *line_color, *line2, str_number[32], str_tags[1024];
    int length;

    if (!exec_cmd || !line)
        return;

    /*
     * if output is sent to the buffer, the buffer must exist
     * (we don't send output by default to core buffer)
     */
    if (exec_cmd->output_to_buffer && !exec_cmd->pipe_command && !buffer)
        return;

    /* decode colors */
    line_color = exec_decode_color (exec_cmd, line);
    if (!line_color)
        return;

    exec_cmd->output_line_nb++;

    if (exec_cmd->pipe_command)
    {
        if (strstr (exec_cmd->pipe_command, "$line"))
        {
            /* replace $line by line content */
            line2 = dogechat_string_replace (exec_cmd->pipe_command,
                                            "$line", line_color);
            if (line2)
            {
                dogechat_command (buffer, line2);
                free (line2);
            }
        }
        else
        {
            /* add line at the end of command, after a space */
            length = strlen (exec_cmd->pipe_command) + 1 + strlen (line_color) + 1;
            line2 = malloc (length);
            if (line2)
            {
                snprintf (line2, length,
                          "%s %s", exec_cmd->pipe_command, line_color);
                dogechat_command (buffer, line2);
                free (line2);
            }
        }
    }
    else if (exec_cmd->output_to_buffer)
    {
        if (exec_cmd->line_numbers)
        {
            length = 32 + strlen (line_color) + 1;
            line2 = malloc (length);
            if (line2)
            {
                snprintf (line2, length,
                          "%d. %s", exec_cmd->output_line_nb, line_color);
                dogechat_command (buffer, line2);
                free (line2);
            }
        }
        else
            dogechat_command (buffer, (line_color[0]) ? line_color : " ");
    }
    else
    {
        snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number);
        snprintf (str_tags, sizeof (str_tags),
                  "exec_%s,exec_cmd_%s",
                  (out == EXEC_STDOUT) ? "stdout" : "stderr",
                  (exec_cmd->name) ? exec_cmd->name : str_number);
        if (dogechat_buffer_get_integer (buffer, "type") == 1)
        {
            snprintf (str_number, sizeof (str_number),
                      "%d. ", exec_cmd->output_line_nb);
            dogechat_printf_y (buffer, -1,
                              "%s%s",
                              (exec_cmd->line_numbers) ? str_number : " ",
                              line_color);
        }
        else
        {
            snprintf (str_number, sizeof (str_number),
                      "%d\t", exec_cmd->output_line_nb);
            dogechat_printf_tags (buffer, str_tags,
                                 "%s%s",
                                 (exec_cmd->line_numbers) ? str_number : " \t",
                                 line_color);
        }
    }
}