Mercurial > pidgin.yaz
changeset 7431:643cbc9a6035
[gaim-migrate @ 8036]
This is good enough for CVS. This is new logging. It centers around the
highly modular "GaimLogLogger," which controls how to write the log. Currently
I only have the plain text logger. I wrote the beginning of an XML logger, but
decided I didn't think it was that great an idea. Plugins can implement loggers
themselves, so you can have, like, an SQL logger or something.
The default logger writes to a file unique to the conversation, and they're saved
on disk in a heirarchical fashion: ~/.gaim/logs/aim/seanegn/robflynn-date.log would
be a conversation I had with Rob on date.
What doesn't work:
System logging
The search button in the log viewer.
Oh, chats probably don't log either, I didn't test.
You can only log in plain text right now.
Obviously, it's not done yet. But you can play around with it, and give it
some love. I'll get back to it tomorrow after school, maybe.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 05 Nov 2003 06:15:49 +0000 |
parents | 783eea64614c |
children | 31faec55ef8e |
files | src/Makefile.am src/connection.c src/conversation.c src/conversation.h src/core.c src/dialogs.c src/gaimrc.c src/gtkconn.c src/gtkconv.c src/gtkprefs.c src/idle.c src/log.c src/log.h src/main.c src/server.c |
diffstat | 15 files changed, 813 insertions(+), 699 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am Wed Nov 05 00:18:51 2003 +0000 +++ b/src/Makefile.am Wed Nov 05 06:15:49 2003 +0000 @@ -135,6 +135,8 @@ gtkimhtml.c \ gtkimhtml.h \ gtkinternal.h \ + gtklog.c \ + gtklog.h \ gtknotify.c \ gtknotify.h \ gtkplugin.c \
--- a/src/connection.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/connection.c Wed Nov 05 06:15:49 2003 +0000 @@ -239,10 +239,10 @@ gaim_connection_set_state(gc, GAIM_DISCONNECTED); + /* LOG system_log(log_signoff, gc, NULL, + OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc); - system_log(log_signoff, gc, NULL, - OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); /* * XXX This is a hack! Remove this and replace it with a better event @@ -328,11 +328,10 @@ GAIM_CONV_ACCOUNT_ONLINE); } + /* LOG system_log(log_signon, gc, NULL, + OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc); - system_log(log_signon, gc, NULL, - OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); - #if 0 /* away option given? */ if (opt_away) {
--- a/src/conversation.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/conversation.c Wed Nov 05 06:15:49 2003 +0000 @@ -807,6 +807,8 @@ conv->history = g_string_new(""); conv->data = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + conv->log = gaim_log_new(GAIM_LOG_IM, name, account, time(NULL)); + if (type == GAIM_CONV_IM) { @@ -1000,6 +1002,7 @@ if (ops != NULL && ops->destroy_conversation != NULL) ops->destroy_conversation(conv); + gaim_log_free(conv->log); g_free(conv); } @@ -1394,7 +1397,7 @@ if (who == NULL) { if (flags & GAIM_MESSAGE_SEND) { b = gaim_find_buddy(account, - gaim_account_get_username(account)); + gaim_account_get_username(account)); if (b != NULL && strcmp(b->name, gaim_get_buddy_alias(b))) who = gaim_get_buddy_alias(b); @@ -1407,7 +1410,7 @@ } else { b = gaim_find_buddy(account, - gaim_conversation_get_name(conv)); + gaim_conversation_get_name(conv)); if (b != NULL) who = gaim_get_buddy_alias(b); @@ -1424,6 +1427,7 @@ } } + gaim_log_write(conv->log, flags, who, mtime, message); ops->write_conv(conv, who, message, flags, mtime); win = gaim_conversation_get_window(conv);
--- a/src/conversation.h Wed Nov 05 00:18:51 2003 +0000 +++ b/src/conversation.h Wed Nov 05 06:15:49 2003 +0000 @@ -116,6 +116,7 @@ } GaimMessageFlags; #include "account.h" +#include "log.h" #include "buddyicon.h" #include "server.h" @@ -241,7 +242,9 @@ char *title; /**< The window title. */ gboolean logging; /**< The status of logging. */ - + + GaimLog *log; /**< This conversation's log */ + GList *send_history; /**< The send history. */ GString *history; /**< The conversation history. */
--- a/src/core.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/core.c Wed Nov 05 06:15:49 2003 +0000 @@ -84,6 +84,7 @@ gaim_connections_init(); gaim_conversations_init(); gaim_blist_init(); + gaim_log_init(); gaim_buddy_icons_init(); gaim_privacy_init(); gaim_pounces_init();
--- a/src/dialogs.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/dialogs.c Wed Nov 05 06:15:49 2003 +0000 @@ -903,89 +903,6 @@ } -/*------------------------------------------------------------------------*/ -/* Functions Called To Add A Log */ -/*------------------------------------------------------------------------*/ - -void cancel_log(GtkWidget *widget, GaimConversation *c) -{ - GaimGtkConversation *gtkconv; - - gtkconv = GAIM_GTK_CONVERSATION(c); - - if (gtkconv->toolbar.log) { - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->toolbar.log), - FALSE); - } - - dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.log); - gtk_widget_destroy(gtkconv->dialogs.log); - gtkconv->dialogs.log = NULL; -} - -void do_log(GtkWidget *w, GaimConversation *c) -{ - GaimGtkConversation *gtkconv; - struct log_conversation *l; - const char *file; - char path[PATHSIZE]; - - gtkconv = GAIM_GTK_CONVERSATION(c); - - if (!find_log_info(c->name)) { - file = gtk_file_selection_get_filename( - GTK_FILE_SELECTION(gtkconv->dialogs.log)); - - strncpy(path, file, PATHSIZE - 1); - - if (gaim_gtk_check_if_dir(path, GTK_FILE_SELECTION(gtkconv->dialogs.log))) - return; - - l = (struct log_conversation *)g_new0(struct log_conversation, 1); - strcpy(l->name, gaim_conversation_get_name(c)); - strcpy(l->filename, file); - log_conversations = g_list_append(log_conversations, l); - - if (c != NULL) - gaim_conversation_set_logging(c, TRUE); - } - - cancel_log(NULL, c); -} - -void show_log_dialog(GaimConversation *c) -{ - GaimGtkConversation *gtkconv; - char *buf = g_malloc(BUF_LEN); - - gtkconv = GAIM_GTK_CONVERSATION(c); - - if (!gtkconv->dialogs.log) { - gtkconv->dialogs.log = gtk_file_selection_new(_("Log Conversation")); - - gtk_file_selection_hide_fileop_buttons( - GTK_FILE_SELECTION(gtkconv->dialogs.log)); - - g_snprintf(buf, BUF_LEN - 1, "%s" G_DIR_SEPARATOR_S "%s.log", - gaim_home_dir(), gaim_normalize(c->account, c->name)); - g_object_set_data(G_OBJECT(gtkconv->dialogs.log), "dialog_type", - "log dialog"); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(gtkconv->dialogs.log), - buf); - g_signal_connect(G_OBJECT(gtkconv->dialogs.log), "delete_event", - G_CALLBACK(delete_event_dialog), c); - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.log)->ok_button), "clicked", - G_CALLBACK(do_log), c); - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.log)->cancel_button), "clicked", - G_CALLBACK(cancel_log), c); - } - - g_free(buf); - - gtk_widget_show(gtkconv->dialogs.log); - gdk_window_raise(gtkconv->dialogs.log->window); -} - /*------------------------------------------------------*/ /* Link Dialog */ /*------------------------------------------------------*/ @@ -2098,19 +2015,6 @@ g_free(x); } -void conv_show_log(GtkWidget *w, gpointer data) -{ - char *name = g_strdup(data); - show_log(name); - g_free(name); -} - -void chat_show_log(GtkWidget *w, gpointer data) -{ - char *name = g_strdup_printf("%s.chat", (char*)data); - show_log(name); - g_free(name); -} static void url_clicked_cb(GtkWidget *widget, const char *uri)
--- a/src/gaimrc.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/gaimrc.c Wed Nov 05 06:15:49 2003 +0000 @@ -63,6 +63,10 @@ #define OPT_LOG_STRIP_HTML 0x00000002 #define OPT_LOG_INDIVIDUAL 0x00000040 #define OPT_LOG_CHATS 0x00000100 +#define OPT_LOG_BUDDY_SIGNON 0x00000004 +#define OPT_LOG_BUDDY_IDLE 0x00000008 +#define OPT_LOG_BUDDY_AWAY 0x00000010 +#define OPT_LOG_MY_SIGNON 0x00000020 #define OPT_BLIST_SHOW_GRPNUM 0x00000008 #define OPT_BLIST_SHOW_PIXMAPS 0x00000010
--- a/src/gtkconn.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/gtkconn.c Wed Nov 05 06:15:49 2003 +0000 @@ -277,6 +277,8 @@ static void disconnect_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget) { + GaimAccount *account = NULL; + switch(id) { case GTK_RESPONSE_CLOSE: gtk_widget_destroy(disconnect_window->window); @@ -284,6 +286,8 @@ disconnect_window = NULL; break; case GTK_RESPONSE_ACCEPT: + + gaim_account_connect(account); break; } }
--- a/src/gtkconv.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/gtkconv.c Wed Nov 05 06:15:49 2003 +0000 @@ -47,6 +47,7 @@ #include "gtkblist.h" #include "gtkconv.h" #include "gtkimhtml.h" +#include "gtklog.h" #include "gtkpounce.h" #include "gtkprivacy.h" #include "gtkutils.h" @@ -712,7 +713,7 @@ conv = gaim_conv_window_get_active_conversation(win); - conv_show_log(NULL, (char *)gaim_conversation_get_name(conv)); + gaim_gtk_log_show((char *)gaim_conversation_get_name(conv), gaim_conversation_get_account(conv)); } struct _search { @@ -4088,7 +4089,7 @@ * * This should probably be elsewhere, but then, logging should * be moved out in some way, either via plugin or via a new API. - */ + if (gaim_conversation_is_logging(conv) && conv_type != GAIM_CONV_MISC) { @@ -4102,7 +4103,6 @@ fd = open_log_file(filename, (conv_type == GAIM_CONV_CHAT)); if (fd) { - /* "---- " is a delimiter, see dialogs.c:show_log() */ if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) fprintf(fd, _("<HR><BR><H3 Align=Center> " @@ -4115,7 +4115,7 @@ fclose(fd); } } - +*/ /* Setup the container for the tab. */ gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(tab_cont), 5); @@ -4506,8 +4506,7 @@ int gtk_font_options = 0; GString *log_str; GSList *images = NULL; - FILE *fd; - char buf[BUF_LONG]; + char buf[BUF_LONG]; char buf2[BUF_LONG]; char mdate[64]; char color[10]; @@ -4522,11 +4521,11 @@ win = gaim_conversation_get_window(conv); if (!(flags & GAIM_MESSAGE_NO_LOG) && - ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && - gaim_prefs_get_bool("/gaim/gtk/conversations/chat/raise_on_events")) || - (gaim_conversation_get_type(conv) == GAIM_CONV_IM && - (gaim_prefs_get_bool("/gaim/gtk/conversations/im/raise_on_events") || - gaim_prefs_get_bool("/gaim/gtk/conversations/im/hide_on_send"))))) { + ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && + gaim_prefs_get_bool("/gaim/gtk/conversations/chat/raise_on_events")) || + (gaim_conversation_get_type(conv) == GAIM_CONV_IM && + (gaim_prefs_get_bool("/gaim/gtk/conversations/im/raise_on_events") || + gaim_prefs_get_bool("/gaim/gtk/conversations/im/hide_on_send"))))) { gaim_conv_window_show(win); } @@ -4541,7 +4540,7 @@ if(gc) sml_attrib = g_strdup_printf("sml=\"%s\"", gc->prpl->info->name); - + gtk_font_options ^= GTK_IMHTML_NO_COMMENTS; if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors")) @@ -4555,87 +4554,52 @@ if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) gtk_font_options ^= GTK_IMHTML_RETURN_LOG; - + if (GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol(conv->account)))->options & - OPT_PROTO_USE_POINTSIZE) { - + OPT_PROTO_USE_POINTSIZE) { + gtk_font_options ^= GTK_IMHTML_USE_POINTSIZE; } if (flags & GAIM_MESSAGE_SYSTEM) { if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")) g_snprintf(buf, BUF_LONG, "(%s) <B>%s</B>", - mdate, message); + mdate, message); else g_snprintf(buf, BUF_LONG, "<B>%s</B>", message); - + g_snprintf(buf2, sizeof(buf2), - "<!--(%s) --><B>%s</B><BR>", - mdate, message); - + "<!--(%s) --><B>%s</B><BR>", + mdate, message); + gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml), buf2, 0, images); - + if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) { char *t1 = gaim_markup_strip_html(buf); - + conv->history = g_string_append(conv->history, t1); conv->history = g_string_append(conv->history, "\n"); - + g_free(t1); } else { conv->history = g_string_append(conv->history, buf); conv->history = g_string_append(conv->history, "<BR>\n"); } - - if (!(flags & GAIM_MESSAGE_NO_LOG) && gaim_conversation_is_logging(conv)) { - - char *t1; - char nm[256]; - const char *nm2; - - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) - t1 = gaim_markup_strip_html(buf); - else - t1 = buf; - - nm2 = gaim_normalize(gaim_conversation_get_account(conv), - gaim_conversation_get_name(conv)); - - if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) - g_snprintf(nm, sizeof(nm), "%s.chat", nm2); - else - strncpy(nm, nm2, sizeof(nm)); - - fd = open_log_file(nm, - (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); - - if (fd) { - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) - fprintf(fd, "%s\n", t1); - else - fprintf(fd, "%s<BR>\n", t1); - - fclose(fd); - } - - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) - g_free(t1); - } - } - else if (flags & GAIM_MESSAGE_NO_LOG) { + + } else if (flags & GAIM_MESSAGE_NO_LOG) { g_snprintf(buf, BUF_LONG, - "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", - message); - + "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", + message); + gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml), buf, 0, images); } else { char *new_message = g_memdup(message, length); - + if (flags & GAIM_MESSAGE_WHISPER) { str = g_malloc(1024); - + /* If we're whispering, it's not an autoresponse. */ if (meify(new_message, length)) { g_snprintf(str, 1024, "***%s", who); @@ -4645,16 +4609,16 @@ g_snprintf(str, 1024, "*%s*:", who); strcpy(color, "#00FF00"); } - } + } else { if (meify(new_message, length)) { str = g_malloc(1024); - + if (flags & GAIM_MESSAGE_AUTO_RESP) g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who); else g_snprintf(str, 1024, "***%s", who); - + if (flags & GAIM_MESSAGE_NICK) strcpy(color, "#AF7F00"); else @@ -4662,24 +4626,22 @@ } else { str = g_malloc(1024); - if (flags & GAIM_MESSAGE_AUTO_RESP) g_snprintf(str, 1024, "%s %s", who, AUTO_RESPONSE); else g_snprintf(str, 1024, "%s:", who); - if (flags & GAIM_MESSAGE_NICK) strcpy(color, "#AF7F00"); else if (flags & GAIM_MESSAGE_RECV) { if (flags & GAIM_MESSAGE_COLORIZE) { const char *u; int m = 0; - + for (u = who; *u != '\0'; u++) m += *u; - + m = m % NUM_NICK_COLORS; - + strcpy(color, nick_colors[m]); } else @@ -4689,22 +4651,22 @@ strcpy(color, "#16569E"); } } - + if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")) g_snprintf(buf, BUF_LONG, - "<FONT COLOR=\"%s\" %s>(%s) " - "<B>%s</B></FONT> ", color, - sml_attrib ? sml_attrib : "", mdate, str); + "<FONT COLOR=\"%s\" %s>(%s) " + "<B>%s</B></FONT> ", color, + sml_attrib ? sml_attrib : "", mdate, str); else g_snprintf(buf, BUF_LONG, - "<FONT COLOR=\"%s\" %s><B>%s</B></FONT> ", color, - sml_attrib ? sml_attrib : "", str); - + "<FONT COLOR=\"%s\" %s><B>%s</B></FONT> ", color, + sml_attrib ? sml_attrib : "", str); + g_snprintf(buf2, BUF_LONG, - "<FONT COLOR=\"%s\" %s><!--(%s) -->" - "<B>%s</B></FONT> ", - color, sml_attrib ? sml_attrib : "", mdate, str); - + "<FONT COLOR=\"%s\" %s><!--(%s) -->" + "<B>%s</B></FONT> ", + color, sml_attrib ? sml_attrib : "", mdate, str); + g_free(str); gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml), buf2, 0, images); @@ -4714,96 +4676,33 @@ char *post = "</font>"; int pre_len = strlen(pre); int post_len = strlen(post); - + with_font_tag = g_malloc(length + pre_len + post_len + 1); - + strcpy(with_font_tag, pre); memcpy(with_font_tag + pre_len, new_message, length); strcpy(with_font_tag + pre_len + length, post); - + length += pre_len + post_len; g_free(pre); } else with_font_tag = g_memdup(new_message, length); - + log_str = gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml), - with_font_tag, gtk_font_options, images); - + with_font_tag, gtk_font_options, images); + gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", 0); - - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) { - char *t1, *t2; - - t1 = gaim_markup_strip_html(buf); - t2 = gaim_markup_strip_html(new_message); - - conv->history = g_string_append(conv->history, t1); - conv->history = g_string_append(conv->history, t2); - conv->history = g_string_append(conv->history, "\n"); - - g_free(t1); - g_free(t2); - } - else { - char *t1, *t2; - - t1 = html_logize(buf); - t2 = html_logize(new_message); - - conv->history = g_string_append(conv->history, t1); - conv->history = g_string_append(conv->history, t2); - conv->history = g_string_append(conv->history, "\n"); - conv->history = g_string_append(conv->history, log_str->str); - conv->history = g_string_append(conv->history, "<BR>\n"); - - g_free(t1); - g_free(t2); - } - - if (gaim_conversation_is_logging(conv)) { - char *t1, *t2; - char nm[256]; - const char *nm2; - - nm2 = gaim_normalize(gaim_conversation_get_account(conv), - gaim_conversation_get_name(conv)); - - if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) - g_snprintf(nm, sizeof(nm), "%s.chat", nm2); - else - strncpy(nm, nm2, sizeof(nm)); - - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) { - t1 = gaim_markup_strip_html(buf); - t2 = gaim_markup_strip_html(with_font_tag); - } - else { - t1 = html_logize(buf); - t2 = html_logize(with_font_tag); - } - - fd = open_log_file(nm, - (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); - - if (fd) { - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) - fprintf(fd, "%s%s\n", t1, t2); - else { - fprintf(fd, "%s%s%s<BR>\n", t1, t2, log_str->str); - g_string_free(log_str, TRUE); - } - - fclose(fd); - } - - g_free(t1); - g_free(t2); - } - - g_free(with_font_tag); - g_free(new_message); - } + + /*conv->history = g_string_append(conv->history, t1); + conv->history = g_string_append(conv->history, t2); + conv->history = g_string_append(conv->history, "\n"); + + g_free(t1); + g_free(t2); */ + } + + g_free(with_font_tag); if(sml_attrib) g_free(sml_attrib); @@ -5048,7 +4947,7 @@ g_free(val); } - + break; } }
--- a/src/gtkprefs.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/gtkprefs.c Wed Nov 05 06:15:49 2003 +0000 @@ -1313,16 +1313,21 @@ GtkWidget *logging_page() { GtkWidget *ret; GtkWidget *vbox; + GList *names; ret = gtk_vbox_new(FALSE, 18); gtk_container_set_border_width (GTK_CONTAINER (ret), 12); vbox = gaim_gtk_make_frame (ret, _("Message Logs")); + names = gaim_log_logger_get_options(); + + prefs_dropdown_from_list(vbox, _("Log _Format:"), GAIM_PREF_STRING, + "/core/logging/format", + names); + prefs_checkbox(_("_Log all instant messages"), "/gaim/gtk/logging/log_ims", vbox); prefs_checkbox(_("Log all c_hats"), "/gaim/gtk/logging/log_chats", vbox); - prefs_checkbox(_("Strip _HTML from logs"), - "/gaim/gtk/logging/strip_html", vbox); vbox = gaim_gtk_make_frame (ret, _("System Logs")); prefs_checkbox(_("Log when buddies _sign on/sign off"), @@ -2731,7 +2736,6 @@ gaim_prefs_add_none("/gaim/gtk/logging"); gaim_prefs_add_bool("/gaim/gtk/logging/log_ims", TRUE); gaim_prefs_add_bool("/gaim/gtk/logging/log_chats", TRUE); - gaim_prefs_add_bool("/gaim/gtk/logging/strip_html", TRUE); gaim_prefs_add_bool("/gaim/gtk/logging/log_signon_signoff", TRUE); gaim_prefs_add_bool("/gaim/gtk/logging/log_idle_state", TRUE); gaim_prefs_add_bool("/gaim/gtk/logging/log_away_state", TRUE);
--- a/src/idle.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/idle.c Wed Nov 05 06:15:49 2003 +0000 @@ -155,12 +155,12 @@ gaim_account_get_username(account), idle_time); serv_set_idle(gc, idle_time); gc->is_idle = 1; - system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); + // LOG system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); } else if (idle_time < IDLEMARK && gc->is_idle) { gaim_debug(GAIM_DEBUG_INFO, "idle", "Setting %s unidle\n", gaim_account_get_username(account)); serv_touch_idle(gc); - system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); + // LOG system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON); } return TRUE;
--- a/src/log.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/log.c Wed Nov 05 06:15:49 2003 +0000 @@ -1,433 +1,570 @@ -/* --------------------------------------------------- - * Function to remove a log file entry - * --------------------------------------------------- +/** + * @file log.c Logging API + * @ingroup core + * + * gaim + * + * Copyright (C) 2003 Buzz Lightyear + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "internal.h" -#include "conversation.h" +#include "account.h" #include "debug.h" +#include "internal.h" #include "log.h" -#include "multi.h" -#include "notify.h" #include "prefs.h" -#include "prpl.h" #include "util.h" -/* XXX CORE/UI */ -#include "gtkinternal.h" -#include "gtkconv.h" -#include "ui.h" +static GaimLogLogger txt_logger; +static GaimLogLogger old_logger; -GList *log_conversations = NULL; - -void rm_log(struct log_conversation *a) -{ - GaimConversation *cnv = gaim_find_conversation(a->name); +/************************************************************************** + * PUBLIC LOGGING FUNCTIONS *********************************************** + **************************************************************************/ - /* Added the following if statements for sanity check */ - if (!a) - { - gaim_notify_error (NULL, NULL, _("Error in specifying buddy conversation."), NULL); - return; - } - cnv = gaim_find_conversation(a->name); - if (!cnv) - { - gaim_notify_error (NULL, NULL, _("Unable to find conversation log"), NULL); - return; - } - - log_conversations = g_list_remove(log_conversations, a); +GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) +{ + GaimLog *log = g_new0(GaimLog, 1); + log->name = g_strdup(name); + log->account = account; + log->time = time; + log->logger = gaim_log_logger_get(); + if (log->logger && log->logger->new) + log->logger->new(log); + return log; } -struct log_conversation *find_log_info(const char *name) +void gaim_log_free(GaimLog *log) { - char *pname = g_malloc(BUF_LEN); - GList *lc = log_conversations; - struct log_conversation *l; - - - strcpy(pname, gaim_normalize(NULL, name)); + g_return_if_fail(log); + if (log->logger && log->logger->finalize) + log->logger->finalize(log); + g_free(log->name); + g_free(log); +} + - while (lc) { - l = (struct log_conversation *)lc->data; - if (!gaim_utf8_strcasecmp(pname, gaim_normalize(NULL, l->name))) { - g_free(pname); - return l; - } - lc = lc->next; - } - g_free(pname); - return NULL; +void gaim_log_write(GaimLog *log, GaimMessageFlags type, + const char *from, time_t time, const char *message) +{ + g_return_if_fail(log); + g_return_if_fail(log->logger); + g_return_if_fail(log->logger->write); + + log->logger->write(log, type, from, time, message); } -void update_log_convs() +char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) { - GList *cnv; - GaimConversation *c; - GaimGtkConversation *gtkconv; - - for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { - - c = (GaimConversation *)cnv->data; - - if (!GAIM_IS_GTK_CONVERSATION(c)) - continue; - - gtkconv = GAIM_GTK_CONVERSATION(c); - - if (gtkconv->toolbar.log) { - if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) - gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), - !gaim_prefs_get_bool("/gaim/gtk/logging/log_chats")); - else - gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), - !gaim_prefs_get_bool("/gaim/gtk/logging/log_ims")); - } - } + g_return_val_if_fail(log && log->logger, NULL); + if (log->logger->read) + return log->logger->read(log, flags); + return (_("<b><font color\"=red\">The logger has no read function</font></b>")); } -static FILE *open_gaim_log_file(const char *name, int *flag) -{ - char *buf; - char *buf2; - char log_all_file[256]; - struct stat st; - FILE *fd; -#ifndef _WIN32 - int res; -#endif - gchar *gaim_dir; - - buf = g_malloc(BUF_LONG); - buf2 = g_malloc(BUF_LONG); - gaim_dir = gaim_user_dir(); - - /* Dont log yourself */ - strncpy(log_all_file, gaim_dir, 256); - -#ifndef _WIN32 - stat(log_all_file, &st); - if (!S_ISDIR(st.st_mode)) - unlink(log_all_file); - - fd = fopen(log_all_file, "r"); - - if (!fd) { - res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); - if (res < 0) { - g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), - log_all_file); - gaim_notify_error(NULL, NULL, buf, NULL); - g_free(buf); - g_free(buf2); - return NULL; - } - } else - fclose(fd); - - g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); +/**************************************************************************** + * LOGGER FUNCTIONS ********************************************************* + ****************************************************************************/ - if (stat(log_all_file, &st) < 0) - *flag = 1; - if (!S_ISDIR(st.st_mode)) - unlink(log_all_file); - - fd = fopen(log_all_file, "r"); - if (!fd) { - res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); - if (res < 0) { - g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), - log_all_file); - gaim_notify_error(NULL, NULL, buf, NULL); - g_free(buf); - g_free(buf2); - return NULL; +static GaimLogLogger *current_logger = NULL; +static GSList *loggers = NULL; + +static void logger_pref_cb(const char *name, GaimPrefType type, + gpointer value, gpointer data) +{ + GaimLogLogger *logger; + GSList *l = loggers; + while (l) { + logger = l->data; + if (!strcmp(logger->id, value)) { + gaim_log_logger_set(logger); + return; } - } else - fclose(fd); -#else /* _WIN32 */ - g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); + l = l->next; + } + gaim_log_logger_set(&txt_logger); +} - if( _mkdir(log_all_file) < 0 && errno != EEXIST ) { - g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), log_all_file); - gaim_notify_error(NULL, NULL, buf, NULL); - g_free(buf); - g_free(buf2); - return NULL; - } -#endif - g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", gaim_dir, name); - if (stat(log_all_file, &st) < 0) - *flag = 1; - - gaim_debug(GAIM_DEBUG_INFO, "log", "Logging to: \"%s\"\n", log_all_file); - - fd = fopen(log_all_file, "a"); - - g_free(buf); - g_free(buf2); - return fd; +GaimLogLogger *gaim_log_logger_new(void(*new)(GaimLog *), + void(*write)(GaimLog *, GaimMessageFlags, const char *, + time_t, const char *), + void(*finalize)(GaimLog *), GList*(*list)(const char*, GaimAccount*), + char*(*read)(GaimLog*, GaimLogReadFlags*)) +{ + GaimLogLogger *logger = g_new0(GaimLogLogger, 1); + logger->new = new; + logger->write = write; + logger->finalize = finalize; + logger->list = list; + logger->read = read; + return logger; } -static FILE *open_system_log_file(const char *name) +void gaim_log_logger_free(GaimLogLogger *logger) { - int x; + g_free(logger); +} - if (name) - return open_log_file(name, 2); - else - return open_gaim_log_file("system", &x); +void gaim_log_logger_add (GaimLogLogger *logger) +{ + g_return_if_fail(logger); + if (g_slist_find(loggers, logger)) + return; + loggers = g_slist_append(loggers, logger); +} + +void gaim_log_logger_remove (GaimLogLogger *logger) +{ + g_return_if_fail(logger); + g_slist_remove(loggers, logger); } -FILE *open_log_file(const char *name, int is_chat) +void gaim_log_logger_set (GaimLogLogger *logger) { - struct stat st; - char realname[256]; - struct log_conversation *l; - FILE *fd; - int flag = 0; + g_return_if_fail(logger); + current_logger = logger; +} - if (((is_chat == 2) && !gaim_prefs_get_bool("/gaim/gtk/logging/individual_logs")) - || ((is_chat == 1) && !gaim_prefs_get_bool("/gaim/gtk/logging/log_chats")) - || ((is_chat == 0) && !gaim_prefs_get_bool("/gaim/gtk/logging/log_ims"))) { - - l = find_log_info(name); - if (!l) - return NULL; +GaimLogLogger *gaim_log_logger_get() +{ + return current_logger; +} - if (stat(l->filename, &st) < 0) - flag = 1; - - fd = fopen(l->filename, "a"); +GList *gaim_log_logger_get_options(void) +{ + GSList *n; + GList *list = NULL; + GaimLogLogger *data; - if (flag) { /* is a new file */ - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) { - fprintf(fd, _("IM Sessions with %s\n"), name); - } else { - fprintf(fd, "<HTML><HEAD><TITLE>"); - fprintf(fd, _("IM Sessions with %s"), name); - fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n"); - } - } - - return fd; + for (n = loggers; n; n = n->next) { + data = n->data; + if (!data->write) + continue; + list = g_list_append(list, data->name); + list = g_list_append(list, data->id); } - g_snprintf(realname, sizeof(realname), "%s.log", name); - fd = open_gaim_log_file(realname, &flag); + return list; +} + +static gint log_compare(GaimLog *a, GaimLog *b) +{ + return b->time - a->time; +} + +GList *gaim_log_get_logs(const char *name, GaimAccount *account) +{ + GList *logs = NULL; + GSList *n; + for (n = loggers; n; n = n->next) { + GaimLogLogger *logger = n->data; + if (!logger->list) + continue; + logs = g_list_concat(logs, logger->list(name, account)); + } + + return g_list_sort(logs, log_compare); +} + +void gaim_log_init(void) +{ + gaim_prefs_add_none("/core/logging"); + gaim_prefs_add_string("/core/logging/format", "txt"); + gaim_log_logger_add(&txt_logger); + gaim_log_logger_add(&old_logger); + gaim_prefs_connect_callback("/core/logging/format", + logger_pref_cb, NULL); + gaim_prefs_trigger_callback("/core/logging/format"); +} + +/**************************************************************************** + * LOGGERS ****************************************************************** + ****************************************************************************/ + +static GList *log_lister_common(const char *screenname, GaimAccount *account, const char *ext, GaimLogLogger *logger) +{ + GDir *dir; + GList *list = NULL; + const char *filename; + char *me = g_strdup(gaim_normalize(account, gaim_account_get_username(account))); - if (fd && flag) { /* is a new file */ - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) { - fprintf(fd, _("IM Sessions with %s\n"), name); - } else { - fprintf(fd, "<HTML><HEAD><TITLE>"); - fprintf(fd, _("IM Sessions with %s"), name); - fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n"); + const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO + (gaim_find_prpl(gaim_account_get_protocol(account)))->list_icon(account, NULL); + char *path = g_build_filename(gaim_user_dir(), "logs", prpl, me, gaim_normalize(account, screenname), NULL); + + if (!(dir = g_dir_open(path, 0, NULL))) { + g_free(path); + g_free(me); + return NULL; + } + while ((filename = g_dir_read_name(dir))) { + if (g_str_has_suffix(filename, ext)) { + const char *l = filename; + struct tm time; + GaimLog *log; + char d[5]; + + strncpy(d, l, 4); + d[4] = '\0'; + time.tm_year = atoi(d) - 1900; + l = l + 5; + + strncpy(d, l, 2); + d[2] = '\0'; + time.tm_mon = atoi(d) - 1; + l = l + 3; + + strncpy(d, l, 2); + time.tm_mday = atoi(d); + l = l + 3; + + strncpy(d, l, 2); + time.tm_hour = atoi(d); + l = l + 2; + + strncpy(d, l, 2); + time.tm_min = atoi(d); + l = l + 2; + + strncpy(d, l, 2); + time.tm_sec = atoi(d); + l = l + 2; + log = gaim_log_new(GAIM_LOG_IM, screenname, account, mktime(&time)); + log->logger = logger; + log->logger_data = g_build_filename(path, filename, NULL); + list = g_list_append(list, log); } } + g_dir_close(dir); + return list; +} - return fd; +#if 0 /* Maybe some other time. */ +/**************** + ** XML LOGGER ** + ****************/ + +static const char *str_from_msg_type (GaimMessageFlags type) +{ + + return ""; + +} + +static void xml_logger_write(GaimLog *log, + GaimMessageFlags type, + const char *from, time_t time, const char *message) +{ + char date[64]; + char *xhtml = NULL; + 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. + */ + char *ud = gaim_user_dir(); + char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); + const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO + (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); + char *dir; + FILE *file; + + strftime(date, sizeof(date), "%F.%H%M%S.xml", localtime(&log->time)); + + dir = g_build_filename(ud, "logs", NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, guy, NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, guy, gaim_normalize(log->account, log->name), NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + + char *filename = g_build_filename(dir, date, NULL); + g_free(dir); + + file = fopen(dir, "r"); + if(!file) + mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); + else + fclose(file); + + log->logger_data = fopen(filename, "a"); + if (!log->logger_data) { + gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); + return; + } + 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"); + + strftime(date, sizeof(date), "%F %T", localtime(&log->time)); + fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", + date, log->name, prpl); + } + + strftime(date, sizeof(date), "%T", localtime(&time)); + 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(xhtml); +} + + 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; + } +} + +static GList *xml_logger_list(const char *sn, GaimAccount *account) +{ + return log_lister_common(sn, account, ".xml", &xml_logger); } -void system_log(enum log_event what, GaimConnection *gc, - GaimBuddy *who, int why) -{ - GaimAccount *account = NULL; - FILE *fd; - char text[256], html[256]; - - if (gc != NULL) - account = gaim_connection_get_account(gc); +static GaimLogLogger xml_logger = { + N_("XML"), "xml", + NULL, + xml_logger_write, + xml_logger_finalize, + xml_logger_list, + NULL +}; +#endif - if ((why & OPT_LOG_MY_SIGNON && - !gaim_prefs_get_bool("/gaim/gtk/logging/log_own_states")) || - (why & OPT_LOG_BUDDY_SIGNON && - !gaim_prefs_get_bool("/gaim/gtk/logging/log_signon_signoff")) || - (why & OPT_LOG_BUDDY_IDLE && - !gaim_prefs_get_bool("/gaim/gtk/logging/log_idle_state")) || - (why & OPT_LOG_BUDDY_AWAY && - !gaim_prefs_get_bool("/gaim/gtk/logging/log_away_state"))) { - - return; - } - - if (gaim_prefs_get_bool("/gaim/gtk/logging/individual_logs")) { - if (why & OPT_LOG_MY_SIGNON) - fd = open_system_log_file(gc ? gaim_account_get_username(account) : NULL); - else - fd = open_system_log_file(who->name); - } else - fd = open_system_log_file(NULL); - - if (!fd) - return; +/**************************** + ** PLAIN TEXT LOGGER ******* + ****************************/ - if (why & OPT_LOG_MY_SIGNON) { - switch (what) { - case log_signon: - g_snprintf(text, sizeof(text), _("+++ %s (%s) signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<B>%s</B>", text); - break; - case log_signoff: - g_snprintf(text, sizeof(text), _("+++ %s (%s) signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); - break; - case log_away: - g_snprintf(text, sizeof(text), _("+++ %s (%s) changed away state @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); - break; - case log_back: - g_snprintf(text, sizeof(text), _("+++ %s (%s) came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - case log_idle: - g_snprintf(text, sizeof(text), _("+++ %s (%s) became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); - break; - case log_unidle: - g_snprintf(text, sizeof(text), _("+++ %s (%s) returned from idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - case log_quit: - g_snprintf(text, sizeof(text), _("+++ Program exit @ %s"), gaim_date_full()); - g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); - break; +static void txt_logger_write(GaimLog *log, + GaimMessageFlags type, + const char *from, time_t time, const char *message) +{ + char date[64]; + char *stripped = NULL; + 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. + */ + char *ud = gaim_user_dir(); + char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); + const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO + (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); + char *dir; + FILE *file; + + strftime(date, sizeof(date), "%F.%H%M%S.txt", localtime(&log->time)); + + dir = g_build_filename(ud, "logs", NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, guy, NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(dir); + dir = g_build_filename(ud, "logs", + prpl, guy, gaim_normalize(log->account, log->name), NULL); + mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); + + char *filename = g_build_filename(dir, date, NULL); + g_free(dir); + + file = fopen(dir, "r"); + if(!file) + mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); + else + fclose(file); + + log->logger_data = fopen(filename, "a"); + if (!log->logger_data) { + gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); + return; } - } else if (gaim_get_buddy_alias_only(who)) { - switch (what) { - case log_signon: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<B>%s</B>", text); - break; - case log_signoff: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); - break; - case log_away: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) went away @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); - break; - case log_back: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - case log_idle: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); - break; - case log_unidle: - g_snprintf(text, sizeof(text), - _("%s (%s) reported that %s (%s) returned from idle @ %s"), gaim_account_get_username(account), - gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - default: - fclose(fd); - return; - break; - } - } else { - switch (what) { - case log_signon: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<B>%s</B>", text); - break; - case log_signoff: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); - break; - case log_away: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s went away @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); - break; - case log_back: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - case log_idle: - g_snprintf(text, sizeof(text), _("%s (%s) reported that %s became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); - break; - case log_unidle: - g_snprintf(text, sizeof(text), - _("%s (%s) reported that %s returned from idle @ %s"), gaim_account_get_username(account), - gc->prpl->info->name, who->name, gaim_date_full()); - g_snprintf(html, sizeof(html), "%s", text); - break; - default: - fclose(fd); - return; - break; + strftime(date, sizeof(date), "%F %T", localtime(&log->time)); + fprintf(log->logger_data, "Conversation with %s at %s on %s (%s)\n", + log->name, date, gaim_account_get_username(log->account), prpl); + } + + strftime(date, sizeof(date), "%T", localtime(&time)); + stripped = gaim_markup_strip_html(message); + fprintf(log->logger_data, "(%s) %s%s %s\n", date, from ? from : "", from ? ":" : "", stripped); + fflush(log->logger_data); + g_free(stripped); +} + +static void txt_logger_finalize(GaimLog *log) +{ + if (log->logger_data) + fclose(log->logger_data); +} + +static GList *txt_logger_list(const char *sn, GaimAccount *account) +{ + return log_lister_common(sn, account, ".txt", &txt_logger); +} + +static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) +{ + char *read, *minus_header; + if (!log->logger_data) + return g_strdup("<font color='red'><b>log->logger_data was NULL!</b></font>"); + if (g_file_get_contents((char *)log->logger_data, &read, NULL, NULL)) { + minus_header = strchr(read, '\n'); + if (!minus_header) + minus_header = g_strdup(read); + else + minus_header = g_strdup(minus_header + 1); + g_free(read); + return minus_header; + } + return g_strdup(_("<font color='red'><b>Could not read file: %s</b></font>")); +} + +static GaimLogLogger txt_logger = { + N_("Plain text"), "txt", + NULL, + txt_logger_write, + txt_logger_finalize, + txt_logger_list, + txt_logger_read +}; + +/**************** + * OLD LOGGER *** + ****************/ + +/* The old logger doesn't write logs, only reads them. This is to include + * old logs in the log viewer transparently. + */ + +struct old_logger_data { + char *path; + int offset; + int length; +}; + +static GList *old_logger_list(const char *sn, GaimAccount *account) +{ + FILE *file; + char buf[BUF_LONG]; + struct tm tm; + struct old_logger_data *data = NULL; + char day[4], month[4], year[5]; + char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); + char *date; + char *path = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); + char *newlog; + + GaimLog *log = NULL; + GList *list = NULL; + + if (!(file = fopen(path, "r"))) + return NULL; + + while (fgets(buf, BUF_LONG, file)) { + if ((newlog = strstr(buf, "---- New C"))) { + int length; + int offset; + GDate gdate; + char convostart[32]; + char *temp = strchr(buf, '@'); + + if (temp == NULL || strlen(temp) < 2) + continue; + + temp++; + length = strcspn(temp, "-"); + if (length > 31) length = 31; + + offset = ftell(file); + + if (data) { + data->length = offset - data->offset - length - + strlen("<HR><BR><H3 Align=Center> ---- New Conversation @ ") - + strlen("----</H3><BR>"); + if (data->length != 0) + list = g_list_append(list, log); + else + gaim_log_free(log); + } + + log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); + log->logger = &old_logger; + + data = g_malloc(sizeof(struct old_logger_data)); + data->offset = offset; + data->path = path; + log->logger_data = data; + + + g_snprintf(convostart, length, "%s", temp); + sscanf(convostart, "%*s %s %s %d:%d:%d %s", + month, day, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, year); + date = g_strdup_printf("%s %s %s", month, day, year); + g_date_set_parse(&gdate, date); + tm.tm_mday = g_date_get_day(&gdate); + tm.tm_mon = g_date_get_month(&gdate) - 1; + tm.tm_year = g_date_get_year(&gdate) - 1900; + log->time = mktime(&tm); + } } - - if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) - fprintf(fd, "---- %s ----\n", text); - else if (gaim_prefs_get_bool("/gaim/gtk/logging/individual_logs")) - fprintf(fd, "<HR>%s<BR><HR><BR>\n", html); - else - fprintf(fd, "%s<BR>\n", html); - - fclose(fd); + fclose(file); + return list; } -char *html_logize(const char *p) +char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) { - const char *temp_p; - char *buffer_p; - char *buffer_start; - int num_cr = 0; - int char_len = 0; - - for (temp_p = p; *temp_p != '\0'; temp_p++) { - char_len++; - - if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) - num_cr++; - } - - buffer_p = g_malloc(char_len + (4 * num_cr) + 1); - - for (temp_p = p, buffer_start = buffer_p; - *temp_p != '\0'; - temp_p++) { + *flags = GAIM_LOG_READ_NO_NEWLINE; + struct old_logger_data *data = log->logger_data; + FILE *file = fopen(data->path, "r"); + char *read = g_malloc(data->length + 1); + fseek(file, data->offset, SEEK_SET); + fread(read, data->length, 1, file); + read[data->length] = '\0'; + return read; +} - if (*temp_p == '\n') { - *buffer_p++ = '<'; - *buffer_p++ = 'B'; - *buffer_p++ = 'R'; - *buffer_p++ = '>'; - *buffer_p++ = '\n'; - - } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { - *buffer_p++ = '&'; - *buffer_p++ = 'l'; - *buffer_p++ = 't'; - *buffer_p++ = ';'; - - } else - *buffer_p++ = *temp_p; - } - - *buffer_p = '\0'; - - return buffer_start; -} +static GaimLogLogger old_logger = { + "old logger", "old", + NULL, NULL, NULL, + old_logger_list, + old_logger_read +};
--- a/src/log.h Wed Nov 05 00:18:51 2003 +0000 +++ b/src/log.h Wed Nov 05 06:15:49 2003 +0000 @@ -4,7 +4,7 @@ * * gaim * - * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> + * Copyright (C) 2003 Douglas E. Egan * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,51 +20,207 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #ifndef _GAIM_LOG_H_ #define _GAIM_LOG_H_ -#include "blist.h" -#include "connection.h" -#include "conversation.h" - -/* XXX Temporary! */ -#define OPT_LOG_BUDDY_SIGNON 0x00000004 -#define OPT_LOG_BUDDY_IDLE 0x00000008 -#define OPT_LOG_BUDDY_AWAY 0x00000010 -#define OPT_LOG_MY_SIGNON 0x00000020 +#include <stdio.h> -enum log_event { - log_signon = 0, - log_signoff, - log_away, - log_back, - log_idle, - log_unidle, - log_quit +/******************************************************** + * DATA STRUCTURES ************************************** + ********************************************************/ + +typedef struct _GaimLog GaimLog; +typedef struct _GaimLogLogger GaimLogLogger; + +typedef enum { + GAIM_LOG_IM, + GAIM_LOG_CHAT, + GAIM_LOG_SYSTEM, +} GaimLogType; + +typedef enum { + GAIM_LOG_READ_NO_NEWLINE = 1, +} GaimLogReadFlags; + +#include "account.h" +#include "conversation.h" + +/** + * A log logger. + * + * This struct gets filled out and is included in the GaimLog. It contains everything + * needed to write and read from logs. + */ +struct _GaimLogLogger { + char *name; /**< The logger's name */ + char *id; /**< an identifier to refer to this logger */ + + /** This gets called when the log is first created. + I don't think this is actually needed. */ + void(*new)(GaimLog *log); + + /** This is used to write to the log file */ + void(*write)(GaimLog *log, + GaimMessageFlags type, + const char *from, + time_t time, + const char *message); + + /** Called when the log is destroyed */ + void (*finalize)(GaimLog *log); + + /** This function returns a sorted GList of available GaimLogs */ + GList *(*list)(const char *name, GaimAccount *account); + + /** Given one of the logs returned by the logger's list function, this returns + * the contents of the log in GtkIMHtml markup */ + char *(*read)(GaimLog *log, GaimLogReadFlags *flags); }; -struct log_conversation { - char name[80]; - char filename[512]; - struct log_conversation *next; +/** + * A log. Not the wooden type. + */ +struct _GaimLog { + GaimLogType type; /**< The type of log this is */ + + char *name; /**< The name of this log */ + GaimAccount *account; /**< The account this log is taking place on */ + time_t time; /**< The time this conversation started */ + + GaimLogLogger *logger; /**< The logging mechanism this log is to use */ + void *logger_data; /**< Data used by the log logger */ }; + #ifdef __cplusplus extern "C" { #endif -extern GList *log_conversations; + /*************************************** + ** LOG FUNCTIONS ********************** + ***************************************/ + + /** + * Creates a new log + * + * @param type The type of log this is. + * @param name The name of this conversation (Screenname, chat name, etc.) + * @param account The account the conversation is occuring on + * @param time The time this conversation started + * @return The new log + */ + GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time); + + /** + * Frees a log + * + * @param log The log to destroy + */ + void gaim_log_free(GaimLog *log); + + /** + * Writes to a log file + * + * @param log The log to write to + * @param type The type of message being logged + * @param from Whom this message is coming from, or NULL for system messages + * @param time A timestamp in UNIX time + * @param message The message to log + */ + void gaim_log_write(GaimLog *log, + GaimMessageFlags type, + const char *from, + time_t time, + const char *message); + + /** + * Reads from a log + * + * @param log The log to read from + * @return The contents of this log in Gaim Markup. + */ + char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags); + + /** + * Returns a list of all available logs + * + * @param name The name of the log + * @param account The account + * @return A sorted list of GaimLogs + */ + GList *gaim_log_get_logs(const char *name, GaimAccount *account); + -FILE *open_log_file (const char *, int); -void system_log(enum log_event, GaimConnection *, GaimBuddy *, int); -void rm_log(struct log_conversation *); -struct log_conversation *find_log_info(const char *); -void update_log_convs(); -char *html_logize(const char *p); + /****************************************** + ** LOGGER FUNCTIONS ********************** + ******************************************/ + + /** + * Creates a new logger + * + * @param new The logger's new function + * @param write The logger's write function + * @return The new logger + */ + GaimLogLogger *gaim_log_logger_new(void(*new)(GaimLog *), + void(*write)(GaimLog *, GaimMessageFlags, + const char *, time_t, const char *), + void(*finalize)(GaimLog *), GList*(*list)(const char*, GaimAccount*), + char*(*read)(GaimLog*, GaimLogReadFlags*)); + /** + * Frees a logger + * + * @param logger The logger to free + */ + void gaim_log_logger_free(GaimLogLogger *logger); + + /** + * Adds a new logger + * + * @param logger The new logger to add + */ + void gaim_log_logger_add (GaimLogLogger *logger); + + /** + * + * Removes a logger + * + * @param logger The logger to remove + */ + void gaim_log_logger_remove (GaimLogLogger *logger); + + /** + * + * Sets the current logger + * + * @param logger The logger to set + */ + void gaim_log_logger_set (GaimLogLogger *logger); + + /** + * + * Returns the current logger + * + * @return logger The current logger + */ + GaimLogLogger *gaim_log_logger_get (void); + + /** + * Returns a GList containing the IDs and Names of the registered log loggers. + * + * @return The list of IDs and names. + */ + GList *gaim_log_logger_get_options(void); + + void gaim_log_init(void); +/*@}*/ + #ifdef __cplusplus } #endif + +#endif /* _GAIM_LOG_H_ */ -#endif /* _GAIM_LOG_H_ */
--- a/src/main.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/main.c Wed Nov 05 06:15:49 2003 +0000 @@ -501,7 +501,7 @@ gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops()); gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops()); gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops()); - gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops()); + gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops()); gaim_gtk_prefs_init(); gaim_gtk_blist_init(); @@ -517,7 +517,7 @@ /* XXX? */ /* captain's log, stardate... */ - system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); + //LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); #ifdef USE_SM /* unplug */ @@ -845,7 +845,6 @@ gaim_prefs_load(); - /* we only read ~/.gaimrc (load_prefs()) if there is no accounts.xml * since prefs.xml existed alongside ~/.gaim in 0.64 */ if (!gaim_accounts_load()) {
--- a/src/server.c Wed Nov 05 00:18:51 2003 +0000 +++ b/src/server.c Wed Nov 05 06:15:49 2003 +0000 @@ -395,10 +395,9 @@ account, state, message); } + /* LOG system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON); */ /* New away message... Clear out the record of sent autoresponses */ flush_last_auto_responses(gc); - - system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON); } void serv_set_away_all(const char *message) @@ -1121,20 +1120,18 @@ if (!b->idle && idle) { gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", b); - system_log(log_idle, gc, b, OPT_LOG_BUDDY_IDLE); } else if (b->idle && !idle) { gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", b); - system_log(log_unidle, gc, b, OPT_LOG_BUDDY_IDLE); } gaim_blist_update_buddy_idle(b, idle); gaim_blist_update_buddy_evil(b, evil); - +/* LOG if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) system_log(log_back, gc, b, OPT_LOG_BUDDY_AWAY); else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) system_log(log_away, gc, b, OPT_LOG_BUDDY_AWAY); - +*/ gaim_blist_update_buddy_status(b, type); if (loggedin) { @@ -1161,7 +1158,7 @@ } } gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); - system_log(log_signon, gc, b, OPT_LOG_BUDDY_SIGNON); + // LOG system_log(log_signon, gc, b, OPT_LOG_BUDDY_SIGNON); } } else { if (GAIM_BUDDY_IS_ONLINE(b)) { @@ -1187,7 +1184,7 @@ } serv_got_typing_stopped(gc, name); /* obviously not typing */ gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); - system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON); + // LOG system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON); } } @@ -1362,7 +1359,7 @@ gaim_conv_chat_set_id(chat, id); - /* TODO Move this to UI logging code! */ + /* TODO Move this to UI logging code! LOG if (gaim_prefs_get_bool("/gaim/gtk/logging/log_chats") || find_log_info(gaim_conversation_get_name(conv))) { @@ -1388,6 +1385,7 @@ } free(filename); } + */ gaim_conv_window_show(gaim_conversation_get_window(conv)); gaim_conv_window_switch_conversation(gaim_conversation_get_window(conv),