annotate src/log.c @ 13411:0d223f4ee868

[gaim-migrate @ 15786] Memory leak fix from Sadrul. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 07 Mar 2006 01:12:13 +0000
parents 3033597a4059
children e4aa2648ca28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1 /**
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
2 * @file log.c Logging API
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
3 * @ingroup core
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
4 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
5 * gaim
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
9 * source distribution.
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
10 *
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
11 * This program is free software; you can redistribute it and/or modify
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
12 * it under the terms of the GNU General Public License as published by
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
14 * (at your option) any later version.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
15 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
16 * This program is distributed in the hope that it will be useful,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
19 * GNU General Public License for more details.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
20 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
21 * You should have received a copy of the GNU General Public License
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
22 * along with this program; if not, write to the Free Software
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
4195
4a0837c49d85 [gaim-migrate @ 4426]
Luke Schierer <lschiere@pidgin.im>
parents: 4192
diff changeset
25
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
26 #include "account.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
27 #include "debug.h"
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
28 #include "internal.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
29 #include "log.h"
5548
80e4ba770f97 [gaim-migrate @ 5949]
Nathan Walp <nwalp@pidgin.im>
parents: 5528
diff changeset
30 #include "prefs.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
31 #include "util.h"
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
32 #include "stringref.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
33
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
34 static GSList *loggers = NULL;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
35
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
36 static GaimLogLogger *html_logger;
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
37 static GaimLogLogger *txt_logger;
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
38 static GaimLogLogger *old_logger;
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
39
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
40 struct _gaim_logsize_user {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
41 char *name;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
42 GaimAccount *account;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
43 };
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
44 static GHashTable *logsize_users = NULL;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
45
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
46 static void log_get_log_sets_common(GHashTable *sets);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
47
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
48 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
49 const char *from, time_t time, const char *message);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
50 static void html_logger_finalize(GaimLog *log);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
51 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
52 static GList *html_logger_list_syslog(GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
53 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags);
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
54 static int html_logger_total_size(GaimLogType type, const char *name, GaimAccount *account);
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
55
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
56 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
57 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
58 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
59 static int old_logger_size (GaimLog *log);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
60 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
61 static void old_logger_finalize(GaimLog *log);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
62
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
63 static gsize txt_logger_write(GaimLog *log,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
64 GaimMessageFlags type,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
65 const char *from, time_t time, const char *message);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
66 static void txt_logger_finalize(GaimLog *log);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
67 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
68 static GList *txt_logger_list_syslog(GaimAccount *account);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
69 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags);
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
70 static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account);
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
71
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
72 /**************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
73 * PUBLIC LOGGING FUNCTIONS ***********************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
74 **************************************************************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
76 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account,
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
77 GaimConversation *conv, time_t time, const struct tm *tm)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
78 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
79 GaimLog *log = g_new0(GaimLog, 1);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
80 log->name = g_strdup(gaim_normalize(account, name));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
81 log->account = account;
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
82 log->conv = conv;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
83 log->time = time;
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
84 log->type = type;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
85 log->logger_data = NULL;
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
86 if (tm != NULL)
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
87 {
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
88 log->tm = g_new0(struct tm, 1);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
89 *(log->tm) = *tm;
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
90
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
91 #ifdef HAVE_STRUCT_TM_TM_ZONE
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
92 /* XXX: This is so wrong... */
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
93 if (log->tm->tm_zone != NULL)
13160
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
94 {
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
95 char *tmp = g_locale_from_utf8(log->tm->tm_zone, -1, NULL, NULL, NULL);
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
96 if (tmp != NULL)
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
97 log->tm->tm_zone = (const char *)tmp;
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
98 else
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
99 /* Just shove the UTF-8 bytes in and hope... */
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
100 log->tm->tm_zone = (const char *)g_strdup(log->tm->tm_zone);
1b48f0ec55e9 [gaim-migrate @ 15523]
Richard Laager <rlaager@wiktel.com>
parents: 13159
diff changeset
101 }
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
102 #endif
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
103 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
104 log->logger = gaim_log_logger_get();
7440
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
105 if (log->logger && log->logger->create)
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
106 log->logger->create(log);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
107 return log;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
110 void gaim_log_free(GaimLog *log)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
112 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
113 if (log->logger && log->logger->finalize)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
114 log->logger->finalize(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
115 g_free(log->name);
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
116
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
117 if (log->tm != NULL)
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
118 {
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
119 #ifdef HAVE_STRUCT_TM_TM_ZONE
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
120 /* XXX: This is so wrong... */
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
121 g_free((char *)log->tm->tm_zone);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
122 #endif
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
123 g_free(log->tm);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
124 }
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
125
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
126 g_free(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
127 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
128
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
129 void gaim_log_write(GaimLog *log, GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
130 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
131 {
10173
c754d26fe85e [gaim-migrate @ 11287]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10171
diff changeset
132 struct _gaim_logsize_user *lu;
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
133 gsize written, total = 0;
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
134 gpointer ptrsize;
10173
c754d26fe85e [gaim-migrate @ 11287]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10171
diff changeset
135
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
136 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
137 g_return_if_fail(log->logger);
7442
d42289ecf0ce [gaim-migrate @ 8047]
Nathan Walp <nwalp@pidgin.im>
parents: 7441
diff changeset
138 g_return_if_fail(log->logger->write);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
139
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
140 written = (log->logger->write)(log, type, from, time, message);
10171
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
141
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
142 lu = g_new(struct _gaim_logsize_user, 1);
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
143
10171
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
144 lu->name = g_strdup(gaim_normalize(log->account, log->name));
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
145 lu->account = log->account;
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
146
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
147 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) {
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
148 total = GPOINTER_TO_INT(ptrsize);
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
149 total += written;
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
150 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(total));
13076
f3abb141042a [gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents: 13069
diff changeset
151 } else {
f3abb141042a [gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents: 13069
diff changeset
152 g_free(lu->name);
f3abb141042a [gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents: 13069
diff changeset
153 g_free(lu);
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
154 }
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
155
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
158 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159 {
7542
ebccd555323b [gaim-migrate @ 8156]
Nathan Walp <nwalp@pidgin.im>
parents: 7541
diff changeset
160 GaimLogReadFlags mflags;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
161 g_return_val_if_fail(log && log->logger, NULL);
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
162 if (log->logger->read) {
7535
f771759739c1 [gaim-migrate @ 8148]
Sean Egan <seanegan@gmail.com>
parents: 7501
diff changeset
163 char *ret = (log->logger->read)(log, flags ? flags : &mflags);
11920
52f27ffe68a5 [gaim-migrate @ 14211]
Mark Doliner <mark@kingant.net>
parents: 11703
diff changeset
164 gaim_str_strip_char(ret, '\r');
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
165 return ret;
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
166 }
13106
a0a4b44239e8 [gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents: 13104
diff changeset
167 return g_strdup(_("<b><font color=\"red\">The logger has no read function</font></b>"));
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 }
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
169
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
170 int gaim_log_get_size(GaimLog *log)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
171 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
172 g_return_val_if_fail(log && log->logger, 0);
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
173
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
174 if (log->logger->size)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
175 return log->logger->size(log);
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
176 return 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
177 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
178
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
179 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
180 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
181 return g_str_hash(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
182 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
183
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
184 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
185 struct _gaim_logsize_user *lu2)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
186 {
13077
64ca89ffc639 [gaim-migrate @ 15439]
Richard Laager <rlaager@wiktel.com>
parents: 13076
diff changeset
187 return (lu1->account == lu2->account && (!strcmp(lu1->name, lu2->name)));
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
188 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
189
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
190 static void _gaim_logsize_user_free_key(struct _gaim_logsize_user *lu)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
191 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
192 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
193 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
194 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
195
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
196 int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
197 {
9677
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
198 gpointer ptrsize;
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
199 int size = 0;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
200 GSList *n;
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
201 struct _gaim_logsize_user *lu;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
202
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
203 lu = g_new(struct _gaim_logsize_user, 1);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
204 lu->name = g_strdup(gaim_normalize(account, name));
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
205 lu->account = account;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
206
9677
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
207 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) {
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
208 size = GPOINTER_TO_INT(ptrsize);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
209 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
210 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
211 } else {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
212 for (n = loggers; n; n = n->next) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
213 GaimLogLogger *logger = n->data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
214
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
215 if(logger->total_size){
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
216 size += (logger->total_size)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
217 } else if(logger->list) {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
218 GList *logs = (logger->list)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
219 int this_size = 0;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
220
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
221 while (logs) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
222 GList *logs2 = logs->next;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
223 GaimLog *log = (GaimLog*)(logs->data);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
224 this_size += gaim_log_get_size(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
225 gaim_log_free(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
226 g_list_free_1(logs);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
227 logs = logs2;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
228 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
229
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
230 size += this_size;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
231 }
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
232 }
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
233
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
234 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size));
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
235 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
236 return size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
237 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
239 char *
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
240 gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
241 {
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
242 GaimPlugin *prpl;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
243 GaimPluginProtocolInfo *prpl_info;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
244 const char *prpl_name;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
245 char *acct_name;
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
246 const char *target;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
247 char *dir;
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
248
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
249 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
250 if (!prpl)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
251 return NULL;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
252 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
253 prpl_name = prpl_info->list_icon(account, NULL);
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
254
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
255 acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account,
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
256 gaim_account_get_username(account))));
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
257
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
258 if (type == GAIM_LOG_CHAT) {
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
259 char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name));
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
260 target = gaim_escape_filename(temp);
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
261 g_free(temp);
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
262 } else if(type == GAIM_LOG_SYSTEM) {
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
263 target = ".system";
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
264 } else {
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
265 target = gaim_escape_filename(gaim_normalize(account, name));
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
266 }
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
267
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
268 dir = g_build_filename(gaim_user_dir(), "logs", prpl_name, acct_name, target, NULL);
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
269
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
270 g_free(acct_name);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
271
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
272 return dir;
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
273 }
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
274
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
275 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
276 * LOGGER FUNCTIONS *********************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
277 ****************************************************************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
279 static GaimLogLogger *current_logger = NULL;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
280
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
281 static void logger_pref_cb(const char *name, GaimPrefType type,
12816
ff267281e882 [gaim-migrate @ 15164]
Mark Doliner <mark@kingant.net>
parents: 12738
diff changeset
282 gconstpointer value, gpointer data)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
283 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
284 GaimLogLogger *logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
285 GSList *l = loggers;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
286 while (l) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
287 logger = l->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
288 if (!strcmp(logger->id, value)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
289 gaim_log_logger_set(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
290 return;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
292 l = l->next;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
293 }
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
294 gaim_log_logger_set(txt_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
295 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
298 GaimLogLogger *gaim_log_logger_new(const char *id, const char *name, int functions, ...)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
299 {
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
300 #if 0
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
301 void(*create)(GaimLog *),
13068
78fa9502715b [gaim-migrate @ 15430]
Richard Laager <rlaager@wiktel.com>
parents: 13059
diff changeset
302 gsize(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *),
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
303 void(*finalize)(GaimLog *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
304 GList*(*list)(GaimLogType type, const char*, GaimAccount*),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
305 char*(*read)(GaimLog*, GaimLogReadFlags*),
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
306 int(*size)(GaimLog*),
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
307 int(*total_size)(GaimLogType type, const char *name, GaimAccount *account),
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
308 GList*(*list_syslog)(GaimAccount *account),
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
309 void(*get_log_sets)(GaimLogSetCallback cb, GHashTable *sets))
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
310 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
311 #endif
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
312 GaimLogLogger *logger;
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
313 va_list args;
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
314
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
315 g_return_val_if_fail(id != NULL, NULL);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
316 g_return_val_if_fail(name != NULL, NULL);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
317 g_return_val_if_fail(functions >= 1, NULL);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
318
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
319 logger = g_new0(GaimLogLogger, 1);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
320 logger->id = g_strdup(id);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
321 logger->name = g_strdup(name);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
322
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
323 va_start(args, functions);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
324
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
325 if (functions >= 1)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
326 logger->create = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
327 if (functions >= 2)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
328 logger->write = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
329 if (functions >= 3)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
330 logger->finalize = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
331 if (functions >= 4)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
332 logger->list = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
333 if (functions >= 5)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
334 logger->read = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
335 if (functions >= 6)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
336 logger->size = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
337 if (functions >= 7)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
338 logger->total_size = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
339 if (functions >= 8)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
340 logger->list_syslog = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
341 if (functions >= 9)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
342 logger->get_log_sets = va_arg(args, void *);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
343
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
344 if (functions > 9)
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
345 gaim_debug_info("log", "Dropping new functions for logger: %s (%s)\n", name, id);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
346
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
347 va_end(args);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
348
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
349 return logger;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
350 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
352 void gaim_log_logger_free(GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
353 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
354 g_free(logger->name);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
355 g_free(logger->id);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
356 g_free(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
357 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
358
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
359 void gaim_log_logger_add (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
360 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
361 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
362 if (g_slist_find(loggers, logger))
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
363 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
364 loggers = g_slist_append(loggers, logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
365 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
366
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
367 void gaim_log_logger_remove (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
368 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
369 g_return_if_fail(logger);
12574
a4500bcbec08 [gaim-migrate @ 14896]
Mark Doliner <mark@kingant.net>
parents: 12241
diff changeset
370 loggers = g_slist_remove(loggers, logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
371 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
372
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
373 void gaim_log_logger_set (GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
374 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
375 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
376 current_logger = logger;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
377 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
378
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
379 GaimLogLogger *gaim_log_logger_get()
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
380 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
381 return current_logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
382 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
383
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
384 GList *gaim_log_logger_get_options(void)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
385 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
386 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
387 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
388 GaimLogLogger *data;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
389
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
390 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
391 data = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
392 if (!data->write)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
393 continue;
12241
4777c5912068 [gaim-migrate @ 14543]
Richard Laager <rlaager@wiktel.com>
parents: 12240
diff changeset
394 list = g_list_append(list, data->name);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
395 list = g_list_append(list, data->id);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
396 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
397
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
398 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
399 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
400
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
401 gint gaim_log_compare(gconstpointer y, gconstpointer z)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
402 {
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
403 const GaimLog *a = y;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
404 const GaimLog *b = z;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
405
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
406 return b->time - a->time;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
407 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
408
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
409 GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
410 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
411 GList *logs = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
412 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
413 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
414 GaimLogLogger *logger = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
415 if (!logger->list)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
416 continue;
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
417 logs = g_list_concat(logger->list(type, name, account), logs);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
418 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
419
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
420 return g_list_sort(logs, gaim_log_compare);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
421 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
422
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
423 gint gaim_log_set_compare(gconstpointer y, gconstpointer z)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
424 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
425 const GaimLogSet *a = y;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
426 const GaimLogSet *b = z;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
427 gint ret = 0;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
428
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
429 /* This logic seems weird at first...
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
430 * If either account is NULL, we pretend the accounts are
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
431 * equal. This allows us to detect duplicates that will
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
432 * exist if one logger knows the account and another
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
433 * doesn't. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
434 if (a->account != NULL && b->account != NULL) {
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
435 ret = strcmp(gaim_account_get_username(a->account), gaim_account_get_username(b->account));
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
436 if (ret != 0)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
437 return ret;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
438 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
439
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
440 ret = strcmp(a->normalized_name, b->normalized_name);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
441 if (ret != 0)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
442 return ret;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
443
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
444 return (gint)b->type - (gint)a->type;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
445 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
446
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
447 static guint
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
448 log_set_hash(gconstpointer key)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
449 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
450 const GaimLogSet *set = key;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
451
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
452 /* The account isn't hashed because we need GaimLogSets with NULL accounts
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
453 * to be found when we search by a GaimLogSet that has a non-NULL account
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
454 * but the same type and name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
455 return g_int_hash((gint *)&set->type) + g_str_hash(set->name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
456 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
457
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
458 static gboolean
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
459 log_set_equal(gconstpointer a, gconstpointer b)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
460 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
461 /* I realize that the choices made for GList and GHashTable
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
462 * make sense for those data types, but I wish the comparison
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
463 * functions were compatible. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
464 return !gaim_log_set_compare(a, b);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
465 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
466
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
467 static void
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11503
diff changeset
468 log_add_log_set_to_hash(GHashTable *sets, GaimLogSet *set)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
469 {
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
470 GaimLogSet *existing_set = g_hash_table_lookup(sets, set);
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
471
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
472 if (existing_set == NULL)
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
473 g_hash_table_insert(sets, set, set);
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
474 else if (existing_set->account == NULL && set->account != NULL)
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
475 g_hash_table_replace(sets, set, set);
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
476 else
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
477 gaim_log_set_free(set);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
478 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
479
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
480 GHashTable *gaim_log_get_log_sets(void)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
481 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
482 GSList *n;
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
483 GHashTable *sets = g_hash_table_new_full(log_set_hash, log_set_equal,
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
484 (GDestroyNotify)gaim_log_set_free, NULL);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
485
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
486 /* Get the log sets from all the loggers. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
487 for (n = loggers; n; n = n->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
488 GaimLogLogger *logger = n->data;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
489
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
490 if (!logger->get_log_sets)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
491 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
492
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
493 logger->get_log_sets(log_add_log_set_to_hash, sets);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
494 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
495
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
496 log_get_log_sets_common(sets);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
497
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
498 /* Return the GHashTable of unique GaimLogSets. */
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
499 return sets;
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
500 }
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
501
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
502 void gaim_log_set_free(GaimLogSet *set)
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
503 {
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
504 g_return_if_fail(set != NULL);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
505
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
506 g_free(set->name);
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
507 if (set->normalized_name != set->name)
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
508 g_free(set->normalized_name);
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
509 g_free(set);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
510 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
511
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
512 GList *gaim_log_get_system_logs(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
513 {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
514 GList *logs = NULL;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
515 GSList *n;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
516 for (n = loggers; n; n = n->next) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
517 GaimLogLogger *logger = n->data;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
518 if (!logger->list_syslog)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
519 continue;
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
520 logs = g_list_concat(logger->list_syslog(account), logs);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
521 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
522
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
523 return g_list_sort(logs, gaim_log_compare);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
524 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
525
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
526 /****************************************************************************
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
527 * LOG SUBSYSTEM ************************************************************
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
528 ****************************************************************************/
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
529
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
530 void *
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
531 gaim_log_get_handle(void)
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
532 {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
533 static int handle;
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
534
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
535 return &handle;
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
536 }
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
537
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
538 void gaim_log_init(void)
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
539 {
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
540 void *handle = gaim_log_get_handle();
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
541
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
542 gaim_prefs_add_none("/core/logging");
7555
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
543 gaim_prefs_add_bool("/core/logging/log_ims", FALSE);
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
544 gaim_prefs_add_bool("/core/logging/log_chats", FALSE);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
545 gaim_prefs_add_bool("/core/logging/log_system", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
546
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
547 gaim_prefs_add_string("/core/logging/format", "txt");
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
548
12240
1c0fd404e07e [gaim-migrate @ 14542]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
549 html_logger = gaim_log_logger_new("html", _("HTML"), 8,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
550 NULL,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
551 html_logger_write,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
552 html_logger_finalize,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
553 html_logger_list,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
554 html_logger_read,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
555 gaim_log_common_sizer,
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
556 html_logger_total_size,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
557 html_logger_list_syslog);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
558 gaim_log_logger_add(html_logger);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
559
12240
1c0fd404e07e [gaim-migrate @ 14542]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
560 txt_logger = gaim_log_logger_new("txt", _("Plain text"), 8,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
561 NULL,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
562 txt_logger_write,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
563 txt_logger_finalize,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
564 txt_logger_list,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
565 txt_logger_read,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
566 gaim_log_common_sizer,
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
567 txt_logger_total_size,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
568 txt_logger_list_syslog);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
569 gaim_log_logger_add(txt_logger);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
570
12240
1c0fd404e07e [gaim-migrate @ 14542]
Mark Doliner <mark@kingant.net>
parents: 11920
diff changeset
571 old_logger = gaim_log_logger_new("old", _("Old Gaim"), 9,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
572 NULL,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
573 NULL,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
574 old_logger_finalize,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
575 old_logger_list,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
576 old_logger_read,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
577 old_logger_size,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
578 old_logger_total_size,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
579 NULL,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
580 old_logger_get_log_sets);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
581 gaim_log_logger_add(old_logger);
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
582
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
583 gaim_signal_register(handle, "log-timestamp",
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
584 gaim_marshal_POINTER__POINTER_POINTER,
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
585 gaim_value_new(GAIM_TYPE_POINTER), 2,
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
586 gaim_value_new(GAIM_TYPE_SUBTYPE,
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
587 GAIM_SUBTYPE_LOG),
12834
03ff00e0bb84 [gaim-migrate @ 15182]
Richard Laager <rlaager@wiktel.com>
parents: 12816
diff changeset
588 gaim_value_new(GAIM_TYPE_BOXED,
03ff00e0bb84 [gaim-migrate @ 15182]
Richard Laager <rlaager@wiktel.com>
parents: 12816
diff changeset
589 "struct tm *"));
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
590
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9977
diff changeset
591 gaim_prefs_connect_callback(NULL, "/core/logging/format",
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
592 logger_pref_cb, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
593 gaim_prefs_trigger_callback("/core/logging/format");
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
594
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
595 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
596 (GEqualFunc)_gaim_logsize_user_equal,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
597 (GDestroyNotify)_gaim_logsize_user_free_key, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
598 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
599
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
600 void
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
601 gaim_log_uninit(void)
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
602 {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
603 gaim_signals_unregister_by_instance(gaim_log_get_handle());
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
604 }
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
605
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
606 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
607 * LOGGERS ******************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
608 ****************************************************************************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
609
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
610 static char *log_get_timestamp(GaimLog *log, time_t when)
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
611 {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
612 char *date;
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
613 struct tm tm = *(localtime(&when));
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
614
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
615 date = gaim_signal_emit_return_1(gaim_log_get_handle(),
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
616 "log-timestamp",
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
617 log, &tm);
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
618 if (date != NULL)
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
619 return date;
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
620
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
621 if (log->type == GAIM_LOG_SYSTEM || time(NULL) > when + 20*60)
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
622 return g_strdup(gaim_date_format_long(&tm));
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
623 else
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
624 return g_strdup(gaim_time_format(&tm));
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
625 }
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
626
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
627 void gaim_log_common_writer(GaimLog *log, const char *ext)
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
628 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
629 GaimLogCommonLoggerData *data = log->logger_data;
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
630
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
631 if (data == NULL)
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
632 {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
633 /* This log is new */
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
634 char *dir;
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
635 struct tm *tm;
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
636 const char *tz;
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
637 const char *date;
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
638 char *filename;
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
639 char *path;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
640
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
641 dir = gaim_log_get_log_dir(log->type, log->name, log->account);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
642 if (dir == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
643 return;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
644
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
645 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
646
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
647 tm = localtime(&log->time);
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
648 tz = gaim_escape_filename(gaim_utf8_strftime("%Z", tm));
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
649 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
650
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
651 filename = g_strdup_printf("%s%s%s", date, tz, ext ? ext : "");
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
652
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
653 path = g_build_filename(dir, filename, NULL);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
654 g_free(dir);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
655 g_free(filename);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
656
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
657 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
658
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
659 data->file = g_fopen(path, "a");
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
660 if (data->file == NULL)
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
661 {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
662 gaim_debug(GAIM_DEBUG_ERROR, "log",
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
663 "Could not create log file %s\n", path);
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
664
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
665 if (log->conv != NULL)
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
666 gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."),
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
667 GAIM_MESSAGE_ERROR, time(NULL));
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
668
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
669 g_free(path);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
670 return;
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
671 }
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
672 g_free(path);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
673 }
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
674 }
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
675
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
676 GList *gaim_log_common_lister(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
677 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
678 GDir *dir;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
679 GList *list = NULL;
13159
d03013fd39bf [gaim-migrate @ 15522]
Richard Laager <rlaager@wiktel.com>
parents: 13156
diff changeset
680 const char *filename;
8111
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
681 char *path;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
682
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
683 if(!account)
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
684 return NULL;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
685
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
686 path = gaim_log_get_log_dir(type, name, account);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
687 if (path == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
688 return NULL;
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
689
12969
b98a28bf29d9 [gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents: 12958
diff changeset
690 if (!(dir = g_dir_open(path, 0, NULL)))
b98a28bf29d9 [gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents: 12958
diff changeset
691 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
692 g_free(path);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
693 return NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
694 }
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
695
13159
d03013fd39bf [gaim-migrate @ 15522]
Richard Laager <rlaager@wiktel.com>
parents: 13156
diff changeset
696 while ((filename = g_dir_read_name(dir)))
12969
b98a28bf29d9 [gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents: 12958
diff changeset
697 {
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
698 if (gaim_str_has_suffix(filename, ext) &&
12969
b98a28bf29d9 [gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents: 12958
diff changeset
699 strlen(filename) >= (17 + strlen(ext)))
b98a28bf29d9 [gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents: 12958
diff changeset
700 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
701 GaimLog *log;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
702 GaimLogCommonLoggerData *data;
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
703 #if defined (HAVE_TM_GMTOFF) && defined (HAVE_STRUCT_TM_TM_ZONE)
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
704 struct tm tm;
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
705 long tz_off;
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
706 const char *rest;
13159
d03013fd39bf [gaim-migrate @ 15522]
Richard Laager <rlaager@wiktel.com>
parents: 13156
diff changeset
707 time_t stamp = gaim_str_to_time(gaim_unescape_filename(filename), FALSE, &tm, &tz_off, &rest);
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
708 char *end;
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
709
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
710 /* As zero is a valid offset, GAIM_NO_TZ_OFF means no offset was
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
711 * provided. See util.h. Yes, it's kinda ugly. */
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
712 if (tz_off != GAIM_NO_TZ_OFF)
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
713 tm.tm_gmtoff = tz_off - tm.tm_gmtoff;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
714
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
715 if (rest == NULL || (end = strchr(rest, '.')) == NULL || strchr(rest, ' ') != NULL)
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
716 {
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
717 log = gaim_log_new(type, name, account, NULL, stamp, NULL);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
718 }
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
719 else
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
720 {
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
721 char *tmp = g_strndup(rest, end - rest);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
722 tm.tm_zone = tmp;
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
723 log = gaim_log_new(type, name, account, NULL, stamp, &tm);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
724 g_free(tmp);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
725 }
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
726 #else
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
727 time_t stamp = gaim_str_to_time(filename, FALSE, NULL, NULL, NULL);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
728
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
729 log = gaim_log_new(type, name, account, NULL, stamp, NULL);
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
730 #endif
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
731
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
732 log->logger = logger;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
733 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
734 data->path = g_build_filename(path, filename, NULL);
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
735 list = g_list_prepend(list, log);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
736 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
737 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
738 g_dir_close(dir);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
739 g_free(path);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
740 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
741 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
742
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
743 int gaim_log_common_total_sizer(GaimLogType type, const char *name, GaimAccount *account, const char *ext)
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
744 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
745 GDir *dir;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
746 int size = 0;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
747 const char *filename;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
748 char *path;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
749
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
750 if(!account)
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
751 return 0;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
752
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
753 path = gaim_log_get_log_dir(type, name, account);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
754 if (path == NULL)
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
755 return 0;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
756
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
757 if (!(dir = g_dir_open(path, 0, NULL)))
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
758 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
759 g_free(path);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
760 return 0;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
761 }
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
762
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
763 while ((filename = g_dir_read_name(dir)))
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
764 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
765 if (gaim_str_has_suffix(filename, ext) &&
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
766 strlen(filename) >= (17 + strlen(ext)))
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
767 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
768 char *tmp = g_build_filename(path, filename, NULL);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
769 struct stat st;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
770 if (g_stat(tmp, &st))
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
771 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
772 gaim_debug_error("log", "Error stating log file: %s\n", tmp);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
773 g_free(tmp);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
774 continue;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
775 }
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
776 g_free(tmp);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
777 size += st.st_size;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
778 }
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
779 }
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
780 g_dir_close(dir);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
781 g_free(path);
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
782 return size;
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
783 }
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
784
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
785 int gaim_log_common_sizer(GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
786 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
787 struct stat st;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
788 GaimLogCommonLoggerData *data = log->logger_data;
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
789
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
790 if (!data->path || g_stat(data->path, &st))
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
791 st.st_size = 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
792
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
793 return st.st_size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
794 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
795
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
796 /* This will build log sets for all loggers that use the common logger
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
797 * functions because they use the same directory structure. */
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
798 static void log_get_log_sets_common(GHashTable *sets)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
799 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
800 gchar *log_path = g_build_filename(gaim_user_dir(), "logs", NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
801 GDir *log_dir = g_dir_open(log_path, 0, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
802 const gchar *protocol;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
803
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
804 if (log_dir == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
805 g_free(log_path);
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
806 return;
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
807 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
808
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
809 while ((protocol = g_dir_read_name(log_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
810 gchar *protocol_path = g_build_filename(log_path, protocol, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
811 GDir *protocol_dir;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
812 const gchar *username;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
813 gchar *protocol_unescaped;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
814 GList *account_iter;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
815 GList *accounts = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
816
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
817 if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
818 g_free(protocol_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
819 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
820 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
821
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
822 /* Using g_strdup() to cover the one-in-a-million chance that a
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
823 * prpl's list_icon function uses gaim_unescape_filename(). */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
824 protocol_unescaped = g_strdup(gaim_unescape_filename(protocol));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
825
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
826 /* Find all the accounts for protocol. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
827 for (account_iter = gaim_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
828 GaimPlugin *prpl;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
829 GaimPluginProtocolInfo *prpl_info;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
830
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
831 prpl = gaim_find_prpl(gaim_account_get_protocol_id((GaimAccount *)account_iter->data));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
832 if (!prpl)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
833 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
834 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
835
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
836 if (!strcmp(protocol_unescaped, prpl_info->list_icon((GaimAccount *)account_iter->data, NULL)))
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
837 accounts = g_list_prepend(accounts, account_iter->data);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
838 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
839 g_free(protocol_unescaped);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
840
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
841 while ((username = g_dir_read_name(protocol_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
842 gchar *username_path = g_build_filename(protocol_path, username, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
843 GDir *username_dir;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
844 const gchar *username_unescaped;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
845 GaimAccount *account = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
846 gchar *name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
847
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
848 if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
849 g_free(username_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
850 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
851 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
852
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
853 /* Find the account for username in the list of accounts for protocol. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
854 username_unescaped = gaim_unescape_filename(username);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
855 for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
856 if (!strcmp(((GaimAccount *)account_iter->data)->username, username_unescaped)) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
857 account = account_iter->data;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
858 break;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
859 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
860 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
861
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
862 /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
863 while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
864 size_t len;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
865 GaimLogSet *set = g_new0(GaimLogSet, 1);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
866
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
867 /* Unescape the filename. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
868 name = g_strdup(gaim_unescape_filename(name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
869
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
870 /* Get the (possibly new) length of name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
871 len = strlen(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
872
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
873 set->account = account;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
874 set->name = name;
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
875 set->normalized_name = g_strdup(gaim_normalize(account, name));
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
876
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
877 /* Chat for .chat or .system at the end of the name to determine the type. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
878 set->type = GAIM_LOG_IM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
879 if (len > 7) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
880 gchar *tmp = &name[len - 7];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
881 if (!strcmp(tmp, ".system")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
882 set->type = GAIM_LOG_SYSTEM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
883 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
884 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
885 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
886 if (len > 5) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
887 gchar *tmp = &name[len - 5];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
888 if (!strcmp(tmp, ".chat")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
889 set->type = GAIM_LOG_CHAT;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
890 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
891 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
892 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
893
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
894 /* Determine if this (account, name) combination exists as a buddy. */
11458
4db38b374d3f [gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents: 11292
diff changeset
895 if (account != NULL)
4db38b374d3f [gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents: 11292
diff changeset
896 set->buddy = (gaim_find_buddy(account, name) != NULL);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
897
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
898 log_add_log_set_to_hash(sets, set);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
899 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
900 g_free(username_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
901 g_dir_close(username_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
902 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
903 g_free(protocol_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
904 g_dir_close(protocol_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
905 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
906 g_free(log_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
907 g_dir_close(log_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
908 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
909
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
910 #if 0 /* Maybe some other time. */
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
911 /****************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
912 ** XML LOGGER **
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
913 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
914
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
915 static const char *str_from_msg_type (GaimMessageFlags type)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
916 {
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
917
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
918 return "";
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
919
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
920 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
921
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
922 static void xml_logger_write(GaimLog *log,
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
923 GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
924 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
925 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
926 char *xhtml = NULL;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
927
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
928 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
929 /* This log is new. We could use the loggers 'new' function, but
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
930 * creating a new file there would result in empty files in the case
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
931 * that you open a convo with someone, but don't say anything.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
932 */
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
933 struct tm *tm;
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
934 const char *tz;
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
935 const char *date;
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
936 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account);
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
937 char *name;
13154
0d755026832c [gaim-migrate @ 15517]
Richard Laager <rlaager@wiktel.com>
parents: 13119
diff changeset
938 char *filename;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
939
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
940 if (dir == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
941 return;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
942
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
943 tm = localtime(&log->time);
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
944 tz = gaim_escape_filename(gaim_utf8_strftime("%Z", tm);
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
945 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm);
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
946
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
947 name = g_strdup_printf("%s%s%s", date, tz, ext ? ext : "");
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
948
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
949 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
950
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
951 filename = g_build_filename(dir, name, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
952 g_free(dir);
13162
dc0375c4984a [gaim-migrate @ 15525]
Richard Laager <rlaager@wiktel.com>
parents: 13160
diff changeset
953 g_free(name);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
954
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
955 log->logger_data = g_fopen(filename, "a");
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
956 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
957 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
958 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
959 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
960 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
961 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
962 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n"
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
963 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n");
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
964
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
965 date = gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", localtime(&log->time));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
966 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
967 date, log->name, prpl);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
968 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
969
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
970 /* if we can't write to the file, give up before we hurt ourselves */
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
971 if(!data->file)
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
972 return;
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
973
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
974 date = log_get_timestamp(log, time);
12692
4da7062a06c2 [gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents: 12574
diff changeset
975
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
976 gaim_markup_html_to_xhtml(message, &xhtml, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
977 if (from)
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
978 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n",
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
979 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
980 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
981 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
982 from, date, xhtml);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
983 else
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
984 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n",
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
985 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
986 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
987 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
988 date, xhtml):
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
989 fflush(log->logger_data);
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
990 g_free(date);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
991 g_free(xhtml);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
992 }
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
993
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
994 static void xml_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
995 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
996 if (log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
997 fprintf(log->logger_data, "</conversation>\n");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
998 fclose(log->logger_data);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
999 log->logger_data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1000 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1001 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
1002
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1003 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1004 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1005 return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1006 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1007
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1008 static GaimLogLogger xml_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1009 N_("XML"), "xml",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1010 NULL,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1011 xml_logger_write,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1012 xml_logger_finalize,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1013 xml_logger_list,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1014 NULL,
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1015 NULL,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1016 NULL
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1017 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1018 #endif
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents: 5560
diff changeset
1019
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1020 /****************************
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1021 ** HTML LOGGER *************
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1022 ****************************/
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1023
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1024 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1025 const char *from, time_t time, const char *message)
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1026 {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1027 char *msg_fixed;
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1028 char *date;
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
1029 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1030 GaimLogCommonLoggerData *data = log->logger_data;
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1031 gsize written = 0;
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
1032
7618
53e38b1ce00a [gaim-migrate @ 8242]
Nathan Walp <nwalp@pidgin.im>
parents: 7616
diff changeset
1033 if(!data) {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1034 const char *prpl =
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1035 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
1036 const char *date;
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
1037 gaim_log_common_writer(log, ".html");
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1038
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1039 data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1040
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1041 /* if we can't write to the file, give up before we hurt ourselves */
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1042 if(!data->file)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1043 return 0;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1044
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
1045 date = gaim_date_format_full(localtime(&log->time));
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
1046
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1047 written += fprintf(data->file, "<html><head>");
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1048 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1049 written += fprintf(data->file, "<title>");
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1050 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)",
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
1051 log->name, date, gaim_account_get_username(log->account), prpl);
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1052 written += fprintf(data->file, "</title></head><body>");
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1053 written += fprintf(data->file,
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1054 "<h3>Conversation with %s at %s on %s (%s)</h3>\n",
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
1055 log->name, date, gaim_account_get_username(log->account), prpl);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1056 }
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
1057
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
1058 /* if we can't write to the file, give up before we hurt ourselves */
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
1059 if(!data->file)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1060 return 0;
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
1061
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
1062 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL);
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1063 date = log_get_timestamp(log, time);
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
1064
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1065 if(log->type == GAIM_LOG_SYSTEM){
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1066 written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1067 } else {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1068 if (type & GAIM_MESSAGE_SYSTEM)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1069 written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed);
13069
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1070 else if (type & GAIM_MESSAGE_ERROR)
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1071 written += fprintf(data->file, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1072 else if (type & GAIM_MESSAGE_WHISPER)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1073 written += fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n",
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1074 date, from, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1075 else if (type & GAIM_MESSAGE_AUTO_RESP) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1076 if (type & GAIM_MESSAGE_SEND)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1077 written += fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s &lt;AUTO-REPLY&gt;:</b></font> %s<br/>\n"), date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1078 else if (type & GAIM_MESSAGE_RECV)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1079 written += fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s &lt;AUTO-REPLY&gt;:</b></font> %s<br/>\n"), date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1080 } else if (type & GAIM_MESSAGE_RECV) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1081 if(gaim_message_meify(msg_fixed, -1))
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1082 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
1083 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1084 else
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1085 written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
1086 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1087 } else if (type & GAIM_MESSAGE_SEND) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1088 if(gaim_message_meify(msg_fixed, -1))
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1089 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
1090 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1091 else
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1092 written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
1093 date, from, msg_fixed);
13069
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1094 } else {
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1095 gaim_debug_error("log", "Unhandled message type.");
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1096 written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n",
42c62476b61b [gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents: 13068
diff changeset
1097 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
1098 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
1099 }
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1100 g_free(date);
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
1101 g_free(msg_fixed);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1102 fflush(data->file);
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1103
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1104 return written;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1105 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1106
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1107 static void html_logger_finalize(GaimLog *log)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1108 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1109 GaimLogCommonLoggerData *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1110 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1111 if(data->file) {
12881
7e45ccd91e58 [gaim-migrate @ 15233]
Richard Laager <rlaager@wiktel.com>
parents: 12834
diff changeset
1112 fprintf(data->file, "</body></html>\n");
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1113 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1114 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1115 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
1116 g_free(data);
7463
f2d82df37252 [gaim-migrate @ 8076]
Nathan Walp <nwalp@pidgin.im>
parents: 7462
diff changeset
1117 }
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1118 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1119
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1120 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1121 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1122 return gaim_log_common_lister(type, sn, account, ".html", html_logger);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1123 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1124
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1125 static GList *html_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1126 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1127 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", html_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1128 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1129
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1130 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1131 {
12958
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1132 char *read;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1133 GaimLogCommonLoggerData *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1134 *flags = GAIM_LOG_READ_NO_NEWLINE;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1135 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1136 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>"));
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1137 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
12958
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1138 char *minus_header = strchr(read, '\n');
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1139
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1140 if (!minus_header)
12958
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1141 return read;
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1142
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1143 minus_header = g_strdup(minus_header + 1);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1144 g_free(read);
12958
6910db1ae6a1 [gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents: 12881
diff changeset
1145
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1146 return minus_header;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1147 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1148 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1149 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1150
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1151 static int html_logger_total_size(GaimLogType type, const char *name, GaimAccount *account)
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1152 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1153 return gaim_log_common_total_sizer(type, name, account, ".html");
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1154 }
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1155
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1156
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1157 /****************************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1158 ** PLAIN TEXT LOGGER *******
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1159 ****************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1160
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1161 static gsize txt_logger_write(GaimLog *log,
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1162 GaimMessageFlags type,
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1163 const char *from, time_t time, const char *message)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1164 {
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1165 char *date;
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1166 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1167 GaimLogCommonLoggerData *data = log->logger_data;
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1168 char *stripped = NULL;
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1169
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1170 gsize written = 0;
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1171
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1172 if (data == NULL) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1173 /* This log is new. We could use the loggers 'new' function, but
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1174 * creating a new file there would result in empty files in the case
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1175 * that you open a convo with someone, but don't say anything.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1176 */
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1177 const char *prpl =
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1178 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
11292
ef9280fdc511 [gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
1179 gaim_log_common_writer(log, ".txt");
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1180
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1181 data = log->logger_data;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1182
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1183 /* if we can't write to the file, give up before we hurt ourselves */
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
1184 if(!data->file)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1185 return 0;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1186
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1187 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n",
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
1188 log->name, gaim_date_format_full(localtime(&log->time)),
13104
e1e5462b7d81 [gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents: 13077
diff changeset
1189 gaim_account_get_username(log->account), prpl);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1190 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1191
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
1192 /* if we can't write to the file, give up before we hurt ourselves */
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
1193 if(!data->file)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1194 return 0;
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
1195
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1196 stripped = gaim_markup_strip_html(message);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1197 date = log_get_timestamp(log, time);
12692
4da7062a06c2 [gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents: 12574
diff changeset
1198
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1199 if(log->type == GAIM_LOG_SYSTEM){
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1200 written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date);
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1201 } else {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1202 if (type & GAIM_MESSAGE_SEND ||
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1203 type & GAIM_MESSAGE_RECV) {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1204 if (type & GAIM_MESSAGE_AUTO_RESP) {
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1205 written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date,
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1206 from, stripped);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1207 } else {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1208 if(gaim_message_meify(stripped, -1))
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1209 written += fprintf(data->file, "(%s) ***%s %s\n", date, from,
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1210 stripped);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1211 else
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1212 written += fprintf(data->file, "(%s) %s: %s\n", date, from,
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1213 stripped);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1214 }
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1215 } else if (type & GAIM_MESSAGE_SYSTEM)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1216 written += fprintf(data->file, "(%s) %s\n", date, stripped);
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1217 else if (type & GAIM_MESSAGE_NO_LOG) {
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1218 /* This shouldn't happen */
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1219 g_free(stripped);
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1220 return written;
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1221 } else if (type & GAIM_MESSAGE_WHISPER)
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1222 written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped);
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1223 else
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1224 written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "",
12737
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1225 from ? ":" : "", stripped);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1226 }
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1227 g_free(date);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1228 g_free(stripped);
a1e241dd50b6 [gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents: 12692
diff changeset
1229 fflush(data->file);
13059
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1230
1b71ad2eccdb [gaim-migrate @ 15421]
Nathan Walp <nwalp@pidgin.im>
parents: 12969
diff changeset
1231 return written;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1232 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1233
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1234 static void txt_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1235 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1236 GaimLogCommonLoggerData *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1237 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1238 if(data->file)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1239 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1240 if(data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1241 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
1242 g_free(data);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1243 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1244 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1245
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1246 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1247 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1248 return gaim_log_common_lister(type, sn, account, ".txt", txt_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1249 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1250
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1251 static GList *txt_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1252 {
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1253 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", txt_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1254 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1255
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1256 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1257 {
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
1258 char *read, *minus_header, *minus_header2;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1259 GaimLogCommonLoggerData *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1260 *flags = 0;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1261 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1262 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>"));
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1263 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1264 minus_header = strchr(read, '\n');
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1265 if (!minus_header)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1266 minus_header = g_strdup(read);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1267 else
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1268 minus_header = g_strdup(minus_header + 1);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1269 g_free(read);
10732
c4cb90065e1d [gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents: 10645
diff changeset
1270 minus_header2 = g_markup_escape_text(minus_header, -1);
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
1271 g_free(minus_header);
13357
af03d3b20cd2 [gaim-migrate @ 15730]
Richard Laager <rlaager@wiktel.com>
parents: 13333
diff changeset
1272 read = gaim_markup_linkify(minus_header2);
af03d3b20cd2 [gaim-migrate @ 15730]
Richard Laager <rlaager@wiktel.com>
parents: 13333
diff changeset
1273 g_free(minus_header2);
af03d3b20cd2 [gaim-migrate @ 15730]
Richard Laager <rlaager@wiktel.com>
parents: 13333
diff changeset
1274 return read;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1275 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1276 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1277 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1278
13388
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1279 static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account)
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1280 {
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1281 return gaim_log_common_total_sizer(type, name, account, ".txt");
0a8b72b12cef [gaim-migrate @ 15761]
Richard Laager <rlaager@wiktel.com>
parents: 13357
diff changeset
1282 }
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1283
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1284
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1285 /****************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1286 * OLD LOGGER ***
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1287 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1288
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1289 /* The old logger doesn't write logs, only reads them. This is to include
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1290 * old logs in the log viewer transparently.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1291 */
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1292
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1293 struct old_logger_data {
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1294 GaimStringref *pathref;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1295 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1296 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1297 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1298
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1299 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1300 {
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1301 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn));
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1302 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1303 GaimStringref *pathref = gaim_stringref_new(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1304 struct stat st;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1305 time_t log_last_modified;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1306 FILE *index;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1307 FILE *file;
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1308 GError *error;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1309 int index_fd;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1310 char *index_tmp;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1311 char buf[BUF_LONG];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1312 struct tm tm;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1313 char month[4];
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1314 struct old_logger_data *data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1315 char *newlog;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1316 int logfound = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1317 int lastoff = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1318 int newlen;
7791
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7770
diff changeset
1319 time_t lasttime = 0;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1320
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1321 GaimLog *log = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1322 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1323
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
1324 g_free(logfile);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1325
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1326 if (g_stat(gaim_stringref_value(pathref), &st))
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1327 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1328 gaim_stringref_unref(pathref);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1329 g_free(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1330 return NULL;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1331 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1332 else
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1333 log_last_modified = st.st_mtime;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1334
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1335 /* Change the .log extension to .idx */
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1336 strcpy(pathstr + strlen(pathstr) - 3, "idx");
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1337
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1338 if (g_stat(pathstr, &st) == 0)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1339 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1340 if (st.st_mtime < log_last_modified)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1341 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1342 gaim_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1343 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1344 else
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1345 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1346 /* The index file exists and is at least as new as the log, so open it. */
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1347 if (!(index = g_fopen(pathstr, "rb")))
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1348 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1349 gaim_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n",
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1350 pathstr, strerror(errno));
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1351
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1352 /* Fall through so that we'll parse the log file. */
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1353 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1354 else
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1355 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1356 gaim_debug_info("log", "Using index: %s\n", pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1357 g_free(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1358 while (fgets(buf, BUF_LONG, index))
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1359 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1360 unsigned long idx_time;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1361 if (sscanf(buf, "%d\t%d\t%lu", &lastoff, &newlen, &idx_time) == 3)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1362 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1363 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1364 log->logger = old_logger;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1365 log->time = (time_t)idx_time;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1366 data = g_new0(struct old_logger_data, 1);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1367 data->offset = lastoff;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1368 data->length = newlen;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1369 data->pathref = gaim_stringref_ref(pathref);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1370 log->logger_data = data;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1371 list = g_list_prepend(list, log);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1372 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1373 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1374
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1375 return list;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1376 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1377 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1378 }
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
1379
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1380 if (!(file = g_fopen(gaim_stringref_value(pathref), "rb"))) {
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1381 gaim_debug_error("log", "Failed to open log file \"%s\" for reading: %s\n",
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1382 gaim_stringref_value(pathref), strerror(errno));
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1383 gaim_stringref_unref(pathref);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1384 g_free(pathstr);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1385 return NULL;
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
1386 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1387
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1388 if ((index_fd = g_file_open_tmp(NULL, &index_tmp, &error)) == -1) {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1389 gaim_debug_error("log", "Failed to open index temp file: %s\n",
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1390 error->message);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1391 g_error_free(error);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1392 g_free(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1393 index = NULL;
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1394 } else {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1395 if ((index = fdopen(index_fd, "wb")) == NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1396 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1397 gaim_debug_error("log", "Failed to fdopen() index temp file: %s\n",
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1398 strerror(errno));
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1399 close(index_fd);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1400 if (index_tmp != NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1401 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1402 g_unlink(index_tmp);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1403 g_free(index_tmp);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1404 }
13411
0d223f4ee868 [gaim-migrate @ 15786]
Richard Laager <rlaager@wiktel.com>
parents: 13406
diff changeset
1405 g_free(pathstr);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1406 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1407 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1408
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1409 while (fgets(buf, BUF_LONG, file)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1410 if ((newlog = strstr(buf, "---- New C"))) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1411 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1412 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1413 char convostart[32];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1414 char *temp = strchr(buf, '@');
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1415
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1416 if (temp == NULL || strlen(temp) < 2)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1417 continue;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1418
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1419 temp++;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1420 length = strcspn(temp, "-");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1421 if (length > 31) length = 31;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1422
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1423 offset = ftell(file);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1424
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1425 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1426 newlen = offset - lastoff - length;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1427 if(strstr(buf, "----</H3><BR>")) {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1428 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1429 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") +
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1430 sizeof("----</H3><BR>") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1431 } else {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1432 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1433 sizeof("---- New Conversation @ ") + sizeof("----") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1434 }
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1435
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
1436 if(strchr(buf, '\r'))
7770
41bcf3f62563 [gaim-migrate @ 8415]
Ethan Blanton <elb@pidgin.im>
parents: 7764
diff changeset
1437 newlen--;
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
1438
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1439 if (newlen != 0) {
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
1440 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1441 log->logger = old_logger;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1442 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1443 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1444 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1445 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1446 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1447 log->logger_data = data;
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
1448 list = g_list_prepend(list, log);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1449
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1450 /* XXX: There is apparently Is there a proper way to print a time_t? */
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1451 if (index != NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1452 fprintf(index, "%d\t%d\t%lu\n", data->offset, data->length, (unsigned long)log->time);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1453 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1454 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1455
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1456 logfound = 1;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1457 lastoff = offset;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1458
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1459 g_snprintf(convostart, length, "%s", temp);
7676
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1460 sscanf(convostart, "%*s %s %d %d:%d:%d %d",
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1461 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year);
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1462 /* Ugly hack, in case current locale is not English */
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1463 if (strcmp(month, "Jan") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1464 tm.tm_mon= 0;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1465 } else if (strcmp(month, "Feb") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1466 tm.tm_mon = 1;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1467 } else if (strcmp(month, "Mar") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1468 tm.tm_mon = 2;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1469 } else if (strcmp(month, "Apr") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1470 tm.tm_mon = 3;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1471 } else if (strcmp(month, "May") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1472 tm.tm_mon = 4;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1473 } else if (strcmp(month, "Jun") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1474 tm.tm_mon = 5;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1475 } else if (strcmp(month, "Jul") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1476 tm.tm_mon = 6;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1477 } else if (strcmp(month, "Aug") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1478 tm.tm_mon = 7;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1479 } else if (strcmp(month, "Sep") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1480 tm.tm_mon = 8;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1481 } else if (strcmp(month, "Oct") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1482 tm.tm_mon = 9;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1483 } else if (strcmp(month, "Nov") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1484 tm.tm_mon = 10;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1485 } else if (strcmp(month, "Dec") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1486 tm.tm_mon = 11;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1487 }
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1488 tm.tm_year -= 1900;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1489 lasttime = mktime(&tm);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1490 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1491 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1492
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1493 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1494 if ((newlen = ftell(file) - lastoff) != 0) {
13119
fcde3faa1f57 [gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents: 13106
diff changeset
1495 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
11503
cd0c8830d881 [gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents: 11458
diff changeset
1496 log->logger = old_logger;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1497 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1498 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1499 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1500 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1501 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1502 log->logger_data = data;
11703
a53cef8bd22b [gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents: 11698
diff changeset
1503 list = g_list_prepend(list, log);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1504
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1505 /* XXX: Is there a proper way to print a time_t? */
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1506 if (index != NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1507 fprintf(index, "%d\t%d\t%d\n", data->offset, data->length, (int)log->time);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1508 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1509 }
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1510
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1511 gaim_stringref_unref(pathref);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1512 fclose(file);
13406
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1513 if (index != NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1514 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1515 fclose(index);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1516
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1517 if (index_tmp == NULL)
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1518 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1519 g_free(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1520 g_return_val_if_reached(list);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1521 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1522
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1523 if (g_rename(index_tmp, pathstr))
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1524 {
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1525 gaim_debug_warning("log", "Failed to rename index temp file \"%s\" to \"%s\": %s\n",
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1526 index_tmp, pathstr, strerror(errno));
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1527 g_unlink(index_tmp);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1528 g_free(index_tmp);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1529 }
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1530 else
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1531 gaim_debug_info("log", "Built index: %s\n", pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1532
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1533 g_free(pathstr);
3033597a4059 [gaim-migrate @ 15781]
Richard Laager <rlaager@wiktel.com>
parents: 13388
diff changeset
1534 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1535 return list;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1536 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1537
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1538 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account)
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1539 {
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1540 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name));
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1541 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1542 int size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1543 struct stat st;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1544
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1545 if (g_stat(pathstr, &st))
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1546 size = 0;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1547 else
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1548 size = st.st_size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1549
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1550 g_free(logfile);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1551 g_free(pathstr);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1552
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1553 return size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1554 }
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1555
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1556 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags)
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1557 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1558 struct old_logger_data *data = log->logger_data;
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1559 FILE *file = g_fopen(gaim_stringref_value(data->pathref), "rb");
10906
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1560 char *tmp, *read = g_malloc(data->length + 1);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1561 fseek(file, data->offset, SEEK_SET);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1562 fread(read, data->length, 1, file);
8370
2279bfa6aa59 [gaim-migrate @ 9097]
Mark Doliner <mark@kingant.net>
parents: 8111
diff changeset
1563 fclose(file);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1564 read[data->length] = '\0';
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1565 *flags = 0;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1566 if(strstr(read, "<BR>"))
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1567 *flags |= GAIM_LOG_READ_NO_NEWLINE;
10906
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1568 else {
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1569 tmp = g_markup_escape_text(read, -1);
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1570 g_free(read);
13357
af03d3b20cd2 [gaim-migrate @ 15730]
Richard Laager <rlaager@wiktel.com>
parents: 13333
diff changeset
1571 read = gaim_markup_linkify(tmp);
af03d3b20cd2 [gaim-migrate @ 15730]
Richard Laager <rlaager@wiktel.com>
parents: 13333
diff changeset
1572 g_free(tmp);
10906
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1573 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1574 return read;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1575 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1576
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1577 static int old_logger_size (GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1578 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1579 struct old_logger_data *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1580 return data ? data->length : 0;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1581 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1582
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
1583 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets)
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1584 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1585 char *log_path = g_build_filename(gaim_user_dir(), "logs", NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1586 GDir *log_dir = g_dir_open(log_path, 0, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1587 gchar *name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1588 GaimBlistNode *gnode, *cnode, *bnode;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1589
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1590 g_free(log_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1591 if (log_dir == NULL)
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
1592 return;
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1593
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1594 /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1595 while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1596 size_t len;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1597 gchar *ext;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1598 GaimLogSet *set;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1599 gboolean found = FALSE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1600
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1601 /* Unescape the filename. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1602 name = g_strdup(gaim_unescape_filename(name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1603
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1604 /* Get the (possibly new) length of name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1605 len = strlen(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1606
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1607 if (len < 5) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1608 g_free(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1609 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1610 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1611
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1612 /* Make sure we're dealing with a log file. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1613 ext = &name[len - 4];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1614 if (strcmp(ext, ".log")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1615 g_free(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1616 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1617 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1618
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1619 set = g_new0(GaimLogSet, 1);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1620
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1621 /* Chat for .chat at the end of the name to determine the type. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1622 *ext = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1623 set->type = GAIM_LOG_IM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1624 if (len > 9) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1625 char *tmp = &name[len - 9];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1626 if (!strcmp(tmp, ".chat")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1627 set->type = GAIM_LOG_CHAT;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1628 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1629 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1630 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1631
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
1632 set->name = set->normalized_name = name;
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1633
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1634 /* Search the buddy list to find the account and to determine if this is a buddy. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1635 for (gnode = gaim_get_blist()->root; !found && gnode != NULL; gnode = gnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1636 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1637 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1638 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1639
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1640 for (cnode = gnode->child; !found && cnode != NULL; cnode = cnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1641 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1642 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1643 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1644
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1645 for (bnode = cnode->child; !found && bnode != NULL; bnode = bnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1646 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1647 GaimBuddy *buddy = (GaimBuddy *)bnode;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1648
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1649 if (!strcmp(buddy->name, name)) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1650 set->account = buddy->account;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1651 set->buddy = TRUE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1652 found = TRUE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1653 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1654 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1655 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1656 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1657
11177
3924db2b1ca8 [gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents: 11094
diff changeset
1658 cb(sets, set);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1659 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1660 g_dir_close(log_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1661 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1662
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1663 static void old_logger_finalize(GaimLog *log)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1664 {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1665 struct old_logger_data *data = log->logger_data;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1666 gaim_stringref_unref(data->pathref);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1667 g_free(data);
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1668 }