Changeset b75671d for protocols/jabber/iq.c
- Timestamp:
- 2015-06-17T22:47:26Z (9 years ago)
- Children:
- b441614
- Parents:
- d832164 (diff), 2f99f23 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
rd832164 rb75671d 27 27 static xt_status jabber_parse_roster(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 28 28 static xt_status jabber_iq_display_vcard(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 29 static xt_status jabber_gmail_handle_new(struct im_connection *ic, struct xt_node *node); 29 30 30 31 xt_status jabber_pkt_iq(struct xt_node *node, gpointer data) … … 141 142 (strcmp(s, XMLNS_SI) == 0)) { 142 143 return jabber_si_handle_request(ic, node, c); 144 } else if ((c = xt_find_node(node->children, "new-mail")) && 145 (s = xt_find_attr(c, "xmlns")) && 146 (strcmp(s, XMLNS_GMAILNOTIFY) == 0)) { 147 return jabber_gmail_handle_new(ic, node); 143 148 } else if (!(c = xt_find_node(node->children, "query")) || 144 149 !(s = xt_find_attr(c, "xmlns"))) { … … 342 347 return XT_ABORT; 343 348 } 349 if (jd->flags & JFLAG_GMAILNOTIFY && node == NULL) { 350 jabber_iq_query_server(ic, jd->server, XMLNS_DISCO_INFO); 351 } 344 352 } else if ((jd->flags & (JFLAG_WANT_BIND | JFLAG_WANT_SESSION)) == 0) { 345 353 if (!jabber_get_roster(ic)) { … … 369 377 370 378 return st; 379 } 380 381 xt_status jabber_iq_query_gmail(struct im_connection *ic); 382 383 static xt_status jabber_gmail_handle_new(struct im_connection *ic, struct xt_node *node) 384 { 385 struct xt_node *response; 386 struct jabber_data *jd = ic->proto_data; 387 388 response = jabber_make_packet("iq", "result", g_strdup_printf("%s@%s", jd->username, jd->server), NULL); 389 390 jabber_cache_add(ic, response, NULL); 391 if (!jabber_write_packet(ic, response)) { 392 return XT_ABORT; 393 } 394 395 jabber_iq_query_gmail(ic); 396 397 return XT_HANDLED; 371 398 } 372 399 … … 710 737 } 711 738 739 xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 740 741 xt_status jabber_iq_query_gmail(struct im_connection *ic) 742 { 743 struct xt_node *node, *query; 744 struct jabber_data *jd = ic->proto_data; 745 746 node = xt_new_node("query", NULL, NULL); 747 xt_add_attr(node, "xmlns", XMLNS_GMAILNOTIFY); 748 if (jd->gmail_time) { 749 char *formatted = g_strdup_printf("%" G_GUINT64_FORMAT, (jd->gmail_time + 1)); 750 xt_add_attr(node, "newer-than-time", formatted); 751 g_free(formatted); 752 } 753 if (jd->gmail_tid) { 754 xt_add_attr(node, "newer-than-tid", jd->gmail_tid); 755 } 756 757 if (!(query = jabber_make_packet("iq", "get", jd->me, node))) { 758 imcb_log(ic, "WARNING: Couldn't generate server query"); 759 xt_free_node(node); 760 } 761 762 jabber_cache_add(ic, query, jabber_iq_parse_gmail); 763 764 return jabber_write_packet(ic, query) ? XT_HANDLED : XT_ABORT; 765 } 766 712 767 xt_status jabber_iq_parse_server_features(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 713 768 … … 729 784 730 785 return jabber_write_packet(ic, query) ? XT_HANDLED : XT_ABORT; 786 } 787 788 xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node, struct xt_node *orig) 789 { 790 struct xt_node *c; 791 struct jabber_data *jd = ic->proto_data; 792 char *xmlns, *from; 793 guint64 l_time = 0; 794 char *tid = NULL; 795 int max = 0; 796 797 if (!(c = xt_find_node(node->children, "mailbox")) || 798 !(from = xt_find_attr(node, "from")) || 799 !(xmlns = xt_find_attr(c, "xmlns")) || 800 (g_strcmp0(xmlns, XMLNS_GMAILNOTIFY) != 0)) { 801 imcb_log(ic, "WARNING: Received incomplete mailbox packet for gmail notify"); 802 return XT_HANDLED; 803 } 804 805 max = set_getint(&ic->acc->set, "mail_notifications_limit"); 806 c = c->children; 807 808 while ((max-- > 0) && (c = xt_find_node(c, "mail-thread-info"))) { 809 struct xt_node *s; 810 char *subject = "<no subject>"; 811 char *sender = "<no sender>"; 812 guint64 t_time; 813 814 t_time = g_ascii_strtoull(xt_find_attr(c, "date"), NULL, 10); 815 if (t_time && t_time > l_time) { 816 l_time = t_time; 817 tid = xt_find_attr(c, "tid"); 818 } 819 820 if ((s = xt_find_node(c->children, "senders")) && 821 (s = xt_find_node_by_attr(s->children, "sender", "unread", "1"))) { 822 sender = xt_find_attr(s, "name"); 823 } 824 825 if ((s = xt_find_node(c->children, "subject")) && s->text) { 826 subject = s->text; 827 } 828 829 imcb_notify_email(ic, "New mail from %s: %s", sender, subject); 830 831 c = c->next; 832 } 833 834 if (l_time && (!jd->gmail_time || l_time > jd->gmail_time)) { 835 jd->gmail_time = l_time; 836 if (tid) { 837 g_free(jd->gmail_tid); 838 jd->gmail_tid = g_strdup(tid); 839 } 840 } 841 842 return XT_HANDLED; 731 843 } 732 844 … … 781 893 c = c->next; 782 894 } 895 896 if (jd->flags & JFLAG_GMAILNOTIFY) { 897 /* search for gmail notification feature */ 898 c = xt_find_node(node->children, "query"); 899 c = c->children; 900 while ((c = xt_find_node(c, "feature"))) { 901 if (strcmp(xt_find_attr(c, "var"), XMLNS_GMAILNOTIFY) == 0) { 902 jabber_iq_query_gmail(ic); 903 } 904 c = c->next; 905 } 906 } 907 783 908 } else if (strcmp(xmlns, XMLNS_BYTESTREAMS) == 0) { 784 909 char *host, *jid, *port_s;
Note: See TracChangeset
for help on using the changeset viewer.