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