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