3 Jappix - An open social platform
4 These are the IQ JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 27/08/11
14 // Handles an incoming IQ packet
15 function handleIQ(iq) {
16 // Gets the IQ content
17 var iqNode = iq.getNode();
18 var iqFrom = fullXID(getStanzaFrom(iq));
19 var iqID = iq.getID();
20 var iqQueryXMLNS = iq.getQueryXMLNS();
21 var iqQuery = iq.getQuery();
22 var iqType = iq.getType();
25 var iqResponse = new JSJaCIQ();
27 iqResponse.setID(iqID);
28 iqResponse.setTo(iqFrom);
29 iqResponse.setType('result');
32 if((iqQueryXMLNS == NS_IQOOB) && (iqType == 'set')) {
33 /* REF: http://xmpp.org/extensions/xep-0066.html */
35 handleOOB(iqFrom, iqID, 'iq', iqNode);
37 logThis('Received IQ OOB request: ' + iqFrom);
41 else if(getDB('send/url', iqID)) {
43 var oob_url = getDB('send/url', iqID);
44 var oob_desc = getDB('send/desc', iqID);
45 var notif_id = hex_md5(oob_url + oob_desc + iqType + iqFrom + iqID);
48 if($(iqNode).find('error').size()) {
50 if($(iqNode).find('error not-acceptable').size())
51 newNotification('send_reject', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
55 newNotification('send_fail', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
58 $.get(oob_url + '&action=remove');
62 else if(iqType == 'result')
63 newNotification('send_accept', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
66 // Software version query
67 else if((iqQueryXMLNS == NS_VERSION) && (iqType == 'get')) {
68 /* REF: http://xmpp.org/extensions/xep-0092.html */
70 var iqQuery = iqResponse.setQuery(NS_VERSION);
72 iqQuery.appendChild(iq.buildNode('name', {'xmlns': NS_VERSION}, 'Jappix'));
73 iqQuery.appendChild(iq.buildNode('version', {'xmlns': NS_VERSION}, JAPPIX_VERSION));
74 iqQuery.appendChild(iq.buildNode('os', {'xmlns': NS_VERSION}, BrowserDetect.OS));
78 logThis('Received software version query: ' + iqFrom);
81 // Last activity query
82 else if((iqQueryXMLNS == NS_LAST) && (iqType == 'get')) {
83 /* REF: http://xmpp.org/extensions/xep-0012.html */
85 var iqQuery = iqResponse.setQuery(NS_LAST);
86 iqQuery.setAttribute('seconds', getLastActivity());
90 logThis('Received last activity query: ' + iqFrom);
94 else if((iqQueryXMLNS == NS_PRIVACY) && (iqType == 'set')) {
95 // REF : http://xmpp.org/extensions/xep-0016.html
101 $(iqQuery).find('list').each(function() {
102 getPrivacy($(this).attr('name'));
105 logThis('Received privacy lists push: ' + iqFrom);
109 else if((iqQueryXMLNS == NS_ROSTER) && (iqType == 'set')) {
110 // REF : http://xmpp.org/extensions/xep-0092.html
113 con.send(iqResponse);
116 $(iqQuery).find('item').each(function() {
117 parseRoster($(this), 'presence');
120 logThis('Received roster push: ' + iqFrom);
123 // Roster Item Exchange query
124 else if($(iqNode).find('x[xmlns=' + NS_ROSTERX + ']').size()) {
125 // Open a new notification
126 newNotification('rosterx', iqFrom, [iqNode], '');
128 logThis('Roster Item Exchange from: ' + iqFrom);
132 else if((iqQueryXMLNS == NS_DISCO_INFO) && (iqType == 'get')) {
133 /* REF: http://xmpp.org/extensions/xep-0030.html */
135 var iqQuery = iqResponse.setQuery(NS_DISCO_INFO);
137 // We set the name of the client
138 iqQuery.appendChild(iq.buildNode('identity', {
139 'category': 'client',
142 'xmlns': NS_DISCO_INFO
145 // We set all the supported features
146 var fArray = myDiscoInfos();
149 iqQuery.appendChild(iq.buildNode('feature', {'var': fArray[i], 'xmlns': NS_DISCO_INFO}));
151 con.send(iqResponse);
153 logThis('Received disco#infos query: ' + iqFrom);
157 else if($(iqNode).find('time').size() && (iqType == 'get')) {
158 /* REF: http://xmpp.org/extensions/xep-0202.html */
160 var iqTime = iqResponse.appendNode('time', {'xmlns': NS_URN_TIME});
161 iqTime.appendChild(iq.buildNode('tzo', {'xmlns': NS_URN_TIME}, getDateTZO()));
162 iqTime.appendChild(iq.buildNode('utc', {'xmlns': NS_URN_TIME}, getXMPPTime('utc')));
164 con.send(iqResponse);
166 logThis('Received local time query: ' + iqFrom);
170 else if($(iqNode).find('ping').size() && (iqType == 'get')) {
171 /* REF: http://xmpp.org/extensions/xep-0199.html */
173 con.send(iqResponse);
175 logThis('Received a ping: ' + iqFrom);
179 else if(!$(iqNode).find('error').size() && ((iqType == 'get') || (iqType == 'set'))) {
180 // Append stanza content
181 for(var i = 0; i < iqNode.childNodes.length; i++)
182 iqResponse.getNode().appendChild(iqNode.childNodes.item(i).cloneNode(true));
184 // Append error content
185 var iqError = iqResponse.appendNode('error', {'xmlns': NS_CLIENT, 'code': '501', 'type': 'cancel'});
186 iqError.appendChild(iq.buildNode('feature-not-implemented', {'xmlns': NS_STANZAS}));
187 iqError.appendChild(iq.buildNode('text', {'xmlns': NS_STANZAS}, _e("The feature requested is not implemented by the recipient or server and therefore cannot be processed.")));
189 con.send(iqResponse);
191 logThis('Received an unsupported IQ query from: ' + iqFrom);