1. Ivan Vučica
  2. ZXMPP

Commits

Ivan Vučica  committed 25bc818

Crashfixes. In presence, show and type are not the same. When doing presenceUpdate, also pass the original stanza to handlers (needed to handle subscriptions).

  • Participants
  • Parent commits 408d4e4
  • Branches default

Comments (0)

Files changed (3)

File zxmpp_caps.js

View file
  • Ignore whitespace
 	this.unpackExt = function zxmppCaps_unpackExt(extdest)
 	{
 		if(!this.ext) return;
+                if(!this.ext.length) return;
 		var exts = this.ext.split(" ");
 		
 		var packet = new this.zxmpp.packet(this.zxmpp);
 		
 		if(needsSending)
 			packet.send("poll");
+                delete packet;
 	}
 
 	this.toJSON = function zxmppCaps_toJSON(key)

File zxmpp_main.js

View file
  • Ignore whitespace
 	}
 }
 
-zxmppClass.prototype.notifyPresenceUpdate = function zxmppMain_notifyPresenceUpdate(presence)
+zxmppClass.prototype.notifyPresenceUpdate = function zxmppMain_notifyPresenceUpdate(presence, stanza)
 {
 	for(var presenceHandlerId in this.onPresenceUpdate)
 	{
 		var presenceHandler = this.onPresenceUpdate[presenceHandlerId];
 		if(presenceHandler.func)
-			presenceHandler.func(presenceHandler.context, this, presence);
+			presenceHandler.func(presenceHandler.context, this, presence, stanza);
 		else
-			presenceHandler(this, presence);
+			presenceHandler(this, presence, stanza);
 	}
 }
 zxmppClass.prototype.notifyRosterUpdate = function zxmppMain_notifyRosterUpdate(rosteritem)

File zxmpp_stanzapresence.js

View file
  • Ignore whitespace
 	
 	this.parseXML = function (xml)
 	{
-		
 		//zxmppConsole.log("Presence parsing: " + this.zxmpp.util.serializedXML(xml));
-		this.zxmpp.util.easierAttrs(xml);
-		
+		this.zxmpp.util.easierAttrs(xml)
+
 		this.from = xml.attr["from"];
 		this.to = xml.attr["to"];
 		this.type = xml.attr["type"];
 		{
 			presence.show = "unavailable";
 			zxmppConsole.log(presence);
-			this.zxmpp.notifyPresenceUpdate(presence);
+			this.zxmpp.notifyPresenceUpdate(presence, this);
 			this.zxmpp.removePresence(this.from);
 			
 			return; // FIXME we should not return and should continue parsing; showing the <status> upon logout might be fun
 			}
 			
 		}
-		this.zxmpp.notifyPresenceUpdate(presence);
+		this.zxmpp.notifyPresenceUpdate(presence, this);
 
 	}
 	
 	
-	this.appendToPacket = function(packet, from, to, type, status, priority)
+	this.appendToPacket = function(packet, from, to, show, status, priority, type)
 	{
 		if(!status) 
 			status = "";
 		this.from = from;
 		this.to = to;
 		this.status = status;
-		if(type == "unavailable")
+		if(show == "unavailable")
 		{
-			this.type = "unavailable";
+			this.show = "unavailable";
 		}
-		else if(type == "avail")
+		else if(show == "avail")
 		{
 			// both show and type are empty!
+			delete this.show;
 		}
 		else
 		{
-			this.show = type;
+			this.show = show;
 		}
 		if(typeof priority != "undefined")
 		{
 			this.priority = priority;
 		}
+		if(typeof type != "undefined")
+		{
+			this.type = type;
+		}
 		
 		
 		var presenceNode = this.presenceNode = packet.xml.createElementNS("jabber:client", "presence");
 		
 		// finally, add our caps!
 		var presence = this.zxmpp.getPresence(this.from);
-		var caps = presence.caps;
-		caps.applyThisClientsCaps();
-		caps.appendToXML(packet, presenceNode);
+		if(presence)
+		{
+			//... but only if this.from actually exists
+			// (it might not in case we're sending <presence type='subscribe'>)
+			var caps = presence.caps;
+			caps.applyThisClientsCaps();
+			caps.appendToXML(packet, presenceNode);
+		}
 		
 		packet.presenceXML = presenceNode;
 		packet.presenceStanza = this;