comparison plugins/log_reader.c @ 13497:2f0d4179ec05

[gaim-migrate @ 15873] Use gaim_str_has_prefix() and gaim_str_has_suffix() for compatibility with old versions of glib. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 13 Mar 2006 18:51:47 +0000
parents e8b0a9376481
children 5c8565315d3e
comparison
equal deleted inserted replaced
13496:d2aadcdbec6c 13497:2f0d4179ec05
94 dir = g_dir_open(path, 0, NULL); 94 dir = g_dir_open(path, 0, NULL);
95 if (dir) { 95 if (dir) {
96 const gchar *file; 96 const gchar *file;
97 97
98 while ((file = g_dir_read_name(dir))) { 98 while ((file = g_dir_read_name(dir))) {
99 if (!g_str_has_prefix(file, sn)) 99 if (!gaim_str_has_prefix(file, sn))
100 continue; 100 continue;
101 if (g_str_has_suffix(file, ".html") || g_str_has_suffix(file, ".AdiumHTMLLog")) { 101 if (gaim_str_has_suffix(file, ".html") || gaim_str_has_suffix(file, ".AdiumHTMLLog")) {
102 struct tm tm; 102 struct tm tm;
103 const char *date = file; 103 const char *date = file;
104 104
105 date += strlen(sn) + 2; 105 date += strlen(sn) + 2;
106 if (sscanf(date, "%u|%u|%u", 106 if (sscanf(date, "%u|%u|%u",
161 log->logger = adium_logger; 161 log->logger = adium_logger;
162 log->logger_data = data; 162 log->logger_data = data;
163 163
164 list = g_list_append(list, log); 164 list = g_list_append(list, log);
165 } 165 }
166 } else if (g_str_has_suffix(file, ".adiumLog")) { 166 } else if (gaim_str_has_suffix(file, ".adiumLog")) {
167 struct tm tm; 167 struct tm tm;
168 const char *date = file; 168 const char *date = file;
169 169
170 date += strlen(sn) + 2; 170 date += strlen(sn) + 2;
171 if (sscanf(date, "%u|%u|%u", 171 if (sscanf(date, "%u|%u|%u",
266 266
267 #ifdef WIN32 267 #ifdef WIN32
268 /* This problem only seems to show up on Windows. 268 /* This problem only seems to show up on Windows.
269 * The BOM is displaying as a space at the beginning of the log. 269 * The BOM is displaying as a space at the beginning of the log.
270 */ 270 */
271 if (g_str_has_prefix(read, "\xef\xbb\xbf")) 271 if (gaim_str_has_prefix(read, "\xef\xbb\xbf"))
272 { 272 {
273 /* FIXME: This feels so wrong... */ 273 /* FIXME: This feels so wrong... */
274 char *temp = g_strdup(&(read[3])); 274 char *temp = g_strdup(&(read[3]));
275 g_free(read); 275 g_free(read);
276 read = temp; 276 read = temp;
585 const gchar *name; 585 const gchar *name;
586 586
587 while ((name = g_dir_read_name(dir))) { 587 while ((name = g_dir_read_name(dir))) {
588 const char *c = name; 588 const char *c = name;
589 589
590 if (!g_str_has_prefix(c, username)) 590 if (!gaim_str_has_prefix(c, username))
591 continue; 591 continue;
592 592
593 c += strlen(username); 593 c += strlen(username);
594 while (*c) { 594 while (*c) {
595 if (!g_ascii_isdigit(*c)) 595 if (!g_ascii_isdigit(*c))
639 const gchar *name; 639 const gchar *name;
640 640
641 while ((name = g_dir_read_name(dir))) { 641 while ((name = g_dir_read_name(dir))) {
642 const char *c = name; 642 const char *c = name;
643 643
644 if (!g_str_has_prefix(c, username)) 644 if (!gaim_str_has_prefix(c, username))
645 continue; 645 continue;
646 646
647 c += strlen(username); 647 c += strlen(username);
648 while (*c) { 648 while (*c) {
649 if (!g_ascii_isdigit(*c)) 649 if (!g_ascii_isdigit(*c))
855 * The first step is to determine if either of the names matches either my 855 * The first step is to determine if either of the names matches either my
856 * friendly name or alias. For this test, "match" is defined as: 856 * friendly name or alias. For this test, "match" is defined as:
857 * ^(friendly_name|alias)([^a-zA-Z0-9].*)?$ 857 * ^(friendly_name|alias)([^a-zA-Z0-9].*)?$
858 */ 858 */
859 from_name_matches = from_name != NULL && ( 859 from_name_matches = from_name != NULL && (
860 (g_str_has_prefix(from_name, friendly_name) && 860 (gaim_str_has_prefix(from_name, friendly_name) &&
861 !isalnum(*(from_name + friendly_name_length))) || 861 !isalnum(*(from_name + friendly_name_length))) ||
862 (g_str_has_prefix(from_name, log->account->alias) && 862 (gaim_str_has_prefix(from_name, log->account->alias) &&
863 !isalnum(*(from_name + alias_length)))); 863 !isalnum(*(from_name + alias_length))));
864 864
865 to_name_matches = to_name != NULL && ( 865 to_name_matches = to_name != NULL && (
866 (gaim_str_has_prefix(to_name, friendly_name) && 866 (gaim_str_has_prefix(to_name, friendly_name) &&
867 !isalnum(*(to_name + friendly_name_length))) || 867 !isalnum(*(to_name + friendly_name_length))) ||
893 /* Try to guess which user is them. 893 /* Try to guess which user is them.
894 * The first step is to determine if either of the names 894 * The first step is to determine if either of the names
895 * matches their alias. For this test, "match" is 895 * matches their alias. For this test, "match" is
896 * defined as: ^alias([^a-zA-Z0-9].*)?$ 896 * defined as: ^alias([^a-zA-Z0-9].*)?$
897 */ 897 */
898 from_name_matches = (g_str_has_prefix( 898 from_name_matches = (gaim_str_has_prefix(
899 from_name, alias) && 899 from_name, alias) &&
900 !isalnum(*(from_name + 900 !isalnum(*(from_name +
901 alias_length))); 901 alias_length)));
902 902
903 to_name_matches = (g_str_has_prefix( 903 to_name_matches = (gaim_str_has_prefix(
904 to_name, alias) && 904 to_name, alias) &&
905 !isalnum(*(to_name + 905 !isalnum(*(to_name +
906 alias_length))); 906 alias_length)));
907 907
908 g_free(alias); 908 g_free(alias);
921 * The first step is to determine if either of 921 * The first step is to determine if either of
922 * the names matches their friendly name. For 922 * the names matches their friendly name. For
923 * this test, "match" is defined as: 923 * this test, "match" is defined as:
924 * ^friendly_name([^a-zA-Z0-9].*)?$ 924 * ^friendly_name([^a-zA-Z0-9].*)?$
925 */ 925 */
926 from_name_matches = (g_str_has_prefix( 926 from_name_matches = (gaim_str_has_prefix(
927 from_name, 927 from_name,
928 buddy->server_alias) && 928 buddy->server_alias) &&
929 !isalnum(*(from_name + 929 !isalnum(*(from_name +
930 friendly_name_length))); 930 friendly_name_length)));
931 931
932 to_name_matches = (g_str_has_prefix( 932 to_name_matches = (gaim_str_has_prefix(
933 to_name, buddy->server_alias) && 933 to_name, buddy->server_alias) &&
934 !isalnum(*(to_name + 934 !isalnum(*(to_name +
935 friendly_name_length))); 935 friendly_name_length)));
936 936
937 if (from_name_matches) { 937 if (from_name_matches) {
1128 c++; 1128 c++;
1129 continue; 1129 continue;
1130 } 1130 }
1131 1131
1132 *c = '\0'; 1132 *c = '\0';
1133 if (g_str_has_prefix(line, "Session Close ")) { 1133 if (gaim_str_has_prefix(line, "Session Close ")) {
1134 if (data && !data->length) 1134 if (data && !data->length)
1135 data->length = last_line_offset - data->offset; 1135 data->length = last_line_offset - data->offset;
1136 if (!data->length) { 1136 if (!data->length) {
1137 /* This log had no data, so we remove it. */ 1137 /* This log had no data, so we remove it. */
1138 GList *last = g_list_last(list); 1138 GList *last = g_list_last(list);
1142 1142
1143 trillian_logger_finalize((GaimLog *)last->data); 1143 trillian_logger_finalize((GaimLog *)last->data);
1144 list = g_list_delete_link(list, last); 1144 list = g_list_delete_link(list, last);
1145 } 1145 }
1146 } else if (line[0] && line[1] && line [3] && 1146 } else if (line[0] && line[1] && line [3] &&
1147 g_str_has_prefix(&line[3], "sion Start ")) { 1147 gaim_str_has_prefix(&line[3], "sion Start ")) {
1148 1148
1149 char *their_nickname = line; 1149 char *their_nickname = line;
1150 char *timestamp; 1150 char *timestamp;
1151 1151
1152 if (data && !data->length) 1152 if (data && !data->length)
1395 line = timestamp; 1395 line = timestamp;
1396 if (line[1] && line[2]) 1396 if (line[1] && line[2])
1397 line += 2; 1397 line += 2;
1398 } 1398 }
1399 1399
1400 if (g_str_has_prefix(line, "*** ")) { 1400 if (gaim_str_has_prefix(line, "*** ")) {
1401 line += (sizeof("*** ") - 1); 1401 line += (sizeof("*** ") - 1);
1402 g_string_append(formatted, "<b>"); 1402 g_string_append(formatted, "<b>");
1403 footer = "</b>"; 1403 footer = "</b>";
1404 if (g_str_has_prefix(line, "NOTE: This user is offline.")) { 1404 if (gaim_str_has_prefix(line, "NOTE: This user is offline.")) {
1405 line = _("User is offline."); 1405 line = _("User is offline.");
1406 } else if (g_str_has_prefix(line, 1406 } else if (gaim_str_has_prefix(line,
1407 "NOTE: Your status is currently set to ")) { 1407 "NOTE: Your status is currently set to ")) {
1408 1408
1409 line += (sizeof("NOTE: ") - 1); 1409 line += (sizeof("NOTE: ") - 1);
1410 } else if (g_str_has_prefix(line, "Auto-response sent to ")) { 1410 } else if (gaim_str_has_prefix(line, "Auto-response sent to ")) {
1411 g_string_append(formatted, _("Auto-response sent:")); 1411 g_string_append(formatted, _("Auto-response sent:"));
1412 while (*line && *line != ':') 1412 while (*line && *line != ':')
1413 line++; 1413 line++;
1414 if (*line) 1414 if (*line)
1415 line++; 1415 line++;
1427 if (buddy != NULL && buddy->alias) 1427 if (buddy != NULL && buddy->alias)
1428 g_string_append(formatted, buddy->alias); 1428 g_string_append(formatted, buddy->alias);
1429 else 1429 else
1430 g_string_append(formatted, log->name); 1430 g_string_append(formatted, log->name);
1431 line = " logged in."; 1431 line = " logged in.";
1432 } else if (g_str_has_prefix(line, 1432 } else if (gaim_str_has_prefix(line,
1433 "One or more messages may have been undeliverable.")) { 1433 "One or more messages may have been undeliverable.")) {
1434 1434
1435 g_string_append(formatted, 1435 g_string_append(formatted,
1436 "<span style=\"color: #ff0000;\">"); 1436 "<span style=\"color: #ff0000;\">");
1437 g_string_append(formatted, 1437 g_string_append(formatted,
1438 _("One or more messages may have been " 1438 _("One or more messages may have been "
1439 "undeliverable.")); 1439 "undeliverable."));
1440 line = ""; 1440 line = "";
1441 footer = "</span></b>"; 1441 footer = "</span></b>";
1442 } else if (g_str_has_prefix(line, 1442 } else if (gaim_str_has_prefix(line,
1443 "You have been disconnected.")) { 1443 "You have been disconnected.")) {
1444 1444
1445 g_string_append(formatted, 1445 g_string_append(formatted,
1446 "<span style=\"color: #ff0000;\">"); 1446 "<span style=\"color: #ff0000;\">");
1447 g_string_append(formatted, 1447 g_string_append(formatted,
1448 _("You were disconnected from the server.")); 1448 _("You were disconnected from the server."));
1449 line = ""; 1449 line = "";
1450 footer = "</span></b>"; 1450 footer = "</span></b>";
1451 } else if (g_str_has_prefix(line, 1451 } else if (gaim_str_has_prefix(line,
1452 "You are currently disconnected.")) { 1452 "You are currently disconnected.")) {
1453 1453
1454 g_string_append(formatted, 1454 g_string_append(formatted,
1455 "<span style=\"color: #ff0000;\">"); 1455 "<span style=\"color: #ff0000;\">");
1456 line = _("You are currently disconnected. Messages " 1456 line = _("You are currently disconnected. Messages "
1457 "will not be received unless you are " 1457 "will not be received unless you are "
1458 "logged in."); 1458 "logged in.");
1459 footer = "</span></b>"; 1459 footer = "</span></b>";
1460 } else if (g_str_has_prefix(line, 1460 } else if (gaim_str_has_prefix(line,
1461 "Your previous message has not been sent.")) { 1461 "Your previous message has not been sent.")) {
1462 1462
1463 g_string_append(formatted, 1463 g_string_append(formatted,
1464 "<span style=\"color: #ff0000;\">"); 1464 "<span style=\"color: #ff0000;\">");
1465 1465
1466 if (g_str_has_prefix(line, 1466 if (gaim_str_has_prefix(line,
1467 "Your previous message has not been sent. " 1467 "Your previous message has not been sent. "
1468 "Reason: Maximum length exceeded.")) { 1468 "Reason: Maximum length exceeded.")) {
1469 1469
1470 g_string_append(formatted, 1470 g_string_append(formatted,
1471 _("Message could not be sent because " 1471 _("Message could not be sent because "
1479 "has not been sent. ") - 1); 1479 "has not been sent. ") - 1);
1480 } 1480 }
1481 1481
1482 footer = "</span></b>"; 1482 footer = "</span></b>";
1483 } 1483 }
1484 } else if (g_str_has_prefix(line, data->their_nickname)) { 1484 } else if (gaim_str_has_prefix(line, data->their_nickname)) {
1485 if (buddy != NULL && buddy->alias) { 1485 if (buddy != NULL && buddy->alias) {
1486 line += strlen(data->their_nickname) + 2; 1486 line += strlen(data->their_nickname) + 2;
1487 g_string_append_printf(formatted, 1487 g_string_append_printf(formatted,
1488 "<span style=\"color: #A82F2F;\">" 1488 "<span style=\"color: #A82F2F;\">"
1489 "<b>%s</b></span>: ", buddy->alias); 1489 "<b>%s</b></span>: ", buddy->alias);
1707 temp++; 1707 temp++;
1708 } 1708 }
1709 *temp = '\0'; 1709 *temp = '\0';
1710 1710
1711 /* Set path. */ 1711 /* Set path. */
1712 if (g_str_has_suffix(value, "trillian.exe")) 1712 if (gaim_str_has_suffix(value, "trillian.exe"))
1713 { 1713 {
1714 value[strlen(value) - (sizeof("trillian.exe") - 1)] = '\0'; 1714 value[strlen(value) - (sizeof("trillian.exe") - 1)] = '\0';
1715 path = g_build_filename(value, "users", "default", "talk.ini", NULL); 1715 path = g_build_filename(value, "users", "default", "talk.ini", NULL);
1716 } 1716 }
1717 } 1717 }
1776 while (*contents) { 1776 while (*contents) {
1777 if (*contents == '\n') { 1777 if (*contents == '\n') {
1778 *contents = '\0'; 1778 *contents = '\0';
1779 1779
1780 /* XXX: This assumes the first Directory key is under [Logging]. */ 1780 /* XXX: This assumes the first Directory key is under [Logging]. */
1781 if (g_str_has_prefix(line, "Directory=")) { 1781 if (gaim_str_has_prefix(line, "Directory=")) {
1782 line += (sizeof("Directory=") - 1); 1782 line += (sizeof("Directory=") - 1);
1783 g_strchomp(line); 1783 g_strchomp(line);
1784 gaim_prefs_add_string( 1784 gaim_prefs_add_string(
1785 "/plugins/core/log_reader/trillian/log_directory", 1785 "/plugins/core/log_reader/trillian/log_directory",
1786 line); 1786 line);