comparison src/protocols/oscar/oscar.c @ 13356:554575d1f9b5

[gaim-migrate @ 15729] Move gaim_str_sub_away_formatters into the oscar PRPL. It wasn't used anywhere else. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 01 Mar 2006 05:13:26 +0000
parents f6f465b8d1c0
children d1b29fb3b6d0
comparison
equal deleted inserted replaced
13355:d278dac585a5 13356:554575d1f9b5
614 *msg = g_strdup(from); 614 *msg = g_strdup(from);
615 *msglen_int = strlen(*msg); 615 *msglen_int = strlen(*msg);
616 *charset = AIM_CHARSET_ASCII; 616 *charset = AIM_CHARSET_ASCII;
617 *charsubset = 0x0000; 617 *charsubset = 0x0000;
618 return; 618 return;
619 }
620
621 /**
622 * Looks for %n, %d, or %t in a string, and replaces them with the
623 * specified name, date, and time, respectively.
624 *
625 * @param str The string that may contain the special variables.
626 * @param name The sender name.
627 *
628 * @return A newly allocated string where the special variables are
629 * expanded. This should be g_free'd by the caller.
630 */
631 static gchar *
632 gaim_str_sub_away_formatters(const char *str, const char *name)
633 {
634 char *c;
635 GString *cpy;
636 time_t t;
637 struct tm *tme;
638
639 g_return_val_if_fail(str != NULL, NULL);
640 g_return_val_if_fail(name != NULL, NULL);
641
642 /* Create an empty GString that is hopefully big enough for most messages */
643 cpy = g_string_sized_new(1024);
644
645 t = time(NULL);
646 tme = localtime(&t);
647
648 c = (char *)str;
649 while (*c) {
650 switch (*c) {
651 case '%':
652 if (*(c + 1)) {
653 switch (*(c + 1)) {
654 case 'n':
655 /* append name */
656 g_string_append(cpy, name);
657 c++;
658 break;
659 case 'd':
660 /* append date */
661 g_string_append(cpy, gaim_date_format_short(tme));
662 c++;
663 break;
664 case 't':
665 /* append time */
666 g_string_append(cpy, gaim_time_format(tme));
667 c++;
668 break;
669 default:
670 g_string_append_c(cpy, *c);
671 }
672 } else {
673 g_string_append_c(cpy, *c);
674 }
675 break;
676 default:
677 g_string_append_c(cpy, *c);
678 }
679 c++;
680 }
681
682 return g_string_free(cpy, FALSE);
619 } 683 }
620 684
621 static gchar *oscar_caps_to_string(guint caps) 685 static gchar *oscar_caps_to_string(guint caps)
622 { 686 {
623 GString *str; 687 GString *str;
6441 int ret = 0; 6505 int ret = 0;
6442 char *iconfile = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(account)); 6506 char *iconfile = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(account));
6443 char *tmp1, *tmp2; 6507 char *tmp1, *tmp2;
6444 6508
6445 if (imflags & GAIM_MESSAGE_AUTO_RESP) 6509 if (imflags & GAIM_MESSAGE_AUTO_RESP)
6510 /*
6511 * TODO: Do this earlier in the IM-sending chain of events.
6512 * We should attach to an IM-sending signal and do it
6513 * there. As it is currently implemented, encrypted
6514 * messages are not substituted.
6515 */
6446 tmp1 = gaim_str_sub_away_formatters(message, name); 6516 tmp1 = gaim_str_sub_away_formatters(message, name);
6447 else 6517 else
6448 tmp1 = g_strdup(message); 6518 tmp1 = g_strdup(message);
6449 6519
6450 if (dim && dim->connected) { 6520 if (dim && dim->connected) {