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