From: <ro...@us...> - 2006-08-22 16:42:21
|
Revision: 16980 Author: roast Date: 2006-08-22 09:42:14 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16980&view=rev Log Message: ----------- the beginnings of a purely signal-driven logging subsystem 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-08-22 16:13:43 UTC (rev 16979) +++ branches/soc-2006-file-loggers/src/log.c 2006-08-22 16:42:14 UTC (rev 16980) @@ -82,6 +82,11 @@ static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags); static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); +static void log_buddy_signed_on_cb(GaimBuddy *buddy); +static void log_buddy_signed_off_cb(GaimBuddy *buddy); +static void log_buddy_status_changed_cb(GaimBuddy *buddy, GaimStatus *old_status, GaimStatus *new_status); +static void log_buddy_idle_changed_cb(GaimBuddy *buddy, gboolean old_idle, gboolean new_idle); + static GaimActionData supported_actions[] = { { GAIM_ACTION_UNSET_ACTION, GAIM_ACTION_UNSET_ACTION, FALSE, NULL}, { GAIM_ACTION_UNSET_STATUS, GAIM_ACTION_UNSET_STATUS, FALSE, NULL}, @@ -701,7 +706,8 @@ void gaim_log_init(void) { - void *handle = gaim_log_get_handle(); + void *log_handle = gaim_log_get_handle(); + void *blist_handle = gaim_blist_get_handle(); gaim_prefs_add_none("/core/logging"); gaim_prefs_add_bool("/core/logging/log_ims", FALSE); @@ -758,7 +764,7 @@ old_logger_get_log_sets); gaim_log_logger_add(old_logger); - gaim_signal_register(handle, "log-timestamp", + gaim_signal_register(log_handle, "log-timestamp", #if SIZEOF_TIME_T == 4 gaim_marshal_POINTER__POINTER_INT, #elif SIZEOF_TIME_T == 8 @@ -784,6 +790,17 @@ logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, (GEqualFunc)_gaim_logsize_user_equal, (GDestroyNotify)_gaim_logsize_user_free_key, NULL); + + // connect to some of our signals + // eventually can rewrite the whole logging structure to use only signals + gaim_signal_connect(blist_handle, "buddy-signed-on", log_handle, + GAIM_CALLBACK(log_buddy_signed_on_cb), NULL); + gaim_signal_connect(blist_handle, "buddy-signed-off", log_handle, + GAIM_CALLBACK(log_buddy_signed_off_cb), NULL); + gaim_signal_connect(blist_handle, "buddy-status-changed", log_handle, + GAIM_CALLBACK(log_buddy_status_changed_cb), NULL); + gaim_signal_connect(blist_handle, "buddy-idle-changed", log_handle, + GAIM_CALLBACK(log_buddy_idle_changed_cb), NULL); } void @@ -1346,6 +1363,8 @@ GaimLogCommonLoggerData *data = log->logger_data; GIOStatus iostat; GError *gerror = NULL; + gboolean is_event = FALSE; /* if true, action is event. else, status */ + int i = 0; gsize written = 0; GString *writebuf = g_string_new(""); @@ -1380,13 +1399,24 @@ return 0; } + // is this action an event or status? + if (action > GAIM_ACTION_UNSET_STATUS && + action < GAIM_ACTION_UNSET_EVENT) { + is_event = FALSE; + } + else { + is_event = TRUE; + } + // create the log action if (tagdata != NULL && strlen(tagdata) > 0) { - g_string_printf(writebuf, "\t<event time=\"%s\"%s type=\"%s\">%s</event>\n", date, from_attributes, + g_string_printf(writebuf, "\t<%s time=\"%s\"%s type=\"%s\">%s</event>\n", + is_event ? "event" : "status", date, from_attributes, gaim_log_action_ulf_value(action), tagdata); } else { - g_string_printf(writebuf, "\t<event time=\"%s\"%s type=\"%s\" />\n", date, from_attributes, + g_string_printf(writebuf, "\t<%s time=\"%s\"%s type=\"%s\" />\n", + is_event ? "event" : "status", date, from_attributes, gaim_log_action_ulf_value(action)); } @@ -2321,3 +2351,101 @@ gaim_stringref_unref(data->pathref); g_slice_free(struct old_logger_data, data); } + +/* log_buddy_signed_(on|off)_cb shows that the xml_logger_write's don't get sender,senderformatted,alias,handle correct */ +static void log_buddy_signed_on_cb(GaimBuddy *buddy) { + GaimConversation *conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); + const char *alias = NULL; + GList *log = NULL; + + if (conv == NULL) return; + + if (buddy->alias != NULL) + alias = buddy->alias; + else if (buddy->server_alias != NULL) + alias = buddy->server_alias; + else + alias = buddy->name; + + log = conv->logs; + while (log != NULL) { + gaim_log_write_action((GaimLog *)log->data, GAIM_ACTION_STATUS_ONLINE, + alias, gaim_presence_get_login_time(buddy->presence), NULL); + log = log->next; + } +} + +static void log_buddy_signed_off_cb(GaimBuddy *buddy) { + GaimConversation *conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); + const char *alias = NULL; + GList *log; + + if (conv == NULL) return; + + if (buddy->alias != NULL) + alias = buddy->alias; + else if (buddy->server_alias != NULL) + alias = buddy->server_alias; + else + alias = buddy->name; + + log = conv->logs; + while (log != NULL) { + gaim_log_write_action((GaimLog *)log->data, GAIM_ACTION_STATUS_OFFLINE, + alias, time(NULL), NULL); + log = log->next; + } + +} + +/* create a gaim_log_write(_action)() call after figuring out which GaimLogs need to be written to */ +static void log_buddy_status_changed_cb(GaimBuddy *buddy, GaimStatus *old_status, GaimStatus *new_status) { + GaimConversation *conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); + const char *alias = NULL; + GList *log; + + if (conv == NULL) return; + + if (buddy->alias != NULL) + alias = buddy->alias; + else if (buddy->server_alias != NULL) + alias = buddy->server_alias; + else + alias = buddy->name; + + log = conv->logs; + while (log != NULL) { + log = log->next; + } +/* + gaim_debug_info("log-cb", "buddy-status-changed: buddy \"%s\" changed from \"%s\" to \"%s\"\n", + buddy->name, + gaim_status_get_name(old_status), + gaim_status_get_name(new_status)); +*/ +} + +/* create a gaim_log_write(_action)() call after figuring out which GaimLogs need to be written to */ +static void log_buddy_idle_changed_cb(GaimBuddy *buddy, gboolean old_idle, gboolean new_idle) { + GaimConversation *conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); + const char *alias = NULL; + GList *log; + + if (conv == NULL) return; + + if (buddy->alias != NULL) + alias = buddy->alias; + else if (buddy->server_alias != NULL) + alias = buddy->server_alias; + else + alias = buddy->name; + + log = conv->logs; + while (log != NULL) { + log = log->next; + } +/* + gaim_debug_info("log-cb", "buddy-idle-changed: buddy \"%s\" changed from \"%s\" to \"%s\", since %d\n", buddy->name, old_idle, new_idle, + gaim_presence_get_idle_time(buddy->presence)); +*/ +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |