comparison mcabber/src/jab_iq.c @ 1016:4d3c48844746

Add /roster note Implement XEP-0145 (Annotations) Usage: /roster note [-|note_text]
author Mikael Berthe <mikael@lilotux.net>
date Wed, 15 Nov 2006 00:04:57 +0100
parents 579299b1c9b2
children f7ef8003fc35
comparison
equal deleted inserted replaced
1015:579299b1c9b2 1016:4d3c48844746
34 #include "hbuf.h" 34 #include "hbuf.h"
35 35
36 36
37 // Bookmarks for IQ:private storage 37 // Bookmarks for IQ:private storage
38 xmlnode bookmarks; 38 xmlnode bookmarks;
39 // Roster notes for IQ:private storage
40 xmlnode rosternotes;
39 41
40 static GSList *iqs_list; 42 static GSList *iqs_list;
41 43
42 // Enum for vCard attributes 44 // Enum for vCard attributes
43 enum vcard_attr { 45 enum vcard_attr {
682 p = xmlnode_get_name(x); 684 p = xmlnode_get_name(x);
683 // If the current node is a conference item, parse it and update the roster 685 // If the current node is a conference item, parse it and update the roster
684 if (p && !strcmp(p, "conference")) 686 if (p && !strcmp(p, "conference"))
685 storage_bookmarks_parse_conference(x); 687 storage_bookmarks_parse_conference(x);
686 } 688 }
689 // Copy the bookmarks node
687 xmlnode_free(bookmarks); 690 xmlnode_free(bookmarks);
688 bookmarks = xmlnode_dup(ansqry); 691 bookmarks = xmlnode_dup(ansqry);
689 } 692 }
690 693
691 static void request_storage_bookmarks(void) 694 static void request_storage_bookmarks(void)
697 700
698 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage"); 701 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
699 xmlnode_put_attrib(x, "xmlns", "storage:bookmarks"); 702 xmlnode_put_attrib(x, "xmlns", "storage:bookmarks");
700 703
701 iqn->callback = &iqscallback_storage_bookmarks; 704 iqn->callback = &iqscallback_storage_bookmarks;
705 jab_send(jc, iqn->xmldata);
706 }
707
708 static void iqscallback_storage_rosternotes(eviqs *iqp, xmlnode xml_result,
709 guint iqcontext)
710 {
711 xmlnode ansqry;
712
713 // Leave now if we cannot process xml_result
714 if (!xml_result || iqcontext) return;
715
716 ansqry = xmlnode_get_tag(xml_result, "query");
717 ansqry = xmlnode_get_tag(ansqry, "storage");
718 if (!ansqry) {
719 scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! "
720 "(storage:rosternotes)");
721 return;
722 }
723 // Copy the rosternotes node
724 xmlnode_free(rosternotes);
725 rosternotes = xmlnode_dup(ansqry);
726 }
727
728 static void request_storage_rosternotes(void)
729 {
730 eviqs *iqn;
731 xmlnode x;
732
733 iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
734
735 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
736 xmlnode_put_attrib(x, "xmlns", "storage:rosternotes");
737
738 iqn->callback = &iqscallback_storage_rosternotes;
702 jab_send(jc, iqn->xmldata); 739 jab_send(jc, iqn->xmldata);
703 } 740 }
704 741
705 void iqscallback_auth(eviqs *iqp, xmlnode xml_result) 742 void iqscallback_auth(eviqs *iqp, xmlnode xml_result)
706 { 743 {
719 jab_send(jc, iqn->xmldata); 756 jab_send(jc, iqn->xmldata);
720 jstate = STATE_SENDAUTH; 757 jstate = STATE_SENDAUTH;
721 } else if (jstate == STATE_SENDAUTH) { 758 } else if (jstate == STATE_SENDAUTH) {
722 request_roster(); 759 request_roster();
723 request_storage_bookmarks(); 760 request_storage_bookmarks();
761 request_storage_rosternotes();
724 jstate = STATE_LOGGED; 762 jstate = STATE_LOGGED;
725 } 763 }
726 } 764 }
727 765
728 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata) 766 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata)
987 1025
988 jab_send(jc, iqn->xmldata); 1026 jab_send(jc, iqn->xmldata);
989 iqs_del(iqn->id); // XXX 1027 iqs_del(iqn->id); // XXX
990 } 1028 }
991 1029
1030 // send_storage_rosternotes()
1031 // Send the current rosternotes node to update the server.
1032 // Note: the sender should check we're online.
1033 void send_storage_rosternotes(void)
1034 {
1035 eviqs *iqn;
1036
1037 if (!rosternotes) return;
1038
1039 iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
1040 xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), rosternotes);
1041
1042 jab_send(jc, iqn->xmldata);
1043 iqs_del(iqn->id); // XXX
1044 }
1045
992 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 1046 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */