# HG changeset patch # User Richard Laager # Date 1126415692 0 # Node ID cd0c8830d8812e1085a76b0ebc0ca524536dd2b5 # Parent b858f992b566db07611dd6626e6bc61c7ecf4ee5 [gaim-migrate @ 13748] Making gaim_log_logger a varargs function so it can be expanded as GaimLogLogger expands, without breaking compatibility. I'm anticipating adding a find() function some day for a database logger. This commit also makes use of gaim_log_logger_new() everywhere it should be used, removing the old static structures. committer: Tailor Script diff -r b858f992b566 -r cd0c8830d881 plugins/ChangeLog.API --- a/plugins/ChangeLog.API Sun Sep 11 04:46:21 2005 +0000 +++ b/plugins/ChangeLog.API Sun Sep 11 05:14:52 2005 +0000 @@ -60,8 +60,7 @@ or is itself an expanded contact * Added: GaimLogSet struct, get_log_sets function to GaimLogLogger, gaim_log_get_log_sets, gaim_log_set_compare - * Changed: gaim_log_logger_new, added total_size, list_syslog, and get_log_sets - parameters to bring the function up-to-date with GaimLogLogger + * Changed: gaim_log_logger_new, rewritten * Changed: gaim_conv_window_remove_conversation()'s last argument to be a GaimConversation. * Added: gaim_privacy_check(), to check if a given user is allowed to diff -r b858f992b566 -r cd0c8830d881 plugins/log_reader.c --- a/plugins/log_reader.c Sun Sep 11 04:46:21 2005 +0000 +++ b/plugins/log_reader.c Sun Sep 11 05:14:52 2005 +0000 @@ -26,7 +26,9 @@ #endif /* Where is the Windows partition mounted? */ -#define LOG_READER_WINDOWS_MOUNT_POINT "/mnt/windows" +#ifndef GAIM_LOG_READER_WINDOWS_MOUNT_POINT +#define GAIM_LOG_READER_WINDOWS_MOUNT_POINT "/mnt/windows" +#endif enum name_guesses { NAME_GUESS_UNKNOWN, @@ -43,7 +45,7 @@ * Adium logs in the log viewer transparently. */ -static GaimLogLogger adium_logger; +static GaimLogLogger *adium_logger; enum adium_log_type { ADIUM_HTML, @@ -155,7 +157,7 @@ tm.tm_mon -= 1; log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); - log->logger = &adium_logger; + log->logger = adium_logger; log->logger_data = data; list = g_list_append(list, log); @@ -215,7 +217,7 @@ data->type = ADIUM_TEXT; log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); - log->logger = &adium_logger; + log->logger = adium_logger; log->logger_data = data; list = g_list_append(list, log); @@ -318,18 +320,6 @@ g_free(data->path); } -static GaimLogLogger adium_logger = { - N_("Adium Log Reader"), "adium", - NULL, NULL, - adium_logger_finalize, - adium_logger_list, - adium_logger_read, - adium_logger_size, - NULL, - NULL, - NULL -}; - /***************************************************************************** * Fire Logger * @@ -339,14 +329,14 @@ * Fire logs in the log viewer transparently. */ -static GaimLogLogger fire_logger; +static GaimLogLogger *fire_logger; struct fire_logger_data { }; static GList *fire_logger_list(GaimLogType type, const char *sn, GaimAccount *account) { - // TODO: Do something here. + /* TODO: Do something here. */ return NULL; } @@ -358,7 +348,7 @@ data = log->logger_data; - // TODO: Do something here. + /* TODO: Do something here. */ return g_strdup(""); } @@ -369,7 +359,7 @@ if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) return 0; - // TODO: Do something here. + /* TODO: Do something here. */ return 0; } @@ -377,21 +367,9 @@ { g_return_if_fail(log != NULL); - // TODO: Do something here. + /* TODO: Do something here. */ } -static GaimLogLogger fire_logger = { - N_("Fire Log Reader"), "fire", - NULL, NULL, - fire_logger_finalize, - fire_logger_list, - fire_logger_read, - fire_logger_size, - NULL, - NULL, - NULL -}; - /***************************************************************************** * Messenger Plus! Logger * @@ -401,14 +379,14 @@ * Messenger Plus! logs in the log viewer transparently. */ -static GaimLogLogger messenger_plus_logger; +static GaimLogLogger *messenger_plus_logger; struct messenger_plus_logger_data { }; static GList *messenger_plus_logger_list(GaimLogType type, const char *sn, GaimAccount *account) { - // TODO: Do something here. + /* TODO: Do something here. */ return NULL; } @@ -420,7 +398,7 @@ data = log->logger_data; - // TODO: Do something here. + /* TODO: Do something here. */ return g_strdup(""); } @@ -431,7 +409,7 @@ if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) return 0; - // TODO: Do something here. + /* TODO: Do something here. */ return 0; } @@ -439,21 +417,9 @@ { g_return_if_fail(log != NULL); - // TODO: Do something here. + /* TODO: Do something here. */ } -static GaimLogLogger messenger_plus_logger = { - N_("Messenger Plus Log Reader"), "messenger_plus", - NULL, NULL, - messenger_plus_logger_finalize, - messenger_plus_logger_list, - messenger_plus_logger_read, - messenger_plus_logger_size, - NULL, - NULL, - NULL -}; - /***************************************************************************** * MSN Messenger Logger * @@ -463,7 +429,7 @@ * MSN Messenger message histories in the log viewer transparently. */ -static GaimLogLogger msn_logger; +static GaimLogLogger *msn_logger; struct msn_logger_data { xmlnode *root; @@ -765,7 +731,7 @@ data->last_log = FALSE; log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, msn_logger_parse_timestamp(message)); - log->logger = &msn_logger; + log->logger = msn_logger; log->logger_data = data; list = g_list_append(list, log); @@ -1063,18 +1029,6 @@ g_string_free(data->text, FALSE); } -static GaimLogLogger msn_logger = { - N_("MSN Log Reader"), "msn", - NULL, NULL, - msn_logger_finalize, - msn_logger_list, - msn_logger_read, - msn_logger_size, - NULL, - NULL, - NULL -}; - /***************************************************************************** * Trillian Logger * @@ -1084,7 +1038,7 @@ * Trillian logs in the log viewer transparently. */ -static GaimLogLogger trillian_logger; +static GaimLogLogger *trillian_logger; static void trillian_logger_finalize(GaimLog *log); struct trillian_logger_data { @@ -1291,7 +1245,7 @@ log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); - log->logger = &trillian_logger; + log->logger = trillian_logger; log->logger_data = data; list = g_list_append(list, log); @@ -1432,7 +1386,7 @@ if (*timestamp == ']') { *timestamp = '\0'; line++; - // TODO: Parse the timestamp and convert it to Gaim's format. + /* TODO: Parse the timestamp and convert it to Gaim's format. */ g_string_append_printf(formatted, "(%s) ", line); line = timestamp; @@ -1602,18 +1556,6 @@ } -static GaimLogLogger trillian_logger = { - N_("Trillian Log Reader"), "trillian", - NULL, NULL, - trillian_logger_finalize, - trillian_logger_list, - trillian_logger_read, - trillian_logger_size, - NULL, - NULL, - NULL -}; - /***************************************************************************** * Plugin Code * @@ -1686,7 +1628,7 @@ #ifdef _WIN32 folder, #else - LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", + GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", g_get_user_name(), "My Documents", #endif "My Chat Logs", NULL); @@ -1712,7 +1654,7 @@ #ifdef _WIN32 folder, #else - LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", + GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", g_get_user_name(), "My Documents", #endif "My Received Files", NULL); @@ -1865,7 +1807,7 @@ #ifdef _WIN32 folder, #else - LOG_READER_WINDOWS_MOUNT_POINT, "Program Files", + GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Program Files", #endif "Trillian", "users", "default", "logs", NULL); #ifdef _WIN32 @@ -1887,11 +1829,50 @@ { g_return_val_if_fail(plugin != NULL, FALSE); - gaim_log_logger_add(&adium_logger); - gaim_log_logger_add(&fire_logger); - gaim_log_logger_add(&messenger_plus_logger); - gaim_log_logger_add(&msn_logger); - gaim_log_logger_add(&trillian_logger); + adium_logger = gaim_log_logger_new("adium", "Adium", 6, + NULL, + NULL, + adium_logger_finalize, + adium_logger_list, + adium_logger_read, + adium_logger_size); + gaim_log_logger_add(adium_logger); + + fire_logger = gaim_log_logger_new("fire", "Fire", 6, + NULL, + NULL, + fire_logger_finalize, + fire_logger_list, + fire_logger_read, + fire_logger_size); + gaim_log_logger_add(fire_logger); + + messenger_plus_logger = gaim_log_logger_new("messenger_plus", "Messenger Plus!", 6, + NULL, + NULL, + messenger_plus_logger_finalize, + messenger_plus_logger_list, + messenger_plus_logger_read, + messenger_plus_logger_size); + gaim_log_logger_add(messenger_plus_logger); + + msn_logger = gaim_log_logger_new("msn", "MSN Messenger", 6, + NULL, + NULL, + msn_logger_finalize, + msn_logger_list, + msn_logger_read, + msn_logger_size); + gaim_log_logger_add(msn_logger); + + trillian_logger = gaim_log_logger_new("trillian", "Trillian", 6, + NULL, + NULL, + trillian_logger_finalize, + trillian_logger_list, + trillian_logger_read, + trillian_logger_size); + gaim_log_logger_add(trillian_logger); return TRUE; } @@ -1901,11 +1882,11 @@ { g_return_val_if_fail(plugin != NULL, FALSE); - gaim_log_logger_remove(&adium_logger); - gaim_log_logger_remove(&fire_logger); - gaim_log_logger_remove(&messenger_plus_logger); - gaim_log_logger_remove(&msn_logger); - gaim_log_logger_remove(&trillian_logger); + gaim_log_logger_remove(adium_logger); + gaim_log_logger_remove(fire_logger); + gaim_log_logger_remove(messenger_plus_logger); + gaim_log_logger_remove(msn_logger); + gaim_log_logger_remove(trillian_logger); return TRUE; } @@ -1991,7 +1972,7 @@ "includes Adium, Fire, Messenger Plus!, " "MSN Messenger, and Trillian."), - "Richard Laager ", /**< author */ + "Richard Laager ", /**< author */ GAIM_WEBSITE, /**< homepage */ plugin_load, /**< load */ plugin_unload, /**< unload */ diff -r b858f992b566 -r cd0c8830d881 src/log.c --- a/src/log.c Sun Sep 11 04:46:21 2005 +0000 +++ b/src/log.c Sun Sep 11 05:14:52 2005 +0000 @@ -33,9 +33,9 @@ static GSList *loggers = NULL; -static GaimLogLogger html_logger; -static GaimLogLogger txt_logger; -static GaimLogLogger old_logger; +static GaimLogLogger *html_logger; +static GaimLogLogger *txt_logger; +static GaimLogLogger *old_logger; struct _gaim_logsize_user { char *name; @@ -45,6 +45,28 @@ static void log_get_log_sets_common(GHashTable *sets); +static void html_logger_write(GaimLog *log, GaimMessageFlags type, + const char *from, time_t time, const char *message); +static void html_logger_finalize(GaimLog *log); +static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *html_logger_list_syslog(GaimAccount *account); +static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); + +static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); +static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags); +static int old_logger_size (GaimLog *log); +static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets); +static void old_logger_finalize(GaimLog *log); + +static void txt_logger_write(GaimLog *log, + GaimMessageFlags type, + const char *from, time_t time, const char *message); +static void txt_logger_finalize(GaimLog *log); +static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); +static GList *txt_logger_list_syslog(GaimAccount *account); +static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags); + /************************************************************************** * PUBLIC LOGGING FUNCTIONS *********************************************** **************************************************************************/ @@ -231,11 +253,13 @@ } l = l->next; } - gaim_log_logger_set(&txt_logger); + gaim_log_logger_set(txt_logger); } -GaimLogLogger *gaim_log_logger_new( +GaimLogLogger *gaim_log_logger_new(const char *id, const char *name, int functions, ...) +{ +#if 0 void(*create)(GaimLog *), void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *), void(*finalize)(GaimLog *), @@ -246,23 +270,51 @@ GList*(*list_syslog)(GaimAccount *account), void(*get_log_sets)(GaimLogSetCallback cb, GHashTable *sets)) { - GaimLogLogger *logger = g_new0(GaimLogLogger, 1); +#endif + GaimLogLogger *logger; + va_list args; + + g_return_val_if_fail(id != NULL, NULL); + g_return_val_if_fail(name != NULL, NULL); + g_return_val_if_fail(functions >= 1, NULL); + + logger = g_new0(GaimLogLogger, 1); + logger->id = g_strdup(id); + logger->name = g_strdup(name); + + va_start(args, functions); - logger->create = create; - logger->write = write; - logger->finalize = finalize; - logger->list = list; - logger->read = read; - logger->size = size; - logger->total_size = total_size; - logger->list_syslog = list_syslog; - logger->get_log_sets = get_log_sets; + if (functions >= 1) + logger->create = va_arg(args, void *); + if (functions >= 2) + logger->write = va_arg(args, void *); + if (functions >= 3) + logger->finalize = va_arg(args, void *); + if (functions >= 4) + logger->list = va_arg(args, void *); + if (functions >= 5) + logger->read = va_arg(args, void *); + if (functions >= 6) + logger->size = va_arg(args, void *); + if (functions >= 7) + logger->total_size = va_arg(args, void *); + if (functions >= 8) + logger->list_syslog = va_arg(args, void *); + if (functions >= 9) + logger->get_log_sets = va_arg(args, void *); + + if (functions > 9) + gaim_debug_info("log", "Dropping new functions for logger: %s (%s)\n", name, id); + + va_end(args); return logger; } void gaim_log_logger_free(GaimLogLogger *logger) { + g_free(logger->name); + g_free(logger->id); g_free(logger); } @@ -442,11 +494,43 @@ gaim_prefs_add_bool("/core/logging/log_own_states", FALSE); gaim_prefs_add_string("/core/logging/format", "txt"); - gaim_log_logger_add(&html_logger); - gaim_log_logger_add(&txt_logger); - gaim_log_logger_add(&old_logger); + + html_logger = gaim_log_logger_new("html", "HTML", 8, + NULL, + html_logger_write, + html_logger_finalize, + html_logger_list, + html_logger_read, + gaim_log_common_sizer, + NULL, + html_logger_list_syslog); + gaim_log_logger_add(html_logger); + + txt_logger = gaim_log_logger_new("txt", "Plain text", 8, + NULL, + txt_logger_write, + txt_logger_finalize, + txt_logger_list, + txt_logger_read, + gaim_log_common_sizer, + NULL, + txt_logger_list_syslog); + gaim_log_logger_add(txt_logger); + + old_logger = gaim_log_logger_new("old", "Old Gaim", 9, + NULL, + NULL, + old_logger_finalize, + old_logger_list, + old_logger_read, + old_logger_size, + old_logger_total_size, + NULL, + old_logger_get_log_sets); + gaim_log_logger_add(old_logger); + gaim_prefs_connect_callback(NULL, "/core/logging/format", - logger_pref_cb, NULL); + logger_pref_cb, NULL); gaim_prefs_trigger_callback("/core/logging/format"); logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, @@ -769,7 +853,7 @@ ****************************/ static void html_logger_write(GaimLog *log, GaimMessageFlags type, - const char *from, time_t time, const char *message) + const char *from, time_t time, const char *message) { char *msg_fixed; char date[64]; @@ -857,12 +941,12 @@ static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) { - return gaim_log_common_lister(type, sn, account, ".html", &html_logger); + return gaim_log_common_lister(type, sn, account, ".html", html_logger); } static GList *html_logger_list_syslog(GaimAccount *account) { - return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", &html_logger); + return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", html_logger); } static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) @@ -884,20 +968,6 @@ return g_strdup_printf(_("Could not read file: %s"), data->path); } -static GaimLogLogger html_logger = { - N_("HTML"), "html", - NULL, - html_logger_write, - html_logger_finalize, - html_logger_list, - html_logger_read, - gaim_log_common_sizer, - NULL, - html_logger_list_syslog, - NULL -}; - - /**************************** @@ -905,15 +975,15 @@ ****************************/ static void txt_logger_write(GaimLog *log, - GaimMessageFlags type, - const char *from, time_t time, const char *message) + GaimMessageFlags type, + const char *from, time_t time, const char *message) { char date[64]; GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; char *stripped = NULL; - if(!data) { + if (data == NULL) { /* 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. @@ -988,12 +1058,12 @@ static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) { - return gaim_log_common_lister(type, sn, account, ".txt", &txt_logger); + return gaim_log_common_lister(type, sn, account, ".txt", txt_logger); } static GList *txt_logger_list_syslog(GaimAccount *account) { - return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", &txt_logger); + return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", txt_logger); } static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) @@ -1017,18 +1087,7 @@ return g_strdup_printf(_("Could not read file: %s"), data->path); } -static GaimLogLogger txt_logger = { - N_("Plain text"), "txt", - NULL, - txt_logger_write, - txt_logger_finalize, - txt_logger_list, - txt_logger_read, - gaim_log_common_sizer, - NULL, - txt_logger_list_syslog, - NULL -}; + /**************** * OLD LOGGER *** @@ -1103,7 +1162,7 @@ if (newlen != 0) { log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); - log->logger = &old_logger; + log->logger = old_logger; log->time = lasttime; data = g_new0(struct old_logger_data, 1); data->offset = lastoff; @@ -1154,7 +1213,7 @@ if (logfound) { if ((newlen = ftell(file) - lastoff) != 0) { log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); - log->logger = &old_logger; + log->logger = old_logger; log->time = lasttime; data = g_new0(struct old_logger_data, 1); data->offset = lastoff; @@ -1300,15 +1359,3 @@ gaim_stringref_unref(data->pathref); g_free(data); } - -static GaimLogLogger old_logger = { - "old logger", "old", - NULL, NULL, - old_logger_finalize, - old_logger_list, - old_logger_read, - old_logger_size, - old_logger_total_size, - NULL, - old_logger_get_log_sets -}; diff -r b858f992b566 -r cd0c8830d881 src/log.h --- a/src/log.h Sun Sep 11 04:46:21 2005 +0000 +++ b/src/log.h Sun Sep 11 05:14:52 2005 +0000 @@ -142,7 +142,7 @@ char *name; /**< The name of the logs available */ GaimAccount *account; /**< The account the available logs took place on. This will be - NULL if the account no longer + @c NULL if the account no longer exists. (Depending on a logger's implementation of list, it may not be possible @@ -190,7 +190,7 @@ * * @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 + * @param from Whom this message is coming from, or @c NULL for * system messages * @param time A timestamp in UNIX time * @param message The message to log @@ -359,28 +359,23 @@ /** * Creates a new logger * - * @param create The logger's new function. - * @param write The logger's write function. - * @param finalize The logger's finalize function. - * @param list The logger's list function. - * @param read The logger's read function. - * @param size The logger's size function. - * @param total_size The logger's total_size function. - * @param list_syslog The logger's list_syslog function. - * @param get_log_sets The logger's get_log_sets function. + * @param id The logger's id. + * @param name The logger's name. + * @param functions The number of functions being passed. The following + * functions are currently available (in order): @c create, + * @c write, @c finalize, @c list, @c read, @c size, + * @c total_size, @c list_syslog, @c get_log_sets. For + * details on these functions, see GaimLogLogger. + * Functions may not be skipped. For example, passing + * @c create and @c write is acceptable (for a total of + * two functions). Passing @c create and @c finalize, + * however, is not. To accomplish that, the caller must + * pass @c create, @c NULL (a placeholder for @c write), + * and @c finalize (for a total of 3 functions). * * @return The new logger */ -GaimLogLogger *gaim_log_logger_new( - void(*create)(GaimLog *), - void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *), - void(*finalize)(GaimLog *), - GList*(*list)(GaimLogType type, const char*, GaimAccount*), - char*(*read)(GaimLog*, GaimLogReadFlags*), - int(*size)(GaimLog*), - int(*total_size)(GaimLogType type, const char *name, GaimAccount *account), - GList*(*list_syslog)(GaimAccount *account), - void(*get_log_sets)(GaimLogSetCallback cb, GHashTable *sets)); +GaimLogLogger *gaim_log_logger_new(const char *id, const char *name, int functions, ...); /** * Frees a logger