comparison src/protocols/jabber/jabber.c @ 3159:fce1883cc608

[gaim-migrate @ 3175] new shortcuts: Ctrl-- Decrease Font Size Ctrl-= Increase Font Size Ctrl-0 Normal Font Size Ctrl-F Select Font Ctrl-C Text Color Ctrl-W Close IM/Chat Window (or Tab, if using tabbed conversations) Ctrl-N New IM/Chat Tab (if using tabbed conversations) Ctrl-Z Minimize (Iconify) IM/Chat Window -As suggested by Shreedeep K Bhachech committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Apr 2002 08:10:13 +0000
parents 0097f5462ac2
children 09e342b27eff
comparison
equal deleted inserted replaced
3158:ea6f8d8d74e5 3159:fce1883cc608
729 } else { 729 } else {
730 g_hash_table_insert(jd->hash, g_strdup(name), msg); 730 g_hash_table_insert(jd->hash, g_strdup(name), msg);
731 } 731 }
732 } 732 }
733 733
734 static time_t iso8601_to_time(char *timestamp)
735 {
736 struct tm t;
737 if(sscanf(timestamp,"%04d%02d%02dT%02d:%02d:%02d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec))
738 {
739 t.tm_year -= 1900;
740 t.tm_mon -= 1;
741 return mktime(&t) - timezone;
742 }
743 return 0;
744 }
745
734 static void jabber_handlemessage(gjconn gjc, jpacket p) 746 static void jabber_handlemessage(gjconn gjc, jpacket p)
735 { 747 {
736 xmlnode y, xmlns, subj; 748 xmlnode y, xmlns, subj, z;
749 time_t time_sent = time(NULL);
737 750
738 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; 751 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL;
739 char m[BUF_LONG * 2]; 752 char m[BUF_LONG * 2];
740 753
741 type = xmlnode_get_attrib(p->x, "type"); 754 type = xmlnode_get_attrib(p->x, "type");
755
756 z = xmlnode_get_firstchild(p->x);
757
758 while(z)
759 {
760 if(NSCHECK(z,NS_DELAY))
761 {
762 char *timestamp = xmlnode_get_attrib(z,"stamp");
763 time_sent = iso8601_to_time(timestamp);
764 }
765 z = xmlnode_get_nextsibling(z);
766 }
742 767
743 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { 768 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) {
744 769
745 /* XXX namespaces could be handled better. (mid) */ 770 /* XXX namespaces could be handled better. (mid) */
746 if ((xmlns = xmlnode_get_tag(p->x, "x"))) 771 if ((xmlns = xmlnode_get_tag(p->x, "x")))
776 serv_got_chat_invite(GJ_GC(gjc), room, from, msg, m); 801 serv_got_chat_invite(GJ_GC(gjc), room, from, msg, m);
777 } else if (msg) { /* whisper */ 802 } else if (msg) { /* whisper */
778 struct jabber_chat *jc; 803 struct jabber_chat *jc;
779 g_snprintf(m, sizeof(m), "%s", msg); 804 g_snprintf(m, sizeof(m), "%s", msg);
780 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) 805 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b)
781 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, time(NULL)); 806 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, time_sent);
782 else { 807 else {
783 int flags = 0; 808 int flags = 0;
784 if (xmlnode_get_tag(p->x, "gaim")) 809 if (xmlnode_get_tag(p->x, "gaim"))
785 flags = IM_FLAG_GAIMUSER; 810 flags = IM_FLAG_GAIMUSER;
786 if (find_conversation(jid_full(p->from))) 811 if (find_conversation(jid_full(p->from)))
787 serv_got_im(GJ_GC(gjc), jid_full(p->from), m, flags, time(NULL), -1); 812 serv_got_im(GJ_GC(gjc), jid_full(p->from), m, flags, time_sent, -1);
788 else { 813 else {
789 if(p->from->user) { 814 if(p->from->user) {
790 from = g_strdup_printf("%s@%s", p->from->user, p->from->server); 815 from = g_strdup_printf("%s@%s", p->from->user, p->from->server);
791 } else { 816 } else {
792 /* server message? */ 817 /* server message? */
793 from = g_strdup(p->from->server); 818 from = g_strdup(p->from->server);
794 } 819 }
795 serv_got_im(GJ_GC(gjc), from, m, flags, time(NULL), -1); 820 serv_got_im(GJ_GC(gjc), from, m, flags, time_sent, -1);
796 g_free(from); 821 g_free(from);
797 } 822 }
798 } 823 }
799 } 824 }
800 825
868 chat_set_topic(jc->b, p->from->resource, tbuf); 893 chat_set_topic(jc->b, p->from->resource, tbuf);
869 } 894 }
870 895
871 896
872 g_snprintf(buf, sizeof(buf), "%s", msg); 897 g_snprintf(buf, sizeof(buf), "%s", msg);
873 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, time(NULL)); 898 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, time_sent);
874 } 899 }
875 } else { /* message from the server */ 900 } else { /* message from the server */
876 if(jc->b && topic) { 901 if(jc->b && topic) {
877 char tbuf[8192]; 902 char tbuf[8192];
878 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); 903 g_snprintf(tbuf, sizeof(tbuf), "%s", topic);
885 910
886 } else { 911 } else {
887 debug_printf("unhandled message %s\n", type); 912 debug_printf("unhandled message %s\n", type);
888 } 913 }
889 } 914 }
890 915
891 static void jabber_handlepresence(gjconn gjc, jpacket p) 916 static void jabber_handlepresence(gjconn gjc, jpacket p)
892 { 917 {
893 char *to, *from, *type; 918 char *to, *from, *type;
894 struct buddy *b = NULL; 919 struct buddy *b = NULL;
895 jid who; 920 jid who;
906 931
907 to = xmlnode_get_attrib(p->x, "to"); 932 to = xmlnode_get_attrib(p->x, "to");
908 from = xmlnode_get_attrib(p->x, "from"); 933 from = xmlnode_get_attrib(p->x, "from");
909 type = xmlnode_get_attrib(p->x, "type"); 934 type = xmlnode_get_attrib(p->x, "type");
910 935
911 z = xmlnode_get_tag(p->x, "x"); 936 z = xmlnode_get_firstchild(p->x);
912 937
913 if(NSCHECK(z,NS_DELAY)) 938 while(z)
914 { 939 {
915 struct tm t; 940 if(NSCHECK(z,NS_DELAY))
916 char *timestamp = xmlnode_get_attrib(z,"stamp");
917 if(sscanf(timestamp,"%04d%02d%02dT%02d:%02d:%02d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec))
918 { 941 {
919 t.tm_year -= 1900; 942 char *timestamp = xmlnode_get_attrib(z,"stamp");
920 t.tm_mon -= 1; 943 signon = iso8601_to_time(timestamp);
921 signon = mktime(&t) - timezone;
922 } 944 }
923 } 945 z = xmlnode_get_nextsibling(z);
924 946 }
947
925 if ((y = xmlnode_get_tag(p->x, "show"))) { 948 if ((y = xmlnode_get_tag(p->x, "show"))) {
926 show = xmlnode_get_data(y); 949 show = xmlnode_get_data(y);
927 if (!show) { 950 if (!show) {
928 state = 0; 951 state = 0;
929 } else if (!strcasecmp(show, "away")) { 952 } else if (!strcasecmp(show, "away")) {