Fri, 05 Oct 2007 05:18:11 +0000
Fix a small leak in the log_reader plugin.
| 11459 | 1 | #include <stdio.h> |
| 2 | ||
| 3 | #include "internal.h" | |
| 4 | ||
| 5 | #include "debug.h" | |
| 6 | #include "log.h" | |
| 7 | #include "plugin.h" | |
| 8 | #include "pluginpref.h" | |
| 9 | #include "prefs.h" | |
| 10 | #include "stringref.h" | |
| 11 | #include "util.h" | |
| 12 | #include "version.h" | |
| 13 | #include "xmlnode.h" | |
| 14 | ||
| 15884 | 15 | /* This must be the last Purple header included. */ |
| 11459 | 16 | #ifdef _WIN32 |
| 17 | #include "win32dep.h" | |
| 18 | #endif | |
| 19 | ||
| 20 | /* Where is the Windows partition mounted? */ | |
| 15884 | 21 | #ifndef PURPLE_LOG_READER_WINDOWS_MOUNT_POINT |
| 22 | #define PURPLE_LOG_READER_WINDOWS_MOUNT_POINT "/mnt/windows" | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
23 | #endif |
| 11459 | 24 | |
| 25 | enum name_guesses { | |
| 26 | NAME_GUESS_UNKNOWN, | |
| 27 | NAME_GUESS_ME, | |
| 28 | NAME_GUESS_THEM | |
| 29 | }; | |
| 30 | ||
| 31 | ||
| 32 | /***************************************************************************** | |
| 33 | * Adium Logger * | |
| 34 | *****************************************************************************/ | |
| 35 | ||
| 36 | /* The adium logger doesn't write logs, only reads them. This is to include | |
| 37 | * Adium logs in the log viewer transparently. | |
| 38 | */ | |
| 39 | ||
| 15884 | 40 | static PurpleLogLogger *adium_logger; |
| 11459 | 41 | |
| 42 | enum adium_log_type { | |
| 43 | ADIUM_HTML, | |
| 44 | ADIUM_TEXT, | |
| 45 | }; | |
| 46 | ||
| 47 | struct adium_logger_data { | |
| 48 | char *path; | |
| 49 | enum adium_log_type type; | |
| 50 | }; | |
| 51 | ||
| 15884 | 52 | static GList *adium_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 11459 | 53 | { |
| 54 | GList *list = NULL; | |
| 55 | const char *logdir; | |
| 15884 | 56 | PurplePlugin *plugin; |
| 57 | PurplePluginProtocolInfo *prpl_info; | |
| 11459 | 58 | char *prpl_name; |
| 59 | char *temp; | |
| 60 | char *path; | |
| 61 | GDir *dir; | |
| 62 | ||
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
63 | g_return_val_if_fail(sn != NULL, NULL); |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
64 | g_return_val_if_fail(account != NULL, NULL); |
| 11459 | 65 | |
| 16481 | 66 | logdir = purple_prefs_get_string("/plugins/core/log_reader/adium/log_directory"); |
| 11459 | 67 | |
| 68 | /* By clearing the log directory path, this logger can be (effectively) disabled. */ | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
69 | if (!logdir || !*logdir) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
70 | return NULL; |
| 11459 | 71 | |
| 15884 | 72 | plugin = purple_find_prpl(purple_account_get_protocol_id(account)); |
| 11459 | 73 | if (!plugin) |
| 74 | return NULL; | |
| 75 | ||
| 15884 | 76 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
| 11459 | 77 | if (!prpl_info->list_icon) |
| 78 | return NULL; | |
| 79 | ||
| 80 | prpl_name = g_ascii_strup(prpl_info->list_icon(account, NULL), -1); | |
| 81 | ||
| 82 | temp = g_strdup_printf("%s.%s", prpl_name, account->username); | |
| 83 | path = g_build_filename(logdir, temp, sn, NULL); | |
| 84 | g_free(temp); | |
| 85 | ||
| 86 | dir = g_dir_open(path, 0, NULL); | |
| 87 | if (dir) { | |
| 88 | const gchar *file; | |
| 89 | ||
| 90 | while ((file = g_dir_read_name(dir))) { | |
| 15884 | 91 | if (!purple_str_has_prefix(file, sn)) |
| 11459 | 92 | continue; |
| 15884 | 93 | if (purple_str_has_suffix(file, ".html") || purple_str_has_suffix(file, ".AdiumHTMLLog")) { |
| 11459 | 94 | struct tm tm; |
| 95 | const char *date = file; | |
| 96 | ||
| 97 | date += strlen(sn) + 2; | |
| 98 | if (sscanf(date, "%u|%u|%u", | |
| 99 | &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { | |
| 100 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
101 | purple_debug_error("Adium log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
102 | "Filename timestamp parsing error\n"); |
| 11459 | 103 | } else { |
| 104 | char *filename = g_build_filename(path, file, NULL); | |
|
13158
3b4295931fd6
[gaim-migrate @ 15520]
Richard Laager <rlaager@pidgin.im>
parents:
13120
diff
changeset
|
105 | FILE *handle = g_fopen(filename, "rb"); |
| 11459 | 106 | char *contents; |
| 107 | char *contents2; | |
| 108 | struct adium_logger_data *data; | |
| 15884 | 109 | PurpleLog *log; |
| 11459 | 110 | |
| 111 | if (!handle) { | |
| 112 | g_free(filename); | |
| 113 | continue; | |
| 114 | } | |
| 115 | ||
| 116 | /* XXX: This is really inflexible. */ | |
| 117 | contents = g_malloc(57); | |
| 118 | fread(contents, 56, 1, handle); | |
| 119 | fclose(handle); | |
| 120 | contents[56] = '\0'; | |
| 121 | ||
| 122 | /* XXX: This is fairly inflexible. */ | |
| 123 | contents2 = contents; | |
| 124 | while (*contents2 && *contents2 != '>') | |
| 125 | contents2++; | |
| 126 | if (*contents2) | |
| 127 | contents2++; | |
| 128 | while (*contents2 && *contents2 != '>') | |
| 129 | contents2++; | |
| 130 | if (*contents2) | |
| 131 | contents2++; | |
| 132 | ||
| 133 | if (sscanf(contents2, "%u.%u.%u", | |
| 134 | &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { | |
| 135 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
136 | purple_debug_error("Adium log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
137 | "Contents timestamp parsing error\n"); |
| 11459 | 138 | g_free(contents); |
| 139 | g_free(filename); | |
| 140 | continue; | |
| 141 | } | |
| 142 | g_free(contents); | |
| 143 | ||
| 144 | data = g_new0(struct adium_logger_data, 1); | |
| 145 | data->path = filename; | |
| 146 | data->type = ADIUM_HTML; | |
| 147 | ||
| 148 | tm.tm_year -= 1900; | |
| 149 | tm.tm_mon -= 1; | |
| 150 | ||
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12727
diff
changeset
|
151 | /* XXX: Look into this later... Should we pass in a struct tm? */ |
| 15884 | 152 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
153 | log->logger = adium_logger; |
| 11459 | 154 | log->logger_data = data; |
| 155 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
156 | list = g_list_prepend(list, log); |
| 11459 | 157 | } |
| 15884 | 158 | } else if (purple_str_has_suffix(file, ".adiumLog")) { |
| 11459 | 159 | struct tm tm; |
| 160 | const char *date = file; | |
| 161 | ||
| 162 | date += strlen(sn) + 2; | |
| 163 | if (sscanf(date, "%u|%u|%u", | |
| 164 | &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { | |
| 165 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
166 | purple_debug_error("Adium log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
167 | "Filename timestamp parsing error\n"); |
| 11459 | 168 | } else { |
| 169 | char *filename = g_build_filename(path, file, NULL); | |
|
13158
3b4295931fd6
[gaim-migrate @ 15520]
Richard Laager <rlaager@pidgin.im>
parents:
13120
diff
changeset
|
170 | FILE *handle = g_fopen(filename, "rb"); |
| 11459 | 171 | char *contents; |
| 172 | char *contents2; | |
| 173 | struct adium_logger_data *data; | |
| 15884 | 174 | PurpleLog *log; |
| 11459 | 175 | |
| 176 | if (!handle) { | |
| 177 | g_free(filename); | |
| 178 | continue; | |
| 179 | } | |
| 180 | ||
| 181 | /* XXX: This is really inflexible. */ | |
| 182 | contents = g_malloc(14); | |
| 183 | fread(contents, 13, 1, handle); | |
| 184 | fclose(handle); | |
| 185 | contents[13] = '\0'; | |
| 186 | ||
| 187 | contents2 = contents; | |
| 188 | while (*contents2 && *contents2 != '(') | |
| 189 | contents2++; | |
| 190 | if (*contents2) | |
| 191 | contents2++; | |
| 192 | ||
| 193 | if (sscanf(contents2, "%u.%u.%u", | |
| 194 | &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { | |
| 195 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
196 | purple_debug_error("Adium log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
197 | "Contents timestamp parsing error\n"); |
| 11459 | 198 | g_free(contents); |
| 199 | g_free(filename); | |
| 200 | continue; | |
| 201 | } | |
| 202 | ||
| 203 | g_free(contents); | |
| 204 | ||
| 205 | tm.tm_year -= 1900; | |
| 206 | tm.tm_mon -= 1; | |
| 207 | ||
| 208 | data = g_new0(struct adium_logger_data, 1); | |
| 209 | data->path = filename; | |
| 210 | data->type = ADIUM_TEXT; | |
| 211 | ||
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12727
diff
changeset
|
212 | /* XXX: Look into this later... Should we pass in a struct tm? */ |
| 15884 | 213 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
214 | log->logger = adium_logger; |
| 11459 | 215 | log->logger_data = data; |
| 216 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
217 | list = g_list_prepend(list, log); |
| 11459 | 218 | } |
| 219 | } | |
| 220 | } | |
| 221 | g_dir_close(dir); | |
| 222 | } | |
| 223 | ||
| 224 | g_free(prpl_name); | |
| 225 | g_free(path); | |
| 226 | ||
| 227 | return list; | |
| 228 | } | |
| 229 | ||
| 15884 | 230 | static char *adium_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
| 11459 | 231 | { |
| 232 | struct adium_logger_data *data; | |
| 233 | GError *error = NULL; | |
| 234 | gchar *read = NULL; | |
| 235 | gsize length; | |
| 236 | ||
| 18531 | 237 | /* XXX: TODO: We probably want to set PURPLE_LOG_READ_NO_NEWLINE |
|
18529
568e24f22c2d
Make the Adium logger set flags, though it's still very much a stub.
Richard Laager <rlaager@pidgin.im>
parents:
18527
diff
changeset
|
238 | * XXX: TODO: for HTML logs. */ |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
239 | if (flags != NULL) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
240 | *flags = 0; |
|
18529
568e24f22c2d
Make the Adium logger set flags, though it's still very much a stub.
Richard Laager <rlaager@pidgin.im>
parents:
18527
diff
changeset
|
241 | |
| 11459 | 242 | g_return_val_if_fail(log != NULL, g_strdup("")); |
| 243 | ||
| 244 | data = log->logger_data; | |
| 245 | ||
| 246 | g_return_val_if_fail(data->path != NULL, g_strdup("")); | |
| 247 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
248 | purple_debug_info("Adium log read", "Reading %s\n", data->path); |
| 11459 | 249 | if (!g_file_get_contents(data->path, &read, &length, &error)) { |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
250 | purple_debug_error("Adium log read", "Error reading log\n"); |
| 11459 | 251 | if (error) |
| 252 | g_error_free(error); | |
| 253 | return g_strdup(""); | |
| 254 | } | |
| 255 | ||
| 256 | if (data->type != ADIUM_HTML) { | |
| 257 | char *escaped = g_markup_escape_text(read, -1); | |
| 258 | g_free(read); | |
| 259 | read = escaped; | |
| 260 | } | |
| 261 | ||
| 262 | #ifdef WIN32 | |
| 263 | /* This problem only seems to show up on Windows. | |
| 264 | * The BOM is displaying as a space at the beginning of the log. | |
| 265 | */ | |
| 15884 | 266 | if (purple_str_has_prefix(read, "\xef\xbb\xbf")) |
| 11459 | 267 | { |
| 268 | /* FIXME: This feels so wrong... */ | |
| 269 | char *temp = g_strdup(&(read[3])); | |
| 270 | g_free(read); | |
| 271 | read = temp; | |
| 272 | } | |
| 273 | #endif | |
| 274 | ||
| 275 | /* TODO: Apply formatting. | |
| 276 | * Replace the above hack with something better, since we'll | |
| 277 | * be looping over the entire log file contents anyway. | |
| 278 | */ | |
| 279 | ||
| 280 | return read; | |
| 281 | } | |
| 282 | ||
| 15884 | 283 | static int adium_logger_size (PurpleLog *log) |
| 11459 | 284 | { |
| 285 | struct adium_logger_data *data; | |
| 286 | char *text; | |
| 287 | size_t size; | |
| 288 | ||
| 289 | g_return_val_if_fail(log != NULL, 0); | |
| 290 | ||
| 291 | data = log->logger_data; | |
| 292 | ||
| 16481 | 293 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) { |
| 11459 | 294 | struct stat st; |
| 295 | ||
| 296 | if (!data->path || stat(data->path, &st)) | |
| 297 | st.st_size = 0; | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13702
diff
changeset
|
298 | |
| 11459 | 299 | return st.st_size; |
| 300 | } | |
| 301 | ||
| 302 | text = adium_logger_read(log, NULL); | |
| 303 | size = strlen(text); | |
| 304 | g_free(text); | |
| 305 | ||
| 306 | return size; | |
| 307 | } | |
| 308 | ||
| 15884 | 309 | static void adium_logger_finalize(PurpleLog *log) |
| 11459 | 310 | { |
| 311 | struct adium_logger_data *data; | |
| 312 | ||
| 313 | g_return_if_fail(log != NULL); | |
| 314 | ||
| 315 | data = log->logger_data; | |
| 316 | ||
| 317 | g_free(data->path); | |
| 18513 | 318 | g_free(data); |
| 11459 | 319 | } |
| 320 | ||
| 321 | ||
| 322 | /***************************************************************************** | |
| 323 | * Fire Logger * | |
| 324 | *****************************************************************************/ | |
| 325 | ||
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
326 | #if 0 |
| 11459 | 327 | /* The fire logger doesn't write logs, only reads them. This is to include |
| 328 | * Fire logs in the log viewer transparently. | |
| 329 | */ | |
| 330 | ||
| 15884 | 331 | static PurpleLogLogger *fire_logger; |
| 11459 | 332 | |
| 333 | struct fire_logger_data { | |
| 334 | }; | |
| 335 | ||
| 15884 | 336 | static GList *fire_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 11459 | 337 | { |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
338 | /* TODO: Do something here. */ |
| 11459 | 339 | return NULL; |
| 340 | } | |
| 341 | ||
| 15884 | 342 | static char * fire_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
| 11459 | 343 | { |
| 344 | struct fire_logger_data *data; | |
| 345 | ||
| 346 | g_return_val_if_fail(log != NULL, g_strdup("")); | |
| 347 | ||
| 348 | data = log->logger_data; | |
| 349 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
350 | /* TODO: Do something here. */ |
| 11459 | 351 | return g_strdup(""); |
| 352 | } | |
| 353 | ||
| 15884 | 354 | static int fire_logger_size (PurpleLog *log) |
| 11459 | 355 | { |
| 356 | g_return_val_if_fail(log != NULL, 0); | |
| 357 | ||
| 16481 | 358 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) |
| 11459 | 359 | return 0; |
| 360 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
361 | /* TODO: Do something here. */ |
| 11459 | 362 | return 0; |
| 363 | } | |
| 364 | ||
| 15884 | 365 | static void fire_logger_finalize(PurpleLog *log) |
| 11459 | 366 | { |
| 367 | g_return_if_fail(log != NULL); | |
| 368 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
369 | /* TODO: Do something here. */ |
| 11459 | 370 | } |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
371 | #endif |
| 11459 | 372 | |
| 373 | ||
| 374 | /***************************************************************************** | |
| 375 | * Messenger Plus! Logger * | |
| 376 | *****************************************************************************/ | |
| 377 | ||
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
378 | #if 0 |
| 11459 | 379 | /* The messenger_plus logger doesn't write logs, only reads them. This is to include |
| 380 | * Messenger Plus! logs in the log viewer transparently. | |
| 381 | */ | |
| 382 | ||
| 15884 | 383 | static PurpleLogLogger *messenger_plus_logger; |
| 11459 | 384 | |
| 385 | struct messenger_plus_logger_data { | |
| 386 | }; | |
| 387 | ||
| 15884 | 388 | static GList *messenger_plus_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 11459 | 389 | { |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
390 | /* TODO: Do something here. */ |
| 11459 | 391 | return NULL; |
| 392 | } | |
| 393 | ||
| 15884 | 394 | static char * messenger_plus_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
| 11459 | 395 | { |
| 396 | struct messenger_plus_logger_data *data = log->logger_data; | |
| 397 | ||
| 398 | g_return_val_if_fail(log != NULL, g_strdup("")); | |
| 399 | ||
| 400 | data = log->logger_data; | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13702
diff
changeset
|
401 | |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
402 | /* TODO: Do something here. */ |
| 11459 | 403 | return g_strdup(""); |
| 404 | } | |
| 405 | ||
| 15884 | 406 | static int messenger_plus_logger_size (PurpleLog *log) |
| 11459 | 407 | { |
| 408 | g_return_val_if_fail(log != NULL, 0); | |
| 409 | ||
| 16481 | 410 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) |
| 11459 | 411 | return 0; |
| 412 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
413 | /* TODO: Do something here. */ |
| 11459 | 414 | return 0; |
| 415 | } | |
| 416 | ||
| 15884 | 417 | static void messenger_plus_logger_finalize(PurpleLog *log) |
| 11459 | 418 | { |
| 419 | g_return_if_fail(log != NULL); | |
| 420 | ||
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
421 | /* TODO: Do something here. */ |
| 11459 | 422 | } |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
423 | #endif |
| 11459 | 424 | |
| 425 | ||
| 426 | /***************************************************************************** | |
| 427 | * MSN Messenger Logger * | |
| 428 | *****************************************************************************/ | |
| 429 | ||
| 430 | /* The msn logger doesn't write logs, only reads them. This is to include | |
| 431 | * MSN Messenger message histories in the log viewer transparently. | |
| 432 | */ | |
| 433 | ||
| 15884 | 434 | static PurpleLogLogger *msn_logger; |
| 11459 | 435 | |
| 436 | struct msn_logger_data { | |
| 437 | xmlnode *root; | |
| 438 | xmlnode *message; | |
| 439 | const char *session_id; | |
| 440 | int last_log; | |
| 441 | GString *text; | |
| 442 | }; | |
| 443 | ||
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
444 | /* This function is really confusing. It makes baby rlaager cry... |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
445 | In other news: "You lost a lot of blood but we found most of it." |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
446 | */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
447 | static time_t msn_logger_parse_timestamp(xmlnode *message, struct tm **tm_out) |
| 11459 | 448 | { |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
449 | const char *datetime; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
450 | static struct tm tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
451 | time_t stamp; |
| 11459 | 452 | const char *date; |
| 453 | const char *time; | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
454 | int month; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
455 | int day; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
456 | int year; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
457 | int hour; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
458 | int min; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
459 | int sec; |
| 11459 | 460 | char am_pm; |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
461 | char *str; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
462 | static struct tm tm; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
463 | time_t t; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
464 | time_t diff; |
| 11459 | 465 | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
466 | #ifndef G_DISABLE_CHECKS |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
467 | if (message != NULL) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
468 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
469 | *tm_out = NULL; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
470 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
471 | /* Trigger the usual warning. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
472 | g_return_val_if_fail(message != NULL, (time_t)0); |
| 11459 | 473 | } |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
474 | #endif |
| 11459 | 475 | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
476 | datetime = xmlnode_get_attrib(message, "DateTime"); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
477 | if (!(datetime && *datetime)) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
478 | { |
| 15884 | 479 | purple_debug_error("MSN log timestamp parse", |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
480 | "Attribute missing: %s\n", "DateTime"); |
| 11459 | 481 | return (time_t)0; |
| 482 | } | |
| 483 | ||
| 15884 | 484 | stamp = purple_str_to_time(datetime, TRUE, &tm2, NULL, NULL); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
485 | #ifdef HAVE_TM_GMTOFF |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
486 | tm2.tm_gmtoff = 0; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
487 | #endif |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
488 | #ifdef HAVE_STRUCT_TM_TM_ZONE |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
489 | /* This is used in the place of a timezone abbreviation if the |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
490 | * offset is way off. The user should never really see it, but |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
491 | * it's here just in case. The parens are to make it clear it's |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
492 | * not a real timezone. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
493 | tm2.tm_zone = _("(UTC)"); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
494 | #endif |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
495 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
496 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
497 | date = xmlnode_get_attrib(message, "Date"); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
498 | if (!(date && *date)) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
499 | { |
| 15884 | 500 | purple_debug_error("MSN log timestamp parse", |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
501 | "Attribute missing: %s\n", "Date"); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
502 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
503 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
504 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
505 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
506 | time = xmlnode_get_attrib(message, "Time"); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
507 | if (!(time && *time)) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
508 | { |
| 15884 | 509 | purple_debug_error("MSN log timestamp parse", |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
510 | "Attribute missing: %s\n", "Time"); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
511 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
512 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
513 | } |
| 11459 | 514 | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
515 | if (sscanf(date, "%u/%u/%u", &month, &day, &year) != 3) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
516 | { |
| 15884 | 517 | purple_debug_error("MSN log timestamp parse", |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
518 | "%s parsing error\n", "Date"); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
519 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
520 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
521 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
522 | else |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
523 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
524 | if (month > 12) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
525 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
526 | int tmp = day; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
527 | day = month; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
528 | month = tmp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
529 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
530 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
531 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
532 | if (sscanf(time, "%u:%u:%u %c", &hour, &min, &sec, &am_pm) != 4) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
533 | { |
| 15884 | 534 | purple_debug_error("MSN log timestamp parse", |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
535 | "%s parsing error\n", "Time"); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
536 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
537 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
538 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
539 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
540 | if (am_pm == 'P') { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
541 | hour += 12; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
542 | } else if (hour == 12) { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
543 | /* 12 AM = 00 hr */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
544 | hour = 0; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
545 | } |
| 11459 | 546 | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
547 | str = g_strdup_printf("%04i-%02i-%02iT%02i:%02i:%02i", year, month, day, hour, min, sec); |
| 15884 | 548 | t = purple_str_to_time(str, TRUE, &tm, NULL, NULL); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
549 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
550 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
551 | if (stamp > t) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
552 | diff = stamp - t; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
553 | else |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
554 | diff = t - stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
555 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
556 | if (diff > (14 * 60 * 60)) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
557 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
558 | if (day <= 12) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
559 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
560 | /* Swap day & month variables, to see if it's a non-US date. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
561 | g_free(str); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
562 | str = g_strdup_printf("%04i-%02i-%02iT%02i:%02i:%02i", year, month, day, hour, min, sec); |
| 15884 | 563 | t = purple_str_to_time(str, TRUE, &tm, NULL, NULL); |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
564 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
565 | if (stamp > t) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
566 | diff = stamp - t; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
567 | else |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
568 | diff = t - stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
569 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
570 | if (diff > (14 * 60 * 60)) |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
571 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
572 | /* We got a time, it's not impossible, but |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
573 | * the diff is too large. Display the UTC time. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
574 | g_free(str); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
575 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
576 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
577 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
578 | else |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
579 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
580 | /* Legal time */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
581 | /* Fall out */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
582 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
583 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
584 | else |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
585 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
586 | /* We got a time, it's not impossible, but |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
587 | * the diff is too large. Display the UTC time. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
588 | g_free(str); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
589 | *tm_out = &tm2; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
590 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
591 | } |
| 11459 | 592 | } |
| 593 | ||
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
594 | /* If we got here, the time is legal with a reasonable offset. |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
595 | * Let's find out if it's in our TZ. */ |
| 15884 | 596 | if (purple_str_to_time(str, FALSE, &tm, NULL, NULL) == stamp) |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
597 | { |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
598 | g_free(str); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
599 | *tm_out = &tm; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
600 | return stamp; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
601 | } |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
602 | g_free(str); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
603 | |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
604 | /* The time isn't in our TZ, but it's reasonable. */ |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
605 | #ifdef HAVE_STRUCT_TM_TM_ZONE |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
606 | tm.tm_zone = " "; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
607 | #endif |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
608 | *tm_out = &tm; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
609 | return stamp; |
| 11459 | 610 | } |
| 611 | ||
| 15884 | 612 | static GList *msn_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 11459 | 613 | { |
| 614 | GList *list = NULL; | |
| 615 | char *username; | |
| 15884 | 616 | PurpleBuddy *buddy; |
| 11459 | 617 | const char *logdir; |
| 618 | const char *savedfilename = NULL; | |
| 619 | char *logfile; | |
| 620 | char *path; | |
| 621 | GError *error = NULL; | |
| 622 | gchar *contents = NULL; | |
| 623 | gsize length; | |
| 624 | xmlnode *root; | |
| 625 | xmlnode *message; | |
| 626 | const char *old_session_id = ""; | |
| 627 | struct msn_logger_data *data = NULL; | |
| 628 | ||
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
629 | g_return_val_if_fail(sn != NULL, NULL); |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
630 | g_return_val_if_fail(account != NULL, NULL); |
| 11459 | 631 | |
| 632 | if (strcmp(account->protocol_id, "prpl-msn")) | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
633 | return NULL; |
| 11459 | 634 | |
| 16481 | 635 | logdir = purple_prefs_get_string("/plugins/core/log_reader/msn/log_directory"); |
| 11459 | 636 | |
| 637 | /* By clearing the log directory path, this logger can be (effectively) disabled. */ | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
638 | if (!logdir || !*logdir) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
639 | return NULL; |
| 11459 | 640 | |
| 15884 | 641 | buddy = purple_find_buddy(account, sn); |
| 11459 | 642 | |
| 15884 | 643 | if ((username = g_strdup(purple_account_get_string( |
| 11459 | 644 | account, "log_reader_msn_log_folder", NULL)))) { |
| 645 | /* As a special case, we allow the null string to kill the parsing | |
| 646 | * straight away. This would allow the user to deal with the case | |
| 647 | * when two account have the same username at different domains and | |
| 648 | * only one has logs stored. | |
| 649 | */ | |
| 650 | if (!*username) { | |
| 651 | g_free(username); | |
| 652 | return list; | |
| 653 | } | |
| 654 | } else { | |
| 15884 | 655 | username = g_strdup(purple_normalize(account, account->username)); |
| 11459 | 656 | } |
| 657 | ||
| 658 | if (buddy) | |
| 15884 | 659 | savedfilename = purple_blist_node_get_string(&buddy->node, "log_reader_msn_log_filename"); |
| 11459 | 660 | |
| 661 | if (savedfilename) { | |
| 662 | /* As a special case, we allow the null string to kill the parsing | |
| 663 | * straight away. This would allow the user to deal with the case | |
| 664 | * when two buddies have the same username at different domains and | |
| 665 | * only one has logs stored. | |
| 666 | */ | |
| 667 | if (!*savedfilename) { | |
| 668 | g_free(username); | |
| 669 | return list; | |
| 670 | } | |
| 671 | ||
| 672 | logfile = g_strdup(savedfilename); | |
| 673 | } else { | |
| 15884 | 674 | logfile = g_strdup_printf("%s.xml", purple_normalize(account, sn)); |
| 11459 | 675 | } |
| 676 | ||
| 677 | path = g_build_filename(logdir, username, "History", logfile, NULL); | |
| 678 | ||
| 679 | if (!g_file_test(path, G_FILE_TEST_EXISTS)) { | |
| 680 | gboolean found = FALSE; | |
| 681 | char *at_sign; | |
| 682 | GDir *dir; | |
| 683 | ||
| 684 | g_free(path); | |
| 685 | ||
| 686 | if (savedfilename) { | |
| 687 | /* We had a saved filename, but it doesn't exist. | |
| 688 | * Returning now is the right course of action because we don't | |
| 689 | * want to detect another file incorrectly. | |
| 690 | */ | |
| 691 | g_free(username); | |
| 692 | g_free(logfile); | |
| 693 | return list; | |
| 694 | } | |
| 695 | ||
| 696 | /* Perhaps we're using a new version of MSN with the weird numbered folders. | |
| 697 | * I don't know how the numbers are calculated, so I'm going to attempt to | |
| 698 | * find logs by pattern matching... | |
| 699 | */ | |
| 700 | ||
| 701 | at_sign = g_strrstr(username, "@"); | |
| 702 | if (at_sign) | |
| 703 | *at_sign = '\0'; | |
| 704 | ||
| 705 | dir = g_dir_open(logdir, 0, NULL); | |
| 706 | if (dir) { | |
| 707 | const gchar *name; | |
| 708 | ||
| 709 | while ((name = g_dir_read_name(dir))) { | |
| 710 | const char *c = name; | |
| 711 | ||
| 15884 | 712 | if (!purple_str_has_prefix(c, username)) |
| 11459 | 713 | continue; |
| 714 | ||
| 715 | c += strlen(username); | |
| 716 | while (*c) { | |
| 717 | if (!g_ascii_isdigit(*c)) | |
| 718 | break; | |
| 719 | ||
| 720 | c++; | |
| 721 | } | |
| 722 | ||
| 723 | path = g_build_filename(logdir, name, NULL); | |
| 724 | /* The !c makes sure we got to the end of the while loop above. */ | |
| 725 | if (!*c && g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
| 726 | char *history_path = g_build_filename( | |
| 727 | path, "History", NULL); | |
| 728 | if (g_file_test(history_path, G_FILE_TEST_IS_DIR)) { | |
| 15884 | 729 | purple_account_set_string(account, |
| 11459 | 730 | "log_reader_msn_log_folder", name); |
| 731 | g_free(path); | |
| 732 | path = history_path; | |
| 733 | found = TRUE; | |
| 734 | break; | |
| 735 | } | |
| 736 | g_free(path); | |
| 737 | g_free(history_path); | |
| 738 | } | |
| 739 | else | |
| 740 | g_free(path); | |
| 741 | } | |
| 742 | g_dir_close(dir); | |
| 743 | } | |
| 744 | g_free(username); | |
| 745 | ||
| 746 | if (!found) { | |
| 747 | g_free(logfile); | |
| 748 | return list; | |
| 749 | } | |
| 750 | ||
| 751 | /* If we've reached this point, we've found a History folder. */ | |
| 752 | ||
| 15884 | 753 | username = g_strdup(purple_normalize(account, sn)); |
| 11459 | 754 | at_sign = g_strrstr(username, "@"); |
| 755 | if (at_sign) | |
| 756 | *at_sign = '\0'; | |
| 757 | ||
| 758 | found = FALSE; | |
| 759 | dir = g_dir_open(path, 0, NULL); | |
| 760 | if (dir) { | |
| 761 | const gchar *name; | |
| 762 | ||
| 763 | while ((name = g_dir_read_name(dir))) { | |
| 764 | const char *c = name; | |
| 765 | ||
| 15884 | 766 | if (!purple_str_has_prefix(c, username)) |
| 11459 | 767 | continue; |
| 768 | ||
| 769 | c += strlen(username); | |
| 770 | while (*c) { | |
| 771 | if (!g_ascii_isdigit(*c)) | |
| 772 | break; | |
| 773 | ||
| 774 | c++; | |
| 775 | } | |
| 776 | ||
| 777 | path = g_build_filename(path, name, NULL); | |
| 778 | if (!strcmp(c, ".xml") && | |
| 779 | g_file_test(path, G_FILE_TEST_EXISTS)) { | |
| 780 | found = TRUE; | |
| 781 | g_free(logfile); | |
| 782 | logfile = g_strdup(name); | |
| 783 | break; | |
| 784 | } | |
| 785 | else | |
| 786 | g_free(path); | |
| 787 | } | |
| 788 | g_dir_close(dir); | |
| 789 | } | |
| 790 | g_free(username); | |
| 791 | ||
| 792 | if (!found) { | |
| 793 | g_free(logfile); | |
| 794 | return list; | |
| 795 | } | |
| 796 | } else { | |
| 797 | g_free(username); | |
| 798 | g_free(logfile); | |
| 799 | logfile = NULL; /* No sense saving the obvious buddy@domain.com. */ | |
| 800 | } | |
| 801 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
802 | purple_debug_info("MSN log read", "Reading %s\n", path); |
| 11459 | 803 | if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 804 | g_free(path); | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
805 | purple_debug_error("MSN log read", "Error reading log\n"); |
| 11459 | 806 | if (error) |
| 807 | g_error_free(error); | |
| 808 | return list; | |
| 809 | } | |
| 810 | g_free(path); | |
| 811 | ||
| 812 | /* Reading the file was successful... | |
| 813 | * Save its name if it involves the crazy numbers. The idea here is that you could | |
| 814 | * then tweak the blist.xml file by hand if need be. This would be the case if two | |
| 815 | * buddies have the same username at different domains. One set of logs would get | |
| 816 | * detected for both buddies. | |
| 817 | */ | |
| 818 | if (buddy && logfile) { | |
| 15884 | 819 | purple_blist_node_set_string(&buddy->node, "log_reader_msn_log_filename", logfile); |
| 11459 | 820 | g_free(logfile); |
| 821 | } | |
| 822 | ||
| 823 | root = xmlnode_from_str(contents, length); | |
| 824 | g_free(contents); | |
| 825 | if (!root) | |
| 826 | return list; | |
| 827 | ||
| 828 | for (message = xmlnode_get_child(root, "Message"); message; | |
| 829 | message = xmlnode_get_next_twin(message)) { | |
| 830 | const char *session_id; | |
| 831 | ||
| 832 | session_id = xmlnode_get_attrib(message, "SessionID"); | |
| 833 | if (!session_id) { | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
834 | purple_debug_error("MSN log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
835 | "Error parsing message: %s\n", "SessionID missing"); |
| 11459 | 836 | continue; |
| 837 | } | |
| 838 | ||
| 839 | if (strcmp(session_id, old_session_id)) { | |
| 840 | /* | |
| 841 | * The session ID differs from the last message. | |
| 842 | * Thus, this is the start of a new conversation. | |
| 843 | */ | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
844 | struct tm *tm; |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
845 | time_t stamp; |
| 15884 | 846 | PurpleLog *log; |
| 11459 | 847 | |
| 848 | data = g_new0(struct msn_logger_data, 1); | |
| 849 | data->root = root; | |
| 850 | data->message = message; | |
| 851 | data->session_id = session_id; | |
| 852 | data->text = NULL; | |
| 853 | data->last_log = FALSE; | |
| 854 | ||
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
855 | stamp = msn_logger_parse_timestamp(message, &tm); |
|
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
856 | |
| 15884 | 857 | log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, stamp, tm); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
858 | log->logger = msn_logger; |
| 11459 | 859 | log->logger_data = data; |
| 860 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
861 | list = g_list_prepend(list, log); |
| 11459 | 862 | } |
| 863 | old_session_id = session_id; | |
| 864 | } | |
| 865 | ||
| 866 | if (data) | |
| 867 | data->last_log = TRUE; | |
| 868 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
869 | return g_list_reverse(list); |
| 11459 | 870 | } |
| 871 | ||
| 15884 | 872 | static char * msn_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
| 11459 | 873 | { |
| 874 | struct msn_logger_data *data; | |
| 875 | GString *text = NULL; | |
| 876 | xmlnode *message; | |
| 877 | ||
|
19060
d330f88b0ed6
Fix #2349 (null pointer deref in log_reader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
18812
diff
changeset
|
878 | if (flags != NULL) |
|
d330f88b0ed6
Fix #2349 (null pointer deref in log_reader plugin).
Daniel Atallah <datallah@pidgin.im>
parents:
18812
diff
changeset
|
879 | *flags = PURPLE_LOG_READ_NO_NEWLINE; |
| 11459 | 880 | g_return_val_if_fail(log != NULL, g_strdup("")); |
| 881 | ||
| 882 | data = log->logger_data; | |
| 883 | ||
| 884 | if (data->text) { | |
| 885 | /* The GTK code which displays the logs g_free()s whatever is | |
| 886 | * returned from this function. Thus, we can't reuse the str | |
| 887 | * part of the GString. The only solution is to free it and | |
| 888 | * start over. | |
| 889 | */ | |
| 890 | g_string_free(data->text, FALSE); | |
| 891 | } | |
| 892 | ||
| 893 | text = g_string_new(""); | |
| 894 | ||
| 895 | if (!data->root || !data->message || !data->session_id) { | |
| 896 | /* Something isn't allocated correctly. */ | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
897 | purple_debug_error("MSN log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
898 | "Error parsing message: %s\n", "Internal variables inconsistent"); |
| 11459 | 899 | data->text = text; |
| 900 | ||
| 901 | return text->str; | |
| 902 | } | |
| 903 | ||
| 904 | for (message = data->message; message; | |
| 905 | message = xmlnode_get_next_twin(message)) { | |
| 906 | ||
| 907 | const char *new_session_id; | |
| 908 | xmlnode *text_node; | |
| 909 | const char *from_name = NULL; | |
| 910 | const char *to_name = NULL; | |
| 911 | xmlnode *from; | |
| 912 | xmlnode *to; | |
| 913 | enum name_guesses name_guessed = NAME_GUESS_UNKNOWN; | |
| 914 | const char *their_name; | |
| 915 | time_t time_unix; | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
916 | struct tm *tm; |
| 11459 | 917 | char *timestamp; |
|
14142
97cb27b1093f
[gaim-migrate @ 16701]
Daniel Atallah <datallah@pidgin.im>
parents:
14139
diff
changeset
|
918 | char *tmp; |
| 11459 | 919 | const char *style; |
| 920 | ||
| 921 | new_session_id = xmlnode_get_attrib(message, "SessionID"); | |
| 922 | ||
| 923 | /* If this triggers, something is wrong with the XML. */ | |
| 924 | if (!new_session_id) { | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
925 | purple_debug_error("MSN log parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
926 | "Error parsing message: %s\n", "New SessionID missing"); |
| 11459 | 927 | break; |
| 928 | } | |
| 929 | ||
| 930 | if (strcmp(new_session_id, data->session_id)) { | |
| 931 | /* The session ID differs from the first message. | |
| 932 | * Thus, this is the start of a new conversation. | |
| 933 | */ | |
| 934 | break; | |
| 935 | } | |
| 936 | ||
| 937 | text_node = xmlnode_get_child(message, "Text"); | |
| 938 | if (!text_node) | |
| 939 | continue; | |
| 940 | ||
| 941 | from = xmlnode_get_child(message, "From"); | |
| 942 | if (from) { | |
| 943 | xmlnode *user = xmlnode_get_child(from, "User"); | |
| 944 | ||
| 945 | if (user) { | |
| 946 | from_name = xmlnode_get_attrib(user, "FriendlyName"); | |
| 947 | ||
| 948 | /* This saves a check later. */ | |
| 949 | if (!*from_name) | |
| 950 | from_name = NULL; | |
| 951 | } | |
| 952 | } | |
| 953 | ||
| 954 | to = xmlnode_get_child(message, "To"); | |
| 955 | if (to) { | |
| 956 | xmlnode *user = xmlnode_get_child(to, "User"); | |
| 957 | if (user) { | |
| 958 | to_name = xmlnode_get_attrib(user, "FriendlyName"); | |
| 959 | ||
| 960 | /* This saves a check later. */ | |
| 961 | if (!*to_name) | |
| 962 | to_name = NULL; | |
| 963 | } | |
| 964 | } | |
| 965 | ||
| 966 | their_name = from_name; | |
| 16481 | 967 | if (from_name && purple_prefs_get_bool("/plugins/core/log_reader/use_name_heuristics")) { |
| 15884 | 968 | const char *friendly_name = purple_connection_get_display_name(log->account->gc); |
| 11459 | 969 | |
|
11702
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
970 | if (friendly_name != NULL) { |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
971 | int friendly_name_length = strlen(friendly_name); |
|
15071
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
972 | const char *alias; |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
973 | int alias_length; |
| 15884 | 974 | PurpleBuddy *buddy = purple_find_buddy(log->account, log->name); |
|
11702
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
975 | gboolean from_name_matches; |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
976 | gboolean to_name_matches; |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
977 | |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
978 | if (buddy && buddy->alias) |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
979 | their_name = buddy->alias; |
| 11459 | 980 | |
|
15071
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
981 | if (log->account->alias) |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
982 | { |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
983 | alias = log->account->alias; |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
984 | alias_length = strlen(alias); |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
985 | } |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
986 | else |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
987 | { |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
988 | alias = ""; |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
989 | alias_length = 0; |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
990 | } |
|
f7927e8ce744
[gaim-migrate @ 17790]
Richard Laager <rlaager@pidgin.im>
parents:
15061
diff
changeset
|
991 | |
|
11702
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
992 | /* Try to guess which user is me. |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
993 | * The first step is to determine if either of the names matches either my |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
994 | * friendly name or alias. For this test, "match" is defined as: |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
995 | * ^(friendly_name|alias)([^a-zA-Z0-9].*)?$ |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
996 | */ |
| 15884 | 997 | from_name_matches = (purple_str_has_prefix(from_name, friendly_name) && |
|
13494
413c793bd39f
[gaim-migrate @ 15869]
Richard Laager <rlaager@pidgin.im>
parents:
13492
diff
changeset
|
998 | !isalnum(*(from_name + friendly_name_length))) || |
| 15884 | 999 | (purple_str_has_prefix(from_name, alias) && |
|
14168
b844e3d268ca
[gaim-migrate @ 16740]
Daniel Atallah <datallah@pidgin.im>
parents:
14142
diff
changeset
|
1000 | !isalnum(*(from_name + alias_length))); |
| 11459 | 1001 | |
|
13494
413c793bd39f
[gaim-migrate @ 15869]
Richard Laager <rlaager@pidgin.im>
parents:
13492
diff
changeset
|
1002 | to_name_matches = to_name != NULL && ( |
| 15884 | 1003 | (purple_str_has_prefix(to_name, friendly_name) && |
|
13494
413c793bd39f
[gaim-migrate @ 15869]
Richard Laager <rlaager@pidgin.im>
parents:
13492
diff
changeset
|
1004 | !isalnum(*(to_name + friendly_name_length))) || |
| 15884 | 1005 | (purple_str_has_prefix(to_name, alias) && |
|
13494
413c793bd39f
[gaim-migrate @ 15869]
Richard Laager <rlaager@pidgin.im>
parents:
13492
diff
changeset
|
1006 | !isalnum(*(to_name + alias_length)))); |
| 11459 | 1007 | |
|
11702
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1008 | if (from_name_matches) { |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1009 | if (!to_name_matches) { |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1010 | name_guessed = NAME_GUESS_ME; |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1011 | } |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1012 | } else if (to_name_matches) { |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1013 | name_guessed = NAME_GUESS_THEM; |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1014 | } else { |
|
4977bb9807d0
[gaim-migrate @ 13993]
Richard Laager <rlaager@pidgin.im>
parents:
11503
diff
changeset
|
1015 | if (buddy && buddy->alias) { |
| 11459 | 1016 | char *alias = g_strdup(buddy->alias); |
| 1017 | ||
| 1018 | /* "Truncate" the string at the first non-alphanumeric | |
| 1019 | * character. The idea is to relax the comparison. | |
| 1020 | */ | |
| 1021 | char *temp; | |
| 1022 | for (temp = alias; *temp ; temp++) { | |
| 1023 | if (!isalnum(*temp)) { | |
| 1024 | *temp = '\0'; | |
| 1025 | break; | |
| 1026 | } | |
| 1027 | } | |
| 1028 | alias_length = strlen(alias); | |
| 1029 | ||
| 1030 | /* Try to guess which user is them. | |
| 1031 | * The first step is to determine if either of the names | |
| 1032 | * matches their alias. For this test, "match" is | |
| 1033 | * defined as: ^alias([^a-zA-Z0-9].*)?$ | |
| 1034 | */ | |
| 15884 | 1035 | from_name_matches = (purple_str_has_prefix( |
| 11459 | 1036 | from_name, alias) && |
| 1037 | !isalnum(*(from_name + | |
| 1038 | alias_length))); | |
| 1039 | ||
| 15884 | 1040 | to_name_matches = to_name && (purple_str_has_prefix( |
| 11459 | 1041 | to_name, alias) && |
| 1042 | !isalnum(*(to_name + | |
| 1043 | alias_length))); | |
| 1044 | ||
| 1045 | g_free(alias); | |
| 1046 | ||
| 1047 | if (from_name_matches) { | |
| 1048 | if (!to_name_matches) { | |
| 1049 | name_guessed = NAME_GUESS_THEM; | |
| 1050 | } | |
| 1051 | } else if (to_name_matches) { | |
| 1052 | name_guessed = NAME_GUESS_ME; | |
| 1053 | } else if (buddy->server_alias) { | |
| 1054 | friendly_name_length = | |
| 1055 | strlen(buddy->server_alias); | |
| 1056 | ||
| 1057 | /* Try to guess which user is them. | |
| 1058 | * The first step is to determine if either of | |
| 1059 | * the names matches their friendly name. For | |
| 1060 | * this test, "match" is defined as: | |
| 1061 | * ^friendly_name([^a-zA-Z0-9].*)?$ | |
| 1062 | */ | |
| 15884 | 1063 | from_name_matches = (purple_str_has_prefix( |
| 11459 | 1064 | from_name, |
| 1065 | buddy->server_alias) && | |
| 1066 | !isalnum(*(from_name + | |
| 1067 | friendly_name_length))); | |
| 1068 | ||
|
14168
b844e3d268ca
[gaim-migrate @ 16740]
Daniel Atallah <datallah@pidgin.im>
parents:
14142
diff
changeset
|
1069 | to_name_matches = to_name && ( |
| 15884 | 1070 | (purple_str_has_prefix( |
| 11459 | 1071 | to_name, buddy->server_alias) && |
| 1072 | !isalnum(*(to_name + | |
|
14168
b844e3d268ca
[gaim-migrate @ 16740]
Daniel Atallah <datallah@pidgin.im>
parents:
14142
diff
changeset
|
1073 | friendly_name_length)))); |
| 11459 | 1074 | |
| 1075 | if (from_name_matches) { | |
| 1076 | if (!to_name_matches) { | |
| 1077 | name_guessed = NAME_GUESS_THEM; | |
| 1078 | } | |
| 1079 | } else if (to_name_matches) { | |
| 1080 | name_guessed = NAME_GUESS_ME; | |
| 1081 | } | |
| 1082 | } | |
| 1083 | } | |
| 1084 | } | |
| 1085 | } | |
| 1086 | } | |
| 1087 | ||
| 1088 | if (name_guessed != NAME_GUESS_UNKNOWN) { | |
| 1089 | text = g_string_append(text, "<span style=\"color: #"); | |
| 1090 | if (name_guessed == NAME_GUESS_ME) | |
| 1091 | text = g_string_append(text, "16569E"); | |
| 1092 | else | |
| 1093 | text = g_string_append(text, "A82F2F"); | |
| 1094 | text = g_string_append(text, ";\">"); | |
| 1095 | } | |
| 1096 | ||
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
1097 | time_unix = msn_logger_parse_timestamp(message, &tm); |
| 11459 | 1098 | |
| 1099 | timestamp = g_strdup_printf("<font size=\"2\">(%02u:%02u:%02u)</font> ", | |
|
15061
a71d30f18de2
[gaim-migrate @ 17778]
Richard Laager <rlaager@pidgin.im>
parents:
14998
diff
changeset
|
1100 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 11459 | 1101 | text = g_string_append(text, timestamp); |
| 1102 | g_free(timestamp); | |
| 1103 | ||
| 1104 | if (from_name) { | |
| 1105 | text = g_string_append(text, "<b>"); | |
| 1106 | ||
|
14998
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1107 | if (name_guessed == NAME_GUESS_ME) { |
|
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1108 | if (log->account->alias) |
|
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1109 | text = g_string_append(text, log->account->alias); |
|
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1110 | else |
|
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1111 | text = g_string_append(text, log->account->username); |
|
76f6b742f4d1
[gaim-migrate @ 17708]
Daniel Atallah <datallah@pidgin.im>
parents:
14334
diff
changeset
|
1112 | } |
| 11459 | 1113 | else if (name_guessed == NAME_GUESS_THEM) |
| 1114 | text = g_string_append(text, their_name); | |
| 1115 | else | |
| 1116 | text = g_string_append(text, from_name); | |
| 1117 | ||
| 1118 | text = g_string_append(text, ":</b> "); | |
| 1119 | } | |
| 1120 | ||
| 1121 | if (name_guessed != NAME_GUESS_UNKNOWN) | |
| 1122 | text = g_string_append(text, "</span>"); | |
| 1123 | ||
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1124 | style = xmlnode_get_attrib(text_node, "Style"); |
| 11459 | 1125 | |
|
14142
97cb27b1093f
[gaim-migrate @ 16701]
Daniel Atallah <datallah@pidgin.im>
parents:
14139
diff
changeset
|
1126 | tmp = xmlnode_get_data(text_node); |
| 11459 | 1127 | if (style && *style) { |
| 1128 | text = g_string_append(text, "<span style=\""); | |
| 1129 | text = g_string_append(text, style); | |
| 1130 | text = g_string_append(text, "\">"); | |
|
14142
97cb27b1093f
[gaim-migrate @ 16701]
Daniel Atallah <datallah@pidgin.im>
parents:
14139
diff
changeset
|
1131 | text = g_string_append(text, tmp); |
|
18530
a14e2e66b293
Make the MSN logger set flags and ues <br> instead of \n. This fixes the
Richard Laager <rlaager@pidgin.im>
parents:
18529
diff
changeset
|
1132 | text = g_string_append(text, "</span><br>"); |
| 11459 | 1133 | } else { |
|
14142
97cb27b1093f
[gaim-migrate @ 16701]
Daniel Atallah <datallah@pidgin.im>
parents:
14139
diff
changeset
|
1134 | text = g_string_append(text, tmp); |
|
18530
a14e2e66b293
Make the MSN logger set flags and ues <br> instead of \n. This fixes the
Richard Laager <rlaager@pidgin.im>
parents:
18529
diff
changeset
|
1135 | text = g_string_append(text, "<br>"); |
| 11459 | 1136 | } |
|
14142
97cb27b1093f
[gaim-migrate @ 16701]
Daniel Atallah <datallah@pidgin.im>
parents:
14139
diff
changeset
|
1137 | g_free(tmp); |
| 11459 | 1138 | } |
| 1139 | ||
| 1140 | data->text = text; | |
| 1141 | ||
| 1142 | return text->str; | |
| 1143 | } | |
| 1144 | ||
| 15884 | 1145 | static int msn_logger_size (PurpleLog *log) |
| 11459 | 1146 | { |
| 1147 | char *text; | |
| 1148 | size_t size; | |
| 1149 | ||
| 1150 | g_return_val_if_fail(log != NULL, 0); | |
| 1151 | ||
| 16481 | 1152 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) |
| 11459 | 1153 | return 0; |
| 1154 | ||
| 1155 | text = msn_logger_read(log, NULL); | |
| 1156 | size = strlen(text); | |
| 1157 | g_free(text); | |
| 1158 | ||
| 1159 | return size; | |
| 1160 | } | |
| 1161 | ||
| 15884 | 1162 | static void msn_logger_finalize(PurpleLog *log) |
| 11459 | 1163 | { |
| 1164 | struct msn_logger_data *data; | |
| 1165 | ||
| 1166 | g_return_if_fail(log != NULL); | |
| 1167 | ||
| 1168 | data = log->logger_data; | |
| 1169 | ||
| 1170 | if (data->last_log) | |
| 1171 | xmlnode_free(data->root); | |
| 1172 | ||
| 1173 | if (data->text) | |
| 1174 | g_string_free(data->text, FALSE); | |
| 18513 | 1175 | |
| 1176 | g_free(data); | |
| 11459 | 1177 | } |
| 1178 | ||
| 1179 | ||
| 1180 | /***************************************************************************** | |
| 1181 | * Trillian Logger * | |
| 1182 | *****************************************************************************/ | |
| 1183 | ||
| 1184 | /* The trillian logger doesn't write logs, only reads them. This is to include | |
| 1185 | * Trillian logs in the log viewer transparently. | |
| 1186 | */ | |
| 1187 | ||
| 15884 | 1188 | static PurpleLogLogger *trillian_logger; |
| 1189 | static void trillian_logger_finalize(PurpleLog *log); | |
| 11459 | 1190 | |
| 1191 | struct trillian_logger_data { | |
| 15884 | 1192 | char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */ |
| 11459 | 1193 | int offset; |
| 1194 | int length; | |
| 1195 | char *their_nickname; | |
| 1196 | }; | |
| 1197 | ||
| 15884 | 1198 | static GList *trillian_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
| 11459 | 1199 | { |
| 1200 | GList *list = NULL; | |
| 1201 | const char *logdir; | |
| 15884 | 1202 | PurplePlugin *plugin; |
| 1203 | PurplePluginProtocolInfo *prpl_info; | |
| 11459 | 1204 | char *prpl_name; |
| 1205 | const char *buddy_name; | |
| 1206 | char *filename; | |
| 1207 | char *path; | |
| 1208 | GError *error = NULL; | |
| 1209 | gchar *contents = NULL; | |
| 1210 | gsize length; | |
| 1211 | gchar *line; | |
| 1212 | gchar *c; | |
| 1213 | ||
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1214 | g_return_val_if_fail(sn != NULL, NULL); |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1215 | g_return_val_if_fail(account != NULL, NULL); |
| 11459 | 1216 | |
| 16481 | 1217 | logdir = purple_prefs_get_string("/plugins/core/log_reader/trillian/log_directory"); |
| 11459 | 1218 | |
| 1219 | /* By clearing the log directory path, this logger can be (effectively) disabled. */ | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1220 | if (!logdir || !*logdir) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1221 | return NULL; |
| 11459 | 1222 | |
| 15884 | 1223 | plugin = purple_find_prpl(purple_account_get_protocol_id(account)); |
| 11459 | 1224 | if (!plugin) |
| 1225 | return NULL; | |
| 1226 | ||
| 15884 | 1227 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
| 11459 | 1228 | if (!prpl_info->list_icon) |
| 1229 | return NULL; | |
| 1230 | ||
| 1231 | prpl_name = g_ascii_strup(prpl_info->list_icon(account, NULL), -1); | |
| 1232 | ||
| 15884 | 1233 | buddy_name = purple_normalize(account, sn); |
| 11459 | 1234 | |
| 1235 | filename = g_strdup_printf("%s.log", buddy_name); | |
| 1236 | path = g_build_filename( | |
| 1237 | logdir, prpl_name, filename, NULL); | |
| 1238 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1239 | purple_debug_info("Trillian log list", "Reading %s\n", path); |
| 11459 | 1240 | /* FIXME: There's really no need to read the entire file at once. |
| 1241 | * See src/log.c:old_logger_list for a better approach. | |
| 1242 | */ | |
| 1243 | if (!g_file_get_contents(path, &contents, &length, &error)) { | |
| 1244 | if (error) { | |
| 1245 | g_error_free(error); | |
| 1246 | error = NULL; | |
| 1247 | } | |
| 1248 | g_free(path); | |
| 1249 | ||
| 1250 | path = g_build_filename( | |
| 1251 | logdir, prpl_name, "Query", filename, NULL); | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1252 | purple_debug_info("Trillian log list", "Reading %s\n", path); |
| 11459 | 1253 | if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 1254 | if (error) | |
| 1255 | g_error_free(error); | |
| 1256 | } | |
| 1257 | } | |
| 1258 | g_free(filename); | |
| 1259 | ||
| 1260 | if (contents) { | |
| 1261 | struct trillian_logger_data *data = NULL; | |
| 1262 | int offset = 0; | |
| 1263 | int last_line_offset = 0; | |
| 1264 | ||
| 1265 | line = contents; | |
| 1266 | c = contents; | |
| 1267 | while (*c) { | |
| 1268 | offset++; | |
| 1269 | ||
| 1270 | if (*c != '\n') { | |
| 1271 | c++; | |
| 1272 | continue; | |
| 1273 | } | |
| 1274 | ||
| 1275 | *c = '\0'; | |
| 15884 | 1276 | if (purple_str_has_prefix(line, "Session Close ")) { |
|
13669
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1277 | if (data && !data->length) { |
|
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1278 | if (!(data->length = last_line_offset - data->offset)) { |
|
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1279 | /* This log had no data, so we remove it. */ |
|
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1280 | GList *last = g_list_last(list); |
| 11459 | 1281 | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1282 | purple_debug_info("Trillian log list", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1283 | "Empty log. Offset %i\n", data->offset); |
| 11459 | 1284 | |
| 15884 | 1285 | trillian_logger_finalize((PurpleLog *)last->data); |
|
13669
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1286 | list = g_list_delete_link(list, last); |
|
ffcdd1227906
[gaim-migrate @ 16070]
Richard Laager <rlaager@pidgin.im>
parents:
13498
diff
changeset
|
1287 | } |
| 11459 | 1288 | } |
|
18180
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1289 | } else if (line[0] && line[1] && line[2] && |
| 15884 | 1290 | purple_str_has_prefix(&line[3], "sion Start ")) { |
|
18180
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1291 | /* The conditional is to make sure we're not reading off |
|
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1292 | * the end of the string. We don't want strlen(), as that'd |
|
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1293 | * have to count the whole string needlessly. |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1294 | * |
|
18180
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1295 | * The odd check here is because a Session Start at the |
|
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1296 | * beginning of the file can be overwritten with a UTF-8 |
|
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1297 | * byte order mark. Yes, it's weird. |
|
96acb4938782
Fix a mistake noticed by Michael Shkutkov and add a comment explaining the code.
Richard Laager <rlaager@pidgin.im>
parents:
17642
diff
changeset
|
1298 | */ |
| 11459 | 1299 | char *their_nickname = line; |
| 1300 | char *timestamp; | |
| 1301 | ||
| 1302 | if (data && !data->length) | |
| 1303 | data->length = last_line_offset - data->offset; | |
| 1304 | ||
| 1305 | while (*their_nickname && (*their_nickname != ':')) | |
| 1306 | their_nickname++; | |
| 1307 | their_nickname++; | |
| 1308 | ||
| 1309 | /* This code actually has nothing to do with | |
| 1310 | * the timestamp YET. I'm simply using this | |
| 1311 | * variable for now to NUL-terminate the | |
| 1312 | * their_nickname string. | |
| 1313 | */ | |
| 1314 | timestamp = their_nickname; | |
| 1315 | while (*timestamp && *timestamp != ')') | |
| 1316 | timestamp++; | |
| 1317 | ||
| 1318 | if (*timestamp == ')') { | |
| 1319 | char *month; | |
| 1320 | struct tm tm; | |
| 1321 | ||
| 1322 | *timestamp = '\0'; | |
| 1323 | if (line[0] && line[1] && line[2]) | |
| 1324 | timestamp += 3; | |
| 1325 | ||
| 1326 | /* Now we start dealing with the timestamp. */ | |
| 1327 | ||
| 1328 | /* Skip over the day name. */ | |
| 1329 | while (*timestamp && (*timestamp != ' ')) | |
| 1330 | timestamp++; | |
| 1331 | *timestamp = '\0'; | |
| 1332 | timestamp++; | |
| 1333 | ||
| 1334 | /* Parse out the month. */ | |
| 1335 | month = timestamp; | |
| 1336 | while (*timestamp && (*timestamp != ' ')) | |
| 1337 | timestamp++; | |
| 1338 | *timestamp = '\0'; | |
| 1339 | timestamp++; | |
| 1340 | ||
| 1341 | /* Parse the day, time, and year. */ | |
| 1342 | if (sscanf(timestamp, "%u %u:%u:%u %u", | |
| 1343 | &tm.tm_mday, &tm.tm_hour, | |
| 1344 | &tm.tm_min, &tm.tm_sec, | |
| 1345 | &tm.tm_year) != 5) { | |
| 1346 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1347 | purple_debug_error("Trillian log timestamp parse", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1348 | "Session Start parsing error\n"); |
| 11459 | 1349 | } else { |
| 15884 | 1350 | PurpleLog *log; |
| 11459 | 1351 | |
| 1352 | tm.tm_year -= 1900; | |
| 1353 | ||
| 1354 | /* Let the C library deal with | |
| 1355 | * daylight savings time. | |
| 1356 | */ | |
| 1357 | tm.tm_isdst = -1; | |
| 1358 | ||
| 1359 | /* Ugly hack, in case current locale | |
| 1360 | * is not English. This code is taken | |
| 1361 | * from log.c. | |
| 1362 | */ | |
| 1363 | if (strcmp(month, "Jan") == 0) { | |
| 1364 | tm.tm_mon= 0; | |
| 1365 | } else if (strcmp(month, "Feb") == 0) { | |
| 1366 | tm.tm_mon = 1; | |
| 1367 | } else if (strcmp(month, "Mar") == 0) { | |
| 1368 | tm.tm_mon = 2; | |
| 1369 | } else if (strcmp(month, "Apr") == 0) { | |
| 1370 | tm.tm_mon = 3; | |
| 1371 | } else if (strcmp(month, "May") == 0) { | |
| 1372 | tm.tm_mon = 4; | |
| 1373 | } else if (strcmp(month, "Jun") == 0) { | |
| 1374 | tm.tm_mon = 5; | |
| 1375 | } else if (strcmp(month, "Jul") == 0) { | |
| 1376 | tm.tm_mon = 6; | |
| 1377 | } else if (strcmp(month, "Aug") == 0) { | |
| 1378 | tm.tm_mon = 7; | |
| 1379 | } else if (strcmp(month, "Sep") == 0) { | |
| 1380 | tm.tm_mon = 8; | |
| 1381 | } else if (strcmp(month, "Oct") == 0) { | |
| 1382 | tm.tm_mon = 9; | |
| 1383 | } else if (strcmp(month, "Nov") == 0) { | |
| 1384 | tm.tm_mon = 10; | |
| 1385 | } else if (strcmp(month, "Dec") == 0) { | |
| 1386 | tm.tm_mon = 11; | |
| 1387 | } | |
| 1388 | ||
| 1389 | data = g_new0( | |
| 1390 | struct trillian_logger_data, 1); | |
| 1391 | data->path = g_strdup(path); | |
| 1392 | data->offset = offset; | |
| 1393 | data->length = 0; | |
| 1394 | data->their_nickname = | |
| 1395 | g_strdup(their_nickname); | |
| 1396 | ||
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12727
diff
changeset
|
1397 | /* XXX: Look into this later... Should we pass in a struct tm? */ |
| 15884 | 1398 | log = purple_log_new(PURPLE_LOG_IM, |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12727
diff
changeset
|
1399 | sn, account, NULL, mktime(&tm), NULL); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
1400 | log->logger = trillian_logger; |
| 11459 | 1401 | log->logger_data = data; |
| 1402 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
1403 | list = g_list_prepend(list, log); |
| 11459 | 1404 | } |
| 1405 | } | |
| 1406 | } | |
| 1407 | c++; | |
| 1408 | line = c; | |
| 1409 | last_line_offset = offset; | |
| 1410 | } | |
| 1411 | ||
| 1412 | g_free(contents); | |
| 1413 | } | |
| 1414 | g_free(path); | |
| 1415 | ||
| 1416 | g_free(prpl_name); | |
| 1417 | ||
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
1418 | return g_list_reverse(list); |
| 11459 | 1419 | } |
| 1420 | ||
| 15884 | 1421 | static char * trillian_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) |
| 11459 | 1422 | { |
| 1423 | struct trillian_logger_data *data; | |
| 1424 | char *read; | |
| 1425 | FILE *file; | |
| 15884 | 1426 | PurpleBuddy *buddy; |
| 11459 | 1427 | char *escaped; |
| 1428 | GString *formatted; | |
| 1429 | char *c; | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1430 | const char *line; |
| 11459 | 1431 | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1432 | if (flags != NULL) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1433 | *flags = PURPLE_LOG_READ_NO_NEWLINE; |
|
19080
37da30ac730d
bug with flags variable initialization was fixed
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
19060
diff
changeset
|
1434 | |
| 11459 | 1435 | g_return_val_if_fail(log != NULL, g_strdup("")); |
| 1436 | ||
| 1437 | data = log->logger_data; | |
| 1438 | ||
| 1439 | g_return_val_if_fail(data->path != NULL, g_strdup("")); | |
| 1440 | g_return_val_if_fail(data->length > 0, g_strdup("")); | |
| 1441 | g_return_val_if_fail(data->their_nickname != NULL, g_strdup("")); | |
| 1442 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
1443 | purple_debug_info("Trillian log read", "Reading %s\n", data->path); |
| 11459 | 1444 | |
| 1445 | read = g_malloc(data->length + 2); | |
| 1446 | ||
|
13158
3b4295931fd6
[gaim-migrate @ 15520]
Richard Laager <rlaager@pidgin.im>
parents:
13120
diff
changeset
|
1447 | file = g_fopen(data->path, "rb"); |
| 11459 | 1448 | fseek(file, data->offset, SEEK_SET); |
| 1449 | fread(read, data->length, 1, file); | |
| 1450 | fclose(file); | |
| 1451 | ||
| 1452 | if (read[data->length-1] == '\n') { | |
| 1453 | read[data->length] = '\0'; | |
| 1454 | } else { | |
| 1455 | read[data->length] = '\n'; | |
| 1456 | read[data->length+1] = '\0'; | |
| 1457 | } | |
| 1458 | ||
| 1459 | /* Load miscellaneous data. */ | |
| 15884 | 1460 | buddy = purple_find_buddy(log->account, log->name); |
| 11459 | 1461 | |
| 1462 | escaped = g_markup_escape_text(read, -1); | |
| 1463 | g_free(read); | |
| 1464 | read = escaped; | |
| 1465 | ||
| 1466 | /* Apply formatting... */ | |
|
17640
e991110a1e71
Size the formatting string first, to avoid unnecessary resizing.
Richard Laager <rlaager@pidgin.im>
parents:
17639
diff
changeset
|
1467 | formatted = g_string_sized_new(strlen(read)); |
| 11459 | 1468 | c = read; |
| 1469 | line = read; | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1470 | while (c) |
| 11459 | 1471 | { |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1472 | const char *link; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1473 | const char *footer = NULL; |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1474 | GString *temp = NULL; |
| 11459 | 1475 | |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1476 | if ((c = strstr(c, "\n"))) |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1477 | { |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1478 | *c = '\0'; |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1479 | c++; |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1480 | } |
| 11459 | 1481 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1482 | /* Convert links. |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1483 | * |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1484 | * The format is (Link: URL)URL |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1485 | * So, I want to find each occurance of "(Link: " and replace that chunk with: |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1486 | * <a href=" |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1487 | * Then, replace the next ")" with: |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1488 | * "> |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1489 | * Then, replace the next " " (or add this if the end-of-line is reached) with: |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1490 | * </a> |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1491 | * |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1492 | * As implemented, this isn't perfect, but it should cover common cases. |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1493 | */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1494 | while (line && (link = strstr(line, "(Link: "))) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1495 | { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1496 | const char *tmp = link; |
| 11459 | 1497 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1498 | link += 7; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1499 | if (*link) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1500 | { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1501 | char *end_paren; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1502 | char *space; |
| 11459 | 1503 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1504 | if (!(end_paren = strstr(link, ")"))) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1505 | { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1506 | /* Something is not as we expect. Bail out. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1507 | break; |
| 11459 | 1508 | } |
| 1509 | ||
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1510 | if (!temp) |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1511 | temp = g_string_sized_new(c ? (c - 1 - line) : strlen(line)); |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1512 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1513 | g_string_append_len(temp, line, (tmp - line)); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1514 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1515 | /* Start an <a> tag. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1516 | g_string_append(temp, "<a href=\""); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1517 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1518 | /* Append up to the ) */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1519 | g_string_append_len(temp, link, end_paren - link); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1520 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1521 | /* Finish the <a> tag. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1522 | g_string_append(temp, "\">"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1523 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1524 | /* The \r is a bit of a hack to keep there from being a \r in |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1525 | * the link text, which may not matter. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1526 | if ((space = strstr(end_paren, " ")) || (space = strstr(end_paren, "\r"))) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1527 | { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1528 | g_string_append_len(temp, end_paren + 1, space - end_paren - 1); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1529 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1530 | /* Close the <a> tag. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1531 | g_string_append(temp, "</a>"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1532 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1533 | space++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1534 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1535 | else |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1536 | { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1537 | /* There is no space before the end of the line. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1538 | g_string_append(temp, end_paren + 1); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1539 | /* Close the <a> tag. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1540 | g_string_append(temp, "</a>"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1541 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1542 | line = space; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1543 | } |
|
17641
03a8f532c3cf
Bail out to avoid an infinite loop in an extreme corner case.
Richard Laager <rlaager@pidgin.im>
parents:
17640
diff
changeset
|
1544 | else |
|
03a8f532c3cf
Bail out to avoid an infinite loop in an extreme corner case.
Richard Laager <rlaager@pidgin.im>
parents:
17640
diff
changeset
|
1545 | { |
|
03a8f532c3cf
Bail out to avoid an infinite loop in an extreme corner case.
Richard Laager <rlaager@pidgin.im>
parents:
17640
diff
changeset
|
1546 | /* Something is not as we expect. Bail out. */ |
|
03a8f532c3cf
Bail out to avoid an infinite loop in an extreme corner case.
Richard Laager <rlaager@pidgin.im>
parents:
17640
diff
changeset
|
1547 | break; |
|
03a8f532c3cf
Bail out to avoid an infinite loop in an extreme corner case.
Richard Laager <rlaager@pidgin.im>
parents:
17640
diff
changeset
|
1548 | } |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1549 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1550 | |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1551 | if (temp) |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1552 | { |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1553 | if (line) |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1554 | g_string_append(temp, line); |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1555 | line = temp->str; |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1556 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1557 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1558 | if (*line == '[') { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1559 | const char *timestamp; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1560 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1561 | if ((timestamp = strstr(line, "]"))) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1562 | line++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1563 | /* TODO: Parse the timestamp and convert it to Purple's format. */ |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1564 | g_string_append(formatted, "<font size=\"2\">("); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1565 | g_string_append_len(formatted, line, (timestamp - line)); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1566 | g_string_append(formatted,")</font> "); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1567 | line = timestamp + 1; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1568 | if (line[0] && line[1]) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1569 | line++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1570 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1571 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1572 | if (purple_str_has_prefix(line, "*** ")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1573 | line += (sizeof("*** ") - 1); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1574 | g_string_append(formatted, "<b>"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1575 | footer = "</b>"; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1576 | if (purple_str_has_prefix(line, "NOTE: This user is offline.")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1577 | line = _("User is offline."); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1578 | } else if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1579 | "NOTE: Your status is currently set to ")) { |
| 11459 | 1580 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1581 | line += (sizeof("NOTE: ") - 1); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1582 | } else if (purple_str_has_prefix(line, "Auto-response sent to ")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1583 | g_string_append(formatted, _("Auto-response sent:")); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1584 | while (*line && *line != ':') |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1585 | line++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1586 | if (*line) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1587 | line++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1588 | g_string_append(formatted, "</b>"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1589 | footer = NULL; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1590 | } else if (strstr(line, " signed off ")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1591 | if (buddy != NULL && buddy->alias) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1592 | g_string_append_printf(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1593 | _("%s has signed off."), buddy->alias); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1594 | else |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1595 | g_string_append_printf(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1596 | _("%s has signed off."), log->name); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1597 | line = ""; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1598 | } else if (strstr(line, " signed on ")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1599 | if (buddy != NULL && buddy->alias) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1600 | g_string_append(formatted, buddy->alias); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1601 | else |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1602 | g_string_append(formatted, log->name); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1603 | line = " logged in."; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1604 | } else if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1605 | "One or more messages may have been undeliverable.")) { |
| 11459 | 1606 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1607 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1608 | "<span style=\"color: #ff0000;\">"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1609 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1610 | _("One or more messages may have been " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1611 | "undeliverable.")); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1612 | line = ""; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1613 | footer = "</span></b>"; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1614 | } else if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1615 | "You have been disconnected.")) { |
| 11459 | 1616 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1617 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1618 | "<span style=\"color: #ff0000;\">"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1619 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1620 | _("You were disconnected from the server.")); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1621 | line = ""; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1622 | footer = "</span></b>"; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1623 | } else if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1624 | "You are currently disconnected.")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1625 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1626 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1627 | "<span style=\"color: #ff0000;\">"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1628 | line = _("You are currently disconnected. Messages " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1629 | "will not be received unless you are " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1630 | "logged in."); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1631 | footer = "</span></b>"; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1632 | } else if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1633 | "Your previous message has not been sent.")) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1634 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1635 | g_string_append(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1636 | "<span style=\"color: #ff0000;\">"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1637 | |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1638 | if (purple_str_has_prefix(line, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1639 | "Your previous message has not been sent. " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1640 | "Reason: Maximum length exceeded.")) { |
| 11459 | 1641 | |
| 1642 | g_string_append(formatted, | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1643 | _("Message could not be sent because " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1644 | "the maximum length was exceeded.")); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1645 | line = ""; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1646 | } else { |
| 11459 | 1647 | g_string_append(formatted, |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1648 | _("Message could not be sent.")); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1649 | line += (sizeof( |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1650 | "Your previous message " |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1651 | "has not been sent. ") - 1); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1652 | } |
| 11459 | 1653 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1654 | footer = "</span></b>"; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1655 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1656 | } else if (purple_str_has_prefix(line, data->their_nickname)) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1657 | if (buddy != NULL && buddy->alias) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1658 | line += strlen(data->their_nickname) + 2; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1659 | g_string_append_printf(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1660 | "<span style=\"color: #A82F2F;\">" |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1661 | "<b>%s</b></span>: ", buddy->alias); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1662 | } |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1663 | } else { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1664 | const char *line2 = strstr(line, ":"); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1665 | if (line2) { |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1666 | const char *acct_name; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1667 | line2++; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1668 | line = line2; |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1669 | acct_name = purple_account_get_alias(log->account); |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1670 | if (!acct_name) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1671 | acct_name = purple_account_get_username(log->account); |
| 11459 | 1672 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1673 | g_string_append_printf(formatted, |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1674 | "<span style=\"color: #16569E;\">" |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1675 | "<b>%s</b></span>:", acct_name); |
| 11459 | 1676 | } |
| 1677 | } | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1678 | } |
| 11459 | 1679 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1680 | g_string_append(formatted, line); |
| 11459 | 1681 | |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1682 | line = c; |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1683 | if (temp) |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1684 | g_string_free(temp, TRUE); |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1685 | |
|
17639
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1686 | if (footer) |
|
6806f13652c0
A patch from o_sukhodolsky to restructure the Trillian log formatting code
Richard Laager <rlaager@pidgin.im>
parents:
17568
diff
changeset
|
1687 | g_string_append(formatted, footer); |
| 11459 | 1688 | |
|
18527
f99e08c197f4
Make the Trillian logger set flags properly, and use <br> instead of \n for
Richard Laager <rlaager@pidgin.im>
parents:
18525
diff
changeset
|
1689 | g_string_append(formatted, "<br>"); |
| 11459 | 1690 | } |
| 1691 | ||
| 1692 | g_free(read); | |
|
18527
f99e08c197f4
Make the Trillian logger set flags properly, and use <br> instead of \n for
Richard Laager <rlaager@pidgin.im>
parents:
18525
diff
changeset
|
1693 | |
|
f99e08c197f4
Make the Trillian logger set flags properly, and use <br> instead of \n for
Richard Laager <rlaager@pidgin.im>
parents:
18525
diff
changeset
|
1694 | /* XXX: TODO: What can we do about removing \r characters? |
|
f99e08c197f4
Make the Trillian logger set flags properly, and use <br> instead of \n for
Richard Laager <rlaager@pidgin.im>
parents:
18525
diff
changeset
|
1695 | * XXX: TODO: and will that allow us to avoid this |
|
f99e08c197f4
Make the Trillian logger set flags properly, and use <br> instead of \n for
Richard Laager <rlaager@pidgin.im>
parents:
18525
diff
changeset
|
1696 | * XXX: TODO: g_strchomp(), or is that unrelated? */ |
|
17642
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1697 | /* XXX: TODO: Avoid this g_strchomp() */ |
|
c0409038fd04
Don't create the temp GString unless it's actually needed, and avoid
Richard Laager <rlaager@pidgin.im>
parents:
17641
diff
changeset
|
1698 | return g_strchomp(g_string_free(formatted, FALSE)); |
| 11459 | 1699 | } |
| 1700 | ||
| 15884 | 1701 | static int trillian_logger_size (PurpleLog *log) |
| 11459 | 1702 | { |
| 1703 | struct trillian_logger_data *data; | |
| 1704 | char *text; | |
| 1705 | size_t size; | |
| 1706 | ||
| 1707 | g_return_val_if_fail(log != NULL, 0); | |
| 1708 | ||
| 1709 | data = log->logger_data; | |
| 1710 | ||
| 16481 | 1711 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) { |
| 11459 | 1712 | return data ? data->length : 0; |
| 1713 | } | |
| 1714 | ||
| 1715 | text = trillian_logger_read(log, NULL); | |
| 1716 | size = strlen(text); | |
| 1717 | g_free(text); | |
| 1718 | ||
| 1719 | return size; | |
| 1720 | } | |
| 1721 | ||
| 15884 | 1722 | static void trillian_logger_finalize(PurpleLog *log) |
| 11459 | 1723 | { |
| 1724 | struct trillian_logger_data *data; | |
| 1725 | ||
| 1726 | g_return_if_fail(log != NULL); | |
| 1727 | ||
| 1728 | data = log->logger_data; | |
| 1729 | ||
| 1730 | g_free(data->path); | |
| 1731 | g_free(data->their_nickname); | |
| 18513 | 1732 | g_free(data); |
| 11459 | 1733 | } |
| 1734 | ||
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1735 | /***************************************************************************** |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1736 | * QIP Logger * |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1737 | *****************************************************************************/ |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1738 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1739 | /* The QIP logger doesn't write logs, only reads them. This is to include |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1740 | * QIP logs in the log viewer transparently. |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1741 | */ |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1742 | #define QIP_LOG_DELIMITER "--------------------------------------" |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1743 | #define QIP_LOG_IN_MESSAGE (QIP_LOG_DELIMITER "<-") |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1744 | #define QIP_LOG_OUT_MESSAGE (QIP_LOG_DELIMITER ">-") |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1745 | #define QIP_LOG_IN_MESSAGE_ESC (QIP_LOG_DELIMITER "<-") |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1746 | #define QIP_LOG_OUT_MESSAGE_ESC (QIP_LOG_DELIMITER ">-") |
|
18509
64bad4cb0a56
creat new log if difference between current and previous message more then predefined constant (currently one hour)
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18508
diff
changeset
|
1747 | #define QIP_LOG_TIMEOUT (60*60) |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1748 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1749 | static PurpleLogLogger *qip_logger; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1750 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1751 | struct qip_logger_data { |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1752 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1753 | char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */ |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1754 | int offset; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1755 | int length; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1756 | }; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1757 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1758 | static GList *qip_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account) |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1759 | { |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1760 | GList *list = NULL; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1761 | const char *logdir; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1762 | PurplePlugin *plugin; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1763 | PurplePluginProtocolInfo *prpl_info; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1764 | char *username; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1765 | char *filename; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1766 | char *path; |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1767 | char *contents; |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1768 | struct qip_logger_data *data = NULL; |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1769 | struct tm prev_tm; |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1770 | struct tm tm; |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1771 | gboolean prev_tm_init = FALSE; |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1772 | gboolean main_cycle = TRUE; |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1773 | char *c; |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1774 | char *start_log; |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1775 | char *new_line; |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1776 | int offset = 0; |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1777 | GError *error; |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1778 | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1779 | g_return_val_if_fail(sn != NULL, NULL); |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1780 | g_return_val_if_fail(account != NULL, NULL); |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1781 | |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1782 | /* QIP only supports ICQ. */ |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1783 | if (strcmp(account->protocol_id, "prpl-icq")) |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1784 | return NULL; |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1785 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1786 | logdir = purple_prefs_get_string("/plugins/core/log_reader/qip/log_directory"); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1787 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1788 | /* By clearing the log directory path, this logger can be (effectively) disabled. */ |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1789 | if (!logdir || !*logdir) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1790 | return NULL; |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1791 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1792 | plugin = purple_find_prpl(purple_account_get_protocol_id(account)); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1793 | if (!plugin) |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1794 | return NULL; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1795 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1796 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1797 | if (!prpl_info->list_icon) |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1798 | return NULL; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1799 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1800 | username = g_strdup(purple_normalize(account, account->username)); |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1801 | filename = g_strdup_printf("%s.txt", purple_normalize(account, sn)); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1802 | path = g_build_filename(logdir, username, "History", filename, NULL); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1803 | g_free(username); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1804 | g_free(filename); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1805 | |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1806 | purple_debug_info("QIP logger", "Reading %s\n", path); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1807 | |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1808 | error = NULL; |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1809 | if (!g_file_get_contents(path, &contents, NULL, &error)) { |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1810 | purple_debug_error("QIP logger", |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1811 | "Couldn't read file %s: %s \n", path, error->message); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1812 | g_error_free(error); |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1813 | g_free(path); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1814 | return list; |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1815 | } |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1816 | |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1817 | c = contents; |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1818 | start_log = contents; |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1819 | while (main_cycle) { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1820 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1821 | gboolean add_new_log = FALSE; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1822 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1823 | if (*c) { |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1824 | if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE) || |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1825 | purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE)) { |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1826 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1827 | char *tmp; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1828 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1829 | new_line = c; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1830 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1831 | /* find EOL */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1832 | c = strstr(c, "\n"); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1833 | c++; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1834 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1835 | /* Find the last '(' character. */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1836 | if ((tmp = strstr(c, "\n")) != NULL) { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1837 | while (*tmp && *tmp != '(') --tmp; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1838 | c = tmp; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1839 | } else { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1840 | while (*c) |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1841 | c++; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1842 | c--; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1843 | c = g_strrstr(c, "("); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1844 | } |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1845 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1846 | if (c != NULL) { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1847 | const char *timestamp = ++c; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1848 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1849 | /* Parse the time, day, month and year */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1850 | if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1851 | &tm.tm_hour, &tm.tm_min, &tm.tm_sec, |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1852 | &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1853 | |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1854 | purple_debug_error("QIP logger list", |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1855 | "Parsing timestamp error\n"); |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1856 | } else { |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1857 | tm.tm_mon -= 1; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1858 | tm.tm_year -= 1900; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1859 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1860 | /* Let the C library deal with |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1861 | * daylight savings time. */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1862 | tm.tm_isdst = -1; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1863 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1864 | if (!prev_tm_init) { |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1865 | prev_tm = tm; |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1866 | prev_tm_init = TRUE; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1867 | } else { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1868 | add_new_log = difftime(mktime(&tm), mktime(&prev_tm)) > QIP_LOG_TIMEOUT; |
|
18509
64bad4cb0a56
creat new log if difference between current and previous message more then predefined constant (currently one hour)
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18508
diff
changeset
|
1869 | } |
|
64bad4cb0a56
creat new log if difference between current and previous message more then predefined constant (currently one hour)
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18508
diff
changeset
|
1870 | } |
|
64bad4cb0a56
creat new log if difference between current and previous message more then predefined constant (currently one hour)
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18508
diff
changeset
|
1871 | } |
|
64bad4cb0a56
creat new log if difference between current and previous message more then predefined constant (currently one hour)
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18508
diff
changeset
|
1872 | } |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1873 | } else { |
|
18521
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1874 | add_new_log = TRUE; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1875 | main_cycle = FALSE; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1876 | new_line = c; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1877 | } |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1878 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1879 | /* adding log */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1880 | if (add_new_log && prev_tm_init) { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1881 | PurpleLog *log; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1882 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1883 | /* filling data */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1884 | data = g_new0(struct qip_logger_data, 1); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1885 | data->path = g_strdup(path); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1886 | data->length = new_line - start_log; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1887 | data->offset = offset; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1888 | offset += data->length; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1889 | purple_debug_info("QIP logger list", |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1890 | "Creating log: path = (%s); length = (%d); offset = (%d)\n", |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1891 | data->path, data->length, data->offset); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1892 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1893 | /* XXX: Look into this later... Should we pass in a struct tm? */ |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1894 | log = purple_log_new(PURPLE_LOG_IM, sn, account, |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1895 | NULL, mktime(&prev_tm), NULL); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1896 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1897 | log->logger = qip_logger; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1898 | log->logger_data = data; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1899 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1900 | list = g_list_prepend(list, log); |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1901 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1902 | prev_tm = tm; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1903 | start_log = new_line; |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1904 | } |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1905 | |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1906 | if (*c) { |
|
88a85456ae56
avoiding some finding EOL and creating new log only in one place
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18520
diff
changeset
|
1907 | /* find EOF */ |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1908 | c = strstr(c, "\n"); |
|
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1909 | c++; |
|
18505
dca6960014b8
Converting all qip logs into UTF8
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18504
diff
changeset
|
1910 | } |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1911 | } |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1912 | |
|
18514
8732891045fc
Avoid some extra nesting.
Richard Laager <rlaager@pidgin.im>
parents:
18513
diff
changeset
|
1913 | g_free(contents); |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1914 | g_free(path); |
|
18516
721bd74979a8
Prepend to lists for performance, and use g_list_reverse when the list is
Richard Laager <rlaager@pidgin.im>
parents:
18515
diff
changeset
|
1915 | return g_list_reverse(list); |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1916 | } |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1917 | |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1918 | static char *qip_logger_read(PurpleLog *log, PurpleLogReadFlags *flags) |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1919 | { |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1920 | struct qip_logger_data *data; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1921 | PurpleBuddy *buddy; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1922 | GString *formatted; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1923 | char *c; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1924 | const char *line; |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1925 | gchar *contents; |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1926 | GError *error; |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1927 | char *utf8_string; |
|
18523
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1928 | FILE *file; |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1929 | |
|
19090
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1930 | if (flags != NULL) |
|
f14418fec130
Fix more null pointer derefs in the log reader plugin. Fixes #2378.
Daniel Atallah <datallah@pidgin.im>
parents:
19080
diff
changeset
|
1931 | *flags = PURPLE_LOG_READ_NO_NEWLINE; |
|
19080
37da30ac730d
bug with flags variable initialization was fixed
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
19060
diff
changeset
|
1932 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1933 | g_return_val_if_fail(log != NULL, g_strdup("")); |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1934 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1935 | data = log->logger_data; |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
1936 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1937 | g_return_val_if_fail(data->path != NULL, g_strdup("")); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1938 | g_return_val_if_fail(data->length > 0, g_strdup("")); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
1939 | |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1940 | error = NULL; |
|
18523
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1941 | |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1942 | contents = g_malloc(data->length + 2); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1943 | |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1944 | file = g_fopen(data->path, "rb"); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1945 | g_return_val_if_fail(file != NULL, g_strdup("")); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1946 | |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1947 | fseek(file, data->offset, SEEK_SET); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1948 | fread(contents, data->length, 1, file); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1949 | fclose(file); |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1950 | |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1951 | contents[data->length] = '\n'; |
|
121b16df5e05
reading only necessary part of log file using g_fopen/fseek/fread
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18522
diff
changeset
|
1952 | contents[data->length + 1] = '\0'; |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1953 | |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1954 | /* Convert file contents from Cp1251 to UTF-8 codeset */ |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1955 | error = NULL; |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1956 | if (!(utf8_string = g_convert(contents, -1, "UTF-8", "Cp1251", NULL, NULL, &error))) { |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1957 | purple_debug_error("QIP logger", |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1958 | "Couldn't convert file %s to UTF-8: %s\n", data->path, error->message); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1959 | g_error_free(error); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1960 | g_free(contents); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1961 | return g_strdup(""); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1962 | } |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1963 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1964 | g_free(contents); |
|
18522
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1965 | contents = g_markup_escape_text(utf8_string, -1); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1966 | g_free(utf8_string); |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1967 | |
|
dbf8b610712a
optimization: finding offsets without converting to UTF8 and escaping
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18521
diff
changeset
|
1968 | buddy = purple_find_buddy(log->account, log->name); |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1969 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1970 | /* Apply formatting... */ |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1971 | formatted = g_string_sized_new(data->length + 2); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1972 | c = contents; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1973 | line = contents; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1974 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1975 | while (*c) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1976 | gboolean is_in_message = FALSE; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1977 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1978 | if (purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC) || |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1979 | purple_str_has_prefix(line, QIP_LOG_OUT_MESSAGE_ESC)) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1980 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1981 | char *tmp; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1982 | const char *buddy_name; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1983 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1984 | is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1985 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1986 | /* find EOL */ |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1987 | c = strstr(c, "\n"); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1988 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1989 | /* XXX: Do we need buddy_name when we have buddy->alias? */ |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1990 | buddy_name = ++c; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1991 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1992 | /* Find the last '(' character. */ |
|
18519
7a6b0327b1a1
using while cycle instead of g_strrstr, because g_strrstr doesn't work properly. g_strrstr finds the last '(' of the string, not the line.
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18518
diff
changeset
|
1993 | if ((tmp = strstr(c, "\n")) != NULL) { |
|
7a6b0327b1a1
using while cycle instead of g_strrstr, because g_strrstr doesn't work properly. g_strrstr finds the last '(' of the string, not the line.
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18518
diff
changeset
|
1994 | while (*tmp && *tmp != '(') --tmp; |
|
7a6b0327b1a1
using while cycle instead of g_strrstr, because g_strrstr doesn't work properly. g_strrstr finds the last '(' of the string, not the line.
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18518
diff
changeset
|
1995 | c = tmp; |
|
7a6b0327b1a1
using while cycle instead of g_strrstr, because g_strrstr doesn't work properly. g_strrstr finds the last '(' of the string, not the line.
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18518
diff
changeset
|
1996 | } else { |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1997 | while (*c) |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1998 | c++; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
1999 | c--; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2000 | c = g_strrstr(c, "("); |
|
18505
dca6960014b8
Converting all qip logs into UTF8
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18504
diff
changeset
|
2001 | } |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2002 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2003 | if (c != NULL) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2004 | const char *timestamp = c; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2005 | int hour; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2006 | int min; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2007 | int sec; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2008 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2009 | timestamp++; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2010 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2011 | /* Parse the time, day, month and year */ |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2012 | if (sscanf(timestamp, "%u:%u:%u", |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2013 | &hour, &min, &sec) != 3) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2014 | purple_debug_error("QIP logger read", |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2015 | "Parsing timestamp error\n"); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2016 | } else { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2017 | g_string_append(formatted, "<font size=\"2\">"); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2018 | /* TODO: Figure out if we can do anything more locale-independent. */ |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2019 | g_string_append_printf(formatted, |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2020 | "(%u:%02u:%02u) %cM ", hour % 12, |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2021 | min, sec, (hour >= 12) ? 'P': 'A'); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2022 | g_string_append(formatted, "</font> "); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2023 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2024 | if (is_in_message) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2025 | if (buddy_name != NULL && buddy->alias) { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2026 | g_string_append_printf(formatted, |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2027 | "<span style=\"color: #A82F2F;\">" |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2028 | "<b>%s</b></span>: ", buddy->alias); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2029 | } |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2030 | } else { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2031 | const char *acct_name; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2032 | acct_name = purple_account_get_alias(log->account); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2033 | if (!acct_name) |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2034 | acct_name = purple_account_get_username(log->account); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2035 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2036 | g_string_append_printf(formatted, |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2037 | "<span style=\"color: #16569E;\">" |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2038 | "<b>%s</b></span>: ", acct_name); |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2039 | } |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2040 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2041 | /* find EOF */ |
|
18505
dca6960014b8
Converting all qip logs into UTF8
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18504
diff
changeset
|
2042 | c = strstr(c, "\n"); |
|
dca6960014b8
Converting all qip logs into UTF8
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18504
diff
changeset
|
2043 | line = ++c; |
|
18503
2cda7502306c
Using g_file_get_contents instead of common file operations; all DEBUG_MESSAGEs were removed
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18502
diff
changeset
|
2044 | } |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2045 | } |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2046 | } else { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2047 | if ((c = strstr(c, "\n"))) |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2048 | *c = '\0'; |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2049 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2050 | if (line[0] != '\n' && line[0] != '\r') { |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2051 | |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2052 | g_string_append(formatted, line); |
|
18525
461301d40a6b
using <br> as end of line instead of '\n' in QIP logger. With this change History plugin works fine
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18523
diff
changeset
|
2053 | g_string_append(formatted, "<br>"); |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2054 | } |
|
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2055 | line = ++c; |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2056 | } |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2057 | } |
|
18503
2cda7502306c
Using g_file_get_contents instead of common file operations; all DEBUG_MESSAGEs were removed
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18502
diff
changeset
|
2058 | g_free(contents); |
|
18518
e634b818b474
Optimize this QIP code some more.
Richard Laager <rlaager@pidgin.im>
parents:
18517
diff
changeset
|
2059 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2060 | /* XXX: TODO: Avoid this g_strchomp() */ |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2061 | return g_strchomp(g_string_free(formatted, FALSE)); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2062 | } |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2063 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2064 | static int qip_logger_size (PurpleLog *log) |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2065 | { |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2066 | struct qip_logger_data *data; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2067 | char *text; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2068 | size_t size; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2069 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2070 | g_return_val_if_fail(log != NULL, 0); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2071 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2072 | data = log->logger_data; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2073 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2074 | if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) { |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2075 | return data ? data->length : 0; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2076 | } |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2077 | |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
2078 | text = qip_logger_read(log, NULL); |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2079 | size = strlen(text); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2080 | g_free(text); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2081 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2082 | return size; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2083 | } |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2084 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2085 | static void qip_logger_finalize(PurpleLog *log) |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2086 | { |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2087 | struct qip_logger_data *data; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2088 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2089 | g_return_if_fail(log != NULL); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2090 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2091 | data = log->logger_data; |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2092 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2093 | g_free(data->path); |
| 18513 | 2094 | g_free(data); |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2095 | } |
| 11459 | 2096 | |
| 2097 | /***************************************************************************** | |
| 2098 | * Plugin Code * | |
| 2099 | *****************************************************************************/ | |
| 2100 | ||
| 2101 | static void | |
| 15884 | 2102 | init_plugin(PurplePlugin *plugin) |
| 11459 | 2103 | { |
| 2104 | char *path; | |
| 2105 | #ifdef _WIN32 | |
| 2106 | char *folder; | |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2107 | gboolean found = FALSE; |
| 11459 | 2108 | #endif |
| 2109 | ||
| 2110 | g_return_if_fail(plugin != NULL); | |
| 2111 | ||
| 16481 | 2112 | purple_prefs_add_none("/plugins/core/log_reader"); |
| 11459 | 2113 | |
| 2114 | ||
| 2115 | /* Add general preferences. */ | |
| 2116 | ||
| 16481 | 2117 | purple_prefs_add_bool("/plugins/core/log_reader/fast_sizes", FALSE); |
| 2118 | purple_prefs_add_bool("/plugins/core/log_reader/use_name_heuristics", TRUE); | |
| 11459 | 2119 | |
| 2120 | ||
| 2121 | /* Add Adium log directory preference. */ | |
| 16481 | 2122 | purple_prefs_add_none("/plugins/core/log_reader/adium"); |
| 11459 | 2123 | |
| 2124 | /* Calculate default Adium log directory. */ | |
| 2125 | #ifdef _WIN32 | |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2126 | purple_prefs_add_string("/plugins/core/log_reader/adium/log_directory", ""); |
| 11459 | 2127 | #else |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2128 | path = g_build_filename(purple_home_dir(), "Library", "Application Support", |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2129 | "Adium 2.0", "Users", "Default", "Logs", NULL); |
| 16481 | 2130 | purple_prefs_add_string("/plugins/core/log_reader/adium/log_directory", path); |
| 11459 | 2131 | g_free(path); |
| 2132 | #endif | |
| 2133 | ||
| 2134 | ||
| 2135 | /* Add Fire log directory preference. */ | |
| 16481 | 2136 | purple_prefs_add_none("/plugins/core/log_reader/fire"); |
| 11459 | 2137 | |
| 2138 | /* Calculate default Fire log directory. */ | |
| 2139 | #ifdef _WIN32 | |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2140 | purple_prefs_add_string("/plugins/core/log_reader/fire/log_directory", ""); |
| 11459 | 2141 | #else |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2142 | path = g_build_filename(purple_home_dir(), "Library", "Application Support", |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2143 | "Fire", "Sessions", NULL); |
| 16481 | 2144 | purple_prefs_add_string("/plugins/core/log_reader/fire/log_directory", path); |
| 11459 | 2145 | g_free(path); |
| 2146 | #endif | |
| 2147 | ||
| 2148 | ||
| 2149 | /* Add Messenger Plus! log directory preference. */ | |
| 16481 | 2150 | purple_prefs_add_none("/plugins/core/log_reader/messenger_plus"); |
| 11459 | 2151 | |
| 2152 | /* Calculate default Messenger Plus! log directory. */ | |
| 2153 | #ifdef _WIN32 | |
| 15884 | 2154 | folder = wpurple_get_special_folder(CSIDL_PERSONAL); |
| 11459 | 2155 | if (folder) { |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2156 | path = g_build_filename(folder, "My Chat Logs", NULL); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2157 | g_free(folder); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2158 | } else |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2159 | path = g_strdup(""); |
| 11459 | 2160 | #else |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2161 | path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2162 | "Documents and Settings", g_get_user_name(), |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2163 | "My Documents", "My Chat Logs", NULL); |
| 11459 | 2164 | #endif |
| 16481 | 2165 | purple_prefs_add_string("/plugins/core/log_reader/messenger_plus/log_directory", path); |
| 11459 | 2166 | g_free(path); |
| 2167 | ||
| 2168 | ||
| 2169 | /* Add MSN Messenger log directory preference. */ | |
| 16481 | 2170 | purple_prefs_add_none("/plugins/core/log_reader/msn"); |
| 11459 | 2171 | |
| 2172 | /* Calculate default MSN message history directory. */ | |
| 2173 | #ifdef _WIN32 | |
| 15884 | 2174 | folder = wpurple_get_special_folder(CSIDL_PERSONAL); |
| 11459 | 2175 | if (folder) { |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2176 | path = g_build_filename(folder, "My Received Files", NULL); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2177 | g_free(folder); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2178 | } else |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2179 | path = g_strdup(""); |
| 11459 | 2180 | #else |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2181 | path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2182 | "Documents and Settings", g_get_user_name(), |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2183 | "My Documents", "My Received Files", NULL); |
| 11459 | 2184 | #endif |
| 16481 | 2185 | purple_prefs_add_string("/plugins/core/log_reader/msn/log_directory", path); |
| 11459 | 2186 | g_free(path); |
| 2187 | ||
| 2188 | ||
| 2189 | /* Add Trillian log directory preference. */ | |
| 16481 | 2190 | purple_prefs_add_none("/plugins/core/log_reader/trillian"); |
| 11459 | 2191 | |
| 2192 | #ifdef _WIN32 | |
| 2193 | /* XXX: While a major hack, this is the most reliable way I could | |
| 2194 | * think of to determine the Trillian installation directory. | |
| 2195 | */ | |
| 2196 | ||
| 2197 | path = NULL; | |
| 15884 | 2198 | if ((folder = wpurple_read_reg_string(HKEY_CLASSES_ROOT, "Trillian.SkinZip\\shell\\Add\\command\\", NULL))) { |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2199 | char *value = folder; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2200 | char *temp; |
| 11459 | 2201 | |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2202 | /* Break apart buffer. */ |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2203 | if (*value == '"') { |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2204 | value++; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2205 | temp = value; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2206 | while (*temp && *temp != '"') |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2207 | temp++; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2208 | } else { |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2209 | temp = value; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2210 | while (*temp && *temp != ' ') |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2211 | temp++; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2212 | } |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2213 | *temp = '\0'; |
| 11459 | 2214 | |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2215 | /* Set path. */ |
| 15884 | 2216 | if (purple_str_has_suffix(value, "trillian.exe")) { |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2217 | value[strlen(value) - (sizeof("trillian.exe") - 1)] = '\0'; |
|
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2218 | path = g_build_filename(value, "users", "default", "talk.ini", NULL); |
| 11459 | 2219 | } |
|
14334
aec64dbd9564
[gaim-migrate @ 16957]
Daniel Atallah <datallah@pidgin.im>
parents:
14297
diff
changeset
|
2220 | g_free(folder); |
| 11459 | 2221 | } |
| 2222 | ||
| 2223 | if (!path) { | |
| 15884 | 2224 | char *folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); |
|
14139
22ee84e0002b
[gaim-migrate @ 16698]
Daniel Atallah <datallah@pidgin.im>
parents:
14097
diff
changeset
|
2225 | if (folder) { |
| 11459 | 2226 | path = g_build_filename(folder, "Trillian", |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2227 | "users", "default", "talk.ini", NULL); |
| 11459 | 2228 | g_free(folder); |
| 2229 | } | |
| 2230 | } | |
| 2231 | ||
| 2232 | if (path) { | |
| 2233 | /* Read talk.ini file to find the log directory. */ | |
| 2234 | GError *error = NULL; | |
| 2235 | ||
|
14139
22ee84e0002b
[gaim-migrate @ 16698]
Daniel Atallah <datallah@pidgin.im>
parents:
14097
diff
changeset
|
2236 | #if 0 && GLIB_CHECK_VERSION(2,6,0) /* FIXME: Not tested yet. */ |
| 11459 | 2237 | GKeyFile *key_file; |
| 2238 | ||
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2239 | purple_debug_info("Trillian talk.ini read", "Reading %s\n", path); |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
2240 | |
|
18508
dc425927e79a
setting error to NULL before using
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
18507
diff
changeset
|
2241 | error = NULL; |
| 11459 | 2242 | if (!g_key_file_load_from_file(key_file, path, G_KEY_FILE_NONE, GError &error)) { |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2243 | purple_debug_error("Trillian talk.ini read", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2244 | "Error reading talk.ini\n"); |
| 11459 | 2245 | if (error) |
| 2246 | g_error_free(error); | |
| 2247 | } else { | |
| 2248 | char *logdir = g_key_file_get_string(key_file, "Logging", "Directory", &error); | |
| 2249 | if (error) { | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2250 | purple_debug_error("Trillian talk.ini read", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2251 | "Error reading Directory value from Logging section\n"); |
| 11459 | 2252 | g_error_free(error); |
| 2253 | } | |
| 2254 | ||
| 2255 | if (logdir) { | |
| 2256 | g_strchomp(logdir); | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2257 | purple_prefs_add_string("/plugins/core/log_reader/trillian/log_directory", logdir); |
| 11459 | 2258 | found = TRUE; |
| 2259 | } | |
| 2260 | ||
| 2261 | g_key_file_free(key_file); | |
| 2262 | } | |
|
14139
22ee84e0002b
[gaim-migrate @ 16698]
Daniel Atallah <datallah@pidgin.im>
parents:
14097
diff
changeset
|
2263 | #else /* !GLIB_CHECK_VERSION(2,6,0) */ |
| 11459 | 2264 | gsize length; |
|
14139
22ee84e0002b
[gaim-migrate @ 16698]
Daniel Atallah <datallah@pidgin.im>
parents:
14097
diff
changeset
|
2265 | gchar *contents = NULL; |
| 11459 | 2266 | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2267 | purple_debug_info("Trillian talk.ini read", |
| 11459 | 2268 | "Reading %s\n", path); |
| 2269 | if (!g_file_get_contents(path, &contents, &length, &error)) { | |
|
18512
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2270 | purple_debug_error("Trillian talk.ini read", |
|
947a4365d795
Change the purple_debug(level, ...) statements to purple_debug_level(...)
Richard Laager <rlaager@pidgin.im>
parents:
18511
diff
changeset
|
2271 | "Error reading talk.ini\n"); |
| 11459 | 2272 | if (error) |
| 2273 | g_error_free(error); | |
|
20860
f1dadcaf5051
Fix a small leak in the log_reader plugin.
Daniel Atallah <datallah@pidgin.im>
parents:
19090
diff
changeset
|
2274 | g_free(path); |
| 11459 | 2275 | } else { |
| 2276 | char *line = contents; | |
| 2277 | while (*contents) { | |
| 2278 | if (*contents == '\n') { | |
| 2279 | *contents = '\0'; | |
| 2280 | ||
| 2281 | /* XXX: This assumes the first Directory key is under [Logging]. */ | |
| 15884 | 2282 | if (purple_str_has_prefix(line, "Directory=")) { |
| 11459 | 2283 | line += (sizeof("Directory=") - 1); |
| 2284 | g_strchomp(line); | |
| 15884 | 2285 | purple_prefs_add_string( |
| 16481 | 2286 | "/plugins/core/log_reader/trillian/log_directory", |
| 11459 | 2287 | line); |
| 2288 | found = TRUE; | |
| 2289 | } | |
| 2290 | ||
| 2291 | contents++; | |
| 2292 | line = contents; | |
| 2293 | } else | |
| 2294 | contents++; | |
| 2295 | } | |
| 2296 | g_free(path); | |
| 2297 | g_free(contents); | |
| 2298 | } | |
| 2299 | #endif /* !GTK_CHECK_VERSION(2,6,0) */ | |
| 2300 | } /* path */ | |
| 2301 | ||
| 2302 | if (!found) { | |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2303 | folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2304 | if (folder) { |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2305 | path = g_build_filename(folder, "Trillian", "users", |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2306 | "default", "logs", NULL); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2307 | g_free(folder); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2308 | } else |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2309 | path = g_strdup(""); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2310 | } |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2311 | #else /* !defined(_WIN32) */ |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2312 | /* TODO: At some point, this could attempt to parse talk.ini |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2313 | * TODO: from the default Trillian install directory on the |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2314 | * TODO: Windows mount point. */ |
| 11459 | 2315 | |
| 2316 | /* Calculate default Trillian log directory. */ | |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2317 | path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2318 | "Program Files", "Trillian", "users", |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2319 | "default", "logs", NULL); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2320 | #endif |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2321 | |
|
20860
f1dadcaf5051
Fix a small leak in the log_reader plugin.
Daniel Atallah <datallah@pidgin.im>
parents:
19090
diff
changeset
|
2322 | /*XXX: Why do we even bother allocating it ? */ |
|
f1dadcaf5051
Fix a small leak in the log_reader plugin.
Daniel Atallah <datallah@pidgin.im>
parents:
19090
diff
changeset
|
2323 | g_free(path); |
|
f1dadcaf5051
Fix a small leak in the log_reader plugin.
Daniel Atallah <datallah@pidgin.im>
parents:
19090
diff
changeset
|
2324 | |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2325 | |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2326 | /* Add QIP log directory preference. */ |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2327 | purple_prefs_add_none("/plugins/core/log_reader/qip"); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2328 | |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2329 | /* Calculate default QIP log directory. */ |
| 11459 | 2330 | #ifdef _WIN32 |
| 15884 | 2331 | folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); |
| 11459 | 2332 | if (folder) { |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2333 | path = g_build_filename(folder, "QIP", "Users", NULL); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2334 | g_free(folder); |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2335 | } else |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2336 | path = g_strdup(""); |
| 11459 | 2337 | #else |
|
18517
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2338 | path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, |
|
27874b1300c9
Trying to avoid duplicating a single line of code is stupid. I've finally
Richard Laager <rlaager@pidgin.im>
parents:
18516
diff
changeset
|
2339 | "Program Files", "QIP", "Users", NULL); |
| 11459 | 2340 | #endif |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2341 | purple_prefs_add_string("/plugins/core/log_reader/qip/log_directory", path); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2342 | g_free(path); |
| 11459 | 2343 | } |
| 2344 | ||
| 2345 | static gboolean | |
| 15884 | 2346 | plugin_load(PurplePlugin *plugin) |
| 11459 | 2347 | { |
| 2348 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 2349 | ||
|
13702
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2350 | /* The names of IM clients are marked for translation at the request of |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2351 | translators who wanted to transliterate them. Many translators |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2352 | choose to leave them alone. Choose what's best for your language. */ |
| 15884 | 2353 | adium_logger = purple_log_logger_new("adium", _("Adium"), 6, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2354 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2355 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2356 | adium_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2357 | adium_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2358 | adium_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2359 | adium_logger_size); |
| 15884 | 2360 | purple_log_logger_add(adium_logger); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2361 | |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2362 | #if 0 |
|
13702
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2363 | /* The names of IM clients are marked for translation at the request of |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2364 | translators who wanted to transliterate them. Many translators |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2365 | choose to leave them alone. Choose what's best for your language. */ |
| 15884 | 2366 | fire_logger = purple_log_logger_new("fire", _("Fire"), 6, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2367 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2368 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2369 | fire_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2370 | fire_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2371 | fire_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2372 | fire_logger_size); |
| 15884 | 2373 | purple_log_logger_add(fire_logger); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2374 | |
|
13702
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2375 | /* The names of IM clients are marked for translation at the request of |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2376 | translators who wanted to transliterate them. Many translators |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2377 | choose to leave them alone. Choose what's best for your language. */ |
| 15884 | 2378 | messenger_plus_logger = purple_log_logger_new("messenger_plus", _("Messenger Plus!"), 6, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2379 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2380 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2381 | messenger_plus_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2382 | messenger_plus_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2383 | messenger_plus_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2384 | messenger_plus_logger_size); |
| 15884 | 2385 | purple_log_logger_add(messenger_plus_logger); |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
2386 | |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2387 | #endif |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2388 | |
|
13702
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2389 | /* The names of IM clients are marked for translation at the request of |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2390 | translators who wanted to transliterate them. Many translators |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2391 | choose to leave them alone. Choose what's best for your language. */ |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2392 | qip_logger = purple_log_logger_new("qip", _("QIP"), 6, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2393 | NULL, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2394 | NULL, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2395 | qip_logger_finalize, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2396 | qip_logger_list, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2397 | qip_logger_read, |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2398 | qip_logger_size); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2399 | purple_log_logger_add(qip_logger); |
|
18515
2a028601289a
Remove trailing whitespace.
Richard Laager <rlaager@pidgin.im>
parents:
18514
diff
changeset
|
2400 | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2401 | /* The names of IM clients are marked for translation at the request of |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2402 | translators who wanted to transliterate them. Many translators |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2403 | choose to leave them alone. Choose what's best for your language. */ |
| 15884 | 2404 | msn_logger = purple_log_logger_new("msn", _("MSN Messenger"), 6, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2405 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2406 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2407 | msn_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2408 | msn_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2409 | msn_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2410 | msn_logger_size); |
| 15884 | 2411 | purple_log_logger_add(msn_logger); |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2412 | |
|
13702
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2413 | /* The names of IM clients are marked for translation at the request of |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2414 | translators who wanted to transliterate them. Many translators |
|
35310965f38a
[gaim-migrate @ 16103]
Richard Laager <rlaager@pidgin.im>
parents:
13669
diff
changeset
|
2415 | choose to leave them alone. Choose what's best for your language. */ |
| 15884 | 2416 | trillian_logger = purple_log_logger_new("trillian", _("Trillian"), 6, |
|
11503
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2417 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2418 | NULL, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2419 | trillian_logger_finalize, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2420 | trillian_logger_list, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2421 | trillian_logger_read, |
|
9f15d4c089b9
[gaim-migrate @ 13748]
Richard Laager <rlaager@pidgin.im>
parents:
11459
diff
changeset
|
2422 | trillian_logger_size); |
| 15884 | 2423 | purple_log_logger_add(trillian_logger); |
| 11459 | 2424 | |
| 2425 | return TRUE; | |
| 2426 | } | |
| 2427 | ||
| 2428 | static gboolean | |
| 15884 | 2429 | plugin_unload(PurplePlugin *plugin) |
| 11459 | 2430 | { |
| 2431 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 2432 | ||
| 15884 | 2433 | purple_log_logger_remove(adium_logger); |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2434 | #if 0 |
| 15884 | 2435 | purple_log_logger_remove(fire_logger); |
| 2436 | purple_log_logger_remove(messenger_plus_logger); | |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2437 | #endif |
| 15884 | 2438 | purple_log_logger_remove(msn_logger); |
| 2439 | purple_log_logger_remove(trillian_logger); | |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2440 | purple_log_logger_remove(qip_logger); |
| 11459 | 2441 | |
| 2442 | return TRUE; | |
| 2443 | } | |
| 2444 | ||
| 15884 | 2445 | static PurplePluginPrefFrame * |
| 2446 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 11459 | 2447 | { |
| 15884 | 2448 | PurplePluginPrefFrame *frame; |
| 2449 | PurplePluginPref *ppref; | |
| 11459 | 2450 | |
| 2451 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 2452 | ||
| 15884 | 2453 | frame = purple_plugin_pref_frame_new(); |
| 11459 | 2454 | |
| 2455 | ||
| 2456 | /* Add general preferences. */ | |
| 2457 | ||
| 15884 | 2458 | ppref = purple_plugin_pref_new_with_label(_("General Log Reading Configuration")); |
| 2459 | purple_plugin_pref_frame_add(frame, ppref); | |
| 11459 | 2460 | |
| 15884 | 2461 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2462 | "/plugins/core/log_reader/fast_sizes", _("Fast size calculations")); |
| 15884 | 2463 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2464 | |
| 15884 | 2465 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2466 | "/plugins/core/log_reader/use_name_heuristics", _("Use name heuristics")); |
| 15884 | 2467 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2468 | |
| 2469 | ||
| 2470 | /* Add Log Directory preferences. */ | |
| 2471 | ||
| 15884 | 2472 | ppref = purple_plugin_pref_new_with_label(_("Log Directory")); |
| 2473 | purple_plugin_pref_frame_add(frame, ppref); | |
| 11459 | 2474 | |
| 15884 | 2475 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2476 | "/plugins/core/log_reader/adium/log_directory", _("Adium")); |
| 15884 | 2477 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2478 | |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2479 | #if 0 |
| 15884 | 2480 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2481 | "/plugins/core/log_reader/fire/log_directory", _("Fire")); |
| 15884 | 2482 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2483 | |
| 15884 | 2484 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2485 | "/plugins/core/log_reader/messenger_plus/log_directory", _("Messenger Plus!")); |
| 15884 | 2486 | purple_plugin_pref_frame_add(frame, ppref); |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2487 | #endif |
| 11459 | 2488 | |
| 15884 | 2489 | ppref = purple_plugin_pref_new_with_name_and_label( |
|
17759
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2490 | "/plugins/core/log_reader/qip/log_directory", _("QIP")); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2491 | purple_plugin_pref_frame_add(frame, ppref); |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2492 | |
|
1500107199ea
QIP logger was implemented
Michael Shkutkov <mshkutkov@soc.pidgin.im>
parents:
17642
diff
changeset
|
2493 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2494 | "/plugins/core/log_reader/msn/log_directory", _("MSN Messenger")); |
| 15884 | 2495 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2496 | |
| 15884 | 2497 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 2498 | "/plugins/core/log_reader/trillian/log_directory", _("Trillian")); |
| 15884 | 2499 | purple_plugin_pref_frame_add(frame, ppref); |
| 11459 | 2500 | |
| 2501 | return frame; | |
| 2502 | } | |
| 2503 | ||
| 15884 | 2504 | static PurplePluginUiInfo prefs_info = { |
|
12727
05ed142fbbe6
[gaim-migrate @ 15071]
Richard Laager <rlaager@pidgin.im>
parents:
11702
diff
changeset
|
2505 | get_plugin_pref_frame, |
|
05ed142fbbe6
[gaim-migrate @ 15071]
Richard Laager <rlaager@pidgin.im>
parents:
11702
diff
changeset
|
2506 | 0, /* page_num (reserved) */ |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2507 | NULL, /* frame (reserved) */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2508 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2509 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2510 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2511 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2512 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2513 | NULL |
| 11459 | 2514 | }; |
| 2515 | ||
| 15884 | 2516 | static PurplePluginInfo info = |
| 11459 | 2517 | { |
| 15884 | 2518 | PURPLE_PLUGIN_MAGIC, |
| 2519 | PURPLE_MAJOR_VERSION, | |
| 2520 | PURPLE_MINOR_VERSION, | |
| 2521 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 11459 | 2522 | NULL, /**< ui_requirement */ |
| 2523 | 0, /**< flags */ | |
| 2524 | NULL, /**< dependencies */ | |
| 15884 | 2525 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 11459 | 2526 | "core-log_reader", /**< id */ |
| 2527 | N_("Log Reader"), /**< name */ | |
| 2528 | VERSION, /**< version */ | |
| 2529 | ||
| 2530 | /** summary */ | |
| 2531 | N_("Includes other IM clients' logs in the " | |
| 2532 | "log viewer."), | |
| 2533 | ||
| 2534 | /** description */ | |
| 2535 | N_("When viewing logs, this plugin will include " | |
| 2536 | "logs from other IM clients. Currently, this " | |
|
14297
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2537 | "includes Adium, MSN Messenger, and Trillian.\n\n" |
|
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2538 | "WARNING: This plugin is still alpha code and " |
|
c1788b3112fd
[gaim-migrate @ 16917]
Richard Laager <rlaager@pidgin.im>
parents:
14253
diff
changeset
|
2539 | "may crash frequently. Use it at your own risk!"), |
| 11459 | 2540 | |
|
15629
a2261cb315e2
Switching to my pidgin.im e-mail address, which I think fits nicely and seems professional.
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
2541 | "Richard Laager <rlaager@pidgin.im>", /**< author */ |
| 15884 | 2542 | PURPLE_WEBSITE, /**< homepage */ |
| 11459 | 2543 | plugin_load, /**< load */ |
| 2544 | plugin_unload, /**< unload */ | |
| 2545 | NULL, /**< destroy */ | |
| 2546 | NULL, /**< ui_info */ | |
| 2547 | NULL, /**< extra_info */ | |
| 2548 | &prefs_info, /**< prefs_info */ | |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2549 | NULL, /**< actions */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2550 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2551 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2552 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2553 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2554 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
2555 | NULL |
| 11459 | 2556 | }; |
| 2557 | ||
| 15884 | 2558 | PURPLE_INIT_PLUGIN(log_reader, init_plugin, info) |