rendered paste body// DEFINITIONSvar PUBSUB_NODE = "home/meteo/foo";var PUBSUB_JID = "pubsub.example.net";var NS_PUBSUB = "http://jabber.org/protocol/pubsub";var NS_PUBSUB_OWNER = NS_PUBSUB + "#owner";var NS_PUBSUB_EVENT = NS_PUBSUB + "#event";// STATEvar channel; // XXXbard: globalvar testAccount = 'meteo@example.net/Firefox/SamePlace';// FUNCTIONSfunction init() { channel = XMPP.createChannel(); channel.on({ event: 'iq', direction: 'in', stanza: function(s) { return s.@type == 'result'; } }, function(iq) { alert(iq.stanza.@id); }); channel.on({ event : 'iq', direction : 'in', stanza: function(s) { default xml namespace="http://a9.com/-/spec/opensearch/1.1/" return s..OpenSearchDescription; }}, function(iq) { //default xml namespace = 'http://jabber.org/protocol/pubsub'; alert("ha"); var foo = iq.stanza; default xml namespace="http://a9.com/-/spec/opensearch/1.1/" alert(foo..OpenSearchDescription.length()); //This doesn't seem to work. }); channel.on({ event : 'iq', direction : 'in', stanza: function(s) { return s..@subid; }}, function(iq) { //alert(iq.stanza..@subid); SUBID = iq.stanza..@subid; //alert(SUBID) });};/* Releasing channel. Not all are implemented yet */function finish() { channel = XMPP.release();}/* Iq PubSub item handler */function iq_pubsub_items_init() { iq_pubsub_items_channel = XMPP.createChannel();/* This is where I get stuck. I can't handle PubSub items like the following example : <iq type="result" id="subman1" from="pubsub.example.net" to="meteo@example.net/Firefox/SamePlace"> <pubsub xmlns="http://jabber.org/protocol/pubsub"> <items subid="apbpPLhnrIEFmGzp6Vg557ee9bpbJ4akB4HxLf9f" node="home/meteo/foo"> <item id="dicM2O4oMUuitne"> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <ShortName>Wikipedia (English)</ShortName> <Description>Wikipedia (English)</Description> <Image height="16" width="16" type="image/x-icon">http://en.wikipedia.org/favicon.ico</Image> <Url type="text/html" method="get" template="http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchTerms}"/> <Url type="application/x-suggestions+json" method="GET" template="http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}"/> </OpenSearchDescription> </item> <item id="3kL8w9fYFJlKML1"> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <ShortName>Wikipedia (English)</ShortName> <Description>Wikipedia (English)</Description> <Image height="16" width="16" type="image/x-icon">http://en.wikipedia.org/favicon.ico</Image> <Url type="text/html" method="get" template="http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchTerms}"/> <Url type="application/x-suggestions+json" method="GET" template="http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}"/> </OpenSearchDescription> </item> </items> </pubsub> <meta account="meteo@example.net/Firefox/SamePlace" direction="in" xmlns="http://hyperstruct.net/xmpp4moz/protocol/internal"/></iq>I'd wish to get an array or a list of all PubSub items so that I can process them to import them in Firefox.*/};// GUI REACTIONS// XXXbard: window.addEventListener('load', function() { init();}, false);window.addEventListener('unload', function() { finish();}, false);// NETWORK ACTIONS// XXXbard: you don't want these in the top level, function testPubsub() { /* Get PubSub items */ var iq_pubsub_get_items = <iq type='get' to={PUBSUB_JID}> <pubsub xmlns={NS_PUBSUB}> <items subid={SUBID} node={PUBSUB_NODE}/> </pubsub> </iq>; //Get PubSub items XMPP.send(testAccount, iq_pubsub_get_items); /*Set PubSub items*/ var opensearch_plugin = <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <ShortName>Wikipedia (English)</ShortName> <Description>Wikipedia (English)</Description> <Image height="16" width="16" type="image/x-icon">http://en.wikipedia.org/favicon.ico</Image> <Url type="text/html" method="get" template="http://en.wikipedia.org/w/index.php?title=Special:Search&search={searchTerms}"/> <Url type="application/x-suggestions+json" method="GET" template="http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}"/> </OpenSearchDescription>; var iq_pubsub_set_items = <iq type='set' to={PUBSUB_JID}> <pubsub xmlns={NS_PUBSUB}> <publish node={PUBSUB_NODE}> <item>{opensearch_plugin}</item> <item>{opensearch_plugin}</item> </publish> </pubsub> </iq>; XMPP.send(testAccount, iq_pubsub_set_items); /* Get PubSub SubID */ var iq_pubsub_get_subs = <iq type='get' to={PUBSUB_JID}> <pubsub xmlns={NS_PUBSUB_OWNER}> <subscriptions node={PUBSUB_NODE}/> </pubsub> </iq>; //print(iq_pubsub_subs); var SUBID = ""; XMPP.send(testAccount, iq_pubsub_get_subs);}// XXXbard: don't care about save-to-disk now, get the protocol issues sorted firstfunction save() { /* This is what follows after having retreived the PubSub OpenSearch items : the plugins are written into an XML file in the /tmp directory and then imported to Firefox. Here's only the writing part : */ // Writing file const Cc = Components.classes; const Ci = Components.interfaces; var nsIProperties = Cc['@mozilla.org/file/directory_service;1']. getService(Ci.nsIProperties); var src_file = nsIProperties.get('TmpD', Ci.nsIFile); src_file.append('OpenSearchFox.xml'); var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); fos.init(src_file, 0x02 | 0x08 | 0x20, 0664, 0); var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); converter.charset ="utf-8" var foo = "hello world" var chunk = converter.ConvertFromUnicode(foo); fos.write(chunk, chunk.length); fos.close(); /* And this is the code borrowed from OpenSearchFox which manages to write the XML file of the OpenSearch plugin and import it to Firefox */ /* writeFile : function (str_Buffer, file, charset){ var fos = Cc["@mozilla.org/network/file-output-stream;1"]. createInstance(Ci.nsIFileOutputStream); fos.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. createInstance(Ci.nsIScriptableUnicodeConverter); converter.charset = charset; var chunk = converter.ConvertFromUnicode(str_Buffer); fos.write(chunk, chunk.length); fos.close(); }, onDone : function(){ try{ var nsIProperties = Cc['@mozilla.org/file/directory_service;1']. getService(Ci.nsIProperties); var src_file = nsIProperties.get('TmpD', Ci.nsIFile); src_file.append('OpenSearchFox.xml'); this.writeFile(this.createOpenSearchDescription(successful_controls), src_file, 'utf-8'); // this part import the OpenSearchFox.xml file as an OpenSearch plugin var nsIBrowserSearchService = Cc["@mozilla.org/browser/search-service;1"]. getService(Ci.nsIBrowserSearchService); nsIBrowserSearchService.addEngine(this.getURLSpecFromFile(src_file), Ci.nsISearchEngine.DATA_XML, '', false); } catch(e){ alert(e); } }, */ }