From: <ro...@us...> - 2006-06-07 01:51:34
|
Revision: 16227 Author: roast Date: 2006-06-06 18:51:23 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16227&view=rev Log Message: ----------- xmllogformat v0.3.1-0x support. 1<x<3 somewhere. Modified Paths: -------------- branches/soc-2006-file-loggers/src/log.c branches/soc-2006-file-loggers/src/util.c Modified: branches/soc-2006-file-loggers/src/log.c =================================================================== --- branches/soc-2006-file-loggers/src/log.c 2006-06-06 17:42:02 UTC (rev 16226) +++ branches/soc-2006-file-loggers/src/log.c 2006-06-07 01:51:23 UTC (rev 16227) @@ -34,6 +34,7 @@ static GSList *loggers = NULL; +static GaimLogLogger *xml_logger; static GaimLogLogger *html_logger; static GaimLogLogger *txt_logger; static GaimLogLogger *old_logger; @@ -46,6 +47,14 @@ static void log_get_log_sets_common(GHashTable *sets); +static gsize xml_logger_write(GaimLog *log, GaimMessageFlags type, + const char *from, time_t time, const char *message); +static void xml_logger_finalize(GaimLog *log); +static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *xml_logger_list_syslog(GaimAccount *account); +//static char *xml_logger_read(GaimLog *log, GaimLogReadFlags *flags); +static int xml_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); + static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, const char *from, time_t time, const char *message); static void html_logger_finalize(GaimLog *log); @@ -558,6 +567,17 @@ gaim_prefs_add_string("/core/logging/format", "txt"); + xml_logger = gaim_log_logger_new("xml", _("Unified Log Format (XML)"), 8, + NULL, + xml_logger_write, + xml_logger_finalize, + xml_logger_list, + txt_logger_read, + gaim_log_common_sizer, + xml_logger_total_size, + xml_logger_list_syslog); + gaim_log_logger_add(xml_logger); + html_logger = gaim_log_logger_new("html", _("HTML"), 8, NULL, html_logger_write, @@ -645,7 +665,7 @@ /* This log is new */ char *dir; struct tm *tm; - const char *tz; + char *tz; const char *date; char *filename; char *path; @@ -656,13 +676,18 @@ gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + // roast: tz must be strdup'd. gaim_escape_filename returns a pointer to static data, + // and I need it for escaping remote_user's name for the filename below tm = localtime(&log->time); - tz = gaim_escape_filename(gaim_utf8_strftime("%Z", tm)); - date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm); + tz = g_strdup(gaim_escape_filename(gaim_utf8_strftime("%Z", tm))); + date = gaim_utf8_strftime("%Y-%m-%dT%H%M%S%z", tm); - filename = g_strdup_printf("%s%s%s", date, tz, ext ? ext : ""); + filename = g_strdup_printf("%s_%s%s%s", + gaim_escape_filename(gaim_normalize(log->account, log->name)), + date, tz, ext ? ext : ""); path = g_build_filename(dir, filename, NULL); + g_free(tz); g_free(dir); g_free(filename); @@ -926,116 +951,125 @@ g_dir_close(log_dir); } -#if 0 /* Maybe some other time. */ /**************** ** XML LOGGER ** ****************/ +/* static const char *str_from_msg_type (GaimMessageFlags type) { + return ""; - return ""; - } +*/ -static void xml_logger_write(GaimLog *log, +static gsize xml_logger_write(GaimLog *log, GaimMessageFlags type, const char *from, time_t time, const char *message) { - char *xhtml = NULL; + char *msg_fixed; + const char *date = gaim_utf8_strftime("%F %T%z", localtime(&log->time)); + GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); + GaimLogCommonLoggerData *data = log->logger_data; + gsize written = 0; + GaimLogType original_type = log->type; + + /* This log is new. We could use the loggers 'new' function, but + * creating a new file there would result in empty files in the case + * that you open a convo with someone, but don't say anything. + */ if (!log->logger_data) { - /* This log is new. We could use the loggers 'new' function, but - * creating a new file there would result in empty files in the case - * that you open a convo with someone, but don't say anything. - */ - struct tm *tm; - const char *tz; - const char *date; - char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); - char *name; - char *filename; + const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); + gaim_log_common_writer(log, ".chatlog"); - if (dir == NULL) - return; + data = log->logger_data; - tm = localtime(&log->time); - tz = gaim_escape_filename(gaim_utf8_strftime("%Z", tm); - date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm); + // if file doesn't exist, die + if (!data->file) return 0; + + fprintf(data->file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); + + if (log->type == GAIM_LOG_SYSTEM) + written += fprintf(data->file, "<chat service=\"%s\" account=\"%s\" version=\"0.3.1-04\" gaim:logtype=\"system\">\n", + prpl, gaim_account_get_username(log->account)); + else + written += fprintf(data->file, "<chat service=\"%s\" account=\"%s\" version=\"0.3.1-04\">\n", + prpl, gaim_account_get_username(log->account)); + written += fprintf(data->file, "\t<event time=\"%s\" type=\"logStart\" \/>\n", date); + } - name = g_strdup_printf("%s%s%s", date, tz, ext ? ext : ""); + /* if we can't write to the file, give up before we hurt ourselves */ + if(!data->file) + return 0; - gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); - filename = g_build_filename(dir, name, NULL); - g_free(dir); - g_free(name); - - log->logger_data = g_fopen(filename, "a"); - if (!log->logger_data) { - gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); - g_free(filename); - return; - } - g_free(filename); - fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" - "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); - - date = gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", localtime(&log->time)); - fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", - date, log->name, prpl); + if (log->type == GAIM_LOG_SYSTEM) { + written += fprintf(data->file, "\t<event time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</event>\n", date, from, msg_fixed); } + else if (type & GAIM_MESSAGE_SYSTEM) { + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</message>\n", date, from, msg_fixed); + } + else if (type & GAIM_MESSAGE_ERROR) { + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"error\">%s</message>\n", date, from, msg_fixed); + } + else if (type & GAIM_MESSAGE_WHISPER) { + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"whisper\">%s</message>\n", date, from, msg_fixed); + } + else if (type & GAIM_MESSAGE_AUTO_RESP && (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV)) { + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\" auto=\"true\">%s</message>\n", date, from, msg_fixed); + } + else if (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV) { + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\">%s</message>\n", date, from, msg_fixed); + } + else { + gaim_debug_error("log", "Unhandled message type."); + written += fprintf(data->file, "\t<message time=\"%s\" sender=\"%s\">%s</message>\n", date, from, msg_fixed); + } - /* if we can't write to the file, give up before we hurt ourselves */ - if(!data->file) - return; + // TODO: haven't written end of file and seeked back - date = log_get_timestamp(log, time); + g_free(msg_fixed); + fflush(data->file); - gaim_markup_html_to_xhtml(message, &xhtml, NULL); - if (from) - fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", - str_from_msg_type(type), - type & GAIM_MESSAGE_SEND ? "direction='sent'" : - type & GAIM_MESSAGE_RECV ? "direction='received'" : "", - from, date, xhtml); - else - fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", - str_from_msg_type(type), - type & GAIM_MESSAGE_SEND ? "direction='sent'" : - type & GAIM_MESSAGE_RECV ? "direction='received'" : "", - date, xhtml): - fflush(log->logger_data); - g_free(date); - g_free(xhtml); + return written; } - static void xml_logger_finalize(GaimLog *log) +static void xml_logger_finalize(GaimLog *log) { - if (log->logger_data) { - fprintf(log->logger_data, "</conversation>\n"); - fclose(log->logger_data); - log->logger_data = NULL; + GaimLogCommonLoggerData *data = log->logger_data; + if (data) { + if (data->file) { + const char *date = gaim_utf8_strftime("%F %T%z", localtime(&log->time)); + fprintf(data->file, "\t<event time=\"%s\" type=\"logEnd\" \/>\n", date); + fprintf(data->file, "</conversation>\n"); + + fclose(data->file); + } + g_free(data->path); + + g_slice_free(GaimLogCommonLoggerData, data); } } static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account) { - return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger); + return gaim_log_common_lister(type, sn, account, ".chatlog", xml_logger); } -static GaimLogLogger xml_logger = { - N_("XML"), "xml", - NULL, - xml_logger_write, - xml_logger_finalize, - xml_logger_list, - NULL, - NULL, - NULL -}; -#endif +// xml_logger_Read +static int xml_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) +{ + return gaim_log_common_total_sizer(type, name, account, ".chatlog"); +} + +static GList *xml_logger_list_syslog(GaimAccount *account) +{ + return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".chatlog", html_logger); +} + /**************************** ** HTML LOGGER ************* ****************************/ Modified: branches/soc-2006-file-loggers/src/util.c =================================================================== --- branches/soc-2006-file-loggers/src/util.c 2006-06-06 17:42:02 UTC (rev 16226) +++ branches/soc-2006-file-loggers/src/util.c 2006-06-07 01:51:23 UTC (rev 16227) @@ -1342,7 +1342,7 @@ face = g_string_append_c(face, *q); q++; } - g_string_append_printf(style, "font-family: %s; ", face->str); + g_string_append_printf(style, "font-family: %s; ", g_strstrip(face->str)); g_string_free(face, TRUE); p = q; } else if(!g_ascii_strncasecmp(p, "size=", strlen("size="))) { @@ -1392,7 +1392,7 @@ pt->dest_tag = "span"; tags = g_list_prepend(tags, pt); if(style->len) - g_string_append_printf(xhtml, "<span style='%s'>", style->str); + g_string_append_printf(xhtml, "<span style='%s'>", g_strstrip(style->str)); else pt->ignore = TRUE; g_string_free(style, TRUE); @@ -1412,7 +1412,7 @@ color = g_string_append_c(color, *q); q++; } - g_string_append_printf(xhtml, "<span style='background: %s;'>", color->str); + g_string_append_printf(xhtml, "<span style='background: %s;'>", g_strstrip(color->str)); g_string_free(color, TRUE); if ((c = strchr(c, '>')) != NULL) c++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |