diff plugins.js @ 2:f31a75c3b6c8

code cleaning
author Sonny Piers <sonny.piers@gmail.com>
date Sun, 18 Dec 2011 22:57:47 +0100
parents 96898e3812a5
children 029c12b8f048
line wrap: on
line diff
--- a/plugins.js
+++ b/plugins.js
@@ -1,15 +1,31 @@
 'use strict';
 
+/**
+  Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
+
+  Permission to use, copy, modify, and/or distribute this software for any
+  purpose with or without fee is hereby granted, provided that the above
+  copyright notice and this permission notice appear in all copies.
+
+  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
 //
 //Roster
 //
 Lighstring.NS.roster = 'jabber:iq:roster';
 Lighstring.stanza.roster = {
 	'get': function() {
-		return "<iq type='get'><query xmlns='"+Mango.NS.roster+"'/></iq>";
+		return "<iq type='get'><query xmlns='"+Lightstring.NS.roster+"'/></iq>";
 	},
 	add: function(aAddress, aGroups, aCustomName) {
-		var iq = $iq({type: 'set'}).c('query', {xmlns: Mango.NS.roster}).c('item', {jid: aAddress}).tree();
+		var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree();
 		if(aCustomName) iq.querySelector('item').setAttribute(aCustomName);
 		for (var i=0; i<aGroups.length; i++) {
 			if(i === 0) iq.querySelector('item').appendChild(document.createElement('group'));
@@ -18,7 +34,7 @@ Lighstring.stanza.roster = {
 		return iq;
 	},
 	remove: function(aAddress) {
-		return $iq({type: 'set'}).c('query', {xmlns: Mango.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
+		return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree();
 	}
 };
 Lighstring.getRoster = function(connection, aCallback) {
@@ -55,14 +71,14 @@ Lighstring.NS.vcard = 'vcard-temp';
 Lighstring.stanza.vcard = {
 	'get': function(aTo) {
 		if(aTo)
-			return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Mango.NS.vcard+"'/></iq>";
+			return "<iq type='get' to='"+aTo+"'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
 		else
-			return "<iq type='get'><vCard xmlns='"+Mango.NS.vcard+"'/></iq>";
+			return "<iq type='get'><vCard xmlns='"+Lightstring.NS.vcard+"'/></iq>";
 	}
 };
 //FIXME we should return a proper vcard, not an XMPP one
 Lighstring.getVcard = function(aConnection, aTo, aCallback) {
-	aConnection.send(Mango.stanza.vcard.get(aTo), function(answer, err){
+	aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){
 		if(answer) {
 			var vcard = answer.querySelector('vCard');
 			if(vcard)
@@ -85,9 +101,9 @@ Lighstring.stanza.disco = {
 			var iq = "<iq type='get'>";
 		
 		if(aNode)
-			var query = "<query xmlns='"+Mango.NS['disco#items']+"' node='"+aNode+"'/>";
+			var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>";
 		else
-			var query = "<query xmlns='"+Mango.NS['disco#items']+"'/>";
+			var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>";
 			
 		return iq+query+"</iq>";
 	},
@@ -97,15 +113,15 @@ Lighstring.stanza.disco = {
 		else
 			var iq = "<iq type='get'>";
 		if(aNode)
-			var query = "<query xmlns='"+Mango.NS['disco#info']+"' node='"+aNode+"'/>";
+			var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>";
 		else
-			var query = "<query xmlns='"+Mango.NS['disco#info']+"'/>";
+			var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>";
 			
 		return iq+query+"</iq>";
 	}
 };
 Lighstring.discoItems = function(aConnection, aTo, aCallback) {
-	aConnection.send(Mango.stanza.disco.items(aTo), function(answer){
+	aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){
 		var items = [];
 		answer.querySelectorAll('item').forEach(function(node) {
 			var item = {
@@ -120,7 +136,7 @@ Lighstring.discoItems = function(aConnec
 	});
 };
 Lighstring.discoInfo = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Mango.stanza.disco.info(aTo, aNode), function(answer){
+	aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){
 		var field = answer.querySelector('field[var="pubsub#creator"] > value');
 		var creator = field ? field.textContent : '';
 		//FIXME callback the entire data
@@ -135,27 +151,27 @@ Lighstring.NS.pubsub = "http://jabber.or
 Lighstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
 Lighstring.stanza.pubsub = {
 	getConfig: function(aTo, aNode) {
-		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
+		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><configure node='"+aNode+"'/></pubsub></iq>";
 	},
 	items: function(aTo, aNode) {
-		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
+		return  "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><items node='"+aNode+"'/></pubsub></iq>";
 	},
 	affiliations: function(aTo, aNode) {
-		return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
+		return "<iq type='get' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'/></pubsub></iq>";
 	},
 	publish: function(aTo, aNode, aItem, aId) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
+		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><publish node='"+aNode+"'><item id='"+aId+"'>"+aItem+"</item></publish></pubsub></iq>";
 	},
 	retract: function(aTo, aNode, aItem) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
+		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><retract node='"+aNode+"'><item id='"+aItem+"'/></retract></pubsub></iq>";
 	},
 	'delete': function(aTo, aNode, aURI) {
-		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
+		return  "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><delete node='"+aNode+"'/></pubsub></iq>";
 	},
 	create: function(aTo, aNode, aFields) {
-		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub+"'><create node='"+aNode+"'/>";
+		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub+"'><create node='"+aNode+"'/>";
 		if(aFields) {
-			iq += "<configure><x xmlns='"+Mango.NS.x+"' type='submit'>"
+			iq += "<configure><x xmlns='"+Lightstring.NS.x+"' type='submit'>"
 			aFields.forEach(function(field) {
 				iq += field;
 			});
@@ -165,7 +181,7 @@ Lighstring.stanza.pubsub = {
 		return iq;
 	},
 	setAffiliations: function(aTo, aNode, aAffiliations) {
-		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Mango.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
+		var iq = "<iq type='set' to='"+aTo+"'><pubsub xmlns='"+Lightstring.NS.pubsub_owner+"'><affiliations node='"+aNode+"'>";
 		for(var i = 0; i < aAffiliations.length; i++) {
 			iq += "<affiliation jid='"+aAffiliations[i][0]+"' affiliation='"+aAffiliations[i][1]+"'/>"
 		}
@@ -174,7 +190,7 @@ Lighstring.stanza.pubsub = {
 	},
 };
 Lighstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.items(aTo, aNode), function(answer){
+	aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){
 		var items = [];
 		answer.querySelectorAll('item').forEach(function(node) {
 			var item = {
@@ -193,7 +209,7 @@ Lighstring.pubsubItems = function(aConne
 	});
 }
 Lighstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
+	aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) {
 		if(answer.getAttribute('type') === 'result')
 			aCallback(null, answer);
 		else
@@ -201,7 +217,7 @@ Lighstring.pubsubCreate = function(aConn
 	});
 };
 Lighstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.getConfig(aTo, aNode), function(answer){
+	aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){
 		var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent;
 		if(accessmodel)
 			aCallback(accessmodel);
@@ -210,13 +226,13 @@ Lighstring.pubsubConfig = function(aConn
 	});
 }
 Lighstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
+	aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){
 		if(aCallback)
 			aCallback(answer);
 	});
 }
 Lighstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
+	aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){
 		if(answer.getAttribute('type') === 'result')
 			aCallback(null, answer);
 		else
@@ -224,13 +240,13 @@ Lighstring.pubsubPublish = function(aCon
 	});
 }
 Lighstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.delete(aTo, aNode), function(answer){
+	aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){
 		if(aCallback)
 			aCallback(answer);
 	});
 }
 Lighstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
+	aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) {
 		if((answer.getAttribute('type') === 'result') && aCallback) {
 			var affiliations = {};
 			answer.querySelectorAll('affiliation').forEach(function(affiliation) {
@@ -241,7 +257,7 @@ Lighstring.pubsubGetAffiliations = funct
 	});
 };
 Lighstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) {
-	aConnection.send(Mango.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
+	aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations));
 };
 //
 //IM