annotate src/log.c @ 9651:8ce2dc65e591

[gaim-migrate @ 10499] updates from Mike Stoddard of Novell committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 03 Aug 2004 23:22:48 +0000
parents 1b13160bf5a4
children 70ff55c0939b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1 /**
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
2 * @file log.c Logging API
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
3 * @ingroup core
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
4 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
5 * gaim
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8027
diff changeset
9 * source distribution.
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
10 *
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
11 * This program is free software; you can redistribute it and/or modify
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
12 * it under the terms of the GNU General Public License as published by
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
14 * (at your option) any later version.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
15 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
16 * This program is distributed in the hope that it will be useful,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
19 * GNU General Public License for more details.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
20 *
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
21 * You should have received a copy of the GNU General Public License
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
22 * along with this program; if not, write to the Free Software
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
4195
4a0837c49d85 [gaim-migrate @ 4426]
Luke Schierer <lschiere@pidgin.im>
parents: 4192
diff changeset
25
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
26 #include "account.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
27 #include "debug.h"
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
28 #include "internal.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
29 #include "log.h"
5548
80e4ba770f97 [gaim-migrate @ 5949]
Nathan Walp <nwalp@pidgin.im>
parents: 5528
diff changeset
30 #include "prefs.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
31 #include "util.h"
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
32 #include "stringref.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
33
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
34 static GSList *loggers = NULL;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
35
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
36 static GaimLogLogger html_logger;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
37 static GaimLogLogger txt_logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
38 static GaimLogLogger old_logger;
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5839
diff changeset
39
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
40 struct _gaim_logsize_user {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
41 char *name;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
42 GaimAccount *account;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
43 };
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
44 static GHashTable *logsize_users = NULL;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
45
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
46
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
47 /**************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
48 * PUBLIC LOGGING FUNCTIONS ***********************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
49 **************************************************************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
51 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
52 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
53 GaimLog *log = g_new0(GaimLog, 1);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
54 log->name = g_strdup(gaim_normalize(account, name));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
55 log->account = account;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
56 log->time = time;
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
57 log->type = type;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
58 log->logger_data = NULL;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
59 log->logger = gaim_log_logger_get();
7440
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
60 if (log->logger && log->logger->create)
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
61 log->logger->create(log);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
62 return log;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
65 void gaim_log_free(GaimLog *log)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
67 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
68 if (log->logger && log->logger->finalize)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
69 log->logger->finalize(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
70 g_free(log->name);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
71 g_free(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
72 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
73
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
74 void gaim_log_write(GaimLog *log, GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
75 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
76 {
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
77 struct _gaim_logsize_user lu;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
78
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
79 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
80 g_return_if_fail(log->logger);
7442
d42289ecf0ce [gaim-migrate @ 8047]
Nathan Walp <nwalp@pidgin.im>
parents: 7441
diff changeset
81 g_return_if_fail(log->logger->write);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
82
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
83 if ((log->type == GAIM_LOG_IM &&
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
84 gaim_prefs_get_bool("/core/logging/log_ims")) ||
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
85 (log->type == GAIM_LOG_CHAT &&
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
86 gaim_prefs_get_bool("/core/logging/log_chats")) ||
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
87 (log->type == GAIM_LOG_SYSTEM &&
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
88 gaim_prefs_get_bool("/core/logging/log_system"))) {
7553
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
89 (log->logger->write)(log, type, from, time, message);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
90 lu.name = g_strdup(gaim_normalize(log->account, log->name));
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
91 lu.account = log->account;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
92 g_hash_table_remove(logsize_users, &lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
93 g_free(lu.name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
94 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
97 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 {
7542
ebccd555323b [gaim-migrate @ 8156]
Nathan Walp <nwalp@pidgin.im>
parents: 7541
diff changeset
99 GaimLogReadFlags mflags;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
100 g_return_val_if_fail(log && log->logger, NULL);
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
101 if (log->logger->read) {
7535
f771759739c1 [gaim-migrate @ 8148]
Sean Egan <seanegan@gmail.com>
parents: 7501
diff changeset
102 char *ret = (log->logger->read)(log, flags ? flags : &mflags);
7478
3c21f3084ff0 [gaim-migrate @ 8091]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7473
diff changeset
103 gaim_str_strip_cr(ret);
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
104 return ret;
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
105 }
7470
ad6435eccf2b [gaim-migrate @ 8083]
Mark Doliner <mark@kingant.net>
parents: 7463
diff changeset
106 return (_("<b><font color=\"red\">The logger has no read function</font></b>"));
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 }
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
108
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
109 int gaim_log_get_size(GaimLog *log)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
110 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
111 g_return_val_if_fail(log && log->logger, 0);
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
112
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
113 if (log->logger->size)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
114 return log->logger->size(log);
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
115 return 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
116 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
117
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
118 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
119 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
120 return g_str_hash(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
121 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
122
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
123 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
124 struct _gaim_logsize_user *lu2)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
125 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
126 return ((!strcmp(lu1->name, lu2->name)) && lu1->account == lu2->account);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
127 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
128
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
129 static void _gaim_logsize_user_free_key(struct _gaim_logsize_user *lu)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
130 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
131 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
132 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
133 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
134
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
135 int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
136 {
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
137 int size;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
138 GSList *n;
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
139 struct _gaim_logsize_user *lu;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
140
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
141 lu = g_new(struct _gaim_logsize_user, 1);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
142 lu->name = g_strdup(gaim_normalize(account, name));
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
143 lu->account = account;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
144
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
145 if((size = GPOINTER_TO_INT(g_hash_table_lookup(logsize_users, lu)))) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
146 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
147 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
148 } else {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
149 for (n = loggers; n; n = n->next) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
150 GaimLogLogger *logger = n->data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
151
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
152 if(logger->total_size){
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
153 size += (logger->total_size)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
154 } else if(logger->list) {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
155 GList *logs = (logger->list)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
156 int this_size = 0;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
157
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
158 while (logs) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
159 GList *logs2 = logs->next;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
160 GaimLog *log = (GaimLog*)(logs->data);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
161 this_size += gaim_log_get_size(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
162 gaim_log_free(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
163 g_list_free_1(logs);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
164 logs = logs2;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
165 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
166
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
167 size += this_size;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
168 }
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
169 }
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
170
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
171 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size));
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
172 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
173 return size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
174 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
176 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
177 * LOGGER FUNCTIONS *********************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
178 ****************************************************************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
180 static GaimLogLogger *current_logger = NULL;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
181
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
182 static void logger_pref_cb(const char *name, GaimPrefType type,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
183 gpointer value, gpointer data)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
184 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
185 GaimLogLogger *logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
186 GSList *l = loggers;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
187 while (l) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
188 logger = l->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
189 if (!strcmp(logger->id, value)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
190 gaim_log_logger_set(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
191 return;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
193 l = l->next;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
194 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
195 gaim_log_logger_set(&txt_logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
196 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
199 GaimLogLogger *gaim_log_logger_new(
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
200 void(*create)(GaimLog *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
201 void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
202 void(*finalize)(GaimLog *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
203 GList*(*list)(GaimLogType type, const char*, GaimAccount*),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
204 char*(*read)(GaimLog*, GaimLogReadFlags*),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
205 int(*size)(GaimLog*))
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
206 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
207 GaimLogLogger *logger = g_new0(GaimLogLogger, 1);
7440
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
208 logger->create = create;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
209 logger->write = write;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
210 logger->finalize = finalize;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
211 logger->list = list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
212 logger->read = read;
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
213 logger->size = size;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
214 return logger;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
215 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
216
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
217 void gaim_log_logger_free(GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
218 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
219 g_free(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
220 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
222 void gaim_log_logger_add (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
223 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
224 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
225 if (g_slist_find(loggers, logger))
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
226 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
227 loggers = g_slist_append(loggers, logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
228 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
229
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
230 void gaim_log_logger_remove (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
231 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
232 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
233 g_slist_remove(loggers, logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
234 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
236 void gaim_log_logger_set (GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
238 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
239 current_logger = logger;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
240 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
242 GaimLogLogger *gaim_log_logger_get()
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
243 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
244 return current_logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
245 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
247 GList *gaim_log_logger_get_options(void)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
248 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
249 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
250 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
251 GaimLogLogger *data;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
252
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
253 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
254 data = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
255 if (!data->write)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
256 continue;
7494
86fe50e88bcd [gaim-migrate @ 8107]
Nathan Walp <nwalp@pidgin.im>
parents: 7491
diff changeset
257 list = g_list_append(list, _(data->name));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
258 list = g_list_append(list, data->id);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
261 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
262 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
263
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
264 gint gaim_log_compare(gconstpointer y, gconstpointer z)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
265 {
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
266 const GaimLog *a = y;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
267 const GaimLog *b = z;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
268
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
269 return b->time - a->time;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
270 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
271
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
272 GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
273 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
274 GList *logs = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
275 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
276 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
277 GaimLogLogger *logger = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
278 if (!logger->list)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
279 continue;
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
280 logs = g_list_concat(logs, logger->list(type, name, account));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
281 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
282
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
283 return g_list_sort(logs, gaim_log_compare);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
284 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
285
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
286 GList *gaim_log_get_system_logs(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
287 {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
288 GList *logs = NULL;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
289 GSList *n;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
290 for (n = loggers; n; n = n->next) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
291 GaimLogLogger *logger = n->data;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
292 if (!logger->list_syslog)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
293 continue;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
294 logs = g_list_concat(logs, logger->list_syslog(account));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
295 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
296
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
297 return g_list_sort(logs, gaim_log_compare);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
298 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
299
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
300 void gaim_log_init(void)
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
301 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
302 gaim_prefs_add_none("/core/logging");
7555
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
303 gaim_prefs_add_bool("/core/logging/log_ims", FALSE);
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
304 gaim_prefs_add_bool("/core/logging/log_chats", FALSE);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
305 gaim_prefs_add_bool("/core/logging/log_system", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
306 gaim_prefs_add_bool("/core/logging/log_signon_signoff", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
307 gaim_prefs_add_bool("/core/logging/log_idle_state", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
308 gaim_prefs_add_bool("/core/logging/log_away_state", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
309 gaim_prefs_add_bool("/core/logging/log_own_states", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
310
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
311 gaim_prefs_add_string("/core/logging/format", "txt");
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
312 gaim_log_logger_add(&html_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
313 gaim_log_logger_add(&txt_logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
314 gaim_log_logger_add(&old_logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
315 gaim_prefs_connect_callback("/core/logging/format",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
316 logger_pref_cb, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
317 gaim_prefs_trigger_callback("/core/logging/format");
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
318
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
319 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
320 (GEqualFunc)_gaim_logsize_user_equal,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
321 (GDestroyNotify)_gaim_logsize_user_free_key, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
322 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
323
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
324 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
325 * LOGGERS ******************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
326 ****************************************************************************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
327
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
328 struct generic_logger_data {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
329 char *path;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
330 FILE *file;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
331 };
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
332
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
333 static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
334 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
335 GDir *dir;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
336 GList *list = NULL;
7628
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7623
diff changeset
337 const char *filename;
8111
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
338 char *me;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
339 const char *prpl;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
340 char *path;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
341
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
342 if(!account)
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
343 return NULL;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
344
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
345 if (type == GAIM_LOG_CHAT)
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
346 me = g_strdup_printf("%s.chat", gaim_normalize(account, gaim_account_get_username(account)));
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
347 else
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
348 me = g_strdup(gaim_normalize(account, gaim_account_get_username(account)));
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7882
diff changeset
350 /* does this seem like a bad way to get this component of the path to anyone else? --Nathan */
8111
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
351 prpl = GAIM_PLUGIN_PROTOCOL_INFO
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7882
diff changeset
352 (gaim_find_prpl(gaim_account_get_protocol_id(account)))->list_icon(account, NULL);
9500
db95a6641ec1 [gaim-migrate @ 10327]
Luke Schierer <lschiere@pidgin.im>
parents: 8898
diff changeset
353 if(type == GAIM_LOG_SYSTEM)
db95a6641ec1 [gaim-migrate @ 10327]
Luke Schierer <lschiere@pidgin.im>
parents: 8898
diff changeset
354 path = g_build_filename(gaim_user_dir(),"logs", prpl, me, name, NULL);
db95a6641ec1 [gaim-migrate @ 10327]
Luke Schierer <lschiere@pidgin.im>
parents: 8898
diff changeset
355 else
db95a6641ec1 [gaim-migrate @ 10327]
Luke Schierer <lschiere@pidgin.im>
parents: 8898
diff changeset
356 path = g_build_filename(gaim_user_dir(),"logs", prpl, me, gaim_normalize(account, name), NULL);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
357 g_free(me);
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
358
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
359 if (!(dir = g_dir_open(path, 0, NULL))) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
360 g_free(path);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
361 return NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
362 }
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
363
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
364 while ((filename = g_dir_read_name(dir))) {
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
365 if (gaim_str_has_suffix(filename, ext) &&
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
366 strlen(filename) == 17 + strlen(ext)) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
367 GaimLog *log;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
368 struct generic_logger_data *data;
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
369 time_t stamp = gaim_str_to_time(filename, FALSE);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
370
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
371 log = gaim_log_new(type, name, account, stamp);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
372 log->logger = logger;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
373 log->logger_data = data = g_new0(struct generic_logger_data, 1);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
374 data->path = g_build_filename(path, filename, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
375 list = g_list_append(list, log);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
376 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
377 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
378 g_dir_close(dir);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
379 g_free(path);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
380 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
381 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
382
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
383 /* Only to be used with logs listed from log_lister_common */
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
384 int log_sizer_common(GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
385 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
386 struct stat st;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
387 struct generic_logger_data *data = log->logger_data;
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
388
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
389 if (!data->path || stat(data->path, &st))
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
390 st.st_size = 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
391
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
392 return st.st_size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
393 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
394
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
395 #if 0 /* Maybe some other time. */
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
396 /****************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
397 ** XML LOGGER **
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
398 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
399
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
400 static const char *str_from_msg_type (GaimMessageFlags type)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
401 {
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
402
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
403 return "";
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
404
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
405 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
406
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
407 static void xml_logger_write(GaimLog *log,
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
408 GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
409 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
410 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
411 char date[64];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
412 char *xhtml = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
413 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
414 /* This log is new. We could use the loggers 'new' function, but
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
415 * creating a new file there would result in empty files in the case
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
416 * that you open a convo with someone, but don't say anything.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
417 */
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
418 char *ud = gaim_user_dir();
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
419 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account)));
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
420 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
421 (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
422 char *dir;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
423 FILE *file;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
424
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
425 if (log->type == GAIM_LOG_CHAT) {
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
426 char *chat = g_strdup_printf("%s.chat", guy);
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
427 g_free(guy);
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
428 guy = chat;
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
429 }
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
430
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
431 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time));
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
432
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
433 dir = g_build_filename(ud, "logs",
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
434 prpl, guy, gaim_normalize(log->account, log->name), NULL);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
435 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
436 g_free(guy);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
437
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
438 char *filename = g_build_filename(dir, date, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
439 g_free(dir);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
440
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
441 log->logger_data = fopen(filename, "a");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
442 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
443 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
444 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
445 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
446 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
447 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
448 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n"
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
449 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n");
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
450
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
451 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
452 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
453 date, log->name, prpl);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
454 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
455
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
456 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
457 gaim_markup_html_to_xhtml(message, &xhtml, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
458 if (from)
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
459 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n",
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
460 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
461 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
462 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
463 from, date, xhtml);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
464 else
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
465 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n",
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
466 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
467 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
468 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
469 date, xhtml):
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
470 fflush(log->logger_data);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
471 g_free(xhtml);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
472 }
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
473
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
474 static void xml_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
475 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
476 if (log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
477 fprintf(log->logger_data, "</conversation>\n");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
478 fclose(log->logger_data);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
479 log->logger_data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
480 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
481 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
482
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
483 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
484 {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
485 return log_lister_common(type, sn, account, ".xml", &xml_logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
486 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
487
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
488 static GaimLogLogger xml_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
489 N_("XML"), "xml",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
490 NULL,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
491 xml_logger_write,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
492 xml_logger_finalize,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
493 xml_logger_list,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
494 NULL,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
495 NULL
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
496 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
497 #endif
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents: 5560
diff changeset
498
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
499 /****************************
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
500 ** HTML LOGGER *************
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
501 ****************************/
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
502
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
503 static void html_logger_write(GaimLog *log, GaimMessageFlags type,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
504 const char *from, time_t time, const char *message)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
505 {
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
506 char date[64];
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
507 char *msg_fixed;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
508 struct generic_logger_data *data = log->logger_data;
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
509 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
510 const char *prpl_name = plugin->info->name;
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
511
7618
53e38b1ce00a [gaim-migrate @ 8242]
Nathan Walp <nwalp@pidgin.im>
parents: 7616
diff changeset
512 if(!data) {
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
513 /* This log is new */
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
514 char *ud = gaim_user_dir();
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
515 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account)));
7553
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
516 char *chat;
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
517 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
518 char *dir;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
519 char *filename;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
520
7553
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
521 if (log->type == GAIM_LOG_CHAT) {
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
522 chat = g_strdup_printf("%s.chat", guy);
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
523 g_free(guy);
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
524 guy = chat;
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
525 }
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
526
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
527 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time));
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
528
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
529 dir = g_build_filename(ud, "logs",
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
530 prpl, guy, gaim_normalize(log->account, log->name), NULL);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
531 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
532 g_free(guy);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
533
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
534 filename = g_build_filename(dir, date, NULL);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
535 g_free(dir);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
536
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
537 log->logger_data = data = g_new0(struct generic_logger_data, 1);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
538
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
539 data->file = fopen(filename, "a");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
540 if (!data->file) {
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
541 gaim_debug(GAIM_DEBUG_ERROR, "log",
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
542 "Could not create log file %s\n", filename);
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
543 g_free(filename);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
544 return;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
545 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
546 g_free(filename);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
547 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
548 fprintf(data->file, "<html><head><title>");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
549 fprintf(data->file, "Conversation with %s at %s on %s (%s)",
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
550 log->name, date, gaim_account_get_username(log->account), prpl);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
551 fprintf(data->file, "</title></head><body>");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
552 fprintf(data->file,
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
553 "<h3>Conversation with %s at %s on %s (%s)</h3>\n",
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
554 log->name, date, gaim_account_get_username(log->account), prpl);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
555 }
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
556
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
557 /* if we can't write to the file, give up before we hurt ourselves */
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
558 if(!data->file)
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
559 return;
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
560
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
561 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL);
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
562
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
563 if(log->type == GAIM_LOG_SYSTEM){
9592
9c78aaa4117e [gaim-migrate @ 10435]
Luke Schierer <lschiere@pidgin.im>
parents: 9500
diff changeset
564 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time));
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
565 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
566 } else {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
567 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
568 if (type & GAIM_MESSAGE_SYSTEM)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
569 fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
570 else if (type & GAIM_MESSAGE_WHISPER)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
571 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n",
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
572 date, from, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
573 else if (type & GAIM_MESSAGE_AUTO_RESP) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
574 if (type & GAIM_MESSAGE_SEND)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
575 fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s &lt;AUTO-REPLY&gt;:</b></font> %s<br/>\n"), date, from, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
576 else if (type & GAIM_MESSAGE_RECV)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
577 fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s &lt;AUTO-REPLY&gt;:</b></font> %s<br/>\n"), date, from, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
578 } else if (type & GAIM_MESSAGE_RECV) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
579 if(gaim_message_meify(msg_fixed, -1))
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
580 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n",
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
581 date, from, prpl_name, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
582 else
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
583 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n",
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
584 date, from, prpl_name, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
585 } else if (type & GAIM_MESSAGE_SEND) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
586 if(gaim_message_meify(msg_fixed, -1))
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
587 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n",
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
588 date, from, prpl_name, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
589 else
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
590 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n",
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
591 date, from, prpl_name, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
592 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
593 }
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
594
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
595 g_free(msg_fixed);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
596 fflush(data->file);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
597 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
598
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
599 static void html_logger_finalize(GaimLog *log)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
600 {
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
601 struct generic_logger_data *data = log->logger_data;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
602 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
603 if(data->file) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
604 fprintf(data->file, "</body></html>");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
605 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
606 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
607 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
608 g_free(data);
7463
f2d82df37252 [gaim-migrate @ 8076]
Nathan Walp <nwalp@pidgin.im>
parents: 7462
diff changeset
609 }
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
610 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
611
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
612 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
613 {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
614 return log_lister_common(type, sn, account, ".html", &html_logger);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
615 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
616
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
617 static GList *html_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
618 {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
619 return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".html", &html_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
620 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
621
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
622 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
623 {
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
624 char *read, *minus_header;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
625 struct generic_logger_data *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
626 *flags = GAIM_LOG_READ_NO_NEWLINE;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
627 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
628 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>"));
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
629 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
630 minus_header = strchr(read, '\n');
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
631 if (!minus_header)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
632 minus_header = g_strdup(read);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
633 else
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
634 minus_header = g_strdup(minus_header + 1);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
635 g_free(read);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
636 return minus_header;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
637 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
638 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
639 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
640
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
641 static void html_logger_create(GaimLog *log)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
642 {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
643 if(log->type == GAIM_LOG_SYSTEM){
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
644 char date[64];
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
645 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
646 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
647 char *ud = gaim_user_dir();
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
648 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
649 char *filename;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
650 struct generic_logger_data *data;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
651
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
652 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
653 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
654 filename = g_build_filename(dir, date, NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
655 g_free(dir);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
656
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
657 log->logger_data = data = g_new0(struct generic_logger_data, 1);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
658
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
659 data->file = fopen(filename, "a");
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
660 if (!data->file) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
661 gaim_debug(GAIM_DEBUG_ERROR, "log",
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
662 "Could not create log file %s\n", filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
663 g_free(filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
664 return;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
665 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
666 fprintf(data->file, "<html><head><title>");
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
667 fprintf(data->file, "System Log for %s (%s)",
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
668 gaim_account_get_username(log->account), prpl);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
669 fprintf(data->file, "</title></head><body>");
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
670 g_free(filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
671 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
672 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
673
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
674 static GaimLogLogger html_logger = {
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
675 N_("HTML"), "html",
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
676 html_logger_create,
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
677 html_logger_write,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
678 html_logger_finalize,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
679 html_logger_list,
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
680 html_logger_read,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
681 log_sizer_common,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
682 NULL,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
683 html_logger_list_syslog
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
684 };
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
685
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
686
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
687
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
688
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
689 /****************************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
690 ** PLAIN TEXT LOGGER *******
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
691 ****************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
692
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
693 static void txt_logger_write(GaimLog *log,
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
694 GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
695 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
696 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
697 char date[64];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
698 char *stripped = NULL;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
699 struct generic_logger_data *data = log->logger_data;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
700 if (!data) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
701 /* This log is new. We could use the loggers 'new' function, but
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
702 * creating a new file there would result in empty files in the case
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
703 * that you open a convo with someone, but don't say anything.
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
704 *
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
705 * The log is also not a system log. Because if it is, data would
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
706 * be created in txt_logger_create
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
707 */
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
708 char *ud = gaim_user_dir();
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
709 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account)));
7553
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
710 char *chat;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
711 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7882
diff changeset
712 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
713 char *dir;
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
714 char *filename;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
715
7553
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
716 if (log->type == GAIM_LOG_CHAT) {
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
717 chat = g_strdup_printf("%s.chat", guy);
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
718 g_free(guy);
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
719 guy = chat;
7d95978b07d9 [gaim-migrate @ 8167]
Sean Egan <seanegan@gmail.com>
parents: 7542
diff changeset
720 }
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
721
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
722 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time));
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
723
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
724 dir = g_build_filename(ud, "logs",
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
725 prpl, guy, gaim_normalize(log->account, log->name), NULL);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
726 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
727 g_free(guy);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
728
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
729 filename = g_build_filename(dir, date, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
730 g_free(dir);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
731
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
732 log->logger_data = data = g_new0(struct generic_logger_data, 1);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
733
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
734 data->file = fopen(filename, "a");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
735 if (!data->file) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
736 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
737 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
738 return;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
739 }
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
740 g_free(filename);
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
741 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
742 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n",
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
743 log->name, date, gaim_account_get_username(log->account), prpl);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
744 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
745
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
746 /* if we can't write to the file, give up before we hurt ourselves */
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
747 if(!data->file)
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
748 return;
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
749
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
750 stripped = gaim_markup_strip_html(message);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
751
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
752 if(log->type == GAIM_LOG_SYSTEM){
9592
9c78aaa4117e [gaim-migrate @ 10435]
Luke Schierer <lschiere@pidgin.im>
parents: 9500
diff changeset
753 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time));
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
754 fprintf(data->file, "---- %s @ %s ----\n", stripped, date);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
755 } else {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
756 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
757 if (type & GAIM_MESSAGE_SEND ||
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
758 type & GAIM_MESSAGE_RECV) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
759 if (type & GAIM_MESSAGE_AUTO_RESP) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
760 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
761 from, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
762 } else {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
763 if(gaim_message_meify(stripped, -1))
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
764 fprintf(data->file, "(%s) ***%s %s\n", date, from,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
765 stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
766 else
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
767 fprintf(data->file, "(%s) %s: %s\n", date, from,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
768 stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
769 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
770 } else if (type & GAIM_MESSAGE_SYSTEM)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
771 fprintf(data->file, "(%s) %s\n", date, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
772 else if (type & GAIM_MESSAGE_NO_LOG) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
773 /* This shouldn't happen */
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
774 g_free(stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
775 return;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
776 } else if (type & GAIM_MESSAGE_WHISPER)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
777 fprintf(data->file, "(%s) *%s* %s", date, from, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
778 else
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
779 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "",
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
780 from ? ":" : "", stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
781 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
782
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
783 fflush(data->file);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
784 g_free(stripped);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
785 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
786
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
787 static void txt_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
788 {
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
789 struct generic_logger_data *data = log->logger_data;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
790 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
791 if(data->file)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
792 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
793 if(data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
794 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
795 g_free(data);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
796 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
797 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
798
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
799 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
800 {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
801 return log_lister_common(type, sn, account, ".txt", &txt_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
802 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
803
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
804 static GList *txt_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
805 {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
806 return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".txt", &txt_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
807 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
808
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
809 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
810 {
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
811 char *read, *minus_header, *minus_header2;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
812 struct generic_logger_data *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
813 *flags = 0;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
814 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
815 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>"));
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
816 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
817 minus_header = strchr(read, '\n');
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
818 if (!minus_header)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
819 minus_header = g_strdup(read);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
820 else
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
821 minus_header = g_strdup(minus_header + 1);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
822 g_free(read);
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
823 minus_header2 = gaim_escape_html(minus_header);
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
824 g_free(minus_header);
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
825 return minus_header2;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
826 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
827 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
828 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
829
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
830 static void txt_logger_create(GaimLog *log)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
831 {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
832 if(log->type == GAIM_LOG_SYSTEM){
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
833 char date[64];
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
834 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
835 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
836 char *ud = gaim_user_dir();
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
837 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
838 char *filename;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
839 struct generic_logger_data *data;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
840
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
841 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
842 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
843 filename = g_build_filename(dir, date, NULL);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
844 g_free(dir);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
845
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
846 log->logger_data = data = g_new0(struct generic_logger_data, 1);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
847
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
848 data->file = fopen(filename, "a");
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
849 if (!data->file) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
850 gaim_debug(GAIM_DEBUG_ERROR, "log",
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
851 "Could not create log file %s\n", filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
852 g_free(filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
853 return;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
854 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
855 g_free(filename);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
856 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
857 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
858
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
859 static GaimLogLogger txt_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
860 N_("Plain text"), "txt",
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
861 txt_logger_create,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
862 txt_logger_write,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
863 txt_logger_finalize,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
864 txt_logger_list,
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
865 txt_logger_read,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
866 log_sizer_common,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
867 NULL,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
868 txt_logger_list_syslog
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
869 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
870
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
871 /****************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
872 * OLD LOGGER ***
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
873 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
874
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
875 /* The old logger doesn't write logs, only reads them. This is to include
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
876 * old logs in the log viewer transparently.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
877 */
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
878
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
879 struct old_logger_data {
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
880 GaimStringref *pathref;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
881 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
882 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
883 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
884
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
885 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
886 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
887 FILE *file;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
888 char buf[BUF_LONG];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
889 struct tm tm;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
890 char month[4];
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
891 struct old_logger_data *data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
892 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn));
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
893 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
894 GaimStringref *pathref = gaim_stringref_new(pathstr);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
895 char *newlog;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
896 int logfound = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
897 int lastoff = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
898 int newlen;
7791
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7770
diff changeset
899 time_t lasttime = 0;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
900
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
901 GaimLog *log = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
902 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
903
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
904 g_free(logfile);
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
905 g_free(pathstr);
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
906
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
907 if (!(file = fopen(gaim_stringref_value(pathref), "rb"))) {
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
908 gaim_stringref_unref(pathref);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
909 return NULL;
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
910 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
911
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
912 while (fgets(buf, BUF_LONG, file)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
913 if ((newlog = strstr(buf, "---- New C"))) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
914 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
915 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
916 char convostart[32];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
917 char *temp = strchr(buf, '@');
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
918
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
919 if (temp == NULL || strlen(temp) < 2)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
920 continue;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
921
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
922 temp++;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
923 length = strcspn(temp, "-");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
924 if (length > 31) length = 31;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
925
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
926 offset = ftell(file);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
927
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
928 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
929 newlen = offset - lastoff - length;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
930 if(strstr(buf, "----</H3><BR>")) {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
931 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
932 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") +
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
933 sizeof("----</H3><BR>") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
934 } else {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
935 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
936 sizeof("---- New Conversation @ ") + sizeof("----") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
937 }
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
938
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
939 if(strchr(buf, '\r'))
7770
41bcf3f62563 [gaim-migrate @ 8415]
Ethan Blanton <elb@pidgin.im>
parents: 7764
diff changeset
940 newlen--;
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
941
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
942 if (newlen != 0) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
943 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
944 log->logger = &old_logger;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
945 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
946 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
947 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
948 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
949 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
950 log->logger_data = data;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
951 list = g_list_append(list, log);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
952 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
953 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
954
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
955 logfound = 1;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
956 lastoff = offset;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
957
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
958 g_snprintf(convostart, length, "%s", temp);
7676
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
959 sscanf(convostart, "%*s %s %d %d:%d:%d %d",
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
960 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year);
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
961 /* Ugly hack, in case current locale is not English */
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
962 if (strcmp(month, "Jan") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
963 tm.tm_mon= 0;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
964 } else if (strcmp(month, "Feb") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
965 tm.tm_mon = 1;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
966 } else if (strcmp(month, "Mar") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
967 tm.tm_mon = 2;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
968 } else if (strcmp(month, "Apr") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
969 tm.tm_mon = 3;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
970 } else if (strcmp(month, "May") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
971 tm.tm_mon = 4;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
972 } else if (strcmp(month, "Jun") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
973 tm.tm_mon = 5;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
974 } else if (strcmp(month, "Jul") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
975 tm.tm_mon = 6;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
976 } else if (strcmp(month, "Aug") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
977 tm.tm_mon = 7;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
978 } else if (strcmp(month, "Sep") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
979 tm.tm_mon = 8;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
980 } else if (strcmp(month, "Oct") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
981 tm.tm_mon = 9;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
982 } else if (strcmp(month, "Nov") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
983 tm.tm_mon = 10;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
984 } else if (strcmp(month, "Dec") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
985 tm.tm_mon = 11;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
986 }
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
987 tm.tm_year -= 1900;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
988 lasttime = mktime(&tm);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
989 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
990 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
991
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
992 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
993 if ((newlen = ftell(file) - lastoff) != 0) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
994 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
995 log->logger = &old_logger;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
996 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
997 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
998 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
999 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1000 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1001 log->logger_data = data;
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1002 list = g_list_append(list, log);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1003 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1004 }
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1005
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1006 gaim_stringref_unref(pathref);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1007 fclose(file);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1008 return list;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1009 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1010
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1011 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account)
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1012 {
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1013 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name));
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1014 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1015 int size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1016 struct stat st;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1017
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1018 if (stat(pathstr, &st))
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1019 size = 0;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1020 else
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1021 size = st.st_size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1022
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1023 g_free(logfile);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1024 g_free(pathstr);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1025
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1026 return size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1027 }
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1028
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1029 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags)
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1030 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1031 struct old_logger_data *data = log->logger_data;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1032 FILE *file = fopen(gaim_stringref_value(data->pathref), "rb");
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1033 char *read = g_malloc(data->length + 1);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1034 fseek(file, data->offset, SEEK_SET);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1035 fread(read, data->length, 1, file);
8370
2279bfa6aa59 [gaim-migrate @ 9097]
Mark Doliner <mark@kingant.net>
parents: 8111
diff changeset
1036 fclose(file);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1037 read[data->length] = '\0';
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1038 *flags = 0;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1039 if(strstr(read, "<BR>"))
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1040 *flags |= GAIM_LOG_READ_NO_NEWLINE;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1041 return read;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1042 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1043
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1044 static int old_logger_size (GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1045 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1046 struct old_logger_data *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1047 return data ? data->length : 0;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1048 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1049
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1050 static void old_logger_finalize(GaimLog *log)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1051 {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1052 struct old_logger_data *data = log->logger_data;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1053 gaim_stringref_unref(data->pathref);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1054 g_free(data);
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1055 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1056
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1057 static GaimLogLogger old_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1058 "old logger", "old",
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1059 NULL, NULL,
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1060 old_logger_finalize,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1061 old_logger_list,
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1062 old_logger_read,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1063 old_logger_size,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1064 old_logger_total_size,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1065 NULL
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1066 };