Ejemplo n.º 1
0
char *
charset_decode_cb (const void *pointer, void *data,
                   const char *modifier, const char *modifier_data,
                   const char *string)
{
    const char *charset;

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

    charset = charset_get (charset_config_section_decode, modifier_data,
                           charset_default_decode);
    if (weechat_charset_plugin->debug)
    {
        weechat_printf (NULL,
                        "charset: debug: using 'decode' charset: %s "
                        "(modifier=\"%s\", modifier_data=\"%s\", string=\"%s\")",
                        charset, modifier, modifier_data, string);
    }
    if (charset && charset[0])
        return weechat_iconv_to_internal (charset, string);

    return NULL;
}
Ejemplo n.º 2
0
struct t_irc_raw_message *
irc_raw_message_add (struct t_irc_server *server, int send, int modified,
                     const char *message)
{
    char *buf, *buf2, prefix[256];
    const unsigned char *ptr_buf;
    const char *hexa = "0123456789ABCDEF";
    int pos_buf, pos_buf2, char_size, i;
    struct t_irc_raw_message *new_raw_message;
    
    buf = weechat_iconv_to_internal (NULL, message);
    buf2 = malloc ((strlen (buf) * 3) + 1);
    if (buf2)
    {
        ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message;
        pos_buf = 0;
        pos_buf2 = 0;
        while (ptr_buf[pos_buf])
        {
            if (ptr_buf[pos_buf] < 32)
            {
                buf2[pos_buf2++] = '\\';
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
                pos_buf++;
            }
            else
            {
                char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
                for (i = 0; i < char_size; i++)
                {
                    buf2[pos_buf2++] = ptr_buf[pos_buf++];
                }
            }
        }
        buf2[pos_buf2] = '\0';
    }
    snprintf (prefix, sizeof (prefix), "%s%s%s%s%s",
              (server) ? weechat_color ("chat_server") : "",
              (server) ? server->name : "",
              (server) ? " " : "",
              (send) ?
              weechat_color ("chat_prefix_quit") :
              weechat_color ("chat_prefix_join"),
              (send) ?
              ((modified) ? IRC_RAW_PREFIX_SEND_MOD : IRC_RAW_PREFIX_SEND) :
              ((modified) ? IRC_RAW_PREFIX_RECV_MOD : IRC_RAW_PREFIX_RECV));
    
    new_raw_message = irc_raw_message_add_to_list (time (NULL),
                                                   prefix,
                                                   (buf2) ? buf2 : ((buf) ? buf : message));
    
    if (buf)
        free (buf);
    if (buf2)
        free (buf2);
    
    return new_raw_message;
}
Ejemplo n.º 3
0
void
logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines)
{
    const char *charset;
    struct t_logger_line *last_lines, *ptr_lines;
    char *pos_message, *pos_tab, *error, *message;
    time_t datetime, time_now;
    struct tm tm_line;
    int num_lines;

    charset = weechat_info_get ("charset_terminal", "");

    weechat_buffer_set (buffer, "print_hooks_enabled", "0");

    num_lines = 0;
    last_lines = logger_tail_file (filename, lines);
    ptr_lines = last_lines;
    while (ptr_lines)
    {
        datetime = 0;
        pos_message = strchr (ptr_lines->data, '\t');
        if (pos_message)
        {
            /* initialize structure, because strptime does not do it */
            memset (&tm_line, 0, sizeof (struct tm));
            /*
             * we get current time to initialize daylight saving time in
             * structure tm_line, otherwise printed time will be shifted
             * and will not use DST used on machine
             */
            time_now = time (NULL);
            localtime_r (&time_now, &tm_line);
            pos_message[0] = '\0';
            error = strptime (ptr_lines->data,
                              weechat_config_string (logger_config_file_time_format),
                              &tm_line);
            if (error && !error[0] && (tm_line.tm_year > 0))
                datetime = mktime (&tm_line);
            pos_message[0] = '\t';
        }
        pos_message = (pos_message && (datetime != 0)) ?
            pos_message + 1 : ptr_lines->data;
        message = (charset) ?
            weechat_iconv_to_internal (charset, pos_message) : strdup (pos_message);
        if (message)
        {
            pos_tab = strchr (message, '\t');
            if (pos_tab)
                pos_tab[0] = '\0';
            weechat_printf_date_tags (buffer, datetime,
                                      "no_highlight,notify_none,logger_backlog",
                                      "%s%s%s%s%s",
                                      weechat_color (weechat_config_string (logger_config_color_backlog_line)),
                                      message,
                                      (pos_tab) ? "\t" : "",
                                      (pos_tab) ? weechat_color (weechat_config_string (logger_config_color_backlog_line)) : "",
                                      (pos_tab) ? pos_tab + 1 : "");
            if (pos_tab)
                pos_tab[0] = '\t';
            free (message);
        }
        num_lines++;
        ptr_lines = ptr_lines->next_line;
    }
    if (last_lines)
        logger_tail_free (last_lines);
    if (num_lines > 0)
    {
        weechat_printf_date_tags (buffer, datetime,
                                  "no_highlight,notify_none,logger_backlog_end",
                                  _("%s===\t%s========== End of backlog (%d lines) =========="),
                                  weechat_color (weechat_config_string (logger_config_color_backlog_end)),
                                  weechat_color (weechat_config_string (logger_config_color_backlog_end)),
                                  num_lines);
        weechat_buffer_set (buffer, "unread", "");
    }
    weechat_buffer_set (buffer, "print_hooks_enabled", "1");
}
Ejemplo n.º 4
0
struct t_relay_raw_message *
relay_raw_message_add (struct t_relay_client *client, int flags,
                       const char *message)
{
    char *buf, *buf2, prefix[256], prefix_arrow[16];
    const unsigned char *ptr_buf;
    const char *hexa = "0123456789ABCDEF";
    int pos_buf, pos_buf2, char_size, i;
    struct t_relay_raw_message *new_raw_message;

    buf = weechat_iconv_to_internal (NULL, message);
    buf2 = malloc ((strlen (buf) * 3) + 1);
    if (buf2)
    {
        ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message;
        pos_buf = 0;
        pos_buf2 = 0;
        while (ptr_buf[pos_buf])
        {
            if (ptr_buf[pos_buf] < 32)
            {
                buf2[pos_buf2++] = '\\';
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
                pos_buf++;
            }
            else
            {
                char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
                for (i = 0; i < char_size; i++)
                {
                    buf2[pos_buf2++] = ptr_buf[pos_buf++];
                }
            }
        }
        buf2[pos_buf2] = '\0';
    }

    /* build prefix with arrow */
    prefix_arrow[0] = '\0';
    switch (flags & (RELAY_RAW_FLAG_RECV | RELAY_RAW_FLAG_SEND))
    {
        case RELAY_RAW_FLAG_RECV:
            strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV);
            break;
        case RELAY_RAW_FLAG_SEND:
            strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND);
            break;
        default:
            if (flags & RELAY_RAW_FLAG_RECV)
                strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV);
            else
                strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND);
            break;
    }

    if (client)
    {
        snprintf (prefix, sizeof (prefix), "%s[%s%d%s] %s%s%s%s %s%s",
                  weechat_color ("chat_delimiters"),
                  weechat_color ("chat"),
                  client->id,
                  weechat_color ("chat_delimiters"),
                  weechat_color ("chat_server"),
                  relay_protocol_string[client->protocol],
                  (client->protocol_args) ? "." : "",
                  (client->protocol_args) ? client->protocol_args : "",
                  (flags & RELAY_RAW_FLAG_SEND) ?
                  weechat_color ("chat_prefix_quit") :
                  weechat_color ("chat_prefix_join"),
                  prefix_arrow);
    }
    else
    {
        snprintf (prefix, sizeof (prefix), "%s%s",
                  (flags & RELAY_RAW_FLAG_SEND) ?
                  weechat_color ("chat_prefix_quit") :
                  weechat_color ("chat_prefix_join"),
                  prefix_arrow);
    }

    new_raw_message = relay_raw_message_add_to_list (time (NULL),
                                                     prefix,
                                                     (buf2) ? buf2 : ((buf) ? buf : message));

    if (buf)
        free (buf);
    if (buf2)
        free (buf2);

    return new_raw_message;
}
Ejemplo n.º 5
0
struct t_irc_raw_message *
irc_raw_message_add (struct t_irc_server *server, int flags,
                     const char *message)
{
    char *buf, *buf2, prefix[256], prefix_arrow[16];
    const unsigned char *ptr_buf;
    const char *hexa = "0123456789ABCDEF";
    int pos_buf, pos_buf2, char_size, i;
    struct t_irc_raw_message *new_raw_message;

    buf = weechat_iconv_to_internal (NULL, message);
    buf2 = malloc ((strlen (buf) * 3) + 1);
    if (buf2)
    {
        ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message;
        pos_buf = 0;
        pos_buf2 = 0;
        while (ptr_buf[pos_buf])
        {
            if (ptr_buf[pos_buf] < 32)
            {
                buf2[pos_buf2++] = '\\';
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
                buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
                pos_buf++;
            }
            else
            {
                char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
                for (i = 0; i < char_size; i++)
                {
                    buf2[pos_buf2++] = ptr_buf[pos_buf++];
                }
            }
        }
        buf2[pos_buf2] = '\0';
    }

    /* build prefix with arrow */
    prefix_arrow[0] = '\0';
    switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND
                     | IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT))
    {
        case IRC_RAW_FLAG_RECV:
            strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
            break;
        case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED:
            strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED);
            break;
        case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT:
            strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT);
            break;
        case IRC_RAW_FLAG_SEND:
            strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
            break;
        case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED:
            strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED);
            break;
        default:
            if (flags & IRC_RAW_FLAG_RECV)
                strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
            else
                strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
            break;
    }

    snprintf (prefix, sizeof (prefix), "%s%s%s%s%s",
              (server) ? weechat_color ("chat_server") : "",
              (server) ? server->name : "",
              (server) ? " " : "",
              (flags & IRC_RAW_FLAG_SEND) ?
              weechat_color ("chat_prefix_quit") :
              weechat_color ("chat_prefix_join"),
              prefix_arrow);

    new_raw_message = irc_raw_message_add_to_list (time (NULL),
                                                   prefix,
                                                   (buf2) ? buf2 : ((buf) ? buf : message));

    if (buf)
        free (buf);
    if (buf2)
        free (buf2);

    return new_raw_message;
}
Ejemplo n.º 6
0
void
relay_raw_message_add (struct t_relay_client *client, int flags,
                       const char *data, int data_size)
{
    char *buf, *buf2, prefix[256], prefix_arrow[16];
    const unsigned char *ptr_buf;
    const char *hexa = "0123456789ABCDEF";
    int pos_buf, pos_buf2, char_size, i;
    struct t_relay_raw_message *new_raw_message;

    buf = NULL;
    buf2 = NULL;

    if (flags & RELAY_RAW_FLAG_BINARY)
    {
        /* binary message */
        buf = weechat_string_hex_dump (data, data_size, 16, "  > ", NULL);
        snprintf (prefix, sizeof (prefix), " ");
    }
    else
    {
        /* text message */
        buf = weechat_iconv_to_internal (NULL, data);
        buf2 = weechat_string_replace (buf, "\r", "");
        if (buf2)
        {
            free (buf);
            buf = buf2;
            buf2 = NULL;
        }
        buf2 = malloc ((strlen (buf) * 4) + 1);
        if (buf2)
        {
            ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)data;
            pos_buf = 0;
            pos_buf2 = 0;
            while (ptr_buf[pos_buf])
            {
                if ((ptr_buf[pos_buf] < 32) && (ptr_buf[pos_buf] != '\n'))
                {
                    buf2[pos_buf2++] = '\\';
                    buf2[pos_buf2++] = 'x';
                    buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
                    buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
                    pos_buf++;
                }
                else
                {
                    char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
                    for (i = 0; i < char_size; i++)
                    {
                        buf2[pos_buf2++] = ptr_buf[pos_buf++];
                    }
                }
            }
            buf2[pos_buf2] = '\0';
        }

        /* build prefix with arrow */
        prefix_arrow[0] = '\0';
        switch (flags & (RELAY_RAW_FLAG_RECV | RELAY_RAW_FLAG_SEND))
        {
            case RELAY_RAW_FLAG_RECV:
                strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV);
                break;
            case RELAY_RAW_FLAG_SEND:
                strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND);
                break;
            default:
                if (flags & RELAY_RAW_FLAG_RECV)
                    strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV);
                else
                    strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND);
                break;
        }

        if (client)
        {
            snprintf (prefix, sizeof (prefix), "%s%s %s[%s%d%s] %s%s%s%s",
                      (flags & RELAY_RAW_FLAG_SEND) ?
                      weechat_color ("chat_prefix_quit") :
                      weechat_color ("chat_prefix_join"),
                      prefix_arrow,
                      weechat_color ("chat_delimiters"),
                      weechat_color ("chat"),
                      client->id,
                      weechat_color ("chat_delimiters"),
                      weechat_color ("chat_server"),
                      relay_protocol_string[client->protocol],
                      (client->protocol_args) ? "." : "",
                      (client->protocol_args) ? client->protocol_args : "");
        }
        else
        {
            snprintf (prefix, sizeof (prefix), "%s%s",
                      (flags & RELAY_RAW_FLAG_SEND) ?
                      weechat_color ("chat_prefix_quit") :
                      weechat_color ("chat_prefix_join"),
                      prefix_arrow);
        }
    }

    new_raw_message = relay_raw_message_add_to_list (
        time (NULL),
        prefix,
        (buf2) ? buf2 : ((buf) ? buf : data));

    if (new_raw_message)
    {
        if (relay_raw_buffer)
            relay_raw_message_print (new_raw_message);
        if (weechat_config_integer (relay_config_look_raw_messages) == 0)
            relay_raw_message_free (new_raw_message);
    }

    if (buf)
        free (buf);
    if (buf2)
        free (buf2);
}