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