When the server sends us our newly bound resource, update Client.Jid
authorChris Jones <chris@cjones.org>
Wed, 28 Dec 2011 11:55:31 -0700
changeset 15 aa2cf77f0ed3
parent 14 fd6781a41e6f
child 16 b839e37b3f29
When the server sends us our newly bound resource, update Client.Jid and allow the <iq> to pass through to the app so they know it's changed.
stream.go
xmpp.go
--- a/stream.go	Wed Dec 28 11:35:21 2011 -0700
+++ b/stream.go	Wed Dec 28 11:55:31 2011 -0700
@@ -475,6 +475,36 @@
 		msg.Any.Any = &Unrecognized{XMLName: xml.Name{Local:
 				"resource"}, Chardata: res}
 	}
+	f := func(st Stanza) bool {
+		if st.XType() == "error" {
+			log.Println("Resource binding failed")
+			return false
+		}
+		bind := st.XChild()
+		if bind == nil {
+			log.Println("nil resource bind")
+			return false
+		}
+		jidEle := bind.Any
+		if jidEle == nil {
+			log.Println("nil resource")
+			return false
+		}
+		jidStr := jidEle.Chardata
+		if jidStr == "" {
+			log.Println("empty resource")
+			return false
+		}
+		jid := new(JID)
+		if !jid.Set(jidStr) {
+			log.Println("Can't parse JID %s", jidStr)
+			return false
+		}
+		cl.Jid = *jid
+		log.Printf("Bound resource: %s", cl.Jid.String())
+		return true
+	}
+	cl.HandleStanza(msg.Id, f)
 	cl.xmlOut <- msg
 }
 
--- a/xmpp.go	Wed Dec 28 11:35:21 2011 -0700
+++ b/xmpp.go	Wed Dec 28 11:55:31 2011 -0700
@@ -85,7 +85,7 @@
 	cl.password = password
 	cl.Jid = *jid
 	cl.socket = tcp
-	cl.handlers = make(chan *stanzaHandler)
+	cl.handlers = make(chan *stanzaHandler, 1)
 
 	// Start the transport handler, initially unencrypted.
 	tlsr, tlsw := cl.startTransport()