From: <ro...@us...> - 2006-07-26 03:01:35
|
Revision: 16575 Author: roast Date: 2006-07-25 20:01:27 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16575&view=rev Log Message: ----------- accountformatted and senderformatted done. Modified Paths: -------------- branches/soc-2006-file-loggers/src/log.c Modified: branches/soc-2006-file-loggers/src/log.c =================================================================== --- branches/soc-2006-file-loggers/src/log.c 2006-07-25 17:46:58 UTC (rev 16574) +++ branches/soc-2006-file-loggers/src/log.c 2006-07-26 03:01:27 UTC (rev 16575) @@ -1019,8 +1019,14 @@ GError *gerror = NULL; char *from_normed = g_strdup(gaim_normalize(log->account, from)); - gboolean from_is_normed = (g_ascii_strcasecmp(from, from_normed) == 0); - char *from_suffix = g_strconcat(from_normed, "\" senderformatted=\"", NULL); + char *from_attributes; + if (strncmp(from, from_normed, strlen(from)) == 0) { + // if from is already normalized; leave senderformatted out + from_attributes = g_strconcat(" sender=\"", from_normed, "\"", NULL); + } else { + // from is NOT normalized; specifying senderformatted + from_attributes = g_strconcat(" sender=\"", from_normed, "\" senderformatted=\"", from, "\"", NULL); + } writebuf = g_string_new(""); @@ -1031,10 +1037,17 @@ if (!log->logger_data) { const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); - /* this is not thread-safe at all */ char *account_normed = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); - gboolean account_is_normed = (g_ascii_strcasecmp(gaim_account_get_username(log->account), account_normed)); - char *account_suffix = g_strconcat(account_suffix, "\" accountformatted=\"", NULL); + char *account_attributes; + if (strncmp(gaim_account_get_username(log->account), account_normed, strlen(account_normed)) == 0) { + // if account is already normalized + account_attributes = g_strconcat(" account=\"", account_normed, "\"", NULL); + } else { + // account is NOT normalized; specifying accountformatted + account_attributes = g_strconcat(" account=\"", account_normed, + "\" accountformatted=\"", + gaim_account_get_username(log->account), "\"", NULL); + } gaim_log_common_writer(log, ".chatlog"); @@ -1046,12 +1059,11 @@ g_string_printf(writebuf, "%c%c%c" "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" - "<chat xmlns=\"http://purl.org/net/ulf/ns/0.4-02\" service=\"%s\" account=\"%s%s\"%s>\n" + "<chat xmlns=\"http://purl.org/net/ulf/ns/0.4-02\" service=\"%s\"%s%s>\n" "\t<event time=\"%s\" type=\"logStart\" />\n", 0xEF, 0xBB, 0xBF, prpl, - account_is_normed ? "" : account_suffix, - gaim_account_get_username(log->account), - log->type == GAIM_LOG_SYSTEM ? "gaim:logtype=\"system\"" : "", date); + account_attributes, + log->type == GAIM_LOG_SYSTEM ? " gaim:logtype=\"system\"" : "", date); iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); if (iostat == G_IO_STATUS_ERROR) { @@ -1062,7 +1074,7 @@ else written += written_buf; g_free(account_normed); - g_free(account_suffix); + g_free(account_attributes); } /* if we can't write to the file, give up before we hurt ourselves */ @@ -1072,19 +1084,19 @@ gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); if (log->type == GAIM_LOG_SYSTEM) { - g_string_printf(writebuf, "\t<event time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</event>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<event time=\"%s\"%s gaim:type=\"system\">%s</event>\n", date, from_attributes, msg_fixed); } else if (type & GAIM_MESSAGE_SYSTEM) { - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\"%s gaim:type=\"system\">%s</message>\n", date, from_attributes, msg_fixed); } else if (type & GAIM_MESSAGE_ERROR) { - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"error\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\"%s gaim:type=\"error\">%s</message>\n", date, from_attributes, msg_fixed); } else if (type & GAIM_MESSAGE_WHISPER) { - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" type=\"whisper\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\"%s type=\"whisper\">%s</message>\n", date, from_attributes, msg_fixed); } else if (type & GAIM_MESSAGE_BELL) { - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" type=\"bell\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\"%s type=\"bell\">%s</message>\n", date, from_attributes, msg_fixed); } else if (type & GAIM_MESSAGE_AUTO_RESP && (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV)) { gboolean recv_from_self = FALSE; @@ -1096,8 +1108,8 @@ } } - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\"%s%s auto=\"true\">%s</message>\n", - date, from, recv_from_self ? " self=\"true\"" : "", + g_string_printf(writebuf, "\t<message time=\"%s\"%s%s%s auto=\"true\">%s</message>\n", + date, from_attributes, recv_from_self ? " self=\"true\"" : "", gaim_message_is_action(msg_fixed, -1) ? " type=\"action\"": "", msg_fixed); } else if (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV) { @@ -1110,13 +1122,13 @@ } } - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\"%s%s>%s</message>\n", - date, from, recv_from_self ? " self=\"true\"" : "", + g_string_printf(writebuf, "\t<message time=\"%s\"%s%s%s>%s</message>\n", + date, from_attributes, recv_from_self ? " self=\"true\"" : "", gaim_message_is_action(msg_fixed, -1) ? " type=\"action\"": "", msg_fixed); } else { gaim_debug_error("log", "Unhandled message type."); - g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\"%s>%s</message>\n", date, from_attributes, msg_fixed); } iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); @@ -1158,7 +1170,7 @@ } g_free(from_normed); - g_free(from_suffix); + g_free(from_attributes); g_string_free(writebuf, TRUE); return written; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |