Tue, 21 Jul 2015 14:38:00 -0400
Remove ancient, never-used, disabled, and presumably broken logging features
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* purple |
| 7431 | 2 | * |
| 15884 | 3 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 4 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 5 | * source distribution. | |
| 7436 | 6 | * |
| 7431 | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 4184 | 20 | */ |
|
4195
37449660e3d5
[gaim-migrate @ 4426]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4192
diff
changeset
|
21 | |
|
13930
91f702895cd9
[gaim-migrate @ 16334]
Daniel Atallah <datallah@pidgin.im>
parents:
13762
diff
changeset
|
22 | #include "internal.h" |
| 7431 | 23 | #include "account.h" |
|
13762
a6c3092757f3
[gaim-migrate @ 16171]
Mark Doliner <markdoliner@pidgin.im>
parents:
13624
diff
changeset
|
24 | #include "dbus-maybe.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
25 | #include "debug.h" |
|
35190
5986ee34c476
libpurple: Fix build and warnings with glib 2.24
Ankit Vani <a@nevitus.org>
parents:
34864
diff
changeset
|
26 | #include "glibcompat.h" |
|
35813
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
27 | #include "image-store.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
28 | #include "log.h" |
| 5548 | 29 | #include "prefs.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
30 | #include "util.h" |
| 7764 | 31 | #include "stringref.h" |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
32 | #include "time.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
33 | |
| 8096 | 34 | static GSList *loggers = NULL; |
| 35 | ||
| 15884 | 36 | static PurpleLogLogger *html_logger; |
| 37 | static PurpleLogLogger *txt_logger; | |
| 38 | static PurpleLogLogger *old_logger; | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
39 | |
| 15884 | 40 | struct _purple_logsize_user { |
| 8635 | 41 | char *name; |
| 15884 | 42 | PurpleAccount *account; |
| 8635 | 43 | }; |
| 44 | static GHashTable *logsize_users = NULL; | |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
45 | static GHashTable *logsize_users_decayed = NULL; |
| 8635 | 46 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
47 | static void log_get_log_sets_common(GHashTable *sets); |
| 8635 | 48 | |
| 15884 | 49 | static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
50 | const char *from, time_t time, const char *message); |
| 15884 | 51 | static void html_logger_finalize(PurpleLog *log); |
| 52 | static GList *html_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account); | |
| 53 | static GList *html_logger_list_syslog(PurpleAccount *account); | |
| 54 | static char *html_logger_read(PurpleLog *log, PurpleLogReadFlags *flags); | |
| 55 | static int html_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account); | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
56 | |
| 15884 | 57 | static GList *old_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account); |
| 58 | static int old_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account); | |
| 59 | static char * old_logger_read (PurpleLog *log, PurpleLogReadFlags *flags); | |
| 60 | static int old_logger_size (PurpleLog *log); | |
| 61 | static void old_logger_get_log_sets(PurpleLogSetCallback cb, GHashTable *sets); | |
| 62 | static void old_logger_finalize(PurpleLog *log); | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
63 | |
| 15884 | 64 | static gsize txt_logger_write(PurpleLog *log, |
| 65 | PurpleMessageFlags type, | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
66 | const char *from, time_t time, const char *message); |
| 15884 | 67 | static void txt_logger_finalize(PurpleLog *log); |
| 68 | static GList *txt_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account); | |
| 69 | static GList *txt_logger_list_syslog(PurpleAccount *account); | |
| 70 | static char *txt_logger_read(PurpleLog *log, PurpleLogReadFlags *flags); | |
| 71 | static int txt_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account); | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
72 | |
| 7431 | 73 | /************************************************************************** |
| 74 | * PUBLIC LOGGING FUNCTIONS *********************************************** | |
| 75 | **************************************************************************/ | |
| 4184 | 76 | |
| 15884 | 77 | PurpleLog *purple_log_new(PurpleLogType type, const char *name, PurpleAccount *account, |
| 78 | PurpleConversation *conv, time_t time, const struct tm *tm) | |
| 7431 | 79 | { |
| 15884 | 80 | PurpleLog *log; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
81 | |
| 15884 | 82 | /* IMPORTANT: Make sure to initialize all the members of PurpleLog */ |
| 83 | log = g_slice_new(PurpleLog); | |
| 84 | PURPLE_DBUS_REGISTER_POINTER(log, PurpleLog); | |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
85 | |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
86 | log->type = type; |
| 15884 | 87 | log->name = g_strdup(purple_normalize(account, name)); |
| 7431 | 88 | log->account = account; |
|
11292
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
89 | log->conv = conv; |
| 7431 | 90 | log->time = time; |
| 15884 | 91 | log->logger = purple_log_logger_get(); |
| 8096 | 92 | log->logger_data = NULL; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
93 | |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
94 | if (tm == NULL) |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
95 | log->tm = NULL; |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
96 | else |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
97 | { |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
98 | /* There's no need to zero this as we immediately do a direct copy. */ |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
99 | log->tm = g_slice_new(struct tm); |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
100 | |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
101 | *(log->tm) = *tm; |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
102 | |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
103 | #ifdef HAVE_STRUCT_TM_TM_ZONE |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
104 | /* XXX: This is so wrong... */ |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
105 | if (log->tm->tm_zone != NULL) |
|
13161
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
106 | { |
|
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
107 | char *tmp = g_locale_from_utf8(log->tm->tm_zone, -1, NULL, NULL, NULL); |
|
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
108 | if (tmp != NULL) |
|
14036
9026f0f99d96
[gaim-migrate @ 16532]
Evan Schoenberg <evands@pidgin.im>
parents:
13930
diff
changeset
|
109 | log->tm->tm_zone = tmp; |
|
13161
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
110 | else |
|
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
111 | /* Just shove the UTF-8 bytes in and hope... */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14068
diff
changeset
|
112 | log->tm->tm_zone = g_strdup(log->tm->tm_zone); |
|
13161
8f84bea3949f
[gaim-migrate @ 15523]
Richard Laager <rlaager@pidgin.im>
parents:
13160
diff
changeset
|
113 | } |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
114 | #endif |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
115 | } |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
116 | |
| 7440 | 117 | if (log->logger && log->logger->create) |
| 118 | log->logger->create(log); | |
| 7431 | 119 | return log; |
| 4184 | 120 | } |
| 121 | ||
| 15884 | 122 | void purple_log_free(PurpleLog *log) |
| 4184 | 123 | { |
| 7431 | 124 | g_return_if_fail(log); |
| 125 | if (log->logger && log->logger->finalize) | |
| 126 | log->logger->finalize(log); | |
| 127 | g_free(log->name); | |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
128 | |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
129 | if (log->tm != NULL) |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
130 | { |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
131 | #ifdef HAVE_STRUCT_TM_TM_ZONE |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
132 | /* XXX: This is so wrong... */ |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
133 | g_free((char *)log->tm->tm_zone); |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
134 | #endif |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
135 | g_slice_free(struct tm, log->tm); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
136 | } |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
137 | |
| 15884 | 138 | PURPLE_DBUS_UNREGISTER_POINTER(log); |
| 139 | g_slice_free(PurpleLog, log); | |
| 7431 | 140 | } |
| 7436 | 141 | |
| 15884 | 142 | void purple_log_write(PurpleLog *log, PurpleMessageFlags type, |
| 7431 | 143 | const char *from, time_t time, const char *message) |
| 144 | { | |
| 15884 | 145 | struct _purple_logsize_user *lu; |
| 13059 | 146 | gsize written, total = 0; |
| 147 | gpointer ptrsize; | |
|
10173
335358c9cee4
[gaim-migrate @ 11287]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10171
diff
changeset
|
148 | |
| 7431 | 149 | g_return_if_fail(log); |
| 150 | g_return_if_fail(log->logger); | |
| 7442 | 151 | g_return_if_fail(log->logger->write); |
| 7431 | 152 | |
| 13059 | 153 | written = (log->logger->write)(log, type, from, time, message); |
|
10171
814764a2d24c
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
154 | |
| 15884 | 155 | lu = g_new(struct _purple_logsize_user, 1); |
| 9892 | 156 | |
| 15884 | 157 | lu->name = g_strdup(purple_normalize(log->account, log->name)); |
|
10171
814764a2d24c
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
158 | lu->account = log->account; |
| 13059 | 159 | |
| 160 | if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { | |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
161 | char *tmp = lu->name; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
162 | |
| 13059 | 163 | total = GPOINTER_TO_INT(ptrsize); |
| 164 | total += written; | |
| 165 | g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(total)); | |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
166 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
167 | /* The hash table takes ownership of lu, so create a new one |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
168 | * for the logsize_users_decayed check below. */ |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
169 | lu = g_new(struct _purple_logsize_user, 1); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
170 | lu->name = g_strdup(tmp); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
171 | lu->account = log->account; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
172 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
173 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
174 | if(g_hash_table_lookup_extended(logsize_users_decayed, lu, NULL, &ptrsize)) { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
175 | total = GPOINTER_TO_INT(ptrsize); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
176 | total += written; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
177 | g_hash_table_replace(logsize_users_decayed, lu, GINT_TO_POINTER(total)); |
|
13077
418101346d08
[gaim-migrate @ 15438]
Richard Laager <rlaager@pidgin.im>
parents:
13069
diff
changeset
|
178 | } else { |
|
418101346d08
[gaim-migrate @ 15438]
Richard Laager <rlaager@pidgin.im>
parents:
13069
diff
changeset
|
179 | g_free(lu->name); |
|
418101346d08
[gaim-migrate @ 15438]
Richard Laager <rlaager@pidgin.im>
parents:
13069
diff
changeset
|
180 | g_free(lu); |
| 13059 | 181 | } |
| 4184 | 182 | } |
| 183 | ||
| 15884 | 184 | char *purple_log_read(PurpleLog *log, PurpleLogReadFlags *flags) |
| 4184 | 185 | { |
| 15884 | 186 | PurpleLogReadFlags mflags; |
| 7431 | 187 | g_return_val_if_fail(log && log->logger, NULL); |
| 7462 | 188 | if (log->logger->read) { |
| 7535 | 189 | char *ret = (log->logger->read)(log, flags ? flags : &mflags); |
| 15884 | 190 | purple_str_strip_char(ret, '\r'); |
| 7462 | 191 | return ret; |
| 192 | } | |
|
13107
704041197f4d
[gaim-migrate @ 15468]
Richard Laager <rlaager@pidgin.im>
parents:
13105
diff
changeset
|
193 | return g_strdup(_("<b><font color=\"red\">The logger has no read function</font></b>")); |
| 4184 | 194 | } |
| 7616 | 195 | |
| 15884 | 196 | int purple_log_get_size(PurpleLog *log) |
| 7556 | 197 | { |
| 198 | g_return_val_if_fail(log && log->logger, 0); | |
| 8096 | 199 | |
| 7556 | 200 | if (log->logger->size) |
| 201 | return log->logger->size(log); | |
| 202 | return 0; | |
| 203 | } | |
| 204 | ||
| 15884 | 205 | static guint _purple_logsize_user_hash(struct _purple_logsize_user *lu) |
| 8635 | 206 | { |
| 207 | return g_str_hash(lu->name); | |
| 208 | } | |
| 209 | ||
| 15884 | 210 | static guint _purple_logsize_user_equal(struct _purple_logsize_user *lu1, |
| 211 | struct _purple_logsize_user *lu2) | |
| 8635 | 212 | { |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
213 | return (lu1->account == lu2->account && purple_strequal(lu1->name, lu2->name)); |
| 8635 | 214 | } |
| 215 | ||
| 15884 | 216 | static void _purple_logsize_user_free_key(struct _purple_logsize_user *lu) |
| 8635 | 217 | { |
| 218 | g_free(lu->name); | |
| 219 | g_free(lu); | |
| 220 | } | |
| 221 | ||
| 15884 | 222 | int purple_log_get_total_size(PurpleLogType type, const char *name, PurpleAccount *account) |
| 7556 | 223 | { |
| 9677 | 224 | gpointer ptrsize; |
| 225 | int size = 0; | |
| 8096 | 226 | GSList *n; |
| 15884 | 227 | struct _purple_logsize_user *lu; |
| 8096 | 228 | |
| 15884 | 229 | lu = g_new(struct _purple_logsize_user, 1); |
| 230 | lu->name = g_strdup(purple_normalize(account, name)); | |
| 8635 | 231 | lu->account = account; |
| 232 | ||
| 9677 | 233 | if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { |
| 234 | size = GPOINTER_TO_INT(ptrsize); | |
| 8635 | 235 | g_free(lu->name); |
| 236 | g_free(lu); | |
| 237 | } else { | |
| 238 | for (n = loggers; n; n = n->next) { | |
| 15884 | 239 | PurpleLogLogger *logger = n->data; |
| 7616 | 240 | |
| 8635 | 241 | if(logger->total_size){ |
|
8898
85f5615bc27e
[gaim-migrate @ 9667]
Mark Doliner <markdoliner@pidgin.im>
parents:
8635
diff
changeset
|
242 | size += (logger->total_size)(type, name, account); |
| 8635 | 243 | } else if(logger->list) { |
|
8898
85f5615bc27e
[gaim-migrate @ 9667]
Mark Doliner <markdoliner@pidgin.im>
parents:
8635
diff
changeset
|
244 | GList *logs = (logger->list)(type, name, account); |
| 8635 | 245 | int this_size = 0; |
| 246 | ||
| 247 | while (logs) { | |
| 15884 | 248 | PurpleLog *log = (PurpleLog*)(logs->data); |
| 249 | this_size += purple_log_get_size(log); | |
| 250 | purple_log_free(log); | |
|
13568
406e8503a006
[gaim-migrate @ 15946]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13520
diff
changeset
|
251 | logs = g_list_delete_link(logs, logs); |
| 8635 | 252 | } |
| 253 | ||
| 254 | size += this_size; | |
| 8096 | 255 | } |
| 8635 | 256 | } |
| 8096 | 257 | |
| 8635 | 258 | g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size)); |
| 7556 | 259 | } |
| 260 | return size; | |
| 261 | } | |
| 4184 | 262 | |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
263 | gint purple_log_get_activity_score(PurpleLogType type, const char *name, PurpleAccount *account) |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
264 | { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
265 | gpointer ptrscore; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
266 | int score; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
267 | GSList *n; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
268 | struct _purple_logsize_user *lu; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
269 | time_t now; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
270 | time(&now); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
271 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
272 | lu = g_new(struct _purple_logsize_user, 1); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
273 | lu->name = g_strdup(purple_normalize(account, name)); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
274 | lu->account = account; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
275 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
276 | if(g_hash_table_lookup_extended(logsize_users_decayed, lu, NULL, &ptrscore)) { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
277 | score = GPOINTER_TO_INT(ptrscore); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
278 | g_free(lu->name); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
279 | g_free(lu); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
280 | } else { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
281 | double score_double = 0.0; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
282 | for (n = loggers; n; n = n->next) { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
283 | PurpleLogLogger *logger = n->data; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
284 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
285 | if(logger->list) { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
286 | GList *logs = (logger->list)(type, name, account); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
287 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
288 | while (logs) { |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
289 | PurpleLog *log = (PurpleLog*)(logs->data); |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
290 | if (!log) { |
|
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
291 | g_warn_if_reached(); |
|
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
292 | continue; |
|
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
293 | } |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
294 | /* Activity score counts bytes in the log, exponentially |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
295 | decayed with a half-life of 14 days. */ |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
296 | score_double += purple_log_get_size(log) * |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
297 | pow(0.5, difftime(now, log->time)/1209600.0); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
298 | purple_log_free(log); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
299 | logs = g_list_delete_link(logs, logs); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
300 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
301 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
302 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
303 | |
|
29784
17baa4c9a8c5
pidgin: Distinguish no logs from really old logs (for Recent Log Activity sort)
Greg McNew <gmcnew@gmail.com>
parents:
28119
diff
changeset
|
304 | score = (gint) ceil(score_double); |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
305 | g_hash_table_replace(logsize_users_decayed, lu, GINT_TO_POINTER(score)); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
306 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
307 | return score; |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
308 | } |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
309 | |
| 15884 | 310 | gboolean purple_log_is_deletable(PurpleLog *log) |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
311 | { |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
312 | g_return_val_if_fail(log != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
313 | g_return_val_if_fail(log->logger != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
314 | |
|
16116
bccaa68c86ad
"delete" is a reserved word in C++, rename the "delete" member of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15981
diff
changeset
|
315 | if (log->logger->remove == NULL) |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
316 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
317 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
318 | if (log->logger->is_deletable != NULL) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
319 | return log->logger->is_deletable(log); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
320 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
321 | return TRUE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
322 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
323 | |
| 15884 | 324 | gboolean purple_log_delete(PurpleLog *log) |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
325 | { |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
326 | g_return_val_if_fail(log != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
327 | g_return_val_if_fail(log->logger != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
328 | |
|
16116
bccaa68c86ad
"delete" is a reserved word in C++, rename the "delete" member of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15981
diff
changeset
|
329 | if (log->logger->remove != NULL) |
|
bccaa68c86ad
"delete" is a reserved word in C++, rename the "delete" member of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15981
diff
changeset
|
330 | return log->logger->remove(log); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
331 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
332 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
333 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
334 | |
| 10822 | 335 | char * |
| 15884 | 336 | purple_log_get_log_dir(PurpleLogType type, const char *name, PurpleAccount *account) |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
337 | { |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
338 | PurpleProtocol *protocol; |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
36544
diff
changeset
|
339 | const char *protocol_name; |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
340 | char *acct_name; |
| 9926 | 341 | const char *target; |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
342 | char *dir; |
| 9926 | 343 | |
|
36626
18fc361b3704
Renamed purple_find_protocol_info to purple_protocols_find
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
344 | protocol = purple_protocols_find(purple_account_get_protocol_id(account)); |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
345 | if (!protocol) |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
346 | return NULL; |
|
36371
7adff7dc0f57
Refactored keyring and log to use the initial GObject plugin API
Ankit Vani <a@nevitus.org>
parents:
36361
diff
changeset
|
347 | |
| 36719 | 348 | protocol_name = purple_protocol_class_list_icon(protocol, account, NULL); |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
349 | |
| 15884 | 350 | acct_name = g_strdup(purple_escape_filename(purple_normalize(account, |
| 351 | purple_account_get_username(account)))); | |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
352 | |
| 15884 | 353 | if (type == PURPLE_LOG_CHAT) { |
| 354 | char *temp = g_strdup_printf("%s.chat", purple_normalize(account, name)); | |
| 355 | target = purple_escape_filename(temp); | |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
356 | g_free(temp); |
| 15884 | 357 | } else if(type == PURPLE_LOG_SYSTEM) { |
| 9926 | 358 | target = ".system"; |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
359 | } else { |
| 15884 | 360 | target = purple_escape_filename(purple_normalize(account, name)); |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
361 | } |
|
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
362 | |
|
36545
23b59a16c808
Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents:
36544
diff
changeset
|
363 | dir = g_build_filename(purple_user_dir(), "logs", protocol_name, acct_name, target, NULL); |
| 9926 | 364 | |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
365 | g_free(acct_name); |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
366 | |
|
9923
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
367 | return dir; |
|
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
368 | } |
|
f3060096e964
[gaim-migrate @ 10815]
Daniel Atallah <datallah@pidgin.im>
parents:
9892
diff
changeset
|
369 | |
| 7431 | 370 | /**************************************************************************** |
| 371 | * LOGGER FUNCTIONS ********************************************************* | |
| 372 | ****************************************************************************/ | |
| 4184 | 373 | |
| 15884 | 374 | static PurpleLogLogger *current_logger = NULL; |
| 7436 | 375 | |
| 15884 | 376 | static void logger_pref_cb(const char *name, PurplePrefType type, |
|
12816
5f93e09fa9a6
[gaim-migrate @ 15164]
Mark Doliner <markdoliner@pidgin.im>
parents:
12738
diff
changeset
|
377 | gconstpointer value, gpointer data) |
| 7431 | 378 | { |
| 15884 | 379 | PurpleLogLogger *logger; |
| 7431 | 380 | GSList *l = loggers; |
| 381 | while (l) { | |
| 382 | logger = l->data; | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
383 | if (purple_strequal(logger->id, value)) { |
| 15884 | 384 | purple_log_logger_set(logger); |
| 7431 | 385 | return; |
| 4184 | 386 | } |
| 7431 | 387 | l = l->next; |
| 388 | } | |
| 15884 | 389 | purple_log_logger_set(txt_logger); |
| 7431 | 390 | } |
| 4184 | 391 | |
| 392 | ||
| 15884 | 393 | PurpleLogLogger *purple_log_logger_new(const char *id, const char *name, int functions, ...) |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
394 | { |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
395 | #if 0 |
| 15884 | 396 | void(*create)(PurpleLog *), |
| 397 | gsize(*write)(PurpleLog *, PurpleMessageFlags, const char *, time_t, const char *), | |
| 398 | void(*finalize)(PurpleLog *), | |
| 399 | GList*(*list)(PurpleLogType type, const char*, PurpleAccount*), | |
| 400 | char*(*read)(PurpleLog*, PurpleLogReadFlags*), | |
| 401 | int(*size)(PurpleLog*), | |
| 402 | int(*total_size)(PurpleLogType type, const char *name, PurpleAccount *account), | |
| 403 | GList*(*list_syslog)(PurpleAccount *account), | |
| 404 | void(*get_log_sets)(PurpleLogSetCallback cb, GHashTable *sets), | |
|
16116
bccaa68c86ad
"delete" is a reserved word in C++, rename the "delete" member of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15981
diff
changeset
|
405 | gboolean(*remove)(PurpleLog *log), |
| 15884 | 406 | gboolean(*is_deletable)(PurpleLog *log)) |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
407 | #endif |
| 15884 | 408 | PurpleLogLogger *logger; |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
409 | va_list args; |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
410 | |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
411 | g_return_val_if_fail(id != NULL, NULL); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
412 | g_return_val_if_fail(name != NULL, NULL); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
413 | g_return_val_if_fail(functions >= 1, NULL); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
414 | |
| 15884 | 415 | logger = g_new0(PurpleLogLogger, 1); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
416 | logger->id = g_strdup(id); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
417 | logger->name = g_strdup(name); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
418 | |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
419 | va_start(args, functions); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
420 | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
421 | if (functions >= 1) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
422 | logger->create = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
423 | if (functions >= 2) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
424 | logger->write = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
425 | if (functions >= 3) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
426 | logger->finalize = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
427 | if (functions >= 4) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
428 | logger->list = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
429 | if (functions >= 5) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
430 | logger->read = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
431 | if (functions >= 6) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
432 | logger->size = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
433 | if (functions >= 7) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
434 | logger->total_size = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
435 | if (functions >= 8) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
436 | logger->list_syslog = va_arg(args, void *); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
437 | if (functions >= 9) |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
438 | logger->get_log_sets = va_arg(args, void *); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
439 | if (functions >= 10) |
|
16116
bccaa68c86ad
"delete" is a reserved word in C++, rename the "delete" member of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15981
diff
changeset
|
440 | logger->remove = va_arg(args, void *); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
441 | if (functions >= 11) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
442 | logger->is_deletable = va_arg(args, void *); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
443 | |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
444 | if (functions >= 12) |
| 15884 | 445 | purple_debug_info("log", "Dropping new functions for logger: %s (%s)\n", name, id); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
446 | |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
447 | va_end(args); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
448 | |
| 7431 | 449 | return logger; |
| 4184 | 450 | } |
| 451 | ||
| 15884 | 452 | void purple_log_logger_free(PurpleLogLogger *logger) |
| 4184 | 453 | { |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
454 | if (!logger) |
|
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
455 | return; |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
456 | g_free(logger->name); |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
457 | g_free(logger->id); |
| 7431 | 458 | g_free(logger); |
| 459 | } | |
| 4184 | 460 | |
| 15884 | 461 | void purple_log_logger_add (PurpleLogLogger *logger) |
| 7431 | 462 | { |
| 463 | g_return_if_fail(logger); | |
| 464 | if (g_slist_find(loggers, logger)) | |
| 465 | return; | |
| 466 | loggers = g_slist_append(loggers, logger); | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
467 | if (purple_strequal(purple_prefs_get_string("/purple/logging/format"), logger->id)) { |
|
18166
3edbd0ef7f1f
Custom logger selection doesn't work after a restart. To fix this, we do a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18152
diff
changeset
|
468 | purple_prefs_trigger_callback("/purple/logging/format"); |
|
3edbd0ef7f1f
Custom logger selection doesn't work after a restart. To fix this, we do a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18152
diff
changeset
|
469 | } |
| 7431 | 470 | } |
| 471 | ||
| 15884 | 472 | void purple_log_logger_remove (PurpleLogLogger *logger) |
| 7431 | 473 | { |
| 474 | g_return_if_fail(logger); | |
|
12574
3c80324a3ea5
[gaim-migrate @ 14896]
Mark Doliner <markdoliner@pidgin.im>
parents:
12241
diff
changeset
|
475 | loggers = g_slist_remove(loggers, logger); |
| 4184 | 476 | } |
| 477 | ||
| 15884 | 478 | void purple_log_logger_set (PurpleLogLogger *logger) |
| 4184 | 479 | { |
| 7431 | 480 | g_return_if_fail(logger); |
| 481 | current_logger = logger; | |
| 7436 | 482 | } |
| 4184 | 483 | |
| 15884 | 484 | PurpleLogLogger *purple_log_logger_get() |
| 7431 | 485 | { |
| 486 | return current_logger; | |
| 487 | } | |
| 4184 | 488 | |
| 15884 | 489 | GList *purple_log_logger_get_options(void) |
| 7431 | 490 | { |
| 491 | GSList *n; | |
| 492 | GList *list = NULL; | |
| 15884 | 493 | PurpleLogLogger *data; |
| 4184 | 494 | |
| 7431 | 495 | for (n = loggers; n; n = n->next) { |
| 496 | data = n->data; | |
| 497 | if (!data->write) | |
| 498 | continue; | |
|
12241
29b388429db5
[gaim-migrate @ 14543]
Richard Laager <rlaager@pidgin.im>
parents:
12240
diff
changeset
|
499 | list = g_list_append(list, data->name); |
| 7431 | 500 | list = g_list_append(list, data->id); |
| 4184 | 501 | } |
| 502 | ||
| 7431 | 503 | return list; |
| 504 | } | |
| 505 | ||
| 15884 | 506 | gint purple_log_compare(gconstpointer y, gconstpointer z) |
| 7431 | 507 | { |
| 15884 | 508 | const PurpleLog *a = y; |
| 509 | const PurpleLog *b = z; | |
| 7436 | 510 | |
| 7431 | 511 | return b->time - a->time; |
| 512 | } | |
| 513 | ||
| 15884 | 514 | GList *purple_log_get_logs(PurpleLogType type, const char *name, PurpleAccount *account) |
| 7431 | 515 | { |
| 516 | GList *logs = NULL; | |
| 517 | GSList *n; | |
| 518 | for (n = loggers; n; n = n->next) { | |
| 15884 | 519 | PurpleLogLogger *logger = n->data; |
| 7431 | 520 | if (!logger->list) |
| 521 | continue; | |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
522 | logs = g_list_concat(logger->list(type, name, account), logs); |
| 7431 | 523 | } |
| 7436 | 524 | |
| 15884 | 525 | return g_list_sort(logs, purple_log_compare); |
| 8573 | 526 | } |
| 527 | ||
| 15884 | 528 | gint purple_log_set_compare(gconstpointer y, gconstpointer z) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
529 | { |
| 15884 | 530 | const PurpleLogSet *a = y; |
| 531 | const PurpleLogSet *b = z; | |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
532 | gint ret = 0; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
533 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
534 | /* This logic seems weird at first... |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
535 | * If either account is NULL, we pretend the accounts are |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
536 | * equal. This allows us to detect duplicates that will |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
537 | * exist if one logger knows the account and another |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
538 | * doesn't. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
539 | if (a->account != NULL && b->account != NULL) { |
| 15884 | 540 | ret = strcmp(purple_account_get_username(a->account), purple_account_get_username(b->account)); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
541 | if (ret != 0) |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
542 | return ret; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
543 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
544 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
545 | ret = strcmp(a->normalized_name, b->normalized_name); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
546 | if (ret != 0) |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
547 | return ret; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
548 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
549 | return (gint)b->type - (gint)a->type; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
550 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
551 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11503
diff
changeset
|
552 | static guint |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11503
diff
changeset
|
553 | log_set_hash(gconstpointer key) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
554 | { |
| 15884 | 555 | const PurpleLogSet *set = key; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
556 | |
| 15884 | 557 | /* The account isn't hashed because we need PurpleLogSets with NULL accounts |
| 558 | * to be found when we search by a PurpleLogSet that has a non-NULL account | |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
559 | * but the same type and name. */ |
|
15483
bfcce3ec6848
Patch #1600087 from Richard 'wabz' Nelson: "Don't include a buddy's name when logging error/raw messages"
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15444
diff
changeset
|
560 | return g_int_hash(&set->type) + g_str_hash(set->name); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
561 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
562 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11503
diff
changeset
|
563 | static gboolean |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11503
diff
changeset
|
564 | log_set_equal(gconstpointer a, gconstpointer b) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
565 | { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
566 | /* I realize that the choices made for GList and GHashTable |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
567 | * make sense for those data types, but I wish the comparison |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
568 | * functions were compatible. */ |
| 15884 | 569 | return !purple_log_set_compare(a, b); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
570 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
571 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11503
diff
changeset
|
572 | static void |
| 15884 | 573 | log_add_log_set_to_hash(GHashTable *sets, PurpleLogSet *set) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
574 | { |
| 15884 | 575 | PurpleLogSet *existing_set = g_hash_table_lookup(sets, set); |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
576 | |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
577 | if (existing_set == NULL) |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
578 | g_hash_table_insert(sets, set, set); |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
579 | else if (existing_set->account == NULL && set->account != NULL) |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
580 | g_hash_table_replace(sets, set, set); |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
581 | else |
| 15884 | 582 | purple_log_set_free(set); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
583 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
584 | |
| 15884 | 585 | GHashTable *purple_log_get_log_sets(void) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
586 | { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
587 | GSList *n; |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
588 | GHashTable *sets = g_hash_table_new_full(log_set_hash, log_set_equal, |
| 15884 | 589 | (GDestroyNotify)purple_log_set_free, NULL); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
590 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
591 | /* Get the log sets from all the loggers. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
592 | for (n = loggers; n; n = n->next) { |
| 15884 | 593 | PurpleLogLogger *logger = n->data; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
594 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
595 | if (!logger->get_log_sets) |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
596 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
597 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
598 | logger->get_log_sets(log_add_log_set_to_hash, sets); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
599 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
600 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
601 | log_get_log_sets_common(sets); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
602 | |
| 15884 | 603 | /* Return the GHashTable of unique PurpleLogSets. */ |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
604 | return sets; |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
605 | } |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
606 | |
| 15884 | 607 | void purple_log_set_free(PurpleLogSet *set) |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
608 | { |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
609 | g_return_if_fail(set != NULL); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
610 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
611 | g_free(set->name); |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
612 | if (set->normalized_name != set->name) |
|
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
613 | g_free(set->normalized_name); |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
614 | |
| 15884 | 615 | g_slice_free(PurpleLogSet, set); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
616 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
617 | |
| 15884 | 618 | GList *purple_log_get_system_logs(PurpleAccount *account) |
| 8573 | 619 | { |
| 620 | GList *logs = NULL; | |
| 621 | GSList *n; | |
| 622 | for (n = loggers; n; n = n->next) { | |
| 15884 | 623 | PurpleLogLogger *logger = n->data; |
| 8573 | 624 | if (!logger->list_syslog) |
| 625 | continue; | |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
626 | logs = g_list_concat(logger->list_syslog(account), logs); |
| 8573 | 627 | } |
| 628 | ||
| 15884 | 629 | return g_list_sort(logs, purple_log_compare); |
| 7431 | 630 | } |
| 631 | ||
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
632 | /**************************************************************************** |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
633 | * LOG SUBSYSTEM ************************************************************ |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
634 | ****************************************************************************/ |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
635 | |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
636 | void * |
| 15884 | 637 | purple_log_get_handle(void) |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
638 | { |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
639 | static int handle; |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
640 | |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
641 | return &handle; |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
642 | } |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
643 | |
| 15884 | 644 | void purple_log_init(void) |
| 7436 | 645 | { |
| 15884 | 646 | void *handle = purple_log_get_handle(); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
647 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16116
diff
changeset
|
648 | purple_prefs_add_none("/purple/logging"); |
|
24971
f6617f5bdcbc
Enable logging of IMs and chats by default, using the HTML log format.
Richard Laager <rlaager@pidgin.im>
parents:
24955
diff
changeset
|
649 | purple_prefs_add_bool("/purple/logging/log_ims", TRUE); |
|
f6617f5bdcbc
Enable logging of IMs and chats by default, using the HTML log format.
Richard Laager <rlaager@pidgin.im>
parents:
24955
diff
changeset
|
650 | purple_prefs_add_bool("/purple/logging/log_chats", TRUE); |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16116
diff
changeset
|
651 | purple_prefs_add_bool("/purple/logging/log_system", FALSE); |
| 8573 | 652 | |
|
24971
f6617f5bdcbc
Enable logging of IMs and chats by default, using the HTML log format.
Richard Laager <rlaager@pidgin.im>
parents:
24955
diff
changeset
|
653 | purple_prefs_add_string("/purple/logging/format", "html"); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
654 | |
| 15884 | 655 | html_logger = purple_log_logger_new("html", _("HTML"), 11, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
656 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
657 | html_logger_write, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
658 | html_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
659 | html_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
660 | html_logger_read, |
| 15884 | 661 | purple_log_common_sizer, |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
662 | html_logger_total_size, |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
663 | html_logger_list_syslog, |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
664 | NULL, |
| 15884 | 665 | purple_log_common_deleter, |
| 666 | purple_log_common_is_deletable); | |
| 667 | purple_log_logger_add(html_logger); | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
668 | |
| 15884 | 669 | txt_logger = purple_log_logger_new("txt", _("Plain text"), 11, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
670 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
671 | txt_logger_write, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
672 | txt_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
673 | txt_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
674 | txt_logger_read, |
| 15884 | 675 | purple_log_common_sizer, |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
676 | txt_logger_total_size, |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
677 | txt_logger_list_syslog, |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
678 | NULL, |
| 15884 | 679 | purple_log_common_deleter, |
| 680 | purple_log_common_is_deletable); | |
| 681 | purple_log_logger_add(txt_logger); | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
682 | |
| 15884 | 683 | old_logger = purple_log_logger_new("old", _("Old flat format"), 9, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
684 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
685 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
686 | old_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
687 | old_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
688 | old_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
689 | old_logger_size, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
690 | old_logger_total_size, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
691 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
692 | old_logger_get_log_sets); |
| 15884 | 693 | purple_log_logger_add(old_logger); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
694 | |
| 15884 | 695 | purple_signal_register(handle, "log-timestamp", |
| 14057 | 696 | #if SIZEOF_TIME_T == 4 |
| 15884 | 697 | purple_marshal_POINTER__POINTER_INT_BOOLEAN, |
| 14057 | 698 | #elif SIZEOF_TIME_T == 8 |
| 15884 | 699 | purple_marshal_POINTER__POINTER_INT64_BOOLEAN, |
| 14057 | 700 | #else |
| 701 | #error Unknown size of time_t | |
| 702 | #endif | |
|
34820
7a89045601ae
Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34792
diff
changeset
|
703 | G_TYPE_STRING, 3, |
|
7a89045601ae
Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34792
diff
changeset
|
704 | PURPLE_TYPE_LOG, |
|
14054
20b2d18319cb
[gaim-migrate @ 16566]
Richard Laager <rlaager@pidgin.im>
parents:
14049
diff
changeset
|
705 | #if SIZEOF_TIME_T == 4 |
|
34820
7a89045601ae
Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34792
diff
changeset
|
706 | G_TYPE_INT, |
|
14068
57ba332d37fc
[gaim-migrate @ 16591]
Richard Laager <rlaager@pidgin.im>
parents:
14057
diff
changeset
|
707 | #elif SIZEOF_TIME_T == 8 |
|
34820
7a89045601ae
Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34792
diff
changeset
|
708 | G_TYPE_INT64, |
|
14054
20b2d18319cb
[gaim-migrate @ 16566]
Richard Laager <rlaager@pidgin.im>
parents:
14049
diff
changeset
|
709 | #else |
|
20b2d18319cb
[gaim-migrate @ 16566]
Richard Laager <rlaager@pidgin.im>
parents:
14049
diff
changeset
|
710 | # error Unknown size of time_t |
|
20b2d18319cb
[gaim-migrate @ 16566]
Richard Laager <rlaager@pidgin.im>
parents:
14049
diff
changeset
|
711 | #endif |
|
34820
7a89045601ae
Refactored log, network, notify to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents:
34792
diff
changeset
|
712 | G_TYPE_BOOLEAN); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
713 | |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16116
diff
changeset
|
714 | purple_prefs_connect_callback(NULL, "/purple/logging/format", |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
715 | logger_pref_cb, NULL); |
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
16116
diff
changeset
|
716 | purple_prefs_trigger_callback("/purple/logging/format"); |
| 8635 | 717 | |
| 15884 | 718 | logsize_users = g_hash_table_new_full((GHashFunc)_purple_logsize_user_hash, |
| 719 | (GEqualFunc)_purple_logsize_user_equal, | |
| 720 | (GDestroyNotify)_purple_logsize_user_free_key, NULL); | |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
721 | logsize_users_decayed = g_hash_table_new_full((GHashFunc)_purple_logsize_user_hash, |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
722 | (GEqualFunc)_purple_logsize_user_equal, |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
723 | (GDestroyNotify)_purple_logsize_user_free_key, NULL); |
| 7431 | 724 | } |
| 725 | ||
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
726 | void |
| 15884 | 727 | purple_log_uninit(void) |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
728 | { |
| 15884 | 729 | purple_signals_unregister_by_instance(purple_log_get_handle()); |
|
22979
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
730 | |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
731 | purple_log_logger_remove(html_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
732 | purple_log_logger_free(html_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
733 | html_logger = NULL; |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
734 | |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
735 | purple_log_logger_remove(txt_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
736 | purple_log_logger_free(txt_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
737 | txt_logger = NULL; |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
738 | |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
739 | purple_log_logger_remove(old_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
740 | purple_log_logger_free(old_logger); |
|
29ca0829efe0
Clean up loggers when quitting (or unloading the logreader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
22850
diff
changeset
|
741 | old_logger = NULL; |
|
25883
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
742 | |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
743 | g_hash_table_destroy(logsize_users); |
|
059b74032730
A patch from Chris Connett to change the log size sorting method to weight
Richard Laager <rlaager@pidgin.im>
parents:
25859
diff
changeset
|
744 | g_hash_table_destroy(logsize_users_decayed); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
745 | } |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
746 | |
|
34792
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
747 | static PurpleLog * |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
748 | purple_log_copy(PurpleLog *log) |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
749 | { |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
750 | PurpleLog *log_copy; |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
751 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
752 | g_return_val_if_fail(log != NULL, NULL); |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
753 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
754 | log_copy = g_new(PurpleLog, 1); |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
755 | *log_copy = *log; |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
756 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
757 | return log_copy; |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
758 | } |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
759 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
760 | GType |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
761 | purple_log_get_type(void) |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
762 | { |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
763 | static GType type = 0; |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
764 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
765 | if (type == 0) { |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
766 | type = g_boxed_type_register_static("PurpleLog", |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
767 | (GBoxedCopyFunc)purple_log_copy, |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
768 | (GBoxedFreeFunc)g_free); |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
769 | } |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
770 | |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
771 | return type; |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
772 | } |
|
09228ea79272
Added GBoxed to certificate, certificate pool, xfer, log
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
773 | |
| 7431 | 774 | /**************************************************************************** |
| 775 | * LOGGERS ****************************************************************** | |
| 776 | ****************************************************************************/ | |
| 777 | ||
| 15884 | 778 | static char *log_get_timestamp(PurpleLog *log, time_t when) |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
779 | { |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15483
diff
changeset
|
780 | gboolean show_date; |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
781 | char *date; |
|
35252
852014ae74a0
Fix a remotely-triggerable null pointer dereference.
Mark Doliner <mark@kingant.net>
parents:
33769
diff
changeset
|
782 | struct tm *tm; |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
783 | |
| 15884 | 784 | show_date = (log->type == PURPLE_LOG_SYSTEM) || (time(NULL) > when + 20*60); |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15483
diff
changeset
|
785 | |
| 15884 | 786 | date = purple_signal_emit_return_1(purple_log_get_handle(), |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
787 | "log-timestamp", |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15483
diff
changeset
|
788 | log, when, show_date); |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
789 | if (date != NULL) |
|
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
790 | return date; |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
791 | |
|
35252
852014ae74a0
Fix a remotely-triggerable null pointer dereference.
Mark Doliner <mark@kingant.net>
parents:
33769
diff
changeset
|
792 | tm = localtime(&when); |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15483
diff
changeset
|
793 | if (show_date) |
|
35252
852014ae74a0
Fix a remotely-triggerable null pointer dereference.
Mark Doliner <mark@kingant.net>
parents:
33769
diff
changeset
|
794 | return g_strdup(purple_date_format_long(tm)); |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
795 | else |
|
35252
852014ae74a0
Fix a remotely-triggerable null pointer dereference.
Mark Doliner <mark@kingant.net>
parents:
33769
diff
changeset
|
796 | return g_strdup(purple_time_format(tm)); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
797 | } |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
798 | |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
799 | /* NOTE: This can return msg (which you may or may not want to g_free()) |
|
35813
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
800 | * NOTE: or a newly allocated string which you MUST g_free(). |
|
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
801 | * TODO: XXX: does it really works? |
|
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
802 | */ |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
803 | static char * |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
804 | convert_image_tags(const PurpleLog *log, const char *msg) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
805 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
806 | const char *tmp; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
807 | const char *start; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
808 | const char *end; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
809 | GData *attributes; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
810 | GString *newmsg = NULL; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
811 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
812 | tmp = msg; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
813 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
814 | while (purple_markup_find_tag("img", tmp, &start, &end, &attributes)) { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
815 | int imgid = 0; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
816 | char *idstr = NULL; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
817 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
818 | if (newmsg == NULL) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
819 | newmsg = g_string_new(""); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
820 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
821 | /* copy any text before the img tag */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
822 | if (tmp < start) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
823 | g_string_append_len(newmsg, tmp, start - tmp); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
824 | |
| 19224 | 825 | if ((idstr = g_datalist_get_data(&attributes, "id")) != NULL) |
| 826 | imgid = atoi(idstr); | |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
827 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
828 | if (imgid != 0) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
829 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
830 | FILE *image_file; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
831 | char *dir; |
|
35813
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
832 | PurpleImage *image; |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
833 | gconstpointer image_data; |
|
35837
528ddb11791c
Drop purple_util_get_image_extension and purple_util_get_image_filename
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35813
diff
changeset
|
834 | const gchar *new_filename = NULL; |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
835 | char *path = NULL; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
836 | size_t image_byte_count; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
837 | |
|
35813
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
838 | image = purple_image_store_get(imgid); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
839 | if (image == NULL) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
840 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
841 | /* This should never happen. */ |
| 19224 | 842 | /* This *does* happen for failed Direct-IMs -DAA */ |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
843 | g_string_free(newmsg, TRUE); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
844 | g_return_val_if_reached((char *)msg); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
845 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
846 | |
|
35813
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
847 | image_data = purple_image_get_data(image); |
|
a5b71a95a42a
imgstore: remove references from libpurple (not prpls yet)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35489
diff
changeset
|
848 | image_byte_count = purple_image_get_size(image); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
849 | dir = purple_log_get_log_dir(log->type, log->name, log->account); |
|
35837
528ddb11791c
Drop purple_util_get_image_extension and purple_util_get_image_filename
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35813
diff
changeset
|
850 | new_filename = purple_image_generate_filename(image); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
851 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
852 | path = g_build_filename(dir, new_filename, NULL); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
853 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
854 | /* Only save unique files. */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
855 | if (!g_file_test(path, G_FILE_TEST_EXISTS)) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
856 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
857 | if ((image_file = g_fopen(path, "wb")) != NULL) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
858 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
859 | if (!fwrite(image_data, image_byte_count, 1, image_file)) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
860 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
861 | purple_debug_error("log", "Error writing %s: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
862 | path, g_strerror(errno)); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
863 | fclose(image_file); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
864 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
865 | /* Attempt to not leave half-written files around. */ |
|
33561
20173b979145
s/unlink/g_unlink/ and log a message if the call fails.
Mark Doliner <mark@kingant.net>
parents:
32438
diff
changeset
|
866 | if (g_unlink(path)) { |
|
20173b979145
s/unlink/g_unlink/ and log a message if the call fails.
Mark Doliner <mark@kingant.net>
parents:
32438
diff
changeset
|
867 | purple_debug_error("log", "Error deleting partial " |
|
20173b979145
s/unlink/g_unlink/ and log a message if the call fails.
Mark Doliner <mark@kingant.net>
parents:
32438
diff
changeset
|
868 | "file %s: %s\n", path, g_strerror(errno)); |
|
20173b979145
s/unlink/g_unlink/ and log a message if the call fails.
Mark Doliner <mark@kingant.net>
parents:
32438
diff
changeset
|
869 | } |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
870 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
871 | else |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
872 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
873 | purple_debug_info("log", "Wrote image file: %s\n", path); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
874 | fclose(image_file); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
875 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
876 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
877 | else |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
878 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
879 | purple_debug_error("log", "Unable to create file %s: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
880 | path, g_strerror(errno)); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
881 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
882 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
883 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
884 | /* Write the new image tag */ |
|
35837
528ddb11791c
Drop purple_util_get_image_extension and purple_util_get_image_filename
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35813
diff
changeset
|
885 | g_string_append_printf(newmsg, "<img src=\"%s\">", new_filename); |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
886 | g_free(path); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
887 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
888 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
889 | /* Continue from the end of the tag */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
890 | tmp = end + 1; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
891 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
892 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
893 | if (newmsg == NULL) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
894 | { |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
895 | /* No images were found to change. */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
896 | return (char *)msg; |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
897 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
898 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
899 | /* Append any remaining message data */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
900 | g_string_append(newmsg, tmp); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
901 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
902 | return g_string_free(newmsg, FALSE); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
903 | } |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
904 | |
| 15884 | 905 | void purple_log_common_writer(PurpleLog *log, const char *ext) |
| 9763 | 906 | { |
| 15884 | 907 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 9763 | 908 | |
|
11292
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
909 | if (data == NULL) |
|
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
910 | { |
| 9763 | 911 | /* This log is new */ |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
912 | char *dir; |
|
13163
2026e49825df
[gaim-migrate @ 15525]
Richard Laager <rlaager@pidgin.im>
parents:
13161
diff
changeset
|
913 | struct tm *tm; |
|
2026e49825df
[gaim-migrate @ 15525]
Richard Laager <rlaager@pidgin.im>
parents:
13161
diff
changeset
|
914 | const char *tz; |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
915 | const char *date; |
|
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
916 | char *filename; |
|
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
917 | char *path; |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
918 | |
| 15884 | 919 | dir = purple_log_get_log_dir(log->type, log->name, log->account); |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
920 | if (dir == NULL) |
|
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
921 | return; |
|
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
922 | |
| 15884 | 923 | purple_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 9763 | 924 | |
|
13163
2026e49825df
[gaim-migrate @ 15525]
Richard Laager <rlaager@pidgin.im>
parents:
13161
diff
changeset
|
925 | tm = localtime(&log->time); |
| 15884 | 926 | tz = purple_escape_filename(purple_utf8_strftime("%Z", tm)); |
| 927 | date = purple_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm); | |
| 9763 | 928 | |
|
13163
2026e49825df
[gaim-migrate @ 15525]
Richard Laager <rlaager@pidgin.im>
parents:
13161
diff
changeset
|
929 | filename = g_strdup_printf("%s%s%s", date, tz, ext ? ext : ""); |
| 9763 | 930 | |
|
13163
2026e49825df
[gaim-migrate @ 15525]
Richard Laager <rlaager@pidgin.im>
parents:
13161
diff
changeset
|
931 | path = g_build_filename(dir, filename, NULL); |
| 9763 | 932 | g_free(dir); |
| 933 | g_free(filename); | |
| 934 | ||
| 15884 | 935 | log->logger_data = data = g_slice_new0(PurpleLogCommonLoggerData); |
| 9763 | 936 | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10577
diff
changeset
|
937 | data->file = g_fopen(path, "a"); |
|
11292
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
938 | if (data->file == NULL) |
|
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
939 | { |
| 15884 | 940 | purple_debug(PURPLE_DEBUG_ERROR, "log", |
| 9892 | 941 | "Could not create log file %s\n", path); |
|
11292
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
942 | |
|
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
943 | if (log->conv != NULL) |
|
36089
c035b9a63457
Use purple_conversation_write_system_message where appropriate
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36086
diff
changeset
|
944 | purple_conversation_write_system_message(log->conv, |
|
c035b9a63457
Use purple_conversation_write_system_message where appropriate
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36086
diff
changeset
|
945 | _("Logging of this conversation failed."), |
|
c035b9a63457
Use purple_conversation_write_system_message where appropriate
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36086
diff
changeset
|
946 | PURPLE_MESSAGE_ERROR); |
|
11292
13068c68def6
[gaim-migrate @ 13492]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
947 | |
| 9763 | 948 | g_free(path); |
| 949 | return; | |
| 950 | } | |
| 951 | g_free(path); | |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
952 | } |
| 9763 | 953 | } |
| 954 | ||
| 15884 | 955 | GList *purple_log_common_lister(PurpleLogType type, const char *name, PurpleAccount *account, const char *ext, PurpleLogLogger *logger) |
| 7431 | 956 | { |
| 957 | GDir *dir; | |
| 958 | GList *list = NULL; | |
|
13160
8177a80d9e27
[gaim-migrate @ 15522]
Richard Laager <rlaager@pidgin.im>
parents:
13157
diff
changeset
|
959 | const char *filename; |
| 8111 | 960 | char *path; |
| 961 | ||
| 962 | if(!account) | |
| 963 | return NULL; | |
| 964 | ||
| 15884 | 965 | path = purple_log_get_log_dir(type, name, account); |
|
10577
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
966 | if (path == NULL) |
|
f27149d1cddf
[gaim-migrate @ 11971]
Richard Laager <rlaager@pidgin.im>
parents:
10173
diff
changeset
|
967 | return NULL; |
|
7447
4876aeb16c60
[gaim-migrate @ 8058]
Mark Doliner <markdoliner@pidgin.im>
parents:
7443
diff
changeset
|
968 | |
|
12969
823d3591438c
[gaim-migrate @ 15322]
Richard Laager <rlaager@pidgin.im>
parents:
12958
diff
changeset
|
969 | if (!(dir = g_dir_open(path, 0, NULL))) |
|
823d3591438c
[gaim-migrate @ 15322]
Richard Laager <rlaager@pidgin.im>
parents:
12958
diff
changeset
|
970 | { |
| 7431 | 971 | g_free(path); |
| 972 | return NULL; | |
| 973 | } | |
|
8898
85f5615bc27e
[gaim-migrate @ 9667]
Mark Doliner <markdoliner@pidgin.im>
parents:
8635
diff
changeset
|
974 | |
|
13160
8177a80d9e27
[gaim-migrate @ 15522]
Richard Laager <rlaager@pidgin.im>
parents:
13157
diff
changeset
|
975 | while ((filename = g_dir_read_name(dir))) |
|
12969
823d3591438c
[gaim-migrate @ 15322]
Richard Laager <rlaager@pidgin.im>
parents:
12958
diff
changeset
|
976 | { |
| 15884 | 977 | if (purple_str_has_suffix(filename, ext) && |
|
12969
823d3591438c
[gaim-migrate @ 15322]
Richard Laager <rlaager@pidgin.im>
parents:
12958
diff
changeset
|
978 | strlen(filename) >= (17 + strlen(ext))) |
|
823d3591438c
[gaim-migrate @ 15322]
Richard Laager <rlaager@pidgin.im>
parents:
12958
diff
changeset
|
979 | { |
| 15884 | 980 | PurpleLog *log; |
| 981 | PurpleLogCommonLoggerData *data; | |
|
13582
54ac10e3c3cc
[gaim-migrate @ 15963]
Richard Laager <rlaager@pidgin.im>
parents:
13568
diff
changeset
|
982 | struct tm tm; |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
983 | #if defined (HAVE_TM_GMTOFF) && defined (HAVE_STRUCT_TM_TM_ZONE) |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
984 | long tz_off; |
|
24177
b4e6c6d462db
purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <datallah@pidgin.im>
parents:
23502
diff
changeset
|
985 | const char *rest, *end; |
| 15884 | 986 | time_t stamp = purple_str_to_time(purple_unescape_filename(filename), FALSE, &tm, &tz_off, &rest); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
987 | |
| 15884 | 988 | /* As zero is a valid offset, PURPLE_NO_TZ_OFF means no offset was |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
989 | * provided. See util.h. Yes, it's kinda ugly. */ |
| 15884 | 990 | if (tz_off != PURPLE_NO_TZ_OFF) |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
991 | tm.tm_gmtoff = tz_off - tm.tm_gmtoff; |
| 7431 | 992 | |
|
17005
ee9efeb18039
Fix log viewer crash when the log filename is doesn't contain a date in the expected format. Fixes #588.
Daniel Atallah <datallah@pidgin.im>
parents:
16478
diff
changeset
|
993 | if (stamp == 0 || rest == NULL || (end = strchr(rest, '.')) == NULL || strchr(rest, ' ') != NULL) |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
994 | { |
| 15884 | 995 | log = purple_log_new(type, name, account, NULL, stamp, NULL); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
996 | } |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
997 | else |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
998 | { |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
999 | char *tmp = g_strndup(rest, end - rest); |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1000 | tm.tm_zone = tmp; |
| 15884 | 1001 | log = purple_log_new(type, name, account, NULL, stamp, &tm); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1002 | g_free(tmp); |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1003 | } |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1004 | #else |
| 15884 | 1005 | time_t stamp = purple_str_to_time(filename, FALSE, &tm, NULL, NULL); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1006 | |
|
17005
ee9efeb18039
Fix log viewer crash when the log filename is doesn't contain a date in the expected format. Fixes #588.
Daniel Atallah <datallah@pidgin.im>
parents:
16478
diff
changeset
|
1007 | log = purple_log_new(type, name, account, NULL, stamp, (stamp != 0) ? &tm : NULL); |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1008 | #endif |
|
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
13107
diff
changeset
|
1009 | |
| 7431 | 1010 | log->logger = logger; |
| 15884 | 1011 | log->logger_data = data = g_slice_new0(PurpleLogCommonLoggerData); |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1012 | |
| 7616 | 1013 | data->path = g_build_filename(path, filename, NULL); |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
1014 | list = g_list_prepend(list, log); |
| 4184 | 1015 | } |
| 1016 | } | |
| 7431 | 1017 | g_dir_close(dir); |
|
7447
4876aeb16c60
[gaim-migrate @ 8058]
Mark Doliner <markdoliner@pidgin.im>
parents:
7443
diff
changeset
|
1018 | g_free(path); |
| 7431 | 1019 | return list; |
| 1020 | } | |
| 4184 | 1021 | |
| 15884 | 1022 | int purple_log_common_total_sizer(PurpleLogType type, const char *name, PurpleAccount *account, const char *ext) |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1023 | { |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1024 | GDir *dir; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1025 | int size = 0; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1026 | const char *filename; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1027 | char *path; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1028 | |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1029 | if(!account) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1030 | return 0; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1031 | |
| 15884 | 1032 | path = purple_log_get_log_dir(type, name, account); |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1033 | if (path == NULL) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1034 | return 0; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1035 | |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1036 | if (!(dir = g_dir_open(path, 0, NULL))) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1037 | { |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1038 | g_free(path); |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1039 | return 0; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1040 | } |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1041 | |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1042 | while ((filename = g_dir_read_name(dir))) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1043 | { |
| 15884 | 1044 | if (purple_str_has_suffix(filename, ext) && |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1045 | strlen(filename) >= (17 + strlen(ext))) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1046 | { |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1047 | char *tmp = g_build_filename(path, filename, NULL); |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33774
diff
changeset
|
1048 | GStatBuf st; |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1049 | if (g_stat(tmp, &st)) |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1050 | { |
| 15884 | 1051 | purple_debug_error("log", "Error stating log file: %s\n", tmp); |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1052 | g_free(tmp); |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1053 | continue; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1054 | } |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1055 | g_free(tmp); |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1056 | size += st.st_size; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1057 | } |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1058 | } |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1059 | g_dir_close(dir); |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1060 | g_free(path); |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1061 | return size; |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1062 | } |
|
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1063 | |
| 15884 | 1064 | int purple_log_common_sizer(PurpleLog *log) |
| 7556 | 1065 | { |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33774
diff
changeset
|
1066 | GStatBuf st; |
| 15884 | 1067 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 7556 | 1068 | |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1069 | g_return_val_if_fail(data != NULL, 0); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1070 | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10577
diff
changeset
|
1071 | if (!data->path || g_stat(data->path, &st)) |
| 7556 | 1072 | st.st_size = 0; |
| 1073 | ||
| 1074 | return st.st_size; | |
| 1075 | } | |
| 1076 | ||
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1077 | /* This will build log sets for all loggers that use the common logger |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1078 | * functions because they use the same directory structure. */ |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1079 | static void log_get_log_sets_common(GHashTable *sets) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1080 | { |
| 15884 | 1081 | gchar *log_path = g_build_filename(purple_user_dir(), "logs", NULL); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1082 | GDir *log_dir = g_dir_open(log_path, 0, NULL); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1083 | const gchar *protocol; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1084 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1085 | if (log_dir == NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1086 | g_free(log_path); |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1087 | return; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1088 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1089 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1090 | while ((protocol = g_dir_read_name(log_dir)) != NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1091 | gchar *protocol_path = g_build_filename(log_path, protocol, NULL); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1092 | GDir *protocol_dir; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1093 | const gchar *username; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1094 | gchar *protocol_unescaped; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
1095 | GList *account_iter; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1096 | GList *accounts = NULL; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1097 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1098 | if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1099 | g_free(protocol_path); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1100 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1101 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1102 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1103 | /* Using g_strdup() to cover the one-in-a-million chance that a |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36626
diff
changeset
|
1104 | * protocol's list_icon function uses purple_unescape_filename(). */ |
| 15884 | 1105 | protocol_unescaped = g_strdup(purple_unescape_filename(protocol)); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1106 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1107 | /* Find all the accounts for protocol. */ |
| 15884 | 1108 | for (account_iter = purple_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) { |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
1109 | PurpleProtocol *protocol; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14068
diff
changeset
|
1110 | |
|
36626
18fc361b3704
Renamed purple_find_protocol_info to purple_protocols_find
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
1111 | protocol = purple_protocols_find(purple_account_get_protocol_id((PurpleAccount *)account_iter->data)); |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
1112 | if (!protocol) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1113 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1114 | |
| 36719 | 1115 | if (purple_strequal(protocol_unescaped, purple_protocol_class_list_icon(protocol, (PurpleAccount *)account_iter->data, NULL))) |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
1116 | accounts = g_list_prepend(accounts, account_iter->data); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1117 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1118 | g_free(protocol_unescaped); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1119 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1120 | while ((username = g_dir_read_name(protocol_dir)) != NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1121 | gchar *username_path = g_build_filename(protocol_path, username, NULL); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1122 | GDir *username_dir; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1123 | const gchar *username_unescaped; |
| 15884 | 1124 | PurpleAccount *account = NULL; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1125 | gchar *name; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1126 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1127 | if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1128 | g_free(username_path); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1129 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1130 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1131 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1132 | /* Find the account for username in the list of accounts for protocol. */ |
| 15884 | 1133 | username_unescaped = purple_unescape_filename(username); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1134 | for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) { |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32001
diff
changeset
|
1135 | if (purple_strequal(purple_account_get_username((PurpleAccount *)account_iter->data), username_unescaped)) { |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1136 | account = account_iter->data; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1137 | break; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1138 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1139 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1140 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1141 | /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1142 | while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1143 | size_t len; |
| 15884 | 1144 | PurpleLogSet *set; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1145 | |
| 15884 | 1146 | /* IMPORTANT: Always initialize all members of PurpleLogSet */ |
| 1147 | set = g_slice_new(PurpleLogSet); | |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1148 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1149 | /* Unescape the filename. */ |
| 15884 | 1150 | name = g_strdup(purple_unescape_filename(name)); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1151 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1152 | /* Get the (possibly new) length of name. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1153 | len = strlen(name); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1154 | |
| 15884 | 1155 | set->type = PURPLE_LOG_IM; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1156 | set->name = name; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1157 | set->account = account; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1158 | /* set->buddy is always set below */ |
| 15884 | 1159 | set->normalized_name = g_strdup(purple_normalize(account, name)); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1160 | |
|
27586
4e908acd43b9
We are definitely "Check"ing here not "Chat"ting.
Etan Reisner <deryni@pidgin.im>
parents:
25883
diff
changeset
|
1161 | /* Check for .chat or .system at the end of the name to determine the type. */ |
|
23430
b26a5d982d62
Correctly detect system logs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22979
diff
changeset
|
1162 | if (len >= 7) { |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1163 | gchar *tmp = &name[len - 7]; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1164 | if (purple_strequal(tmp, ".system")) { |
| 15884 | 1165 | set->type = PURPLE_LOG_SYSTEM; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1166 | *tmp = '\0'; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1167 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1168 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1169 | if (len > 5) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1170 | gchar *tmp = &name[len - 5]; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1171 | if (purple_strequal(tmp, ".chat")) { |
| 15884 | 1172 | set->type = PURPLE_LOG_CHAT; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1173 | *tmp = '\0'; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1174 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1175 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1176 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1177 | /* Determine if this (account, name) combination exists as a buddy. */ |
|
33769
96f89e35d24d
Fix various "Dereference before null check" issues
Daniel Atallah <datallah@pidgin.im>
parents:
33597
diff
changeset
|
1178 | if (account != NULL && *name != '\0') |
|
34728
8efd73063ecf
Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents:
34699
diff
changeset
|
1179 | set->buddy = (purple_blist_find_buddy(account, name) != NULL); |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1180 | else |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1181 | set->buddy = FALSE; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1182 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1183 | log_add_log_set_to_hash(sets, set); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1184 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1185 | g_free(username_path); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1186 | g_dir_close(username_dir); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1187 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1188 | g_free(protocol_path); |
|
31822
ec832bf0ba51
I will compile before committing. I will compile before committing.
Paul Aurich <darkrain42@pidgin.im>
parents:
31821
diff
changeset
|
1189 | g_list_free(accounts); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1190 | g_dir_close(protocol_dir); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1191 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1192 | g_free(log_path); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1193 | g_dir_close(log_dir); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1194 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1195 | |
| 15884 | 1196 | gboolean purple_log_common_deleter(PurpleLog *log) |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1197 | { |
| 15884 | 1198 | PurpleLogCommonLoggerData *data; |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1199 | int ret; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1200 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1201 | g_return_val_if_fail(log != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1202 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1203 | data = log->logger_data; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1204 | if (data == NULL) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1205 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1206 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1207 | if (data->path == NULL) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1208 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1209 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1210 | ret = g_unlink(data->path); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1211 | if (ret == 0) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1212 | return TRUE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1213 | else if (ret == -1) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1214 | { |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
1215 | purple_debug_error("log", "Failed to delete: %s - %s\n", data->path, g_strerror(errno)); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1216 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1217 | else |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1218 | { |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1219 | /* I'm not sure that g_unlink() will ever return |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1220 | * something other than 0 or -1. -- rlaager */ |
| 15884 | 1221 | purple_debug_error("log", "Failed to delete: %s\n", data->path); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1222 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1223 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1224 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1225 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1226 | |
| 15884 | 1227 | gboolean purple_log_common_is_deletable(PurpleLog *log) |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1228 | { |
| 15884 | 1229 | PurpleLogCommonLoggerData *data; |
| 15676 | 1230 | #ifndef _WIN32 |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1231 | gchar *dirname; |
| 15676 | 1232 | #endif |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1233 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1234 | g_return_val_if_fail(log != NULL, FALSE); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1235 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1236 | data = log->logger_data; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1237 | if (data == NULL) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1238 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1239 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1240 | if (data->path == NULL) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1241 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1242 | |
|
15585
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1243 | #ifndef _WIN32 |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1244 | dirname = g_path_get_dirname(data->path); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1245 | if (g_access(dirname, W_OK) == 0) |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1246 | { |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1247 | g_free(dirname); |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1248 | return TRUE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1249 | } |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
1250 | purple_debug_info("log", "access(%s) failed: %s\n", dirname, g_strerror(errno)); |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1251 | g_free(dirname); |
|
15585
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1252 | #else |
|
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1253 | /* Unless and until someone writes equivalent win32 code, |
|
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1254 | * we'll assume the file is deletable. */ |
|
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1255 | return TRUE; |
|
93dff667b2a3
I had the wrong arguments for gaim_log_logger_new(). It didn't work, but
Richard Laager <rlaager@pidgin.im>
parents:
15584
diff
changeset
|
1256 | #endif |
|
15584
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1257 | |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1258 | return FALSE; |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1259 | } |
|
f4d9ac6f94b8
This is the core code to support log deletion. It's untested.
Richard Laager <rlaager@pidgin.im>
parents:
15575
diff
changeset
|
1260 | |
| 15594 | 1261 | static char *process_txt_log(char *txt, char *to_free) |
| 1262 | { | |
| 1263 | char *tmp; | |
| 1264 | ||
| 1265 | /* The to_free argument allows us to save a | |
| 1266 | * g_strdup() in some cases. */ | |
| 1267 | ||
| 1268 | if (to_free == NULL) | |
| 1269 | to_free = txt; | |
| 1270 | ||
| 1271 | /* g_markup_escape_text requires valid UTF-8 */ | |
| 1272 | if (!g_utf8_validate(txt, -1, NULL)) | |
| 1273 | { | |
| 15884 | 1274 | tmp = purple_utf8_salvage(txt); |
| 15594 | 1275 | g_free(to_free); |
| 1276 | to_free = txt = tmp; | |
| 1277 | } | |
| 1278 | ||
| 1279 | tmp = g_markup_escape_text(txt, -1); | |
| 1280 | g_free(to_free); | |
| 15884 | 1281 | txt = purple_markup_linkify(tmp); |
| 15594 | 1282 | g_free(tmp); |
| 1283 | ||
| 1284 | return txt; | |
| 1285 | } | |
| 1286 | ||
| 7431 | 1287 | /**************************** |
| 7457 | 1288 | ** HTML LOGGER ************* |
| 1289 | ****************************/ | |
| 1290 | ||
| 15884 | 1291 | static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1292 | const char *from, time_t time, const char *message) |
| 7457 | 1293 | { |
| 9763 | 1294 | char *msg_fixed; |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1295 | char *image_corrected_msg; |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1296 | char *date; |
|
13514
735953c0929d
[gaim-migrate @ 15889]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13513
diff
changeset
|
1297 | char *header; |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1298 | char *escaped_from; |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
1299 | PurpleProtocol *protocol = |
|
36626
18fc361b3704
Renamed purple_find_protocol_info to purple_protocols_find
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
1300 | purple_protocols_find(purple_account_get_protocol_id(log->account)); |
| 15884 | 1301 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 13059 | 1302 | gsize written = 0; |
| 9613 | 1303 | |
| 7618 | 1304 | if(!data) { |
| 36719 | 1305 | const char *proto = purple_protocol_class_list_icon(protocol, log->account, NULL); |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
1306 | const char *date; |
| 15884 | 1307 | purple_log_common_writer(log, ".html"); |
| 7457 | 1308 | |
| 9763 | 1309 | data = log->logger_data; |
| 7457 | 1310 | |
| 9763 | 1311 | /* if we can't write to the file, give up before we hurt ourselves */ |
| 1312 | if(!data->file) | |
| 13059 | 1313 | return 0; |
| 7616 | 1314 | |
| 15884 | 1315 | date = purple_date_format_full(localtime(&log->time)); |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13078
diff
changeset
|
1316 | |
| 13059 | 1317 | written += fprintf(data->file, "<html><head>"); |
| 1318 | written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); | |
| 1319 | written += fprintf(data->file, "<title>"); | |
| 15884 | 1320 | if (log->type == PURPLE_LOG_SYSTEM) |
|
13514
735953c0929d
[gaim-migrate @ 15889]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13513
diff
changeset
|
1321 | header = g_strdup_printf("System log for account %s (%s) connected at %s", |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36626
diff
changeset
|
1322 | purple_account_get_username(log->account), proto, date); |
|
13509
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1323 | else |
|
13514
735953c0929d
[gaim-migrate @ 15889]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13513
diff
changeset
|
1324 | header = g_strdup_printf("Conversation with %s at %s on %s (%s)", |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36626
diff
changeset
|
1325 | log->name, date, purple_account_get_username(log->account), proto); |
|
13509
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1326 | |
|
13514
735953c0929d
[gaim-migrate @ 15889]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13513
diff
changeset
|
1327 | written += fprintf(data->file, "%s", header); |
| 13059 | 1328 | written += fprintf(data->file, "</title></head><body>"); |
|
13509
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1329 | written += fprintf(data->file, "<h3>%s</h3>\n", header); |
|
13514
735953c0929d
[gaim-migrate @ 15889]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
13513
diff
changeset
|
1330 | g_free(header); |
| 7457 | 1331 | } |
| 7623 | 1332 | |
| 9892 | 1333 | /* if we can't write to the file, give up before we hurt ourselves */ |
| 1334 | if(!data->file) | |
| 13059 | 1335 | return 0; |
| 9892 | 1336 | |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1337 | escaped_from = g_markup_escape_text(from, -1); |
|
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1338 | |
|
18101
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1339 | image_corrected_msg = convert_image_tags(log, message); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1340 | purple_markup_html_to_xhtml(image_corrected_msg, &msg_fixed, NULL); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1341 | |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1342 | /* Yes, this breaks encapsulation. But it's a static function and |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1343 | * this saves a needless strdup(). */ |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1344 | if (image_corrected_msg != message) |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1345 | g_free(image_corrected_msg); |
|
3ce21b5a182c
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents:
17005
diff
changeset
|
1346 | |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1347 | date = log_get_timestamp(log, time); |
| 7882 | 1348 | |
| 15884 | 1349 | if(log->type == PURPLE_LOG_SYSTEM){ |
| 13059 | 1350 | written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
| 8577 | 1351 | } else { |
| 15884 | 1352 | if (type & PURPLE_MESSAGE_SYSTEM) |
| 13059 | 1353 | written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); |
| 15884 | 1354 | else if (type & PURPLE_MESSAGE_RAW) |
|
15483
bfcce3ec6848
Patch #1600087 from Richard 'wabz' Nelson: "Don't include a buddy's name when logging error/raw messages"
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15444
diff
changeset
|
1355 | written += fprintf(data->file, "<font size=\"2\">(%s)</font> %s<br/>\n", date, msg_fixed); |
| 15884 | 1356 | else if (type & PURPLE_MESSAGE_ERROR) |
|
13069
37b879f161f4
[gaim-migrate @ 15431]
Richard Laager <rlaager@pidgin.im>
parents:
13068
diff
changeset
|
1357 | written += fprintf(data->file, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed); |
| 15884 | 1358 | else if (type & PURPLE_MESSAGE_AUTO_RESP) { |
| 1359 | if (type & PURPLE_MESSAGE_SEND) | |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1360 | written += fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, escaped_from, msg_fixed); |
| 15884 | 1361 | else if (type & PURPLE_MESSAGE_RECV) |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1362 | written += fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, escaped_from, msg_fixed); |
| 15884 | 1363 | } else if (type & PURPLE_MESSAGE_RECV) { |
| 1364 | if(purple_message_meify(msg_fixed, -1)) | |
| 13059 | 1365 | written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1366 | date, escaped_from, msg_fixed); |
| 8577 | 1367 | else |
| 13059 | 1368 | written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1369 | date, escaped_from, msg_fixed); |
| 15884 | 1370 | } else if (type & PURPLE_MESSAGE_SEND) { |
| 1371 | if(purple_message_meify(msg_fixed, -1)) | |
| 13059 | 1372 | written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1373 | date, escaped_from, msg_fixed); |
| 8577 | 1374 | else |
| 13059 | 1375 | written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1376 | date, escaped_from, msg_fixed); |
|
13069
37b879f161f4
[gaim-migrate @ 15431]
Richard Laager <rlaager@pidgin.im>
parents:
13068
diff
changeset
|
1377 | } else { |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19224
diff
changeset
|
1378 | purple_debug_error("log", "Unhandled message type.\n"); |
|
13069
37b879f161f4
[gaim-migrate @ 15431]
Richard Laager <rlaager@pidgin.im>
parents:
13068
diff
changeset
|
1379 | written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1380 | date, escaped_from, msg_fixed); |
| 8577 | 1381 | } |
| 7564 | 1382 | } |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1383 | g_free(date); |
| 7882 | 1384 | g_free(msg_fixed); |
|
28119
3da0d6dbb454
log: Escape the "from" name in the HTML logger. Refs #9824.
Paul Aurich <darkrain42@pidgin.im>
parents:
27586
diff
changeset
|
1385 | g_free(escaped_from); |
| 7616 | 1386 | fflush(data->file); |
| 13059 | 1387 | |
| 1388 | return written; | |
| 7457 | 1389 | } |
| 1390 | ||
| 15884 | 1391 | static void html_logger_finalize(PurpleLog *log) |
| 7457 | 1392 | { |
| 15884 | 1393 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 7616 | 1394 | if (data) { |
| 1395 | if(data->file) { | |
|
12881
d4db623e3d8c
[gaim-migrate @ 15233]
Richard Laager <rlaager@pidgin.im>
parents:
12834
diff
changeset
|
1396 | fprintf(data->file, "</body></html>\n"); |
| 7616 | 1397 | fclose(data->file); |
| 1398 | } | |
| 1399 | g_free(data->path); | |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1400 | |
| 15884 | 1401 | g_slice_free(PurpleLogCommonLoggerData, data); |
| 7463 | 1402 | } |
| 7457 | 1403 | } |
| 1404 | ||
| 15884 | 1405 | static GList *html_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 7457 | 1406 | { |
| 15884 | 1407 | return purple_log_common_lister(type, sn, account, ".html", html_logger); |
| 7457 | 1408 | } |
| 1409 | ||
| 15884 | 1410 | static GList *html_logger_list_syslog(PurpleAccount *account) |
| 8573 | 1411 | { |
| 15884 | 1412 | return purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account, ".html", html_logger); |
| 8573 | 1413 | } |
| 1414 | ||
| 15884 | 1415 | static char *html_logger_read(PurpleLog *log, PurpleLogReadFlags *flags) |
| 7457 | 1416 | { |
|
12958
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1417 | char *read; |
| 15884 | 1418 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 1419 | *flags = PURPLE_LOG_READ_NO_NEWLINE; | |
| 7616 | 1420 | if (!data || !data->path) |
| 1421 | return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 1422 | if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
|
12958
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1423 | char *minus_header = strchr(read, '\n'); |
|
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1424 | |
| 7457 | 1425 | if (!minus_header) |
|
12958
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1426 | return read; |
|
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1427 | |
|
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1428 | minus_header = g_strdup(minus_header + 1); |
| 7457 | 1429 | g_free(read); |
|
12958
706645a0b944
[gaim-migrate @ 15311]
Richard Laager <rlaager@pidgin.im>
parents:
12881
diff
changeset
|
1430 | |
| 7457 | 1431 | return minus_header; |
| 1432 | } | |
| 8578 | 1433 | return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7457 | 1434 | } |
| 1435 | ||
| 15884 | 1436 | static int html_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account) |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1437 | { |
| 15884 | 1438 | return purple_log_common_total_sizer(type, name, account, ".html"); |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1439 | } |
| 7457 | 1440 | |
| 1441 | ||
| 1442 | /**************************** | |
| 7431 | 1443 | ** PLAIN TEXT LOGGER ******* |
| 1444 | ****************************/ | |
| 4184 | 1445 | |
| 15884 | 1446 | static gsize txt_logger_write(PurpleLog *log, |
| 1447 | PurpleMessageFlags type, | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1448 | const char *from, time_t time, const char *message) |
| 7431 | 1449 | { |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1450 | char *date; |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36371
diff
changeset
|
1451 | PurpleProtocol *protocol = |
|
36626
18fc361b3704
Renamed purple_find_protocol_info to purple_protocols_find
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
1452 | purple_protocols_find(purple_account_get_protocol_id(log->account)); |
| 15884 | 1453 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 9763 | 1454 | char *stripped = NULL; |
| 1455 | ||
| 13059 | 1456 | gsize written = 0; |
| 1457 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1458 | if (data == NULL) { |
| 7431 | 1459 | /* This log is new. We could use the loggers 'new' function, but |
| 1460 | * creating a new file there would result in empty files in the case | |
| 1461 | * that you open a convo with someone, but don't say anything. | |
| 1462 | */ | |
| 36719 | 1463 | const char *proto = purple_protocol_class_list_icon(protocol, log->account, NULL); |
| 15884 | 1464 | purple_log_common_writer(log, ".txt"); |
|
8898
85f5615bc27e
[gaim-migrate @ 9667]
Mark Doliner <markdoliner@pidgin.im>
parents:
8635
diff
changeset
|
1465 | |
| 9763 | 1466 | data = log->logger_data; |
| 7436 | 1467 | |
| 9763 | 1468 | /* if we can't write to the file, give up before we hurt ourselves */ |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35298
diff
changeset
|
1469 | if(!data || !data->file) |
| 13059 | 1470 | return 0; |
| 7616 | 1471 | |
| 15884 | 1472 | if (log->type == PURPLE_LOG_SYSTEM) |
|
13509
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1473 | written += fprintf(data->file, "System log for account %s (%s) connected at %s\n", |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36626
diff
changeset
|
1474 | purple_account_get_username(log->account), proto, |
| 15884 | 1475 | purple_date_format_full(localtime(&log->time))); |
|
13509
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1476 | else |
|
38ebac941c40
[gaim-migrate @ 15884]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13474
diff
changeset
|
1477 | written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
| 15884 | 1478 | log->name, purple_date_format_full(localtime(&log->time)), |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36626
diff
changeset
|
1479 | purple_account_get_username(log->account), proto); |
| 7431 | 1480 | } |
| 7436 | 1481 | |
| 7623 | 1482 | /* if we can't write to the file, give up before we hurt ourselves */ |
| 1483 | if(!data->file) | |
| 13059 | 1484 | return 0; |
| 7623 | 1485 | |
| 15884 | 1486 | stripped = purple_markup_strip_html(message); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1487 | date = log_get_timestamp(log, time); |
|
12692
249f9d844f6f
[gaim-migrate @ 15035]
Douglas Thrift <douglas@douglasthrift.net>
parents:
12574
diff
changeset
|
1488 | |
| 15884 | 1489 | if(log->type == PURPLE_LOG_SYSTEM){ |
| 13059 | 1490 | written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1491 | } else { |
| 15884 | 1492 | if (type & PURPLE_MESSAGE_SEND || |
| 1493 | type & PURPLE_MESSAGE_RECV) { | |
| 1494 | if (type & PURPLE_MESSAGE_AUTO_RESP) { | |
| 13059 | 1495 | written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1496 | from, stripped); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1497 | } else { |
| 15884 | 1498 | if(purple_message_meify(stripped, -1)) |
| 13059 | 1499 | written += fprintf(data->file, "(%s) ***%s %s\n", date, from, |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1500 | stripped); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1501 | else |
| 13059 | 1502 | written += fprintf(data->file, "(%s) %s: %s\n", date, from, |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1503 | stripped); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1504 | } |
| 15884 | 1505 | } else if (type & PURPLE_MESSAGE_SYSTEM || |
| 1506 | type & PURPLE_MESSAGE_ERROR || | |
| 1507 | type & PURPLE_MESSAGE_RAW) | |
| 13059 | 1508 | written += fprintf(data->file, "(%s) %s\n", date, stripped); |
| 15884 | 1509 | else if (type & PURPLE_MESSAGE_NO_LOG) { |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1510 | /* This shouldn't happen */ |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1511 | g_free(stripped); |
| 13059 | 1512 | return written; |
|
36086
5e1693f7c0d5
Remove whisper completely, fix flags property in PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36034
diff
changeset
|
1513 | } else |
| 13059 | 1514 | written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", |
|
12737
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1515 | from ? ":" : "", stripped); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1516 | } |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1517 | g_free(date); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1518 | g_free(stripped); |
|
e1300804318e
[gaim-migrate @ 15082]
Richard Laager <rlaager@pidgin.im>
parents:
12692
diff
changeset
|
1519 | fflush(data->file); |
| 13059 | 1520 | |
| 1521 | return written; | |
| 7431 | 1522 | } |
| 1523 | ||
| 15884 | 1524 | static void txt_logger_finalize(PurpleLog *log) |
| 7431 | 1525 | { |
| 15884 | 1526 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 7616 | 1527 | if (data) { |
| 1528 | if(data->file) | |
| 1529 | fclose(data->file); | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14068
diff
changeset
|
1530 | g_free(data->path); |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1531 | |
| 15884 | 1532 | g_slice_free(PurpleLogCommonLoggerData, data); |
| 7616 | 1533 | } |
| 7431 | 1534 | } |
| 1535 | ||
| 15884 | 1536 | static GList *txt_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 7431 | 1537 | { |
| 15884 | 1538 | return purple_log_common_lister(type, sn, account, ".txt", txt_logger); |
| 7431 | 1539 | } |
| 1540 | ||
| 15884 | 1541 | static GList *txt_logger_list_syslog(PurpleAccount *account) |
| 8573 | 1542 | { |
| 15884 | 1543 | return purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account, ".txt", txt_logger); |
| 8573 | 1544 | } |
| 1545 | ||
| 15884 | 1546 | static char *txt_logger_read(PurpleLog *log, PurpleLogReadFlags *flags) |
| 7431 | 1547 | { |
| 15676 | 1548 | char *read, *minus_header; |
| 15884 | 1549 | PurpleLogCommonLoggerData *data = log->logger_data; |
| 7457 | 1550 | *flags = 0; |
| 7616 | 1551 | if (!data || !data->path) |
| 1552 | return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 1553 | if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
| 7431 | 1554 | minus_header = strchr(read, '\n'); |
| 15594 | 1555 | |
| 1556 | if (minus_header) | |
| 1557 | return process_txt_log(minus_header + 1, read); | |
| 7436 | 1558 | else |
| 15594 | 1559 | return process_txt_log(read, NULL); |
| 7431 | 1560 | } |
| 8578 | 1561 | return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7436 | 1562 | } |
| 7431 | 1563 | |
| 15884 | 1564 | static int txt_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account) |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1565 | { |
| 15884 | 1566 | return purple_log_common_total_sizer(type, name, account, ".txt"); |
|
13389
27cf7d84dfd1
[gaim-migrate @ 15761]
Richard Laager <rlaager@pidgin.im>
parents:
13358
diff
changeset
|
1567 | } |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1568 | |
| 7431 | 1569 | |
| 1570 | /**************** | |
| 1571 | * OLD LOGGER *** | |
| 1572 | ****************/ | |
| 1573 | ||
| 1574 | /* The old logger doesn't write logs, only reads them. This is to include | |
| 1575 | * old logs in the log viewer transparently. | |
| 1576 | */ | |
| 1577 | ||
| 1578 | struct old_logger_data { | |
| 15884 | 1579 | PurpleStringref *pathref; |
| 7431 | 1580 | int offset; |
| 1581 | int length; | |
| 1582 | }; | |
| 1583 | ||
| 15884 | 1584 | static GList *old_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 7431 | 1585 | { |
| 15884 | 1586 | char *logfile = g_strdup_printf("%s.log", purple_normalize(account, sn)); |
| 1587 | char *pathstr = g_build_filename(purple_user_dir(), "logs", logfile, NULL); | |
| 1588 | PurpleStringref *pathref = purple_stringref_new(pathstr); | |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33774
diff
changeset
|
1589 | GStatBuf st; |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1590 | time_t log_last_modified; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1591 | FILE *index; |
| 7431 | 1592 | FILE *file; |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1593 | int file_fd, index_fd; |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1594 | char *index_tmp; |
| 7431 | 1595 | char buf[BUF_LONG]; |
| 1596 | struct tm tm; | |
| 7761 | 1597 | char month[4]; |
| 7431 | 1598 | struct old_logger_data *data = NULL; |
| 7761 | 1599 | int logfound = 0; |
| 1600 | int lastoff = 0; | |
| 1601 | int newlen; | |
| 7791 | 1602 | time_t lasttime = 0; |
| 7431 | 1603 | |
| 15884 | 1604 | PurpleLog *log = NULL; |
| 7431 | 1605 | GList *list = NULL; |
| 1606 | ||
|
7473
881da47ca83f
[gaim-migrate @ 8086]
Mark Doliner <markdoliner@pidgin.im>
parents:
7472
diff
changeset
|
1607 | g_free(logfile); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1608 | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1609 | file_fd = g_open(purple_stringref_value(pathref), 0, O_RDONLY); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1610 | if (file_fd == -1 || (file = fdopen(file_fd, "rb")) == NULL) { |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1611 | purple_debug_error("log", |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1612 | "Failed to open log file \"%s\" for reading: %s\n", |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1613 | purple_stringref_value(pathref), g_strerror(errno)); |
| 15884 | 1614 | purple_stringref_unref(pathref); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1615 | g_free(pathstr); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1616 | return NULL; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1617 | } |
|
36034
4bba5ea5d08a
Provide a portable alternative for fstat
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36031
diff
changeset
|
1618 | if (_purple_fstat(file_fd, &st) == -1) { |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1619 | purple_stringref_unref(pathref); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1620 | g_free(pathstr); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1621 | fclose(file); |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1622 | return NULL; |
|
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1623 | } else |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1624 | log_last_modified = st.st_mtime; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1625 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1626 | /* Change the .log extension to .idx */ |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1627 | strcpy(pathstr + strlen(pathstr) - 3, "idx"); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1628 | |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1629 | index_fd = g_open(pathstr, 0, O_RDONLY); |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1630 | if (index_fd != -1) { |
|
36034
4bba5ea5d08a
Provide a portable alternative for fstat
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36031
diff
changeset
|
1631 | if (_purple_fstat(index_fd, &st) != 0) { |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1632 | close(index_fd); |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1633 | index_fd = -1; |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1634 | } |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1635 | } |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1636 | |
|
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1637 | if (index_fd != -1) { |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1638 | if (st.st_mtime < log_last_modified) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1639 | { |
| 15884 | 1640 | purple_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr); |
|
36027
175e769076e1
Fix newly generated coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35995
diff
changeset
|
1641 | close(index_fd); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1642 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1643 | else |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1644 | { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1645 | /* The index file exists and is at least as new as the log, so open it. */ |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1646 | if (!(index = fdopen(index_fd, "rb"))) { |
| 15884 | 1647 | purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
1648 | pathstr, g_strerror(errno)); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1649 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1650 | /* Fall through so that we'll parse the log file. */ |
|
35995
d0bbb2dad7f3
Fix some CWE-367 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35992
diff
changeset
|
1651 | } else { |
| 15884 | 1652 | purple_debug_info("log", "Using index: %s\n", pathstr); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1653 | g_free(pathstr); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1654 | while (fgets(buf, BUF_LONG, index)) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1655 | { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1656 | unsigned long idx_time; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1657 | if (sscanf(buf, "%d\t%d\t%lu", &lastoff, &newlen, &idx_time) == 3) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1658 | { |
| 15884 | 1659 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, -1, NULL); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1660 | log->logger = old_logger; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1661 | log->time = (time_t)idx_time; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1662 | |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1663 | /* IMPORTANT: Always set all members of struct old_logger_data */ |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1664 | data = g_slice_new(struct old_logger_data); |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1665 | |
| 15884 | 1666 | data->pathref = purple_stringref_ref(pathref); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1667 | data->offset = lastoff; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1668 | data->length = newlen; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1669 | |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1670 | log->logger_data = data; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1671 | list = g_list_prepend(list, log); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1672 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1673 | } |
|
13469
6c9da180e40d
[gaim-migrate @ 15843]
Richard Laager <rlaager@pidgin.im>
parents:
13412
diff
changeset
|
1674 | fclose(index); |
|
22599
7987eb3eb3e6
Fix a couple of memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22189
diff
changeset
|
1675 | purple_stringref_unref(pathref); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1676 | |
|
36030
9a2250c4e9d1
Fix Coverity TOCTOU warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36027
diff
changeset
|
1677 | fclose(file); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1678 | return list; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1679 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1680 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1681 | } |
|
7473
881da47ca83f
[gaim-migrate @ 8086]
Mark Doliner <markdoliner@pidgin.im>
parents:
7472
diff
changeset
|
1682 | |
|
13473
8fe2387d215b
[gaim-migrate @ 15848]
Richard Laager <rlaager@pidgin.im>
parents:
13472
diff
changeset
|
1683 | index_tmp = g_strdup_printf("%s.XXXXXX", pathstr); |
|
8fe2387d215b
[gaim-migrate @ 15848]
Richard Laager <rlaager@pidgin.im>
parents:
13472
diff
changeset
|
1684 | if ((index_fd = g_mkstemp(index_tmp)) == -1) { |
| 15884 | 1685 | purple_debug_error("log", "Failed to open index temp file: %s\n", |
| 33596 | 1686 | g_strerror(errno)); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1687 | g_free(pathstr); |
|
13473
8fe2387d215b
[gaim-migrate @ 15848]
Richard Laager <rlaager@pidgin.im>
parents:
13472
diff
changeset
|
1688 | g_free(index_tmp); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1689 | index = NULL; |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1690 | } else { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1691 | if ((index = fdopen(index_fd, "wb")) == NULL) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1692 | { |
| 15884 | 1693 | purple_debug_error("log", "Failed to fdopen() index temp file: %s\n", |
| 33596 | 1694 | g_strerror(errno)); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1695 | close(index_fd); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1696 | if (index_tmp != NULL) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1697 | { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1698 | g_unlink(index_tmp); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1699 | g_free(index_tmp); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1700 | } |
|
13412
67ef3053ef45
[gaim-migrate @ 15786]
Richard Laager <rlaager@pidgin.im>
parents:
13407
diff
changeset
|
1701 | g_free(pathstr); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1702 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1703 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1704 | |
| 7431 | 1705 | while (fgets(buf, BUF_LONG, file)) { |
|
30626
bec413ce77c7
Fix some "Dead nested assignment"s and then kill off some useless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
29801
diff
changeset
|
1706 | if (strstr(buf, "---- New C") != NULL) { |
| 7431 | 1707 | int length; |
| 1708 | int offset; | |
| 1709 | char convostart[32]; | |
| 1710 | char *temp = strchr(buf, '@'); | |
| 7436 | 1711 | |
| 7431 | 1712 | if (temp == NULL || strlen(temp) < 2) |
| 1713 | continue; | |
| 7436 | 1714 | |
| 7431 | 1715 | temp++; |
| 1716 | length = strcspn(temp, "-"); | |
| 1717 | if (length > 31) length = 31; | |
| 7436 | 1718 | |
| 7431 | 1719 | offset = ftell(file); |
| 7436 | 1720 | |
| 7761 | 1721 | if (logfound) { |
| 1722 | newlen = offset - lastoff - length; | |
| 7436 | 1723 | if(strstr(buf, "----</H3><BR>")) { |
| 7761 | 1724 | newlen -= |
| 1725 | sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
| 1726 | sizeof("----</H3><BR>") - 2; | |
| 7436 | 1727 | } else { |
| 7761 | 1728 | newlen -= |
| 1729 | sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
| 7436 | 1730 | } |
| 1731 | ||
| 7461 | 1732 | if(strchr(buf, '\r')) |
| 7770 | 1733 | newlen--; |
| 7461 | 1734 | |
| 7761 | 1735 | if (newlen != 0) { |
| 15884 | 1736 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, -1, NULL); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1737 | log->logger = old_logger; |
| 7761 | 1738 | log->time = lasttime; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1739 | |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1740 | /* IMPORTANT: Always set all members of struct old_logger_data */ |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1741 | data = g_slice_new(struct old_logger_data); |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1742 | |
| 15884 | 1743 | data->pathref = purple_stringref_ref(pathref); |
| 7761 | 1744 | data->offset = lastoff; |
| 1745 | data->length = newlen; | |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1746 | |
| 7761 | 1747 | log->logger_data = data; |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
1748 | list = g_list_prepend(list, log); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1749 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1750 | if (index != NULL) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1751 | fprintf(index, "%d\t%d\t%lu\n", data->offset, data->length, (unsigned long)log->time); |
| 7761 | 1752 | } |
| 7431 | 1753 | } |
| 1754 | ||
| 7761 | 1755 | logfound = 1; |
| 1756 | lastoff = offset; | |
| 7436 | 1757 | |
| 7431 | 1758 | g_snprintf(convostart, length, "%s", temp); |
|
22850
573b2ea02083
Keep valgrind happy by zeroing out the tm struct before we stuff our
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22599
diff
changeset
|
1759 | memset(&tm, 0, sizeof(tm)); |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1760 | if (sscanf(convostart, "%*s %3s %d %d:%d:%d %d", month, |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1761 | &tm.tm_mday, &tm.tm_hour, &tm.tm_min, |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1762 | &tm.tm_sec, &tm.tm_year) != 6) |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1763 | { |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1764 | purple_debug_warning("log", "invalid date format\n"); |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1765 | } |
| 7676 | 1766 | /* Ugly hack, in case current locale is not English */ |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1767 | if (purple_strequal(month, "Jan")) { |
| 7676 | 1768 | tm.tm_mon= 0; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1769 | } else if (purple_strequal(month, "Feb")) { |
| 7676 | 1770 | tm.tm_mon = 1; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1771 | } else if (purple_strequal(month, "Mar")) { |
| 7676 | 1772 | tm.tm_mon = 2; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1773 | } else if (purple_strequal(month, "Apr")) { |
| 7676 | 1774 | tm.tm_mon = 3; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1775 | } else if (purple_strequal(month, "May")) { |
| 7676 | 1776 | tm.tm_mon = 4; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1777 | } else if (purple_strequal(month, "Jun")) { |
| 7676 | 1778 | tm.tm_mon = 5; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1779 | } else if (purple_strequal(month, "Jul")) { |
| 7676 | 1780 | tm.tm_mon = 6; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1781 | } else if (purple_strequal(month, "Aug")) { |
| 7676 | 1782 | tm.tm_mon = 7; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1783 | } else if (purple_strequal(month, "Sep")) { |
| 7676 | 1784 | tm.tm_mon = 8; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1785 | } else if (purple_strequal(month, "Oct")) { |
| 7676 | 1786 | tm.tm_mon = 9; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1787 | } else if (purple_strequal(month, "Nov")) { |
| 7676 | 1788 | tm.tm_mon = 10; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1789 | } else if (purple_strequal(month, "Dec")) { |
| 7676 | 1790 | tm.tm_mon = 11; |
| 1791 | } | |
| 1792 | tm.tm_year -= 1900; | |
| 7761 | 1793 | lasttime = mktime(&tm); |
| 4184 | 1794 | } |
| 1795 | } | |
| 7613 | 1796 | |
| 7761 | 1797 | if (logfound) { |
| 1798 | if ((newlen = ftell(file) - lastoff) != 0) { | |
| 15884 | 1799 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, -1, NULL); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11458
diff
changeset
|
1800 | log->logger = old_logger; |
| 7761 | 1801 | log->time = lasttime; |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1802 | |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1803 | /* IMPORTANT: Always set all members of struct old_logger_data */ |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1804 | data = g_slice_new(struct old_logger_data); |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1805 | |
| 15884 | 1806 | data->pathref = purple_stringref_ref(pathref); |
| 7761 | 1807 | data->offset = lastoff; |
| 1808 | data->length = newlen; | |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1809 | |
| 7761 | 1810 | log->logger_data = data; |
|
11703
6b22ef099870
[gaim-migrate @ 13994]
Richard Laager <rlaager@pidgin.im>
parents:
11698
diff
changeset
|
1811 | list = g_list_prepend(list, log); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1812 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1813 | if (index != NULL) |
|
33597
8ab5ed149286
Cleanup the time_t handling in log.c
Richard Laager <rlaager@pidgin.im>
parents:
33596
diff
changeset
|
1814 | fprintf(index, "%d\t%d\t%lu\n", data->offset, data->length, (unsigned long)log->time); |
| 7761 | 1815 | } |
| 7613 | 1816 | } |
| 1817 | ||
| 15884 | 1818 | purple_stringref_unref(pathref); |
| 7431 | 1819 | fclose(file); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1820 | if (index != NULL) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1821 | { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1822 | fclose(index); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1823 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1824 | if (index_tmp == NULL) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1825 | { |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1826 | g_free(pathstr); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1827 | g_return_val_if_reached(list); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1828 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1829 | |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1830 | if (g_rename(index_tmp, pathstr)) |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1831 | { |
| 15884 | 1832 | purple_debug_warning("log", "Failed to rename index temp file \"%s\" to \"%s\": %s\n", |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20147
diff
changeset
|
1833 | index_tmp, pathstr, g_strerror(errno)); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1834 | g_unlink(index_tmp); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1835 | } |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1836 | else |
| 15884 | 1837 | purple_debug_info("log", "Built index: %s\n", pathstr); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1838 | |
|
22599
7987eb3eb3e6
Fix a couple of memory leaks
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22189
diff
changeset
|
1839 | g_free(index_tmp); |
|
13407
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1840 | g_free(pathstr); |
|
8b5d4dc349b1
[gaim-migrate @ 15781]
Richard Laager <rlaager@pidgin.im>
parents:
13389
diff
changeset
|
1841 | } |
| 7431 | 1842 | return list; |
| 4184 | 1843 | } |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1844 | |
| 15884 | 1845 | static int old_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account) |
| 8096 | 1846 | { |
| 15884 | 1847 | char *logfile = g_strdup_printf("%s.log", purple_normalize(account, name)); |
| 1848 | char *pathstr = g_build_filename(purple_user_dir(), "logs", logfile, NULL); | |
| 8096 | 1849 | int size; |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33774
diff
changeset
|
1850 | GStatBuf st; |
| 8096 | 1851 | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10577
diff
changeset
|
1852 | if (g_stat(pathstr, &st)) |
| 8096 | 1853 | size = 0; |
| 1854 | else | |
| 1855 | size = st.st_size; | |
| 1856 | ||
| 1857 | g_free(logfile); | |
| 1858 | g_free(pathstr); | |
| 1859 | ||
| 1860 | return size; | |
| 1861 | } | |
| 1862 | ||
| 15884 | 1863 | static char * old_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1864 | { |
|
22189
641712d18a3d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21985
diff
changeset
|
1865 | size_t result; |
| 7431 | 1866 | struct old_logger_data *data = log->logger_data; |
|
22189
641712d18a3d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21985
diff
changeset
|
1867 | const char *path = purple_stringref_value(data->pathref); |
|
641712d18a3d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21985
diff
changeset
|
1868 | FILE *file = g_fopen(path, "rb"); |
|
35992
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
1869 | char *read; |
|
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
1870 | |
|
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
1871 | g_return_val_if_fail(file, g_strdup("")); |
|
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
1872 | read = g_malloc(data->length + 1); |
|
34a67264df99
Fix some CWE-476 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
1873 | |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1874 | if (fseek(file, data->offset, SEEK_SET) != 0) |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1875 | result = 0; |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1876 | else |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35252
diff
changeset
|
1877 | result = fread(read, data->length, 1, file); |
|
22189
641712d18a3d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21985
diff
changeset
|
1878 | if (result != 1) |
|
641712d18a3d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21985
diff
changeset
|
1879 | purple_debug_error("log", "Unable to read from log file: %s\n", path); |
|
8370
ce5393bfcf57
[gaim-migrate @ 9097]
Mark Doliner <markdoliner@pidgin.im>
parents:
8111
diff
changeset
|
1880 | fclose(file); |
| 7431 | 1881 | read[data->length] = '\0'; |
| 7436 | 1882 | *flags = 0; |
| 15594 | 1883 | if (strstr(read, "<BR>")) |
| 1884 | { | |
| 15884 | 1885 | *flags |= PURPLE_LOG_READ_NO_NEWLINE; |
| 15594 | 1886 | return read; |
|
10906
1825ffb6b495
[gaim-migrate @ 12636]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10822
diff
changeset
|
1887 | } |
| 15594 | 1888 | |
| 1889 | return process_txt_log(read, NULL); | |
| 7431 | 1890 | } |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1891 | |
| 15884 | 1892 | static int old_logger_size (PurpleLog *log) |
| 7556 | 1893 | { |
| 1894 | struct old_logger_data *data = log->logger_data; | |
| 7616 | 1895 | return data ? data->length : 0; |
| 1896 | } | |
| 1897 | ||
| 15884 | 1898 | static void old_logger_get_log_sets(PurpleLogSetCallback cb, GHashTable *sets) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1899 | { |
| 15884 | 1900 | char *log_path = g_build_filename(purple_user_dir(), "logs", NULL); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1901 | GDir *log_dir = g_dir_open(log_path, 0, NULL); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1902 | gchar *name; |
| 15884 | 1903 | PurpleBlistNode *gnode, *cnode, *bnode; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1904 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1905 | g_free(log_path); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1906 | if (log_dir == NULL) |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1907 | return; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1908 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1909 | /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1910 | while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1911 | size_t len; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1912 | gchar *ext; |
| 15884 | 1913 | PurpleLogSet *set; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1914 | gboolean found = FALSE; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1915 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1916 | /* Unescape the filename. */ |
| 15884 | 1917 | name = g_strdup(purple_unescape_filename(name)); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1918 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1919 | /* Get the (possibly new) length of name. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1920 | len = strlen(name); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1921 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1922 | if (len < 5) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1923 | g_free(name); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1924 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1925 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1926 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1927 | /* Make sure we're dealing with a log file. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1928 | ext = &name[len - 4]; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1929 | if (!purple_strequal(ext, ".log")) { |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1930 | g_free(name); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1931 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1932 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1933 | |
| 15884 | 1934 | /* IMPORTANT: Always set all members of PurpleLogSet */ |
| 1935 | set = g_slice_new(PurpleLogSet); | |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1936 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1937 | /* Chat for .chat at the end of the name to determine the type. */ |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1938 | *ext = '\0'; |
| 15884 | 1939 | set->type = PURPLE_LOG_IM; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1940 | if (len > 9) { |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1941 | char *tmp = &name[len - 9]; |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1942 | if (purple_strequal(tmp, ".chat")) { |
| 15884 | 1943 | set->type = PURPLE_LOG_CHAT; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1944 | *tmp = '\0'; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1945 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1946 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1947 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1948 | set->name = set->normalized_name = name; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1949 | |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1950 | /* Search the buddy list to find the account and to determine if this is a buddy. */ |
|
24955
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1951 | for (gnode = purple_blist_get_root(); |
|
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1952 | !found && gnode != NULL; |
| 33596 | 1953 | gnode = purple_blist_node_get_sibling_next(gnode)) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1954 | { |
|
34696
6e0d13978666
Global replace to use GObject-style macros. See details.
Ankit Vani <a@nevitus.org>
parents:
33940
diff
changeset
|
1955 | if (!PURPLE_IS_GROUP(gnode)) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1956 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1957 | |
|
24955
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1958 | for (cnode = purple_blist_node_get_first_child(gnode); |
|
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1959 | !found && cnode != NULL; |
|
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1960 | cnode = purple_blist_node_get_sibling_next(cnode)) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1961 | { |
|
34696
6e0d13978666
Global replace to use GObject-style macros. See details.
Ankit Vani <a@nevitus.org>
parents:
33940
diff
changeset
|
1962 | if (!PURPLE_IS_CONTACT(cnode)) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1963 | continue; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1964 | |
|
24955
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1965 | for (bnode = purple_blist_node_get_first_child(cnode); |
|
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1966 | !found && bnode != NULL; |
| 33596 | 1967 | bnode = purple_blist_node_get_sibling_next(bnode)) |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1968 | { |
| 15884 | 1969 | PurpleBuddy *buddy = (PurpleBuddy *)bnode; |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1970 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
24971
diff
changeset
|
1971 | if (purple_strequal(purple_buddy_get_name(buddy), name)) { |
|
24955
77727fac30c6
Finish off the libpurple updates for the hidden blist structs
Gary Kramlich <grim@reaperworld.com>
parents:
24177
diff
changeset
|
1972 | set->account = purple_buddy_get_account(buddy); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1973 | set->buddy = TRUE; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1974 | found = TRUE; |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1975 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1976 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1977 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1978 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1979 | |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1980 | if (!found) |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1981 | { |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1982 | set->account = NULL; |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1983 | set->buddy = FALSE; |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1984 | } |
|
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1985 | |
|
11177
534ca3ae0bfc
[gaim-migrate @ 13285]
Richard Laager <rlaager@pidgin.im>
parents:
11094
diff
changeset
|
1986 | cb(sets, set); |
|
11025
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1987 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1988 | g_dir_close(log_dir); |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1989 | } |
|
41b6449f7dff
[gaim-migrate @ 12899]
Richard Laager <rlaager@pidgin.im>
parents:
10906
diff
changeset
|
1990 | |
| 15884 | 1991 | static void old_logger_finalize(PurpleLog *log) |
| 7616 | 1992 | { |
| 1993 | struct old_logger_data *data = log->logger_data; | |
| 15884 | 1994 | purple_stringref_unref(data->pathref); |
|
13624
c6577def4e2a
[gaim-migrate @ 16009]
Richard Laager <rlaager@pidgin.im>
parents:
13584
diff
changeset
|
1995 | g_slice_free(struct old_logger_data, data); |
| 7556 | 1996 | } |