annotate src/log.c @ 11133:1081735edc10

[gaim-migrate @ 13192] keeping in synch with the current plugin code committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Wed, 20 Jul 2005 12:32:20 +0000
parents 59a1ff5a4bae
children 3924db2b1ca8
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
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
46 static GList *log_get_log_sets_common();
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
47
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
48 /**************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
49 * PUBLIC LOGGING FUNCTIONS ***********************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
50 **************************************************************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
52 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
53 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
54 GaimLog *log = g_new0(GaimLog, 1);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
55 log->name = g_strdup(gaim_normalize(account, name));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
56 log->account = account;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
57 log->time = time;
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
58 log->type = type;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
59 log->logger_data = NULL;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
60 log->logger = gaim_log_logger_get();
7440
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
61 if (log->logger && log->logger->create)
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
62 log->logger->create(log);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
63 return log;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
66 void gaim_log_free(GaimLog *log)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
68 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
69 if (log->logger && log->logger->finalize)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
70 log->logger->finalize(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
71 g_free(log->name);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
72 g_free(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
73 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
74
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
75 void gaim_log_write(GaimLog *log, GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
76 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
77 {
10173
c754d26fe85e [gaim-migrate @ 11287]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10171
diff changeset
78 struct _gaim_logsize_user *lu;
c754d26fe85e [gaim-migrate @ 11287]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10171
diff changeset
79
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
80 g_return_if_fail(log);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
81 g_return_if_fail(log->logger);
7442
d42289ecf0ce [gaim-migrate @ 8047]
Nathan Walp <nwalp@pidgin.im>
parents: 7441
diff changeset
82 g_return_if_fail(log->logger->write);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
83
10171
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
84 (log->logger->write)(log, type, from, time, message);
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
85
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
86 lu = g_new(struct _gaim_logsize_user, 1);
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
87
10171
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
88 lu->name = g_strdup(gaim_normalize(log->account, log->name));
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
89 lu->account = log->account;
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
90 g_hash_table_remove(logsize_users, lu);
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
91 g_free(lu->name);
829a569993e0 [gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents: 10087
diff changeset
92 g_free(lu);
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
93
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
96 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97 {
7542
ebccd555323b [gaim-migrate @ 8156]
Nathan Walp <nwalp@pidgin.im>
parents: 7541
diff changeset
98 GaimLogReadFlags mflags;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
99 g_return_val_if_fail(log && log->logger, NULL);
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
100 if (log->logger->read) {
7535
f771759739c1 [gaim-migrate @ 8148]
Sean Egan <seanegan@gmail.com>
parents: 7501
diff changeset
101 char *ret = (log->logger->read)(log, flags ? flags : &mflags);
7478
3c21f3084ff0 [gaim-migrate @ 8091]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7473
diff changeset
102 gaim_str_strip_cr(ret);
7462
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
103 return ret;
5fb4cbf1ac54 [gaim-migrate @ 8075]
Nathan Walp <nwalp@pidgin.im>
parents: 7461
diff changeset
104 }
7470
ad6435eccf2b [gaim-migrate @ 8083]
Mark Doliner <mark@kingant.net>
parents: 7463
diff changeset
105 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
106 }
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
107
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
108 int gaim_log_get_size(GaimLog *log)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
109 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
110 g_return_val_if_fail(log && log->logger, 0);
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
111
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
112 if (log->logger->size)
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
113 return log->logger->size(log);
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
114 return 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
115 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
116
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
117 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
118 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
119 return g_str_hash(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
120 }
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 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
123 struct _gaim_logsize_user *lu2)
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
124 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
125 return ((!strcmp(lu1->name, lu2->name)) && lu1->account == lu2->account);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
126 }
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 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
129 {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
130 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
131 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
132 }
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
133
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
134 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
135 {
9677
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
136 gpointer ptrsize;
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
137 int size = 0;
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
9677
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
145 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) {
70ff55c0939b [gaim-migrate @ 10529]
Nathan Walp <nwalp@pidgin.im>
parents: 9613
diff changeset
146 size = GPOINTER_TO_INT(ptrsize);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
147 g_free(lu->name);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
148 g_free(lu);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
149 } else {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
150 for (n = loggers; n; n = n->next) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
151 GaimLogLogger *logger = n->data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
152
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
153 if(logger->total_size){
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
154 size += (logger->total_size)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
155 } else if(logger->list) {
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
156 GList *logs = (logger->list)(type, name, account);
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
157 int this_size = 0;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
158
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
159 while (logs) {
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
160 GList *logs2 = logs->next;
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
161 GaimLog *log = (GaimLog*)(logs->data);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
162 this_size += gaim_log_get_size(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
163 gaim_log_free(log);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
164 g_list_free_1(logs);
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
165 logs = logs2;
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
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
168 size += this_size;
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
169 }
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
170 }
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
171
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
172 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
173 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
174 return size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
175 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
177 char *
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
178 gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
179 {
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
180 GaimPlugin *prpl;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
181 GaimPluginProtocolInfo *prpl_info;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
182 const char *prpl_name;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
183 char *acct_name;
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
184 const char *target;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
185 char *dir;
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
186
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
187 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
188 if (!prpl)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
189 return NULL;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
190 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
191 prpl_name = prpl_info->list_icon(account, NULL);
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
192
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
193 acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account,
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
194 gaim_account_get_username(account))));
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
195
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
196 if (type == GAIM_LOG_CHAT) {
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
197 char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name));
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
198 target = gaim_escape_filename(temp);
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
199 g_free(temp);
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
200 } else if(type == GAIM_LOG_SYSTEM) {
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
201 target = ".system";
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
202 } else {
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
203 target = gaim_escape_filename(gaim_normalize(account, name));
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
204 }
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
205
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
206 dir = g_build_filename(gaim_user_dir(), "logs", prpl_name, acct_name, target, NULL);
9926
b23e70bd1215 [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9923
diff changeset
207
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
208 g_free(acct_name);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
209
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
210 return dir;
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
211 }
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
212
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
213 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
214 * LOGGER FUNCTIONS *********************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
215 ****************************************************************************/
4184
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 static GaimLogLogger *current_logger = NULL;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
218
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
219 static void logger_pref_cb(const char *name, GaimPrefType type,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
220 gpointer value, gpointer data)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
221 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
222 GaimLogLogger *logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
223 GSList *l = loggers;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
224 while (l) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
225 logger = l->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
226 if (!strcmp(logger->id, value)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
227 gaim_log_logger_set(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
228 return;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
230 l = l->next;
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 gaim_log_logger_set(&txt_logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
233 }
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
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
236 GaimLogLogger *gaim_log_logger_new(
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
237 void(*create)(GaimLog *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
238 void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
239 void(*finalize)(GaimLog *),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
240 GList*(*list)(GaimLogType type, const char*, GaimAccount*),
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
241 char*(*read)(GaimLog*, GaimLogReadFlags*),
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
242 int(*size)(GaimLog*),
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
243 int(*total_size)(GaimLogType type, const char *name, GaimAccount *account),
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
244 GList*(*list_syslog)(GaimAccount *account),
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
245 GList*(*get_log_sets)(void))
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
246 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
247 GaimLogLogger *logger = g_new0(GaimLogLogger, 1);
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
248
7440
8c0527c91a92 [gaim-migrate @ 8045]
Nathan Walp <nwalp@pidgin.im>
parents: 7436
diff changeset
249 logger->create = create;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
250 logger->write = write;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
251 logger->finalize = finalize;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
252 logger->list = list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
253 logger->read = read;
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
254 logger->size = size;
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
255 logger->total_size = total_size;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
256 logger->list_syslog = list_syslog;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
257 logger->get_log_sets = get_log_sets;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
258
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
259 return logger;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
262 void gaim_log_logger_free(GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
264 g_free(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
265 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
267 void gaim_log_logger_add (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
268 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
269 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
270 if (g_slist_find(loggers, logger))
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
271 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
272 loggers = g_slist_append(loggers, logger);
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
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
275 void gaim_log_logger_remove (GaimLogLogger *logger)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
276 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
277 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
278 g_slist_remove(loggers, logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
281 void gaim_log_logger_set (GaimLogLogger *logger)
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
283 g_return_if_fail(logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
284 current_logger = logger;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
285 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
287 GaimLogLogger *gaim_log_logger_get()
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
288 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
289 return current_logger;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
290 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
292 GList *gaim_log_logger_get_options(void)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
293 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
294 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
295 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
296 GaimLogLogger *data;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
298 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
299 data = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
300 if (!data->write)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
301 continue;
7494
86fe50e88bcd [gaim-migrate @ 8107]
Nathan Walp <nwalp@pidgin.im>
parents: 7491
diff changeset
302 list = g_list_append(list, _(data->name));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
303 list = g_list_append(list, data->id);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
306 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
307 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
308
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
309 gint gaim_log_compare(gconstpointer y, gconstpointer z)
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
310 {
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
311 const GaimLog *a = y;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
312 const GaimLog *b = z;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
313
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
314 return b->time - a->time;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
315 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
316
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
317 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
318 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
319 GList *logs = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
320 GSList *n;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
321 for (n = loggers; n; n = n->next) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
322 GaimLogLogger *logger = n->data;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
323 if (!logger->list)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
324 continue;
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
325 logs = g_list_concat(logs, logger->list(type, name, account));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
326 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
327
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
328 return g_list_sort(logs, gaim_log_compare);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
329 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
330
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
331 gint gaim_log_set_compare(gconstpointer y, gconstpointer z)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
332 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
333 const GaimLogSet *a = y;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
334 const GaimLogSet *b = z;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
335 gint ret = 0;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
336 char *tmp;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
337
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
338 /* This logic seems weird at first...
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
339 * If either account is NULL, we pretend the accounts are
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
340 * equal. This allows us to detect duplicates that will
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
341 * exist if one logger knows the account and another
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
342 * doesn't. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
343 if (a->account != NULL && b->account != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
344 ret = gaim_utf8_strcasecmp(gaim_account_get_username(a->account), gaim_account_get_username(b->account));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
345 if (ret != 0)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
346 return ret;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
347 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
348
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
349 tmp = g_strdup(gaim_normalize(a->account, a->name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
350 ret = gaim_utf8_strcasecmp(tmp, gaim_normalize(b->account, b->name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
351 g_free(tmp);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
352 if (ret != 0)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
353 return ret;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
354
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
355 return (gint)b->type - (gint)a->type;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
356 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
357
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
358 guint log_set_hash(gconstpointer key)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
359 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
360 const GaimLogSet *set = key;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
361
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
362 /* The account isn't hashed because we need GaimLogSets with NULL accounts
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
363 * to be found when we search by a GaimLogSet that has a non-NULL account
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
364 * but the same type and name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
365 return g_int_hash((gint *)&set->type) + g_str_hash(set->name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
366 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
367
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
368 gboolean log_set_equal(gconstpointer a, gconstpointer b)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
369 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
370 /* I realize that the choices made for GList and GHashTable
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
371 * make sense for those data types, but I wish the comparison
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
372 * functions were compatible. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
373 return !gaim_log_set_compare(a, b);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
374 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
375
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
376 void log_set_build_list(gpointer key, gpointer value, gpointer user_data)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
377 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
378 *((GList **)user_data) = g_list_append(*((GList **)user_data), key);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
379 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
380
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
381 GList *gaim_log_get_log_sets()
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
382 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
383 GSList *n;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
384 GList *sets = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
385 GList *set;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
386 GHashTable *sets_ht = g_hash_table_new(log_set_hash, log_set_equal);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
387
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
388 /* Get the log sets from all the loggers. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
389 for (n = loggers; n; n = n->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
390 GaimLogLogger *logger = n->data;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
391
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
392 if (!logger->get_log_sets)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
393 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
394
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
395 sets = g_list_concat(sets, logger->get_log_sets());
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
396 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
397
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
398 /* Get the log sets for loggers that use the common logger functions. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
399 sets = g_list_concat(sets, log_get_log_sets_common());
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
400
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
401 for (set = sets; set != NULL ; set = set->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
402 GaimLogSet *existing_set = g_hash_table_lookup(sets_ht, set->data);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
403
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
404 if (existing_set == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
405 g_hash_table_insert(sets_ht, set->data, set->data);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
406 } else if (existing_set->account == NULL && ((GaimLogSet *)set->data)->account != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
407 /* The existing entry in the hash table has no account.
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
408 * This one does. We'll delete the old one and keep this one. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
409 g_hash_table_replace(sets_ht, set->data, set->data);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
410 g_free(existing_set->name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
411 g_free(existing_set);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
412 } else {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
413 g_free(((GaimLogSet *)set->data)->name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
414 g_free(set->data);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
415 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
416 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
417 g_list_free(sets);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
418
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
419 /* At this point, we've built a GHashTable of unique GaimLogSets.
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
420 * So, we build a list of those keys and destroy the GHashTable. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
421 sets = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
422 g_hash_table_foreach(sets_ht, log_set_build_list, &sets);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
423 g_hash_table_destroy(sets_ht);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
424
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
425 return g_list_sort(sets, gaim_log_set_compare);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
426 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
427
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
428 GList *gaim_log_get_system_logs(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
429 {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
430 GList *logs = NULL;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
431 GSList *n;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
432 for (n = loggers; n; n = n->next) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
433 GaimLogLogger *logger = n->data;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
434 if (!logger->list_syslog)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
435 continue;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
436 logs = g_list_concat(logs, logger->list_syslog(account));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
437 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
438
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
439 return g_list_sort(logs, gaim_log_compare);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
440 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
441
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
442 void gaim_log_init(void)
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
443 {
11033
50224ac8184d [gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11025
diff changeset
444 gaim_debug_register_category("log");
50224ac8184d [gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11025
diff changeset
445
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
446 gaim_prefs_add_none("/core/logging");
7555
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
447 gaim_prefs_add_bool("/core/logging/log_ims", FALSE);
450b25d8d953 [gaim-migrate @ 8169]
Nathan Walp <nwalp@pidgin.im>
parents: 7554
diff changeset
448 gaim_prefs_add_bool("/core/logging/log_chats", FALSE);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
449 gaim_prefs_add_bool("/core/logging/log_system", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
450 gaim_prefs_add_bool("/core/logging/log_signon_signoff", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
451 gaim_prefs_add_bool("/core/logging/log_idle_state", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
452 gaim_prefs_add_bool("/core/logging/log_away_state", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
453 gaim_prefs_add_bool("/core/logging/log_own_states", FALSE);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
454
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
455 gaim_prefs_add_string("/core/logging/format", "txt");
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
456 gaim_log_logger_add(&html_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
457 gaim_log_logger_add(&txt_logger);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
458 gaim_log_logger_add(&old_logger);
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9977
diff changeset
459 gaim_prefs_connect_callback(NULL, "/core/logging/format",
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
460 logger_pref_cb, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
461 gaim_prefs_trigger_callback("/core/logging/format");
8635
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
462
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
463 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
464 (GEqualFunc)_gaim_logsize_user_equal,
4aee5a47937d [gaim-migrate @ 9387]
Nathan Walp <nwalp@pidgin.im>
parents: 8619
diff changeset
465 (GDestroyNotify)_gaim_logsize_user_free_key, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
466 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
467
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
468 /****************************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
469 * LOGGERS ******************************************************************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
470 ****************************************************************************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
471
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
472 void gaim_log_common_writer(GaimLog *log, time_t time, const char *ext)
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
473 {
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
474 char date[64];
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
475 GaimLogCommonLoggerData *data = log->logger_data;
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
476
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
477 if(!data) {
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
478 /* This log is new */
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
479 char *dir, *filename, *path;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
480
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
481 dir = gaim_log_get_log_dir(log->type, log->name, log->account);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
482 if (dir == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
483 return;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
484
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
485 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
486
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
487 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S", localtime(&log->time));
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
488
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
489 filename = g_strdup_printf("%s%s", date, ext ? ext : "");
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
490
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
491 path = g_build_filename(dir, filename, NULL);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
492 g_free(dir);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
493 g_free(filename);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
494
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
495 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
496
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
497 data->file = g_fopen(path, "a");
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
498 if (!data->file) {
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
499 gaim_debug(GAIM_DEBUG_ERROR, "log",
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
500 "Could not create log file %s\n", path);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
501 g_free(path);
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
502 return;
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
503 }
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
504 g_free(path);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
505 }
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
506 }
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
507
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
508 GList *gaim_log_common_lister(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
509 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
510 GDir *dir;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
511 GList *list = NULL;
7628
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7623
diff changeset
512 const char *filename;
8111
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
513 char *path;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
514
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
515 if(!account)
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
516 return NULL;
869d5a5495b8 [gaim-migrate @ 8812]
Nathan Walp <nwalp@pidgin.im>
parents: 8096
diff changeset
517
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
518 path = gaim_log_get_log_dir(type, name, account);
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
519 if (path == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
520 return NULL;
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
521
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
522 if (!(dir = g_dir_open(path, 0, NULL))) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
523 g_free(path);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
524 return NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
525 }
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
526
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
527 while ((filename = g_dir_read_name(dir))) {
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
528 if (gaim_str_has_suffix(filename, ext) &&
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
529 strlen(filename) == 17 + strlen(ext)) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
530 GaimLog *log;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
531 GaimLogCommonLoggerData *data;
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
532 time_t stamp = gaim_str_to_time(filename, FALSE);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
533
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
534 log = gaim_log_new(type, name, account, stamp);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
535 log->logger = logger;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
536 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
537 data->path = g_build_filename(path, filename, NULL);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
538 list = g_list_append(list, log);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
539 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
540 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
541 g_dir_close(dir);
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
542 g_free(path);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
543 return list;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
544 }
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
545
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
546 int gaim_log_common_sizer(GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
547 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
548 struct stat st;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
549 GaimLogCommonLoggerData *data = log->logger_data;
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
550
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
551 if (!data->path || g_stat(data->path, &st))
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
552 st.st_size = 0;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
553
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
554 return st.st_size;
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
555 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
556
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
557 /* This will build log sets for all loggers that use the common logger
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
558 * functions because they use the same directory structure. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
559 static GList *log_get_log_sets_common()
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
560 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
561 gchar *log_path = g_build_filename(gaim_user_dir(), "logs", NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
562 GDir *log_dir = g_dir_open(log_path, 0, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
563 const gchar *protocol;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
564 GList *sets = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
565
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
566 if (log_dir == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
567 g_free(log_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
568 return NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
569 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
570
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
571 while ((protocol = g_dir_read_name(log_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
572 gchar *protocol_path = g_build_filename(log_path, protocol, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
573 GDir *protocol_dir;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
574 const gchar *username;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
575 gchar *protocol_unescaped;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
576 GList *account_iter;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
577 GList *accounts = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
578
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
579 if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
580 g_free(protocol_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
581 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
582 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
583
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
584 /* Using g_strdup() to cover the one-in-a-million chance that a
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
585 * prpl's list_icon function uses gaim_unescape_filename(). */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
586 protocol_unescaped = g_strdup(gaim_unescape_filename(protocol));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
587
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
588 /* Find all the accounts for protocol. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
589 for (account_iter = gaim_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
590 GaimPlugin *prpl;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
591 GaimPluginProtocolInfo *prpl_info;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
592
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
593 prpl = gaim_find_prpl(gaim_account_get_protocol_id((GaimAccount *)account_iter->data));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
594 if (!prpl)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
595 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
596 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
597
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
598 if (!strcmp(protocol_unescaped, prpl_info->list_icon((GaimAccount *)account_iter->data, NULL)))
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
599 accounts = g_list_append(accounts, account_iter->data);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
600 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
601 g_free(protocol_unescaped);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
602
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
603 while ((username = g_dir_read_name(protocol_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
604 gchar *username_path = g_build_filename(protocol_path, username, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
605 GDir *username_dir;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
606 const gchar *username_unescaped;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
607 GaimAccount *account = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
608 gchar *name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
609
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
610 if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
611 g_free(username_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
612 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
613 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
614
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
615 /* Find the account for username in the list of accounts for protocol. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
616 username_unescaped = gaim_unescape_filename(username);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
617 for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
618 if (!strcmp(((GaimAccount *)account_iter->data)->username, username_unescaped)) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
619 account = account_iter->data;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
620 break;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
621 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
622 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
623
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
624 /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
625 while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
626 size_t len;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
627 GaimLogSet *set = g_new0(GaimLogSet, 1);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
628
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
629 /* Unescape the filename. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
630 name = g_strdup(gaim_unescape_filename(name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
631
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
632 /* Get the (possibly new) length of name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
633 len = strlen(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
634
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
635 set->account = account;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
636 set->name = name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
637
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
638 /* Chat for .chat or .system at the end of the name to determine the type. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
639 set->type = GAIM_LOG_IM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
640 if (len > 7) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
641 gchar *tmp = &name[len - 7];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
642 if (!strcmp(tmp, ".system")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
643 set->type = GAIM_LOG_SYSTEM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
644 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
645 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
646 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
647 if (len > 5) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
648 gchar *tmp = &name[len - 5];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
649 if (!strcmp(tmp, ".chat")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
650 set->type = GAIM_LOG_CHAT;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
651 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
652 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
653 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
654
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
655 /* Determine if this (account, name) combination exists as a buddy. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
656 if (gaim_find_buddy(account, name) != NULL)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
657 set->buddy = TRUE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
658 else
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
659 set->buddy = FALSE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
660
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
661 sets = g_list_append(sets, set);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
662 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
663 g_free(username_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
664 g_dir_close(username_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
665 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
666 g_free(protocol_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
667 g_dir_close(protocol_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
668 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
669 g_free(log_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
670 g_dir_close(log_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
671
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
672 return sets;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
673 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
674
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
675 #if 0 /* Maybe some other time. */
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
676 /****************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
677 ** XML LOGGER **
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
678 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
679
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
680 static const char *str_from_msg_type (GaimMessageFlags type)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
681 {
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
682
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
683 return "";
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
684
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
685 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
686
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
687 static void xml_logger_write(GaimLog *log,
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
688 GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
689 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
690 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
691 char date[64];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
692 char *xhtml = NULL;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
693
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
694 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
695 /* 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
696 * 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
697 * 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
698 */
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
699 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
700 FILE *file;
10577
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
701
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
702 if (dir == NULL)
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
703 return;
af1eb57050cc [gaim-migrate @ 11971]
Mark Doliner <mark@kingant.net>
parents: 10173
diff changeset
704
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
705 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
706
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
707 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
708
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
709 char *filename = g_build_filename(dir, date, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
710 g_free(dir);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
711
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
712 log->logger_data = g_fopen(filename, "a");
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
713 if (!log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
714 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
715 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
716 return;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
717 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
718 g_free(filename);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
719 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
720 "<?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
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", localtime(&log->time));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
723 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
724 date, log->name, prpl);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
725 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
726
9923
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
727 /* if we can't write to the file, give up before we hurt ourselves */
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
728 if(!data->file)
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
729 return;
248c3f88ce99 [gaim-migrate @ 10815]
Luke Schierer <lschiere@pidgin.im>
parents: 9892
diff changeset
730
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
731 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
732 gaim_markup_html_to_xhtml(message, &xhtml, NULL);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
733 if (from)
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
734 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
735 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
736 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
737 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
738 from, date, xhtml);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
739 else
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
740 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
741 str_from_msg_type(type),
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
742 type & GAIM_MESSAGE_SEND ? "direction='sent'" :
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
743 type & GAIM_MESSAGE_RECV ? "direction='received'" : "",
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
744 date, xhtml):
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
745 fflush(log->logger_data);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
746 g_free(xhtml);
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
747 }
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
748
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
749 static void xml_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
750 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
751 if (log->logger_data) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
752 fprintf(log->logger_data, "</conversation>\n");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
753 fclose(log->logger_data);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
754 log->logger_data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
755 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
756 }
7443
df50bd14e161 [gaim-migrate @ 8048]
Luke Schierer <lschiere@pidgin.im>
parents: 7442
diff changeset
757
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
758 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
759 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
760 return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
761 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
762
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
763 static GaimLogLogger xml_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
764 N_("XML"), "xml",
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
765 NULL,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
766 xml_logger_write,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
767 xml_logger_finalize,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
768 xml_logger_list,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
769 NULL,
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
770 NULL,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
771 NULL
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
772 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
773 #endif
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents: 5560
diff changeset
774
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
775 /****************************
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
776 ** HTML LOGGER *************
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
777 ****************************/
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
778
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
779 static void html_logger_write(GaimLog *log, GaimMessageFlags type,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
780 const char *from, time_t time, const char *message)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
781 {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
782 char *msg_fixed;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
783 char date[64];
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
784 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
785 GaimLogCommonLoggerData *data = log->logger_data;
9613
1b13160bf5a4 [gaim-migrate @ 10456]
Luke Schierer <lschiere@pidgin.im>
parents: 9592
diff changeset
786
7618
53e38b1ce00a [gaim-migrate @ 8242]
Nathan Walp <nwalp@pidgin.im>
parents: 7616
diff changeset
787 if(!data) {
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
788 const char *prpl =
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
789 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
790 gaim_log_common_writer(log, time, ".html");
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
791
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
792 data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
793
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
794 /* if we can't write to the file, give up before we hurt ourselves */
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
795 if(!data->file)
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
796 return;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
797
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
798 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
11092
68652f4ad6a7 [gaim-migrate @ 13115]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
799 fprintf(data->file, "<html><head>");
11094
59a1ff5a4bae [gaim-migrate @ 13119]
Richard Laager <rlaager@wiktel.com>
parents: 11092
diff changeset
800 fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
11092
68652f4ad6a7 [gaim-migrate @ 13115]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
801 fprintf(data->file, "<title>");
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
802 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
803 log->name, date, gaim_account_get_username(log->account), prpl);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
804 fprintf(data->file, "</title></head><body>");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
805 fprintf(data->file,
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
806 "<h3>Conversation with %s at %s on %s (%s)</h3>\n",
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
807 log->name, date, gaim_account_get_username(log->account), prpl);
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
808
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
809 }
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
810
9892
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
811 /* if we can't write to the file, give up before we hurt ourselves */
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
812 if(!data->file)
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
813 return;
284a84477ee9 [gaim-migrate @ 10780]
Luke Schierer <lschiere@pidgin.im>
parents: 9883
diff changeset
814
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
815 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL);
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
816
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
817 if(log->type == GAIM_LOG_SYSTEM){
9592
9c78aaa4117e [gaim-migrate @ 10435]
Luke Schierer <lschiere@pidgin.im>
parents: 9500
diff changeset
818 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
819 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
820 } else {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
821 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
822 if (type & GAIM_MESSAGE_SYSTEM)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
823 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
824 else if (type & GAIM_MESSAGE_WHISPER)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
825 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
826 date, from, msg_fixed);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
827 else if (type & GAIM_MESSAGE_AUTO_RESP) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
828 if (type & GAIM_MESSAGE_SEND)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
829 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
830 else if (type & GAIM_MESSAGE_RECV)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
831 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
832 } else if (type & GAIM_MESSAGE_RECV) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
833 if(gaim_message_meify(msg_fixed, -1))
10735
a0edd89ddb83 [gaim-migrate @ 12337]
Luke Schierer <lschiere@pidgin.im>
parents: 10732
diff changeset
834 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
835 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
836 else
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
837 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n",
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
838 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
839 } else if (type & GAIM_MESSAGE_SEND) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
840 if(gaim_message_meify(msg_fixed, -1))
10735
a0edd89ddb83 [gaim-migrate @ 12337]
Luke Schierer <lschiere@pidgin.im>
parents: 10732
diff changeset
841 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n",
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
842 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
843 else
10645
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
844 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n",
6480697e907b [gaim-migrate @ 12157]
Sean Egan <seanegan@gmail.com>
parents: 10589
diff changeset
845 date, from, msg_fixed);
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8573
diff changeset
846 }
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7556
diff changeset
847 }
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
848
7882
b4c2f92d4d24 [gaim-migrate @ 8536]
Nathan Walp <nwalp@pidgin.im>
parents: 7791
diff changeset
849 g_free(msg_fixed);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
850 fflush(data->file);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
851 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
852
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
853 static void html_logger_finalize(GaimLog *log)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
854 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
855 GaimLogCommonLoggerData *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
856 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
857 if(data->file) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
858 fprintf(data->file, "</body></html>");
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
859 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
860 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
861 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
862 g_free(data);
7463
f2d82df37252 [gaim-migrate @ 8076]
Nathan Walp <nwalp@pidgin.im>
parents: 7462
diff changeset
863 }
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
864 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
865
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
866 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
867 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
868 return gaim_log_common_lister(type, sn, account, ".html", &html_logger);
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
869 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
870
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
871 static GList *html_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
872 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
873 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", &html_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
874 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
875
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
876 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
877 {
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
878 char *read, *minus_header;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
879 GaimLogCommonLoggerData *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
880 *flags = GAIM_LOG_READ_NO_NEWLINE;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
881 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
882 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
883 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
884 minus_header = strchr(read, '\n');
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
885 if (!minus_header)
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
886 minus_header = g_strdup(read);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
887 else
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
888 minus_header = g_strdup(minus_header + 1);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
889 g_free(read);
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
890 return minus_header;
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
891 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
892 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
893 }
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
894
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
895 static GaimLogLogger html_logger = {
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
896 N_("HTML"), "html",
9819
34b468bdc1c5 [gaim-migrate @ 10690]
Mark Doliner <mark@kingant.net>
parents: 9763
diff changeset
897 NULL,
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
898 html_logger_write,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
899 html_logger_finalize,
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
900 html_logger_list,
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
901 html_logger_read,
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
902 gaim_log_common_sizer,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
903 NULL,
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
904 html_logger_list_syslog,
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
905 NULL
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
906 };
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
907
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
908
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
909
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
910
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
911 /****************************
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
912 ** PLAIN TEXT LOGGER *******
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
913 ****************************/
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
914
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
915 static void txt_logger_write(GaimLog *log,
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
916 GaimMessageFlags type,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
917 const char *from, time_t time, const char *message)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
918 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
919 char date[64];
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
920 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
921 GaimLogCommonLoggerData *data = log->logger_data;
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
922 char *stripped = NULL;
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
923
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
924 if(!data) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
925 /* 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
926 * 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
927 * 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
928 */
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
929 const char *prpl =
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
930 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
931 gaim_log_common_writer(log, time, ".txt");
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
932
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
933 data = log->logger_data;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
934
9763
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
935 /* if we can't write to the file, give up before we hurt ourselves */
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
936 if(!data->file)
b85df3f44350 [gaim-migrate @ 10631]
Luke Schierer <lschiere@pidgin.im>
parents: 9677
diff changeset
937 return;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
938
7453
6f5918e4f668 [gaim-migrate @ 8066]
Nathan Walp <nwalp@pidgin.im>
parents: 7447
diff changeset
939 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
940 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
941 log->name, date, gaim_account_get_username(log->account), prpl);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
942 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
943
7623
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
944 /* 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
945 if(!data->file)
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
946 return;
5381f96fc185 [gaim-migrate @ 8247]
Nathan Walp <nwalp@pidgin.im>
parents: 7618
diff changeset
947
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
948 stripped = gaim_markup_strip_html(message);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
949
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
950 if(log->type == GAIM_LOG_SYSTEM){
9592
9c78aaa4117e [gaim-migrate @ 10435]
Luke Schierer <lschiere@pidgin.im>
parents: 9500
diff changeset
951 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
952 fprintf(data->file, "---- %s @ %s ----\n", stripped, date);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
953 } else {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
954 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time));
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
955 if (type & GAIM_MESSAGE_SEND ||
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
956 type & GAIM_MESSAGE_RECV) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
957 if (type & GAIM_MESSAGE_AUTO_RESP) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
958 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
959 from, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
960 } else {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
961 if(gaim_message_meify(stripped, -1))
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
962 fprintf(data->file, "(%s) ***%s %s\n", date, from,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
963 stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
964 else
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
965 fprintf(data->file, "(%s) %s: %s\n", date, from,
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
966 stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
967 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
968 } else if (type & GAIM_MESSAGE_SYSTEM)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
969 fprintf(data->file, "(%s) %s\n", date, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
970 else if (type & GAIM_MESSAGE_NO_LOG) {
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
971 /* This shouldn't happen */
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
972 g_free(stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
973 return;
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
974 } else if (type & GAIM_MESSAGE_WHISPER)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
975 fprintf(data->file, "(%s) *%s* %s", date, from, stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
976 else
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
977 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "",
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
978 from ? ":" : "", stripped);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
979 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
980
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
981 fflush(data->file);
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
982 g_free(stripped);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
983 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
984
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
985 static void txt_logger_finalize(GaimLog *log)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
986 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
987 GaimLogCommonLoggerData *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
988 if (data) {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
989 if(data->file)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
990 fclose(data->file);
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
991 if(data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
992 g_free(data->path);
7752
68e205e746c9 [gaim-migrate @ 8397]
Ethan Blanton <elb@pidgin.im>
parents: 7685
diff changeset
993 g_free(data);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
994 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
995 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
996
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
997 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
998 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
999 return gaim_log_common_lister(type, sn, account, ".txt", &txt_logger);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1000 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1001
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1002 static GList *txt_logger_list_syslog(GaimAccount *account)
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1003 {
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1004 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", &txt_logger);
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1005 }
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1006
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1007 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1008 {
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
1009 char *read, *minus_header, *minus_header2;
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1010 GaimLogCommonLoggerData *data = log->logger_data;
7457
8bc33ec515a1 [gaim-migrate @ 8070]
Nathan Walp <nwalp@pidgin.im>
parents: 7453
diff changeset
1011 *flags = 0;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1012 if (!data || !data->path)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1013 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
1014 if (g_file_get_contents(data->path, &read, NULL, NULL)) {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1015 minus_header = strchr(read, '\n');
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1016 if (!minus_header)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1017 minus_header = g_strdup(read);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1018 else
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1019 minus_header = g_strdup(minus_header + 1);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1020 g_free(read);
10732
c4cb90065e1d [gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents: 10645
diff changeset
1021 minus_header2 = g_markup_escape_text(minus_header, -1);
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
1022 g_free(minus_header);
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8408
diff changeset
1023 return minus_header2;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1024 }
8578
089a3400b2aa [gaim-migrate @ 9327]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1025 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
1026 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1027
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1028 static GaimLogLogger txt_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1029 N_("Plain text"), "txt",
9819
34b468bdc1c5 [gaim-migrate @ 10690]
Mark Doliner <mark@kingant.net>
parents: 9763
diff changeset
1030 NULL,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1031 txt_logger_write,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1032 txt_logger_finalize,
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1033 txt_logger_list,
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1034 txt_logger_read,
10822
5c5120837bab [gaim-migrate @ 12484]
Mark Doliner <mark@kingant.net>
parents: 10735
diff changeset
1035 gaim_log_common_sizer,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1036 NULL,
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1037 txt_logger_list_syslog,
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1038 NULL
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1039 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1040
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1041 /****************
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1042 * OLD LOGGER ***
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1043 ****************/
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1044
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1045 /* 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
1046 * old logs in the log viewer transparently.
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1047 */
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1048
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1049 struct old_logger_data {
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1050 GaimStringref *pathref;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1051 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1052 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1053 };
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1054
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1055 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
1056 {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1057 FILE *file;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1058 char buf[BUF_LONG];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1059 struct tm tm;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1060 char month[4];
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1061 struct old_logger_data *data = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1062 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
1063 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1064 GaimStringref *pathref = gaim_stringref_new(pathstr);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1065 char *newlog;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1066 int logfound = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1067 int lastoff = 0;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1068 int newlen;
7791
21be2d9e8399 [gaim-migrate @ 8437]
Nathan Walp <nwalp@pidgin.im>
parents: 7770
diff changeset
1069 time_t lasttime = 0;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1070
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1071 GaimLog *log = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1072 GList *list = NULL;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1073
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
1074 g_free(logfile);
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1075 g_free(pathstr);
7473
859e4cf4d472 [gaim-migrate @ 8086]
Mark Doliner <mark@kingant.net>
parents: 7472
diff changeset
1076
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1077 if (!(file = g_fopen(gaim_stringref_value(pathref), "rb"))) {
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1078 gaim_stringref_unref(pathref);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1079 return NULL;
7447
0e7a835e2433 [gaim-migrate @ 8058]
Mark Doliner <mark@kingant.net>
parents: 7443
diff changeset
1080 }
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1081
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1082 while (fgets(buf, BUF_LONG, file)) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1083 if ((newlog = strstr(buf, "---- New C"))) {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1084 int length;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1085 int offset;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1086 char convostart[32];
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1087 char *temp = strchr(buf, '@');
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1088
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1089 if (temp == NULL || strlen(temp) < 2)
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1090 continue;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1091
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1092 temp++;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1093 length = strcspn(temp, "-");
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1094 if (length > 31) length = 31;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1095
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1096 offset = ftell(file);
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1097
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1098 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1099 newlen = offset - lastoff - length;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1100 if(strstr(buf, "----</H3><BR>")) {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1101 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1102 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") +
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1103 sizeof("----</H3><BR>") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1104 } else {
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1105 newlen -=
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1106 sizeof("---- New Conversation @ ") + sizeof("----") - 2;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1107 }
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1108
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
1109 if(strchr(buf, '\r'))
7770
41bcf3f62563 [gaim-migrate @ 8415]
Ethan Blanton <elb@pidgin.im>
parents: 7764
diff changeset
1110 newlen--;
7461
c1ddc403fda4 [gaim-migrate @ 8074]
Nathan Walp <nwalp@pidgin.im>
parents: 7457
diff changeset
1111
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1112 if (newlen != 0) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1113 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1114 log->logger = &old_logger;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1115 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1116 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1117 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1118 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1119 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1120 log->logger_data = data;
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1121 list = g_list_append(list, log);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1122 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1123 }
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1124
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1125 logfound = 1;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1126 lastoff = offset;
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1127
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1128 g_snprintf(convostart, length, "%s", temp);
7676
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1129 sscanf(convostart, "%*s %s %d %d:%d:%d %d",
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1130 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
1131 /* Ugly hack, in case current locale is not English */
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1132 if (strcmp(month, "Jan") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1133 tm.tm_mon= 0;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1134 } else if (strcmp(month, "Feb") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1135 tm.tm_mon = 1;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1136 } else if (strcmp(month, "Mar") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1137 tm.tm_mon = 2;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1138 } else if (strcmp(month, "Apr") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1139 tm.tm_mon = 3;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1140 } else if (strcmp(month, "May") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1141 tm.tm_mon = 4;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1142 } else if (strcmp(month, "Jun") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1143 tm.tm_mon = 5;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1144 } else if (strcmp(month, "Jul") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1145 tm.tm_mon = 6;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1146 } else if (strcmp(month, "Aug") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1147 tm.tm_mon = 7;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1148 } else if (strcmp(month, "Sep") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1149 tm.tm_mon = 8;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1150 } else if (strcmp(month, "Oct") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1151 tm.tm_mon = 9;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1152 } else if (strcmp(month, "Nov") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1153 tm.tm_mon = 10;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1154 } else if (strcmp(month, "Dec") == 0) {
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1155 tm.tm_mon = 11;
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1156 }
5c5acdf8b982 [gaim-migrate @ 8320]
Sean Egan <seanegan@gmail.com>
parents: 7628
diff changeset
1157 tm.tm_year -= 1900;
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1158 lasttime = mktime(&tm);
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1159 }
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1160 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1161
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1162 if (logfound) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1163 if ((newlen = ftell(file) - lastoff) != 0) {
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1164 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1165 log->logger = &old_logger;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1166 log->time = lasttime;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1167 data = g_new0(struct old_logger_data, 1);
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1168 data->offset = lastoff;
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1169 data->length = newlen;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1170 data->pathref = gaim_stringref_ref(pathref);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1171 log->logger_data = data;
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1172 list = g_list_append(list, log);
7761
946120d41b77 [gaim-migrate @ 8406]
Ethan Blanton <elb@pidgin.im>
parents: 7752
diff changeset
1173 }
7613
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1174 }
62d11301b8a6 [gaim-migrate @ 8237]
Nathan Walp <nwalp@pidgin.im>
parents: 7612
diff changeset
1175
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1176 gaim_stringref_unref(pathref);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1177 fclose(file);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1178 return list;
4184
af2eeb7f7cf8 [gaim-migrate @ 4415]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1179 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1180
8898
de87e510ff9a [gaim-migrate @ 9667]
Mark Doliner <mark@kingant.net>
parents: 8635
diff changeset
1181 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
1182 {
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1183 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name));
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1184 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1185 int size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1186 struct stat st;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1187
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1188 if (g_stat(pathstr, &st))
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1189 size = 0;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1190 else
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1191 size = st.st_size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1192
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1193 g_free(logfile);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1194 g_free(pathstr);
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1195
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1196 return size;
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1197 }
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1198
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1199 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags)
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1200 {
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1201 struct old_logger_data *data = log->logger_data;
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10577
diff changeset
1202 FILE *file = g_fopen(gaim_stringref_value(data->pathref), "rb");
10906
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1203 char *tmp, *read = g_malloc(data->length + 1);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1204 fseek(file, data->offset, SEEK_SET);
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1205 fread(read, data->length, 1, file);
8370
2279bfa6aa59 [gaim-migrate @ 9097]
Mark Doliner <mark@kingant.net>
parents: 8111
diff changeset
1206 fclose(file);
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1207 read[data->length] = '\0';
7436
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1208 *flags = 0;
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1209 if(strstr(read, "<BR>"))
7cdbd2eb7546 [gaim-migrate @ 8041]
Nathan Walp <nwalp@pidgin.im>
parents: 7431
diff changeset
1210 *flags |= GAIM_LOG_READ_NO_NEWLINE;
10906
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1211 else {
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1212 tmp = g_markup_escape_text(read, -1);
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1213 g_free(read);
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1214 read = tmp;
5e41c817dfa2 [gaim-migrate @ 12636]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10822
diff changeset
1215 }
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1216 return read;
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1217 }
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4227
diff changeset
1218
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1219 static int old_logger_size (GaimLog *log)
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1220 {
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1221 struct old_logger_data *data = log->logger_data;
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1222 return data ? data->length : 0;
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1223 }
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1224
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1225 static GList *old_logger_get_log_sets()
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1226 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1227 char *log_path = g_build_filename(gaim_user_dir(), "logs", NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1228 GDir *log_dir = g_dir_open(log_path, 0, NULL);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1229 gchar *name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1230 GList *sets = NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1231 GaimBlistNode *gnode, *cnode, *bnode;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1232
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1233 g_free(log_path);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1234 if (log_dir == NULL)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1235 return NULL;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1236
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1237 /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1238 while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1239 size_t len;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1240 gchar *ext;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1241 GaimLogSet *set;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1242 gboolean found = FALSE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1243
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1244 /* Unescape the filename. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1245 name = g_strdup(gaim_unescape_filename(name));
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1246
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1247 /* Get the (possibly new) length of name. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1248 len = strlen(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1249
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1250 if (len < 5) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1251 g_free(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1252 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1253 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1254
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1255 /* Make sure we're dealing with a log file. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1256 ext = &name[len - 4];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1257 if (strcmp(ext, ".log")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1258 g_free(name);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1259 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1260 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1261
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1262 set = g_new0(GaimLogSet, 1);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1263
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1264 /* Chat for .chat at the end of the name to determine the type. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1265 *ext = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1266 set->type = GAIM_LOG_IM;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1267 if (len > 9) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1268 char *tmp = &name[len - 9];
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1269 if (!strcmp(tmp, ".chat")) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1270 set->type = GAIM_LOG_CHAT;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1271 *tmp = '\0';
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1272 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1273 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1274
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1275 set->name = name;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1276
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1277 /* Search the buddy list to find the account and to determine if this is a buddy. */
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1278 for (gnode = gaim_get_blist()->root; !found && gnode != NULL; gnode = gnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1279 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1280 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1281 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1282
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1283 for (cnode = gnode->child; !found && cnode != NULL; cnode = cnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1284 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1285 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1286 continue;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1287
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1288 for (bnode = cnode->child; !found && bnode != NULL; bnode = bnode->next)
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1289 {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1290 GaimBuddy *buddy = (GaimBuddy *)bnode;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1291
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1292 if (!strcmp(buddy->name, name)) {
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1293 set->account = buddy->account;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1294 set->buddy = TRUE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1295 found = TRUE;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1296 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1297 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1298 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1299 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1300
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1301 sets = g_list_append(sets, set);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1302 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1303 g_dir_close(log_dir);
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1304
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1305 return sets;
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1306 }
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1307
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1308 static void old_logger_finalize(GaimLog *log)
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1309 {
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1310 struct old_logger_data *data = log->logger_data;
7764
88886239f31e [gaim-migrate @ 8409]
Ethan Blanton <elb@pidgin.im>
parents: 7761
diff changeset
1311 gaim_stringref_unref(data->pathref);
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1312 g_free(data);
7556
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1313 }
219903d29401 [gaim-migrate @ 8170]
Sean Egan <seanegan@gmail.com>
parents: 7555
diff changeset
1314
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1315 static GaimLogLogger old_logger = {
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1316 "old logger", "old",
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1317 NULL, NULL,
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1318 old_logger_finalize,
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1319 old_logger_list,
7616
a4acf41898c1 [gaim-migrate @ 8240]
Nathan Walp <nwalp@pidgin.im>
parents: 7613
diff changeset
1320 old_logger_read,
8096
81079e3eda47 [gaim-migrate @ 8795]
Luke Schierer <lschiere@pidgin.im>
parents: 8062
diff changeset
1321 old_logger_size,
8573
7dcd6f26e4a7 [gaim-migrate @ 9321]
Luke Schierer <lschiere@pidgin.im>
parents: 8517
diff changeset
1322 old_logger_total_size,
11025
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1323 NULL,
8d2007d738d5 [gaim-migrate @ 12899]
Mark Doliner <mark@kingant.net>
parents: 10906
diff changeset
1324 old_logger_get_log_sets
7431
643cbc9a6035 [gaim-migrate @ 8036]
Sean Egan <seanegan@gmail.com>
parents: 7322
diff changeset
1325 };